##// END OF EJS Templates
split: use rewriteutil.precheck() instead of reimplementing it...
Martin von Zweigbergk -
r44387:2349a60f default
parent child Browse files
Show More
@@ -22,11 +22,10 b' from mercurial import ('
22 commands,
22 commands,
23 error,
23 error,
24 hg,
24 hg,
25 obsolete,
26 phases,
27 pycompat,
25 pycompat,
28 registrar,
26 registrar,
29 revsetlang,
27 revsetlang,
28 rewriteutil,
30 scmutil,
29 scmutil,
31 )
30 )
32
31
@@ -77,45 +76,26 b' def split(ui, repo, *revs, **opts):'
77
76
78 rev = revs.first()
77 rev = revs.first()
79 ctx = repo[rev]
78 ctx = repo[rev]
79 # Handle nullid specially here (instead of leaving for precheck()
80 # below) so we get a nicer message and error code.
80 if rev is None or ctx.node() == nullid:
81 if rev is None or ctx.node() == nullid:
81 ui.status(_(b'nothing to split\n'))
82 ui.status(_(b'nothing to split\n'))
82 return 1
83 return 1
83 if ctx.node() is None:
84 if ctx.node() is None:
84 raise error.Abort(_(b'cannot split working directory'))
85 raise error.Abort(_(b'cannot split working directory'))
85
86
86 # rewriteutil.precheck is not very useful here because:
87 # 1. null check is done above and it's more friendly to return 1
88 # instead of abort
89 # 2. mergestate check is done below by cmdutil.bailifchanged
90 # 3. unstable check is more complex here because of --rebase
91 #
92 # So only "public" check is useful and it's checked directly here.
93 if ctx.phase() == phases.public:
94 raise error.Abort(
95 _(b'cannot split public changeset'),
96 hint=_(b"see 'hg help phases' for details"),
97 )
98
99 descendants = list(repo.revs(b'(%d::) - (%d)', rev, rev))
100 alloworphaned = obsolete.isenabled(repo, obsolete.allowunstableopt)
101 if opts.get(b'rebase'):
87 if opts.get(b'rebase'):
102 # Skip obsoleted descendants and their descendants so the rebase
88 # Skip obsoleted descendants and their descendants so the rebase
103 # won't cause conflicts for sure.
89 # won't cause conflicts for sure.
90 descendants = list(repo.revs(b'(%d::) - (%d)', rev, rev))
104 torebase = list(
91 torebase = list(
105 repo.revs(
92 repo.revs(
106 b'%ld - (%ld & obsolete())::', descendants, descendants
93 b'%ld - (%ld & obsolete())::', descendants, descendants
107 )
94 )
108 )
95 )
109 if not alloworphaned and len(torebase) != len(descendants):
110 raise error.Abort(
111 _(b'split would leave orphaned changesets behind')
112 )
113 else:
96 else:
114 if not alloworphaned and descendants:
97 torebase = []
115 raise error.Abort(
98 rewriteutil.precheck(repo, [rev] + torebase, b'split')
116 _(b'cannot split changeset with children without rebase')
117 )
118 torebase = ()
119
99
120 if len(ctx.parents()) > 1:
100 if len(ctx.parents()) > 1:
121 raise error.Abort(_(b'cannot split a merge changeset'))
101 raise error.Abort(_(b'cannot split a merge changeset'))
@@ -77,7 +77,7 b' Cannot split a public changeset'
77
77
78 $ hg phase --public -r 'all()'
78 $ hg phase --public -r 'all()'
79 $ hg split .
79 $ hg split .
80 abort: cannot split public changeset
80 abort: cannot split public changesets
81 (see 'hg help phases' for details)
81 (see 'hg help phases' for details)
82 [255]
82 [255]
83
83
@@ -466,7 +466,7 b' Split a non-head without rebase'
466 $ cd $TESTTMP/d
466 $ cd $TESTTMP/d
467 #if obsstore-off
467 #if obsstore-off
468 $ runsplit -r 1 --no-rebase
468 $ runsplit -r 1 --no-rebase
469 abort: cannot split changeset with children without rebase
469 abort: cannot split changeset with children
470 [255]
470 [255]
471 #else
471 #else
472 $ runsplit -r 1 --no-rebase >/dev/null
472 $ runsplit -r 1 --no-rebase >/dev/null
@@ -517,7 +517,7 b' Split a non-head with obsoleted descenda'
517 $ eval `hg tags -T '{tag}={node}\n'`
517 $ eval `hg tags -T '{tag}={node}\n'`
518 $ rm .hg/localtags
518 $ rm .hg/localtags
519 $ hg split $B --config experimental.evolution=createmarkers
519 $ hg split $B --config experimental.evolution=createmarkers
520 abort: split would leave orphaned changesets behind
520 abort: cannot split changeset with children
521 [255]
521 [255]
522 $ cat > $TESTTMP/messages <<EOF
522 $ cat > $TESTTMP/messages <<EOF
523 > Split B
523 > Split B
General Comments 0
You need to be logged in to leave comments. Login now