Mercurial > public > mercurial-scm > hg
annotate mercurial/cmd_impls/graft.py @ 52504:de16800904f9
graft: extract meta information computation in a function
This will be useful to reuse it in an in-memory version of graft.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 02 Dec 2024 02:41:57 +0100 |
parents | cef86c1d5dfd |
children | 68dc6cecca32 |
rev | line source |
---|---|
52328
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 |
52350
d4e30c15626d
typing: add missing `from __future__ import annotations` to core modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
52348
diff
changeset
|
3 from __future__ import annotations |
d4e30c15626d
typing: add missing `from __future__ import annotations` to core modules
Matt Harbison <matt_harbison@yahoo.com>
parents:
52348
diff
changeset
|
4 |
52351
9042ffea4edd
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10
Matt Harbison <matt_harbison@yahoo.com>
parents:
52350
diff
changeset
|
5 import typing |
9042ffea4edd
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10
Matt Harbison <matt_harbison@yahoo.com>
parents:
52350
diff
changeset
|
6 |
9042ffea4edd
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10
Matt Harbison <matt_harbison@yahoo.com>
parents:
52350
diff
changeset
|
7 from typing import ( |
9042ffea4edd
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10
Matt Harbison <matt_harbison@yahoo.com>
parents:
52350
diff
changeset
|
8 Any, |
9042ffea4edd
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10
Matt Harbison <matt_harbison@yahoo.com>
parents:
52350
diff
changeset
|
9 Tuple, |
9042ffea4edd
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10
Matt Harbison <matt_harbison@yahoo.com>
parents:
52350
diff
changeset
|
10 ) |
9042ffea4edd
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10
Matt Harbison <matt_harbison@yahoo.com>
parents:
52350
diff
changeset
|
11 |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
12 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
|
13 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
14 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
|
15 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
16 |
52351
9042ffea4edd
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10
Matt Harbison <matt_harbison@yahoo.com>
parents:
52350
diff
changeset
|
17 if typing.TYPE_CHECKING: |
9042ffea4edd
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10
Matt Harbison <matt_harbison@yahoo.com>
parents:
52350
diff
changeset
|
18 _ActionT = str |
9042ffea4edd
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10
Matt Harbison <matt_harbison@yahoo.com>
parents:
52350
diff
changeset
|
19 _CmdArgsT = Any # TODO: (statedata, revs, editor, cont, dry_run, tool) |
9042ffea4edd
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10
Matt Harbison <matt_harbison@yahoo.com>
parents:
52350
diff
changeset
|
20 |
9042ffea4edd
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10
Matt Harbison <matt_harbison@yahoo.com>
parents:
52350
diff
changeset
|
21 |
9042ffea4edd
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10
Matt Harbison <matt_harbison@yahoo.com>
parents:
52350
diff
changeset
|
22 def cmd_graft(ui, repo, *revs, **opts) -> int: |
52347
0facc743b92f
graft: fix a few typos in doc comments
Matt Harbison <matt_harbison@yahoo.com>
parents:
52346
diff
changeset
|
23 """implement the graft command as defined in mercurial/commands.py""" |
52329
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
24 ret = _process_args(ui, repo, *revs, **opts) |
52334
77cb5d8643b3
graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52333
diff
changeset
|
25 action, graftstate, args = ret |
77cb5d8643b3
graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52333
diff
changeset
|
26 if action == "ERROR": |
52329
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
27 return -1 |
52334
77cb5d8643b3
graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52333
diff
changeset
|
28 elif action == "ABORT": |
77cb5d8643b3
graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52333
diff
changeset
|
29 assert args is None |
77cb5d8643b3
graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52333
diff
changeset
|
30 return cmdutil.abortgraft(ui, repo, graftstate) |
52329
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
31 elif action == "STOP": |
52334
77cb5d8643b3
graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52333
diff
changeset
|
32 assert args is None |
77cb5d8643b3
graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52333
diff
changeset
|
33 return _stopgraft(ui, repo, graftstate) |
52329
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
34 elif action == "GRAFT": |
52334
77cb5d8643b3
graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52333
diff
changeset
|
35 return _graft_revisions(ui, repo, graftstate, *args) |
52329
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
36 else: |
52346
1802d9afddf7
graft: fix interpolation in a ProgrammingError case
Matt Harbison <matt_harbison@yahoo.com>
parents:
52337
diff
changeset
|
37 raise error.ProgrammingError('unknown action: %s' % action) |
52329
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
38 |
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
39 |
52351
9042ffea4edd
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10
Matt Harbison <matt_harbison@yahoo.com>
parents:
52350
diff
changeset
|
40 def _process_args( |
9042ffea4edd
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10
Matt Harbison <matt_harbison@yahoo.com>
parents:
52350
diff
changeset
|
41 ui, repo, *revs, **opts |
9042ffea4edd
typing: add minimal annotations to cmd_impls/graft.py to pytype with 3.10
Matt Harbison <matt_harbison@yahoo.com>
parents:
52350
diff
changeset
|
42 ) -> Tuple[_ActionT, statemod.cmdstate | None, _CmdArgsT | None]: |
52329
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
43 """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:
52328
diff
changeset
|
44 |
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
45 This also filter the selected revision to skip the one that cannot be graft |
52347
0facc743b92f
graft: fix a few typos in doc comments
Matt Harbison <matt_harbison@yahoo.com>
parents:
52346
diff
changeset
|
46 or were already grafted. |
52329
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
47 """ |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
48 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
|
49 ui.warn( |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
50 _( |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
51 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
|
52 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
|
53 ) |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
54 ) |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
55 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
56 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
|
57 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
|
58 # 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
|
59 statedata = {} |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
60 # 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
|
61 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
|
62 |
52336
8faabe8abf66
graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52335
diff
changeset
|
63 # argument incompatible with followup from an interrupted operation |
8faabe8abf66
graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52335
diff
changeset
|
64 commit_args = ['edit', 'log', 'user', 'date', 'currentdate', 'currentuser'] |
52337
58827d815646
graft: also forbid "--base" with "--stop" and the like
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52336
diff
changeset
|
65 nofollow_args = commit_args + ['base', 'rev'] |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
66 |
52336
8faabe8abf66
graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52335
diff
changeset
|
67 arg_compatibilities = [ |
8faabe8abf66
graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52335
diff
changeset
|
68 ('no_commit', commit_args), |
8faabe8abf66
graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52335
diff
changeset
|
69 ('stop', nofollow_args), |
8faabe8abf66
graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52335
diff
changeset
|
70 ('abort', nofollow_args), |
8faabe8abf66
graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52335
diff
changeset
|
71 ] |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
72 cmdutil.check_at_most_one_arg(opts, 'abort', 'stop', 'continue') |
52336
8faabe8abf66
graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52335
diff
changeset
|
73 for arg, incompatible in arg_compatibilities: |
8faabe8abf66
graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52335
diff
changeset
|
74 cmdutil.check_incompatible_arguments(opts, arg, incompatible) |
8faabe8abf66
graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52335
diff
changeset
|
75 |
8faabe8abf66
graft: gather arg compatibility code
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52335
diff
changeset
|
76 cmdutil.resolve_commit_options(ui, opts) |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
77 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
78 cont = False |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
79 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
80 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
|
81 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
82 if opts.get('stop'): |
52334
77cb5d8643b3
graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52333
diff
changeset
|
83 return "STOP", graftstate, None |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
84 elif opts.get('abort'): |
52334
77cb5d8643b3
graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52333
diff
changeset
|
85 return "ABORT", graftstate, None |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
86 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
|
87 cont = True |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
88 if revs: |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
89 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
|
90 # 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 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
|
96 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
|
97 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
|
98 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
|
99 else: |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
100 cmdutil.wrongtooltocontinue(repo, _(b'graft')) |
52329
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
101 elif not revs: |
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
102 raise error.InputError(_(b'no revisions specified')) |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
103 else: |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
104 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
|
105 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
|
106 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
|
107 |
52330
8572e80f978c
graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52329
diff
changeset
|
108 for o in ( |
8572e80f978c
graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52329
diff
changeset
|
109 b'date', |
8572e80f978c
graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52329
diff
changeset
|
110 b'user', |
8572e80f978c
graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52329
diff
changeset
|
111 b'log', |
52331
11fb7f737456
graft: move no_commit into "statedata" too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52330
diff
changeset
|
112 b'no_commit', |
52332
8d7029218a61
graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52331
diff
changeset
|
113 b'dry_run', |
52330
8572e80f978c
graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52329
diff
changeset
|
114 ): |
8572e80f978c
graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52329
diff
changeset
|
115 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:
52329
diff
changeset
|
116 # 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:
52329
diff
changeset
|
117 # 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:
52329
diff
changeset
|
118 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:
52329
diff
changeset
|
119 statedata[o] = v |
8572e80f978c
graft: assign computed configuration value to statedata instead of opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52329
diff
changeset
|
120 |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
121 skipped = set() |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
122 basectx = None |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
123 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
|
124 basectx = logcmdutil.revsingle(repo, opts['base'], None) |
52332
8d7029218a61
graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52331
diff
changeset
|
125 statedata[b'base'] = basectx.hex() |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
126 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
|
127 # 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 if not revs: |
52334
77cb5d8643b3
graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52333
diff
changeset
|
133 return "ERROR", None, None |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
134 if basectx is not None and len(revs) != 1: |
52348
99615755fb8e
graft: trim an InputError message
Matt Harbison <matt_harbison@yahoo.com>
parents:
52347
diff
changeset
|
135 raise error.InputError(_(b'only one revision allowed with --base')) |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
136 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
137 # 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
|
138 # --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
|
139 # 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
|
140 # 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
|
141 # 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
|
142 # 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
|
143 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
|
144 # 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
|
145 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
|
146 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
|
147 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
|
148 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
149 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
|
150 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
151 if not revs: |
52334
77cb5d8643b3
graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52333
diff
changeset
|
152 return "ERROR", None, None |
52328
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 # 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
|
155 ids = {} |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
156 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
|
157 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
|
158 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
|
159 if n: |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
160 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
|
161 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
162 # 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
|
163 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
|
164 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
165 # 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
|
166 # 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 try: |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
172 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
|
173 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
|
174 r = None |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
175 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
|
176 ui.warn( |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
177 _( |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
178 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
|
179 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
|
180 ) |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
181 % (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
|
182 ) |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
183 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
|
184 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
|
185 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
|
186 ui.warn( |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
187 _( |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
188 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
|
189 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
|
190 ) |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
191 % (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
|
192 ) |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
193 else: |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
194 ui.warn( |
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 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
|
197 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
|
198 ) |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
199 % (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
|
200 ) |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
201 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
|
202 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
|
203 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
|
204 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
|
205 ui.warn( |
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 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
|
208 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
|
209 ) |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
210 % (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
|
211 ) |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
212 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
|
213 if not revs: |
52334
77cb5d8643b3
graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52333
diff
changeset
|
214 return "ERROR", None, None |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
215 |
52335
0b52283d50bb
graft: get the editor later
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52334
diff
changeset
|
216 editor = cmdutil.getcommiteditor(editform=b'graft', **opts) |
52332
8d7029218a61
graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52331
diff
changeset
|
217 dry_run = bool(opts.get("dry_run")) |
52333
da216ed31c3d
graft: explicitly pass the "tool" argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52332
diff
changeset
|
218 tool = opts.get('tool', b'') |
52334
77cb5d8643b3
graft: clarify the args passing depending of variants
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52333
diff
changeset
|
219 return "GRAFT", graftstate, (statedata, revs, editor, cont, dry_run, tool) |
52329
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
220 |
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
221 |
52503
cef86c1d5dfd
graft: extract creation of progress report line in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52351
diff
changeset
|
222 def _build_progress(ui, repo, ctx): |
cef86c1d5dfd
graft: extract creation of progress report line in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52351
diff
changeset
|
223 rev_sum = b'%d:%s "%s"' % ( |
cef86c1d5dfd
graft: extract creation of progress report line in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52351
diff
changeset
|
224 ctx.rev(), |
cef86c1d5dfd
graft: extract creation of progress report line in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52351
diff
changeset
|
225 ctx, |
cef86c1d5dfd
graft: extract creation of progress report line in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52351
diff
changeset
|
226 ctx.description().split(b'\n', 1)[0], |
cef86c1d5dfd
graft: extract creation of progress report line in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52351
diff
changeset
|
227 ) |
cef86c1d5dfd
graft: extract creation of progress report line in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52351
diff
changeset
|
228 names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node()) |
cef86c1d5dfd
graft: extract creation of progress report line in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52351
diff
changeset
|
229 if names: |
cef86c1d5dfd
graft: extract creation of progress report line in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52351
diff
changeset
|
230 rev_sum += b' (%s)' % b' '.join(names) |
cef86c1d5dfd
graft: extract creation of progress report line in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52351
diff
changeset
|
231 return _(b'grafting %s\n') % rev_sum |
cef86c1d5dfd
graft: extract creation of progress report line in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52351
diff
changeset
|
232 |
cef86c1d5dfd
graft: extract creation of progress report line in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52351
diff
changeset
|
233 |
52504
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
234 def _build_meta(ui, repo, ctx, statedata): |
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
235 source = ctx.extra().get(b'source') |
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
236 extra = {} |
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
237 if source: |
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
238 extra[b'source'] = source |
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
239 extra[b'intermediate-source'] = ctx.hex() |
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
240 else: |
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
241 extra[b'source'] = ctx.hex() |
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
242 user = statedata.get(b'user', ctx.user()) |
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
243 date = statedata.get(b'date', ctx.date()) |
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
244 message = ctx.description() |
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
245 if statedata.get(b'log'): |
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
246 message += b'\n(grafted from %s)' % ctx.hex() |
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
247 return (user, date, message, extra) |
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
248 |
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
249 |
52329
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
250 def _graft_revisions( |
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
251 ui, |
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
252 repo, |
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
253 graftstate, |
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
254 statedata, |
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
255 revs, |
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
256 editor, |
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
257 cont=False, |
52332
8d7029218a61
graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52331
diff
changeset
|
258 dry_run=False, |
52333
da216ed31c3d
graft: explicitly pass the "tool" argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52332
diff
changeset
|
259 tool=b'', |
52329
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
260 ): |
5ab77b93567c
graft: split the argument processing from the grafting
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52328
diff
changeset
|
261 """actually graft some revisions""" |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
262 for pos, ctx in enumerate(repo.set(b"%ld", revs)): |
52503
cef86c1d5dfd
graft: extract creation of progress report line in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52351
diff
changeset
|
263 ui.status(_build_progress(ui, repo, ctx)) |
52332
8d7029218a61
graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52331
diff
changeset
|
264 if dry_run: |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
265 continue |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
266 |
52504
de16800904f9
graft: extract meta information computation in a function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52503
diff
changeset
|
267 (user, date, message, extra) = _build_meta(ui, repo, ctx, statedata) |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
268 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
269 # 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
|
270 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
|
271 # perform the graft merge with p1(rev) as 'ancestor' |
52333
da216ed31c3d
graft: explicitly pass the "tool" argument
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52332
diff
changeset
|
272 overrides = {(b'ui', b'forcemerge'): tool} |
52332
8d7029218a61
graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52331
diff
changeset
|
273 if b'base' in statedata: |
8d7029218a61
graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52331
diff
changeset
|
274 base = repo[statedata[b'base']] |
8d7029218a61
graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52331
diff
changeset
|
275 else: |
8d7029218a61
graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52331
diff
changeset
|
276 base = ctx.p1() |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
277 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
|
278 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
|
279 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
|
280 ) |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
281 # 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
|
282 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
|
283 # 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
|
284 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
|
285 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
|
286 stateversion = 1 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
287 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
|
288 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
|
289 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
|
290 return 1 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
291 else: |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
292 cont = False |
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 # commit if --no-commit is false |
52331
11fb7f737456
graft: move no_commit into "statedata" too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52330
diff
changeset
|
295 if not statedata.get(b'no_commit'): |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
296 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
|
297 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
|
298 ) |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
299 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
|
300 ui.warn( |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
301 _(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
|
302 % (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
|
303 ) |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
304 # 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
310 # remove state when we complete successfully |
52332
8d7029218a61
graft: move "dry_run" and "base" in statedate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52331
diff
changeset
|
311 if not dry_run: |
52328
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
312 graftstate.delete() |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
313 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
314 return 0 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
315 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
316 |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
317 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
|
318 """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
|
319 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
|
320 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
|
321 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
|
322 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
|
323 graftstate.delete() |
f2fc0a91faca
commands: create a "mercurial.cmd_impls" module to host graft
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
diff
changeset
|
324 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
|
325 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
|
326 return 0 |