summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--klaus/repo.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/klaus/repo.py b/klaus/repo.py
index 8774b7a..69f4973 100644
--- a/klaus/repo.py
+++ b/klaus/repo.py
@@ -2,6 +2,8 @@ import os
import io
import stat
+from dulwich.object_store import tree_lookup_path
+from dulwich.errors import NotTreeError
import dulwich, dulwich.patch
from klaus.utils import check_output, force_unicode, parent_directory, encode_for_git, decode_from_git
@@ -137,15 +139,14 @@ class FancyRepo(dulwich.repo.Repo):
def get_blob_or_tree(self, commit, path):
"""Return the Git tree or blob object for `path` at `commit`."""
- tree_or_blob = self[commit.tree] # Still a tree here but may turn into
- # a blob somewhere in the loop.
- for part in path.strip('/').split('/'):
- if part:
- if isinstance(tree_or_blob, dulwich.objects.Blob):
- # Blobs don't have sub-files/folders.
- raise KeyError
- tree_or_blob = self[tree_or_blob[encode_for_git(part)][1]]
- return tree_or_blob
+ try:
+ (mode, oid) = tree_lookup_path(self.__getitem__, commit.tree,
+ encode_for_git(path))
+ except NotTreeError:
+ # Some part of the path was a file where a folder was expected.
+ # Example: path="/path/to/foo.txt" but "to" is a file in "/path".
+ raise KeyError
+ return self[oid]
def listdir(self, commit, path):
"""Return a list of directories and files in given directory."""