Adjusted py_str_to_git_oid to allow 20 byte binary strings. This improves usability to other clients which already store their shas as binary strings, increasing overall performance as they won't have to convert them into hex beforehand, which would have to be converted back to binary form by libgit2 in turn.
Adjusted tests to accept binary shas.
The new function does a little more, saving some lines from the callers.
This change will allow to implement a cache, now all object lookups are
centralized in a single function.
Do not allow to create commits, trees, blobs and tags directly from the
constructor. For instance, now calling "Commit(...)" raises an error.
Instead use the create methods of the repository object:
Before Now
----------------------------- -----------------------------
commit = Commit(repo, ...) sha = repo.create_commit(...)
tag = Tag(repo, ...) sha = repo.create_tag(...)
Most often you won't need to get the object just created, but if you
do just call "repo[sha]" afterwards. (Methods to create blobs and trees
are still missing, just like before.)
Similarly the method that creates a tree object from the index file does
not return the tree object anymore, but just its SHA:
Before Now
----------------------------- -----------------------------
tree = index.create_tree() sha = index.create_tree()
Tree entries are not Git objects like commits, blobs, etc.
By inheriting from Object it was even possible to produce a segfault
when accessing inherited attributes like 'type'.
Now it is possible to pass None as the commit hash to get a non
initialized walker. A second and optional parameter allows to set
the sorting mode.
Signed-off-by: J. David Ibañez <jdavid@itaapy.com>
It is possible to:
len(index) # get the number of entries in the index
'...' in index # check whether there is an entry with the given path
index[1] # get entry by position
index['...'] # get entry by path
del index[...] # remove entry by position or path