comparison mercurial/cmdutil.py @ 42568:f9da9d5f3f5a

graft: moved abortgraft and readgraft to cmdutil This patch moves `abortgraft` and `readgraft` to `cmdutil`. Various callers are updated accordingly. This is done because these serve as ulitlity functions for command `graft` and so that new functions regarding graft can be built from them. Differential Revision: https://phab.mercurial-scm.org/D6608
author Taapas Agrawal <taapas2897@gmail.com>
date Sat, 06 Jul 2019 22:19:36 +0530
parents 0231032729c4
children ceb31d96d3ae
comparison
equal deleted inserted replaced
42567:4eaf7197a740 42568:f9da9d5f3f5a
36 obsolete, 36 obsolete,
37 patch, 37 patch,
38 pathutil, 38 pathutil,
39 phases, 39 phases,
40 pycompat, 40 pycompat,
41 repair,
41 revlog, 42 revlog,
42 rewriteutil, 43 rewriteutil,
43 scmutil, 44 scmutil,
44 smartset, 45 smartset,
45 state as statemod, 46 state as statemod,
3343 after = howtocontinue(repo) 3344 after = howtocontinue(repo)
3344 hint = None 3345 hint = None
3345 if after[1]: 3346 if after[1]:
3346 hint = after[0] 3347 hint = after[0]
3347 raise error.Abort(_('no %s in progress') % task, hint=hint) 3348 raise error.Abort(_('no %s in progress') % task, hint=hint)
3349
3350 def abortgraft(ui, repo, graftstate):
3351 """abort the interrupted graft and rollbacks to the state before interrupted
3352 graft"""
3353 if not graftstate.exists():
3354 raise error.Abort(_("no interrupted graft to abort"))
3355 statedata = readgraftstate(repo, graftstate)
3356 newnodes = statedata.get('newnodes')
3357 if newnodes is None:
3358 # and old graft state which does not have all the data required to abort
3359 # the graft
3360 raise error.Abort(_("cannot abort using an old graftstate"))
3361
3362 # changeset from which graft operation was started
3363 if len(newnodes) > 0:
3364 startctx = repo[newnodes[0]].p1()
3365 else:
3366 startctx = repo['.']
3367 # whether to strip or not
3368 cleanup = False
3369 from . import hg
3370 if newnodes:
3371 newnodes = [repo[r].rev() for r in newnodes]
3372 cleanup = True
3373 # checking that none of the newnodes turned public or is public
3374 immutable = [c for c in newnodes if not repo[c].mutable()]
3375 if immutable:
3376 repo.ui.warn(_("cannot clean up public changesets %s\n")
3377 % ', '.join(bytes(repo[r]) for r in immutable),
3378 hint=_("see 'hg help phases' for details"))
3379 cleanup = False
3380
3381 # checking that no new nodes are created on top of grafted revs
3382 desc = set(repo.changelog.descendants(newnodes))
3383 if desc - set(newnodes):
3384 repo.ui.warn(_("new changesets detected on destination "
3385 "branch, can't strip\n"))
3386 cleanup = False
3387
3388 if cleanup:
3389 with repo.wlock(), repo.lock():
3390 hg.updaterepo(repo, startctx.node(), overwrite=True)
3391 # stripping the new nodes created
3392 strippoints = [c.node() for c in repo.set("roots(%ld)",
3393 newnodes)]
3394 repair.strip(repo.ui, repo, strippoints, backup=False)
3395
3396 if not cleanup:
3397 # we don't update to the startnode if we can't strip
3398 startctx = repo['.']
3399 hg.updaterepo(repo, startctx.node(), overwrite=True)
3400
3401 ui.status(_("graft aborted\n"))
3402 ui.status(_("working directory is now at %s\n") % startctx.hex()[:12])
3403 graftstate.delete()
3404 return 0
3405
3406 def readgraftstate(repo, graftstate):
3407 """read the graft state file and return a dict of the data stored in it"""
3408 try:
3409 return graftstate.read()
3410 except error.CorruptedState:
3411 nodes = repo.vfs.read('graftstate').splitlines()
3412 return {'nodes': nodes}