Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Lib/git2.dllbin235008 -> 253952 bytes
-rw-r--r--LibGit2Sharp.Tests/RepositoryFixture.cs10
-rw-r--r--LibGit2Sharp/CommitCollection.cs28
-rw-r--r--LibGit2Sharp/Core/NativeMethods.cs25
-rwxr-xr-xLibGit2Sharp/Core/ObjectSafeWrapper.cs7
-rw-r--r--LibGit2Sharp/ReferenceCollection.cs31
-rw-r--r--LibGit2Sharp/Repository.cs11
-rw-r--r--LibGit2Sharp/RepositoryInformation.cs6
-rw-r--r--LibGit2Sharp/TagCollection.cs12
m---------libgit20
10 files changed, 46 insertions, 84 deletions
diff --git a/Lib/git2.dll b/Lib/git2.dll
index cbe774b8..0e2378d9 100644
--- a/Lib/git2.dll
+++ b/Lib/git2.dll
Binary files differ
diff --git a/LibGit2Sharp.Tests/RepositoryFixture.cs b/LibGit2Sharp.Tests/RepositoryFixture.cs
index 277f32b8..b2649183 100644
--- a/LibGit2Sharp.Tests/RepositoryFixture.cs
+++ b/LibGit2Sharp.Tests/RepositoryFixture.cs
@@ -297,35 +297,35 @@ namespace LibGit2Sharp.Tests
public void CanDiscoverABareRepoGivenTheRepoPath()
{
string path = Repository.Discover(Constants.BareTestRepoPath);
- path.ShouldEqual(Path.GetFullPath(Constants.BareTestRepoPath));
+ path.ShouldEqual(Path.GetFullPath(Constants.BareTestRepoPath + Path.DirectorySeparatorChar));
}
[Test]
public void CanDiscoverABareRepoGivenASubDirectoryOfTheRepoPath()
{
string path = Repository.Discover(Path.Combine(Constants.BareTestRepoPath, "objects/4a"));
- path.ShouldEqual(Path.GetFullPath(Constants.BareTestRepoPath));
+ path.ShouldEqual(Path.GetFullPath(Constants.BareTestRepoPath + Path.DirectorySeparatorChar));
}
[Test]
public void CanDiscoverAStandardRepoGivenTheRepoPath()
{
string path = Repository.Discover(Constants.StandardTestRepoPath);
- path.ShouldEqual(Path.GetFullPath(Constants.StandardTestRepoPath));
+ path.ShouldEqual(Path.GetFullPath(Constants.StandardTestRepoPath + Path.DirectorySeparatorChar));
}
[Test]
public void CanDiscoverAStandardRepoGivenASubDirectoryOfTheRepoPath()
{
string path = Repository.Discover(Path.Combine(Constants.StandardTestRepoPath, "objects/4a"));
- path.ShouldEqual(Path.GetFullPath(Constants.StandardTestRepoPath));
+ path.ShouldEqual(Path.GetFullPath(Constants.StandardTestRepoPath + Path.DirectorySeparatorChar));
}
[Test]
public void CanDiscoverAStandardRepoGivenTheWorkingDirPath()
{
string path = Repository.Discover(Constants.StandardTestRepoWorkingDirPath);
- path.ShouldEqual(Path.GetFullPath(Constants.StandardTestRepoPath));
+ path.ShouldEqual(Path.GetFullPath(Constants.StandardTestRepoPath + Path.DirectorySeparatorChar));
}
}
} \ No newline at end of file
diff --git a/LibGit2Sharp/CommitCollection.cs b/LibGit2Sharp/CommitCollection.cs
index b1799232..480a2cc0 100644
--- a/LibGit2Sharp/CommitCollection.cs
+++ b/LibGit2Sharp/CommitCollection.cs
@@ -110,26 +110,40 @@ namespace LibGit2Sharp
Ensure.Success(res);
Reference head = repo.Refs["HEAD"];
- GitOid[] gitOids = RetrieveCommitParent(head);
GitOid commitOid;
- res = NativeMethods.git_commit_create(out commitOid, repo.Handle, head.CanonicalName, author.Handle,
- committer.Handle, message, ref treeOid, gitOids.Count(), ref gitOids);
+ using (var treePtr = new ObjectSafeWrapper(new ObjectId(treeOid), repo))
+ using (var headPtr = RetrieveHeadCommitPtr(head))
+ {
+ var parentPtrs = BuildArrayFrom(headPtr);
+ res = NativeMethods.git_commit_create(out commitOid, repo.Handle, head.CanonicalName, author.Handle,
+ committer.Handle, message, treePtr.ObjectPtr, parentPtrs.Count(), parentPtrs);
+ }
Ensure.Success(res);
return repo.Lookup<Commit>(new ObjectId(commitOid));
}
- private static GitOid[] RetrieveCommitParent(Reference head)
+ private static IntPtr[] BuildArrayFrom(ObjectSafeWrapper headPtr)
{
+ if (headPtr.ObjectPtr == IntPtr.Zero)
+ {
+ return new IntPtr[]{};
+ }
+
+ return new IntPtr[]{headPtr.ObjectPtr};
+ }
+
+ private ObjectSafeWrapper RetrieveHeadCommitPtr(Reference head)
+ {
+
DirectReference oidRef = head.ResolveToDirectReference();
if (oidRef == null)
{
- return new GitOid[] { };
+ return new ObjectSafeWrapper(null, repo);
}
- var headCommitId = new ObjectId(oidRef.TargetIdentifier);
- return new[] { headCommitId.Oid };
+ return new ObjectSafeWrapper(new ObjectId(oidRef.TargetIdentifier), repo);
}
private class CommitEnumerator : IEnumerator<Commit>
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index 2103ec20..f1ff2f45 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -21,10 +21,7 @@ namespace LibGit2Sharp.Core
public static extern IntPtr git_commit_committer(IntPtr commit);
[DllImport(libgit2)]
- 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);
-
- [DllImport(libgit2)]
- 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);
+ 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);
[DllImport(libgit2)]
public static extern IntPtr git_commit_message(IntPtr commit);
@@ -94,16 +91,10 @@ namespace LibGit2Sharp.Core
public static extern int git_oid_cmp(ref GitOid a, ref GitOid b);
[DllImport(libgit2)]
- public static extern int git_reference_create_oid(out IntPtr reference, RepositorySafeHandle repo, string name, ref GitOid oid);
-
- [DllImport(libgit2)]
- public static extern int git_reference_create_oid_f(out IntPtr reference, RepositorySafeHandle repo, string name, ref GitOid oid);
-
- [DllImport(libgit2)]
- public static extern int git_reference_create_symbolic(out IntPtr reference, RepositorySafeHandle repo, string name, string target);
+ public static extern int git_reference_create_oid(out IntPtr reference, RepositorySafeHandle repo, string name, ref GitOid oid, bool force);
[DllImport(libgit2)]
- public static extern int git_reference_create_symbolic_f(out IntPtr reference, RepositorySafeHandle repo, string name, string target);
+ public static extern int git_reference_create_symbolic(out IntPtr reference, RepositorySafeHandle repo, string name, string target, bool force);
[DllImport(libgit2)]
public static extern int git_reference_delete(IntPtr reference);
@@ -118,10 +109,7 @@ namespace LibGit2Sharp.Core
public static extern IntPtr git_reference_oid(IntPtr reference);
[DllImport(libgit2)]
- public static extern int git_reference_rename(IntPtr reference, string newName);
-
- [DllImport(libgit2)]
- public static extern int git_reference_rename_f(IntPtr reference, string newName);
+ public static extern int git_reference_rename(IntPtr reference, string newName, bool force);
[DllImport(libgit2)]
public static extern int git_reference_resolve(out IntPtr resolvedReference, IntPtr reference);
@@ -196,10 +184,7 @@ namespace LibGit2Sharp.Core
public static extern IntPtr git_signature_new(string name, string email, long time, int offset);
[DllImport(libgit2)]
- public static extern int git_tag_create(out GitOid oid, RepositorySafeHandle repo, string name, ref GitOid target, GitObjectType type, GitSignature signature, string message);
-
- [DllImport(libgit2)]
- public static extern int git_tag_create_f(out GitOid oid, RepositorySafeHandle repo, string name, ref GitOid target, GitObjectType type, GitSignature signature, string message);
+ public static extern int git_tag_create(out GitOid oid, RepositorySafeHandle repo, string name, IntPtr target, GitSignature signature, string message, bool force);
[DllImport(libgit2)]
public static extern int git_tag_delete(RepositorySafeHandle repo, string tagName);
diff --git a/LibGit2Sharp/Core/ObjectSafeWrapper.cs b/LibGit2Sharp/Core/ObjectSafeWrapper.cs
index 078a7e0e..c254612e 100755
--- a/LibGit2Sharp/Core/ObjectSafeWrapper.cs
+++ b/LibGit2Sharp/Core/ObjectSafeWrapper.cs
@@ -4,10 +4,15 @@ namespace LibGit2Sharp.Core
{
internal class ObjectSafeWrapper : IDisposable
{
- private IntPtr objectPtr;
+ private IntPtr objectPtr = IntPtr.Zero;
public ObjectSafeWrapper(ObjectId id, Repository repo)
{
+ if (id == null)
+ {
+ return;
+ }
+
var oid = id.Oid;
var res = NativeMethods.git_object_lookup(out objectPtr, repo.Handle, ref oid, GitObjectType.Any);
Ensure.Success(res);
diff --git a/LibGit2Sharp/ReferenceCollection.cs b/LibGit2Sharp/ReferenceCollection.cs
index 1fa74832..0d103ae8 100644
--- a/LibGit2Sharp/ReferenceCollection.cs
+++ b/LibGit2Sharp/ReferenceCollection.cs
@@ -91,12 +91,7 @@ namespace LibGit2Sharp
private int CreateSymbolicReference(string name, string target, bool allowOverwrite, out IntPtr reference)
{
- if (allowOverwrite)
- {
- return NativeMethods.git_reference_create_symbolic_f(out reference, repo.Handle, name, target);
- }
-
- return NativeMethods.git_reference_create_symbolic(out reference, repo.Handle, name, target);
+ return NativeMethods.git_reference_create_symbolic(out reference, repo.Handle, name, target, allowOverwrite);
}
private int CreateDirectReference(string name, ObjectId targetOid, bool allowOverwrite, out IntPtr reference)
@@ -109,16 +104,11 @@ namespace LibGit2Sharp
Ensure.Success((int) GitErrorCode.GIT_ENOTFOUND);
}
targetOid = obj.Id;
- }
-
- GitOid oid = targetOid.Oid;
-
- if (allowOverwrite)
- {
- return NativeMethods.git_reference_create_oid_f(out reference, repo.Handle, name, ref oid);
}
- return NativeMethods.git_reference_create_oid(out reference, repo.Handle, name, ref oid);
+ GitOid oid = targetOid.Oid;
+
+ return NativeMethods.git_reference_create_oid(out reference, repo.Handle, name, ref oid, allowOverwrite);
}
/// <summary>
@@ -148,17 +138,8 @@ namespace LibGit2Sharp
Ensure.ArgumentNotNullOrEmptyString(newName, "newName");
IntPtr referencePtr = RetrieveReferencePtr(currentName);
- int res;
-
- if (allowOverwrite)
- {
- res = NativeMethods.git_reference_rename_f(referencePtr, newName);
- }
- else
- {
- res = NativeMethods.git_reference_rename(referencePtr, newName);
- }
-
+
+ int res = NativeMethods.git_reference_rename(referencePtr, newName, allowOverwrite);
Ensure.Success(res);
return Reference.BuildFromPtr<Reference>(referencePtr, repo);
diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs
index 25cf1d53..568c43c4 100644
--- a/LibGit2Sharp/Repository.cs
+++ b/LibGit2Sharp/Repository.cs
@@ -179,20 +179,9 @@ namespace LibGit2Sharp
string normalizedPath = NativeMethods.git_repository_path(repo, GitRepositoryPathId.GIT_REPO_PATH).MarshallAsString();
repo.Dispose();
- if (!isBare)
- {
- HideGitFolder(normalizedPath);
- }
-
return PosixPathHelper.ToNative(normalizedPath);
}
- private static void HideGitFolder(string gitDirPath)
- {
- //TODO: Push this down into libgit2
- File.SetAttributes(gitDirPath, File.GetAttributes(gitDirPath) | FileAttributes.Hidden);
- }
-
/// <summary>
/// Try to lookup an object by its <see cref = "ObjectId" /> and <see cref = "GitObjectType" />. If no matching object is found, null will be returned.
/// </summary>
diff --git a/LibGit2Sharp/RepositoryInformation.cs b/LibGit2Sharp/RepositoryInformation.cs
index 2be3d62d..c77c1ca9 100644
--- a/LibGit2Sharp/RepositoryInformation.cs
+++ b/LibGit2Sharp/RepositoryInformation.cs
@@ -49,12 +49,6 @@ namespace LibGit2Sharp
{
get
{
- //TODO: Remove this once git_repository_is_empty() accepts detached head state
- if (repo.Refs["HEAD"] is DirectReference)
- {
- return false;
- }
-
var res = NativeMethods.git_repository_is_empty(repo.Handle);
Ensure.Success(res, true);
diff --git a/LibGit2Sharp/TagCollection.cs b/LibGit2Sharp/TagCollection.cs
index 0baeec64..e392792d 100644
--- a/LibGit2Sharp/TagCollection.cs
+++ b/LibGit2Sharp/TagCollection.cs
@@ -78,17 +78,11 @@ namespace LibGit2Sharp
GitObject objectToTag = RetrieveObjectToTag(target);
- var targetOid = objectToTag.Id.Oid;
- GitOid oid;
int res;
-
- if (allowOverwrite)
- {
- res = NativeMethods.git_tag_create_f(out oid, repo.Handle, name, ref targetOid, GitObject.TypeToTypeMap[objectToTag.GetType()], tagger.Handle, message);
- }
- else
+ using (var objectPtr = new ObjectSafeWrapper(objectToTag.Id, repo))
{
- res = NativeMethods.git_tag_create(out oid, repo.Handle, name, ref targetOid, GitObject.TypeToTypeMap[objectToTag.GetType()], tagger.Handle, message);
+ GitOid oid;
+ res = NativeMethods.git_tag_create(out oid, repo.Handle, name, objectPtr.ObjectPtr, tagger.Handle, message, allowOverwrite);
}
Ensure.Success(res);
diff --git a/libgit2 b/libgit2
-Subproject 2a406ab51c33059f49a5a9105be07b3a1f8210f
+Subproject 33afca47cbacd0ad6fe4115f29f3e7b58428bc7