diff --git a/Lib/NativeBinaries/amd64/git2.dll b/Lib/NativeBinaries/amd64/git2.dll index 542676413..71d8fa71b 100644 Binary files a/Lib/NativeBinaries/amd64/git2.dll and b/Lib/NativeBinaries/amd64/git2.dll differ diff --git a/Lib/NativeBinaries/amd64/git2.pdb b/Lib/NativeBinaries/amd64/git2.pdb index 7843c6029..3c9e58000 100644 Binary files a/Lib/NativeBinaries/amd64/git2.pdb and b/Lib/NativeBinaries/amd64/git2.pdb differ diff --git a/Lib/NativeBinaries/x86/git2.dll b/Lib/NativeBinaries/x86/git2.dll index bf2aab770..550e212af 100644 Binary files a/Lib/NativeBinaries/x86/git2.dll and b/Lib/NativeBinaries/x86/git2.dll differ diff --git a/Lib/NativeBinaries/x86/git2.pdb b/Lib/NativeBinaries/x86/git2.pdb index 38d9e1e0e..b621e816d 100644 Binary files a/Lib/NativeBinaries/x86/git2.pdb and b/Lib/NativeBinaries/x86/git2.pdb differ diff --git a/LibGit2Sharp.Tests/CloneFixture.cs b/LibGit2Sharp.Tests/CloneFixture.cs index 0f1350604..f5f005d19 100644 --- a/LibGit2Sharp.Tests/CloneFixture.cs +++ b/LibGit2Sharp.Tests/CloneFixture.cs @@ -103,7 +103,7 @@ public void CallsProgressCallbacks(string url) var scd = BuildSelfCleaningDirectory(); using (Repository repo = Repository.Clone(url, scd.RootedDirectoryPath, - onTransferProgress: (_) => transferWasCalled = true, + onTransferProgress: (_) => { transferWasCalled = true; return 0; }, onCheckoutProgress: (a, b, c) => checkoutWasCalled = true)) { Assert.True(transferWasCalled); diff --git a/LibGit2Sharp/Branch.cs b/LibGit2Sharp/Branch.cs index ff2992617..cb11c1d94 100644 --- a/LibGit2Sharp/Branch.cs +++ b/LibGit2Sharp/Branch.cs @@ -216,10 +216,7 @@ private string RemoteNameFromLocalBranch() private string RemoteNameFromRemoteTrackingBranch() { - using (ReferenceSafeHandle branchPtr = repo.Refs.RetrieveReferencePtr(CanonicalName)) - { - return Proxy.git_branch_remote_name(repo.Handle, branchPtr); - } + return Proxy.git_branch_remote_name(repo.Handle, CanonicalName); } /// diff --git a/LibGit2Sharp/BranchCollection.cs b/LibGit2Sharp/BranchCollection.cs index 462260635..82f329182 100644 --- a/LibGit2Sharp/BranchCollection.cs +++ b/LibGit2Sharp/BranchCollection.cs @@ -184,7 +184,9 @@ public virtual Branch Move(Branch branch, string newName, bool allowOverwrite = using (ReferenceSafeHandle referencePtr = repo.Refs.RetrieveReferencePtr("refs/heads/" + branch.Name)) { - Proxy.git_branch_move(referencePtr, newName, allowOverwrite); + using (ReferenceSafeHandle ref_out = Proxy.git_branch_move(referencePtr, newName, allowOverwrite)) + { + } } return this[newName]; diff --git a/LibGit2Sharp/BranchUpdater.cs b/LibGit2Sharp/BranchUpdater.cs index 3eb034582..fd834b90e 100644 --- a/LibGit2Sharp/BranchUpdater.cs +++ b/LibGit2Sharp/BranchUpdater.cs @@ -108,10 +108,7 @@ private void GetUpstreamInformation(string canonicalName, out string remoteName, } else if (canonicalName.StartsWith(remotePrefix, StringComparison.Ordinal)) { - using (ReferenceSafeHandle branchPtr = repo.Refs.RetrieveReferencePtr(canonicalName)) - { - remoteName = Proxy.git_branch_remote_name(repo.Handle, branchPtr); - } + remoteName = Proxy.git_branch_remote_name(repo.Handle, canonicalName); Remote remote = repo.Network.Remotes.RemoteForName(remoteName); using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repo.Handle, remote.Name, true)) diff --git a/LibGit2Sharp/Core/GitDiff.cs b/LibGit2Sharp/Core/GitDiff.cs index d5c60ecf9..b6b7ae8b2 100644 --- a/LibGit2Sharp/Core/GitDiff.cs +++ b/LibGit2Sharp/Core/GitDiff.cs @@ -193,12 +193,9 @@ public void Dispose() [Flags] internal enum GitDiffFileFlags { - GIT_DIFF_FILE_VALID_OID = (1 << 0), - GIT_DIFF_FILE_FREE_PATH = (1 << 1), - GIT_DIFF_FILE_BINARY = (1 << 2), - GIT_DIFF_FILE_NOT_BINARY = (1 << 3), - GIT_DIFF_FILE_FREE_DATA = (1 << 4), - GIT_DIFF_FILE_UNMAP_DATA = (1 << 5), + GIT_DIFF_FLAG_BINARY = (1 << 0), + GIT_DIFF_FLAG_NOT_BINARY = (1 << 1), + GIT_DIFF_FLAG_VALID_OID = (1 << 2), } [StructLayout(LayoutKind.Sequential)] @@ -218,7 +215,7 @@ internal class GitDiffDelta public GitDiffFile NewFile; public ChangeKind Status; public uint Similarity; - public int Binary; + public uint Flags; } [StructLayout(LayoutKind.Sequential)] diff --git a/LibGit2Sharp/Core/GitDiffExtensions.cs b/LibGit2Sharp/Core/GitDiffExtensions.cs index cdd00d2a0..ae2afaf95 100644 --- a/LibGit2Sharp/Core/GitDiffExtensions.cs +++ b/LibGit2Sharp/Core/GitDiffExtensions.cs @@ -7,8 +7,8 @@ internal static class GitDiffExtensions public static bool IsBinary(this GitDiffDelta delta) { //TODO Fix the interop issue on amd64 and use GitDiffDelta.Binary - return delta.OldFile.Flags.HasFlag(GitDiffFileFlags.GIT_DIFF_FILE_BINARY) - || delta.NewFile.Flags.HasFlag(GitDiffFileFlags.GIT_DIFF_FILE_BINARY); + return delta.OldFile.Flags.HasFlag(GitDiffFileFlags.GIT_DIFF_FLAG_BINARY) + || delta.NewFile.Flags.HasFlag(GitDiffFileFlags.GIT_DIFF_FLAG_BINARY); } } } diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 18d30e772..a8650829e 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -137,6 +137,7 @@ internal static extern int git_branch_foreach( [DllImport(libgit2)] internal static extern int git_branch_move( + out ReferenceSafeHandle ref_out, ReferenceSafeHandle reference, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string new_branch_name, [MarshalAs(UnmanagedType.Bool)] bool force); @@ -146,7 +147,7 @@ internal static extern int git_branch_remote_name( byte[] remote_name_out, UIntPtr buffer_size, RepositorySafeHandle repo, - ReferenceSafeHandle branch); + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string canonical_branch_name); [DllImport(libgit2)] internal static extern int git_branch_tracking_name( @@ -648,6 +649,7 @@ internal static extern int git_reference_lookup( [DllImport(libgit2)] internal static extern int git_reference_rename( + out ReferenceSafeHandle ref_out, ReferenceSafeHandle reference, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string newName, [MarshalAs(UnmanagedType.Bool)] bool force); @@ -656,10 +658,11 @@ internal static extern int git_reference_rename( internal static extern int git_reference_resolve(out ReferenceSafeHandle resolvedReference, ReferenceSafeHandle reference); [DllImport(libgit2)] - internal static extern int git_reference_set_target(ReferenceSafeHandle reference, ref GitOid id); + internal static extern int git_reference_set_target(out ReferenceSafeHandle ref_out, ReferenceSafeHandle reference, ref GitOid id); [DllImport(libgit2)] internal static extern int git_reference_symbolic_set_target( + out ReferenceSafeHandle ref_out, ReferenceSafeHandle reference, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string target); @@ -986,7 +989,7 @@ internal static extern int git_tag_delete( [DllImport(libgit2)] internal static extern void git_threads_shutdown(); - internal delegate void git_transfer_progress_callback(ref GitTransferProgress stats, IntPtr payload); + internal delegate int git_transfer_progress_callback(ref GitTransferProgress stats, IntPtr payload); [DllImport(libgit2)] internal static extern uint git_tree_entry_filemode(SafeHandle entry); diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs index 89e53cb80..6b8a7c41a 100644 --- a/LibGit2Sharp/Core/Proxy.cs +++ b/LibGit2Sharp/Core/Proxy.cs @@ -135,25 +135,27 @@ public static ICollection git_branch_foreach( return git_foreach(resultSelector, c => NativeMethods.git_branch_foreach(repo, branch_type, (x, y, p) => c(x, y, p), IntPtr.Zero)); } - public static void git_branch_move(ReferenceSafeHandle reference, string new_branch_name, bool force) + public static ReferenceSafeHandle git_branch_move(ReferenceSafeHandle reference, string new_branch_name, bool force) { using (ThreadAffinity()) { - int res = NativeMethods.git_branch_move(reference, new_branch_name, force); + ReferenceSafeHandle ref_out; + int res = NativeMethods.git_branch_move(out ref_out, reference, new_branch_name, force); Ensure.ZeroResult(res); + return ref_out; } } - public static string git_branch_remote_name(RepositorySafeHandle repo, ReferenceSafeHandle branch) + public static string git_branch_remote_name(RepositorySafeHandle repo, string canonical_branch_name) { using (ThreadAffinity()) { - int bufSize = NativeMethods.git_branch_remote_name(null, UIntPtr.Zero, repo, branch); + int bufSize = NativeMethods.git_branch_remote_name(null, UIntPtr.Zero, repo, canonical_branch_name); Ensure.Int32Result(bufSize); var buffer = new byte[bufSize]; - int res = NativeMethods.git_branch_remote_name(buffer, (UIntPtr)buffer.Length, repo, branch); + int res = NativeMethods.git_branch_remote_name(buffer, (UIntPtr)buffer.Length, repo, canonical_branch_name); Ensure.Int32Result(res); return Utf8Marshaler.Utf8FromBuffer(buffer) ?? string.Empty; @@ -1124,8 +1126,6 @@ public static void git_reference_delete(ReferenceSafeHandle reference) using (ThreadAffinity()) { int res = NativeMethods.git_reference_delete(reference); - reference.SetHandleAsInvalid(); - Ensure.ZeroResult(res); } } @@ -1192,12 +1192,16 @@ public static ObjectId git_reference_oid(ReferenceSafeHandle reference) return NativeMethods.git_reference_target(reference).MarshalAsObjectId(); } - public static void git_reference_rename(ReferenceSafeHandle reference, string newName, bool allowOverwrite) + public static ReferenceSafeHandle git_reference_rename(ReferenceSafeHandle reference, string newName, bool allowOverwrite) { using (ThreadAffinity()) { - int res = NativeMethods.git_reference_rename(reference, newName, allowOverwrite); + ReferenceSafeHandle ref_out; + + int res = NativeMethods.git_reference_rename(out ref_out, reference, newName, allowOverwrite); Ensure.ZeroResult(res); + + return ref_out; } } @@ -1219,22 +1223,30 @@ public static ReferenceSafeHandle git_reference_resolve(ReferenceSafeHandle refe } } - public static void git_reference_set_oid(ReferenceSafeHandle reference, ObjectId id) + public static ReferenceSafeHandle git_reference_set_target(ReferenceSafeHandle reference, ObjectId id) { using (ThreadAffinity()) { GitOid oid = id.Oid; - int res = NativeMethods.git_reference_set_target(reference, ref oid); + ReferenceSafeHandle ref_out; + + int res = NativeMethods.git_reference_set_target(out ref_out, reference, ref oid); Ensure.ZeroResult(res); + + return ref_out; } } - public static void git_reference_set_target(ReferenceSafeHandle reference, string target) + public static ReferenceSafeHandle git_reference_symbolic_set_target(ReferenceSafeHandle reference, string target) { using (ThreadAffinity()) { - int res = NativeMethods.git_reference_symbolic_set_target(reference, target); + ReferenceSafeHandle ref_out; + + int res = NativeMethods.git_reference_symbolic_set_target(out ref_out, reference, target); Ensure.ZeroResult(res); + + return ref_out; } } diff --git a/LibGit2Sharp/Diff.cs b/LibGit2Sharp/Diff.cs index 279eb6b21..a80e99bd5 100644 --- a/LibGit2Sharp/Diff.cs +++ b/LibGit2Sharp/Diff.cs @@ -23,6 +23,7 @@ private GitDiffOptions BuildOptions(DiffOptions diffOptions, IEnumerable var options = new GitDiffOptions(); options.Flags |= GitDiffOptionFlags.GIT_DIFF_INCLUDE_TYPECHANGE; + options.ContextLines = 3; if (diffOptions.HasFlag(DiffOptions.IncludeUntracked)) { diff --git a/LibGit2Sharp/Handlers.cs b/LibGit2Sharp/Handlers.cs index 60eb11793..96b64b9f2 100644 --- a/LibGit2Sharp/Handlers.cs +++ b/LibGit2Sharp/Handlers.cs @@ -30,7 +30,8 @@ /// Delegate definition for transfer progress callback. /// /// The object containing progress information. - public delegate void TransferProgressHandler(TransferProgress progress); + /// Return negative integer to cancel. + public delegate int TransferProgressHandler(TransferProgress progress); /// /// Delegate definition to handle reporting errors when updating references on the remote. diff --git a/LibGit2Sharp/ReferenceCollection.cs b/LibGit2Sharp/ReferenceCollection.cs index 672aec972..8b2f8b056 100644 --- a/LibGit2Sharp/ReferenceCollection.cs +++ b/LibGit2Sharp/ReferenceCollection.cs @@ -153,9 +153,10 @@ public virtual Reference Move(Reference reference, string newName, bool allowOve using (ReferenceSafeHandle handle = RetrieveReferencePtr(reference.CanonicalName)) { - Proxy.git_reference_rename(handle, newName, allowOverwrite); - - return Reference.BuildFromPtr(handle, repo); + using (ReferenceSafeHandle handle_out = Proxy.git_reference_rename(handle, newName, allowOverwrite)) + { + return Reference.BuildFromPtr(handle_out, repo); + } } } @@ -181,7 +182,7 @@ public virtual Reference UpdateTarget(Reference directRef, ObjectId targetId) Ensure.ArgumentNotNull(targetId, "targetId"); return UpdateTarget(directRef, targetId, - (h, id) => Proxy.git_reference_set_oid(h, id)); + (h, id) => Proxy.git_reference_set_target(h, id)); } /// @@ -196,10 +197,10 @@ public virtual Reference UpdateTarget(Reference symbolicRef, Reference targetRef Ensure.ArgumentNotNull(targetRef, "targetRef"); return UpdateTarget(symbolicRef, targetRef, - (h, r) => Proxy.git_reference_set_target(h, r.CanonicalName)); + (h, r) => Proxy.git_reference_symbolic_set_target(h, r.CanonicalName)); } - private Reference UpdateTarget(Reference reference, T target, Action setter) + private Reference UpdateTarget(Reference reference, T target, Func setter) { if (reference.CanonicalName == "HEAD") { @@ -219,8 +220,10 @@ private Reference UpdateTarget(Reference reference, T target, Action(referencePtr, repo); + using (ReferenceSafeHandle ref_out = setter(referencePtr, target)) + { + return Reference.BuildFromPtr(ref_out, repo); + } } } diff --git a/LibGit2Sharp/TransferCallbacks.cs b/LibGit2Sharp/TransferCallbacks.cs index d094dd0d2..311870629 100644 --- a/LibGit2Sharp/TransferCallbacks.cs +++ b/LibGit2Sharp/TransferCallbacks.cs @@ -46,9 +46,10 @@ internal static NativeMethods.git_transfer_progress_callback GenerateCallback(Tr /// /// structure containing progress information. /// Payload data. - private void OnGitTransferProgress(ref GitTransferProgress progress, IntPtr payload) + /// the result of the wrapped + private int OnGitTransferProgress(ref GitTransferProgress progress, IntPtr payload) { - onTransferProgress(new TransferProgress(progress)); + return onTransferProgress(new TransferProgress(progress)); } } } diff --git a/LibGit2Sharp/libgit2_hash.txt b/LibGit2Sharp/libgit2_hash.txt index 9e5aa9d2e..3df82b31a 100644 --- a/LibGit2Sharp/libgit2_hash.txt +++ b/LibGit2Sharp/libgit2_hash.txt @@ -1 +1 @@ -40a605104c2060c2bc5a08dfb62cafe473baeb21 +eef7e80e68a530f8ce1d1ec196d41fc33a1ced6e diff --git a/libgit2 b/libgit2 index 40a605104..eef7e80e6 160000 --- a/libgit2 +++ b/libgit2 @@ -1 +1 @@ -Subproject commit 40a605104c2060c2bc5a08dfb62cafe473baeb21 +Subproject commit eef7e80e68a530f8ce1d1ec196d41fc33a1ced6e