merge-base 是哪一次提交
算出 main 和 feature 最近的共同祖先。运行下面这段程序:
def ancestors(g, c):
seen = set()
st = [c]
while st:
x = st.pop()
if x in seen:
continue
seen.add(x)
st.extend(g[x])
return seen
def merge_base(g, a, b):
both = ancestors(g, a) & ancestors(g, b)
for x in both:
others = both - {x}
if not any(x in ancestors(g, y) for y in others):
return x
return None
g = {'3f2a91c': [],
'7b4e2d0': ['3f2a91c'],
'a1c5f83': ['7b4e2d0'],
'e90d417': ['7b4e2d0'],
'5c8b206': ['e90d417']}
print(merge_base(g, 'a1c5f83', '5c8b206'))
全部评论