2

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

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

  1. 枚举起始修订版的 .hgsubstate 文件
  2. 找出子存储库及其起始修订版
  3. hg log为他们奔跑
  4. 按日期合并和排序结果。

还有其他更简单的方法吗?也许我缺少一个命令?

4

1 回答 1

0

由于它显然在待办事项上已有一段时间 并且不可用,因此我编写了自己的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')
于 2017-04-16T03:39:39.300 回答