Skip to content

Commit de2b4e5

Browse files
committed
Enable multi-threaded pack file creation
libgit2 supports creating pack files using multiple threads, which can significantly speed up a push operation. Enable Remote.push() to take advantage of that capability by adding a relevant keyword argument whose value gets passed to git_remote_push().
1 parent d0879d8 commit de2b4e5

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

pygit2/remotes.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def push_refspecs(self):
237237
check_error(err)
238238
return strarray_to_strings(specs)
239239

240-
def push(self, specs, callbacks=None, proxy=None, push_options=None):
240+
def push(self, specs, callbacks=None, proxy=None, push_options=None, threads=1):
241241
"""
242242
Push the given refspec to the remote. Raises ``GitError`` on protocol
243243
error or unpack failure.
@@ -263,9 +263,19 @@ def push(self, specs, callbacks=None, proxy=None, push_options=None):
263263
push_options : [str]
264264
Push options to send to the server, which passes them to the
265265
pre-receive as well as the post-receive hook.
266+
267+
threads : int
268+
If the transport being used to push to the remote requires the
269+
creation of a pack file, this controls the number of worker threads
270+
used by the packbuilder when creating that pack file to be sent to
271+
the remote.
272+
273+
If set to 0, the packbuilder will auto-detect the number of threads
274+
to create. The default value is 1.
266275
"""
267276
with git_push_options(callbacks) as payload:
268277
opts = payload.push_options
278+
opts.pb_parallelism = threads
269279
self.__set_proxy(opts.proxy_opts, proxy)
270280
with StrArray(specs) as refspecs, StrArray(push_options) as pushopts:
271281
pushopts.assign_to(opts.remote_push_options)

test/test_remote.py

+16
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,19 @@ def test_push_options(origin, clone, remote):
466466
remote_push_options = callbacks.push_options.remote_push_options
467467
assert remote_push_options.count == 2
468468
# strings pointed to by remote_push_options.strings[] are already freed
469+
470+
471+
def test_push_threads(origin, clone, remote):
472+
from pygit2 import RemoteCallbacks
473+
474+
callbacks = RemoteCallbacks()
475+
remote.push(['refs/heads/master'], callbacks)
476+
assert callbacks.push_options.pb_parallelism == 1
477+
478+
callbacks = RemoteCallbacks()
479+
remote.push(['refs/heads/master'], callbacks, threads=0)
480+
assert callbacks.push_options.pb_parallelism == 0
481+
482+
callbacks = RemoteCallbacks()
483+
remote.push(['refs/heads/master'], callbacks, threads=1)
484+
assert callbacks.push_options.pb_parallelism == 1

0 commit comments

Comments
 (0)