Mercurial > evolve
changeset 5777:c5dfbbe4363d
evolve: when relocating, optionally first try to do it using in-memory merge
This patch adds a config option to let run evolve's relocation step
using in-memory merge. It is disabled by default. When the option is
on, the relocation is first attempted in memory. If that fails because
of merge conflicts, it retries that commit in the working copy.
There are a few reasons that I made it configurable. The most
important one is that the precommit hook won't trigger when using
in-memory merge. Another reason is that it lets us roll out the
feature slowly to our users at Google.
For now, we also update the working copy after creating the commit (in the
successful case, when there are no merge conflicts). The next patch will make it
so we don't do that update.
Because of the unnecessary working-copy update, this patch doesn't
provide any benefit on its own. Evolving 29 commits that each change
one line in the hg slows down from ~4.5s to ~4.8s when the config
option is on.
I've added `#testcases inmemory ondisk` to select `.t` files. Almost
all differences are because of the new "hit merge conflicts" message
and retrying the merge. There's also one difference in
`test-stabilize-order.t` caused by the different order of working copy
updates (we now update the working copy at the end).
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 15 Oct 2020 15:40:36 -0700 |
parents | 453ba695c3d4 |
children | 84affb254cdf |
files | hgext3rd/evolve/__init__.py hgext3rd/evolve/evolvecmd.py tests/test-evolve-abort-orphan.t tests/test-evolve-abort-phasediv.t tests/test-evolve-continue.t tests/test-evolve-inmemory.t tests/test-evolve-noupdate.t tests/test-evolve-phase.t tests/test-evolve-stop-orphan.t tests/test-evolve-stop-phasediv.t tests/test-evolve-wdir.t tests/test-evolve.t tests/test-stabilize-order.t |
diffstat | 13 files changed, 267 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/evolve/__init__.py Thu Oct 01 12:34:36 2020 -0700 +++ b/hgext3rd/evolve/__init__.py Thu Oct 15 15:40:36 2020 -0700 @@ -348,6 +348,7 @@ # Configuration eh.configitem(b'experimental', b'evolutioncommands', []) eh.configitem(b'experimental', b'evolution.allnewcommands', None) +eh.configitem(b'experimental', b'evolution.in-memory', b'false') ##################################################################### ### Option configuration ###
--- a/hgext3rd/evolve/evolvecmd.py Thu Oct 01 12:34:36 2020 -0700 +++ b/hgext3rd/evolve/evolvecmd.py Thu Oct 15 15:40:36 2020 -0700 @@ -32,6 +32,8 @@ util, ) +from mercurial.utils import stringutil + from mercurial.i18n import _ from . import ( @@ -164,7 +166,7 @@ progresscb() with state.saver(evolvestate, {b'current': orig.node()}): newid = _relocate(repo, orig, target, evolvestate, pctx, - keepbranch, b'orphan') + keepbranch, b'orphan', update=False) return (True, newid) def _solvephasedivergence(ui, repo, bumped, evolvestate, display, @@ -932,10 +934,20 @@ b'not be updated\n') % sha1) return commitmsg +def _use_in_memory_merge(repo): + config_value = repo.ui.config(b'experimental', b'evolution.in-memory') + if config_value == b'force': + return True + if repo.ui.hasconfig(b'hooks', b'precommit'): + return False + return stringutil.parsebool(config_value) + def _relocate(repo, orig, dest, evolvestate, pctx=None, keepbranch=False, - category=None): + category=None, update=True): """rewrites the orig rev on dest rev + Also updates bookmarks and creates obsmarkers. + returns the node of new commit which is formed """ if orig.rev() == dest.rev(): @@ -960,11 +972,40 @@ if repo._activebookmark: repo.ui.status(_(b"(leaving bookmark %s)\n") % repo._activebookmark) bookmarksmod.deactivate(repo) - nodenew = _relocatecommit(repo, orig, dest, pctx, keepbranch, commitmsg) + nodenew = _relocatecommit(repo, orig, dest, pctx, keepbranch, commitmsg, + update) _finalizerelocate(repo, orig, dest, nodenew, tr, category, evolvestate) return nodenew -def _relocatecommit(repo, orig, dest, pctx, keepbranch, commitmsg): +def _relocatecommit(repo, orig, dest, pctx, keepbranch, commitmsg, update): + extra = dict(orig.extra()) + if b'branch' in extra: + del extra[b'branch'] + extra[b'rebase_source'] = orig.hex() + targetphase = max(orig.phase(), phases.draft) + configoverrides = { + (b'phases', b'new-commit'): targetphase + } + with repo.ui.configoverride(configoverrides, source=b'evolve'): + if not update and _use_in_memory_merge(repo): + try: + return _relocatecommitinmem( + repo, orig, dest, pctx, keepbranch, commitmsg, extra + ) + except error.InMemoryMergeConflictsError: + repo.ui.status( + b'hit merge conflicts; retrying merge in working copy\n') + return _relocatecommitondisk(repo, orig, dest, pctx, keepbranch, + commitmsg, extra) + +def _relocatecommitondisk(repo, orig, dest, pctx, keepbranch, commitmsg, extra): + """rewrites the orig rev on dest rev on disk + + Creates the new commit by using the old-fashioned way of creating + commits by writing files to the working copy. + + returns the node of new commit which is formed + """ if repo[b'.'].rev() != dest.rev(): compat._update(repo, dest, branchmerge=False, force=True) if keepbranch: @@ -985,19 +1026,55 @@ raise error.InterventionRequired(_(b"unresolved merge conflicts"), hint=hint) - extra = dict(orig.extra()) - if b'branch' in extra: - del extra[b'branch'] - extra[b'rebase_source'] = orig.hex() + # Commit might fail if unresolved files exist + return repo.commit(text=commitmsg, user=orig.user(), + date=orig.date(), extra=extra) + +def _relocatecommitinmem(repo, orig, dest, pctx, keepbranch, commitmsg, extra): + """rewrites the orig rev on dest rev in memory + + Creates the new commit by using the modern way of creating + commits without writing files to the working copy. + + returns the node of new commit which is formed + """ + wctx = context.overlayworkingctx(repo) + wctx.setbase(dest) + + stats = merge.graft( + repo, + orig, + pctx, + [b'destination', b'evolving'], + keepparent=True, + wctx=wctx + ) - targetphase = max(orig.phase(), phases.draft) - configoverride = repo.ui.configoverride({ - (b'phases', b'new-commit'): targetphase - }, source=b'evolve') - with configoverride: - # Commit might fail if unresolved files exist - return repo.commit(text=commitmsg, user=orig.user(), - date=orig.date(), extra=extra) + if stats.unresolvedcount: # some conflict + raise error.InMemoryMergeConflictsError() + + branch = None + if keepbranch: + branch = orig.branch() + # FIXME: We call _compact() because it's required to correctly detect + # changed files. This was added to fix a regression shortly before the 5.5 + # release. A proper fix will be done in the default branch. + wctx._compact() + memctx = wctx.tomemctx( + commitmsg, + date=orig.date(), + extra=extra, + user=orig.user(), + branch=branch, + ) + if memctx.isempty() and not repo.ui.configbool(b'ui', b'allowemptycommit'): + return None + n = repo.commitctx(memctx) + # TODO: Don't update here, update at the end of the whole evolve + # operation instead. + compat.clean_update(repo[n or dest]) + return n + def _finalizerelocate(repo, orig, dest, nodenew, tr, category, evolvestate): if nodenew is not None:
--- a/tests/test-evolve-abort-orphan.t Thu Oct 01 12:34:36 2020 -0700 +++ b/tests/test-evolve-abort-orphan.t Thu Oct 15 15:40:36 2020 -0700 @@ -27,6 +27,14 @@ > EOF #endif +#testcases inmemory ondisk +#if inmemory + $ cat >> $HGRCPATH <<EOF + > [experimental] + > evolution.in-memory = yes + > EOF +#endif + $ hg init abortrepo $ cd abortrepo $ echo ".*\.orig" > .hgignore @@ -97,6 +105,8 @@ $ hg evolve --all move:[4] added d atop:[5] added c + merging d (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging d warning: conflicts while merging d! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -144,6 +154,8 @@ $ hg evolve --all --update move:[4] added d atop:[5] added c + merging d (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging d warning: conflicts while merging d! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -172,6 +184,8 @@ move:[2] added b atop:[7] added a move:[5] added c + merging c (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging c warning: conflicts while merging c! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -284,6 +298,8 @@ atop:[7] added a move:[6] foo to a atop:[7] added a + merging a (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging a warning: conflicts while merging a! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -349,6 +365,8 @@ atop:[7] added a move:[6] foo to a atop:[7] added a + merging a (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging a warning: conflicts while merging a! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -427,6 +445,8 @@ atop:[9] added c move:[6] foo to a atop:[7] added a + merging a (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging a warning: conflicts while merging a! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -503,6 +523,8 @@ move:[2] added b atop:[4] added a move:[3] added c + merging c (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging c warning: conflicts while merging c! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -550,6 +572,8 @@ $ hg next --evolve move:[3] added c atop:[5] added b + merging c (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging c warning: conflicts while merging c! (edit, then use 'hg resolve --mark') unresolved merge conflicts
--- a/tests/test-evolve-abort-phasediv.t Thu Oct 01 12:34:36 2020 -0700 +++ b/tests/test-evolve-abort-phasediv.t Thu Oct 15 15:40:36 2020 -0700 @@ -27,6 +27,14 @@ > EOF #endif +#testcases inmemory ondisk +#if inmemory + $ cat >> $HGRCPATH <<EOF + > [experimental] + > evolution.in-memory = yes + > EOF +#endif + $ hg init abortrepo $ cd abortrepo $ echo ".*\.orig" > .hgignore
--- a/tests/test-evolve-continue.t Thu Oct 01 12:34:36 2020 -0700 +++ b/tests/test-evolve-continue.t Thu Oct 15 15:40:36 2020 -0700 @@ -10,6 +10,14 @@ > EOF $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH +#testcases inmemory ondisk +#if inmemory + $ cat >> $HGRCPATH <<EOF + > [experimental] + > evolution.in-memory = yes + > EOF +#endif + Setting up the repo $ hg init repo @@ -56,6 +64,8 @@ $ hg evolve --all move:[4] added d atop:[5] added c + merging d (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging d warning: conflicts while merging d! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -116,6 +126,8 @@ $ hg evolve --update move:[7] added e atop:[8] added d + merging e (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging e warning: conflicts while merging e! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -156,6 +168,8 @@ $ hg evolve --all --update move:[2] added b atop:[9] added a + merging b (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging b warning: conflicts while merging b! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -241,6 +255,8 @@ move:[12] added d atop:[16] added c move:[13] added f + merging f (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging f warning: conflicts while merging f! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -256,6 +272,8 @@ move:[14] added g atop:[18] added f move:[15] added h + merging h (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging h warning: conflicts while merging h! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -303,6 +321,8 @@ move:[19] added g atop:[21] added f perform evolve? [Ny] y + merging g (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging g warning: conflicts while merging g! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -352,6 +372,8 @@ $ hg next --evolve move:[22] added g atop:[24] added f + merging g (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging g warning: conflicts while merging g! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -419,6 +441,8 @@ $ hg evolve move:[3] added d, modified c atop:[5] added c + merging c (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging c warning: conflicts while merging c! (edit, then use 'hg resolve --mark') unresolved merge conflicts
--- a/tests/test-evolve-inmemory.t Thu Oct 01 12:34:36 2020 -0700 +++ b/tests/test-evolve-inmemory.t Thu Oct 15 15:40:36 2020 -0700 @@ -8,6 +8,8 @@ > drawdag=$RUNTESTDIR/drawdag.py > [alias] > glog = log -G -T '{rev}:{node|short} {separate(" ", phase, tags)}\n{desc|firstline}' + > [experimental] + > evolution.in-memory = yes > EOF Test evolving a single orphan @@ -63,6 +65,8 @@ atop:[2] B2 move:[4] D merging b + hit merge conflicts; retrying merge in working copy + merging b warning: conflicts while merging b! (edit, then use 'hg resolve --mark') unresolved merge conflicts (see 'hg help evolve.interrupted') @@ -98,7 +102,6 @@ evolving 4:57e51f6a6d36 "D" move:[5] E atop:[7] D - working directory is now at 000000000000 $ hg glog o 8:3c658574f8ed draft tip | E @@ -123,3 +126,31 @@ c e $ cd .. + +Test that in-memory merge is disabled if there's a precommit hook + + $ hg init precommit-hook + $ cd precommit-hook + $ hg debugdrawdag <<'EOS' + > C # C/c = c\n + > B2 | # B2/b = b2\n + > | B # B/b = b\n + > \ / # replace: B -> B2 + > A + > EOS + 1 new orphan changesets + $ cat >> .hg/hgrc <<EOF + > [hooks] + > precommit = echo "running precommit hook" + > EOF +The hook is not run with in-memory=force + $ hg evolve --config experimental.evolution.in-memory=force + move:[3] C + atop:[2] B2 + $ hg touch tip^ + 1 new orphan changesets +The hook is run with in-memory=yes + $ hg evolve --config experimental.evolution.in-memory=yes + move:[4] C + atop:[5] B2 + running precommit hook
--- a/tests/test-evolve-noupdate.t Thu Oct 01 12:34:36 2020 -0700 +++ b/tests/test-evolve-noupdate.t Thu Oct 15 15:40:36 2020 -0700 @@ -18,6 +18,14 @@ > EOF $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH +#testcases inmemory ondisk +#if inmemory + $ cat >> $HGRCPATH <<EOF + > [experimental] + > evolution.in-memory = yes + > EOF +#endif + $ hg init stoprepo $ cd stoprepo $ echo ".*\.orig" > .hgignore
--- a/tests/test-evolve-phase.t Thu Oct 01 12:34:36 2020 -0700 +++ b/tests/test-evolve-phase.t Thu Oct 15 15:40:36 2020 -0700 @@ -9,6 +9,14 @@ > EOF $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH +#testcases inmemory ondisk +#if inmemory + $ cat >> $HGRCPATH <<EOF + > [experimental] + > evolution.in-memory = yes + > EOF +#endif + Testing when there are no conflicts during evolve $ hg init noconflict @@ -83,6 +91,8 @@ $ hg evolve move:[2] c atop:[3] b + merging a (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging a warning: conflicts while merging a! (edit, then use 'hg resolve --mark') unresolved merge conflicts
--- a/tests/test-evolve-stop-orphan.t Thu Oct 01 12:34:36 2020 -0700 +++ b/tests/test-evolve-stop-orphan.t Thu Oct 15 15:40:36 2020 -0700 @@ -16,6 +16,14 @@ > EOF $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH +#testcases inmemory ondisk +#if inmemory + $ cat >> $HGRCPATH <<EOF + > [experimental] + > evolution.in-memory = yes + > EOF +#endif + $ hg init stoprepo $ cd stoprepo $ echo ".*\.orig" > .hgignore @@ -88,6 +96,8 @@ $ hg evolve move:[4] added d atop:[5] added c + merging d (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging d warning: conflicts while merging d! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -134,6 +144,8 @@ $ hg next --evolve move:[4] added d atop:[5] added c + merging d (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging d warning: conflicts while merging d! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -196,6 +208,8 @@ $ hg evolve --update move:[4] added d atop:[5] added c + merging d (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging d warning: conflicts while merging d! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -246,6 +260,8 @@ atop:[7] added hgignore move:[2] added b move:[5] added c + merging c (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging c warning: conflicts while merging c! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -284,6 +300,8 @@ $ hg evolve --all move:[5] added c atop:[9] added b + merging c (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging c warning: conflicts while merging c! (edit, then use 'hg resolve --mark') unresolved merge conflicts @@ -359,6 +377,8 @@ move:[9] added b atop:[12] added a move:[10] added c + merging c (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging c warning: conflicts while merging c! (edit, then use 'hg resolve --mark') unresolved merge conflicts
--- a/tests/test-evolve-stop-phasediv.t Thu Oct 01 12:34:36 2020 -0700 +++ b/tests/test-evolve-stop-phasediv.t Thu Oct 15 15:40:36 2020 -0700 @@ -16,6 +16,14 @@ > EOF $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH +#testcases inmemory ondisk +#if inmemory + $ cat >> $HGRCPATH <<EOF + > [experimental] + > evolution.in-memory = yes + > EOF +#endif + $ hg init stoprepo $ cd stoprepo $ echo ".*\.orig" > .hgignore
--- a/tests/test-evolve-wdir.t Thu Oct 01 12:34:36 2020 -0700 +++ b/tests/test-evolve-wdir.t Thu Oct 15 15:40:36 2020 -0700 @@ -35,6 +35,14 @@ > glog = log --graph --template "{rev}:{node|short} ({phase}): {desc|firstline} {if(troubles, '[{troubles}]')}\n" > EOF +#testcases inmemory ondisk +#if inmemory + $ cat >> $HGRCPATH <<EOF + > [experimental] + > evolution.in-memory = yes + > EOF +#endif + $ hg init repo $ cd repo $ mkcommit c_A
--- a/tests/test-evolve.t Thu Oct 01 12:34:36 2020 -0700 +++ b/tests/test-evolve.t Thu Oct 15 15:40:36 2020 -0700 @@ -16,6 +16,15 @@ > [extensions] > EOF $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH + +#testcases inmemory ondisk +#if inmemory + $ cat >> $HGRCPATH <<EOF + > [experimental] + > evolution.in-memory = yes + > EOF +#endif + $ mkcommit() { > echo "$1" > "$1" > hg add "$1" @@ -1407,6 +1416,8 @@ move:[30] will be evolved safely atop:[32] amended move:[31] will cause conflict at evolve + merging newfile (inmemory !) + hit merge conflicts; retrying merge in working copy (inmemory !) merging newfile warning: conflicts while merging newfile! (edit, then use 'hg resolve --mark') unresolved merge conflicts
--- a/tests/test-stabilize-order.t Thu Oct 01 12:34:36 2020 -0700 +++ b/tests/test-stabilize-order.t Thu Oct 15 15:40:36 2020 -0700 @@ -5,6 +5,14 @@ > EOF $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH +#testcases inmemory ondisk +#if inmemory + $ cat >> $HGRCPATH <<EOF + > [experimental] + > evolution.in-memory = yes + > EOF +#endif + $ glog() { > hg log -G --template '{rev}:{node|short}@{branch}({phase}) {desc|firstline}\n' "$@" > } @@ -72,6 +80,8 @@ b committing manifest committing changelog + resolving manifests (inmemory !) + getting b (inmemory !) resolving manifests removing b $ glog @@ -95,14 +105,17 @@ move:[3] addc atop:[6] addb hg rebase -r 7a7552255fb5 -d 81b8bbcd5892 - resolving manifests - getting b + resolving manifests (ondisk !) + getting b (ondisk !) resolving manifests getting c committing files: c committing manifest committing changelog + resolving manifests (inmemory !) + getting b (inmemory !) + getting c (inmemory !) working directory is now at 0f691739f917 $ hg debugobsolete > successors.new $ diff -u successors.old successors.new @@ -157,15 +170,17 @@ move:[7] addc atop:[8] addb hg rebase -r 0f691739f917 -d 7a68bc4596ea - resolving manifests - removing c - getting b + resolving manifests (ondisk !) + removing c (ondisk !) + getting b (ondisk !) resolving manifests getting c committing files: c committing manifest committing changelog + resolving manifests (inmemory !) + getting b (inmemory !) working directory is now at 2256dae6521f $ glog @ 9:2256dae6521f@default(draft) addc