5

How can I use the Mercurial API to determine the changes made to a repository for each changeset? I am able to get a list of files relevant to a particular revision, but I cannot figure out how to tell what happened to that file.

How can I answer these questions about each file in a changeset:

  • Was it added?
  • Was it deleted?
  • Was it modified?

Is there an attribute in the file context that will tell me this (if so, I cannot find it), or there ways to figure this out by other means?

Here is my code:

def index(request):
    u = ui.ui()
    repo = hg.repository(ui.ui(), '/path/to/repo')
    changes = repo.changelog
    changesets = []

    for change in changes:
        ctx = repo.changectx(change)
        fileCtxs = []
        for aFile in ctx.files():
            if aFile in ctx:
                for status in repo.status(None, ctx.node()):
                    # I'm hoping this could return A, M, D, ? etc
                    fileCtxs.append(status)

        changeset = {
            'files':ctx.files(),
            'rev':str(ctx.rev()),
            'desc':ctx.description(),
            'user':ctx.user(),
            'filectxs':fileCtxs,
        }
        changesets.append(changeset)

    c = Context({
        'changesets': changesets,
    })

    tmplt = loader.get_template('web/index.html')
    return HttpResponse(tmplt.render(c))
Michael La Voie
  • 27,772
  • 14
  • 72
  • 92
joshwbrick
  • 5,882
  • 9
  • 48
  • 72

1 Answers1

5

localrepo.status() can take contexts as argument (node1 and node2).

See http://hg.intevation.org/mercurial/crew/file/6505773080e4/mercurial/localrepo.py#l973

tonfa
  • 24,151
  • 2
  • 35
  • 41
  • I gave this a try and all I get back are lists of files that I can't seem to make sense of. They aren't the files that changed and there is no modified, added, removed, deleted, unknown, ignored, or clean information. – joshwbrick Feb 28 '10 at 19:31
  • Ok I think I figured it out. Each set of lists returned corresponds to a different status. Thanks! – joshwbrick Feb 28 '10 at 19:43
  • The value returnes are: `modified, added, removed, deleted, unknown, ignored, clean` – tonfa Feb 28 '10 at 20:02
  • 1
    Some of them will only be filled if you pass `clean=True` or `ignored=True` for performance reasons. – tonfa Feb 28 '10 at 20:03
  • The link is not up to date any longer. – jaques-sam Jan 05 '18 at 08:23