def _rev_left_right(left, right): if args: revinfo = repo.git.rev_list("%s...%s" % (left, right), left_right=True, *args) else: revinfo = repo.git.rev_list("%s...%s" % (left, right), left_right=True) for rev in revinfo.splitlines(): c = Commit(repo, rev[1:]) c.direction = rev[0] yield c
def _commit_for_blob(ref, fn): upstream = Commit.find_all(repo, ref, fn) for commit in upstream: try: blob = _traverse(commit.tree, fn).next() except KeyError: return if blob.id == initialblob.id: return commit
def file(): """For a given file, compare its history against UPSTREAM.""" repo = Repo() fn = argv[1] upstream = argv[2] try: local = argv[3] except IndexError: local = "HEAD" lstart = Commit.find_all(repo, local, fn)[-1] initialblob = _traverse(lstart.tree, fn).next() def _commit_for_blob(ref, fn): upstream = Commit.find_all(repo, ref, fn) for commit in upstream: try: blob = _traverse(commit.tree, fn).next() except KeyError: return if blob.id == initialblob.id: return commit ustart = _commit_for_blob(upstream, fn) if ustart: upstream_precommits = set(c.id for c in Commit.find_all(repo, ustart, fn)) else: print >>stderr, "Warning: upstream does not have the initial blob for %s." % fn upstream, local = (_commit(repo, upstream), _commit(repo, local)) commits = reversed(left_right(repo, upstream, local, fn)) for commit in commits: if ustart: if commit.direction != "-" and \ commit.id in upstream_precommits: commit.direction = "-" print("%s %s" % (commit.direction, commit))