Skip to content
Merged
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
12 changes: 12 additions & 0 deletions LibGit2Sharp/Core/GitPushOptions.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
3 changes: 3 additions & 0 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,9 @@ internal static extern int git_object_peel(
[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,
Expand Down
9 changes: 9 additions & 0 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,15 @@ public static PushSafeHandle git_push_new(RemoteSafeHandle remote)
}
}

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())
Expand Down
2 changes: 2 additions & 0 deletions LibGit2Sharp/LibGit2Sharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down Expand Up @@ -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" />
Expand Down
30 changes: 21 additions & 9 deletions LibGit2Sharp/Network.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,20 @@ public virtual void Fetch(
/// <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>
Expand All @@ -173,17 +173,17 @@ public virtual void Push(
/// <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>
Expand All @@ -192,12 +192,12 @@ public virtual void Push(
/// <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");
Expand All @@ -208,12 +208,17 @@ public virtual void Push(
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);

Expand All @@ -224,6 +229,13 @@ public virtual void Push(
// 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)
{
Expand Down
38 changes: 23 additions & 15 deletions LibGit2Sharp/NetworkExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public static class NetworkExtensions
/// <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>
Expand All @@ -34,13 +34,13 @@ public static void Push(
/// <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();

Expand All @@ -55,7 +55,7 @@ public static void Push(

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);
}
}

Expand All @@ -66,21 +66,21 @@ public static void Push(
/// <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>
Expand All @@ -89,14 +89,18 @@ public static PushResult Push(
/// <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>
Expand All @@ -105,9 +109,13 @@ public static PushResult Push(this Network network, Remote remote, string pushRe
/// <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");
Expand All @@ -118,7 +126,7 @@ public static PushResult Push(this Network network, Remote remote, IEnumerable<s
remote,
pushRefSpecs,
failedRemoteUpdates.Add,
credentials);
pushOptions);

return new PushResult(failedRemoteUpdates);
}
Expand Down
24 changes: 24 additions & 0 deletions LibGit2Sharp/PushOptions.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}