-
-
Notifications
You must be signed in to change notification settings - Fork 386
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
Add support for PackBuilder methods #1048
Conversation
I don't think you need the |
Looks good. Just don't see |
aa41739
to
4c4ff49
Compare
4c4ff49
to
402fa4e
Compare
Thanks for the comments. I've updated based on them and added the tests. Please let me know any other feedback. EDIT: I see some of my tests are not working on windows, am investigating |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just made a few comments.
pygit2/packbuilder.py
Outdated
def write(self, path): | ||
err = C.git_packbuilder_write(self._packbuilder, to_bytes(path), 0, ffi.NULL, ffi.NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
git_packbuilder_write
supports NULL for default location, so we should support None
here:
def write(self, path=None):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have updated to support NULL
pygit2/repository.py
Outdated
@@ -83,6 +84,39 @@ def write(self, *args, **kwargs): | |||
object.""" | |||
return self.odb.write(*args, **kwargs) | |||
|
|||
def pack(self, path, pack_delegate=None, max_threads=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, path=None
should be supported
pygit2/repository.py
Outdated
pack_delegate = pack_delegate or pack_all_objects | ||
|
||
builder = PackBuilder(self) | ||
if max_threads: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libgit2 docs say: when set to 0, libgit2 will autodetect the number of CPUs
But here if the user passes zero set_max_threads
won't be called. Instead the test should be:
if max_threads is not None:
Please update the documentation string as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have updated to support 0 and renamed the method and argument
pygit2/packbuilder.py
Outdated
err = C.git_packbuilder_insert_recur(self._packbuilder, oid, ffi.NULL) | ||
check_error(err) | ||
|
||
def set_max_threads(self, n_threads): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs for git_packbuilder_set_threads
says Set number of threads to spawn
It doesn't say anything about maximum, so please rename this method to set_threads
pygit2/packbuilder.py
Outdated
def convert_object_to_oid(git_object): | ||
oid = ffi.new('git_oid *') | ||
ffi.buffer(oid)[:] = git_object.raw[:] | ||
return oid | ||
|
||
def add(self, git_object): | ||
oid = self.convert_object_to_oid(git_object) | ||
err = C.git_packbuilder_insert(self._packbuilder, oid, ffi.NULL) | ||
check_error(err) | ||
|
||
def add_recur(self, git_object): | ||
oid = self.convert_object_to_oid(git_object) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are not expecting a Git object here, but an Object id, so the argument git_object
is misleading. I would call it oid
but then you had to rename the local variable with the same name, maybe git_oid
?
def convert_object_to_oid(oid):
git_oid = ffi.new('git_oid *')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've renamed it here and the other methods which call it
Merged, thanks! |
A (very much WIP) attempt to add support for the Packbuilder methods from Libgit2 to create .pack and .idx files for a repository.
I just wanted to get initial input on whether the approach taken here is correct, or if I should be structuring it a different way?
I based the overall strategy on what was done for Libgit2Sharp: libgit2/libgit2sharp#1183
TODOs:
Once I've got some feedback and done the TODOs then I'll write up a proper pull request.