Closed
Description
I'm trying to get the latest commit for each item in a list of Tree
or Blob
objects (sth. like a repo browser). Currently i'm doing something like
repo = git.Repo("test.git")
tree = repo.tree()
for obj in tree:
print obj, obj.path, repo.iter_commits(paths=obj.path, max_count=1).next()
but this is incredible slow. Another solution is to use repo.iter_commits()
to fill a dict of path <-> commit:
for commit in repo.iter_commits(paths=paths):
for f in commit.stats.files.keys():
p = f[:f.index('/')] if '/' in f else f
if p in latest_commits:
continue
latest_commits[p] = commit
However, in the worst case this one iterates over all commits in the entire repository (which is obviously a very bad idea).
Is there a faster solution?