【问题标题】:Use Mercurial API to Get Changes to a Repository For a Given Changeset使用 Mercurial API 获取对给定变更集的存储库的更改
【发布时间】:2010-02-28 18:36:44
【问题描述】:

如何使用 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))

【问题讨论】:

  • 我很好奇,你用这段代码构建了什么?

标签: python mercurial dvcs changeset mercurial-extension


【解决方案1】:

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

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

【讨论】:

  • 我试了一下,得到的只是我似乎无法理解的文件列表。它们不是已更改的文件,也没有修改、添加、删除、删除、未知、忽略或干净的信息。
  • 好吧,我想我明白了。返回的每组列表对应于不同的状态。谢谢!
  • 返回值是:modified, added, removed, deleted, unknown, ignored, clean
  • 出于性能原因,只有在您通过clean=Trueignored=True 时才会填充其中的一些。
  • 链接不再是最新的。
猜你喜欢
  • 1970-01-01
  • 2016-04-14
  • 1970-01-01
  • 2011-05-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多