comparison hgext/uncommit.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 649d3ac37a12
comparison
equal deleted inserted replaced
43076:2372284d9457 43077:687b865b95ad
41 41
42 configtable = {} 42 configtable = {}
43 configitem = registrar.configitem(configtable) 43 configitem = registrar.configitem(configtable)
44 44
45 configitem( 45 configitem(
46 'experimental', 'uncommitondirtywdir', default=False, 46 b'experimental', b'uncommitondirtywdir', default=False,
47 ) 47 )
48 configitem( 48 configitem(
49 'experimental', 'uncommit.keep', default=False, 49 b'experimental', b'uncommit.keep', default=False,
50 ) 50 )
51 51
52 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for 52 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
53 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should 53 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
54 # be specifying the version(s) of Mercurial they are tested with, or 54 # be specifying the version(s) of Mercurial they are tested with, or
55 # leave the attribute unspecified. 55 # leave the attribute unspecified.
56 testedwith = 'ships-with-hg-core' 56 testedwith = b'ships-with-hg-core'
57 57
58 58
59 def _commitfiltered( 59 def _commitfiltered(
60 repo, ctx, match, keepcommit, message=None, user=None, date=None 60 repo, ctx, match, keepcommit, message=None, user=None, date=None
61 ): 61 ):
94 copysource=copied.get(path), 94 copysource=copied.get(path),
95 ) 95 )
96 return mctx 96 return mctx
97 97
98 if not files: 98 if not files:
99 repo.ui.status(_("note: keeping empty commit\n")) 99 repo.ui.status(_(b"note: keeping empty commit\n"))
100 100
101 if message is None: 101 if message is None:
102 message = ctx.description() 102 message = ctx.description()
103 if not user: 103 if not user:
104 user = ctx.user() 104 user = ctx.user()
117 ) 117 )
118 return repo.commitctx(new) 118 return repo.commitctx(new)
119 119
120 120
121 @command( 121 @command(
122 'uncommit', 122 b'uncommit',
123 [ 123 [
124 ('', 'keep', None, _('allow an empty commit after uncommitting')), 124 (b'', b'keep', None, _(b'allow an empty commit after uncommitting')),
125 ( 125 (
126 '', 126 b'',
127 'allow-dirty-working-copy', 127 b'allow-dirty-working-copy',
128 False, 128 False,
129 _('allow uncommit with outstanding changes'), 129 _(b'allow uncommit with outstanding changes'),
130 ), 130 ),
131 (b'n', b'note', b'', _(b'store a note on uncommit'), _(b'TEXT')), 131 (b'n', b'note', b'', _(b'store a note on uncommit'), _(b'TEXT')),
132 ] 132 ]
133 + commands.walkopts 133 + commands.walkopts
134 + commands.commitopts 134 + commands.commitopts
135 + commands.commitopts2 135 + commands.commitopts2
136 + commands.commitopts3, 136 + commands.commitopts3,
137 _('[OPTION]... [FILE]...'), 137 _(b'[OPTION]... [FILE]...'),
138 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, 138 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT,
139 ) 139 )
140 def uncommit(ui, repo, *pats, **opts): 140 def uncommit(ui, repo, *pats, **opts):
141 """uncommit part or all of a local changeset 141 """uncommit part or all of a local changeset
142 142
156 with repo.wlock(), repo.lock(): 156 with repo.wlock(), repo.lock():
157 157
158 m, a, r, d = repo.status()[:4] 158 m, a, r, d = repo.status()[:4]
159 isdirtypath = any(set(m + a + r + d) & set(pats)) 159 isdirtypath = any(set(m + a + r + d) & set(pats))
160 allowdirtywcopy = opts[ 160 allowdirtywcopy = opts[
161 'allow_dirty_working_copy' 161 b'allow_dirty_working_copy'
162 ] or repo.ui.configbool('experimental', 'uncommitondirtywdir') 162 ] or repo.ui.configbool(b'experimental', b'uncommitondirtywdir')
163 if not allowdirtywcopy and (not pats or isdirtypath): 163 if not allowdirtywcopy and (not pats or isdirtypath):
164 cmdutil.bailifchanged( 164 cmdutil.bailifchanged(
165 repo, 165 repo,
166 hint=_('requires ' '--allow-dirty-working-copy to uncommit'), 166 hint=_(b'requires ' b'--allow-dirty-working-copy to uncommit'),
167 ) 167 )
168 old = repo['.'] 168 old = repo[b'.']
169 rewriteutil.precheck(repo, [old.rev()], 'uncommit') 169 rewriteutil.precheck(repo, [old.rev()], b'uncommit')
170 if len(old.parents()) > 1: 170 if len(old.parents()) > 1:
171 raise error.Abort(_("cannot uncommit merge changeset")) 171 raise error.Abort(_(b"cannot uncommit merge changeset"))
172 172
173 match = scmutil.match(old, pats, opts) 173 match = scmutil.match(old, pats, opts)
174 174
175 # Check all explicitly given files; abort if there's a problem. 175 # Check all explicitly given files; abort if there's a problem.
176 if match.files(): 176 if match.files():
198 raise error.Abort( 198 raise error.Abort(
199 _(b'cannot uncommit "%s"') % scmutil.getuipathfn(repo)(f), 199 _(b'cannot uncommit "%s"') % scmutil.getuipathfn(repo)(f),
200 hint=hint, 200 hint=hint,
201 ) 201 )
202 202
203 with repo.transaction('uncommit'): 203 with repo.transaction(b'uncommit'):
204 if not (opts[b'message'] or opts[b'logfile']): 204 if not (opts[b'message'] or opts[b'logfile']):
205 opts[b'message'] = old.description() 205 opts[b'message'] = old.description()
206 message = cmdutil.logmessage(ui, opts) 206 message = cmdutil.logmessage(ui, opts)
207 207
208 keepcommit = pats 208 keepcommit = pats
209 if not keepcommit: 209 if not keepcommit:
210 if opts.get('keep') is not None: 210 if opts.get(b'keep') is not None:
211 keepcommit = opts.get('keep') 211 keepcommit = opts.get(b'keep')
212 else: 212 else:
213 keepcommit = ui.configbool('experimental', 'uncommit.keep') 213 keepcommit = ui.configbool(
214 b'experimental', b'uncommit.keep'
215 )
214 newid = _commitfiltered( 216 newid = _commitfiltered(
215 repo, 217 repo,
216 old, 218 old,
217 match, 219 match,
218 keepcommit, 220 keepcommit,
219 message=message, 221 message=message,
220 user=opts.get(b'user'), 222 user=opts.get(b'user'),
221 date=opts.get(b'date'), 223 date=opts.get(b'date'),
222 ) 224 )
223 if newid is None: 225 if newid is None:
224 ui.status(_("nothing to uncommit\n")) 226 ui.status(_(b"nothing to uncommit\n"))
225 return 1 227 return 1
226 228
227 mapping = {} 229 mapping = {}
228 if newid != old.p1().node(): 230 if newid != old.p1().node():
229 # Move local changes on filtered changeset 231 # Move local changes on filtered changeset
233 mapping[old.node()] = () 235 mapping[old.node()] = ()
234 236
235 with repo.dirstate.parentchange(): 237 with repo.dirstate.parentchange():
236 scmutil.movedirstate(repo, repo[newid], match) 238 scmutil.movedirstate(repo, repo[newid], match)
237 239
238 scmutil.cleanupnodes(repo, mapping, 'uncommit', fixphase=True) 240 scmutil.cleanupnodes(repo, mapping, b'uncommit', fixphase=True)
239 241
240 242
241 def predecessormarkers(ctx): 243 def predecessormarkers(ctx):
242 """yields the obsolete markers marking the given changeset as a successor""" 244 """yields the obsolete markers marking the given changeset as a successor"""
243 for data in ctx.repo().obsstore.predecessors.get(ctx.node(), ()): 245 for data in ctx.repo().obsstore.predecessors.get(ctx.node(), ()):
244 yield obsutil.marker(ctx.repo(), data) 246 yield obsutil.marker(ctx.repo(), data)
245 247
246 248
247 @command( 249 @command(
248 'unamend', 250 b'unamend',
249 [], 251 [],
250 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, 252 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT,
251 helpbasic=True, 253 helpbasic=True,
252 ) 254 )
253 def unamend(ui, repo, **opts): 255 def unamend(ui, repo, **opts):
258 `hg amend` (e.g. files modified as part of an amend will be 260 `hg amend` (e.g. files modified as part of an amend will be
259 marked as modified `hg status`) 261 marked as modified `hg status`)
260 """ 262 """
261 263
262 unfi = repo.unfiltered() 264 unfi = repo.unfiltered()
263 with repo.wlock(), repo.lock(), repo.transaction('unamend'): 265 with repo.wlock(), repo.lock(), repo.transaction(b'unamend'):
264 266
265 # identify the commit from which to unamend 267 # identify the commit from which to unamend
266 curctx = repo['.'] 268 curctx = repo[b'.']
267 269
268 rewriteutil.precheck(repo, [curctx.rev()], 'unamend') 270 rewriteutil.precheck(repo, [curctx.rev()], b'unamend')
269 271
270 # identify the commit to which to unamend 272 # identify the commit to which to unamend
271 markers = list(predecessormarkers(curctx)) 273 markers = list(predecessormarkers(curctx))
272 if len(markers) != 1: 274 if len(markers) != 1:
273 e = _("changeset must have one predecessor, found %i predecessors") 275 e = _(b"changeset must have one predecessor, found %i predecessors")
274 raise error.Abort(e % len(markers)) 276 raise error.Abort(e % len(markers))
275 277
276 prednode = markers[0].prednode() 278 prednode = markers[0].prednode()
277 predctx = unfi[prednode] 279 predctx = unfi[prednode]
278 280
279 # add an extra so that we get a new hash 281 # add an extra so that we get a new hash
280 # note: allowing unamend to undo an unamend is an intentional feature 282 # note: allowing unamend to undo an unamend is an intentional feature
281 extras = predctx.extra() 283 extras = predctx.extra()
282 extras['unamend_source'] = curctx.hex() 284 extras[b'unamend_source'] = curctx.hex()
283 285
284 def filectxfn(repo, ctx_, path): 286 def filectxfn(repo, ctx_, path):
285 try: 287 try:
286 return predctx.filectx(path) 288 return predctx.filectx(path)
287 except KeyError: 289 except KeyError:
304 306
305 with dirstate.parentchange(): 307 with dirstate.parentchange():
306 scmutil.movedirstate(repo, newpredctx) 308 scmutil.movedirstate(repo, newpredctx)
307 309
308 mapping = {curctx.node(): (newprednode,)} 310 mapping = {curctx.node(): (newprednode,)}
309 scmutil.cleanupnodes(repo, mapping, 'unamend', fixphase=True) 311 scmutil.cleanupnodes(repo, mapping, b'unamend', fixphase=True)