Changes to 3 files · Browse files at 4bc6f89b0c62 Showing diff from parent c50fc0fd5b06 Diff from another changeset...
@@ -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,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,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').
|
Loading...