Commit 5dba668f authored by Martin von Zweigbergk's avatar Martin von Zweigbergk
Browse files

compat: let cleanupnodes() handle compat across hg commit b99903534e06

This makes it so `compat.cleanupnodes()` requires the `replacements`
dict to have an iterable as key. On older Mercurials (< 4.7) we
convert that into many items with a single value as key instead.

--HG--
branch : stable
parent 7370725cdba7
Pipeline #10243 passed with stage
in 6 minutes and 5 seconds
......@@ -169,7 +169,7 @@ def amendpatch(ui, repo, *pats, **opts):
metadata = {}
if opts.get('note'):
metadata[b'note'] = opts['note']
replacements = {old.node(): [newnode]}
replacements = {(old.node(),): [newnode]}
compat.cleanupnodes(repo, replacements, operation=b'amend',
metadata=metadata)
phases.retractboundary(repo, tr, old.phase(), [newnode])
......@@ -508,7 +508,7 @@ def uncommit(ui, repo, *pats, **opts):
if opts.get('note'):
metadata[b'note'] = opts['note']
replacements = {old.node(): [newid]}
replacements = {(old.node(),): [newid]}
compat.cleanupnodes(repo, replacements, operation=b"uncommit",
metadata=metadata)
phases.retractboundary(repo, tr, oldphase, [newid])
......@@ -745,17 +745,9 @@ def fold(ui, repo, *revs, **opts):
p2.node()],
commitopts=commitopts)
phases.retractboundary(repo, tr, targetphase, [newid])
# Use this condition as a proxy since the commit we care about
# (b99903534e06) didn't change any signatures.
if util.safehasattr(scmutil, 'nullrev'):
replacements = {tuple(ctx.node() for ctx in allctx): [newid]}
compat.cleanupnodes(repo, replacements, operation=b"fold",
metadata=metadata)
else:
# hg <= 4.7 (b99903534e06)
replacements = {ctx.node(): [newid] for ctx in allctx}
compat.cleanupnodes(repo, replacements, operation=b"fold",
metadata=metadata)
replacements = {tuple(ctx.node() for ctx in allctx): [newid]}
compat.cleanupnodes(repo, replacements, operation=b"fold",
metadata=metadata)
tr.close()
finally:
tr.release()
......@@ -882,21 +874,9 @@ def metaedit(ui, repo, *revs, **opts):
metadata[b'note'] = opts['note']
phases.retractboundary(repo, tr, targetphase, [newid])
# Use this condition as a proxy since the commit we care about
# (b99903534e06) didn't change any signatures.
if util.safehasattr(scmutil, 'nullrev'):
replacements = {
tuple(ctx.node() for ctx in allctx): (newid,)
}
compat.cleanupnodes(repo, replacements,
operation=b"metaedit",
metadata=metadata)
else:
# hg <= 4.7 (b99903534e06)
replacements = {ctx.node(): (newid,) for ctx in allctx}
compat.cleanupnodes(repo, replacements,
operation=b"metaedit",
metadata=metadata)
replacements = {tuple(ctx.node() for ctx in allctx): (newid,)}
compat.cleanupnodes(repo, replacements, operation=b"metaedit",
metadata=metadata)
else:
ui.status(_(b"nothing changed\n"))
tr.close()
......@@ -1035,9 +1015,9 @@ def cmdprune(ui, repo, *revs, **opts):
msg = b"please add --fold if you want to do a fold"
raise error.Abort(msg)
elif biject:
replacements = {p.node(): [s.node()] for p, s in zip(precs, sucs)}
replacements = {(p.node(),): [s.node()] for p, s in zip(precs, sucs)}
else:
replacements = {p.node(): [s.node() for s in sucs] for p in precs}
replacements = {(p.node(),): [s.node() for s in sucs] for p in precs}
wdp = repo[b'.']
......@@ -1117,14 +1097,11 @@ def cmdprune(ui, repo, *revs, **opts):
# but then revset took a lazy arrow in the knee and became much
# slower. The new forms makes as much sense and a much faster.
for dest in ctx.ancestors():
if not dest.obsolete() and dest.node() not in replacements:
if not dest.obsolete() and (dest.node(),) not in replacements:
moves[ctx.node()] = dest.node()
break
if len(sucs) == 1 and len(precs) > 1 and fold:
# hg <= 4.7 (b99903534e06)
# Using a proxy condition to let people wrap cleanupnodes()
if util.safehasattr(scmutil, 'nullrev'):
replacements = {tuple(p.node() for p in precs): [s.node() for s in sucs]}
replacements = {tuple(p.node() for p in precs): [s.node() for s in sucs]}
compat.cleanupnodes(repo, replacements, operation=b"prune", moves=moves,
metadata=metadata)
......@@ -1480,10 +1457,10 @@ def cmdpick(ui, repo, *revs, **opts):
if pickstate:
pickstate.delete()
if newnode is None:
replacements = {origctx.node(): []}
replacements = {(origctx.node(),): []}
else:
newctx = repo[newnode]
replacements = {origctx.node(): [newctx.node()]}
replacements = {(origctx.node(),): [newctx.node()]}
compat.cleanupnodes(repo, replacements, operation=b"pick")
if newnode is None:
......
......@@ -388,5 +388,16 @@ def parentchange(repo):
repo._quick_access_changeid_invalidate()
def cleanupnodes(repo, replacements, operation, moves=None, metadata=None):
scmutil.cleanupnodes(repo, replacements=replacements, operation=operation,
# Use this condition as a proxy since the commit we care about
# (b99903534e06) didn't change any signatures.
if util.safehasattr(scmutil, 'nullrev'):
fixedreplacements = replacements
else:
# hg <= 4.7 (b99903534e06)
fixedreplacements = {}
for oldnodes, newnodes in replacements.items():
for oldnode in oldnodes:
fixedreplacements[oldnode] = newnodes
scmutil.cleanupnodes(repo, replacements=fixedreplacements, operation=operation,
moves=moves, metadata=metadata)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment