8000 Update libgit2 binaries to 33afca4 · dotjosh/libgit2sharp@148fb75 · GitHub
[go: up one dir, main page]

Skip to content

Commit 148fb75

Browse files
committed
Update libgit2 binaries to 33afca4
Final fixes for issue libgit2#51, libgit2#52 and libgit2#53.
1 parent dbf812d commit 148fb75

10 files changed

+47
-85
lines changed

Lib/git2.dll

18.5 KB
Binary file not shown.

LibGit2Sharp.Tests/RepositoryFixture.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,35 +297,35 @@ public void CheckingForObjectExistenceWithBadParamsThrows()
297297
public void CanDiscoverABareRepoGivenTheRepoPath()
298298
{
299299
string path = Repository.Discover(Constants.BareTestRepoPath);
300-
path.ShouldEqual(Path.GetFullPath(Constants.BareTestRepoPath));
300+
path.ShouldEqual(Path.GetFullPath(Constants.BareTestRepoPath + Path.DirectorySeparatorChar));
301301
}
302302

303303
[Test]
304304
public void CanDiscoverABareRepoGivenASubDirectoryOfTheRepoPath()
305305
{
306306
string path = Repository.Discover(Path.Combine(Constants.BareTestRepoPath, "objects/4a"));
307-
path.ShouldEqual(Path.GetFullPath(Constants.BareTestRepoPath));
307+
path.ShouldEqual(Path.GetFullPath(Constants.BareTestRepoPath + Path.DirectorySeparatorChar));
308308
}
309309

310310
[Test]
311311
public void CanDiscoverAStandardRepoGivenTheRepoPath()
312312
{
313313
string path = Repository.Discover(Constants.StandardTestRepoPath);
314-
path.ShouldEqual(Path.GetFullPath(Constants.StandardTestRepoPath));
314+
path.ShouldEqual(Path.GetFullPath(Constants.StandardTestRepoPath + Path.DirectorySeparatorChar));
315315
}
316316

317317
[Test]
318318
public void CanDiscoverAStandardRepoGivenASubDirectoryOfTheRepoPath()
319319
{
320320
string path = Repository.Discover(Path.Combine(Constants.StandardTestRepoPath, "objects/4a"));
321-
path.ShouldEqual(Path.GetFullPath(Constants.StandardTestRepoPath));
321+
path.ShouldEqual(Path.GetFullPath(Constants.StandardTestRepoPath + Path.DirectorySeparatorChar));
322322
}
323323

324324
[Test]
325325
public void CanDiscoverAStandardRepoGivenTheWorkingDirPath()
326326
{
327327
string path = Repository.Discover(Constants.StandardTestRepoWorkingDirPath);
328-
path.ShouldEqual(Path.GetFullPath(Constants.StandardTestRepoPath));
328+
path.ShouldEqual(Path.GetFullPath(Constants.StandardTestRepoPath + Path.DirectorySeparatorChar));
329329
}
330330
}
331331
}

LibGit2Sharp/CommitCollection.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,26 +110,40 @@ public Commit Create(Signature author, Signature committer, string message)
110110
Ensure.Success(res);
111111

112112
Reference head = repo.Refs["HEAD"];
113-
GitOid[] gitOids = RetrieveCommitParent(head);
114113

115114
GitOid commitOid;
116-
res = NativeMethods.git_commit_create(out commitOid, repo.Handle, head.CanonicalName, author.Handle,
117-
committer.Handle, message, ref treeOid, gitOids.Count(), ref gitOids);
115+
using (var treePtr = new ObjectSafeWrapper(new ObjectId(treeOid), repo))
116+
using (var headPtr = RetrieveHeadCommitPtr(head))
117+
{
118+
var parentPtrs = BuildArrayFrom(headPtr);
119+
res = NativeMethods.git_commit_create(out commitOid, repo.Handle, head.CanonicalName, author.Handle,
120+
committer.Handle, message, treePtr.ObjectPtr, parentPtrs.Count(), parentPtrs);
121+
}
118122
Ensure.Success(res);
119123

120124
return repo.Lookup<Commit>(new ObjectId(commitOid));
121125
}
122126

123-
private static GitOid[] RetrieveCommitParent(Reference head)
127+
private static IntPtr[] BuildArrayFrom(ObjectSafeWrapper headPtr)
124128
{
129+
if (headPtr.ObjectPtr == IntPtr.Zero)
130+
{
131+
return new IntPtr[]{};
132+
}
133+
134+
return new IntPtr[]{headPtr.ObjectPtr};
135+
}
136+
137+
private ObjectSafeWrapper RetrieveHeadCommitPtr(Reference head)
138+
{
139+
125140
DirectReference oidRef = head.ResolveToDirectReference();
126141
if (oidRef == null)
127142
{
128-
return new GitOid[] { };
143+
return new ObjectSafeWrapper(null, repo);
129144
}
130145

131-
var headCommitId = new ObjectId(oidRef.TargetIdentifier);
132-
return new[] { headCommitId.Oid };
146+
return new ObjectSafeWrapper(new ObjectId(oidRef.TargetIdentifier), repo);
133147
}
134148

135149
private class CommitEnumerator : IEnumerator<Commit>

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ internal static class NativeMethods
2121
public static extern IntPtr git_commit_committer(IntPtr commit);
2222

2323
[DllImport(libgit2)]
24-
public static extern int git_commit_create(out GitOid oid, RepositorySafeHandle repo, string updateRef, GitSignature author, GitSignature committer, string message, ref GitOid treeOid, int parentCount, ref GitOid[] parents);
25-
26-
[DllImport(libgit2)]
27-
public static extern int git_commit_create_o(out GitOid oid, RepositorySafeHandle repo, string updateRef, IntPtr author, IntPtr committer, string message, IntPtr tree, int parentCount, IntPtr parents);
24+
public static extern int git_commit_create(out GitOid oid, RepositorySafeHandle repo, string updateRef, GitSignature author, GitSignature committer, string message, IntPtr tree, int parentCount, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 7)] [In] IntPtr[] parents);
2825

2926
[DllImport(libgit2)]
3027
public static extern IntPtr git_commit_message(IntPtr commit);
@@ -94,16 +91,10 @@ internal static class NativeMethods
9491
public static extern int git_oid_cmp(ref GitOid a, ref GitOid b);
9592

9693
[DllImport(libgit2)]
97-
public static extern int git_reference_create_oid(out IntPtr reference, RepositorySafeHandle repo, string name, ref GitOid oid);
98-
99-
[DllImport(libgit2)]
100-
public static extern int git_reference_create_oid_f(out IntPtr reference, RepositorySafeHandle repo, string name, ref GitOid oid);
101-
102-
[DllImport(libgit2)]
103-
public static extern int git_reference_create_symbolic(out IntPtr reference, RepositorySafeHandle repo, string name, string target);
94+
public static extern int git_reference_create_oid(out IntPtr reference, RepositorySafeHandle repo, string name, ref GitOid oid, bool force);
10495

10596
[DllImport(libgit2)]
106-
public static extern int git_reference_create_symbolic_f(out IntPtr reference, RepositorySafeHandle repo, string name, string target);
97+
public static extern int git_reference_create_symbolic(out IntPtr reference, RepositorySafeHandle repo, string name, string target, bool force);
10798

10899
[DllImport(libgit2)]
109100
public static extern int git_reference_delete(IntPtr reference);
@@ -118,10 +109,7 @@ internal static class NativeMethods
118109
public static extern IntPtr git_reference_oid(IntPtr reference);
119110

120111
[DllImport(libgit2)]
121-
public static extern int git_reference_rename(IntPtr reference, string newName);
122-
123-
[DllImport(libgit2)]
124-
public static extern int git_reference_rename_f(IntPtr reference, string newName);
112+
public static extern int git_reference_rename(IntPtr reference, string newName, bool force);
125113

126114
[DllImport(libgit2)]
127115
public static extern int git_reference_resolve(out IntPtr resolvedReference, IntPtr reference);
@@ -196,10 +184,7 @@ public static extern int git_repository_discover(StringBuilder repository_path,
196184
public static extern IntPtr git_signature_new(string name, string email, long time, int offset);
197185

198186
[DllImport(libgit2)]
199-
public static extern int git_tag_create(out GitOid oid, RepositorySafeHandle repo, string name, ref GitOid target, GitObjectType type, GitSignature signature, string message);
200-
201-
[DllImport(libgit2)]
202-
public static extern int git_tag_create_f(out GitOid oid, RepositorySafeHandle repo, string name, ref GitOid target, GitObjectType type, GitSignature signature, string message);
187+
public static extern int git_tag_create(out GitOid oid, RepositorySafeHandle repo, string name, IntPtr target, GitSignature signature, string message, bool force);
203188

204189
[DllImport(libgit2)]
205190
public static extern int git_tag_delete(RepositorySafeHandle repo, string tagName);

LibGit2Sharp/Core/ObjectSafeWrapper.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ namespace LibGit2Sharp.Core
44
{
55
internal class ObjectSafeWrapper : IDisposable
66
{
7-
private IntPtr objectPtr;
7+
private IntPtr objectPtr = IntPtr.Zero;
88

99
public ObjectSafeWrapper(ObjectId id, Repository repo)
1010
{
11+
if (id == null)
12+
{
13+
return;
14+
}
15+
1116
var oid = id.Oid;
1217
var res = NativeMethods.git_object_lookup(out objectPtr, repo.Handle, ref oid, GitObjectType.Any);
1318
Ensure.Success(res);

LibGit2Sharp/ReferenceCollection.cs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,7 @@ public Reference Create(string name, string target, bool allowOverwrite = false)
9191

9292
private int CreateSymbolicReference(string name, string target, bool allowOverwrite, out IntPtr reference)
9393
{
94-
if (allowOverwrite)
95-
{
96-
return NativeMethods.git_reference_create_symbolic_f(out reference, repo.Handle, name, target);
97-
}
98-
99-
return NativeMethods.git_reference_create_symbolic(out reference, repo.Handle, name, target);
94+
return NativeMethods.git_reference_create_symbolic(out reference, repo.Handle, name, target, allowOverwrite);
10095
}
10196

10297
private int CreateDirectReference(string name, ObjectId targetOid, bool allowOverwrite, out IntPtr reference)
@@ -109,16 +104,11 @@ private int CreateDirectReference(string name, ObjectId targetOid, bool allowOve
109104
Ensure.Success((int) GitErrorCode.GIT_ENOTFOUND);
110105
}
111106
targetOid = obj.Id;
112-
}
113-
114-
GitOid oid = targetOid.Oid;
115-
116-
if (allowOverwrite)
117-
{
118-
return NativeMethods.git_reference_create_oid_f(out reference, repo.Handle, name, ref oid);
119107
}
120108

121-
return NativeMethods.git_reference_create_oid(out reference, repo.Handle, name, ref oid);
109+
GitOid oid = targetOid.Oid;
110+
111+
return NativeMethods.git_reference_create_oid(out reference, repo.Handle, name, ref oid, allowOverwrite);
122112
}
123113

124114
/// <summary>
@@ -148,17 +138,8 @@ public Reference Move(string currentName, string newName, bool allowOverwrite =
148138
Ensure.ArgumentNotNullOrEmptyString(newName, "newName");
149139

150140
IntPtr referencePtr = RetrieveReferencePtr(currentName);
151-
int res;
152-
153-
if (allowOverwrite)
154-
{
155-
res = NativeMethods.git_reference_rename_f(referencePtr, newName);
156-
}
157-
else
158-
{
159-
res = NativeMethods.git_reference_rename(referencePtr, newName);
160-
}
161-
141+
142+
int res = NativeMethods.git_reference_rename(referencePtr, newName, allowOverwrite);
162143
Ensure.Success(res);
163144

164145
return Reference.BuildFromPtr<Reference>(referencePtr, repo);

LibGit2Sharp/Repository.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,9 @@ public static string Init(string path, bool isBare = false)
179179
string normalizedPath = NativeMethods.git_repository_path(repo, GitRepositoryPathId.GIT_REPO_PATH).MarshallAsString();
180180
repo.Dispose();
181181

182-
if (!isBare)
183-
{
184-
HideGitFolder(normalizedPath);
185-
}
186-
187182
return PosixPathHelper.ToNative(normalizedPath);
188183
}
189184

190-
private static void HideGitFolder(string gitDirPath)
191-
{
192-
//TODO: Push this down into libgit2
193-
File.SetAttributes(gitDirPath, File.GetAttributes(gitDirPath) | FileAttributes.Hidden);
194-
}
195-
196185
/// <summary>
197186
/// Try to lookup an object by its <see cref = "ObjectId" /> and <see cref = "GitObjectType" />. If no matching object is found, null will be returned.
198187
/// </summary>

LibGit2Sharp/RepositoryInformation.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ public bool IsEmpty
4949
{
5050
get
5151
{
52-
//TODO: Remove this once git_repository_is_empty() accepts detached head state
53-
if (repo.Refs["HEAD"] is DirectReference)
54-
{
55-
return false;
56-
}
57-
5852
var res = NativeMethods.git_repository_is_empty(repo.Handle);
5953
Ensure.Success(res, true);
6054

LibGit2Sharp/TagCollection.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,11 @@ public Tag Create(string name, string target, Signature tagger, string message,
7878

7979
GitObject objectToTag = RetrieveObjectToTag(target);
8080

81-
var targetOid = objectToTag.Id.Oid;
82-
GitOid oid;
8381
int res;
84-
85-
if (allowOverwrite)
86-
{
87-
res = NativeMethods.git_tag_create_f(out oid, repo.Handle, name, ref targetOid, GitObject.TypeToTypeMap[objectToTag.GetType()], tagger.Handle, message);
88-
}
89-
else
82+
using (var objectPtr = new ObjectSafeWrapper(objectToTag.Id, repo))
9083
{
91-
res = NativeMethods.git_tag_create(out oid, repo.Handle, name, ref targetOid, GitObject.TypeToTypeMap[objectToTag.GetType()], tagger.Handle, message);
84+
GitOid oid;
85+
res = NativeMethods.git_tag_create(out oid, repo.Handle, name, objectPtr.ObjectPtr, tagger.Handle, message, allowOverwrite);
9286
}
9387

9488
Ensure.Success(res);

libgit2

Submodule libgit2 updated 161 files

0 commit comments

Comments
 (0)
0