Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
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))