Skip to content

Commit 4d4ebe2

Browse files
jamillEdward Thomson
authored and
Edward Thomson
committed
Allow push APIs to set packbuilder parallelism
1 parent e2290f8 commit 4d4ebe2

File tree

7 files changed

+94
-24
lines changed

7 files changed

+94
-24
lines changed

LibGit2Sharp/Core/GitPushOptions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace LibGit2Sharp.Core
5+
{
6+
[StructLayout(LayoutKind.Sequential)]
7+
internal class GitPushOptions
8+
{
9+
public int Version = 1;
10+
public int PackbuilderDegreeOfParallelism;
11+
}
12+
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,9 @@ internal static extern int git_object_peel(
616616
[DllImport(libgit2)]
617617
internal static extern int git_push_new(out PushSafeHandle push, RemoteSafeHandle remote);
618618

619+
[DllImport(libgit2)]
620+
internal static extern int git_push_set_options(PushSafeHandle push, GitPushOptions options);
621+
619622
[DllImport(libgit2)]
620623
internal static extern int git_push_add_refspec(
621624
PushSafeHandle push,

LibGit2Sharp/Core/Proxy.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,15 @@ public static PushSafeHandle git_push_new(RemoteSafeHandle remote)
11111111
}
11121112
}
11131113

1114+
public static void git_push_set_options(PushSafeHandle push, GitPushOptions options)
1115+
{
1116+
using (ThreadAffinity())
1117+
{
1118+
int res = NativeMethods.git_push_set_options(push, options);
1119+
Ensure.ZeroResult(res);
1120+
}
1121+
}
1122+
11141123
public static void git_push_status_foreach(PushSafeHandle push, NativeMethods.push_status_foreach_cb status_cb)
11151124
{
11161125
using (ThreadAffinity())

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<Compile Include="CommitSortStrategies.cs" />
7373
<Compile Include="CompareOptions.cs" />
7474
<Compile Include="Core\EncodingMarshaler.cs" />
75+
<Compile Include="PushOptions.cs" />
7576
<Compile Include="UnbornBranchException.cs" />
7677
<Compile Include="LockedFileException.cs" />
7778
<Compile Include="Core\GitRepositoryInitOptions.cs" />
@@ -104,6 +105,7 @@
104105
<Compile Include="MatchedPathsAggregator.cs" />
105106
<Compile Include="Core\Handles\SubmoduleSafeHandle.cs" />
106107
<Compile Include="Core\SubmoduleLazyGroup.cs" />
108+
<Compile Include="Core\GitPushOptions.cs" />
107109
<Compile Include="Network.cs" />
108110
<Compile Include="Core\GitRemoteHead.cs" />
109111
<Compile Include="ReflogEntry.cs" />

LibGit2Sharp/Network.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,20 @@ public virtual void Fetch(
151151
/// <param name="objectish">The source objectish to push.</param>
152152
/// <param name="destinationSpec">The reference to update on the remote.</param>
153153
/// <param name="onPushStatusError">Handler for reporting failed push updates.</param>
154-
/// <param name="credentials">Credentials to use for user/pass authentication</param>
154+
/// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
155155
public virtual void Push(
156156
Remote remote,
157157
string objectish,
158158
string destinationSpec,
159159
PushStatusErrorHandler onPushStatusError,
160-
Credentials credentials = null)
160+
PushOptions pushOptions = null)
161161
{
162162
Ensure.ArgumentNotNull(remote, "remote");
163163
Ensure.ArgumentNotNull(objectish, "objectish");
164164
Ensure.ArgumentNotNullOrEmptyString(destinationSpec, destinationSpec);
165165

166166
Push(remote, string.Format(CultureInfo.InvariantCulture,
167-
"{0}:{1}", objectish, destinationSpec), onPushStatusError, credentials);
167+
"{0}:{1}", objectish, destinationSpec), onPushStatusError, pushOptions);
168168
}
169169

170170
/// <summary>
@@ -173,17 +173,17 @@ public virtual void Push(
173173
/// <param name="remote">The <see cref="Remote"/> to push to.</param>
174174
/// <param name="pushRefSpec">The pushRefSpec to push.</param>
175175
/// <param name="onPushStatusError">Handler for reporting failed push updates.</param>
176-
/// <param name="credentials">Credentials to use for user/pass authentication</param>
176+
/// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
177177
public virtual void Push(
178178
Remote remote,
179179
string pushRefSpec,
180180
PushStatusErrorHandler onPushStatusError,
181-
Credentials credentials = null)
181+
PushOptions pushOptions = null)
182182
{
183183
Ensure.ArgumentNotNull(remote, "remote");
184184
Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec");
185185

186-
Push(remote, new string[] { pushRefSpec }, onPushStatusError, credentials);
186+
Push(remote, new string[] { pushRefSpec }, onPushStatusError, pushOptions);
187187
}
188188

189189
/// <summary>
@@ -192,12 +192,12 @@ public virtual void Push(
192192
/// <param name="remote">The <see cref="Remote"/> to push to.</param>
193193
/// <param name="pushRefSpecs">The pushRefSpecs to push.</param>
194194
/// <param name="onPushStatusError">Handler for reporting failed push updates.</param>
195-
/// <param name="credentials">Credentials to use for user/pass authentication</param>
195+
/// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
196196
public virtual void Push(
197197
Remote remote,
198198
IEnumerable<string> pushRefSpecs,
199199
PushStatusErrorHandler onPushStatusError,
200-
Credentials credentials = null)
200+
PushOptions pushOptions = null)
201201
{
202202
Ensure.ArgumentNotNull(remote, "remote");
203203
Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs");
@@ -208,12 +208,17 @@ public virtual void Push(
208208
return;
209209
}
210210

211+
if (pushOptions == null)
212+
{
213+
pushOptions = new PushOptions();
214+
}
215+
211216
PushCallbacks pushStatusUpdates = new PushCallbacks(onPushStatusError);
212217

213218
// Load the remote.
214219
using (RemoteSafeHandle remoteHandle = Proxy.git_remote_load(repository.Handle, remote.Name, true))
215220
{
216-
var callbacks = new RemoteCallbacks(null, null, null, null, credentials);
221+
var callbacks = new RemoteCallbacks(null, null, null, null, pushOptions.Credentials);
217222
GitRemoteCallbacks gitCallbacks = callbacks.GenerateCallbacks();
218223
Proxy.git_remote_set_callbacks(remoteHandle, ref gitCallbacks);
219224

@@ -224,6 +229,13 @@ public virtual void Push(
224229
// Perform the actual push.
225230
using (PushSafeHandle pushHandle = Proxy.git_push_new(remoteHandle))
226231
{
232+
// Set push options.
233+
Proxy.git_push_set_options(pushHandle,
234+
new GitPushOptions()
235+
{
236+
PackbuilderDegreeOfParallelism = pushOptions.PackbuilderDegreeOfParallelism
237+
});
238+
227239
// Add refspecs.
228240
foreach (string pushRefSpec in pushRefSpecs)
229241
{

LibGit2Sharp/NetworkExtensions.cs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public static class NetworkExtensions
1717
/// <param name="network">The <see cref="Network"/> being worked with.</param>
1818
/// <param name="branch">The branch to push.</param>
1919
/// <param name="onPushStatusError">Handler for reporting failed push updates.</param>
20-
/// <param name="credentials">Credentials to use for user/pass authentication.</param>
20+
/// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
2121
/// <exception cref="LibGit2SharpException">Throws if either the Remote or the UpstreamBranchCanonicalName is not set.</exception>
2222
public static void Push(
2323
this Network network,
2424
Branch branch,
2525
PushStatusErrorHandler onPushStatusError = null,
26-
Credentials credentials = null)
26+
PushOptions pushOptions = null)
2727
{
28-
network.Push(new[] { branch }, onPushStatusError, credentials);
28+
network.Push(new[] { branch }, onPushStatusError, pushOptions);
2929
}
3030

3131
/// <summary>
@@ -34,13 +34,13 @@ public static void Push(
3434
/// <param name="network">The <see cref="Network"/> being worked with.</param>
3535
/// <param name="branches">The branches to push.</param>
3636
/// <param name="onPushStatusError">Handler for reporting failed push updates.</param>
37-
/// <param name="credentials">Credentials to use for user/pass authentication.</param>
37+
/// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
3838
/// <exception cref="LibGit2SharpException">Throws if either the Remote or the UpstreamBranchCanonicalName is not set.</exception>
3939
public static void Push(
4040
this Network network,
4141
IEnumerable<Branch> branches,
4242
PushStatusErrorHandler onPushStatusError = null,
43-
Credentials credentials = null)
43+
PushOptions pushOptions = null)
4444
{
4545
var enumeratedBranches = branches as IList<Branch> ?? branches.ToList();
4646

@@ -55,7 +55,7 @@ public static void Push(
5555

5656
foreach (var branch in enumeratedBranches)
5757
{
58-
network.Push(branch.Remote, string.Format("{0}:{1}", branch.CanonicalName, branch.UpstreamBranchCanonicalName), onPushStatusError, credentials);
58+
network.Push(branch.Remote, string.Format("{0}:{1}", branch.CanonicalName, branch.UpstreamBranchCanonicalName), onPushStatusError, pushOptions);
5959
}
6060
}
6161

@@ -66,21 +66,21 @@ public static void Push(
6666
/// <param name="remote">The <see cref="Remote"/> to push to.</param>
6767
/// <param name="objectish">The source objectish to push.</param>
6868
/// <param name="destinationSpec">The reference to update on the remote.</param>
69-
/// <param name="credentials">Credentials to use for user/pass authentication</param>
69+
/// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
7070
/// <returns>Results of the push operation.</returns>
7171
public static PushResult Push(
7272
this Network network,
7373
Remote remote,
7474
string objectish,
7575
string destinationSpec,
76-
Credentials credentials = null)
76+
PushOptions pushOptions = null)
7777
{
7878
Ensure.ArgumentNotNull(remote, "remote");
7979
Ensure.ArgumentNotNull(objectish, "objectish");
8080
Ensure.ArgumentNotNullOrEmptyString(destinationSpec, "destinationSpec");
8181

8282
return network.Push(remote, string.Format(CultureInfo.InvariantCulture,
83-
"{0}:{1}", objectish, destinationSpec), credentials);
83+
"{0}:{1}", objectish, destinationSpec), pushOptions);
8484
}
8585

8686
/// <summary>
@@ -89,14 +89,18 @@ public static PushResult Push(
8989
/// <param name="network">The <see cref="Network"/> being worked with.</param>
9090
/// <param name="remote">The <see cref="Remote"/> to push to.</param>
9191
/// <param name="pushRefSpec">The pushRefSpec to push.</param>
92-
/// <param name="credentials">Credentials to use for user/pass authentication</param>
92+
/// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
9393
/// <returns>Results of the push operation.</returns>
94-
public static PushResult Push(this Network network, Remote remote, string pushRefSpec, Credentials credentials = null)
94+
public static PushResult Push(
95+
this Network network,
96+
Remote remote,
97+
string pushRefSpec,
98+
PushOptions pushOptions = null)
9599
{
96100
Ensure.ArgumentNotNull(remote, "remote");
97101
Ensure.ArgumentNotNullOrEmptyString(pushRefSpec, "pushRefSpec");
98102

99-
return network.Push(remote, new[] { pushRefSpec }, credentials);
103+
return network.Push(remote, new string[] { pushRefSpec }, pushOptions);
100104
}
101105

102106
/// <summary>
@@ -105,9 +109,13 @@ public static PushResult Push(this Network network, Remote remote, string pushRe
105109
/// <param name="network">The <see cref="Network"/> being worked with.</param>
106110
/// <param name="remote">The <see cref="Remote"/> to push to.</param>
107111
/// <param name="pushRefSpecs">The pushRefSpecs to push.</param>
108-
/// <param name="credentials">Credentials to use for user/pass authentication</param>
112+
/// <param name="pushOptions"><see cref="PushOptions"/> controlling push behavior</param>
109113
/// <returns>Results of the push operation.</returns>
110-
public static PushResult Push(this Network network, Remote remote, IEnumerable<string> pushRefSpecs, Credentials credentials = null)
114+
public static PushResult Push(
115+
this Network network,
116+
Remote remote,
117+
IEnumerable<string> pushRefSpecs,
118+
PushOptions pushOptions = null)
111119
{
112120
Ensure.ArgumentNotNull(remote, "remote");
113121
Ensure.ArgumentNotNull(pushRefSpecs, "pushRefSpecs");
@@ -118,7 +126,7 @@ public static PushResult Push(this Network network, Remote remote, IEnumerable<s
118126
remote,
119127
pushRefSpecs,
120128
failedRemoteUpdates.Add,
121-
credentials);
129+
pushOptions);
122130

123131
return new PushResult(failedRemoteUpdates);
124132
}

LibGit2Sharp/PushOptions.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using LibGit2Sharp.Handlers;
2+
3+
namespace LibGit2Sharp
4+
{
5+
/// <summary>
6+
/// Collection of parameters controlling Push behavior.
7+
/// </summary>
8+
public sealed class PushOptions
9+
{
10+
/// <summary>
11+
/// The <see cref="Credentials"/> to authenticate with during the push.
12+
/// </summary>
13+
public Credentials Credentials { get; set; }
14+
15+
/// <summary>
16+
/// If the transport being used to push to the remote requires the creation
17+
/// of a pack file, this controls the number of worker threads used by
18+
/// the packbuilder when creating that pack file to be sent to the remote.
19+
/// The default is 0, which indicates that the packbuilder will auto-detect
20+
/// the number of threads to create.
21+
/// </summary>
22+
public int PackbuilderDegreeOfParallelism { get; set; }
23+
}
24+
}

0 commit comments

Comments
 (0)