hgext/histedit.py
changeset 19021 26b41a902195
parent 19020 12c06686d371
child 19039 41669a18a7d6
equal deleted inserted replaced
19020:12c06686d371 19021:26b41a902195
   402     if oldctx.node() != newctx.node():
   402     if oldctx.node() != newctx.node():
   403         return newctx, [(oldctx.node(), (new,))]
   403         return newctx, [(oldctx.node(), (new,))]
   404     # We didn't make an edit, so just indicate no replaced nodes
   404     # We didn't make an edit, so just indicate no replaced nodes
   405     return newctx, []
   405     return newctx, []
   406 
   406 
       
   407 def findoutgoing(ui, repo, remote=None, force=False, opts={}):
       
   408     """utility function to find the first outgoing changeset
       
   409 
       
   410     Used by initialisation code"""
       
   411     dest = ui.expandpath(remote or 'default-push', remote or 'default')
       
   412     dest, revs = hg.parseurl(dest, None)[:2]
       
   413     ui.status(_('comparing with %s\n') % util.hidepassword(dest))
       
   414 
       
   415     revs, checkout = hg.addbranchrevs(repo, repo, revs, None)
       
   416     other = hg.peer(repo, opts, dest)
       
   417 
       
   418     if revs:
       
   419         revs = [repo.lookup(rev) for rev in revs]
       
   420 
       
   421     # hexlify nodes from outgoing, because we're going to parse
       
   422     # parent[0] using revsingle below, and if the binary hash
       
   423     # contains special revset characters like ":" the revset
       
   424     # parser can choke.
       
   425     outgoing = discovery.findcommonoutgoing(repo, other, revs, force=force)
       
   426     if not outgoing.missing:
       
   427         raise util.Abort(_('no outgoing ancestors'))
       
   428     return outgoing.missing[0]
       
   429 
   407 actiontable = {'p': pick,
   430 actiontable = {'p': pick,
   408                'pick': pick,
   431                'pick': pick,
   409                'e': edit,
   432                'e': edit,
   410                'edit': edit,
   433                'edit': edit,
   411                'f': fold,
   434                'f': fold,
   464                 raise util.Abort(_('no revisions allowed with --outgoing'))
   487                 raise util.Abort(_('no revisions allowed with --outgoing'))
   465             if len(freeargs) > 1:
   488             if len(freeargs) > 1:
   466                 raise util.Abort(
   489                 raise util.Abort(
   467                     _('only one repo argument allowed with --outgoing'))
   490                     _('only one repo argument allowed with --outgoing'))
   468         else:
   491         else:
   469             parent = list(freeargs) + opts.get('rev', [])
   492             revs.extend(freeargs)
   470             if len(parent) != 1:
   493             if len(revs) != 1:
   471                 raise util.Abort(
   494                 raise util.Abort(
   472                     _('histedit requires exactly one parent revision'))
   495                     _('histedit requires exactly one parent revision'))
   473 
   496 
   474     if opts.get('outgoing'):
       
   475         if freeargs:
       
   476             parent = freeargs[0]
       
   477 
       
   478         dest = ui.expandpath(parent or 'default-push', parent or 'default')
       
   479         dest, revs = hg.parseurl(dest, None)[:2]
       
   480         ui.status(_('comparing with %s\n') % util.hidepassword(dest))
       
   481 
       
   482         revs, checkout = hg.addbranchrevs(repo, repo, revs, None)
       
   483         other = hg.peer(repo, opts, dest)
       
   484 
       
   485         if revs:
       
   486             revs = [repo.lookup(rev) for rev in revs]
       
   487 
       
   488         # hexlify nodes from outgoing, because we're going to parse
       
   489         # parent[0] using revsingle below, and if the binary hash
       
   490         # contains special revset characters like ":" the revset
       
   491         # parser can choke.
       
   492         parent = [node.hex(n) for n in discovery.findcommonoutgoing(
       
   493             repo, other, revs, force=force).missing[0:1]]
       
   494         if not parent:
       
   495             raise util.Abort(_('no outgoing ancestors'))
       
   496 
   497 
   497     if goal == 'continue':
   498     if goal == 'continue':
   498         (parentctxnode, rules, keep, topmost, replacements) = readstate(repo)
   499         (parentctxnode, rules, keep, topmost, replacements) = readstate(repo)
   499         currentparent, wantnull = repo.dirstate.parents()
   500         currentparent, wantnull = repo.dirstate.parents()
   500         parentctx = repo[parentctxnode]
   501         parentctx = repo[parentctxnode]
   511         return
   512         return
   512     else:
   513     else:
   513         cmdutil.bailifchanged(repo)
   514         cmdutil.bailifchanged(repo)
   514 
   515 
   515         topmost, empty = repo.dirstate.parents()
   516         topmost, empty = repo.dirstate.parents()
   516 
   517         if outg:
   517         parent = scmutil.revsingle(repo, parent[0]).node()
   518             if freeargs:
       
   519                 remote = freeargs[0]
       
   520             else:
       
   521                 remote = None
       
   522             root = findoutgoing(ui, repo, remote, force, opts)
       
   523         else:
       
   524             root = revs[0]
       
   525             root = scmutil.revsingle(repo, root).node()
   518 
   526 
   519         keep = opts.get('keep', False)
   527         keep = opts.get('keep', False)
   520         revs = between(repo, parent, topmost, keep)
   528         revs = between(repo, root, topmost, keep)
   521         if not revs:
   529         if not revs:
   522             raise util.Abort(_('%s is not an ancestor of working directory') %
   530             raise util.Abort(_('%s is not an ancestor of working directory') %
   523                              node.short(parent))
   531                              node.short(root))
   524 
   532 
   525         ctxs = [repo[r] for r in revs]
   533         ctxs = [repo[r] for r in revs]
   526         if not rules:
   534         if not rules:
   527             rules = '\n'.join([makedesc(c) for c in ctxs])
   535             rules = '\n'.join([makedesc(c) for c in ctxs])
   528             rules += '\n\n'
   536             rules += '\n\n'
   529             rules += editcomment % (node.short(parent), node.short(topmost))
   537             rules += editcomment % (node.short(root), node.short(topmost))
   530             rules = ui.edit(rules, ui.username())
   538             rules = ui.edit(rules, ui.username())
   531             # Save edit rules in .hg/histedit-last-edit.txt in case
   539             # Save edit rules in .hg/histedit-last-edit.txt in case
   532             # the user needs to ask for help after something
   540             # the user needs to ask for help after something
   533             # surprising happens.
   541             # surprising happens.
   534             f = open(repo.join('histedit-last-edit.txt'), 'w')
   542             f = open(repo.join('histedit-last-edit.txt'), 'w')
   543             f.close()
   551             f.close()
   544         rules = [l for l in (r.strip() for r in rules.splitlines())
   552         rules = [l for l in (r.strip() for r in rules.splitlines())
   545                  if l and not l[0] == '#']
   553                  if l and not l[0] == '#']
   546         rules = verifyrules(rules, repo, ctxs)
   554         rules = verifyrules(rules, repo, ctxs)
   547 
   555 
   548         parentctx = repo[parent].parents()[0]
   556         parentctx = repo[root].parents()[0]
   549         keep = opts.get('keep', False)
   557         keep = opts.get('keep', False)
   550         replacements = []
   558         replacements = []
   551 
   559 
   552 
   560 
   553     while rules:
   561     while rules: