Mercurial存储库日志包括子存储库

时间:2012-06-06 17:37:07

标签: mercurial mercurial-subrepos changelist

在我们的构建脚本中,我使用模板hg log命令获取特定构建的更改列表。这很好用,但不幸的是它不包括subrepos中的更改(我们有超过10个)。我也想包括它们,但似乎没有这样的命令。

我正在考虑编写一个脚本:

  1. 在起始修订版
  2. 中枚举.hgsubstate文件
  3. 找出subrepos及其开始修订
  4. 为他们运行hg log
  5. 按日期合并和排序结果。
  6. 还有其他更简单的方法吗?也许我错过了一个命令?

1 个答案:

答案 0 :(得分:0)

由于它显然在todo上进行了 ,否则无法使用,我写了自己的subtools.py

from __future__ import print_function
import hglib
import os
import sys

def get_substate(client, rev=None):
    substate_filename = os.path.join(client.root(), '.hgsubstate')
    if os.path.isfile(substate_filename):
        lines = client.cat([substate_filename], rev).split('\n')
        return { key : value for (value,key) in [ line.split() for line in lines if line ]}
    else:
        return {}


def substate_diff(client, revA, revB):
    substate_a = get_substate(client, revA)
    substate_b = get_substate(client, revB)
    key_union = set(substate_b) | set(substate_a)

    diff = {}
    for key in key_union:
       diff[key] = (substate_a[key], substate_b[key])

    return diff

def recursive_log(path, revA, revB):
    logtree = { 'logs': [], 'subrepos': {}}

    try:
        client = hglib.open(path)
    except:
        return logtree

    if revA == revB:
        print("no changes on {}".format(client.root()))
        return logtree

    print("Checking {} between {} and {}...".format(client.root(), revA, revB))

    for key, revisions in substate_diff(client, revA, revB).iteritems():
        if revisions[0] and revisions[1]:
            logtree['subrepos'][key] = recursive_log(os.path.join(client.root(),key), revisions[0], revisions[1])
        elif revisions[0] and not revisions[1]:
            print("removed subrepo with path: %s"%key, file=sys.stderr)
        elif revisions[1] and not revisions[2]:
            print("added subrepo with path: %s"%key, file=sys.stderr)

    logtree['logs'] = client.log("%s:%s"%(revA,revB))
    return logtree

使用原样:

In [15]: log = subtools.recursive_log('./', '947', '951')