annotate mercurial/cmd_impls/graft.py @ 52363:11fb7f737456

graft: move no_commit into "statedata" too Same logic as before.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 20 Nov 2024 02:37:28 +0100
parents 8572e80f978c
children 8d7029218a61
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)
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
11 if ret is None:
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
12 return -1
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
13 action, args = ret
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
14 if action == "ABORT":
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
15 return cmdutil.abortgraft(ui, repo, *args)
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
16 elif action == "STOP":
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
17 return _stopgraft(ui, repo, *args)
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
18 elif action == "GRAFT":
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
19 return _graft_revisions(ui, repo, *args)
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
20 else:
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
21 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
22 return 0
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
23
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 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
26 """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
27
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
28 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
29 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
30 """
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
31 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
32 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
33 _(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
34 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
35 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
36 )
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 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
40 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
41 # 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
42 statedata = {}
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
43 # 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
44 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
45
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
46 cmdutil.resolve_commit_options(ui, opts)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
47
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
48 editor = cmdutil.getcommiteditor(editform=b'graft', **opts)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
49
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
50 cmdutil.check_at_most_one_arg(opts, 'abort', 'stop', 'continue')
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
51
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
52 cont = False
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
53 if opts.get('no_commit'):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
54 cmdutil.check_incompatible_arguments(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
55 opts,
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
56 'no_commit',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
57 ['edit', 'currentuser', 'currentdate', 'log'],
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
58 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
59
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
60 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
61
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
62 if opts.get('stop'):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
63 cmdutil.check_incompatible_arguments(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
64 opts,
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
65 'stop',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
66 [
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
67 'edit',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
68 'log',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
69 'user',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
70 'date',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
71 'currentdate',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
72 'currentuser',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
73 'rev',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
74 ],
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
75 )
52361
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
76 return "STOP", [graftstate]
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
77 elif opts.get('abort'):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
78 cmdutil.check_incompatible_arguments(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
79 opts,
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
80 'abort',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
81 [
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
82 'edit',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
83 'log',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
84 'user',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
85 'date',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
86 'currentdate',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
87 'currentuser',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
88 'rev',
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
89 ],
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
90 )
52361
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
91 return "ABORT", [graftstate]
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
92 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
93 cont = True
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
94 if revs:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
95 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
96 # 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
97 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
98 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
99 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
100 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
101 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
102 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
103 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
104 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
105 else:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
106 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
107 elif not revs:
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
108 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
109 else:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
110 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
111 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
112 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
113
52362
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
114 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
115 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
116 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
117 b'log',
52363
11fb7f737456 graft: move no_commit into "statedata" too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52362
diff changeset
118 b'no_commit',
52362
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
119 ):
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
120 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
121 # 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
122 # 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
123 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
124 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
125
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
126 skipped = set()
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
127 basectx = None
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
128 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
129 basectx = logcmdutil.revsingle(repo, opts['base'], None)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
130 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
131 # 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
132 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
133 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
134 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
135 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
136 if not revs:
52361
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
137 return None
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
138 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
139 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
140
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
141 # 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
142 # --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
143 # 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
144 # 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
145 # 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
146 # 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
147 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
148 # 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
149 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
150 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
151 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
152
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
153 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
154
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
155 if not revs:
52361
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
156 return None
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
157
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
158 # 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
159 ids = {}
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
160 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
161 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
162 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
163 if n:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
164 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
165
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
166 # 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
167 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
168
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
169 # 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
170 # 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
171 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
172 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
173 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
174 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
175 try:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
176 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
177 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
178 r = None
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
179 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
180 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
181 _(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
182 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
183 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
184 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
185 % (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
186 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
187 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
188 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
189 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
190 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
191 _(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
192 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
193 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
194 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
195 % (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
196 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
197 else:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
198 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
199 _(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
200 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
201 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
202 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
203 % (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
204 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
205 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
206 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
207 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
208 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
209 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
210 _(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
211 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
212 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
213 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
214 % (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
215 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
216 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
217 if not revs:
52361
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
218 return None
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
219
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
220 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
221 statedata[b'base'] = opts['base']
52361
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
222
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
223 return "GRAFT", [graftstate, statedata, revs, editor, basectx, cont, opts]
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
224
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
225
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
226 def _graft_revisions(
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
227 ui,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
228 repo,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
229 graftstate,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
230 statedata,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
231 revs,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
232 editor,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
233 basectx,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
234 cont=False,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
235 opts,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
236 ):
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
237 """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
238 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
239 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
240 ctx.rev(),
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
241 ctx,
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
242 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
243 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
244 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
245 if names:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
246 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
247 ui.status(_(b'grafting %s\n') % desc)
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
248 if opts.get('dry_run'):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
249 continue
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
250
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
251 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
252 extra = {}
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
253 if source:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
254 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
255 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
256 else:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
257 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
258 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
259 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
260 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
261 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
262 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
263
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
264 # 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
265 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
266 # perform the graft merge with p1(rev) as 'ancestor'
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
267 overrides = {(b'ui', b'forcemerge'): opts.get('tool', b'')}
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
268 base = ctx.p1() if basectx is None else basectx
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
269 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
270 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
271 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
272 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
273 # 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
274 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
275 # 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
276 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
277 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
278 stateversion = 1
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
279 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
280 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
281 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
282 return 1
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
283 else:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
284 cont = False
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
285
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
286 # 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
287 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
288 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
289 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
290 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
291 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
292 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
293 _(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
294 % (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
295 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
296 # 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
297 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
298 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
299 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
300 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
301
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
302 # remove state when we complete successfully
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
303 if not opts.get('dry_run'):
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
304 graftstate.delete()
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
305
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
306 return 0
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
307
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
308
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
309 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
310 """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
311 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
312 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
313 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
314 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
315 graftstate.delete()
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
316 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
317 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
318 return 0