Mercurial > hg
comparison hgext/split.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 42e2c7c52e1b |
children | 687b865b95ad |
comparison
equal
deleted
inserted
replaced
43075:57875cf423c9 | 43076:2372284d9457 |
---|---|
29 revsetlang, | 29 revsetlang, |
30 scmutil, | 30 scmutil, |
31 ) | 31 ) |
32 | 32 |
33 # allow people to use split without explicitly enabling rebase extension | 33 # allow people to use split without explicitly enabling rebase extension |
34 from . import ( | 34 from . import rebase |
35 rebase, | |
36 ) | |
37 | 35 |
38 cmdtable = {} | 36 cmdtable = {} |
39 command = registrar.command(cmdtable) | 37 command = registrar.command(cmdtable) |
40 | 38 |
41 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for | 39 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
42 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should | 40 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
43 # be specifying the version(s) of Mercurial they are tested with, or | 41 # be specifying the version(s) of Mercurial they are tested with, or |
44 # leave the attribute unspecified. | 42 # leave the attribute unspecified. |
45 testedwith = 'ships-with-hg-core' | 43 testedwith = 'ships-with-hg-core' |
46 | 44 |
47 @command('split', | 45 |
48 [('r', 'rev', '', _("revision to split"), _('REV')), | 46 @command( |
49 ('', 'rebase', True, _('rebase descendants after split')), | 47 'split', |
50 ] + cmdutil.commitopts2, | 48 [ |
49 ('r', 'rev', '', _("revision to split"), _('REV')), | |
50 ('', 'rebase', True, _('rebase descendants after split')), | |
51 ] | |
52 + cmdutil.commitopts2, | |
51 _('hg split [--no-rebase] [[-r] REV]'), | 53 _('hg split [--no-rebase] [[-r] REV]'), |
52 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, helpbasic=True) | 54 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, |
55 helpbasic=True, | |
56 ) | |
53 def split(ui, repo, *revs, **opts): | 57 def split(ui, repo, *revs, **opts): |
54 """split a changeset into smaller ones | 58 """split a changeset into smaller ones |
55 | 59 |
56 Repeatedly prompt changes and commit message for new changesets until there | 60 Repeatedly prompt changes and commit message for new changesets until there |
57 is nothing left in the original changeset. | 61 is nothing left in the original changeset. |
85 # 2. mergestate check is done below by cmdutil.bailifchanged | 89 # 2. mergestate check is done below by cmdutil.bailifchanged |
86 # 3. unstable check is more complex here because of --rebase | 90 # 3. unstable check is more complex here because of --rebase |
87 # | 91 # |
88 # So only "public" check is useful and it's checked directly here. | 92 # So only "public" check is useful and it's checked directly here. |
89 if ctx.phase() == phases.public: | 93 if ctx.phase() == phases.public: |
90 raise error.Abort(_('cannot split public changeset'), | 94 raise error.Abort( |
91 hint=_("see 'hg help phases' for details")) | 95 _('cannot split public changeset'), |
96 hint=_("see 'hg help phases' for details"), | |
97 ) | |
92 | 98 |
93 descendants = list(repo.revs('(%d::) - (%d)', rev, rev)) | 99 descendants = list(repo.revs('(%d::) - (%d)', rev, rev)) |
94 alloworphaned = obsolete.isenabled(repo, obsolete.allowunstableopt) | 100 alloworphaned = obsolete.isenabled(repo, obsolete.allowunstableopt) |
95 if opts.get('rebase'): | 101 if opts.get('rebase'): |
96 # Skip obsoleted descendants and their descendants so the rebase | 102 # Skip obsoleted descendants and their descendants so the rebase |
97 # won't cause conflicts for sure. | 103 # won't cause conflicts for sure. |
98 torebase = list(repo.revs('%ld - (%ld & obsolete())::', | 104 torebase = list( |
99 descendants, descendants)) | 105 repo.revs( |
106 '%ld - (%ld & obsolete())::', descendants, descendants | |
107 ) | |
108 ) | |
100 if not alloworphaned and len(torebase) != len(descendants): | 109 if not alloworphaned and len(torebase) != len(descendants): |
101 raise error.Abort(_('split would leave orphaned changesets ' | 110 raise error.Abort( |
102 'behind')) | 111 _('split would leave orphaned changesets ' 'behind') |
112 ) | |
103 else: | 113 else: |
104 if not alloworphaned and descendants: | 114 if not alloworphaned and descendants: |
105 raise error.Abort( | 115 raise error.Abort( |
106 _('cannot split changeset with children without rebase')) | 116 _('cannot split changeset with children without rebase') |
117 ) | |
107 torebase = () | 118 torebase = () |
108 | 119 |
109 if len(ctx.parents()) > 1: | 120 if len(ctx.parents()) > 1: |
110 raise error.Abort(_('cannot split a merge changeset')) | 121 raise error.Abort(_('cannot split a merge changeset')) |
111 | 122 |
128 if bname: | 139 if bname: |
129 bookmarks.activate(repo, bname) | 140 bookmarks.activate(repo, bname) |
130 if torebase and top: | 141 if torebase and top: |
131 dorebase(ui, repo, torebase, top) | 142 dorebase(ui, repo, torebase, top) |
132 | 143 |
144 | |
133 def dosplit(ui, repo, tr, ctx, opts): | 145 def dosplit(ui, repo, tr, ctx, opts): |
134 committed = [] # [ctx] | 146 committed = [] # [ctx] |
135 | 147 |
136 # Set working parent to ctx.p1(), and keep working copy as ctx's content | 148 # Set working parent to ctx.p1(), and keep working copy as ctx's content |
137 if ctx.node() != repo.dirstate.p1(): | 149 if ctx.node() != repo.dirstate.p1(): |
138 hg.clean(repo, ctx.node(), show_stats=False) | 150 hg.clean(repo, ctx.node(), show_stats=False) |
139 with repo.dirstate.parentchange(): | 151 with repo.dirstate.parentchange(): |
143 incomplete = lambda repo: any(repo.status()[:4]) | 155 incomplete = lambda repo: any(repo.status()[:4]) |
144 | 156 |
145 # Main split loop | 157 # Main split loop |
146 while incomplete(repo): | 158 while incomplete(repo): |
147 if committed: | 159 if committed: |
148 header = (_('HG: Splitting %s. So far it has been split into:\n') | 160 header = _( |
149 % short(ctx.node())) | 161 'HG: Splitting %s. So far it has been split into:\n' |
162 ) % short(ctx.node()) | |
150 for c in committed: | 163 for c in committed: |
151 firstline = c.description().split('\n', 1)[0] | 164 firstline = c.description().split('\n', 1)[0] |
152 header += _('HG: - %s: %s\n') % (short(c.node()), firstline) | 165 header += _('HG: - %s: %s\n') % (short(c.node()), firstline) |
153 header += _('HG: Write commit message for the next split ' | 166 header += _( |
154 'changeset.\n') | 167 'HG: Write commit message for the next split ' 'changeset.\n' |
168 ) | |
155 else: | 169 else: |
156 header = _('HG: Splitting %s. Write commit message for the ' | 170 header = _( |
157 'first split changeset.\n') % short(ctx.node()) | 171 'HG: Splitting %s. Write commit message for the ' |
158 opts.update({ | 172 'first split changeset.\n' |
159 'edit': True, | 173 ) % short(ctx.node()) |
160 'interactive': True, | 174 opts.update( |
161 'message': header + ctx.description(), | 175 { |
162 }) | 176 'edit': True, |
177 'interactive': True, | |
178 'message': header + ctx.description(), | |
179 } | |
180 ) | |
163 commands.commit(ui, repo, **pycompat.strkwargs(opts)) | 181 commands.commit(ui, repo, **pycompat.strkwargs(opts)) |
164 newctx = repo['.'] | 182 newctx = repo['.'] |
165 committed.append(newctx) | 183 committed.append(newctx) |
166 | 184 |
167 if not committed: | 185 if not committed: |
168 raise error.Abort(_('cannot split an empty revision')) | 186 raise error.Abort(_('cannot split an empty revision')) |
169 | 187 |
170 scmutil.cleanupnodes(repo, {ctx.node(): [c.node() for c in committed]}, | 188 scmutil.cleanupnodes( |
171 operation='split', fixphase=True) | 189 repo, |
190 {ctx.node(): [c.node() for c in committed]}, | |
191 operation='split', | |
192 fixphase=True, | |
193 ) | |
172 | 194 |
173 return committed[-1] | 195 return committed[-1] |
174 | 196 |
197 | |
175 def dorebase(ui, repo, src, destctx): | 198 def dorebase(ui, repo, src, destctx): |
176 rebase.rebase(ui, repo, rev=[revsetlang.formatspec('%ld', src)], | 199 rebase.rebase( |
177 dest=revsetlang.formatspec('%d', destctx.rev())) | 200 ui, |
201 repo, | |
202 rev=[revsetlang.formatspec('%ld', src)], | |
203 dest=revsetlang.formatspec('%d', destctx.rev()), | |
204 ) |