comparison hgext/split.py @ 43077:687b865b95ad

formatting: byteify all mercurial/ and hgext/ string literals Done with python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py') black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**') # skip-blame mass-reformatting only Differential Revision: https://phab.mercurial-scm.org/D6972
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:48:39 -0400
parents 2372284d9457
children 8ff1ecfadcd1
comparison
equal deleted inserted replaced
43076:2372284d9457 43077:687b865b95ad
38 38
39 # 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
40 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should 40 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
41 # 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
42 # leave the attribute unspecified. 42 # leave the attribute unspecified.
43 testedwith = 'ships-with-hg-core' 43 testedwith = b'ships-with-hg-core'
44 44
45 45
46 @command( 46 @command(
47 'split', 47 b'split',
48 [ 48 [
49 ('r', 'rev', '', _("revision to split"), _('REV')), 49 (b'r', b'rev', b'', _(b"revision to split"), _(b'REV')),
50 ('', 'rebase', True, _('rebase descendants after split')), 50 (b'', b'rebase', True, _(b'rebase descendants after split')),
51 ] 51 ]
52 + cmdutil.commitopts2, 52 + cmdutil.commitopts2,
53 _('hg split [--no-rebase] [[-r] REV]'), 53 _(b'hg split [--no-rebase] [[-r] REV]'),
54 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, 54 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT,
55 helpbasic=True, 55 helpbasic=True,
56 ) 56 )
57 def split(ui, repo, *revs, **opts): 57 def split(ui, repo, *revs, **opts):
58 """split a changeset into smaller ones 58 """split a changeset into smaller ones
65 By default, rebase connected non-obsoleted descendants onto the new 65 By default, rebase connected non-obsoleted descendants onto the new
66 changeset. Use --no-rebase to avoid the rebase. 66 changeset. Use --no-rebase to avoid the rebase.
67 """ 67 """
68 opts = pycompat.byteskwargs(opts) 68 opts = pycompat.byteskwargs(opts)
69 revlist = [] 69 revlist = []
70 if opts.get('rev'): 70 if opts.get(b'rev'):
71 revlist.append(opts.get('rev')) 71 revlist.append(opts.get(b'rev'))
72 revlist.extend(revs) 72 revlist.extend(revs)
73 with repo.wlock(), repo.lock(), repo.transaction('split') as tr: 73 with repo.wlock(), repo.lock(), repo.transaction(b'split') as tr:
74 revs = scmutil.revrange(repo, revlist or ['.']) 74 revs = scmutil.revrange(repo, revlist or [b'.'])
75 if len(revs) > 1: 75 if len(revs) > 1:
76 raise error.Abort(_('cannot split multiple revisions')) 76 raise error.Abort(_(b'cannot split multiple revisions'))
77 77
78 rev = revs.first() 78 rev = revs.first()
79 ctx = repo[rev] 79 ctx = repo[rev]
80 if rev is None or ctx.node() == nullid: 80 if rev is None or ctx.node() == nullid:
81 ui.status(_('nothing to split\n')) 81 ui.status(_(b'nothing to split\n'))
82 return 1 82 return 1
83 if ctx.node() is None: 83 if ctx.node() is None:
84 raise error.Abort(_('cannot split working directory')) 84 raise error.Abort(_(b'cannot split working directory'))
85 85
86 # rewriteutil.precheck is not very useful here because: 86 # rewriteutil.precheck is not very useful here because:
87 # 1. null check is done above and it's more friendly to return 1 87 # 1. null check is done above and it's more friendly to return 1
88 # instead of abort 88 # instead of abort
89 # 2. mergestate check is done below by cmdutil.bailifchanged 89 # 2. mergestate check is done below by cmdutil.bailifchanged
90 # 3. unstable check is more complex here because of --rebase 90 # 3. unstable check is more complex here because of --rebase
91 # 91 #
92 # 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.
93 if ctx.phase() == phases.public: 93 if ctx.phase() == phases.public:
94 raise error.Abort( 94 raise error.Abort(
95 _('cannot split public changeset'), 95 _(b'cannot split public changeset'),
96 hint=_("see 'hg help phases' for details"), 96 hint=_(b"see 'hg help phases' for details"),
97 ) 97 )
98 98
99 descendants = list(repo.revs('(%d::) - (%d)', rev, rev)) 99 descendants = list(repo.revs(b'(%d::) - (%d)', rev, rev))
100 alloworphaned = obsolete.isenabled(repo, obsolete.allowunstableopt) 100 alloworphaned = obsolete.isenabled(repo, obsolete.allowunstableopt)
101 if opts.get('rebase'): 101 if opts.get(b'rebase'):
102 # Skip obsoleted descendants and their descendants so the rebase 102 # Skip obsoleted descendants and their descendants so the rebase
103 # won't cause conflicts for sure. 103 # won't cause conflicts for sure.
104 torebase = list( 104 torebase = list(
105 repo.revs( 105 repo.revs(
106 '%ld - (%ld & obsolete())::', descendants, descendants 106 b'%ld - (%ld & obsolete())::', descendants, descendants
107 ) 107 )
108 ) 108 )
109 if not alloworphaned and len(torebase) != len(descendants): 109 if not alloworphaned and len(torebase) != len(descendants):
110 raise error.Abort( 110 raise error.Abort(
111 _('split would leave orphaned changesets ' 'behind') 111 _(b'split would leave orphaned changesets ' b'behind')
112 ) 112 )
113 else: 113 else:
114 if not alloworphaned and descendants: 114 if not alloworphaned and descendants:
115 raise error.Abort( 115 raise error.Abort(
116 _('cannot split changeset with children without rebase') 116 _(b'cannot split changeset with children without rebase')
117 ) 117 )
118 torebase = () 118 torebase = ()
119 119
120 if len(ctx.parents()) > 1: 120 if len(ctx.parents()) > 1:
121 raise error.Abort(_('cannot split a merge changeset')) 121 raise error.Abort(_(b'cannot split a merge changeset'))
122 122
123 cmdutil.bailifchanged(repo) 123 cmdutil.bailifchanged(repo)
124 124
125 # Deactivate bookmark temporarily so it won't get moved unintentionally 125 # Deactivate bookmark temporarily so it won't get moved unintentionally
126 bname = repo._activebookmark 126 bname = repo._activebookmark
127 if bname and repo._bookmarks[bname] != ctx.node(): 127 if bname and repo._bookmarks[bname] != ctx.node():
128 bookmarks.deactivate(repo) 128 bookmarks.deactivate(repo)
129 129
130 wnode = repo['.'].node() 130 wnode = repo[b'.'].node()
131 top = None 131 top = None
132 try: 132 try:
133 top = dosplit(ui, repo, tr, ctx, opts) 133 top = dosplit(ui, repo, tr, ctx, opts)
134 finally: 134 finally:
135 # top is None: split failed, need update --clean recovery. 135 # top is None: split failed, need update --clean recovery.
156 156
157 # Main split loop 157 # Main split loop
158 while incomplete(repo): 158 while incomplete(repo):
159 if committed: 159 if committed:
160 header = _( 160 header = _(
161 'HG: Splitting %s. So far it has been split into:\n' 161 b'HG: Splitting %s. So far it has been split into:\n'
162 ) % short(ctx.node()) 162 ) % short(ctx.node())
163 for c in committed: 163 for c in committed:
164 firstline = c.description().split('\n', 1)[0] 164 firstline = c.description().split(b'\n', 1)[0]
165 header += _('HG: - %s: %s\n') % (short(c.node()), firstline) 165 header += _(b'HG: - %s: %s\n') % (short(c.node()), firstline)
166 header += _( 166 header += _(
167 'HG: Write commit message for the next split ' 'changeset.\n' 167 b'HG: Write commit message for the next split ' b'changeset.\n'
168 ) 168 )
169 else: 169 else:
170 header = _( 170 header = _(
171 'HG: Splitting %s. Write commit message for the ' 171 b'HG: Splitting %s. Write commit message for the '
172 'first split changeset.\n' 172 b'first split changeset.\n'
173 ) % short(ctx.node()) 173 ) % short(ctx.node())
174 opts.update( 174 opts.update(
175 { 175 {
176 'edit': True, 176 b'edit': True,
177 'interactive': True, 177 b'interactive': True,
178 'message': header + ctx.description(), 178 b'message': header + ctx.description(),
179 } 179 }
180 ) 180 )
181 commands.commit(ui, repo, **pycompat.strkwargs(opts)) 181 commands.commit(ui, repo, **pycompat.strkwargs(opts))
182 newctx = repo['.'] 182 newctx = repo[b'.']
183 committed.append(newctx) 183 committed.append(newctx)
184 184
185 if not committed: 185 if not committed:
186 raise error.Abort(_('cannot split an empty revision')) 186 raise error.Abort(_(b'cannot split an empty revision'))
187 187
188 scmutil.cleanupnodes( 188 scmutil.cleanupnodes(
189 repo, 189 repo,
190 {ctx.node(): [c.node() for c in committed]}, 190 {ctx.node(): [c.node() for c in committed]},
191 operation='split', 191 operation=b'split',
192 fixphase=True, 192 fixphase=True,
193 ) 193 )
194 194
195 return committed[-1] 195 return committed[-1]
196 196
197 197
198 def dorebase(ui, repo, src, destctx): 198 def dorebase(ui, repo, src, destctx):
199 rebase.rebase( 199 rebase.rebase(
200 ui, 200 ui,
201 repo, 201 repo,
202 rev=[revsetlang.formatspec('%ld', src)], 202 rev=[revsetlang.formatspec(b'%ld', src)],
203 dest=revsetlang.formatspec('%d', destctx.rev()), 203 dest=revsetlang.formatspec(b'%d', destctx.rev()),
204 ) 204 )