comparison hgext/uncommit.py @ 35200:9e339c97fabb

unamend: drop unused vars, query after taking lock, use ctx.hex() for extras This is the followup of review on D821. Differential Revision: https://phab.mercurial-scm.org/D1579
author Pulkit Goyal <7895pulkit@gmail.com>
date Sun, 03 Dec 2017 00:29:51 +0530
parents 9dadcb99cc17
children 98f97eb20597
comparison
equal deleted inserted replaced
35199:80bb15769c73 35200:9e339c97fabb
210 `hg amend` (e.g. files modified as part of an amend will be 210 `hg amend` (e.g. files modified as part of an amend will be
211 marked as modified `hg status`) 211 marked as modified `hg status`)
212 """ 212 """
213 213
214 unfi = repo.unfiltered() 214 unfi = repo.unfiltered()
215
216 # identify the commit from which to unamend
217 curctx = repo['.']
218
219 with repo.wlock(), repo.lock(), repo.transaction('unamend'): 215 with repo.wlock(), repo.lock(), repo.transaction('unamend'):
216
217 # identify the commit from which to unamend
218 curctx = repo['.']
219
220 if not curctx.mutable(): 220 if not curctx.mutable():
221 raise error.Abort(_('cannot unamend public changesets')) 221 raise error.Abort(_('cannot unamend public changesets'))
222 222
223 # identify the commit to which to unamend 223 # identify the commit to which to unamend
224 markers = list(predecessormarkers(curctx)) 224 markers = list(predecessormarkers(curctx))
233 raise error.Abort(_("cannot unamend a changeset with children")) 233 raise error.Abort(_("cannot unamend a changeset with children"))
234 234
235 # add an extra so that we get a new hash 235 # add an extra so that we get a new hash
236 # note: allowing unamend to undo an unamend is an intentional feature 236 # note: allowing unamend to undo an unamend is an intentional feature
237 extras = predctx.extra() 237 extras = predctx.extra()
238 extras['unamend_source'] = curctx.node() 238 extras['unamend_source'] = curctx.hex()
239 239
240 def filectxfn(repo, ctx_, path): 240 def filectxfn(repo, ctx_, path):
241 try: 241 try:
242 return predctx.filectx(path) 242 return predctx.filectx(path)
243 except KeyError: 243 except KeyError:
257 overrides = {('phases', 'new-commit'): commitphase} 257 overrides = {('phases', 'new-commit'): commitphase}
258 with repo.ui.configoverride(overrides, 'uncommit'): 258 with repo.ui.configoverride(overrides, 'uncommit'):
259 newprednode = repo.commitctx(newctx) 259 newprednode = repo.commitctx(newctx)
260 260
261 newpredctx = repo[newprednode] 261 newpredctx = repo[newprednode]
262
263 changedfiles = []
264 wctx = repo[None]
265 wm = wctx.manifest()
266 cm = newpredctx.manifest()
267 dirstate = repo.dirstate 262 dirstate = repo.dirstate
268 diff = cm.diff(wm)
269 changedfiles.extend(diff.iterkeys())
270 263
271 with dirstate.parentchange(): 264 with dirstate.parentchange():
272 dirstate.setparents(newprednode, node.nullid) 265 dirstate.setparents(newprednode, node.nullid)
273 s = repo.status(predctx, curctx) 266 s = repo.status(predctx, curctx)
274 _fixdirstate(repo, curctx, newpredctx, s) 267 _fixdirstate(repo, curctx, newpredctx, s)