diff options
Diffstat (limited to 'fit.py')
-rw-r--r-- | fit.py | 22 |
1 files changed, 8 insertions, 14 deletions
@@ -4,7 +4,7 @@ import os, time import collections -from pygit2 import init_repository, Signature +from pygit2 import init_repository, Signature, GIT_FILEMODE_TREE, GIT_FILEMODE_BLOB from binascii import b2a_hex @@ -57,9 +57,9 @@ class Fit: # similiar to `git update-server-info` info_refs_path = os.path.join(self.repo.path, 'info', 'refs') with open(info_refs_path, 'w') as f: - f.write('%s\trefs/heads/master\n' % b2a_hex(commit).decode('ascii')) + f.write('%s\trefs/heads/master\n' % b2a_hex(str(commit)).decode('ascii')) - return b2a_hex(blob_oid).decode('ascii') + return b2a_hex(str(blob_oid)).decode('ascii') def _insert_node(self, node_oid, path, root_oid): @@ -101,7 +101,7 @@ class Fit: builder = last_dir[1] pre = last_dir[0] - builder.insert(filename, node_oid, 0100644) + builder.insert(filename, node_oid, GIT_FILEMODE_BLOB) current_tree_oid = builder.write() # create new nodes bottom-up for our node @@ -109,32 +109,26 @@ class Fit: pre = new_path.pop(0) for entry in reversed(new_path): builder = self.repo.TreeBuilder() - builder.insert(entry, current_tree_oid, 040000) + builder.insert(entry, current_tree_oid, GIT_FILEMODE_TREE) current_tree_oid = builder.write() # connect existing nodes with created nodes for name, builder in reversed(existing_builders): - builder.insert(pre, current_tree_oid, 040000) + builder.insert(pre, current_tree_oid, GIT_FILEMODE_TREE) current_tree_oid = builder.write() pre = name return current_tree_oid - def _get_last_commit(self): - head = self.repo.lookup_reference('HEAD').resolve() - return self.repo[head.oid] - - def _list(self, path=None): """ Lists all entries for a given path """ try: - commit = self._get_last_commit() - tree = commit.tree + tree = self.repo.head.get_object().tree if path: for p in path.split('/'): - tree = tree[p].to_object() + tree = self.repo[tree[p].id] return [(x.name, x.hex) for x in tree] |