comparison hgext/histedit.py @ 17665:b65533958b85

histedit: rename `tip` to `topmost` I expected `tip` to be repo's tip when it was the rewritten set tip. I rename the variable to the less ambiguous `topmost`.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Wed, 26 Sep 2012 18:13:00 +0200
parents 4eb13b619785
children 5b6c8f2fbda5
comparison
equal deleted inserted replaced
17664:4eb13b619785 17665:b65533958b85
415 raise util.Abort(_('--force only allowed with --outgoing')) 415 raise util.Abort(_('--force only allowed with --outgoing'))
416 416
417 if opts.get('continue', False): 417 if opts.get('continue', False):
418 if len(parent) != 0: 418 if len(parent) != 0:
419 raise util.Abort(_('no arguments allowed with --continue')) 419 raise util.Abort(_('no arguments allowed with --continue'))
420 (parentctxnode, created, replaced, 420 (parentctxnode, created, replaced, tmpnodes,
421 tmpnodes, existing, rules, keep, tip, replacemap) = readstate(repo) 421 existing, rules, keep, topmost, replacemap) = readstate(repo)
422 currentparent, wantnull = repo.dirstate.parents() 422 currentparent, wantnull = repo.dirstate.parents()
423 parentctx = repo[parentctxnode] 423 parentctx = repo[parentctxnode]
424 # existing is the list of revisions initially considered by 424 # existing is the list of revisions initially considered by
425 # histedit. Here we use it to list new changesets, descendants 425 # histedit. Here we use it to list new changesets, descendants
426 # of parentctx without an 'existing' changeset in-between. We 426 # of parentctx without an 'existing' changeset in-between. We
477 477
478 elif opts.get('abort', False): 478 elif opts.get('abort', False):
479 if len(parent) != 0: 479 if len(parent) != 0:
480 raise util.Abort(_('no arguments allowed with --abort')) 480 raise util.Abort(_('no arguments allowed with --abort'))
481 (parentctxnode, created, replaced, tmpnodes, 481 (parentctxnode, created, replaced, tmpnodes,
482 existing, rules, keep, tip, replacemap) = readstate(repo) 482 existing, rules, keep, topmost, replacemap) = readstate(repo)
483 ui.debug('restore wc to old tip %s\n' % node.hex(tip)) 483 ui.debug('restore wc to old parent %s\n' % node.short(topmost))
484 hg.clean(repo, tip) 484 hg.clean(repo, topmost)
485 cleanupnode(ui, repo, 'created', created) 485 cleanupnode(ui, repo, 'created', created)
486 cleanupnode(ui, repo, 'temp', tmpnodes) 486 cleanupnode(ui, repo, 'temp', tmpnodes)
487 os.unlink(os.path.join(repo.path, 'histedit-state')) 487 os.unlink(os.path.join(repo.path, 'histedit-state'))
488 return 488 return
489 else: 489 else:
490 cmdutil.bailifchanged(repo) 490 cmdutil.bailifchanged(repo)
491 if os.path.exists(os.path.join(repo.path, 'histedit-state')): 491 if os.path.exists(os.path.join(repo.path, 'histedit-state')):
492 raise util.Abort(_('history edit already in progress, try ' 492 raise util.Abort(_('history edit already in progress, try '
493 '--continue or --abort')) 493 '--continue or --abort'))
494 494
495 tip, empty = repo.dirstate.parents() 495 topmost, empty = repo.dirstate.parents()
496 496
497 497
498 if len(parent) != 1: 498 if len(parent) != 1:
499 raise util.Abort(_('histedit requires exactly one parent revision')) 499 raise util.Abort(_('histedit requires exactly one parent revision'))
500 parent = scmutil.revsingle(repo, parent[0]).node() 500 parent = scmutil.revsingle(repo, parent[0]).node()
501 501
502 keep = opts.get('keep', False) 502 keep = opts.get('keep', False)
503 revs = between(repo, parent, tip, keep) 503 revs = between(repo, parent, topmost, keep)
504 504
505 ctxs = [repo[r] for r in revs] 505 ctxs = [repo[r] for r in revs]
506 existing = [r.node() for r in ctxs] 506 existing = [r.node() for r in ctxs]
507 rules = opts.get('commands', '') 507 rules = opts.get('commands', '')
508 if not rules: 508 if not rules:
509 rules = '\n'.join([makedesc(c) for c in ctxs]) 509 rules = '\n'.join([makedesc(c) for c in ctxs])
510 rules += '\n\n' 510 rules += '\n\n'
511 rules += editcomment % (node.short(parent), node.short(tip)) 511 rules += editcomment % (node.short(parent), node.short(topmost))
512 rules = ui.edit(rules, ui.username()) 512 rules = ui.edit(rules, ui.username())
513 # Save edit rules in .hg/histedit-last-edit.txt in case 513 # Save edit rules in .hg/histedit-last-edit.txt in case
514 # the user needs to ask for help after something 514 # the user needs to ask for help after something
515 # surprising happens. 515 # surprising happens.
516 f = open(repo.join('histedit-last-edit.txt'), 'w') 516 f = open(repo.join('histedit-last-edit.txt'), 'w')
532 created = [] 532 created = []
533 533
534 534
535 while rules: 535 while rules:
536 writestate(repo, parentctx.node(), created, replaced, 536 writestate(repo, parentctx.node(), created, replaced,
537 tmpnodes, existing, rules, keep, tip, replacemap) 537 tmpnodes, existing, rules, keep, topmost, replacemap)
538 action, ha = rules.pop(0) 538 action, ha = rules.pop(0)
539 ui.debug('histedit: processing %s %s\n' % (action, ha)) 539 ui.debug('histedit: processing %s %s\n' % (action, ha))
540 (parentctx, created_, replaced_, tmpnodes_) = actiontable[action]( 540 (parentctx, created_, replaced_, tmpnodes_) = actiontable[action](
541 ui, repo, parentctx, ha, opts) 541 ui, repo, parentctx, ha, opts)
542 542
620 raise util.Abort(_('cannot edit history that would orphan nodes')) 620 raise util.Abort(_('cannot edit history that would orphan nodes'))
621 return revs 621 return revs
622 622
623 623
624 def writestate(repo, parentctxnode, created, replaced, 624 def writestate(repo, parentctxnode, created, replaced,
625 tmpnodes, existing, rules, keep, oldtip, replacemap): 625 tmpnodes, existing, rules, keep, topmost, replacemap):
626 fp = open(os.path.join(repo.path, 'histedit-state'), 'w') 626 fp = open(os.path.join(repo.path, 'histedit-state'), 'w')
627 pickle.dump((parentctxnode, created, replaced, 627 pickle.dump((parentctxnode, created, replaced,
628 tmpnodes, existing, rules, keep, oldtip, replacemap), 628 tmpnodes, existing, rules, keep, topmost, replacemap),
629 fp) 629 fp)
630 fp.close() 630 fp.close()
631 631
632 def readstate(repo): 632 def readstate(repo):
633 """Returns a tuple of (parentnode, created, replaced, tmp, existing, rules, 633 """Returns a tuple of (parentnode, created, replaced, tmp, existing, rules,
634 keep, oldtip, replacemap ). 634 keep, topmost, replacemap ).
635 """ 635 """
636 fp = open(os.path.join(repo.path, 'histedit-state')) 636 fp = open(os.path.join(repo.path, 'histedit-state'))
637 return pickle.load(fp) 637 return pickle.load(fp)
638 638
639 639