在我们的构建脚本中,我使用模板化的hg log
命令来获取特定构建的更改列表。这很好用,但不幸的是它不包括子存储库中的更改(我们有 10 多个)。我也想包括它们,但似乎没有这样的命令。
我正在考虑编写一个脚本:
- 枚举
- 起始修订版中的 .hgsubstate 文件
- 找出子存储库及其起始修订版
- 为他们运行
hg log
- 按日期合并和排序结果。
还有其他更简单的方法吗?也许我缺少一个命令?
由于它显然在待办事项上已经有一段时间了,否则不可用,所以我写了自己的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')