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.
pulkit |
hg-reviewers |
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.
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/cmdutil.py (65 lines) | |||
M | mercurial/commands.py (68 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
78613fb531a8 | 400c1d83b76f | Taapas Agrawal | Jul 6 2019, 12:49 PM |
Status | Author | Revision | |
---|---|---|---|
Closed | taapas1128 | ||
Closed | taapas1128 | ||
Closed | taapas1128 | ||
Closed | taapas1128 | ||
Closed | taapas1128 |
narrowspec, | narrowspec, | ||||
obsolete, | obsolete, | ||||
obsutil, | obsutil, | ||||
patch, | patch, | ||||
phases, | phases, | ||||
pycompat, | pycompat, | ||||
rcutil, | rcutil, | ||||
registrar, | registrar, | ||||
repair, | |||||
revsetlang, | revsetlang, | ||||
rewriteutil, | rewriteutil, | ||||
scmutil, | scmutil, | ||||
server, | server, | ||||
shelve as shelvemod, | shelve as shelvemod, | ||||
state as statemod, | state as statemod, | ||||
streamclone, | streamclone, | ||||
tags as tagsmod, | tags as tagsmod, | ||||
if opts.get('continue'): | if opts.get('continue'): | ||||
raise error.Abort(_("cannot use '--continue' and " | raise error.Abort(_("cannot use '--continue' and " | ||||
"'--abort' together")) | "'--abort' together")) | ||||
if any((opts.get('edit'), opts.get('log'), opts.get('user'), | if any((opts.get('edit'), opts.get('log'), opts.get('user'), | ||||
opts.get('date'), opts.get('currentdate'), | opts.get('date'), opts.get('currentdate'), | ||||
opts.get('currentuser'), opts.get('rev'))): | opts.get('currentuser'), opts.get('rev'))): | ||||
raise error.Abort(_("cannot specify any other flag with '--abort'")) | raise error.Abort(_("cannot specify any other flag with '--abort'")) | ||||
return _abortgraft(ui, repo, graftstate) | return cmdutil.abortgraft(ui, repo, graftstate) | ||||
elif opts.get('continue'): | elif opts.get('continue'): | ||||
cont = True | cont = True | ||||
if revs: | if revs: | ||||
raise error.Abort(_("can't specify --continue and revisions")) | raise error.Abort(_("can't specify --continue and revisions")) | ||||
# read in unfinished revisions | # read in unfinished revisions | ||||
if graftstate.exists(): | if graftstate.exists(): | ||||
statedata = _readgraftstate(repo, graftstate) | statedata = cmdutil.readgraftstate(repo, graftstate) | ||||
if statedata.get('date'): | if statedata.get('date'): | ||||
opts['date'] = statedata['date'] | opts['date'] = statedata['date'] | ||||
if statedata.get('user'): | if statedata.get('user'): | ||||
opts['user'] = statedata['user'] | opts['user'] = statedata['user'] | ||||
if statedata.get('log'): | if statedata.get('log'): | ||||
opts['log'] = True | opts['log'] = True | ||||
if statedata.get('no_commit'): | if statedata.get('no_commit'): | ||||
opts['no_commit'] = statedata.get('no_commit') | opts['no_commit'] = statedata.get('no_commit') | ||||
statedata['newnodes'].append(node) | statedata['newnodes'].append(node) | ||||
# remove state when we complete successfully | # remove state when we complete successfully | ||||
if not opts.get('dry_run'): | if not opts.get('dry_run'): | ||||
graftstate.delete() | graftstate.delete() | ||||
return 0 | return 0 | ||||
def _abortgraft(ui, repo, graftstate): | |||||
"""abort the interrupted graft and rollbacks to the state before interrupted | |||||
graft""" | |||||
if not graftstate.exists(): | |||||
raise error.Abort(_("no interrupted graft to abort")) | |||||
statedata = _readgraftstate(repo, graftstate) | |||||
newnodes = statedata.get('newnodes') | |||||
if newnodes is None: | |||||
# and old graft state which does not have all the data required to abort | |||||
# the graft | |||||
raise error.Abort(_("cannot abort using an old graftstate")) | |||||
# changeset from which graft operation was started | |||||
if len(newnodes) > 0: | |||||
startctx = repo[newnodes[0]].p1() | |||||
else: | |||||
startctx = repo['.'] | |||||
# whether to strip or not | |||||
cleanup = False | |||||
if newnodes: | |||||
newnodes = [repo[r].rev() for r in newnodes] | |||||
cleanup = True | |||||
# checking that none of the newnodes turned public or is public | |||||
immutable = [c for c in newnodes if not repo[c].mutable()] | |||||
if immutable: | |||||
repo.ui.warn(_("cannot clean up public changesets %s\n") | |||||
% ', '.join(bytes(repo[r]) for r in immutable), | |||||
hint=_("see 'hg help phases' for details")) | |||||
cleanup = False | |||||
# checking that no new nodes are created on top of grafted revs | |||||
desc = set(repo.changelog.descendants(newnodes)) | |||||
if desc - set(newnodes): | |||||
repo.ui.warn(_("new changesets detected on destination " | |||||
"branch, can't strip\n")) | |||||
cleanup = False | |||||
if cleanup: | |||||
with repo.wlock(), repo.lock(): | |||||
hg.updaterepo(repo, startctx.node(), overwrite=True) | |||||
# stripping the new nodes created | |||||
strippoints = [c.node() for c in repo.set("roots(%ld)", | |||||
newnodes)] | |||||
repair.strip(repo.ui, repo, strippoints, backup=False) | |||||
if not cleanup: | |||||
# we don't update to the startnode if we can't strip | |||||
startctx = repo['.'] | |||||
hg.updaterepo(repo, startctx.node(), overwrite=True) | |||||
ui.status(_("graft aborted\n")) | |||||
ui.status(_("working directory is now at %s\n") % startctx.hex()[:12]) | |||||
graftstate.delete() | |||||
return 0 | |||||
def _readgraftstate(repo, graftstate): | |||||
"""read the graft state file and return a dict of the data stored in it""" | |||||
try: | |||||
return graftstate.read() | |||||
except error.CorruptedState: | |||||
nodes = repo.vfs.read('graftstate').splitlines() | |||||
return {'nodes': nodes} | |||||
def _stopgraft(ui, repo, graftstate): | def _stopgraft(ui, repo, graftstate): | ||||
"""stop the interrupted graft""" | """stop the interrupted graft""" | ||||
if not graftstate.exists(): | if not graftstate.exists(): | ||||
raise error.Abort(_("no interrupted graft found")) | raise error.Abort(_("no interrupted graft found")) | ||||
pctx = repo['.'] | pctx = repo['.'] | ||||
hg.updaterepo(repo, pctx.node(), overwrite=True) | hg.updaterepo(repo, pctx.node(), overwrite=True) | ||||
graftstate.delete() | graftstate.delete() | ||||
ui.status(_("stopped the interrupted graft\n")) | ui.status(_("stopped the interrupted graft\n")) |
We should drop _ perfix from names, both here and below.