diff --git a/Lib/NativeBinaries/amd64/git2-11f8336.dll b/Lib/NativeBinaries/amd64/git2-11f8336.dll deleted file mode 100644 index d06ebea12..000000000 Binary files a/Lib/NativeBinaries/amd64/git2-11f8336.dll and /dev/null differ diff --git a/Lib/NativeBinaries/amd64/git2-11f8336.pdb b/Lib/NativeBinaries/amd64/git2-11f8336.pdb deleted file mode 100644 index 34989493f..000000000 Binary files a/Lib/NativeBinaries/amd64/git2-11f8336.pdb and /dev/null differ diff --git a/Lib/NativeBinaries/amd64/git2-146b4d1.dll b/Lib/NativeBinaries/amd64/git2-146b4d1.dll new file mode 100644 index 000000000..8bb661de0 Binary files /dev/null and b/Lib/NativeBinaries/amd64/git2-146b4d1.dll differ diff --git a/Lib/NativeBinaries/amd64/git2-146b4d1.pdb b/Lib/NativeBinaries/amd64/git2-146b4d1.pdb new file mode 100644 index 000000000..8d71a2311 Binary files /dev/null and b/Lib/NativeBinaries/amd64/git2-146b4d1.pdb differ diff --git a/Lib/NativeBinaries/x86/git2-11f8336.dll b/Lib/NativeBinaries/x86/git2-11f8336.dll deleted file mode 100644 index 7d66ec112..000000000 Binary files a/Lib/NativeBinaries/x86/git2-11f8336.dll and /dev/null differ diff --git a/Lib/NativeBinaries/x86/git2-11f8336.pdb b/Lib/NativeBinaries/x86/git2-11f8336.pdb deleted file mode 100644 index def46eba0..000000000 Binary files a/Lib/NativeBinaries/x86/git2-11f8336.pdb and /dev/null differ diff --git a/Lib/NativeBinaries/x86/git2-146b4d1.dll b/Lib/NativeBinaries/x86/git2-146b4d1.dll new file mode 100644 index 000000000..841686829 Binary files /dev/null and b/Lib/NativeBinaries/x86/git2-146b4d1.dll differ diff --git a/Lib/NativeBinaries/x86/git2-146b4d1.pdb b/Lib/NativeBinaries/x86/git2-146b4d1.pdb new file mode 100644 index 000000000..4fd5f9165 Binary files /dev/null and b/Lib/NativeBinaries/x86/git2-146b4d1.pdb differ diff --git a/LibGit2Sharp/Core/GitCloneOptions.cs b/LibGit2Sharp/Core/GitCloneOptions.cs index 5382b60a2..669d15d21 100644 --- a/LibGit2Sharp/Core/GitCloneOptions.cs +++ b/LibGit2Sharp/Core/GitCloneOptions.cs @@ -9,21 +9,12 @@ internal class GitCloneOptions public uint Version = 1; public GitCheckoutOpts CheckoutOpts; - public IntPtr InitOptions; + public GitRemoteCallbacks RemoteCallbacks; + public int Bare; - public NativeMethods.git_transfer_progress_callback TransferProgressCallback; - public IntPtr TransferProgressPayload; + public int IgnoreCertErrors; public IntPtr RemoteName; - public IntPtr PushUrl; - public IntPtr FetchSpec; - public IntPtr PushSpec; - - public NativeMethods.git_cred_acquire_cb CredAcquireCallback; - public IntPtr CredAcquirePayload; - - public IntPtr Transport; - public GitRemoteCallbacks RemoteCallbacks; - public int RemoteAutotag; + public IntPtr CheckoutBranch; } } diff --git a/LibGit2Sharp/Core/GitRemoteCallbacks.cs b/LibGit2Sharp/Core/GitRemoteCallbacks.cs index b1b2f7bcc..7903f567a 100644 --- a/LibGit2Sharp/Core/GitRemoteCallbacks.cs +++ b/LibGit2Sharp/Core/GitRemoteCallbacks.cs @@ -15,6 +15,10 @@ internal struct GitRemoteCallbacks internal NativeMethods.remote_completion_callback completion; + internal NativeMethods.git_cred_acquire_cb acquire_credentials; + + internal NativeMethods.git_transfer_progress_callback download_progress; + internal NativeMethods.remote_update_tips_callback update_tips; internal IntPtr payload; diff --git a/LibGit2Sharp/Core/NativeDllName.cs b/LibGit2Sharp/Core/NativeDllName.cs index 03663892b..cb0ee457f 100644 --- a/LibGit2Sharp/Core/NativeDllName.cs +++ b/LibGit2Sharp/Core/NativeDllName.cs @@ -2,6 +2,6 @@ namespace LibGit2Sharp.Core { internal static class NativeDllName { - public const string Name = "git2-11f8336"; + public const string Name = "git2-146b4d1"; } } diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 9fc8ba878..dc6417f3b 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -783,9 +783,7 @@ internal static extern int git_remote_create( [DllImport(libgit2)] internal static extern int git_remote_download( - RemoteSafeHandle remote, - git_transfer_progress_callback progress_cb, - IntPtr payload); + RemoteSafeHandle remote); [DllImport(libgit2)] internal static extern void git_remote_free(IntPtr remote); @@ -815,12 +813,6 @@ internal static extern int git_remote_load( [DllImport(libgit2)] internal static extern int git_remote_save(RemoteSafeHandle remote); - [DllImport(libgit2)] - internal static extern void git_remote_set_cred_acquire_cb( - RemoteSafeHandle remote, - git_cred_acquire_cb cred_acquire_cb, - IntPtr payload); - [DllImport(libgit2)] [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(Utf8NoCleanupMarshaler))] internal static extern string git_remote_url(RemoteSafeHandle remote); diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs index cf9dfe2b3..5f224e075 100644 --- a/LibGit2Sharp/Core/Proxy.cs +++ b/LibGit2Sharp/Core/Proxy.cs @@ -1406,13 +1406,11 @@ public static GitRefSpecHandle git_remote_get_refspec(RemoteSafeHandle remote, i return NativeMethods.git_remote_get_refspec(remote, (UIntPtr)n); } - public static void git_remote_download(RemoteSafeHandle remote, TransferProgressHandler onTransferProgress) + public static void git_remote_download(RemoteSafeHandle remote) { using (ThreadAffinity()) { - NativeMethods.git_transfer_progress_callback cb = TransferCallbacks.GenerateCallback(onTransferProgress); - - int res = NativeMethods.git_remote_download(remote, cb, IntPtr.Zero); + int res = NativeMethods.git_remote_download(remote); Ensure.ZeroResult(res); } } @@ -1505,11 +1503,6 @@ public static void git_remote_set_callbacks(RemoteSafeHandle remote, ref GitRemo } } - public static void git_remote_set_cred_acquire_cb(RemoteSafeHandle remote, NativeMethods.git_cred_acquire_cb cred_acquire_cb, IntPtr payload) - { - NativeMethods.git_remote_set_cred_acquire_cb(remote, cred_acquire_cb, payload); - } - public static void git_remote_update_tips(RemoteSafeHandle remote) { using (ThreadAffinity()) diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index d3cff3cc6..ecf13686f 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -192,7 +192,6 @@ - diff --git a/LibGit2Sharp/Network.cs b/LibGit2Sharp/Network.cs index c57c28ef9..6ff108603 100644 --- a/LibGit2Sharp/Network.cs +++ b/LibGit2Sharp/Network.cs @@ -111,14 +111,9 @@ public virtual void Fetch( { Ensure.ArgumentNotNull(remote, "remote"); - // We need to keep a reference to the git_cred_acquire_cb callback around - // so it will not be garbage collected before we are done with it. - // Note that we also have a GC.KeepAlive call at the end of the method. - NativeMethods.git_cred_acquire_cb credentialCallback = null; - using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { - var callbacks = new RemoteCallbacks(onProgress, onCompletion, onUpdateTips); + var callbacks = new RemoteCallbacks(onProgress, onTransferProgress, onCompletion, onUpdateTips, credentials); GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks(); if (tagFetchMode.HasValue) @@ -126,17 +121,6 @@ public virtual void Fetch( Proxy.git_remote_set_autotag(remoteHandle, tagFetchMode.Value); } - if (credentials != null) - { - credentialCallback = (out IntPtr cred, IntPtr url, IntPtr username_from_url, uint types, IntPtr payload) => - NativeMethods.git_cred_userpass_plaintext_new(out cred, credentials.Username, credentials.Password); - - Proxy.git_remote_set_cred_acquire_cb( - remoteHandle, - credentialCallback, - IntPtr.Zero); - } - // It is OK to pass the reference to the GitCallbacks directly here because libgit2 makes a copy of // the data in the git_remote_callbacks structure. If, in the future, libgit2 changes its implementation // to store a reference to the git_remote_callbacks structure this would introduce a subtle bug @@ -150,7 +134,7 @@ public virtual void Fetch( try { Proxy.git_remote_connect(remoteHandle, GitDirection.Fetch); - Proxy.git_remote_download(remoteHandle, onTransferProgress); + Proxy.git_remote_download(remoteHandle); Proxy.git_remote_update_tips(remoteHandle); } finally @@ -158,10 +142,6 @@ public virtual void Fetch( Proxy.git_remote_disconnect(remoteHandle); } } - - // To be safe, make sure the credential callback is kept until - // alive until at least this point. - GC.KeepAlive(credentialCallback); } /// @@ -222,11 +202,6 @@ public virtual void Push( Ensure.ArgumentNotNull(remote, "remote"); Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs"); - // We need to keep a reference to the git_cred_acquire_cb callback around - // so it will not be garbage collected before we are done with it. - // Note that we also have a GC.KeepAlive call at the end of the method. - NativeMethods.git_cred_acquire_cb credentialCallback = null; - // Return early if there is nothing to push. if (!pushRefSpecs.Any()) { @@ -238,16 +213,9 @@ public virtual void Push( // Load the remote. using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true)) { - if (credentials != null) - { - credentialCallback = (out IntPtr cred, IntPtr url, IntPtr username_from_url, uint types, IntPtr payload) => - NativeMethods.git_cred_userpass_plaintext_new(out cred, credentials.Username, credentials.Password); - - Proxy.git_remote_set_cred_acquire_cb( - remoteHandle, - credentialCallback, - IntPtr.Zero); - } + var callbacks = new RemoteCallbacks(null, null, null, null, credentials); + GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks(); + Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks); try { @@ -279,10 +247,6 @@ public virtual void Push( Proxy.git_remote_disconnect(remoteHandle); } } - - // To be safe, make sure the credential callback is kept - // alive until at least this point. - GC.KeepAlive(credentialCallback); } /// diff --git a/LibGit2Sharp/RemoteCallbacks.cs b/LibGit2Sharp/RemoteCallbacks.cs index 3427e634a..e00bd9afb 100644 --- a/LibGit2Sharp/RemoteCallbacks.cs +++ b/LibGit2Sharp/RemoteCallbacks.cs @@ -12,11 +12,18 @@ namespace LibGit2Sharp /// internal class RemoteCallbacks { - internal RemoteCallbacks(ProgressHandler onProgress = null, CompletionHandler onCompletion = null, UpdateTipsHandler onUpdateTips = null) + internal RemoteCallbacks( + ProgressHandler onProgress = null, + TransferProgressHandler onDownloadProgress = null, + CompletionHandler onCompletion = null, + UpdateTipsHandler onUpdateTips = null, + Credentials credentials = null) { Progress = onProgress; + DownloadTransferProgress = onDownloadProgress; Completion = onCompletion; UpdateTips = onUpdateTips; + Credentials = credentials; } #region Delegates @@ -36,8 +43,19 @@ internal RemoteCallbacks(ProgressHandler onProgress = null, CompletionHandler on /// private readonly CompletionHandler Completion; + /// + /// Managed delegate to be called in response to a git_transfer_progress_callback callback from libgit2. + /// This will in turn call the user provided delegate. + /// + private readonly TransferProgressHandler DownloadTransferProgress; + #endregion + /// + /// The credentials to use for the credential callback. + /// + Credentials Credentials; + internal GitRemoteCallbacks GenerateCallbacks() { var callbacks = new GitRemoteCallbacks {version = 1}; @@ -57,6 +75,16 @@ internal GitRemoteCallbacks GenerateCallbacks() callbacks.completion = GitCompletionHandler; } + if (Credentials != null) + { + callbacks.acquire_credentials = GitCredentialHandler; + } + + if (DownloadTransferProgress != null) + { + callbacks.download_progress = GitDownloadTransferProgressHandler; + } + return callbacks; } @@ -126,6 +154,29 @@ private int GitCompletionHandler(RemoteCompletionType remoteCompletionType, IntP return result; } + /// + /// The delegate with the signature that matches the native git_transfer_progress_callback function's signature. + /// + /// structure containing progress information. + /// Payload data. + /// the result of the wrapped + private int GitDownloadTransferProgressHandler(ref GitTransferProgress progress, IntPtr payload) + { + int result = 0; + + if (DownloadTransferProgress != null) + { + result = DownloadTransferProgress(new TransferProgress(progress)); + } + + return result; + } + + private int GitCredentialHandler(out IntPtr cred, IntPtr url, IntPtr username_from_url, uint types, IntPtr payload) + { + return NativeMethods.git_cred_userpass_plaintext_new(out cred, Credentials.Username, Credentials.Password); + } + #endregion } } diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index d9399302b..9835283ea 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -559,11 +559,13 @@ public static string Clone(string sourceUrl, string workdirPath, Credentials credentials = null) { CheckoutCallbacks checkoutCallbacks = CheckoutCallbacks.GenerateCheckoutCallbacks(onCheckoutProgress, null); + + var callbacks = new RemoteCallbacks(null, onTransferProgress, null, null, credentials); + GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks(); var cloneOpts = new GitCloneOptions { Bare = bare ? 1 : 0, - TransferProgressCallback = TransferCallbacks.GenerateCallback(onTransferProgress), CheckoutOpts = { version = 1, @@ -573,25 +575,15 @@ public static string Clone(string sourceUrl, string workdirPath, ? CheckoutStrategy.GIT_CHECKOUT_SAFE_CREATE : CheckoutStrategy.GIT_CHECKOUT_NONE }, + RemoteCallbacks = gitCallbacks, }; - if (credentials != null) - { - cloneOpts.CredAcquireCallback = - (out IntPtr cred, IntPtr url, IntPtr username_from_url, uint types, IntPtr payload) => - NativeMethods.git_cred_userpass_plaintext_new(out cred, credentials.Username, credentials.Password); - } - FilePath repoPath; using (RepositorySafeHandle repo = Proxy.git_clone(sourceUrl, workdirPath, cloneOpts)) { repoPath = Proxy.git_repository_path(repo); } - // To be safe, make sure the credential callback is kept until - // alive until at least this point. - GC.KeepAlive(cloneOpts.CredAcquireCallback); - return repoPath.Native; } diff --git a/LibGit2Sharp/TransferCallbacks.cs b/LibGit2Sharp/TransferCallbacks.cs deleted file mode 100644 index 46497ba6b..000000000 --- a/LibGit2Sharp/TransferCallbacks.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using LibGit2Sharp.Core; -using LibGit2Sharp.Handlers; - -namespace LibGit2Sharp -{ - /// - /// Class to handle the mapping between libgit2 git_transfer_progress_callback function and - /// a corresponding . Generates a delegate that - /// wraps the delegate with a delegate that matches - /// the git_transfer_progress_callback signature. - /// - internal class TransferCallbacks - { - /// - /// Managed delegate to be called in response to a git_transfer_progress_callback callback from libgit2. - /// - private readonly TransferProgressHandler onTransferProgress; - - /// - /// Constructor to set up the native callback given managed delegate. - /// - /// The delegate that the git_transfer_progress_callback will call. - private TransferCallbacks(TransferProgressHandler onTransferProgress) - { - this.onTransferProgress = onTransferProgress; - } - - /// - /// Generates a delegate that matches the native git_transfer_progress_callback function's signature and wraps the delegate. - /// - /// The delegate to call in responde to a the native git_transfer_progress_callback callback. - /// A delegate method with a signature that matches git_transfer_progress_callback. - internal static NativeMethods.git_transfer_progress_callback GenerateCallback(TransferProgressHandler onTransferProgress) - { - if (onTransferProgress == null) - { - return null; - } - - return new TransferCallbacks(onTransferProgress).OnGitTransferProgress; - } - - /// - /// The delegate with the signature that matches the native git_transfer_progress_callback function's signature. - /// - /// structure containing progress information. - /// Payload data. - /// the result of the wrapped - private int OnGitTransferProgress(ref GitTransferProgress progress, IntPtr payload) - { - return onTransferProgress(new TransferProgress(progress)); - } - } -} diff --git a/LibGit2Sharp/UnbornBranchException.cs b/LibGit2Sharp/UnbornBranchException.cs index 0ee5e4afa..5899321ea 100644 --- a/LibGit2Sharp/UnbornBranchException.cs +++ b/LibGit2Sharp/UnbornBranchException.cs @@ -11,7 +11,7 @@ namespace LibGit2Sharp public class UnbornBranchException : LibGit2SharpException { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public UnbornBranchException() { diff --git a/LibGit2Sharp/libgit2_hash.txt b/LibGit2Sharp/libgit2_hash.txt index f3f5d3a01..99c333af5 100644 --- a/LibGit2Sharp/libgit2_hash.txt +++ b/LibGit2Sharp/libgit2_hash.txt @@ -1 +1 @@ -11f8336ec93ea3a270c9fe80c4bbb68aa4729423 +146b4d1c5f98aa14df086503f996d131d40b92f8 diff --git a/libgit2 b/libgit2 index 11f8336ec..146b4d1c5 160000 --- a/libgit2 +++ b/libgit2 @@ -1 +1 @@ -Subproject commit 11f8336ec93ea3a270c9fe80c4bbb68aa4729423 +Subproject commit 146b4d1c5f98aa14df086503f996d131d40b92f8