使用Mercurial API获取给定变更集对存储库的更改

mac*_*osh 5 python mercurial dvcs changeset mercurial-extension

如何使用Mercurial API确定每个变更集对存储库所做的更改?我可以获得与特定修订版相关的文件列表,但是我无法弄清楚如何知道该文件发生了什么。

我如何回答变更集中每个文件的这些问题:

  • 是否添加了?
  • 它被删除了吗?
  • 修改了吗?

文件上下文中是否有一个属性可以告诉我(如果是这样,我找不到它),或者有其他方法可以解决这个问题?

这是我的代码:

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))
Run Code Online (Sandbox Code Playgroud)

ton*_*nfa 5

localrepo.status()可以将上下文作为参数(node1node2)。

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