comparison mercurial/commands.py @ 15240:bfb93963bb39

graft: add user, date, and tool options
author Matt Mackall <mpm@selenic.com>
date Wed, 12 Oct 2011 18:46:23 -0500
parents f5d9d0d0f588
children e4d135632f6d
comparison
equal deleted inserted replaced
15239:f5d9d0d0f588 15240:bfb93963bb39
2445 ui.status(_('removing %s\n') % m.rel(f)) 2445 ui.status(_('removing %s\n') % m.rel(f))
2446 2446
2447 repo[None].forget(forget) 2447 repo[None].forget(forget)
2448 return errs 2448 return errs
2449 2449
2450 @command('graft', 2450 @command(
2451 [('e', 'edit', False, _('invoke editor on commit messages'))], 2451 'graft',
2452 [('e', 'edit', False, _('invoke editor on commit messages')),
2453 ('D', 'currentdate', False,
2454 _('record the current date as commit date')),
2455 ('U', 'currentuser', False,
2456 _('record the current user as committer'), _('DATE'))]
2457 + commitopts2 + mergetoolopts,
2452 _('[OPTION]... REVISION...')) 2458 _('[OPTION]... REVISION...'))
2453 def graft(ui, repo, rev, *revs, **opts): 2459 def graft(ui, repo, rev, *revs, **opts):
2454 '''copy changes from other branches onto the current branch 2460 '''copy changes from other branches onto the current branch
2455 2461
2456 This command uses Mercurial's merge logic to copy individual 2462 This command uses Mercurial's merge logic to copy individual
2463 2469
2464 Returns 0 on successful completion. 2470 Returns 0 on successful completion.
2465 ''' 2471 '''
2466 2472
2467 cmdutil.bailifchanged(repo) 2473 cmdutil.bailifchanged(repo)
2474
2475 if not opts.get('user') and opts.get('currentuser'):
2476 opts['user'] = ui.username()
2477 if not opts.get('date') and opts.get('currentdate'):
2478 opts['date'] = "%d %d" % util.makedate()
2468 2479
2469 editor = None 2480 editor = None
2470 if opts.get('edit'): 2481 if opts.get('edit'):
2471 editor = cmdutil.commitforceeditor 2482 editor = cmdutil.commitforceeditor
2472 2483
2500 2511
2501 for ctx in repo.set("%ld", revs): 2512 for ctx in repo.set("%ld", revs):
2502 current = repo['.'] 2513 current = repo['.']
2503 ui.debug('grafting revision %s', ctx.rev()) 2514 ui.debug('grafting revision %s', ctx.rev())
2504 # perform the graft merge with p1(rev) as 'ancestor' 2515 # perform the graft merge with p1(rev) as 'ancestor'
2505 stats = mergemod.update(repo, ctx.node(), True, True, False, 2516 try:
2506 ctx.p1().node()) 2517 # ui.forcemerge is an internal variable, do not document
2518 repo.ui.setconfig('ui', 'forcemerge', opts.get('tool', ''))
2519 stats = mergemod.update(repo, ctx.node(), True, True, False,
2520 ctx.p1().node())
2521 finally:
2522 ui.setconfig('ui', 'forcemerge', '')
2507 # drop the second merge parent 2523 # drop the second merge parent
2508 repo.dirstate.setparents(current.node(), nullid) 2524 repo.dirstate.setparents(current.node(), nullid)
2509 repo.dirstate.write() 2525 repo.dirstate.write()
2510 # fix up dirstate for copies and renames 2526 # fix up dirstate for copies and renames
2511 cmdutil.duplicatecopies(repo, ctx.rev(), current.node(), nullid) 2527 cmdutil.duplicatecopies(repo, ctx.rev(), current.node(), nullid)
2513 if stats and stats[3] > 0: 2529 if stats and stats[3] > 0:
2514 raise util.Abort(_("unresolved conflicts, can't continue"), 2530 raise util.Abort(_("unresolved conflicts, can't continue"),
2515 hint=_('use hg resolve and hg graft --continue')) 2531 hint=_('use hg resolve and hg graft --continue'))
2516 # commit 2532 # commit
2517 extra = {'source': ctx.hex()} 2533 extra = {'source': ctx.hex()}
2518 repo.commit(text=ctx.description(), user=ctx.user(), 2534 user = ctx.user()
2519 date=ctx.date(), extra=extra, editor=editor) 2535 if opts.get('user'):
2536 user = opts['user']
2537 date = ctx.date()
2538 if opts.get('date'):
2539 date = opts['date']
2540 repo.commit(text=ctx.description(), user=user,
2541 date=date, extra=extra, editor=editor)
2520 2542
2521 return 0 2543 return 0
2522 2544
2523 @command('grep', 2545 @command('grep',
2524 [('0', 'print0', None, _('end fields with NUL')), 2546 [('0', 'print0', None, _('end fields with NUL')),