[Updated] [++- ] D11038: amend: make `hg amend -r` fold temporary commit into target commit
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Mon Jul 12 18:43:30 UTC 2021
martinvonz updated this revision to Diff 29212.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D11038?vs=29051&id=29212
BRANCH
default
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D11038/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D11038
AFFECTED FILES
hgext/amend.py
tests/test-amend-rev.t
CHANGE DETAILS
diff --git a/tests/test-amend-rev.t b/tests/test-amend-rev.t
--- a/tests/test-amend-rev.t
+++ b/tests/test-amend-rev.t
@@ -52,19 +52,19 @@
Can amend into grandparent
$ hg amend -r 'desc("modify a")'
+ 1 new orphan changesets
$ hg log -G -T '{rev} {desc}'
- o 4 temporary commit for "amend --rev" (known-bad-output !)
- | (known-bad-output !)
- | @ 2 add b (known-bad-output !)
+ o 5 modify a
+ |
+ | @ 2 add b
+ | | (known-bad-output !)
+ | x 1 modify a (known-bad-output !)
|/ (known-bad-output !)
- o 1 modify a
- |
o 0 add a
Target commit has new content
$ hg cat -r 'desc("modify a")' a
- a2 (known-bad-output !)
- a3 (missing-correct-output !)
+ a3
The working copy is clean and there is no unfinished operation
$ hg st -v
@@ -98,18 +98,15 @@
$ echo a2 > a
$ hg amend -r 'desc("add b")'
$ hg log -G -T '{rev} {desc}'
- o 4 temporary commit for "amend --rev" (known-bad-output !)
- | (known-bad-output !)
- | @ 2 add c (known-bad-output !)
- | | (known-bad-output !)
- o | 1 add b (known-bad-output !)
+ o 5 add b
+ |
+ | @ 2 add c
|/
o 0 add a
Target commit has new content
$ hg cat -r 'desc("add b")' a
- a (known-bad-output !)
- a2 (missing-correct-output !)
+ a2
The working copy is clean and there is no unfinished operation
$ hg st -v
@@ -140,16 +137,13 @@
$ hg amend -r 'desc("add b")'
created new head
$ hg log -G -T '{rev} {desc}'
- o 3 temporary commit for "amend --rev" (known-bad-output !)
- |
- o 1 add b
+ o 4 add b
|
@ 0 add a
Target commit has new content
$ hg cat -r 'desc("add b")' a
- a (known-bad-output !)
- a2 (missing-correct-output !)
+ a2
The working copy is clean and there is no unfinished operation
$ hg st -v
@@ -223,17 +217,16 @@
(no more unresolved files)
continue: hg amend --continue
$ hg continue
+ 1 new orphan changesets
$ hg log -G -T '{rev} {desc}'
- o 3 temporary commit for "amend --rev" (known-bad-output !)
- | (known-bad-output !)
- | @ 1 modify a (known-bad-output !)
- |/ (known-bad-output !)
- o 0 add a
+ o 4 add a
+
+ @ 1 modify a
+ |
+ x 0 add a
Target commit has new content
$ hg cat -r 'desc("add a")' a
- a (known-bad-output !)
- resolved (missing-correct-output !)
+ resolved
The working copy is clean and there is no unfinished operation
$ hg st -v
- ? a.orig
diff --git a/hgext/amend.py b/hgext/amend.py
--- a/hgext/amend.py
+++ b/hgext/amend.py
@@ -214,7 +214,10 @@
target_ctx = unfi[state[b'target_node']]
temp_ctx = unfi[state[b'temp_node']]
- _rebase_temp_node(ui, repo, state, rebase, temp_ctx, target_ctx)
+ rebased_temp_ctx = _rebase_temp_node(
+ ui, repo, state, rebase, temp_ctx, target_ctx
+ )
+ _fold_temp_node(ui, repo, state, rebase, rebased_temp_ctx, target_ctx)
def _rebase_temp_node(ui, repo, state, rebase, temp_ctx, target_ctx):
@@ -240,6 +243,43 @@
return rebased_temp_ctx
+def _fold_temp_node(ui, repo, state, rebase, rebased_temp_ctx, target_ctx):
+ if b'amended_node' in state:
+ return repo.unfiltered()[state[b'amended_node']]
+ elif statemod.ischildunfinished(repo, b'amend', b'rebase'):
+ with ui.silent(), statemod.delegating(repo, b'amend', b'rebase'):
+ ret = statemod.continuechild(ui, repo, b'amend', b'rebase')
+ else:
+ # Use rebase with collapse=True to fold the temporary commit into
+ # the target.
+ # Temporarily allow orphans; we'll rebase them ourselves.
+ overrides = {(b'experimental', b'evolution.allowunstable'): b"true"}
+ with ui.configoverride(
+ overrides, b'amend'
+ ), ui.silent(), statemod.delegating(repo, b'amend', b'rebase'):
+ ret = rebase.rebase(
+ ui,
+ repo,
+ rev=[
+ revsetlang.formatspec(
+ b'%d + %d', target_ctx.rev(), rebased_temp_ctx.rev()
+ )
+ ],
+ dest=revsetlang.formatspec(
+ b'%ld', [pctx.rev() for pctx in target_ctx.parents()]
+ ),
+ collapse=True,
+ message=target_ctx.description(),
+ )
+
+ if ret:
+ raise error.Abort(_(b'failed to fold temporary commit'))
+
+ amended_ctx = repo[b'tip']
+ state[b'amended_node'] = amended_ctx.node()
+ return amended_ctx
+
+
def _abort_amend_rev(ui, repo):
with repo.wlock(), repo.lock(), repo.transaction(b'amend'):
state_store = statemod.cmdstate(repo, b'amend-state')
@@ -263,6 +303,7 @@
scmutil.movedirstate(unfi, temp_ctx.p1())
rebased_temp_node = state.get(b'rebased_temp_node')
to_strip.append(rebased_temp_node)
+ to_strip.append(state.get(b'amended_node'))
to_strip = [node for node in to_strip if node and node in unfi]
if to_strip:
repair.delayedstrip(ui, unfi, to_strip)
To: martinvonz, #hg-reviewers, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210712/13caaf5e/attachment-0002.html>
More information about the Mercurial-patches
mailing list