annotate mercurial/cmd_impls/graft.py @ 52362:8572e80f978c

graft: assign computed configuration value to statedata instead of opts The goal is for the graft logic to not deal with the command line option, so lets to reinjecting value in these config option.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 20 Nov 2024 02:10:43 +0100
parents 5ab77b93567c
children 11fb7f737456
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',
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
118 ):
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
119 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
120 # 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
121 # 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
122 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
123 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
124
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
125 skipped = set()
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
126 basectx = None
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
127 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
128 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
129 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
130 # 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
131 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
132 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
133 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
134 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
135 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
136 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
137 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
138 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
139
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
140 # 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
141 # --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
142 # 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
143 # 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
144 # 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
145 # 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
146 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
147 # 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
148 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
149 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
150 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
151
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
152 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
153
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
154 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
155 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
156
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
157 # 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
158 ids = {}
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
159 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
160 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
161 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
162 if n:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
163 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
164
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
165 # 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
166 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
167
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
168 # 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
169 # 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
170 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
171 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
172 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
173 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
174 try:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
175 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
176 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
177 r = None
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
178 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
179 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
180 _(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
181 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
182 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
183 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
184 % (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
185 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
186 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
187 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
188 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
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'(%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
193 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
194 % (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
195 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
196 else:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
197 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
198 _(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
199 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
200 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
201 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
202 % (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
203 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
204 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
205 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
206 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
207 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
208 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
209 _(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
210 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
211 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
212 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
213 % (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
214 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
215 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
216 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
217 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
218
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
219 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
220 statedata[b'no_commit'] = True
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
221 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
222 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
223
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
224 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
225
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
226
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
227 def _graft_revisions(
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
228 ui,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
229 repo,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
230 graftstate,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
231 statedata,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
232 revs,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
233 editor,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
234 basectx,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
235 cont=False,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
236 opts,
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
237 ):
5ab77b93567c graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52360
diff changeset
238 """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
239 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
240 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
241 ctx.rev(),
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
242 ctx,
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
243 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
244 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
245 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
246 if names:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
247 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
248 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
249 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
250 continue
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
251
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
252 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
253 extra = {}
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
254 if 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'source'] = source
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
256 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
257 else:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
258 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
259 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
260 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
261 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
262 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
263 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
264
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
265 # 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
266 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
267 # 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
268 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
269 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
270 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
271 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
272 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
273 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
274 # 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
275 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
276 # 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
277 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
278 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
279 stateversion = 1
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
280 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
281 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
282 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
283 return 1
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
284 else:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
285 cont = False
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
286
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
287 # commit if --no-commit is false
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
288 if not 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
289 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
290 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
291 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
292 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
293 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
294 _(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
295 % (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
296 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
297 # 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
298 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
299 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
300 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
301 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
302
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
303 # 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
304 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
305 graftstate.delete()
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
306
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
307 return 0
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
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
310 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
311 """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
312 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
313 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
314 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
315 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
316 graftstate.delete()
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"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
318 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
319 return 0