comparison hgext/evolve.py @ 1683:1b1c8c0ab20e

evolve: factor out sanity checks for folds We're going to use the same checks in another context in an upcoming patch.
author Siddharth Agarwal <sid0@fb.com>
date Mon, 25 Apr 2016 16:24:42 -0700
parents fe4b41a2af4e
children 40d7b0c4abb1
comparison
equal deleted inserted replaced
1682:fe4b41a2af4e 1683:1b1c8c0ab20e
3120 3120
3121 if len(revs) == 1: 3121 if len(revs) == 1:
3122 ui.write_err(_('single revision specified, nothing to fold\n')) 3122 ui.write_err(_('single revision specified, nothing to fold\n'))
3123 return 1 3123 return 1
3124 3124
3125 root, head = _foldcheck(repo, revs)
3126
3127 wlock = lock = None
3128 try:
3129 wlock = repo.wlock()
3130 lock = repo.lock()
3131 tr = repo.transaction('touch')
3132 try:
3133 commitopts = opts.copy()
3134 allctx = [repo[r] for r in revs]
3135 targetphase = max(c.phase() for c in allctx)
3136
3137 if commitopts.get('message') or commitopts.get('logfile'):
3138 commitopts['edit'] = False
3139 else:
3140 msgs = ["HG: This is a fold of %d changesets." % len(allctx)]
3141 msgs += ["HG: Commit message of changeset %s.\n\n%s\n" %
3142 (c.rev(), c.description()) for c in allctx]
3143 commitopts['message'] = "\n".join(msgs)
3144 commitopts['edit'] = True
3145
3146 newid, unusedvariable = rewrite(repo, root, allctx, head,
3147 [root.p1().node(),
3148 root.p2().node()],
3149 commitopts=commitopts)
3150 phases.retractboundary(repo, tr, targetphase, [newid])
3151 obsolete.createmarkers(repo, [(ctx, (repo[newid],))
3152 for ctx in allctx])
3153 tr.close()
3154 finally:
3155 tr.release()
3156 ui.status('%i changesets folded\n' % len(revs))
3157 if repo['.'].rev() in revs:
3158 hg.update(repo, newid)
3159 finally:
3160 lockmod.release(lock, wlock)
3161
3162 def _foldcheck(repo, revs):
3125 roots = repo.revs('roots(%ld)', revs) 3163 roots = repo.revs('roots(%ld)', revs)
3126 if len(roots) > 1: 3164 if len(roots) > 1:
3127 raise error.Abort(_("cannot fold non-linear revisions " 3165 raise error.Abort(_("cannot fold non-linear revisions "
3128 "(multiple roots given)")) 3166 "(multiple roots given)"))
3129 root = repo[roots.first()] 3167 root = repo[roots.first()]
3137 disallowunstable = not obsolete.isenabled(repo, obsolete.allowunstableopt) 3175 disallowunstable = not obsolete.isenabled(repo, obsolete.allowunstableopt)
3138 if disallowunstable: 3176 if disallowunstable:
3139 if repo.revs("(%ld::) - %ld", revs, revs): 3177 if repo.revs("(%ld::) - %ld", revs, revs):
3140 raise error.Abort(_("cannot fold chain not ending with a head "\ 3178 raise error.Abort(_("cannot fold chain not ending with a head "\
3141 "or with branching")) 3179 "or with branching"))
3142 wlock = lock = None 3180 return root, head
3143 try:
3144 wlock = repo.wlock()
3145 lock = repo.lock()
3146 tr = repo.transaction('touch')
3147 try:
3148 commitopts = opts.copy()
3149 allctx = [repo[r] for r in revs]
3150 targetphase = max(c.phase() for c in allctx)
3151
3152 if commitopts.get('message') or commitopts.get('logfile'):
3153 commitopts['edit'] = False
3154 else:
3155 msgs = ["HG: This is a fold of %d changesets." % len(allctx)]
3156 msgs += ["HG: Commit message of changeset %s.\n\n%s\n" %
3157 (c.rev(), c.description()) for c in allctx]
3158 commitopts['message'] = "\n".join(msgs)
3159 commitopts['edit'] = True
3160
3161 newid, unusedvariable = rewrite(repo, root, allctx, head,
3162 [root.p1().node(),
3163 root.p2().node()],
3164 commitopts=commitopts)
3165 phases.retractboundary(repo, tr, targetphase, [newid])
3166 obsolete.createmarkers(repo, [(ctx, (repo[newid],))
3167 for ctx in allctx])
3168 tr.close()
3169 finally:
3170 tr.release()
3171 ui.status('%i changesets folded\n' % len(revs))
3172 if repo['.'].rev() in revs:
3173 hg.update(repo, newid)
3174 finally:
3175 lockmod.release(lock, wlock)
3176
3177
3178 3181
3179 @eh.wrapcommand('graft') 3182 @eh.wrapcommand('graft')
3180 def graftwrapper(orig, ui, repo, *revs, **kwargs): 3183 def graftwrapper(orig, ui, repo, *revs, **kwargs):
3181 kwargs = dict(kwargs) 3184 kwargs = dict(kwargs)
3182 revs = list(revs) + kwargs.get('rev', []) 3185 revs = list(revs) + kwargs.get('rev', [])