Kiln » Dependencies » Dulwich Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master

objects: Add lookup_path method to Tree.

The proximate reason for this change is to avoid a circular import in
diff_tree.

Change-Id: I5516556739b08b1ebfbef9caab03cd43457ec28c

Changeset 4bc6f89b0c62

Parent c50fc0fd5b06

committed by Jelmer Vernooij

authored by David Borowitz

Changes to 3 files · Browse files at 4bc6f89b0c62 Showing diff from parent c50fc0fd5b06 Diff from another changeset...

Change 1 of 1 Show Entire File NEWS Stacked
 
71
72
73
 
 
74
75
76
 
71
72
73
74
75
76
77
78
@@ -71,6 +71,8 @@
  value of unpack_object and various DeltaChainIterator methods.   (Dave Borowitz)   + * Add a lookup_path convenience method to Tree. (Dave Borowitz) +   TEST CHANGES     * If setuptools is installed, "python setup.py test" will now run the testsuite.
 
685
686
687
688
 
689
690
691
692
 
693
694
695
696
697
698
699
700
701
702
703
704
 
 
 
 
705
706
707
 
685
686
687
 
688
689
690
691
692
693
694
 
 
 
 
 
 
 
 
 
 
 
695
696
697
698
699
700
701
@@ -685,23 +685,17 @@
     def tree_lookup_path(lookup_obj, root_sha, path): - """Lookup an object in a Git tree. + """Look up an object in a Git tree.     :param lookup_obj: Callback for retrieving object by SHA1   :param root_sha: SHA1 of the root tree   :param path: Path to lookup + :return: A tuple of (mode, SHA) of the resulting path.   """ - parts = path.split("/") - sha = root_sha - mode = None - for p in parts: - obj = lookup_obj(sha) - if not isinstance(obj, Tree): - raise NotTreeError(sha) - if p == '': - continue - mode, sha = obj[p] - return mode, sha + tree = lookup_obj(root_sha) + if not isinstance(tree, Tree): + raise NotTreeError(root_sha) + return tree.lookup_path(lookup_obj, path)      class MissingObjectFinder(object):
 
919
920
921
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
922
923
924
 
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
@@ -919,6 +919,25 @@
  text.append("%04o %s %s\t%s\n" % (mode, kind, hexsha, name))   return "".join(text)   + def lookup_path(self, lookup_obj, path): + """Look up an object in a Git tree. + + :param lookup_obj: Callback for retrieving object by SHA1 + :param path: Path to lookup + :return: A tuple of (mode, SHA) of the resulting path. + """ + parts = path.split('/') + sha = self.id + mode = None + for p in parts: + if not p: + continue + obj = lookup_obj(sha) + if not isinstance(obj, Tree): + raise NotTreeError(sha) + mode, sha = obj[p] + return mode, sha +    def parse_timezone(text):   """Parse a timezone text fragment (e.g. '+0100').