зеркало из https://github.com/github/libgit2sharp.git
Allow push APIs to set packbuilder parallelism
This commit is contained in:
Родитель
e2290f86dc
Коммит
4d4ebe2ead
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace LibGit2Sharp.Core
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal class GitPushOptions
|
||||
{
|
||||
public int Version = 1;
|
||||
public int PackbuilderDegreeOfParallelism;
|
||||
}
|
||||
}
|
|
@ -616,6 +616,9 @@ namespace LibGit2Sharp.Core
|
|||
[DllImport(libgit2)]
|
||||
internal static extern int git_push_new(out PushSafeHandle push, RemoteSafeHandle remote);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
internal static extern int git_push_set_options(PushSafeHandle push, GitPushOptions options);
|
||||
|
||||
[DllImport(libgit2)]
|
||||
internal static extern int git_push_add_refspec(
|
||||
PushSafeHandle push,
|
||||
|
|
|
@ -1111,6 +1111,15 @@ namespace LibGit2Sharp.Core
|
|||
}
|
||||
}
|
||||
|
||||
public static void git_push_set_options(PushSafeHandle push, GitPushOptions options)
|
||||
{
|
||||
using (ThreadAffinity())
|
||||
{
|
||||
int res = NativeMethods.git_push_set_options(push, options);
|
||||
Ensure.ZeroResult(res);
|
||||
}
|
||||
}
|
||||
|
||||
public static void git_push_status_foreach(PushSafeHandle push, NativeMethods.push_status_foreach_cb status_cb)
|
||||
{
|
||||
using (ThreadAffinity())
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
<Compile Include="CommitSortStrategies.cs" />
|
||||
<Compile Include="CompareOptions.cs" />
|
||||
<Compile Include="Core\EncodingMarshaler.cs" />
|
||||
<Compile Include="PushOptions.cs" />
|
||||
<Compile Include="UnbornBranchException.cs" />
|
||||
<Compile Include="LockedFileException.cs" />
|
||||
<Compile Include="Core\GitRepositoryInitOptions.cs" />
|
||||
|
@ -104,6 +105,7 @@
|
|||
<Compile Include="MatchedPathsAggregator.cs" />
|
||||
<Compile Include="Core\Handles\SubmoduleSafeHandle.cs" />
|
||||
<Compile Include="Core\SubmoduleLazyGroup.cs" />
|
||||
<Compile Include="Core\GitPushOptions.cs" />
|
||||
<Compile Include="Network.cs" />
|
||||
<Compile Include="Core\GitRemoteHead.cs" />
|
||||
<Compile Include="ReflogEntry.cs" />
|
||||
|
|
|
@ -151,20 +151,20 @@ namespace LibGit2Sharp
|
|||
/// <param name="objectish">The source objectish to push.</param>
|
||||
/// <param name="destinationSpec">The reference to update on the remote.</param>
|
||||
/// <param name="onPushStatusError">Handler for reporting failed push updates.</param>
|
||||
/// <param name="credentials">Credentials to use for user/pass authentication</param>
|
||||
/// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
|
||||
public virtual void Push(
|
||||
Remote remote,
|
||||
string objectish,
|
||||
string destinationSpec,
|
||||
PushStatusErrorHandler onPushStatusError,
|
||||
Credentials credentials = null)
|
||||
PushOptions pushOptions = null)
|
||||
{
|
||||
Ensure.ArgumentNotNull(remote, "remote");
|
||||
Ensure.ArgumentNotNull(objectish, "objectish");
|
||||
Ensure.ArgumentNotNullOrEmptyString(destinationSpec, destinationSpec);
|
||||
|
||||
Push(remote, string.Format(CultureInfo.InvariantCulture,
|
||||
"{0}:{1}", objectish, destinationSpec), onPushStatusError, credentials);
|
||||
"{0}:{1}", objectish, destinationSpec), onPushStatusError, pushOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -173,17 +173,17 @@ namespace LibGit2Sharp
|
|||
/// <param name="remote">The <see cref="Remote"/> to push to.</param>
|
||||
/// <param name="pushRefSpec">The pushRefSpec to push.</param>
|
||||
/// <param name="onPushStatusError">Handler for reporting failed push updates.</param>
|
||||
/// <param name="credentials">Credentials to use for user/pass authentication</param>
|
||||
/// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
|
||||
public virtual void Push(
|
||||
Remote remote,
|
||||
string pushRefSpec,
|
||||
PushStatusErrorHandler onPushStatusError,
|
||||
Credentials credentials = null)
|
||||
PushOptions pushOptions = null)
|
||||
{
|
||||
Ensure.ArgumentNotNull(remote, "remote");
|
||||
Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec");
|
||||
|
||||
Push(remote, new string[] { pushRefSpec }, onPushStatusError, credentials);
|
||||
Push(remote, new string[] { pushRefSpec }, onPushStatusError, pushOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -192,12 +192,12 @@ namespace LibGit2Sharp
|
|||
/// <param name="remote">The <see cref="Remote"/> to push to.</param>
|
||||
/// <param name="pushRefSpecs">The pushRefSpecs to push.</param>
|
||||
/// <param name="onPushStatusError">Handler for reporting failed push updates.</param>
|
||||
/// <param name="credentials">Credentials to use for user/pass authentication</param>
|
||||
/// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
|
||||
public virtual void Push(
|
||||
Remote remote,
|
||||
IEnumerable<string> pushRefSpecs,
|
||||
PushStatusErrorHandler onPushStatusError,
|
||||
Credentials credentials = null)
|
||||
PushOptions pushOptions = null)
|
||||
{
|
||||
Ensure.ArgumentNotNull(remote, "remote");
|
||||
Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs");
|
||||
|
@ -208,12 +208,17 @@ namespace LibGit2Sharp
|
|||
return;
|
||||
}
|
||||
|
||||
if (pushOptions == null)
|
||||
{
|
||||
pushOptions = new PushOptions();
|
||||
}
|
||||
|
||||
PushCallbacks pushStatusUpdates = new PushCallbacks(onPushStatusError);
|
||||
|
||||
// Load the remote.
|
||||
using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true))
|
||||
{
|
||||
var callbacks = new RemoteCallbacks(null, null, null, null, credentials);
|
||||
var callbacks = new RemoteCallbacks(null, null, null, null, pushOptions.Credentials);
|
||||
GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks();
|
||||
Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks);
|
||||
|
||||
|
@ -224,6 +229,13 @@ namespace LibGit2Sharp
|
|||
// Perform the actual push.
|
||||
using (PushSafeHandle pushHandle = Proxy.git_push_new(remoteHandle))
|
||||
{
|
||||
// Set push options.
|
||||
Proxy.git_push_set_options(pushHandle,
|
||||
new GitPushOptions()
|
||||
{
|
||||
PackbuilderDegreeOfParallelism = pushOptions.PackbuilderDegreeOfParallelism
|
||||
});
|
||||
|
||||
// Add refspecs.
|
||||
foreach (string pushRefSpec in pushRefSpecs)
|
||||
{
|
||||
|
|
|
@ -17,15 +17,15 @@ namespace LibGit2Sharp
|
|||
/// <param name="network">The <see cref="Network"/> being worked with.</param>
|
||||
/// <param name="branch">The branch to push.</param>
|
||||
/// <param name="onPushStatusError">Handler for reporting failed push updates.</param>
|
||||
/// <param name="credentials">Credentials to use for user/pass authentication.</param>
|
||||
/// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
|
||||
/// <exception cref="LibGit2SharpException">Throws if either the Remote or the UpstreamBranchCanonicalName is not set.</exception>
|
||||
public static void Push(
|
||||
this Network network,
|
||||
Branch branch,
|
||||
PushStatusErrorHandler onPushStatusError = null,
|
||||
Credentials credentials = null)
|
||||
PushOptions pushOptions = null)
|
||||
{
|
||||
network.Push(new[] { branch }, onPushStatusError, credentials);
|
||||
network.Push(new[] { branch }, onPushStatusError, pushOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -34,13 +34,13 @@ namespace LibGit2Sharp
|
|||
/// <param name="network">The <see cref="Network"/> being worked with.</param>
|
||||
/// <param name="branches">The branches to push.</param>
|
||||
/// <param name="onPushStatusError">Handler for reporting failed push updates.</param>
|
||||
/// <param name="credentials">Credentials to use for user/pass authentication.</param>
|
||||
/// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
|
||||
/// <exception cref="LibGit2SharpException">Throws if either the Remote or the UpstreamBranchCanonicalName is not set.</exception>
|
||||
public static void Push(
|
||||
this Network network,
|
||||
IEnumerable<Branch> branches,
|
||||
PushStatusErrorHandler onPushStatusError = null,
|
||||
Credentials credentials = null)
|
||||
PushOptions pushOptions = null)
|
||||
{
|
||||
var enumeratedBranches = branches as IList<Branch> ?? branches.ToList();
|
||||
|
||||
|
@ -55,7 +55,7 @@ namespace LibGit2Sharp
|
|||
|
||||
foreach (var branch in enumeratedBranches)
|
||||
{
|
||||
network.Push(branch.Remote, string.Format("{0}:{1}", branch.CanonicalName, branch.UpstreamBranchCanonicalName), onPushStatusError, credentials);
|
||||
network.Push(branch.Remote, string.Format("{0}:{1}", branch.CanonicalName, branch.UpstreamBranchCanonicalName), onPushStatusError, pushOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,21 +66,21 @@ namespace LibGit2Sharp
|
|||
/// <param name="remote">The <see cref="Remote"/> to push to.</param>
|
||||
/// <param name="objectish">The source objectish to push.</param>
|
||||
/// <param name="destinationSpec">The reference to update on the remote.</param>
|
||||
/// <param name="credentials">Credentials to use for user/pass authentication</param>
|
||||
/// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
|
||||
/// <returns>Results of the push operation.</returns>
|
||||
public static PushResult Push(
|
||||
this Network network,
|
||||
Remote remote,
|
||||
string objectish,
|
||||
string destinationSpec,
|
||||
Credentials credentials = null)
|
||||
PushOptions pushOptions = null)
|
||||
{
|
||||
Ensure.ArgumentNotNull(remote, "remote");
|
||||
Ensure.ArgumentNotNull(objectish, "objectish");
|
||||
Ensure.ArgumentNotNullOrEmptyString(destinationSpec, "destinationSpec");
|
||||
|
||||
return network.Push(remote, string.Format(CultureInfo.InvariantCulture,
|
||||
"{0}:{1}", objectish, destinationSpec), credentials);
|
||||
"{0}:{1}", objectish, destinationSpec), pushOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -89,14 +89,18 @@ namespace LibGit2Sharp
|
|||
/// <param name="network">The <see cref="Network"/> being worked with.</param>
|
||||
/// <param name="remote">The <see cref="Remote"/> to push to.</param>
|
||||
/// <param name="pushRefSpec">The pushRefSpec to push.</param>
|
||||
/// <param name="credentials">Credentials to use for user/pass authentication</param>
|
||||
/// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
|
||||
/// <returns>Results of the push operation.</returns>
|
||||
public static PushResult Push(this Network network, Remote remote, string pushRefSpec, Credentials credentials = null)
|
||||
public static PushResult Push(
|
||||
this Network network,
|
||||
Remote remote,
|
||||
string pushRefSpec,
|
||||
PushOptions pushOptions = null)
|
||||
{
|
||||
Ensure.ArgumentNotNull(remote, "remote");
|
||||
Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec");
|
||||
|
||||
return network.Push(remote, new[] { pushRefSpec }, credentials);
|
||||
return network.Push(remote, new string[] { pushRefSpec }, pushOptions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -105,9 +109,13 @@ namespace LibGit2Sharp
|
|||
/// <param name="network">The <see cref="Network"/> being worked with.</param>
|
||||
/// <param name="remote">The <see cref="Remote"/> to push to.</param>
|
||||
/// <param name="pushRefSpecs">The pushRefSpecs to push.</param>
|
||||
/// <param name="credentials">Credentials to use for user/pass authentication</param>
|
||||
/// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
|
||||
/// <returns>Results of the push operation.</returns>
|
||||
public static PushResult Push(this Network network, Remote remote, IEnumerable<string> pushRefSpecs, Credentials credentials = null)
|
||||
public static PushResult Push(
|
||||
this Network network,
|
||||
Remote remote,
|
||||
IEnumerable<string> pushRefSpecs,
|
||||
PushOptions pushOptions = null)
|
||||
{
|
||||
Ensure.ArgumentNotNull(remote, "remote");
|
||||
Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs");
|
||||
|
@ -118,7 +126,7 @@ namespace LibGit2Sharp
|
|||
remote,
|
||||
pushRefSpecs,
|
||||
failedRemoteUpdates.Add,
|
||||
credentials);
|
||||
pushOptions);
|
||||
|
||||
return new PushResult(failedRemoteUpdates);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
using LibGit2Sharp.Handlers;
|
||||
|
||||
namespace LibGit2Sharp
|
||||
{
|
||||
/// <summary>
|
||||
/// Collection of parameters controlling Push behavior.
|
||||
/// </summary>
|
||||
public sealed class PushOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="Credentials"/> to authenticate with during the push.
|
||||
/// </summary>
|
||||
public Credentials Credentials { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// If the transport being used to push to the remote requires the creation
|
||||
/// of a pack file, this controls the number of worker threads used by
|
||||
/// the packbuilder when creating that pack file to be sent to the remote.
|
||||
/// The default is 0, which indicates that the packbuilder will auto-detect
|
||||
/// the number of threads to create.
|
||||
/// </summary>
|
||||
public int PackbuilderDegreeOfParallelism { get; set; }
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче