Skip to content

Update libgit2 binaries to 146b4d1 #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed Lib/NativeBinaries/amd64/git2-11f8336.dll
Binary file not shown.
Binary file removed Lib/NativeBinaries/amd64/git2-11f8336.pdb
Binary file not shown.
Binary file added Lib/NativeBinaries/amd64/git2-146b4d1.dll
Binary file not shown.
Binary file added Lib/NativeBinaries/amd64/git2-146b4d1.pdb
Binary file not shown.
Binary file removed Lib/NativeBinaries/x86/git2-11f8336.dll
Binary file not shown.
Binary file removed Lib/NativeBinaries/x86/git2-11f8336.pdb
Binary file not shown.
Binary file added Lib/NativeBinaries/x86/git2-146b4d1.dll
Binary file not shown.
Binary file added Lib/NativeBinaries/x86/git2-146b4d1.pdb
Binary file not shown.
17 changes: 4 additions & 13 deletions LibGit2Sharp/Core/GitCloneOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 4 additions & 0 deletions LibGit2Sharp/Core/GitRemoteCallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Core/NativeDllName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace LibGit2Sharp.Core
{
internal static class NativeDllName
{
public const string Name = "git2-11f8336";
public const string Name = "git2-146b4d1";
}
}
10 changes: 1 addition & 9 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 2 additions & 9 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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())
Expand Down
1 change: 0 additions & 1 deletion LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@
<Compile Include="Note.cs" />
<Compile Include="RepositoryNotFoundException.cs" />
<Compile Include="TagFetchMode.cs" />
<Compile Include="TransferCallbacks.cs" />
<Compile Include="TransferProgress.cs" />
<Compile Include="TreeChanges.cs" />
<Compile Include="TreeEntryChanges.cs" />
Expand Down
46 changes: 5 additions & 41 deletions LibGit2Sharp/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,32 +111,16 @@ 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)
{
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
Expand All @@ -150,18 +134,14 @@ 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
{
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);
}

/// <summary>
Expand Down Expand Up @@ -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())
{
Expand All @@ -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
{
Expand Down Expand Up @@ -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);
}

/// <summary>
Expand Down
53 changes: 52 additions & 1 deletion LibGit2Sharp/RemoteCallbacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ namespace LibGit2Sharp
/// </summary>
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
Expand All @@ -36,8 +43,19 @@ internal RemoteCallbacks(ProgressHandler onProgress = null, CompletionHandler on
/// </summary>
private readonly CompletionHandler Completion;

/// <summary>
/// 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.
/// </summary>
private readonly TransferProgressHandler DownloadTransferProgress;

#endregion

/// <summary>
/// The credentials to use for the credential callback.
/// </summary>
Credentials Credentials;

internal GitRemoteCallbacks GenerateCallbacks()
{
var callbacks = new GitRemoteCallbacks {version = 1};
Expand All @@ -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;
}

Expand Down Expand Up @@ -126,6 +154,29 @@ private int GitCompletionHandler(RemoteCompletionType remoteCompletionType, IntP
return result;
}

/// <summary>
/// The delegate with the signature that matches the native git_transfer_progress_callback function's signature.
/// </summary>
/// <param name="progress"><see cref="GitTransferProgress"/> structure containing progress information.</param>
/// <param name="payload">Payload data.</param>
/// <returns>the result of the wrapped <see cref="TransferProgressHandler"/></returns>
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
}
}
16 changes: 4 additions & 12 deletions LibGit2Sharp/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

Expand Down
55 changes: 0 additions & 55 deletions LibGit2Sharp/TransferCallbacks.cs

This file was deleted.

2 changes: 1 addition & 1 deletion LibGit2Sharp/UnbornBranchException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace LibGit2Sharp
public class UnbornBranchException : LibGit2SharpException
{
/// <summary>
/// Initializes a new instance of the <see cref="OrphanedHeadException"/> class.
/// Initializes a new instance of the <see cref="UnbornBranchException"/> class.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

/// </summary>
public UnbornBranchException()
{
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/libgit2_hash.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11f8336ec93ea3a270c9fe80c4bbb68aa4729423
146b4d1c5f98aa14df086503f996d131d40b92f8
Loading