comparison hgext/evolve.py @ 1685:4fd0db2f6d84

commands: introduce a new command to edit commit metadata This patch introduces metaedit, a command to metadata of a set of revisions without updating the working copy. This is particularly relevant for repositories where changing the parent of the working copy is time-consuming. We could add more stack manipulation operations to metaedit in the future.
author Siddharth Agarwal <sid0@fb.com>
date Mon, 25 Apr 2016 16:24:42 -0700
parents 40d7b0c4abb1
children 474db2d60202
comparison
equal deleted inserted replaced
1684:40d7b0c4abb1 1685:4fd0db2f6d84
3156 if repo['.'].rev() in revs: 3156 if repo['.'].rev() in revs:
3157 hg.update(repo, newid) 3157 hg.update(repo, newid)
3158 finally: 3158 finally:
3159 lockmod.release(lock, wlock) 3159 lockmod.release(lock, wlock)
3160 3160
3161 @command('^metaedit',
3162 [('r', 'rev', [], _("revision to edit")),
3163 ] + commitopts + commitopts2,
3164 _('hg metaedit [OPTION]... [-r] [REV]'))
3165 def metaedit(ui, repo, *revs, **opts):
3166 """edit commit information
3167
3168 Edits the commit information for the specified revision. By default, edits
3169 commit information for the working directory parent.
3170
3171 .. container:: verbose
3172
3173 Some examples:
3174
3175 - Edit the commit message for the working directory parent::
3176
3177 hg metaedit
3178
3179 - Change the username for the working directory parent::
3180
3181 hg metaedit --user 'New User <new-email@example.com>'
3182
3183 """
3184 revs = list(revs)
3185 revs.extend(opts['rev'])
3186 if not revs:
3187 revs = ['.']
3188
3189 wlock = lock = None
3190 try:
3191 wlock = repo.wlock()
3192 lock = repo.lock()
3193
3194 revs = scmutil.revrange(repo, revs)
3195 if len(revs) > 1:
3196 # TODO: handle multiple revisions. This is somewhat tricky because
3197 # if we want to edit a series of commits:
3198 #
3199 # a ---- b ---- c
3200 #
3201 # we need to rewrite a first, then directly rewrite b on top of the
3202 # new a, then rewrite c on top of the new b. So we need to handle
3203 # revisions in topological order.
3204 raise error.Abort(_('editing multiple revisions is not '
3205 'currently supported'))
3206
3207 newunstable = _disallowednewunstable(repo, revs)
3208 if newunstable:
3209 raise error.Abort(
3210 _('cannot edit commit information in the middle of a stack'),
3211 hint=_('%s will be affected') % repo[newunstable.first()])
3212 if repo.revs("%ld and public()", revs):
3213 raise error.Abort(_('cannot edit commit information for public '
3214 'revisions'))
3215 root = head = repo[revs.first()]
3216
3217 wctx = repo[None]
3218 p1 = wctx.p1()
3219 tr = repo.transaction('metaedit')
3220 newp1 = None
3221 try:
3222 commitopts = opts.copy()
3223 allctx = [repo[r] for r in revs]
3224 targetphase = max(c.phase() for c in allctx)
3225
3226 if commitopts.get('message') or commitopts.get('logfile'):
3227 commitopts['edit'] = False
3228 else:
3229 msgs = [head.description()]
3230 commitopts['message'] = "\n".join(msgs)
3231 commitopts['edit'] = True
3232
3233 # TODO: if the author and message are the same, don't create a new
3234 # hash. Right now we create a new hash because the date can be
3235 # different.
3236 newid, created = rewrite(repo, root, allctx, head,
3237 [root.p1().node(), root.p2().node()],
3238 commitopts=commitopts)
3239 if created:
3240 if p1.rev() in revs:
3241 newp1 = newid
3242 phases.retractboundary(repo, tr, targetphase, [newid])
3243 obsolete.createmarkers(repo, [(ctx, (repo[newid],))
3244 for ctx in allctx])
3245 else:
3246 ui.status(_("nothing changed\n"))
3247 tr.close()
3248 finally:
3249 tr.release()
3250
3251 if newp1 is not None:
3252 hg.update(repo, newp1)
3253 finally:
3254 lockmod.release(lock, wlock)
3255
3161 def _foldcheck(repo, revs): 3256 def _foldcheck(repo, revs):
3162 roots = repo.revs('roots(%ld)', revs) 3257 roots = repo.revs('roots(%ld)', revs)
3163 if len(roots) > 1: 3258 if len(roots) > 1:
3164 raise error.Abort(_("cannot fold non-linear revisions " 3259 raise error.Abort(_("cannot fold non-linear revisions "
3165 "(multiple roots given)")) 3260 "(multiple roots given)"))