Skip to content

Commit

Permalink
Merge pull request open-research#326 from timtroendle/fix-proper-cont…
Browse files Browse the repository at this point in the history
…ent-finding-git

finding git content directly by hash
  • Loading branch information
apdavison committed Jan 23, 2016
2 parents 29ac837 + 0758a78 commit 9394217
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions sumatra/versioncontrol/_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,21 @@ def diff(self):
def content(self, digest, file=None):
"""Get the file content from repository."""
repo = git.Repo(self.path)
for item in repo.iter_commits('master'):
if item.hexsha == digest:
curtree = item.tree
if file is None:
return curtree.blobs[0].data_stream.read() # Get the latest added file content.
dirname,filename = os.path.split(file)
if dirname != '':
for dname in dirname.split(os.path.sep):
for subtree in curtree.trees:
if subtree.name == dname:
curtree = subtree
break
for blob in curtree.blobs:
if blob.name == filename:
expected_encoding = sys.getfilesystemencoding()
file_content = blob.data_stream.read().decode(expected_encoding)
return file_content
curtree = repo.commit(digest).tree
if file is None:
return curtree.blobs[0].data_stream.read() # Get the latest added file content.
dirname, filename = os.path.split(file)
if dirname != '':
for dname in dirname.split(os.path.sep):
for subtree in curtree.trees:
if subtree.name == dname:
curtree = subtree
break
for blob in curtree.blobs:
if blob.name == filename:
expected_encoding = sys.getfilesystemencoding()
file_content = blob.data_stream.read().decode(expected_encoding)
return file_content
return 'File content not found.'

def contains(self, path):
Expand Down

0 comments on commit 9394217

Please sign in to comment.