Mercurial > hg
changeset 43935:2349a60f33db
split: use rewriteutil.precheck() instead of reimplementing it
As you can see from the patch, I disagree with most of the comment
saying that `rewriteutil.precheck()` is not worthwhile.
Differential Revision: https://phab.mercurial-scm.org/D7686
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 17 Dec 2019 11:09:22 -0800 |
parents | 71fee4564410 |
children | 699d6be3820a |
files | hgext/split.py tests/test-split.t |
diffstat | 2 files changed, 9 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/split.py Wed Dec 18 09:18:02 2019 +0300 +++ b/hgext/split.py Tue Dec 17 11:09:22 2019 -0800 @@ -22,11 +22,10 @@ commands, error, hg, - obsolete, - phases, pycompat, registrar, revsetlang, + rewriteutil, scmutil, ) @@ -77,45 +76,26 @@ rev = revs.first() ctx = repo[rev] + # Handle nullid specially here (instead of leaving for precheck() + # below) so we get a nicer message and error code. if rev is None or ctx.node() == nullid: ui.status(_(b'nothing to split\n')) return 1 if ctx.node() is None: raise error.Abort(_(b'cannot split working directory')) - # rewriteutil.precheck is not very useful here because: - # 1. null check is done above and it's more friendly to return 1 - # instead of abort - # 2. mergestate check is done below by cmdutil.bailifchanged - # 3. unstable check is more complex here because of --rebase - # - # So only "public" check is useful and it's checked directly here. - if ctx.phase() == phases.public: - raise error.Abort( - _(b'cannot split public changeset'), - hint=_(b"see 'hg help phases' for details"), - ) - - descendants = list(repo.revs(b'(%d::) - (%d)', rev, rev)) - alloworphaned = obsolete.isenabled(repo, obsolete.allowunstableopt) if opts.get(b'rebase'): # Skip obsoleted descendants and their descendants so the rebase # won't cause conflicts for sure. + descendants = list(repo.revs(b'(%d::) - (%d)', rev, rev)) torebase = list( repo.revs( b'%ld - (%ld & obsolete())::', descendants, descendants ) ) - if not alloworphaned and len(torebase) != len(descendants): - raise error.Abort( - _(b'split would leave orphaned changesets behind') - ) else: - if not alloworphaned and descendants: - raise error.Abort( - _(b'cannot split changeset with children without rebase') - ) - torebase = () + torebase = [] + rewriteutil.precheck(repo, [rev] + torebase, b'split') if len(ctx.parents()) > 1: raise error.Abort(_(b'cannot split a merge changeset'))
--- a/tests/test-split.t Wed Dec 18 09:18:02 2019 +0300 +++ b/tests/test-split.t Tue Dec 17 11:09:22 2019 -0800 @@ -77,7 +77,7 @@ $ hg phase --public -r 'all()' $ hg split . - abort: cannot split public changeset + abort: cannot split public changesets (see 'hg help phases' for details) [255] @@ -466,7 +466,7 @@ $ cd $TESTTMP/d #if obsstore-off $ runsplit -r 1 --no-rebase - abort: cannot split changeset with children without rebase + abort: cannot split changeset with children [255] #else $ runsplit -r 1 --no-rebase >/dev/null @@ -517,7 +517,7 @@ $ eval `hg tags -T '{tag}={node}\n'` $ rm .hg/localtags $ hg split $B --config experimental.evolution=createmarkers - abort: split would leave orphaned changesets behind + abort: cannot split changeset with children [255] $ cat > $TESTTMP/messages <<EOF > Split B