comparison mercurial/cmdutil.py @ 42932:e4803231f538

amend: add option to update to the current user This is also from the evolve extension's version of amend. A side effect of this refactoring is for uncommit to support `rewrite.update-timestamp`. Differential Revision: https://phab.mercurial-scm.org/D6853
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 14 Sep 2019 15:13:16 -0400
parents 4690902850df
children 7e9997041781
comparison
equal deleted inserted replaced
42931:181ee2118a96 42932:e4803231f538
182 # editor text 182 # editor text
183 _linebelow = "^HG: ------------------------ >8 ------------------------$" 183 _linebelow = "^HG: ------------------------ >8 ------------------------$"
184 184
185 def resolvecommitoptions(ui, opts): 185 def resolvecommitoptions(ui, opts):
186 """modify commit options dict to handle related options 186 """modify commit options dict to handle related options
187
188 The return value indicates that ``rewrite.update-timestamp`` is the reason
189 the ``date`` option is set.
187 """ 190 """
188 if opts.get('date') and opts.get('currentdate'): 191 if opts.get('date') and opts.get('currentdate'):
189 raise error.Abort(_('--date and --currentdate are mutually ' 192 raise error.Abort(_('--date and --currentdate are mutually '
190 'exclusive')) 193 'exclusive'))
191 if opts.get(b'user') and opts.get(b'currentuser'): 194 if opts.get(b'user') and opts.get(b'currentuser'):
192 raise error.Abort(_('--user and --currentuser are mutually ' 195 raise error.Abort(_('--user and --currentuser are mutually '
193 'exclusive')) 196 'exclusive'))
194 197
195 # N.B. this is extremely similar to setupheaderopts() in mq.py 198 datemaydiffer = False # date-only change should be ignored?
199
196 if opts.get(b'currentdate'): 200 if opts.get(b'currentdate'):
197 opts[b'date'] = b'%d %d' % dateutil.makedate() 201 opts[b'date'] = b'%d %d' % dateutil.makedate()
202 elif (not opts.get('date')
203 and ui.configbool('rewrite', 'update-timestamp')
204 and opts.get('currentdate') is None):
205 opts[b'date'] = b'%d %d' % dateutil.makedate()
206 datemaydiffer = True
207
198 if opts.get(b'currentuser'): 208 if opts.get(b'currentuser'):
199 opts[b'user'] = ui.username() 209 opts[b'user'] = ui.username()
210
211 return datemaydiffer
200 212
201 def ishunk(x): 213 def ishunk(x):
202 hunkclasses = (crecordmod.uihunk, patch.recordhunk) 214 hunkclasses = (crecordmod.uihunk, patch.recordhunk)
203 return isinstance(x, hunkclasses) 215 return isinstance(x, hunkclasses)
204 216
2468 extra.update(old.extra()) 2480 extra.update(old.extra())
2469 2481
2470 # Also update it from the from the wctx 2482 # Also update it from the from the wctx
2471 extra.update(wctx.extra()) 2483 extra.update(wctx.extra())
2472 2484
2473 user = opts.get('user') or old.user() 2485 # date-only change should be ignored?
2474 2486 datemaydiffer = resolvecommitoptions(ui, opts)
2475 datemaydiffer = False # date-only change should be ignored? 2487
2476 if opts.get('date') and opts.get('currentdate'): 2488 date = old.date()
2477 raise error.Abort(_('--date and --currentdate are mutually '
2478 'exclusive'))
2479 if opts.get('date'): 2489 if opts.get('date'):
2480 date = dateutil.parsedate(opts.get('date')) 2490 date = dateutil.parsedate(opts.get('date'))
2481 elif opts.get('currentdate'): 2491 user = opts.get('user') or old.user()
2482 date = dateutil.makedate()
2483 elif (ui.configbool('rewrite', 'update-timestamp')
2484 and opts.get('currentdate') is None):
2485 date = dateutil.makedate()
2486 datemaydiffer = True
2487 else:
2488 date = old.date()
2489 2492
2490 if len(old.parents()) > 1: 2493 if len(old.parents()) > 1:
2491 # ctx.files() isn't reliable for merges, so fall back to the 2494 # ctx.files() isn't reliable for merges, so fall back to the
2492 # slower repo.status() method 2495 # slower repo.status() method
2493 files = {fn for st in base.status(old)[:3] for fn in st} 2496 files = {fn for st in base.status(old)[:3] for fn in st}