annotate mercurial/cmd_impls/graft.py @ 52364:8d7029218a61

graft: move "dry_run" and "base" in statedate Same logic as before.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 20 Nov 2024 02:37:37 +0100
parents 11fb7f737456
children da216ed31c3d
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',
52364
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
119 b'dry_run',
52362
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
120 ):
8572e80f978c graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52361
diff changeset
121 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
122 # 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
123 # 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
124 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
125 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
126
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
127 skipped = set()
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
128 basectx = 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 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
130 basectx = logcmdutil.revsingle(repo, opts['base'], None)
52364
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
131 statedata[b'base'] = basectx.hex()
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
132 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
133 # 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
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
142
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
143 # 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
144 # --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
145 # 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
146 # 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
147 # 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
148 # 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
149 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
150 # 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
151 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
152 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
153 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
154
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
155 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
156
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
157 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
158 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
159
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
160 # 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
161 ids = {}
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
162 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
163 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
164 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
165 if n:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
166 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
167
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
168 # 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
169 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
170
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
171 # 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
172 # 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
173 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
174 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
175 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
176 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
177 try:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
178 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
179 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
180 r = None
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
181 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
182 ui.warn(
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 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
185 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
186 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
187 % (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
188 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
189 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
190 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
191 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
192 ui.warn(
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 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
195 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
196 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
197 % (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
198 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
199 else:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
200 ui.warn(
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 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
203 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
204 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
205 % (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
206 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
207 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
208 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
209 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
210 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
211 ui.warn(
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 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
214 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
215 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
216 % (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
217 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
218 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
219 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
220 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
221
52364
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
222 dry_run = bool(opts.get("dry_run"))
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
223 return "GRAFT", [graftstate, statedata, revs, editor, cont, dry_run, opts]
52361
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 cont=False,
52364
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
234 dry_run=False,
52361
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)
52364
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
248 if dry_run:
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
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'')}
52364
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
268 if b'base' in statedata:
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
269 base = repo[statedata[b'base']]
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
270 else:
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
271 base = ctx.p1()
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
272 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
273 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
274 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
275 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
276 # 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
277 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
278 # 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
279 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
280 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
281 stateversion = 1
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
282 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
283 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
284 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
285 return 1
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
286 else:
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
287 cont = False
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
288
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
289 # 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
290 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
291 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
292 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
293 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
294 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
295 ui.warn(
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
296 _(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
297 % (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
298 )
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
299 # 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
300 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
301 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
302 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
303 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
304
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
305 # remove state when we complete successfully
52364
8d7029218a61 graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52363
diff changeset
306 if not dry_run:
52360
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
307 graftstate.delete()
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 return 0
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
310
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
311
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
312 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
313 """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
314 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
315 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
316 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
317 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
318 graftstate.delete()
f2fc0a91faca commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff changeset
319 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
320 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
321 return 0