comparison hgext/histedit.py @ 17766:d9da327516f8

histedit: clean abort when there is nothing to edit
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Sun, 14 Oct 2012 23:58:02 +0200
parents ef7760f0be87
children a787e46d3b94
comparison
equal deleted inserted replaced
17765:ef7760f0be87 17766:d9da327516f8
453 raise util.Abort(_('histedit requires exactly one parent revision')) 453 raise util.Abort(_('histedit requires exactly one parent revision'))
454 parent = scmutil.revsingle(repo, parent[0]).node() 454 parent = scmutil.revsingle(repo, parent[0]).node()
455 455
456 keep = opts.get('keep', False) 456 keep = opts.get('keep', False)
457 revs = between(repo, parent, topmost, keep) 457 revs = between(repo, parent, topmost, keep)
458 if not revs:
459 ui.warn(_('nothing to edit\n'))
460 return 1
458 461
459 ctxs = [repo[r] for r in revs] 462 ctxs = [repo[r] for r in revs]
460 rules = opts.get('commands', '') 463 rules = opts.get('commands', '')
461 if not rules: 464 if not rules:
462 rules = '\n'.join([makedesc(c) for c in ctxs]) 465 rules = '\n'.join([makedesc(c) for c in ctxs])
586 def between(repo, old, new, keep): 589 def between(repo, old, new, keep):
587 """select and validate the set of revision to edit 590 """select and validate the set of revision to edit
588 591
589 When keep is false, the specified set can't have children.""" 592 When keep is false, the specified set can't have children."""
590 ctxs = list(repo.set('%n::%n', old, new)) 593 ctxs = list(repo.set('%n::%n', old, new))
591 if not keep: 594 if ctxs and not keep:
592 if repo.revs('(%ld::) - (%ld + hidden())', ctxs, ctxs): 595 if repo.revs('(%ld::) - (%ld + hidden())', ctxs, ctxs):
593 raise util.Abort(_('cannot edit history that would orphan nodes')) 596 raise util.Abort(_('cannot edit history that would orphan nodes'))
594 root = min(ctxs) 597 root = min(ctxs)
595 if not root.phase(): 598 if not root.phase():
596 raise util.Abort(_('cannot edit immutable changeset: %s') % root) 599 raise util.Abort(_('cannot edit immutable changeset: %s') % root)