histedit: avoid pointless merge for "fold"/"roll"

Summary: The fold action collapsed commits up to and including the working copy, but it left the working copy dirty. When it subsequently updated to the new collapsed commit, it "merged" all the files. They merge cleanly since their contents are identical, but we still invoke the merge drivers (why are we invoking merge drivers if the contents are identical?). Fix by using ctx.markcommitted() which updates the dirstate based on what was committed. And, we no longer need to do the "hg.update()" anymore since the working copy will already be on the collapsed commit.

Reviewed By: quark-zju, zzl0

Differential Revision: D43718659

fbshipit-source-id: 26865cca11feb600e21933c60ed83796212da954
This commit is contained in:
Muir Manders 2023-03-08 15:21:58 -08:00 committed by Facebook GitHub Bot
parent 990a7c50a7
commit f425cf9998
2 changed files with 24 additions and 6 deletions

View File

@ -723,7 +723,9 @@ def collapse(repo, first, commitopts, skipprompt=False):
loginfo=loginfo,
mutinfo=mutinfo,
)
return repo.commitctx(new)
n = repo.commitctx(new)
new.markcommitted(n)
return n
def _isdirtywc(repo):
@ -894,10 +896,6 @@ class fold(histeditaction):
n = collapse(repo, ctx, commitopts, skipprompt=self.skipprompt())
if n is None:
return ctx, []
repo.ui.pushbuffer()
with repo.transaction("fold-checkout"):
hg.update(repo, n)
repo.ui.popbuffer()
mergemod.mergestate.read(repo).reset()
replacements = [
(oldctx.node(), (n,)),

View File

@ -574,5 +574,25 @@ Test rolling into a commit with multiple children (issue5498)
o 301d76bdc3ae bb
o 8f0162e483d0 aa
$ cd ..
Fold/roll shouldn't trigger a merge:
$ hg init rollmerge
$ cd rollmerge
$ echo a > a
$ hg commit -qAm a
$ echo b > a
$ hg commit -qAm b
$ hg log -G -T '{node|short} {desc}'
@ 1e6c11564562 b
o cb9a9f314b8b a
Set a bogus mergedriver as a tripwire to make sure we don't invoke merge driver.
$ hg histedit --config extensions.mergedriver= --config experimental.mergedriver=dontrunthis --commands - << EOF
> p cb9a9f314b8b
> r 1e6c11564562
> EOF
$ hg log -G -T '{node|short} {desc}'
@ 9e233947f73d a