#!/usr/bin/python # 2013-04-10 01:46 to 02:18: got Dulwich repository walking working import sys import dulwich.repo def resolve(repo, tree, path): path = path[:] while path: tree = repo.get_object(tree[path.pop(0)][1]) return tree def history(repo, commit): queue = [commit] seen = set() while queue: cob = repo.get_object(queue.pop(0)) if cob.id in seen: continue seen.add(cob.id) queue.extend(cob.parents) yield cob def file_history(repo, raw_fname): fname = raw_fname.split(b'/') for cob in history(repo, repo.head()): try: blob = resolve(repo, repo.get_object(cob.tree), fname) except KeyError: blob = None yield cob, blob def main(raw_fname): last_blob_id = None for commit, blob in file_history(dulwich.repo.Repo('.'), raw_fname): print(commit.id, commit.message.decode('utf-8').split('\n')[0]) if not blob: print("no", raw_fname) pass elif blob.id == last_blob_id: print("unchanged") else: print("bytes:", len(str(blob))) last_blob_id = blob.id if __name__ == '__main__': main(sys.argv[1].encode('utf-8'))