8000 Replace managed version of lightweight tag creation with native libgi… · MicrosoftWebMatrix/libgit2sharp@822f6c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 822f6c1

Browse files
committed
Replace managed version of lightweight tag creation with native libgit2 implementation
1 parent 4acb95c commit 822f6c1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ public static extern int git_repository_discover(StringBuilder repository_path,
189189
[DllImport(libgit2)]
190190
public static extern int git_tag_create(out GitOid oid, RepositorySafeHandle repo, string name, IntPtr target, GitSignature signature, string message, bool force);
191191

192+
[DllImport(libgit2)]
193+
public static extern int git_tag_create_lightweight(out GitOid oid, RepositorySafeHandle repo, string name, IntPtr target, bool force);
194+
192195
[DllImport(libgit2)]
193196
public static extern int git_tag_delete(RepositorySafeHandle repo, string tagName);
194197

LibGit2Sharp/TagCollection.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,19 @@ public Tag Create(string name, string target, Signature tagger, string message,
9999
/// <returns></returns>
100100
public Tag Create(string name, string target, bool allowOverwrite = false)
101101
{
102+
Ensure.ArgumentNotNullOrEmptyString(name, "name");
102103
Ensure.ArgumentNotNullOrEmptyString(target, "target");
103104

104105
GitObject objectToTag = RetrieveObjectToTag(target);
105106

106-
repo.Refs.Create(NormalizeToCanonicalName(name), objectToTag.Id.Sha, allowOverwrite); //TODO: To be replaced by native libgit2 git_tag_create_lightweight() when available.
107+
int res;
108+
using (var objectPtr = new ObjectSafeWrapper(objectToTag.Id, repo))
109+
{
110+
GitOid oid;
111+
res = NativeMethods.git_tag_create_lightweight(out oid, repo.Handle, name, objectPtr.ObjectPtr, allowOverwrite);
112+
}
113+
114+
Ensure.Success(res);
107115

108116
return this[name];
109117
}

0 commit comments

Comments
 (0)
0