##// END OF EJS Templates
libgit2: changed is_empty and introduced new way for checking tree_id for path in git
marcink -
r726:f20a6430 default
parent child Browse files
Show More
@@ -160,13 +160,10 b' class GitRemote(object):'
160 160 def is_empty(self, wire):
161 161 repo = self._factory.repo_libgit2(wire)
162 162
163 # NOTE(marcink): old solution as an alternative
164 # try:
165 # return not repo.head.name
166 # except Exception:
167 # return True
168
169 return repo.is_empty
163 try:
164 return not repo.head.name
165 except Exception:
166 return True
170 167
171 168 @reraise_safe_exceptions
172 169 def add_object(self, wire, content):
@@ -227,13 +224,18 b' class GitRemote(object):'
227 224
228 225 @reraise_safe_exceptions
229 226 def is_large_file(self, wire, sha):
230 repo = self._factory.repo(wire)
231 blob = repo[sha]
232 return self._parse_lfs_pointer(blob.as_raw_string())
227 repo_init = self._factory.repo_libgit2(wire)
228
229 with repo_init as repo:
230 blob = repo[sha]
231 if blob.is_binary:
232 return {}
233
234 return self._parse_lfs_pointer(blob.data)
233 235
234 236 @reraise_safe_exceptions
235 237 def in_largefiles_store(self, wire, oid):
236 repo = self._factory.repo(wire)
238 repo = self._factory.repo_libgit2(wire)
237 239 conf = self._wire_to_config(wire)
238 240
239 241 store_location = conf.get('vcs_git_lfs_store_location')
@@ -247,7 +249,7 b' class GitRemote(object):'
247 249
248 250 @reraise_safe_exceptions
249 251 def store_path(self, wire, oid):
250 repo = self._factory.repo(wire)
252 repo = self._factory.repo_libgit2(wire)
251 253 conf = self._wire_to_config(wire)
252 254
253 255 store_location = conf.get('vcs_git_lfs_store_location')
@@ -725,11 +727,27 b' class GitRemote(object):'
725 727 return list(result)
726 728
727 729 @reraise_safe_exceptions
730 def tree_and_type_for_path(self, wire, commit_id, path):
731 repo_init = self._factory.repo_libgit2(wire)
732
733 with repo_init as repo:
734 commit = repo[commit_id]
735 try:
736 tree = commit.tree[path]
737 except KeyError:
738 return None, None, None
739
740 return tree.id.hex, tree.type, tree.filemode
741
742 @reraise_safe_exceptions
728 743 def tree_items(self, wire, tree_id):
729 744 repo_init = self._factory.repo_libgit2(wire)
730 745
731 746 with repo_init as repo:
732 tree = repo[tree_id]
747 try:
748 tree = repo[tree_id]
749 except KeyError:
750 raise ObjectMissing('No tree with id: {}'.format(tree_id))
733 751
734 752 result = []
735 753 for item in tree:
General Comments 0
You need to be logged in to leave comments. Login now