hgext/histedit.py
changeset 24002 96d130697f07
parent 22987 e6d890e1ed4f
child 24009 00d331763442
equal deleted inserted replaced
24001:f610c3bd03d3 24002:96d130697f07
   347 
   347 
   348 def pick(ui, state, ha, opts):
   348 def pick(ui, state, ha, opts):
   349     repo, ctx = state.repo, state.parentctx
   349     repo, ctx = state.repo, state.parentctx
   350     oldctx = repo[ha]
   350     oldctx = repo[ha]
   351     if oldctx.parents()[0] == ctx:
   351     if oldctx.parents()[0] == ctx:
   352         ui.debug('node %s unchanged\n' % ha)
   352         ui.debug('node %s unchanged\n' % ha[:12])
   353         return oldctx, []
   353         return oldctx, []
   354     hg.update(repo, ctx.node())
   354     hg.update(repo, ctx.node())
   355     stats = applychanges(ui, repo, oldctx, opts)
   355     stats = applychanges(ui, repo, oldctx, opts)
   356     if stats and stats[3] > 0:
   356     if stats and stats[3] > 0:
   357         raise error.InterventionRequired(_('Fix up the change and run '
   357         raise error.InterventionRequired(_('Fix up the change and run '
   359     # drop the second merge parent
   359     # drop the second merge parent
   360     commit = commitfuncfor(repo, oldctx)
   360     commit = commitfuncfor(repo, oldctx)
   361     n = commit(text=oldctx.description(), user=oldctx.user(),
   361     n = commit(text=oldctx.description(), user=oldctx.user(),
   362                date=oldctx.date(), extra=oldctx.extra())
   362                date=oldctx.date(), extra=oldctx.extra())
   363     if n is None:
   363     if n is None:
   364         ui.warn(_('%s: empty changeset\n') % node.hex(ha))
   364         ui.warn(_('%s: empty changeset\n') % ha[:12])
   365         return ctx, []
   365         return ctx, []
   366     new = repo[n]
   366     new = repo[n]
   367     return new, [(oldctx.node(), (n,))]
   367     return new, [(oldctx.node(), (n,))]
   368 
   368 
   369 
   369 
   387     hg.update(repo, ctx.node())
   387     hg.update(repo, ctx.node())
   388     stats = applychanges(ui, repo, oldctx, opts)
   388     stats = applychanges(ui, repo, oldctx, opts)
   389     if stats and stats[3] > 0:
   389     if stats and stats[3] > 0:
   390         raise error.InterventionRequired(
   390         raise error.InterventionRequired(
   391             _('Fix up the change and run hg histedit --continue'))
   391             _('Fix up the change and run hg histedit --continue'))
   392     n = repo.commit(text='fold-temp-revision %s' % ha, user=oldctx.user(),
   392     n = repo.commit(text='fold-temp-revision %s' % ha[:12], user=oldctx.user(),
   393                     date=oldctx.date(), extra=oldctx.extra())
   393                     date=oldctx.date(), extra=oldctx.extra())
   394     if n is None:
   394     if n is None:
   395         ui.warn(_('%s: empty changeset') % node.hex(ha))
   395         ui.warn(_('%s: empty changeset') % ha[:12])
   396         return ctx, []
   396         return ctx, []
   397     return finishfold(ui, repo, ctx, oldctx, n, opts, [])
   397     return finishfold(ui, repo, ctx, oldctx, n, opts, [])
   398 
   398 
   399 def finishfold(ui, repo, ctx, oldctx, newnode, opts, internalchanges):
   399 def finishfold(ui, repo, ctx, oldctx, newnode, opts, internalchanges):
   400     parent = ctx.parents()[0].node()
   400     parent = ctx.parents()[0].node()
   664         state.replacements = replacements
   664         state.replacements = replacements
   665 
   665 
   666     while state.rules:
   666     while state.rules:
   667         state.write()
   667         state.write()
   668         action, ha = state.rules.pop(0)
   668         action, ha = state.rules.pop(0)
   669         ui.debug('histedit: processing %s %s\n' % (action, ha))
   669         ui.debug('histedit: processing %s %s\n' % (action, ha[:12]))
   670         actfunc = actiontable[action]
   670         actfunc = actiontable[action]
   671         state.parentctx, replacement_ = actfunc(ui, state, ha, opts)
   671         state.parentctx, replacement_ = actfunc(ui, state, ha, opts)
   672         state.replacements.extend(replacement_)
   672         state.replacements.extend(replacement_)
   673 
   673 
   674     hg.update(repo, state.parentctx.node())
   674     hg.update(repo, state.parentctx.node())
   734     new = None
   734     new = None
   735     s = repo.status()
   735     s = repo.status()
   736     if s.modified or s.added or s.removed or s.deleted:
   736     if s.modified or s.added or s.removed or s.deleted:
   737         # prepare the message for the commit to comes
   737         # prepare the message for the commit to comes
   738         if action in ('f', 'fold', 'r', 'roll'):
   738         if action in ('f', 'fold', 'r', 'roll'):
   739             message = 'fold-temp-revision %s' % currentnode
   739             message = 'fold-temp-revision %s' % currentnode[:12]
   740         else:
   740         else:
   741             message = ctx.description()
   741             message = ctx.description()
   742         editopt = action in ('e', 'edit', 'm', 'mess')
   742         editopt = action in ('e', 'edit', 'm', 'mess')
   743         canonaction = {'e': 'edit', 'm': 'mess', 'p': 'pick'}
   743         canonaction = {'e': 'edit', 'm': 'mess', 'p': 'pick'}
   744         editform = 'histedit.%s' % canonaction.get(action, action)
   744         editform = 'histedit.%s' % canonaction.get(action, action)
   820 
   820 
   821     Will abort if there are to many or too few rules, a malformed rule,
   821     Will abort if there are to many or too few rules, a malformed rule,
   822     or a rule on a changeset outside of the user-given range.
   822     or a rule on a changeset outside of the user-given range.
   823     """
   823     """
   824     parsed = []
   824     parsed = []
   825     expected = set(str(c) for c in ctxs)
   825     expected = set(c.hex() for c in ctxs)
   826     seen = set()
   826     seen = set()
   827     for r in rules:
   827     for r in rules:
   828         if ' ' not in r:
   828         if ' ' not in r:
   829             raise util.Abort(_('malformed line "%s"') % r)
   829             raise util.Abort(_('malformed line "%s"') % r)
   830         action, rest = r.split(' ', 1)
   830         action, rest = r.split(' ', 1)
   831         ha = rest.strip().split(' ', 1)[0]
   831         ha = rest.strip().split(' ', 1)[0]
   832         try:
   832         try:
   833             ha = str(repo[ha])  # ensure its a short hash
   833             ha = repo[ha].hex()
   834         except error.RepoError:
   834         except error.RepoError:
   835             raise util.Abort(_('unknown changeset %s listed') % ha)
   835             raise util.Abort(_('unknown changeset %s listed') % ha[:12])
   836         if ha not in expected:
   836         if ha not in expected:
   837             raise util.Abort(
   837             raise util.Abort(
   838                 _('may not use changesets other than the ones listed'))
   838                 _('may not use changesets other than the ones listed'))
   839         if ha in seen:
   839         if ha in seen:
   840             raise util.Abort(_('duplicated command for changeset %s') % ha)
   840             raise util.Abort(_('duplicated command for changeset %s') %
       
   841                     ha[:12])
   841         seen.add(ha)
   842         seen.add(ha)
   842         if action not in actiontable:
   843         if action not in actiontable:
   843             raise util.Abort(_('unknown action "%s"') % action)
   844             raise util.Abort(_('unknown action "%s"') % action)
   844         parsed.append([action, ha])
   845         parsed.append([action, ha])
   845     missing = sorted(expected - seen)  # sort to stabilize output
   846     missing = sorted(expected - seen)  # sort to stabilize output
   846     if missing:
   847     if missing:
   847         raise util.Abort(_('missing rules for changeset %s') % missing[0],
   848         raise util.Abort(_('missing rules for changeset %s') %
   848                          hint=_('do you want to use the drop action?'))
   849                 missing[0][:12],
       
   850                 hint=_('do you want to use the drop action?'))
   849     return parsed
   851     return parsed
   850 
   852 
   851 def processreplacement(state):
   853 def processreplacement(state):
   852     """process the list of replacements to return
   854     """process the list of replacements to return
   853 
   855