8000 Turn Tags.Add() overloads into extension methods · rlazev/libgit2sharp@6301a50 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6301a50

Browse files
committed
Turn Tags.Add() overloads into extension methods
1 parent 34c4aac commit 6301a50

File tree

3 files changed

+48
-37
lines changed

3 files changed

+48
-37
lines changed

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
<Compile Include="CommitLog.cs" />
6767
<Compile Include="Configuration.cs" />
6868
<Compile Include="ContentChanges.cs" />
69+
<Compile Include="TagCollectionExtensions.cs" />
6970
<Compile Include="Core\Compat\Environment.cs" />
7071
<Compile Include="Core\FilePath.cs" />
7172
<Compile Include="Core\FilePathExtensions.cs" />

LibGit2Sharp/TagCollection.cs

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace LibGit2Sharp
1212
/// </summary>
1313
public class TagCollection : IEnumerable<Tag>
1414
{
15-
private readonly Repository repo;
15+
internal readonly Repository repo;
1616
private const string refsTagsPrefix = "refs/tags/";
1717

1818
/// <summary>
@@ -100,24 +100,6 @@ public virtual Tag Add(string name, ObjectId targetId, Signature tagger, string
100100
return this[name];
101101
}
102102

103-
/// <summary>
104-
/// Creates an annotated tag with the specified name.
105-
/// </summary>
106-
/// <param name = "name">The name.</param>
107-
/// <param name = "objectish">Revparse spec for the target object.</param>
108-
/// <param name = "tagger">The tagger.</param>
109-
/// <param name = "message">The message.</param>
110-
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing tag, false otherwise.</param>
111-
/// <returns></returns>
112-
public virtual Tag Add(string name, string objectish, Signature tagger, string message, bool allowOverwrite = false)
113-
{
114-
Ensure.ArgumentNotNullOrEmptyString(objectish, "target");
115-
116-
GitObject objectToTag = repo.Lookup(objectish, GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound);
117-
118-
return Add(name, objectToTag.Id, tagger, message, allowOverwrite);
119-
}
120-
121103
internal static string PrettifyMessage(string message)
122104
{
123105
var buffer = new byte[NativeMethods.GIT_PATH_MAX];
@@ -139,7 +121,7 @@ internal static string PrettifyMessage(string message)
139121
[Obsolete("This method will be removed in the next release. Please use Add() instead.")]
140122
public virtual Tag Create(string name, string target, Signature tagger, string message, bool allowOverwrite = false)
141123
{
142-
return Add(name, target, tagger, message, allowOverwrite);
124+
return this.Add(name, target, tagger, message, allowOverwrite);
143125
}
144126

145127
/// <summary>
@@ -166,22 +148,6 @@ public virtual Tag Add(string name, ObjectId targetId, bool allowOverwrite = fal
166148
return this[name];
167149
}
168150

169-
/// <summary>
170-
/// Creates a lightweight tag with the specified name.
171-
/// </summary>
172-
/// <param name = "name">The name.</param>
173-
/// <param name = "objectish">Revparse spec for the target object.</param>
174-
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing tag, false otherwise.</param>
175-
/// <returns></returns>
176-
public virtual Tag Add(string name, string objectish, bool allowOverwrite = false)
177-
{
178-
Ensure.ArgumentNotNullOrEmptyString(objectish, "objectish");
179-
180-
GitObject objectToTag = repo.Lookup(objectish, GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound);
181-
182-
return Add(name, objectToTag.Id, allowOverwrite);
183-
}
184-
185151
/// <summary>
186152
/// Creates a lightweight tag with the specified name.
187153
/// </summary>
@@ -192,7 +158,7 @@ public virtual Tag Add(string name, string objectish, bool allowOverwrite = fals
192158
[Obsolete("This method will be removed in the next release. Please use Add() instead.")]
193159
public virtual Tag Create(string name, string target, bool allowOverwrite = false)
194160
{
195-
return Add(name, target, allowOverwrite);
161+
return this.Add(name, target, allowOverwrite);
196162
}
197163

198164
/// <summary>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using LibGit2Sharp.Core;
2+
3+
namespace LibGit2Sharp
4+
{
5+
/// <summary>
6+
/// Provides helper overloads to a <see cref = "TagCollection" />.
7+
/// </summary>
8+
public static class TagCollectionExtensions
9+
{
10+
/// <summary>
11+
/// Creates an annotated tag with the specified name.
12+
/// </summary>
13+
/// <param name = "name">The name.</param>
14+
/// <param name = "objectish">Revparse spec for the target object.</param>
15+
/// <param name = "tagger">The tagger.</param>
16+
/// <param name = "message">The message.</param>
17+
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing tag, false otherwise.</param>
18+
/// <param name = "tags">The <see cref="TagCollection"/> being worked with.</param>
19+
public static Tag Add(this TagCollection tags, string name, string objectish, Signature tagger, string message, bool allowOverwrite = false)
20+
{
21+
Ensure.ArgumentNotNullOrEmptyString(objectish, "target");
22+
23+
GitObject objectToTag = tags.repo.Lookup(objectish, GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound);
24+
25+
return tags.Add(name, objectToTag.Id, tagger, message, allowOverwrite);
26+
}
27+
28+
/// <summary>
29+
/// Creates a lightweight tag with the specified name.
30+
/// </summary>
31+
/// <param name = "name">The name.</param>
32+
/// <param name = "objectish">Revparse spec for the target object.</param>
33+
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing tag, false otherwise.</param>
34+
/// <param name = "tags">The <see cref="TagCollection"/> being worked with.</param>
35+
public static Tag Add(this TagCollection tags, string name, string objectish, bool allowOverwrite = false)
36+
{
37+
Ensure.ArgumentNotNullOrEmptyString(objectish, "objectish");
38+
39+
GitObject objectToTag = tags.repo.Lookup(objectish, GitObjectType.Any, LookUpOptions.ThrowWhenNoGitObjectHasBeenFound);
40+
41+
return tags.Add(name, objectToTag.Id, allowOverwrite);
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)
0