Mercurial > hg
comparison hgext/split.py @ 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 | 705738def50c |
children | 84ce9ffc95ad |
comparison
equal
deleted
inserted
replaced
43934:71fee4564410 | 43935:2349a60f33db |
---|---|
20 bookmarks, | 20 bookmarks, |
21 cmdutil, | 21 cmdutil, |
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 |
33 # allow people to use split without explicitly enabling rebase extension | 32 # allow people to use split without explicitly enabling rebase extension |
34 from . import rebase | 33 from . import rebase |
75 if len(revs) > 1: | 74 if len(revs) > 1: |
76 raise error.Abort(_(b'cannot split multiple revisions')) | 75 raise error.Abort(_(b'cannot split multiple revisions')) |
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')) |
122 | 102 |
123 cmdutil.bailifchanged(repo) | 103 cmdutil.bailifchanged(repo) |