Permalink
Browse files

Turn Tags.Add() overloads into extension methods

  • Loading branch information...
nulltoken committed Aug 25, 2012
1 parent 34c4aac commit 6301a50bb355bf7161b368f4f745982983f4d726
Showing with 48 additions and 37 deletions.
  1. +1 −0 LibGit2Sharp/LibGit2Sharp.csproj
  2. +3 −37 LibGit2Sharp/TagCollection.cs
  3. +44 −0 LibGit2Sharp/TagCollectionExtensions.cs
@@ -66,6 +66,7 @@
<Compile Include="CommitLog.cs" />
<Compile Include="Configuration.cs" />
<Compile Include="ContentChanges.cs" />
+ <Compile Include="TagCollectionExtensions.cs" />
<Compile Include="Core\Compat\Environment.cs" />
<Compile Include="Core\FilePath.cs" />
<Compile Include="Core\FilePathExtensions.cs" />
@@ -12,7 +12,7 @@ namespace LibGit2Sharp
/// </summary>
public class TagCollection : IEnumerable<Tag>
{
- private readonly Repository repo;
+ internal readonly Repository repo;
private const string refsTagsPrefix = "refs/tags/";
/// <summary>
@@ -100,24 +100,6 @@ public virtual Tag Add(string name, ObjectId targetId, Signature tagger, string
return this[name];
}
- /// <summary>
- /// Creates an annotated tag with the specified name.
- /// </summary>
- /// <param name = "name">The name.</param>
- /// <param name = "objectish">Revparse spec for the target object.</param>
- /// <param name = "tagger">The tagger.</param>
- /// <param name = "message">The message.</param>
- /// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing tag, false otherwise.</param>
- /// <returns></returns>
- public virtual Tag Add(string name, string objectish, Signature tagger, string message, bool allowOverwrite = false)
- {
- Ensure.ArgumentNotNullOrEmptyString(objectish, "target");
-
- GitObject objectToTag = repo.Lookup(objectish, GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound);
-
- return Add(name, objectToTag.Id, tagger, message, allowOverwrite);
- }
-
internal static string PrettifyMessage(string message)
{
var buffer = new byte[NativeMethods.GIT_PATH_MAX];
@@ -139,7 +121,7 @@ internal static string PrettifyMessage(string message)
[Obsolete("This method will be removed in the next release. Please use Add() instead.")]
public virtual Tag Create(string name, string target, Signature tagger, string message, bool allowOverwrite = false)
{
- return Add(name, target, tagger, message, allowOverwrite);
+ return this.Add(name, target, tagger, message, allowOverwrite);
}
/// <summary>
@@ -166,22 +148,6 @@ public virtual Tag Add(string name, ObjectId targetId, bool allowOverwrite = fal
return this[name];
}
- /// <summary>
- /// Creates a lightweight tag with the specified name.
- /// </summary>
- /// <param name = "name">The name.</param>
- /// <param name = "objectish">Revparse spec for the target object.</param>
- /// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing tag, false otherwise.</param>
- /// <returns></returns>
- public virtual Tag Add(string name, string objectish, bool allowOverwrite = false)
- {
- Ensure.ArgumentNotNullOrEmptyString(objectish, "objectish");
-
- GitObject objectToTag = repo.Lookup(objectish, GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound);
-
- return Add(name, objectToTag.Id, allowOverwrite);
- }
-
/// <summary>
/// Creates a lightweight tag with the specified name.
/// </summary>
@@ -192,7 +158,7 @@ public virtual Tag Add(string name, string objectish, bool allowOverwrite = fals
[Obsolete("This method will be removed in the next release. Please use Add() instead.")]
public virtual Tag Create(string name, string target, bool allowOverwrite = false)
{
- return Add(name, target, allowOverwrite);
+ return this.Add(name, target, allowOverwrite);
}
/// <summary>
@@ -0,0 +1,44 @@
+using LibGit2Sharp.Core;
+
+namespace LibGit2Sharp
+{
+ /// <summary>
+ /// Provides helper overloads to a <see cref = "TagCollection" />.
+ /// </summary>
+ public static class TagCollectionExtensions
+ {
+ /// <summary>
+ /// Creates an annotated tag with the specified name.
+ /// </summary>
+ /// <param name = "name">The name.</param>
+ /// <param name = "objectish">Revparse spec for the target object.</param>
+ /// <param name = "tagger">The tagger.</param>
+ /// <param name = "message">The message.</param>
+ /// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing tag, false otherwise.</param>
+ /// <param name = "tags">The <see cref="TagCollection"/> being worked with.</param>
+ public static Tag Add(this TagCollection tags, string name, string objectish, Signature tagger, string message, bool allowOverwrite = false)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(objectish, "target");
+
+ GitObject objectToTag = tags.repo.Lookup(objectish, GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound);
+
+ return tags.Add(name, objectToTag.Id, tagger, message, allowOverwrite);
+ }
+
+ /// <summary>
+ /// Creates a lightweight tag with the specified name.
+ /// </summary>
+ /// <param name = "name">The name.</param>
+ /// <param name = "objectish">Revparse spec for the target object.</param>
+ /// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing tag, false otherwise.</param>
+ /// <param name = "tags">The <see cref="TagCollection"/> being worked with.</param>
+ public static Tag Add(this TagCollection tags, string name, string objectish, bool allowOverwrite = false)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(objectish, "objectish");
+
+ GitObject objectToTag = tags.repo.Lookup(objectish, GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound);
+
+ return tags.Add(name, objectToTag.Id, allowOverwrite);
+ }
+ }
+}

0 comments on commit 6301a50

Please sign in to comment.