annotate mercurial/cmd_impls/graft.py @ 52368:8faabe8abf66

graft: gather arg compatibility code Lets do it all in one place and at the start, this is easier to maintain consistently. We also take this as an opportunity to do this before we resolve commit options, that so user do not get error about "--date" when they actually they specified the "--current-date" argument.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 28 Nov 2024 13:22:31 +0100
parents 0b52283d50bb
children 58827d815646
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
1 # graft.py - implementation of the graft command
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
2
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
3 from ..i18n import _
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
4
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
5 from .. import cmdutil, error, logcmdutil, merge as mergemod, state as statemod
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
6
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
7
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
8 def cmd_graft(ui, repo, *revs, **opts):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
9 """implement the graft command as defined in mercuria/commands.py"""
52361
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
10 ret = _process_args(ui, repo, *revs, **opts)
52366
77cb5d8643b3 graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52365
diff changeset
11 action, graftstate, args = ret
77cb5d8643b3 graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52365
diff changeset
12 if action == "ERROR":
52361
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
13 return -1
52366
77cb5d8643b3 graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52365
diff changeset
14 elif action == "ABORT":
77cb5d8643b3 graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52365
diff changeset
15 assert args is None
77cb5d8643b3 graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52365
diff changeset
16 return cmdutil.abortgraft(ui, repo, graftstate)
52361
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
17 elif action == "STOP":
52366
77cb5d8643b3 graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52365
diff changeset
18 assert args is None
77cb5d8643b3 graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52365
diff changeset
19 return _stopgraft(ui, repo, graftstate)
52361
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
20 elif action == "GRAFT":
52366
77cb5d8643b3 graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52365
diff changeset
21 return _graft_revisions(ui, repo, graftstate, *args)
52361
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
22 else:
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
23 raise error.ProgrammingError(b'unknown action: %s' % action)
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
24
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
25
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
26 def _process_args(ui, repo, *revs, **opts):
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
27 """process the graft command argument to figure out what to do
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
28
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
29 This also filter the selected revision to skip the one that cannot be graft
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
30 or were alredy grafted.
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
31 """
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
32 if revs and opts.get('rev'):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
33 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
34 _(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
35 b'warning: inconsistent use of --rev might give unexpected '
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
36 b'revision ordering!\n'
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
37 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
38 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
39
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
40 revs = list(revs)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
41 revs.extend(opts.get('rev'))
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
42 # a dict of data to be stored in state file
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
43 statedata = {}
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
44 # list of new nodes created by ongoing graft
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
45 statedata[b'newnodes'] = []
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
46
52368
8faabe8abf66 graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52367
diff changeset
47 # argument incompatible with followup from an interrupted operation
8faabe8abf66 graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52367
diff changeset
48 commit_args = ['edit', 'log', 'user', 'date', 'currentdate', 'currentuser']
8faabe8abf66 graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52367
diff changeset
49 nofollow_args = commit_args + ['rev']
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
50
52368
8faabe8abf66 graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52367
diff changeset
51 arg_compatibilities = [
8faabe8abf66 graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52367
diff changeset
52 ('no_commit', commit_args),
8faabe8abf66 graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52367
diff changeset
53 ('stop', nofollow_args),
8faabe8abf66 graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52367
diff changeset
54 ('abort', nofollow_args),
8faabe8abf66 graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52367
diff changeset
55 ]
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
56 cmdutil.check_at_most_one_arg(opts, 'abort', 'stop', 'continue')
52368
8faabe8abf66 graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52367
diff changeset
57 for arg, incompatible in arg_compatibilities:
8faabe8abf66 graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52367
diff changeset
58 cmdutil.check_incompatible_arguments(opts, arg, incompatible)
8faabe8abf66 graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52367
diff changeset
59
8faabe8abf66 graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52367
diff changeset
60 cmdutil.resolve_commit_options(ui, opts)
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
61
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
62 cont = False
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
63
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
64 graftstate = statemod.cmdstate(repo, b'graftstate')
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
65
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
66 if opts.get('stop'):
52366
77cb5d8643b3 graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52365
diff changeset
67 return "STOP", graftstate, None
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
68 elif opts.get('abort'):
52366
77cb5d8643b3 graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52365
diff changeset
69 return "ABORT", graftstate, None
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
70 elif opts.get('continue'):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
71 cont = True
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
72 if revs:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
73 raise error.InputError(_(b"can't specify --continue and revisions"))
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
74 # read in unfinished revisions
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
75 if graftstate.exists():
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
76 statedata = cmdutil.readgraftstate(repo, graftstate)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
77 if statedata.get(b'no_commit'):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
78 opts['no_commit'] = statedata.get(b'no_commit')
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
79 if statedata.get(b'base'):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
80 opts['base'] = statedata.get(b'base')
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
81 nodes = statedata[b'nodes']
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
82 revs = [repo[node].rev() for node in nodes]
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
83 else:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
84 cmdutil.wrongtooltocontinue(repo, _(b'graft'))
52361
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
85 elif not revs:
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
86 raise error.InputError(_(b'no revisions specified'))
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
87 else:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
88 cmdutil.checkunfinished(repo)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
89 cmdutil.bailifchanged(repo)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
90 revs = logcmdutil.revrange(repo, revs)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
91
52362
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
92 for o in (
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
93 b'date',
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
94 b'user',
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
95 b'log',
52363
11fb7f737456 graft: move no_commit into "statedata" too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52362
diff changeset
96 b'no_commit',
52364
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
97 b'dry_run',
52362
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
98 ):
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
99 v = opts.get(o.decode('ascii'))
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
100 # if statedata is already set, it comes from --continue and test says
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
101 # we should honor them above the options (which seems weird).
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
102 if v and o not in statedata:
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
103 statedata[o] = v
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
104
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
105 skipped = set()
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
106 basectx = None
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
107 if opts.get('base'):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
108 basectx = logcmdutil.revsingle(repo, opts['base'], None)
52364
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
109 statedata[b'base'] = basectx.hex()
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
110 if basectx is None:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
111 # check for merges
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
112 for rev in repo.revs(b'%ld and merge()', revs):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
113 ui.warn(_(b'skipping ungraftable merge revision %d\n') % rev)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
114 skipped.add(rev)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
115 revs = [r for r in revs if r not in skipped]
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
116 if not revs:
52366
77cb5d8643b3 graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52365
diff changeset
117 return "ERROR", None, None
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
118 if basectx is not None and len(revs) != 1:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
119 raise error.InputError(_(b'only one revision allowed with --base '))
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
120
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
121 # Don't check in the --continue case, in effect retaining --force across
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
122 # --continues. That's because without --force, any revisions we decided to
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
123 # skip would have been filtered out here, so they wouldn't have made their
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
124 # way to the graftstate. With --force, any revisions we would have otherwise
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
125 # skipped would not have been filtered out, and if they hadn't been applied
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
126 # already, they'd have been in the graftstate.
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
127 if not (cont or opts.get('force')) and basectx is None:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
128 # check for ancestors of dest branch
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
129 ancestors = repo.revs(b'%ld & (::.)', revs)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
130 for rev in ancestors:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
131 ui.warn(_(b'skipping ancestor revision %d:%s\n') % (rev, repo[rev]))
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
132
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
133 revs = [r for r in revs if r not in ancestors]
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
134
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
135 if not revs:
52366
77cb5d8643b3 graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52365
diff changeset
136 return "ERROR", None, None
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
137
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
138 # analyze revs for earlier grafts
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
139 ids = {}
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
140 for ctx in repo.set(b"%ld", revs):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
141 ids[ctx.hex()] = ctx.rev()
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
142 n = ctx.extra().get(b'source')
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
143 if n:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
144 ids[n] = ctx.rev()
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
145
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
146 # check ancestors for earlier grafts
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
147 ui.debug(b'scanning for duplicate grafts\n')
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
148
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
149 # The only changesets we can be sure doesn't contain grafts of any
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
150 # revs, are the ones that are common ancestors of *all* revs:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
151 for rev in repo.revs(b'only(%d,ancestor(%ld))', repo[b'.'].rev(), revs):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
152 ctx = repo[rev]
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
153 n = ctx.extra().get(b'source')
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
154 if n in ids:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
155 try:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
156 r = repo[n].rev()
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
157 except error.RepoLookupError:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
158 r = None
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
159 if r in revs:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
160 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
161 _(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
162 b'skipping revision %d:%s '
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
163 b'(already grafted to %d:%s)\n'
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
164 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
165 % (r, repo[r], rev, ctx)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
166 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
167 revs.remove(r)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
168 elif ids[n] in revs:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
169 if r is None:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
170 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
171 _(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
172 b'skipping already grafted revision %d:%s '
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
173 b'(%d:%s also has unknown origin %s)\n'
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
174 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
175 % (ids[n], repo[ids[n]], rev, ctx, n[:12])
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
176 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
177 else:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
178 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
179 _(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
180 b'skipping already grafted revision %d:%s '
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
181 b'(%d:%s also has origin %d:%s)\n'
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
182 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
183 % (ids[n], repo[ids[n]], rev, ctx, r, n[:12])
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
184 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
185 revs.remove(ids[n])
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
186 elif ctx.hex() in ids:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
187 r = ids[ctx.hex()]
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
188 if r in revs:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
189 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
190 _(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
191 b'skipping already grafted revision %d:%s '
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
192 b'(was grafted from %d:%s)\n'
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
193 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
194 % (r, repo[r], rev, ctx)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
195 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
196 revs.remove(r)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
197 if not revs:
52366
77cb5d8643b3 graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52365
diff changeset
198 return "ERROR", None, None
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
199
52367
0b52283d50bb graft: get the editor later
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52366
diff changeset
200 editor = cmdutil.getcommiteditor(editform=b'graft', **opts)
52364
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
201 dry_run = bool(opts.get("dry_run"))
52365
da216ed31c3d graft: explicitly pass the "tool" argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52364
diff changeset
202 tool = opts.get('tool', b'')
52366
77cb5d8643b3 graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52365
diff changeset
203 return "GRAFT", graftstate, (statedata, revs, editor, cont, dry_run, tool)
52361
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
204
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
205
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
206 def _graft_revisions(
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
207 ui,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
208 repo,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
209 graftstate,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
210 statedata,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
211 revs,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
212 editor,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
213 cont=False,
52364
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
214 dry_run=False,
52365
da216ed31c3d graft: explicitly pass the "tool" argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52364
diff changeset
215 tool=b'',
52361
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
216 ):
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
217 """actually graft some revisions"""
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
218 for pos, ctx in enumerate(repo.set(b"%ld", revs)):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
219 desc = b'%d:%s "%s"' % (
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
220 ctx.rev(),
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
221 ctx,
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
222 ctx.description().split(b'\n', 1)[0],
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
223 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
224 names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node())
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
225 if names:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
226 desc += b' (%s)' % b' '.join(names)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
227 ui.status(_(b'grafting %s\n') % desc)
52364
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
228 if dry_run:
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
229 continue
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
230
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
231 source = ctx.extra().get(b'source')
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
232 extra = {}
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
233 if source:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
234 extra[b'source'] = source
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
235 extra[b'intermediate-source'] = ctx.hex()
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
236 else:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
237 extra[b'source'] = ctx.hex()
52362
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
238 user = statedata.get(b'user', ctx.user())
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
239 date = statedata.get(b'date', ctx.date())
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
240 message = ctx.description()
52362
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
241 if statedata.get(b'log'):
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
242 message += b'\n(grafted from %s)' % ctx.hex()
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
243
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
244 # we don't merge the first commit when continuing
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
245 if not cont:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
246 # perform the graft merge with p1(rev) as 'ancestor'
52365
da216ed31c3d graft: explicitly pass the "tool" argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52364
diff changeset
247 overrides = {(b'ui', b'forcemerge'): tool}
52364
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
248 if b'base' in statedata:
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
249 base = repo[statedata[b'base']]
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
250 else:
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
251 base = ctx.p1()
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
252 with ui.configoverride(overrides, b'graft'):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
253 stats = mergemod.graft(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
254 repo, ctx, base, [b'local', b'graft', b'parent of graft']
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
255 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
256 # report any conflicts
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
257 if stats.unresolvedcount > 0:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
258 # write out state for --continue
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
259 nodes = [repo[rev].hex() for rev in revs[pos:]]
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
260 statedata[b'nodes'] = nodes
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
261 stateversion = 1
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
262 graftstate.save(stateversion, statedata)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
263 ui.error(_(b"abort: unresolved conflicts, can't continue\n"))
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
264 ui.error(_(b"(use 'hg resolve' and 'hg graft --continue')\n"))
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
265 return 1
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
266 else:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
267 cont = False
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
268
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
269 # commit if --no-commit is false
52363
11fb7f737456 graft: move no_commit into "statedata" too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52362
diff changeset
270 if not statedata.get(b'no_commit'):
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
271 node = repo.commit(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
272 text=message, user=user, date=date, extra=extra, editor=editor
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
273 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
274 if node is None:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
275 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
276 _(b'note: graft of %d:%s created no changes to commit\n')
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
277 % (ctx.rev(), ctx)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
278 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
279 # checking that newnodes exist because old state files won't have it
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
280 elif statedata.get(b'newnodes') is not None:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
281 nn = statedata[b'newnodes']
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
282 assert isinstance(nn, list) # list of bytes
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
283 nn.append(node)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
284
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
285 # remove state when we complete successfully
52364
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
286 if not dry_run:
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
287 graftstate.delete()
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
288
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
289 return 0
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
290
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
291
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
292 def _stopgraft(ui, repo, graftstate):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
293 """stop the interrupted graft"""
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
294 if not graftstate.exists():
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
295 raise error.StateError(_(b"no interrupted graft found"))
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
296 pctx = repo[b'.']
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
297 mergemod.clean_update(pctx)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
298 graftstate.delete()
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
299 ui.status(_(b"stopped the interrupted graft\n"))
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
300 ui.status(_(b"working directory is now at %s\n") % pctx.hex()[:12])
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
301 return 0