Mercurial > hg
annotate mercurial/cmdutil.py @ 51703:ca7bde5dbafb
black: format the codebase with 23.3.0
The CI has moved to 23.3.0, which is the last version that supports 3.7
at runtime, so we should honor this change.
# skip-blame mass-reformating only
author | Raphaël Gomès <rgomes@octobus.net> |
---|---|
date | Thu, 18 Jul 2024 12:36:12 +0200 |
parents | 7f0cb9ee0534 |
children | 7601978f9e9f |
rev | line source |
---|---|
2957 | 1 # cmdutil.py - help for command processing in mercurial |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
2 # |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents:
46794
diff
changeset
|
3 # Copyright 2005-2007 Olivia Mackall <olivia@selenic.com> |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
4 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8210
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
7 |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
8 |
41977
4ea21df312ec
record: prevent commits that don't pick up dirty subrepo changes (issue6102)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41206
diff
changeset
|
9 import copy as copymod |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
10 import errno |
50203
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
11 import functools |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
12 import os |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
13 import re |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
14 |
50093
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
15 from typing import ( |
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
16 Any, |
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
17 AnyStr, |
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
18 Dict, |
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
19 Iterable, |
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
20 Optional, |
51285
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51163
diff
changeset
|
21 TYPE_CHECKING, |
50093
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
22 cast, |
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
23 ) |
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
24 |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
25 from .i18n import _ |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
26 from .node import ( |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
27 hex, |
46842
ad878e3f282b
refactor: prefer lookup by revision, even for null
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
28 nullrev, |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
29 short, |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
30 ) |
43087
66f2cc210a29
py3: manually import pycompat.setattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43085
diff
changeset
|
31 from .pycompat import ( |
66f2cc210a29
py3: manually import pycompat.setattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43085
diff
changeset
|
32 open, |
66f2cc210a29
py3: manually import pycompat.setattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43085
diff
changeset
|
33 ) |
43841
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
34 from .thirdparty import attr |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
35 |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
36 from . import ( |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
37 bookmarks, |
51555
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
38 bundle2, |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
39 changelog, |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
40 copies, |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
41 crecord as crecordmod, |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
42 encoding, |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
43 error, |
51555
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
44 exchange, |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
45 formatter, |
35885
7625b4f7db70
cmdutil: split functions of log-like commands to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35874
diff
changeset
|
46 logcmdutil, |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
47 match as matchmod, |
36010
46a54de96a54
merge: cut import cycle at merge -> extensions
Yuya Nishihara <yuya@tcha.org>
parents:
36009
diff
changeset
|
48 merge as mergemod, |
44856
b7808443ed6a
mergestate: split out merge state handling code from main merge module
Augie Fackler <augie@google.com>
parents:
44807
diff
changeset
|
49 mergestate as mergestatemod, |
36844
eeb87b24aea7
amend: abort if unresolved merge conflicts found (issue5805)
Yuya Nishihara <yuya@tcha.org>
parents:
35746
diff
changeset
|
50 mergeutil, |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
51 obsolete, |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
52 patch, |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
53 pathutil, |
38423
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38373
diff
changeset
|
54 phases, |
30519
20a42325fdef
py3: use pycompat.getcwd() instead of os.getcwd()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30506
diff
changeset
|
55 pycompat, |
42568
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
56 repair, |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
57 revlog, |
35745
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
58 rewriteutil, |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
59 scmutil, |
42529
5f2f6912c9e6
states: moved cmdutil.unfinishedstates to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents:
42478
diff
changeset
|
60 state as statemod, |
51555
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
61 streamclone, |
36009
55e8efa2451a
subrepo: split non-core functions to new module
Yuya Nishihara <yuya@tcha.org>
parents:
35954
diff
changeset
|
62 subrepoutil, |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
63 templatekw, |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
64 templater, |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
65 util, |
31237
1b08aca7870a
vfs: use 'vfs' module directly in 'mercurial.cmdutil'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31216
diff
changeset
|
66 vfs as vfsmod, |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
67 ) |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36988
diff
changeset
|
68 |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36988
diff
changeset
|
69 from .utils import ( |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36988
diff
changeset
|
70 dateutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36988
diff
changeset
|
71 stringutil, |
51555
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
72 urlutil, |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36988
diff
changeset
|
73 ) |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36988
diff
changeset
|
74 |
47072
4c041c71ec01
revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47021
diff
changeset
|
75 from .revlogutils import ( |
4c041c71ec01
revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47021
diff
changeset
|
76 constants as revlog_constants, |
4c041c71ec01
revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47021
diff
changeset
|
77 ) |
4c041c71ec01
revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47021
diff
changeset
|
78 |
51285
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51163
diff
changeset
|
79 if TYPE_CHECKING: |
50093
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
80 from . import ( |
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
81 ui as uimod, |
43700
a58d2361b231
cmdutil: add a pytype annotation to help out some callsites
Augie Fackler <augie@google.com>
parents:
43698
diff
changeset
|
82 ) |
a58d2361b231
cmdutil: add a pytype annotation to help out some callsites
Augie Fackler <augie@google.com>
parents:
43698
diff
changeset
|
83 |
28861
86db5cb55d46
pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents:
28837
diff
changeset
|
84 stringio = util.stringio |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
85 |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
86 # templates of common command options |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
87 |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
88 dryrunopts = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
89 (b'n', b'dry-run', None, _(b'do not perform actions, just print output')), |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
90 ] |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
91 |
38667
572dff5c946e
rebase: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
38648
diff
changeset
|
92 confirmopts = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
93 (b'', b'confirm', None, _(b'ask before applying actions')), |
38667
572dff5c946e
rebase: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
38648
diff
changeset
|
94 ] |
572dff5c946e
rebase: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
38648
diff
changeset
|
95 |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
96 remoteopts = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
97 (b'e', b'ssh', b'', _(b'specify ssh command to use'), _(b'CMD')), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
98 ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
99 b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
100 b'remotecmd', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
101 b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
102 _(b'specify hg command to run on the remote side'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
103 _(b'CMD'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
104 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
105 ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
106 b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
107 b'insecure', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
108 None, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
109 _(b'do not verify server certificate (ignoring web.cacerts config)'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
110 ), |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
111 ] |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
112 |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
113 walkopts = [ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
114 ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
115 b'I', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
116 b'include', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
117 [], |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
118 _(b'include names matching the given patterns'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
119 _(b'PATTERN'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
120 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
121 ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
122 b'X', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
123 b'exclude', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
124 [], |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
125 _(b'exclude names matching the given patterns'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
126 _(b'PATTERN'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
127 ), |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
128 ] |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
129 |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
130 commitopts = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
131 (b'm', b'message', b'', _(b'use text as commit message'), _(b'TEXT')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
132 (b'l', b'logfile', b'', _(b'read commit message from file'), _(b'FILE')), |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
133 ] |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
134 |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
135 commitopts2 = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
136 ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
137 b'd', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
138 b'date', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
139 b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
140 _(b'record the specified date as commit date'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
141 _(b'DATE'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
142 ), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
143 ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
144 b'u', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
145 b'user', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
146 b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
147 _(b'record the specified user as committer'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
148 _(b'USER'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
149 ), |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
150 ] |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
151 |
42903
66048f6b5d0d
uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42892
diff
changeset
|
152 commitopts3 = [ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
153 (b'D', b'currentdate', None, _(b'record the current date as commit date')), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
154 (b'U', b'currentuser', None, _(b'record the current user as committer')), |
42903
66048f6b5d0d
uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42892
diff
changeset
|
155 ] |
66048f6b5d0d
uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42892
diff
changeset
|
156 |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
157 formatteropts = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
158 (b'T', b'template', b'', _(b'display with template'), _(b'TEMPLATE')), |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
159 ] |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
160 |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
161 templateopts = [ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
162 ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
163 b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
164 b'style', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
165 b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
166 _(b'display using template map file (DEPRECATED)'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
167 _(b'STYLE'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
168 ), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
169 (b'T', b'template', b'', _(b'display with template'), _(b'TEMPLATE')), |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
170 ] |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
171 |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
172 logopts = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
173 (b'p', b'patch', None, _(b'show patch')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
174 (b'g', b'git', None, _(b'use git extended diff format')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
175 (b'l', b'limit', b'', _(b'limit number of changes displayed'), _(b'NUM')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
176 (b'M', b'no-merges', None, _(b'do not show merges')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
177 (b'', b'stat', None, _(b'output diffstat-style summary of changes')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
178 (b'G', b'graph', None, _(b"show the revision DAG")), |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
179 ] + templateopts |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
180 |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
181 diffopts = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
182 (b'a', b'text', None, _(b'treat all files as text')), |
44306
a0ec05d93c8e
cleanup: re-run black on the codebase
Augie Fackler <augie@google.com>
parents:
44296
diff
changeset
|
183 ( |
a0ec05d93c8e
cleanup: re-run black on the codebase
Augie Fackler <augie@google.com>
parents:
44296
diff
changeset
|
184 b'g', |
a0ec05d93c8e
cleanup: re-run black on the codebase
Augie Fackler <augie@google.com>
parents:
44296
diff
changeset
|
185 b'git', |
a0ec05d93c8e
cleanup: re-run black on the codebase
Augie Fackler <augie@google.com>
parents:
44296
diff
changeset
|
186 None, |
a0ec05d93c8e
cleanup: re-run black on the codebase
Augie Fackler <augie@google.com>
parents:
44296
diff
changeset
|
187 _(b'use git extended diff format (DEFAULT: diff.git)'), |
a0ec05d93c8e
cleanup: re-run black on the codebase
Augie Fackler <augie@google.com>
parents:
44296
diff
changeset
|
188 ), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
189 (b'', b'binary', None, _(b'generate binary diffs in git mode (default)')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
190 (b'', b'nodates', None, _(b'omit dates from diff headers')), |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
191 ] |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
192 |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
193 diffwsopts = [ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
194 ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
195 b'w', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
196 b'ignore-all-space', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
197 None, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
198 _(b'ignore white space when comparing lines'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
199 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
200 ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
201 b'b', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
202 b'ignore-space-change', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
203 None, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
204 _(b'ignore changes in the amount of white space'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
205 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
206 ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
207 b'B', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
208 b'ignore-blank-lines', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
209 None, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
210 _(b'ignore changes whose lines are all blank'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
211 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
212 ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
213 b'Z', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
214 b'ignore-space-at-eol', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
215 None, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
216 _(b'ignore changes in whitespace at EOL'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
217 ), |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
218 ] |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
219 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
220 diffopts2 = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
221 [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
222 (b'', b'noprefix', None, _(b'omit a/ and b/ prefixes from filenames')), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
223 ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
224 b'p', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
225 b'show-function', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
226 None, |
44306
a0ec05d93c8e
cleanup: re-run black on the codebase
Augie Fackler <augie@google.com>
parents:
44296
diff
changeset
|
227 _( |
a0ec05d93c8e
cleanup: re-run black on the codebase
Augie Fackler <augie@google.com>
parents:
44296
diff
changeset
|
228 b'show which function each change is in (DEFAULT: diff.showfunc)' |
a0ec05d93c8e
cleanup: re-run black on the codebase
Augie Fackler <augie@google.com>
parents:
44296
diff
changeset
|
229 ), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
230 ), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
231 (b'', b'reverse', None, _(b'produce a diff that undoes the changes')), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
232 ] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
233 + diffwsopts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
234 + [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
235 ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
236 b'U', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
237 b'unified', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
238 b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
239 _(b'number of lines of context to show'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
240 _(b'NUM'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
241 ), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
242 (b'', b'stat', None, _(b'output diffstat-style summary of changes')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
243 ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
244 b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
245 b'root', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
246 b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
247 _(b'produce diffs relative to subdirectory'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
248 _(b'DIR'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
249 ), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
250 ] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
251 ) |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
252 |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
253 mergetoolopts = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
254 (b't', b'tool', b'', _(b'specify merge tool'), _(b'TOOL')), |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
255 ] |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
256 |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
257 similarityopts = [ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
258 ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
259 b's', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
260 b'similarity', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
261 b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
262 _(b'guess renamed files by similarity (0<=s<=100)'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
263 _(b'SIMILARITY'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
264 ) |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
265 ] |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
266 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
267 subrepoopts = [(b'S', b'subrepos', None, _(b'recurse into subrepositories'))] |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
268 |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
269 debugrevlogopts = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
270 (b'c', b'changelog', False, _(b'open changelog')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
271 (b'm', b'manifest', False, _(b'open manifest')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
272 (b'', b'dir', b'', _(b'open directory manifest')), |
32375
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
273 ] |
04baab18d60a
commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32362
diff
changeset
|
274 |
30703
5c85c93cdd61
cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents:
30695
diff
changeset
|
275 # special string such that everything below this line will be ingored in the |
5c85c93cdd61
cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents:
30695
diff
changeset
|
276 # editor text |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
277 _linebelow = b"^HG: ------------------------ >8 ------------------------$" |
30703
5c85c93cdd61
cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents:
30695
diff
changeset
|
278 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
279 |
50093
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
280 def check_at_most_one_arg( |
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
281 opts: Dict[AnyStr, Any], |
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
282 *args: AnyStr, |
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
283 ) -> Optional[AnyStr]: |
43899
fff21278554b
rebase: use cmdutil.check_at_most_one_arg() for action
Martin von Zweigbergk <martinvonz@google.com>
parents:
43898
diff
changeset
|
284 """abort if more than one of the arguments are in opts |
fff21278554b
rebase: use cmdutil.check_at_most_one_arg() for action
Martin von Zweigbergk <martinvonz@google.com>
parents:
43898
diff
changeset
|
285 |
fff21278554b
rebase: use cmdutil.check_at_most_one_arg() for action
Martin von Zweigbergk <martinvonz@google.com>
parents:
43898
diff
changeset
|
286 Returns the unique argument or None if none of them were specified. |
fff21278554b
rebase: use cmdutil.check_at_most_one_arg() for action
Martin von Zweigbergk <martinvonz@google.com>
parents:
43898
diff
changeset
|
287 """ |
43941
dfac25883dbf
cmdutil: return underscore-separate name from check_at_most_one_arg()
Martin von Zweigbergk <martinvonz@google.com>
parents:
43939
diff
changeset
|
288 |
50093
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
289 def to_display(name: AnyStr) -> bytes: |
43942
6c8108274dc5
cmdutil: allow native string as input to check_at_most_one_arg()
Martin von Zweigbergk <martinvonz@google.com>
parents:
43941
diff
changeset
|
290 return pycompat.sysbytes(name).replace(b'_', b'-') |
43941
dfac25883dbf
cmdutil: return underscore-separate name from check_at_most_one_arg()
Martin von Zweigbergk <martinvonz@google.com>
parents:
43939
diff
changeset
|
291 |
43892
d587937600be
clone: extract helper for checking mutually exclusive args
Martin von Zweigbergk <martinvonz@google.com>
parents:
43861
diff
changeset
|
292 previous = None |
d587937600be
clone: extract helper for checking mutually exclusive args
Martin von Zweigbergk <martinvonz@google.com>
parents:
43861
diff
changeset
|
293 for x in args: |
d587937600be
clone: extract helper for checking mutually exclusive args
Martin von Zweigbergk <martinvonz@google.com>
parents:
43861
diff
changeset
|
294 if opts.get(x): |
d587937600be
clone: extract helper for checking mutually exclusive args
Martin von Zweigbergk <martinvonz@google.com>
parents:
43861
diff
changeset
|
295 if previous: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
296 raise error.InputError( |
43941
dfac25883dbf
cmdutil: return underscore-separate name from check_at_most_one_arg()
Martin von Zweigbergk <martinvonz@google.com>
parents:
43939
diff
changeset
|
297 _(b'cannot specify both --%s and --%s') |
dfac25883dbf
cmdutil: return underscore-separate name from check_at_most_one_arg()
Martin von Zweigbergk <martinvonz@google.com>
parents:
43939
diff
changeset
|
298 % (to_display(previous), to_display(x)) |
43892
d587937600be
clone: extract helper for checking mutually exclusive args
Martin von Zweigbergk <martinvonz@google.com>
parents:
43861
diff
changeset
|
299 ) |
d587937600be
clone: extract helper for checking mutually exclusive args
Martin von Zweigbergk <martinvonz@google.com>
parents:
43861
diff
changeset
|
300 previous = x |
43899
fff21278554b
rebase: use cmdutil.check_at_most_one_arg() for action
Martin von Zweigbergk <martinvonz@google.com>
parents:
43898
diff
changeset
|
301 return previous |
43892
d587937600be
clone: extract helper for checking mutually exclusive args
Martin von Zweigbergk <martinvonz@google.com>
parents:
43861
diff
changeset
|
302 |
d587937600be
clone: extract helper for checking mutually exclusive args
Martin von Zweigbergk <martinvonz@google.com>
parents:
43861
diff
changeset
|
303 |
50093
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
304 def check_incompatible_arguments( |
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
305 opts: Dict[AnyStr, Any], |
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
306 first: AnyStr, |
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
307 others: Iterable[AnyStr], |
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
308 ) -> None: |
43898
023ad45e2fd2
releasenotes: extract helper for checking for incompatible arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
43894
diff
changeset
|
309 """abort if the first argument is given along with any of the others |
023ad45e2fd2
releasenotes: extract helper for checking for incompatible arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
43894
diff
changeset
|
310 |
023ad45e2fd2
releasenotes: extract helper for checking for incompatible arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
43894
diff
changeset
|
311 Unlike check_at_most_one_arg(), `others` are not mutually exclusive |
44194
d4c1501225c4
cmdutil: change check_incompatible_arguments() *arg to single iterable
Martin von Zweigbergk <martinvonz@google.com>
parents:
44098
diff
changeset
|
312 among themselves, and they're passed as a single collection. |
43898
023ad45e2fd2
releasenotes: extract helper for checking for incompatible arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
43894
diff
changeset
|
313 """ |
023ad45e2fd2
releasenotes: extract helper for checking for incompatible arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
43894
diff
changeset
|
314 for other in others: |
023ad45e2fd2
releasenotes: extract helper for checking for incompatible arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
43894
diff
changeset
|
315 check_at_most_one_arg(opts, first, other) |
023ad45e2fd2
releasenotes: extract helper for checking for incompatible arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
43894
diff
changeset
|
316 |
023ad45e2fd2
releasenotes: extract helper for checking for incompatible arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
43894
diff
changeset
|
317 |
50093
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
318 def resolve_commit_options(ui: "uimod.ui", opts: Dict[str, Any]) -> bool: |
42903
66048f6b5d0d
uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42892
diff
changeset
|
319 """modify commit options dict to handle related options |
42932
e4803231f538
amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents:
42921
diff
changeset
|
320 |
e4803231f538
amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents:
42921
diff
changeset
|
321 The return value indicates that ``rewrite.update-timestamp`` is the reason |
e4803231f538
amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents:
42921
diff
changeset
|
322 the ``date`` option is set. |
42903
66048f6b5d0d
uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42892
diff
changeset
|
323 """ |
47432
7f7457f84311
cmdutil: make resolvecommitoptions() work on str-keyed opts
Martin von Zweigbergk <martinvonz@google.com>
parents:
47431
diff
changeset
|
324 check_at_most_one_arg(opts, 'date', 'currentdate') |
7f7457f84311
cmdutil: make resolvecommitoptions() work on str-keyed opts
Martin von Zweigbergk <martinvonz@google.com>
parents:
47431
diff
changeset
|
325 check_at_most_one_arg(opts, 'user', 'currentuser') |
42921
4690902850df
uncommit: make -D/--date and -U/--user mutually exclusive
Matt Harbison <matt_harbison@yahoo.com>
parents:
42920
diff
changeset
|
326 |
42932
e4803231f538
amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents:
42921
diff
changeset
|
327 datemaydiffer = False # date-only change should be ignored? |
e4803231f538
amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents:
42921
diff
changeset
|
328 |
47432
7f7457f84311
cmdutil: make resolvecommitoptions() work on str-keyed opts
Martin von Zweigbergk <martinvonz@google.com>
parents:
47431
diff
changeset
|
329 if opts.get('currentdate'): |
7f7457f84311
cmdutil: make resolvecommitoptions() work on str-keyed opts
Martin von Zweigbergk <martinvonz@google.com>
parents:
47431
diff
changeset
|
330 opts['date'] = b'%d %d' % dateutil.makedate() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
331 elif ( |
47432
7f7457f84311
cmdutil: make resolvecommitoptions() work on str-keyed opts
Martin von Zweigbergk <martinvonz@google.com>
parents:
47431
diff
changeset
|
332 not opts.get('date') |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
333 and ui.configbool(b'rewrite', b'update-timestamp') |
47432
7f7457f84311
cmdutil: make resolvecommitoptions() work on str-keyed opts
Martin von Zweigbergk <martinvonz@google.com>
parents:
47431
diff
changeset
|
334 and opts.get('currentdate') is None |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
335 ): |
47432
7f7457f84311
cmdutil: make resolvecommitoptions() work on str-keyed opts
Martin von Zweigbergk <martinvonz@google.com>
parents:
47431
diff
changeset
|
336 opts['date'] = b'%d %d' % dateutil.makedate() |
42932
e4803231f538
amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents:
42921
diff
changeset
|
337 datemaydiffer = True |
e4803231f538
amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents:
42921
diff
changeset
|
338 |
47432
7f7457f84311
cmdutil: make resolvecommitoptions() work on str-keyed opts
Martin von Zweigbergk <martinvonz@google.com>
parents:
47431
diff
changeset
|
339 if opts.get('currentuser'): |
7f7457f84311
cmdutil: make resolvecommitoptions() work on str-keyed opts
Martin von Zweigbergk <martinvonz@google.com>
parents:
47431
diff
changeset
|
340 opts['user'] = ui.username() |
42903
66048f6b5d0d
uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42892
diff
changeset
|
341 |
42932
e4803231f538
amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents:
42921
diff
changeset
|
342 return datemaydiffer |
e4803231f538
amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents:
42921
diff
changeset
|
343 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
344 |
50093
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
345 def check_note_size(opts: Dict[str, Any]) -> None: |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
46969
diff
changeset
|
346 """make sure note is of valid format""" |
42933
7e9997041781
amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents:
42932
diff
changeset
|
347 |
47428
54849b65dc5f
cmdutil: make checknotesize() work on str-keyed opts
Martin von Zweigbergk <martinvonz@google.com>
parents:
47150
diff
changeset
|
348 note = opts.get('note') |
42933
7e9997041781
amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents:
42932
diff
changeset
|
349 if not note: |
7e9997041781
amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents:
42932
diff
changeset
|
350 return |
7e9997041781
amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents:
42932
diff
changeset
|
351 |
7e9997041781
amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents:
42932
diff
changeset
|
352 if len(note) > 255: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
353 raise error.InputError(_(b"cannot store a note of more than 255 bytes")) |
42933
7e9997041781
amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents:
42932
diff
changeset
|
354 if b'\n' in note: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
355 raise error.InputError(_(b"note cannot contain a newline")) |
42933
7e9997041781
amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents:
42932
diff
changeset
|
356 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
357 |
25256
5a8398b085ed
record: extract ishunk to a function
Laurent Charignon <lcharignon@fb.com>
parents:
25228
diff
changeset
|
358 def ishunk(x): |
5a8398b085ed
record: extract ishunk to a function
Laurent Charignon <lcharignon@fb.com>
parents:
25228
diff
changeset
|
359 hunkclasses = (crecordmod.uihunk, patch.recordhunk) |
5a8398b085ed
record: extract ishunk to a function
Laurent Charignon <lcharignon@fb.com>
parents:
25228
diff
changeset
|
360 return isinstance(x, hunkclasses) |
5a8398b085ed
record: extract ishunk to a function
Laurent Charignon <lcharignon@fb.com>
parents:
25228
diff
changeset
|
361 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
362 |
47565
00ae1fb6c459
cmdutil: fix newandmodified file accounting for --interactive commits
Daniel Ploch <dploch@google.com>
parents:
47432
diff
changeset
|
363 def isheader(x): |
00ae1fb6c459
cmdutil: fix newandmodified file accounting for --interactive commits
Daniel Ploch <dploch@google.com>
parents:
47432
diff
changeset
|
364 headerclasses = (crecordmod.uiheader, patch.header) |
00ae1fb6c459
cmdutil: fix newandmodified file accounting for --interactive commits
Daniel Ploch <dploch@google.com>
parents:
47432
diff
changeset
|
365 return isinstance(x, headerclasses) |
00ae1fb6c459
cmdutil: fix newandmodified file accounting for --interactive commits
Daniel Ploch <dploch@google.com>
parents:
47432
diff
changeset
|
366 |
00ae1fb6c459
cmdutil: fix newandmodified file accounting for --interactive commits
Daniel Ploch <dploch@google.com>
parents:
47432
diff
changeset
|
367 |
00ae1fb6c459
cmdutil: fix newandmodified file accounting for --interactive commits
Daniel Ploch <dploch@google.com>
parents:
47432
diff
changeset
|
368 def newandmodified(chunks): |
25257
07326d76f19d
record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents:
25256
diff
changeset
|
369 newlyaddedandmodifiedfiles = set() |
42856
3cf091843b4f
split: handle partial commit of renames when doing split or record (issue5723)
Kyle Lippincott <spectral@google.com>
parents:
42643
diff
changeset
|
370 alsorestore = set() |
25257
07326d76f19d
record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents:
25256
diff
changeset
|
371 for chunk in chunks: |
47565
00ae1fb6c459
cmdutil: fix newandmodified file accounting for --interactive commits
Daniel Ploch <dploch@google.com>
parents:
47432
diff
changeset
|
372 if isheader(chunk) and chunk.isnewfile(): |
00ae1fb6c459
cmdutil: fix newandmodified file accounting for --interactive commits
Daniel Ploch <dploch@google.com>
parents:
47432
diff
changeset
|
373 newlyaddedandmodifiedfiles.add(chunk.filename()) |
00ae1fb6c459
cmdutil: fix newandmodified file accounting for --interactive commits
Daniel Ploch <dploch@google.com>
parents:
47432
diff
changeset
|
374 alsorestore.update(set(chunk.files()) - {chunk.filename()}) |
42856
3cf091843b4f
split: handle partial commit of renames when doing split or record (issue5723)
Kyle Lippincott <spectral@google.com>
parents:
42643
diff
changeset
|
375 return newlyaddedandmodifiedfiles, alsorestore |
25257
07326d76f19d
record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents:
25256
diff
changeset
|
376 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
377 |
10401
6252852b4332
mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents:
10344
diff
changeset
|
378 def parsealiases(cmd): |
46241
012e25abc603
command: automatically create alias for command using '-' in names
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45942
diff
changeset
|
379 base_aliases = cmd.split(b"|") |
012e25abc603
command: automatically create alias for command using '-' in names
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45942
diff
changeset
|
380 all_aliases = set(base_aliases) |
012e25abc603
command: automatically create alias for command using '-' in names
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45942
diff
changeset
|
381 extra_aliases = [] |
012e25abc603
command: automatically create alias for command using '-' in names
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45942
diff
changeset
|
382 for alias in base_aliases: |
012e25abc603
command: automatically create alias for command using '-' in names
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45942
diff
changeset
|
383 if b'-' in alias: |
012e25abc603
command: automatically create alias for command using '-' in names
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45942
diff
changeset
|
384 folded_alias = alias.replace(b'-', b'') |
012e25abc603
command: automatically create alias for command using '-' in names
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45942
diff
changeset
|
385 if folded_alias not in all_aliases: |
012e25abc603
command: automatically create alias for command using '-' in names
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45942
diff
changeset
|
386 all_aliases.add(folded_alias) |
012e25abc603
command: automatically create alias for command using '-' in names
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45942
diff
changeset
|
387 extra_aliases.append(folded_alias) |
012e25abc603
command: automatically create alias for command using '-' in names
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45942
diff
changeset
|
388 base_aliases.extend(extra_aliases) |
012e25abc603
command: automatically create alias for command using '-' in names
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45942
diff
changeset
|
389 return base_aliases |
10401
6252852b4332
mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents:
10344
diff
changeset
|
390 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
391 |
24356
a38f384f2a57
record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents:
24345
diff
changeset
|
392 def setupwrapcolorwrite(ui): |
a38f384f2a57
record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents:
24345
diff
changeset
|
393 # wrap ui.write so diff output can be labeled/colorized |
a38f384f2a57
record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents:
24345
diff
changeset
|
394 def wrapwrite(orig, *args, **kw): |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43491
diff
changeset
|
395 label = kw.pop('label', b'') |
24356
a38f384f2a57
record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents:
24345
diff
changeset
|
396 for chunk, l in patch.difflabel(lambda: args): |
a38f384f2a57
record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents:
24345
diff
changeset
|
397 orig(chunk, label=label + l) |
a38f384f2a57
record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents:
24345
diff
changeset
|
398 |
a38f384f2a57
record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents:
24345
diff
changeset
|
399 oldwrite = ui.write |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
400 |
24356
a38f384f2a57
record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents:
24345
diff
changeset
|
401 def wrap(*args, **kwargs): |
a38f384f2a57
record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents:
24345
diff
changeset
|
402 return wrapwrite(oldwrite, *args, **kwargs) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
403 |
24356
a38f384f2a57
record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents:
24345
diff
changeset
|
404 setattr(ui, 'write', wrap) |
a38f384f2a57
record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents:
24345
diff
changeset
|
405 return oldwrite |
a38f384f2a57
record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents:
24345
diff
changeset
|
406 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
407 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
408 def filterchunks(ui, originalhunks, usecurses, testfile, match, operation=None): |
38047
dabc2237963c
crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents:
37958
diff
changeset
|
409 try: |
dabc2237963c
crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents:
37958
diff
changeset
|
410 if usecurses: |
dabc2237963c
crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents:
37958
diff
changeset
|
411 if testfile: |
dabc2237963c
crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents:
37958
diff
changeset
|
412 recordfn = crecordmod.testdecorator( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
413 testfile, crecordmod.testchunkselector |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
414 ) |
38047
dabc2237963c
crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents:
37958
diff
changeset
|
415 else: |
dabc2237963c
crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents:
37958
diff
changeset
|
416 recordfn = crecordmod.chunkselector |
dabc2237963c
crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents:
37958
diff
changeset
|
417 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
418 return crecordmod.filterpatch( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
419 ui, originalhunks, recordfn, operation |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
420 ) |
38047
dabc2237963c
crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents:
37958
diff
changeset
|
421 except crecordmod.fallbackerror as e: |
44098
19533e4c3450
py3: fix curses chunkselector fallback (when diffs are too large) on py3
Kyle Lippincott <spectral@google.com>
parents:
44049
diff
changeset
|
422 ui.warn(b'%s\n' % e) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
423 ui.warn(_(b'falling back to text mode\n')) |
38047
dabc2237963c
crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents:
37958
diff
changeset
|
424 |
42071
db72f9f6580e
interactive: do not prompt about files given in command line
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
42057
diff
changeset
|
425 return patch.filterpatch(ui, originalhunks, match, operation) |
db72f9f6580e
interactive: do not prompt about files given in command line
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
42057
diff
changeset
|
426 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
427 |
42071
db72f9f6580e
interactive: do not prompt about files given in command line
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
42057
diff
changeset
|
428 def recordfilter(ui, originalhunks, match, operation=None): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
429 """Prompts the user to filter the originalhunks and return a list of |
25310
c1f5ef76d1c2
record: add an operation arguments to customize recording ui
Laurent Charignon <lcharignon@fb.com>
parents:
25273
diff
changeset
|
430 selected hunks. |
29326
d48fc6f318a3
patch: define full messages for interactive record/revert
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
29283
diff
changeset
|
431 *operation* is used for to build ui messages to indicate the user what |
d48fc6f318a3
patch: define full messages for interactive record/revert
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
29283
diff
changeset
|
432 kind of filtering they are doing: reverting, committing, shelving, etc. |
d48fc6f318a3
patch: define full messages for interactive record/revert
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
29283
diff
changeset
|
433 (see patch.filterpatch). |
25310
c1f5ef76d1c2
record: add an operation arguments to customize recording ui
Laurent Charignon <lcharignon@fb.com>
parents:
25273
diff
changeset
|
434 """ |
27531
84d686cb62c4
cmdutil: use crecordmod.checkcurses
Sean Farley <sean@farley.io>
parents:
27370
diff
changeset
|
435 usecurses = crecordmod.checkcurses(ui) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
436 testfile = ui.config(b'experimental', b'crecordtest') |
24358
8d9e9063b040
record: move ui.write wrapping where it should be
Laurent Charignon <lcharignon@fb.com>
parents:
24357
diff
changeset
|
437 oldwrite = setupwrapcolorwrite(ui) |
8d9e9063b040
record: move ui.write wrapping where it should be
Laurent Charignon <lcharignon@fb.com>
parents:
24357
diff
changeset
|
438 try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
439 newchunks, newopts = filterchunks( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
440 ui, originalhunks, usecurses, testfile, match, operation |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
441 ) |
24358
8d9e9063b040
record: move ui.write wrapping where it should be
Laurent Charignon <lcharignon@fb.com>
parents:
24357
diff
changeset
|
442 finally: |
8d9e9063b040
record: move ui.write wrapping where it should be
Laurent Charignon <lcharignon@fb.com>
parents:
24357
diff
changeset
|
443 ui.write = oldwrite |
27155
8d3c5797a175
commit: add a way to return more information from the chunkselector
Laurent Charignon <lcharignon@fb.com>
parents:
27148
diff
changeset
|
444 return newchunks, newopts |
24357
2da601ab3125
record: refactor the filtering code
Laurent Charignon <lcharignon@fb.com>
parents:
24356
diff
changeset
|
445 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
446 |
50203
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
447 def _record( |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
448 ui, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
449 repo, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
450 message, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
451 match, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
452 opts, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
453 commitfunc, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
454 backupall, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
455 filterfn, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
456 pats, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
457 ): |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
458 """This is generic record driver. |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
459 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
460 Its job is to interactively filter local changes, and |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
461 accordingly prepare working directory into a state in which the |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
462 job can be delegated to a non-interactive commit command such as |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
463 'commit' or 'qrefresh'. |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
464 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
465 After the actual job is done by non-interactive command, the |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
466 working directory is restored to its original state. |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
467 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
468 In the end we'll record interesting changes, and everything else |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
469 will be left in place, so the user can continue working. |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
470 """ |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
471 assert repo.currentwlock() is not None |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
472 if not opts.get(b'interactive-unshelve'): |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
473 checkunfinished(repo, commit=True) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
474 wctx = repo[None] |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
475 merge = len(wctx.parents()) > 1 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
476 if merge: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
477 raise error.InputError( |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
478 _(b'cannot partially commit a merge ' b'(use "hg commit" instead)') |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
479 ) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
480 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
481 def fail(f, msg): |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
482 raise error.InputError(b'%s: %s' % (f, msg)) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
483 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
484 force = opts.get(b'force') |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
485 if not force: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
486 match = matchmod.badmatch(match, fail) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
487 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
488 status = repo.status(match=match) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
489 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
490 overrides = {(b'ui', b'commitsubrepos'): True} |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
491 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
492 with repo.ui.configoverride(overrides, b'record'): |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
493 # subrepoutil.precommit() modifies the status |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
494 tmpstatus = scmutil.status( |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
495 copymod.copy(status.modified), |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
496 copymod.copy(status.added), |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
497 copymod.copy(status.removed), |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
498 copymod.copy(status.deleted), |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
499 copymod.copy(status.unknown), |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
500 copymod.copy(status.ignored), |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
501 copymod.copy(status.clean), # pytype: disable=wrong-arg-count |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
502 ) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
503 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
504 # Force allows -X subrepo to skip the subrepo. |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
505 subs, commitsubs, newstate = subrepoutil.precommit( |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
506 repo.ui, wctx, tmpstatus, match, force=True |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
507 ) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
508 for s in subs: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
509 if s in commitsubs: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
510 dirtyreason = wctx.sub(s).dirtyreason(True) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
511 raise error.Abort(dirtyreason) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
512 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
513 if not force: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
514 repo.checkcommitpatterns(wctx, match, status, fail) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
515 diffopts = patch.difffeatureopts( |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
516 ui, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
517 opts=opts, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
518 whitespace=True, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
519 section=b'commands', |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
520 configprefix=b'commit.interactive.', |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
521 ) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
522 diffopts.nodates = True |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
523 diffopts.git = True |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
524 diffopts.showfunc = True |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
525 originaldiff = patch.diff(repo, changes=status, opts=diffopts) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
526 original_headers = patch.parsepatch(originaldiff) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
527 match = scmutil.match(repo[None], pats) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
528 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
529 # 1. filter patch, since we are intending to apply subset of it |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
530 try: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
531 chunks, newopts = filterfn(ui, original_headers, match) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
532 except error.PatchParseError as err: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
533 raise error.InputError(_(b'error parsing patch: %s') % err) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
534 except error.PatchApplicationError as err: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
535 raise error.StateError(_(b'error applying patch: %s') % err) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
536 opts.update(newopts) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
537 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
538 # We need to keep a backup of files that have been newly added and |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
539 # modified during the recording process because there is a previous |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
540 # version without the edit in the workdir. We also will need to restore |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
541 # files that were the sources of renames so that the patch application |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
542 # works. |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
543 newlyaddedandmodifiedfiles, alsorestore = newandmodified(chunks) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
544 contenders = set() |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
545 for h in chunks: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
546 if isheader(h): |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
547 contenders.update(set(h.files())) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
548 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
549 changed = status.modified + status.added + status.removed |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
550 newfiles = [f for f in changed if f in contenders] |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
551 if not newfiles: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
552 ui.status(_(b'no changes to record\n')) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
553 return 0 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
554 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
555 modified = set(status.modified) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
556 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
557 # 2. backup changed files, so we can restore them in the end |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
558 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
559 if backupall: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
560 tobackup = changed |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
561 else: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
562 tobackup = [ |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
563 f |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
564 for f in newfiles |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
565 if f in modified or f in newlyaddedandmodifiedfiles |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
566 ] |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
567 backups = {} |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
568 if tobackup: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
569 backupdir = repo.vfs.join(b'record-backups') |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
570 try: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
571 os.mkdir(backupdir) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
572 except FileExistsError: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
573 pass |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
574 try: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
575 # backup continues |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
576 for f in tobackup: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
577 fd, tmpname = pycompat.mkstemp( |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
578 prefix=os.path.basename(f) + b'.', dir=backupdir |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
579 ) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
580 os.close(fd) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
581 ui.debug(b'backup %r as %r\n' % (f, tmpname)) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
582 util.copyfile(repo.wjoin(f), tmpname, copystat=True) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
583 backups[f] = tmpname |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
584 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
585 fp = stringio() |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
586 for c in chunks: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
587 fname = c.filename() |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
588 if fname in backups: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
589 c.write(fp) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
590 dopatch = fp.tell() |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
591 fp.seek(0) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
592 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
593 # 2.5 optionally review / modify patch in text editor |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
594 if opts.get(b'review', False): |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
595 patchtext = ( |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
596 crecordmod.diffhelptext + crecordmod.patchhelptext + fp.read() |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
597 ) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
598 reviewedpatch = ui.edit( |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
599 patchtext, b"", action=b"diff", repopath=repo.path |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
600 ) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
601 fp.truncate(0) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
602 fp.write(reviewedpatch) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
603 fp.seek(0) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
604 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
605 [os.unlink(repo.wjoin(c)) for c in newlyaddedandmodifiedfiles] |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
606 # 3a. apply filtered patch to clean repo (clean) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
607 if backups: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
608 m = scmutil.matchfiles(repo, set(backups.keys()) | alsorestore) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
609 mergemod.revert_to(repo[b'.'], matcher=m) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
610 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
611 # 3b. (apply) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
612 if dopatch: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
613 try: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
614 ui.debug(b'applying patch\n') |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
615 ui.debug(fp.getvalue()) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
616 patch.internalpatch(ui, repo, fp, 1, eolmode=None) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
617 except error.PatchParseError as err: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
618 raise error.InputError(pycompat.bytestr(err)) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
619 except error.PatchApplicationError as err: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
620 raise error.StateError(pycompat.bytestr(err)) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
621 del fp |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
622 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
623 # 4. We prepared working directory according to filtered |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
624 # patch. Now is the time to delegate the job to |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
625 # commit/qrefresh or the like! |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
626 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
627 # Make all of the pathnames absolute. |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
628 newfiles = [repo.wjoin(nf) for nf in newfiles] |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
629 return commitfunc(ui, repo, *newfiles, **pycompat.strkwargs(opts)) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
630 finally: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
631 # 5. finally restore backed-up files |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
632 try: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
633 dirstate = repo.dirstate |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
634 for realname, tmpname in backups.items(): |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
635 ui.debug(b'restoring %r to %r\n' % (tmpname, realname)) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
636 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
637 if dirstate.get_entry(realname).maybe_clean: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
638 # without normallookup, restoring timestamp |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
639 # may cause partially committed files |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
640 # to be treated as unmodified |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
641 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
642 # XXX-PENDINGCHANGE: We should clarify the context in |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
643 # which this function is called to make sure it |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
644 # already called within a `pendingchange`, However we |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
645 # are taking a shortcut here in order to be able to |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
646 # quickly deprecated the older API. |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
647 with dirstate.changing_parents(repo): |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
648 dirstate.update_file( |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
649 realname, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
650 p1_tracked=True, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
651 wc_tracked=True, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
652 possibly_dirty=True, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
653 ) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
654 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
655 # copystat=True here and above are a hack to trick any |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
656 # editors that have f open that we haven't modified them. |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
657 # |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
658 # Also note that this racy as an editor could notice the |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
659 # file's mtime before we've finished writing it. |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
660 util.copyfile(tmpname, repo.wjoin(realname), copystat=True) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
661 os.unlink(tmpname) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
662 if tobackup: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
663 os.rmdir(backupdir) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
664 except OSError: |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
665 pass |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
666 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
667 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
668 def dorecord( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
669 ui, repo, commitfunc, cmdsuggest, backupall, filterfn, *pats, **opts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
670 ): |
32144
93155367a2a6
py3: convert opts to bytes in cmdutil.dorecord()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32046
diff
changeset
|
671 opts = pycompat.byteskwargs(opts) |
24272
26a1c617e047
record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents:
24260
diff
changeset
|
672 if not ui.interactive(): |
25795
69145daacdfa
cmdutil: allow callers of cmdutil.dorecord to omit suggestion
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25763
diff
changeset
|
673 if cmdsuggest: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
674 msg = _(b'running non-interactively, use %s instead') % cmdsuggest |
25795
69145daacdfa
cmdutil: allow callers of cmdutil.dorecord to omit suggestion
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25763
diff
changeset
|
675 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
676 msg = _(b'running non-interactively') |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
677 raise error.InputError(msg) |
24272
26a1c617e047
record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents:
24260
diff
changeset
|
678 |
26a1c617e047
record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents:
24260
diff
changeset
|
679 # make sure username is set before going interactive |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
680 if not opts.get(b'user'): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
681 ui.username() # raise exception, username not provided |
24272
26a1c617e047
record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents:
24260
diff
changeset
|
682 |
50203
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
683 func = functools.partial( |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
684 _record, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
685 commitfunc=commitfunc, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
686 backupall=backupall, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
687 filterfn=filterfn, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
688 pats=pats, |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
689 ) |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
690 |
ee7a7155de10
record: extract a closure to the module level
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50202
diff
changeset
|
691 return commit(ui, repo, func, pats, opts) |
24272
26a1c617e047
record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents:
24260
diff
changeset
|
692 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
693 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48913
diff
changeset
|
694 class dirnode: |
33548
4cd4344a53c4
status: add a flag to terse the output (issue4119)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33509
diff
changeset
|
695 """ |
34698
23eb03f46929
tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents:
34684
diff
changeset
|
696 Represent a directory in user working copy with information required for |
23eb03f46929
tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents:
34684
diff
changeset
|
697 the purpose of tersing its status. |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
698 |
38219
51e420a7a41a
cmdutil: use internal separators when building the terse list
Matt Harbison <matt_harbison@yahoo.com>
parents:
38164
diff
changeset
|
699 path is the path to the directory, without a trailing '/' |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
700 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
701 statuses is a set of statuses of all files in this directory (this includes |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
702 all the files in all the subdirectories too) |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
703 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
704 files is a list of files which are direct child of this directory |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
705 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
706 subdirs is a dictionary of sub-directory name as the key and it's own |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
707 dirnode object as the value |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
708 """ |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
709 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
710 def __init__(self, dirpath): |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
711 self.path = dirpath |
42057
566daffc607d
cleanup: use set literals where possible
Martin von Zweigbergk <martinvonz@google.com>
parents:
41994
diff
changeset
|
712 self.statuses = set() |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
713 self.files = [] |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
714 self.subdirs = {} |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
715 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
716 def _addfileindir(self, filename, status): |
34698
23eb03f46929
tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents:
34684
diff
changeset
|
717 """Add a file in this directory as a direct child.""" |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
718 self.files.append((filename, status)) |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
719 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
720 def addfile(self, filename, status): |
33548
4cd4344a53c4
status: add a flag to terse the output (issue4119)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33509
diff
changeset
|
721 """ |
34698
23eb03f46929
tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents:
34684
diff
changeset
|
722 Add a file to this directory or to its direct parent directory. |
23eb03f46929
tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents:
34684
diff
changeset
|
723 |
23eb03f46929
tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents:
34684
diff
changeset
|
724 If the file is not direct child of this directory, we traverse to the |
23eb03f46929
tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents:
34684
diff
changeset
|
725 directory of which this file is a direct child of and add the file |
23eb03f46929
tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents:
34684
diff
changeset
|
726 there. |
33548
4cd4344a53c4
status: add a flag to terse the output (issue4119)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33509
diff
changeset
|
727 """ |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
728 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
729 # the filename contains a path separator, it means it's not the direct |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
730 # child of this directory |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
731 if b'/' in filename: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
732 subdir, filep = filename.split(b'/', 1) |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
733 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
734 # does the dirnode object for subdir exists |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
735 if subdir not in self.subdirs: |
38219
51e420a7a41a
cmdutil: use internal separators when building the terse list
Matt Harbison <matt_harbison@yahoo.com>
parents:
38164
diff
changeset
|
736 subdirpath = pathutil.join(self.path, subdir) |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
737 self.subdirs[subdir] = dirnode(subdirpath) |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
738 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
739 # try adding the file in subdir |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
740 self.subdirs[subdir].addfile(filep, status) |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
741 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
742 else: |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
743 self._addfileindir(filename, status) |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
744 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
745 if status not in self.statuses: |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
746 self.statuses.add(status) |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
747 |
34684
5d98674df18a
tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents:
34683
diff
changeset
|
748 def iterfilepaths(self): |
34698
23eb03f46929
tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents:
34684
diff
changeset
|
749 """Yield (status, path) for files directly under this directory.""" |
34683
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
750 for f, st in self.files: |
38219
51e420a7a41a
cmdutil: use internal separators when building the terse list
Matt Harbison <matt_harbison@yahoo.com>
parents:
38164
diff
changeset
|
751 yield st, pathutil.join(self.path, f) |
34684
5d98674df18a
tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents:
34683
diff
changeset
|
752 |
5d98674df18a
tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents:
34683
diff
changeset
|
753 def tersewalk(self, terseargs): |
34683
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
754 """ |
34698
23eb03f46929
tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents:
34684
diff
changeset
|
755 Yield (status, path) obtained by processing the status of this |
23eb03f46929
tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents:
34684
diff
changeset
|
756 dirnode. |
34683
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
757 |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
758 terseargs is the string of arguments passed by the user with `--terse` |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
759 flag. |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
760 |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
761 Following are the cases which can happen: |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
762 |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
763 1) All the files in the directory (including all the files in its |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
764 subdirectories) share the same status and the user has asked us to terse |
38219
51e420a7a41a
cmdutil: use internal separators when building the terse list
Matt Harbison <matt_harbison@yahoo.com>
parents:
38164
diff
changeset
|
765 that status. -> yield (status, dirpath). dirpath will end in '/'. |
34683
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
766 |
34698
23eb03f46929
tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents:
34684
diff
changeset
|
767 2) Otherwise, we do following: |
34683
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
768 |
34684
5d98674df18a
tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents:
34683
diff
changeset
|
769 a) Yield (status, filepath) for all the files which are in this |
5d98674df18a
tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents:
34683
diff
changeset
|
770 directory (only the ones in this directory, not the subdirs) |
34683
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
771 |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
772 b) Recurse the function on all the subdirectories of this |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
773 directory |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
774 """ |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
775 |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
776 if len(self.statuses) == 1: |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
777 onlyst = self.statuses.pop() |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
778 |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
779 # Making sure we terse only when the status abbreviation is |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
780 # passed as terse argument |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
781 if onlyst in terseargs: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
782 yield onlyst, self.path + b'/' |
34683
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
783 return |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
784 |
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
785 # add the files to status list |
34684
5d98674df18a
tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents:
34683
diff
changeset
|
786 for st, fpath in self.iterfilepaths(): |
5d98674df18a
tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents:
34683
diff
changeset
|
787 yield st, fpath |
34683
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
788 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
789 # recurse on the subdirs |
34683
3d6d4b12128e
tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents:
34682
diff
changeset
|
790 for dirobj in self.subdirs.values(): |
34684
5d98674df18a
tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents:
34683
diff
changeset
|
791 for st, fpath in dirobj.tersewalk(terseargs): |
5d98674df18a
tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents:
34683
diff
changeset
|
792 yield st, fpath |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
793 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
794 |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
795 def tersedir(statuslist, terseargs): |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
796 """ |
34698
23eb03f46929
tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents:
34684
diff
changeset
|
797 Terse the status if all the files in a directory shares the same status. |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
798 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
799 statuslist is scmutil.status() object which contains a list of files for |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
800 each status. |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
801 terseargs is string which is passed by the user as the argument to `--terse` |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
802 flag. |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
803 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
804 The function makes a tree of objects of dirnode class, and at each node it |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
805 stores the information required to know whether we can terse a certain |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
806 directory or not. |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
807 """ |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
808 # the order matters here as that is used to produce final list |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
809 allst = (b'm', b'a', b'r', b'd', b'u', b'i', b'c') |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
810 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
811 # checking the argument validity |
34893
068e0e531584
cmdutil: fix status tersing on Python 3
Augie Fackler <augie@google.com>
parents:
34857
diff
changeset
|
812 for s in pycompat.bytestr(terseargs): |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
813 if s not in allst: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
814 raise error.InputError(_(b"'%s' not recognized") % s) |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
815 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
816 # creating a dirnode object for the root of the repo |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
817 rootobj = dirnode(b'') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
818 pstatus = ( |
50910
1270677d740b
terse-status: use `sysstr` to specify attributes to set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50828
diff
changeset
|
819 ('modified', b'm'), |
1270677d740b
terse-status: use `sysstr` to specify attributes to set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50828
diff
changeset
|
820 ('added', b'a'), |
1270677d740b
terse-status: use `sysstr` to specify attributes to set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50828
diff
changeset
|
821 ('deleted', b'd'), |
1270677d740b
terse-status: use `sysstr` to specify attributes to set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50828
diff
changeset
|
822 ('clean', b'c'), |
1270677d740b
terse-status: use `sysstr` to specify attributes to set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50828
diff
changeset
|
823 ('unknown', b'u'), |
1270677d740b
terse-status: use `sysstr` to specify attributes to set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50828
diff
changeset
|
824 ('ignored', b'i'), |
1270677d740b
terse-status: use `sysstr` to specify attributes to set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50828
diff
changeset
|
825 ('removed', b'r'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
826 ) |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
827 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
828 tersedict = {} |
50910
1270677d740b
terse-status: use `sysstr` to specify attributes to set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50828
diff
changeset
|
829 for attrname, statuschar in pstatus: |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
830 for f in getattr(statuslist, attrname): |
34893
068e0e531584
cmdutil: fix status tersing on Python 3
Augie Fackler <augie@google.com>
parents:
34857
diff
changeset
|
831 rootobj.addfile(f, statuschar) |
068e0e531584
cmdutil: fix status tersing on Python 3
Augie Fackler <augie@google.com>
parents:
34857
diff
changeset
|
832 tersedict[statuschar] = [] |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
833 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
834 # we won't be tersing the root dir, so add files in it |
34684
5d98674df18a
tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents:
34683
diff
changeset
|
835 for st, fpath in rootobj.iterfilepaths(): |
5d98674df18a
tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents:
34683
diff
changeset
|
836 tersedict[st].append(fpath) |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
837 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
838 # process each sub-directory and build tersedict |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
839 for subdir in rootobj.subdirs.values(): |
34684
5d98674df18a
tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents:
34683
diff
changeset
|
840 for st, f in subdir.tersewalk(terseargs): |
5d98674df18a
tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents:
34683
diff
changeset
|
841 tersedict[st].append(f) |
34682
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
842 |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
843 tersedlist = [] |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
844 for st in allst: |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
845 tersedict[st].sort() |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
846 tersedlist.append(tersedict[st]) |
7e3001b74ab3
tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34372
diff
changeset
|
847 |
43645
9cb7f855e2fc
cmdutil: convert terse status result back to an scmutil.status
Augie Fackler <augie@google.com>
parents:
43644
diff
changeset
|
848 return scmutil.status(*tersedlist) |
33548
4cd4344a53c4
status: add a flag to terse the output (issue4119)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33509
diff
changeset
|
849 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
850 |
33771
96f43981c1c4
morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33737
diff
changeset
|
851 def _commentlines(raw): |
96f43981c1c4
morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33737
diff
changeset
|
852 '''Surround lineswith a comment char and a new line''' |
96f43981c1c4
morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33737
diff
changeset
|
853 lines = raw.splitlines() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
854 commentedlines = [b'# %s' % line for line in lines] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
855 return b'\n'.join(commentedlines) + b'\n' |
33771
96f43981c1c4
morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33737
diff
changeset
|
856 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
857 |
43841
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
858 @attr.s(frozen=True) |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48913
diff
changeset
|
859 class morestatus: |
49456
cdfba684b6a1
status: include `repo` in template context also for resolved paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
49305
diff
changeset
|
860 repo = attr.ib() |
43841
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
861 unfinishedop = attr.ib() |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
862 unfinishedmsg = attr.ib() |
43937
4ca89cc20d02
status: extract active-merge state for reuse
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43926
diff
changeset
|
863 activemerge = attr.ib() |
43841
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
864 unresolvedpaths = attr.ib() |
43939
07ebb567e8bb
status: make unresolved files always be in the morestatus structured output
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43938
diff
changeset
|
865 _formattedpaths = attr.ib(init=False, default=set()) |
43841
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
866 _label = b'status.morestatus' |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
867 |
43842
7315464f0613
status: add template/json data about whether a file has unresolved conflicts
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43841
diff
changeset
|
868 def formatfile(self, path, fm): |
43939
07ebb567e8bb
status: make unresolved files always be in the morestatus structured output
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43938
diff
changeset
|
869 self._formattedpaths.add(path) |
43937
4ca89cc20d02
status: extract active-merge state for reuse
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43926
diff
changeset
|
870 if self.activemerge and path in self.unresolvedpaths: |
43842
7315464f0613
status: add template/json data about whether a file has unresolved conflicts
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43841
diff
changeset
|
871 fm.data(unresolved=True) |
7315464f0613
status: add template/json data about whether a file has unresolved conflicts
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43841
diff
changeset
|
872 |
43841
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
873 def formatfooter(self, fm): |
43938
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
874 if self.unfinishedop or self.unfinishedmsg: |
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
875 fm.startitem() |
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
876 fm.data(itemtype=b'morestatus') |
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
877 |
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
878 if self.unfinishedop: |
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
879 fm.data(unfinished=self.unfinishedop) |
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
880 statemsg = ( |
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
881 _(b'The repository is in an unfinished *%s* state.') |
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
882 % self.unfinishedop |
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
883 ) |
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
884 fm.plain(b'%s\n' % _commentlines(statemsg), label=self._label) |
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
885 if self.unfinishedmsg: |
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
886 fm.data(unfinishedmsg=self.unfinishedmsg) |
43841
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
887 |
43939
07ebb567e8bb
status: make unresolved files always be in the morestatus structured output
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43938
diff
changeset
|
888 # May also start new data items. |
43841
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
889 self._formatconflicts(fm) |
43938
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
890 |
43841
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
891 if self.unfinishedmsg: |
43855
612951e08278
formatting: fix some recent formatting regressions
Martin von Zweigbergk <martinvonz@google.com>
parents:
43842
diff
changeset
|
892 fm.plain( |
612951e08278
formatting: fix some recent formatting regressions
Martin von Zweigbergk <martinvonz@google.com>
parents:
43842
diff
changeset
|
893 b'%s\n' % _commentlines(self.unfinishedmsg), label=self._label |
612951e08278
formatting: fix some recent formatting regressions
Martin von Zweigbergk <martinvonz@google.com>
parents:
43842
diff
changeset
|
894 ) |
43841
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
895 |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
896 def _formatconflicts(self, fm): |
43937
4ca89cc20d02
status: extract active-merge state for reuse
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43926
diff
changeset
|
897 if not self.activemerge: |
43841
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
898 return |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
899 |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
900 if self.unresolvedpaths: |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
901 mergeliststr = b'\n'.join( |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
902 [ |
43855
612951e08278
formatting: fix some recent formatting regressions
Martin von Zweigbergk <martinvonz@google.com>
parents:
43842
diff
changeset
|
903 b' %s' |
49456
cdfba684b6a1
status: include `repo` in template context also for resolved paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
49305
diff
changeset
|
904 % util.pathto(self.repo.root, encoding.getcwd(), path) |
43841
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
905 for path in self.unresolvedpaths |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
906 ] |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
907 ) |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
908 msg = ( |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
909 _( |
46687
83ffc49f7e48
morestatus: convert a UI message about merge conflicts to bytes
Matt Harbison <matt_harbison@yahoo.com>
parents:
46475
diff
changeset
|
910 b'''Unresolved merge conflicts: |
33771
96f43981c1c4
morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33737
diff
changeset
|
911 |
96f43981c1c4
morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33737
diff
changeset
|
912 %s |
96f43981c1c4
morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33737
diff
changeset
|
913 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
914 To mark files as resolved: hg resolve --mark FILE''' |
43841
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
915 ) |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
916 % mergeliststr |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
917 ) |
43939
07ebb567e8bb
status: make unresolved files always be in the morestatus structured output
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43938
diff
changeset
|
918 |
07ebb567e8bb
status: make unresolved files always be in the morestatus structured output
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43938
diff
changeset
|
919 # If any paths with unresolved conflicts were not previously |
07ebb567e8bb
status: make unresolved files always be in the morestatus structured output
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43938
diff
changeset
|
920 # formatted, output them now. |
07ebb567e8bb
status: make unresolved files always be in the morestatus structured output
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43938
diff
changeset
|
921 for f in self.unresolvedpaths: |
07ebb567e8bb
status: make unresolved files always be in the morestatus structured output
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43938
diff
changeset
|
922 if f in self._formattedpaths: |
07ebb567e8bb
status: make unresolved files always be in the morestatus structured output
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43938
diff
changeset
|
923 # Already output. |
07ebb567e8bb
status: make unresolved files always be in the morestatus structured output
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43938
diff
changeset
|
924 continue |
07ebb567e8bb
status: make unresolved files always be in the morestatus structured output
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43938
diff
changeset
|
925 fm.startitem() |
49456
cdfba684b6a1
status: include `repo` in template context also for resolved paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
49305
diff
changeset
|
926 fm.context(repo=self.repo) |
43939
07ebb567e8bb
status: make unresolved files always be in the morestatus structured output
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43938
diff
changeset
|
927 # We can't claim to know the status of the file - it may just |
07ebb567e8bb
status: make unresolved files always be in the morestatus structured output
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43938
diff
changeset
|
928 # have been in one of the states that were not requested for |
07ebb567e8bb
status: make unresolved files always be in the morestatus structured output
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43938
diff
changeset
|
929 # display, so it could be anything. |
07ebb567e8bb
status: make unresolved files always be in the morestatus structured output
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43938
diff
changeset
|
930 fm.data(itemtype=b'file', path=f, unresolved=True) |
07ebb567e8bb
status: make unresolved files always be in the morestatus structured output
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43938
diff
changeset
|
931 |
43841
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
932 else: |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
933 msg = _(b'No unresolved merge conflicts.') |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
934 |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
935 fm.plain(b'%s\n' % _commentlines(msg), label=self._label) |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
936 |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
937 |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
938 def readmorestatus(repo): |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
939 """Returns a morestatus object if the repo has unfinished state.""" |
42531
5bddd2244814
state: moved cmdutil.STATES and utilities to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents:
42530
diff
changeset
|
940 statetuple = statemod.getrepostate(repo) |
44856
b7808443ed6a
mergestate: split out merge state handling code from main merge module
Augie Fackler <augie@google.com>
parents:
44807
diff
changeset
|
941 mergestate = mergestatemod.mergestate.read(repo) |
43937
4ca89cc20d02
status: extract active-merge state for reuse
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43926
diff
changeset
|
942 activemerge = mergestate.active() |
43938
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
943 if not statetuple and not activemerge: |
43841
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
944 return None |
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
945 |
43938
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
946 unfinishedop = unfinishedmsg = unresolved = None |
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
947 if statetuple: |
489fdf27769c
status: make morestatus call out unresolved conflicts after update
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43937
diff
changeset
|
948 unfinishedop, unfinishedmsg = statetuple |
43937
4ca89cc20d02
status: extract active-merge state for reuse
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43926
diff
changeset
|
949 if activemerge: |
43841
fb4a6d584756
status: split morestatus data loading from display
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
43820
diff
changeset
|
950 unresolved = sorted(mergestate.unresolved()) |
43855
612951e08278
formatting: fix some recent formatting regressions
Martin von Zweigbergk <martinvonz@google.com>
parents:
43842
diff
changeset
|
951 return morestatus( |
49456
cdfba684b6a1
status: include `repo` in template context also for resolved paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
49305
diff
changeset
|
952 repo, unfinishedop, unfinishedmsg, activemerge, unresolved |
43855
612951e08278
formatting: fix some recent formatting regressions
Martin von Zweigbergk <martinvonz@google.com>
parents:
43842
diff
changeset
|
953 ) |
33771
96f43981c1c4
morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33737
diff
changeset
|
954 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
955 |
7213
b4c035057d34
findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents:
7121
diff
changeset
|
956 def findpossible(cmd, table, strict=False): |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
957 """ |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
958 Return cmd -> (aliases, command table entry) |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
959 for each matching command. |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
960 Return debug commands (or their aliases) only if no normal command matches. |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
961 """ |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
962 choice = {} |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
963 debugchoice = {} |
15600
195dbd1cef0c
alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents:
15231
diff
changeset
|
964 |
195dbd1cef0c
alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents:
15231
diff
changeset
|
965 if cmd in table: |
40295
fa88170c10bb
help: adding a proper declaration for shortlist/basic commands (API)
Rodrigo Damazio <rdamazio@google.com>
parents:
40101
diff
changeset
|
966 # short-circuit exact matches, "log" alias beats "log|history" |
15600
195dbd1cef0c
alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents:
15231
diff
changeset
|
967 keys = [cmd] |
195dbd1cef0c
alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents:
15231
diff
changeset
|
968 else: |
195dbd1cef0c
alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents:
15231
diff
changeset
|
969 keys = table.keys() |
195dbd1cef0c
alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents:
15231
diff
changeset
|
970 |
24222
02d7b5cd373b
dispatch: offer suggestions of similar-named commands
Augie Fackler <augie@google.com>
parents:
24216
diff
changeset
|
971 allcmds = [] |
15600
195dbd1cef0c
alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents:
15231
diff
changeset
|
972 for e in keys: |
10401
6252852b4332
mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents:
10344
diff
changeset
|
973 aliases = parsealiases(e) |
24222
02d7b5cd373b
dispatch: offer suggestions of similar-named commands
Augie Fackler <augie@google.com>
parents:
24216
diff
changeset
|
974 allcmds.extend(aliases) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
975 found = None |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
976 if cmd in aliases: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
977 found = cmd |
7213
b4c035057d34
findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents:
7121
diff
changeset
|
978 elif not strict: |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
979 for a in aliases: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
980 if a.startswith(cmd): |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
981 found = a |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
982 break |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
983 if found is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
984 if aliases[0].startswith(b"debug") or found.startswith(b"debug"): |
5178
18a9fbb5cd78
dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents:
5177
diff
changeset
|
985 debugchoice[found] = (aliases, table[e]) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
986 else: |
5178
18a9fbb5cd78
dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents:
5177
diff
changeset
|
987 choice[found] = (aliases, table[e]) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
988 |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
989 if not choice and debugchoice: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
990 choice = debugchoice |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
991 |
24222
02d7b5cd373b
dispatch: offer suggestions of similar-named commands
Augie Fackler <augie@google.com>
parents:
24216
diff
changeset
|
992 return choice, allcmds |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
993 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
994 |
7213
b4c035057d34
findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents:
7121
diff
changeset
|
995 def findcmd(cmd, table, strict=True): |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
996 """Return (aliases, command table entry) for command string.""" |
24222
02d7b5cd373b
dispatch: offer suggestions of similar-named commands
Augie Fackler <augie@google.com>
parents:
24216
diff
changeset
|
997 choice, allcmds = findpossible(cmd, table, strict) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
998 |
5915
d0576d065993
Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents:
5843
diff
changeset
|
999 if cmd in choice: |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
1000 return choice[cmd] |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
1001 |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
1002 if len(choice) > 1: |
32528
9f56d462634c
cmdutil: use sorted(dict) instead of x = dict.keys(); x.sort()
Augie Fackler <raf@durin42.com>
parents:
32434
diff
changeset
|
1003 clist = sorted(choice) |
7643
9a1ea6587557
error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents:
7404
diff
changeset
|
1004 raise error.AmbiguousCommand(cmd, clist) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
1005 |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
1006 if choice: |
32862
e4a43b810528
py3: explicitly convert dict.values() to a list on py3
Pulkit Goyal <7895pulkit@gmail.com>
parents:
32842
diff
changeset
|
1007 return list(choice.values())[0] |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
1008 |
24222
02d7b5cd373b
dispatch: offer suggestions of similar-named commands
Augie Fackler <augie@google.com>
parents:
24216
diff
changeset
|
1009 raise error.UnknownCommand(cmd, allcmds) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
1010 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1011 |
50828
13ad1b2ad3b4
branch: migrate `opts` to native kwargs
Matt Harbison <matt_harbison@yahoo.com>
parents:
50824
diff
changeset
|
1012 def changebranch(ui, repo, revs, label, **opts): |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
46969
diff
changeset
|
1013 """Change the branch name of given revs to label""" |
35745
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1014 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1015 with repo.wlock(), repo.lock(), repo.transaction(b'branches'): |
35745
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1016 # abort in case of uncommitted merge or dirty wdir |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1017 bailifchanged(repo) |
48116
5ced12cfa41b
errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48104
diff
changeset
|
1018 revs = logcmdutil.revrange(repo, revs) |
35745
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1019 if not revs: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1020 raise error.InputError(b"empty revision set") |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1021 roots = repo.revs(b'roots(%ld)', revs) |
35745
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1022 if len(roots) > 1: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1023 raise error.InputError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1024 _(b"cannot change branch of non-linear revisions") |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1025 ) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1026 rewriteutil.precheck(repo, revs, b'change branch of') |
35746
e5b6ba786d83
branch: allow changing branch name to existing name if possible
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35745
diff
changeset
|
1027 |
e5b6ba786d83
branch: allow changing branch name to existing name if possible
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35745
diff
changeset
|
1028 root = repo[roots.first()] |
40666
69268a13ffa5
branch: allow changing branch of merge commits with --rev
Anton Shestakov <av6@dwimlabs.net>
parents:
40367
diff
changeset
|
1029 rpb = {parent.branch() for parent in root.parents()} |
44401
92b7caf4cb9e
branch: make --force work even when specifying revs
Manuel Jacob <me@manueljacob.de>
parents:
44330
diff
changeset
|
1030 if ( |
50828
13ad1b2ad3b4
branch: migrate `opts` to native kwargs
Matt Harbison <matt_harbison@yahoo.com>
parents:
50824
diff
changeset
|
1031 not opts.get('force') |
44401
92b7caf4cb9e
branch: make --force work even when specifying revs
Manuel Jacob <me@manueljacob.de>
parents:
44330
diff
changeset
|
1032 and label not in rpb |
92b7caf4cb9e
branch: make --force work even when specifying revs
Manuel Jacob <me@manueljacob.de>
parents:
44330
diff
changeset
|
1033 and label in repo.branchmap() |
92b7caf4cb9e
branch: make --force work even when specifying revs
Manuel Jacob <me@manueljacob.de>
parents:
44330
diff
changeset
|
1034 ): |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1035 raise error.InputError( |
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1036 _(b"a branch of the same name already exists") |
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1037 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1038 |
35745
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1039 # make sure only topological heads |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1040 if repo.revs(b'heads(%ld) - head()', revs): |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1041 raise error.InputError( |
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1042 _(b"cannot change branch in middle of a stack") |
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1043 ) |
35745
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1044 |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1045 replacements = {} |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1046 # avoid import cycle mercurial.cmdutil -> mercurial.context -> |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1047 # mercurial.subrepo -> mercurial.cmdutil |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1048 from . import context |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1049 |
35745
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1050 for rev in revs: |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1051 ctx = repo[rev] |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1052 oldbranch = ctx.branch() |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1053 # check if ctx has same branch |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1054 if oldbranch == label: |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1055 continue |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1056 |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1057 def filectxfn(repo, newctx, path): |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1058 try: |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1059 return ctx[path] |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1060 except error.ManifestLookupError: |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1061 return None |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1062 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1063 ui.debug( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1064 b"changing branch of '%s' from '%s' to '%s'\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1065 % (hex(ctx.node()), oldbranch, label) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1066 ) |
35745
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1067 extra = ctx.extra() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1068 extra[b'branch_change'] = hex(ctx.node()) |
35745
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1069 # While changing branch of set of linear commits, make sure that |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1070 # we base our commits on new parent rather than old parent which |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1071 # was obsoleted while changing the branch |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1072 p1 = ctx.p1().node() |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1073 p2 = ctx.p2().node() |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1074 if p1 in replacements: |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1075 p1 = replacements[p1][0] |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1076 if p2 in replacements: |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1077 p2 = replacements[p2][0] |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1078 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1079 mc = context.memctx( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1080 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1081 (p1, p2), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1082 ctx.description(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1083 ctx.files(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1084 filectxfn, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1085 user=ctx.user(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1086 date=ctx.date(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1087 extra=extra, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1088 branch=label, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1089 ) |
35745
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1090 |
38423
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38373
diff
changeset
|
1091 newnode = repo.commitctx(mc) |
35745
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1092 replacements[ctx.node()] = (newnode,) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1093 ui.debug(b'new node id is %s\n' % hex(newnode)) |
35745
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1094 |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1095 # create obsmarkers and move bookmarks |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1096 scmutil.cleanupnodes( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1097 repo, replacements, b'branch-change', fixphase=True |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1098 ) |
35745
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1099 |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1100 # move the working copy too |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1101 wctx = repo[None] |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1102 # in-progress merge is a bit too complex for now. |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1103 if len(wctx.parents()) == 1: |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1104 newid = replacements.get(wctx.p1().node()) |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1105 if newid is not None: |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1106 # avoid import cycle mercurial.cmdutil -> mercurial.hg -> |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1107 # mercurial.cmdutil |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1108 from . import hg |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1109 |
35745
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1110 hg.update(repo, newid[0], quietempty=True) |
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1111 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1112 ui.status(_(b"changed branch on %d changesets\n") % len(replacements)) |
35745
3bd8ab4c80a5
branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35743
diff
changeset
|
1113 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1114 |
10402
d216fa04e48a
mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents:
10401
diff
changeset
|
1115 def findrepo(p): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1116 while not os.path.isdir(os.path.join(p, b".hg")): |
10402
d216fa04e48a
mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents:
10401
diff
changeset
|
1117 oldp, p = p, os.path.dirname(p) |
d216fa04e48a
mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents:
10401
diff
changeset
|
1118 if p == oldp: |
d216fa04e48a
mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents:
10401
diff
changeset
|
1119 return None |
d216fa04e48a
mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents:
10401
diff
changeset
|
1120 |
d216fa04e48a
mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents:
10401
diff
changeset
|
1121 return p |
d216fa04e48a
mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents:
10401
diff
changeset
|
1122 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1123 |
30755
0fbb3a5c188e
rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents:
30724
diff
changeset
|
1124 def bailifchanged(repo, merge=True, hint=None): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
1125 """enforce the precondition that working directory must be clean. |
30755
0fbb3a5c188e
rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents:
30724
diff
changeset
|
1126 |
0fbb3a5c188e
rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents:
30724
diff
changeset
|
1127 'merge' can be set to false if a pending uncommitted merge should be |
0fbb3a5c188e
rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents:
30724
diff
changeset
|
1128 ignored (such as when 'update --check' runs). |
0fbb3a5c188e
rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents:
30724
diff
changeset
|
1129 |
0fbb3a5c188e
rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents:
30724
diff
changeset
|
1130 'hint' is the usual hint given to Abort exception. |
0fbb3a5c188e
rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents:
30724
diff
changeset
|
1131 """ |
0fbb3a5c188e
rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents:
30724
diff
changeset
|
1132 |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46969
diff
changeset
|
1133 if merge and repo.dirstate.p2() != repo.nullid: |
45840
527ce85c2e60
errors: introduce StateError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45827
diff
changeset
|
1134 raise error.StateError(_(b'outstanding uncommitted merge'), hint=hint) |
43644
e01e0641f18a
cmdutil: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents:
43523
diff
changeset
|
1135 st = repo.status() |
e01e0641f18a
cmdutil: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents:
43523
diff
changeset
|
1136 if st.modified or st.added or st.removed or st.deleted: |
45840
527ce85c2e60
errors: introduce StateError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45827
diff
changeset
|
1137 raise error.StateError(_(b'uncommitted changes'), hint=hint) |
15231
cd6f10dccf16
cmdutil.bailifchanged: abort for dirty subrepos
Eric Roshan Eisner <ede@alum.mit.edu>
parents:
15214
diff
changeset
|
1138 ctx = repo[None] |
18364
6252b4f1c4b4
subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents:
18340
diff
changeset
|
1139 for s in sorted(ctx.substate): |
30755
0fbb3a5c188e
rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents:
30724
diff
changeset
|
1140 ctx.sub(s).bailifchanged(hint=hint) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
1141 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1142 |
50093
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
1143 def logmessage(ui: "uimod.ui", opts: Dict[bytes, Any]) -> Optional[bytes]: |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
46969
diff
changeset
|
1144 """get the log message according to -m and -l option""" |
43894
774cee0e95c6
amend: use cmdutil.check_at_most_one_arg()
Martin von Zweigbergk <martinvonz@google.com>
parents:
43893
diff
changeset
|
1145 |
774cee0e95c6
amend: use cmdutil.check_at_most_one_arg()
Martin von Zweigbergk <martinvonz@google.com>
parents:
43893
diff
changeset
|
1146 check_at_most_one_arg(opts, b'message', b'logfile') |
774cee0e95c6
amend: use cmdutil.check_at_most_one_arg()
Martin von Zweigbergk <martinvonz@google.com>
parents:
43893
diff
changeset
|
1147 |
50093
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
1148 message = cast(Optional[bytes], opts.get(b'message')) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1149 logfile = opts.get(b'logfile') |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
1150 |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
1151 if not message and logfile: |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
1152 try: |
32618
d3e1c5b4986c
cmdutil: use isstdiofilename() where appropriate
Yuya Nishihara <yuya@tcha.org>
parents:
32584
diff
changeset
|
1153 if isstdiofilename(logfile): |
14635
217b7d83afc3
cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents:
14518
diff
changeset
|
1154 message = ui.fin.read() |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
1155 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1156 message = b'\n'.join(util.readfile(logfile).splitlines()) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25657
diff
changeset
|
1157 except IOError as inst: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1158 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1159 _(b"can't read commit message '%s': %s") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1160 % (logfile, encoding.strtolocal(inst.strerror)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1161 ) |
4549
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
1162 return message |
0c61124ad877
dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents:
4548
diff
changeset
|
1163 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1164 |
24180
d8e0c591781c
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
24176
diff
changeset
|
1165 def mergeeditform(ctxorbool, baseformname): |
d8e0c591781c
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
24176
diff
changeset
|
1166 """return appropriate editform name (referencing a committemplate) |
d8e0c591781c
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
24176
diff
changeset
|
1167 |
d8e0c591781c
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
24176
diff
changeset
|
1168 'ctxorbool' is either a ctx to be committed, or a bool indicating whether |
22248
75618a223e18
commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22237
diff
changeset
|
1169 merging is committed. |
75618a223e18
commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22237
diff
changeset
|
1170 |
24180
d8e0c591781c
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
24176
diff
changeset
|
1171 This returns baseformname with '.merge' appended if it is a merge, |
d8e0c591781c
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
24176
diff
changeset
|
1172 otherwise '.normal' is appended. |
22248
75618a223e18
commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22237
diff
changeset
|
1173 """ |
75618a223e18
commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22237
diff
changeset
|
1174 if isinstance(ctxorbool, bool): |
75618a223e18
commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22237
diff
changeset
|
1175 if ctxorbool: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1176 return baseformname + b".merge" |
40029
e2697acd9381
cleanup: some Yoda conditions, this patch removes
Martin von Zweigbergk <martinvonz@google.com>
parents:
39931
diff
changeset
|
1177 elif len(ctxorbool.parents()) > 1: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1178 return baseformname + b".merge" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1179 |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1180 return baseformname + b".normal" |
22248
75618a223e18
commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22237
diff
changeset
|
1181 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1182 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1183 def getcommiteditor( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1184 edit=False, finishdesc=None, extramsg=None, editform=b'', **opts |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1185 ): |
21419
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1186 """get appropriate commit message editor according to '--edit' option |
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1187 |
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1188 'finishdesc' is a function to be called with edited commit message |
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1189 (= 'description' of the new changeset) just after editing, but |
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1190 before checking empty-ness. It should return actual text to be |
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1191 stored into history. This allows to change description before |
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1192 storing. |
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1193 |
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1194 'extramsg' is a extra message to be shown in the editor instead of |
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1195 'Leave message empty to abort commit' line. 'HG: ' prefix and EOL |
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1196 is automatically added. |
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1197 |
21999
6ce282ed801e
cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21998
diff
changeset
|
1198 'editform' is a dot-separated list of names, to distinguish |
6ce282ed801e
cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21998
diff
changeset
|
1199 the purpose of commit text editing. |
6ce282ed801e
cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21998
diff
changeset
|
1200 |
21419
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1201 'getcommiteditor' returns 'commitforceeditor' regardless of |
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1202 'edit', if one of 'finishdesc' or 'extramsg' is specified, because |
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1203 they are specific for usage in MQ. |
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1204 """ |
272785489ed3
cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21417
diff
changeset
|
1205 if edit or finishdesc or extramsg: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1206 return lambda r, c, s: commitforceeditor( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1207 r, c, s, finishdesc=finishdesc, extramsg=extramsg, editform=editform |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1208 ) |
21999
6ce282ed801e
cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21998
diff
changeset
|
1209 elif editform: |
6ce282ed801e
cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21998
diff
changeset
|
1210 return lambda r, c, s: commiteditor(r, c, s, editform=editform) |
21405
dcf20f244c2a
cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21241
diff
changeset
|
1211 else: |
dcf20f244c2a
cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21241
diff
changeset
|
1212 return commiteditor |
dcf20f244c2a
cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21241
diff
changeset
|
1213 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1214 |
37774
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1215 def _escapecommandtemplate(tmpl): |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1216 parts = [] |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1217 for typ, start, end in templater.scantemplate(tmpl, raw=True): |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1218 if typ == b'string': |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1219 parts.append(stringutil.escapestr(tmpl[start:end])) |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1220 else: |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1221 parts.append(tmpl[start:end]) |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1222 return b''.join(parts) |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1223 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1224 |
37774
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1225 def rendercommandtemplate(ui, tmpl, props): |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1226 r"""Expand a literal template 'tmpl' in a way suitable for command line |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1227 |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1228 '\' in outermost string is not taken as an escape character because it |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1229 is a directory separator on Windows. |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1230 |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1231 >>> from . import ui as uimod |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1232 >>> ui = uimod.ui() |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1233 >>> rendercommandtemplate(ui, b'c:\\{path}', {b'path': b'foo'}) |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1234 'c:\\foo' |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1235 >>> rendercommandtemplate(ui, b'{"c:\\{path}"}', {'path': b'foo'}) |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1236 'c:{path}' |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1237 """ |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1238 if not tmpl: |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1239 return tmpl |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1240 t = formatter.maketemplater(ui, _escapecommandtemplate(tmpl)) |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1241 return t.renderdefault(props) |
d6970628b95f
fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents:
37763
diff
changeset
|
1242 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1243 |
36511
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1244 def rendertemplate(ctx, tmpl, props=None): |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1245 """Expand a literal template 'tmpl' byte-string against one changeset |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1246 |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1247 Each props item must be a stringify-able value or a callable returning |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1248 such value, i.e. no bare list nor dict should be passed. |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1249 """ |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1250 repo = ctx.repo() |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1251 tres = formatter.templateresources(repo.ui, repo) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1252 t = formatter.maketemplater( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1253 repo.ui, tmpl, defaults=templatekw.keywords, resources=tres |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1254 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1255 mapping = {b'ctx': ctx} |
36511
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1256 if props: |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1257 mapping.update(props) |
36988
317382151ac3
templater: rename .render(mapping) to .renderdefault(mapping) (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36986
diff
changeset
|
1258 return t.renderdefault(mapping) |
36511
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1259 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1260 |
45770
96fcc37a9c80
rebase: make summary template configurable, with default to shared template
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
1261 def format_changeset_summary(ui, ctx, command=None, default_spec=None): |
96fcc37a9c80
rebase: make summary template configurable, with default to shared template
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
1262 """Format a changeset summary (one line).""" |
96fcc37a9c80
rebase: make summary template configurable, with default to shared template
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
1263 spec = None |
96fcc37a9c80
rebase: make summary template configurable, with default to shared template
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
1264 if command: |
96fcc37a9c80
rebase: make summary template configurable, with default to shared template
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
1265 spec = ui.config( |
96fcc37a9c80
rebase: make summary template configurable, with default to shared template
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
1266 b'command-templates', b'oneline-summary.%s' % command, None |
96fcc37a9c80
rebase: make summary template configurable, with default to shared template
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
1267 ) |
96fcc37a9c80
rebase: make summary template configurable, with default to shared template
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
1268 if not spec: |
96fcc37a9c80
rebase: make summary template configurable, with default to shared template
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
1269 spec = ui.config(b'command-templates', b'oneline-summary') |
96fcc37a9c80
rebase: make summary template configurable, with default to shared template
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
1270 if not spec: |
96fcc37a9c80
rebase: make summary template configurable, with default to shared template
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
1271 spec = default_spec |
96fcc37a9c80
rebase: make summary template configurable, with default to shared template
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
1272 if not spec: |
45771
f90a5c211251
rebase: change and standarize template for rebase's one-line summary
Martin von Zweigbergk <martinvonz@google.com>
parents:
45770
diff
changeset
|
1273 spec = ( |
f90a5c211251
rebase: change and standarize template for rebase's one-line summary
Martin von Zweigbergk <martinvonz@google.com>
parents:
45770
diff
changeset
|
1274 b'{separate(" ", ' |
45796
e9555305c5c6
templates: include all non-branch namespaces in default one-line summary
Martin von Zweigbergk <martinvonz@google.com>
parents:
45771
diff
changeset
|
1275 b'label("oneline-summary.changeset", "{rev}:{node|short}")' |
45771
f90a5c211251
rebase: change and standarize template for rebase's one-line summary
Martin von Zweigbergk <martinvonz@google.com>
parents:
45770
diff
changeset
|
1276 b', ' |
45796
e9555305c5c6
templates: include all non-branch namespaces in default one-line summary
Martin von Zweigbergk <martinvonz@google.com>
parents:
45771
diff
changeset
|
1277 b'join(filter(namespaces % "{ifeq(namespace, "branches", "", join(names % "{label("oneline-summary.{namespace}", name)}", " "))}"), " ")' |
45771
f90a5c211251
rebase: change and standarize template for rebase's one-line summary
Martin von Zweigbergk <martinvonz@google.com>
parents:
45770
diff
changeset
|
1278 b')} ' |
45796
e9555305c5c6
templates: include all non-branch namespaces in default one-line summary
Martin von Zweigbergk <martinvonz@google.com>
parents:
45771
diff
changeset
|
1279 b'"{label("oneline-summary.desc", desc|firstline)}"' |
45771
f90a5c211251
rebase: change and standarize template for rebase's one-line summary
Martin von Zweigbergk <martinvonz@google.com>
parents:
45770
diff
changeset
|
1280 ) |
45770
96fcc37a9c80
rebase: make summary template configurable, with default to shared template
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
1281 text = rendertemplate(ctx, spec) |
96fcc37a9c80
rebase: make summary template configurable, with default to shared template
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
1282 return text.split(b'\n')[0] |
96fcc37a9c80
rebase: make summary template configurable, with default to shared template
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
1283 |
96fcc37a9c80
rebase: make summary template configurable, with default to shared template
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
1284 |
36511
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1285 def _buildfntemplate(pat, total=None, seqno=None, revwidth=None, pathname=None): |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1286 r"""Convert old-style filename format string to template string |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1287 |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1288 >>> _buildfntemplate(b'foo-%b-%n.patch', seqno=0) |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1289 'foo-{reporoot|basename}-{seqno}.patch' |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1290 >>> _buildfntemplate(b'%R{tags % "{tag}"}%H') |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1291 '{rev}{tags % "{tag}"}{node}' |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1292 |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1293 '\' in outermost strings has to be escaped because it is a directory |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1294 separator on Windows: |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1295 |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1296 >>> _buildfntemplate(b'c:\\tmp\\%R\\%n.patch', seqno=0) |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1297 'c:\\\\tmp\\\\{rev}\\\\{seqno}.patch' |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1298 >>> _buildfntemplate(b'\\\\foo\\bar.patch') |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1299 '\\\\\\\\foo\\\\bar.patch' |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1300 >>> _buildfntemplate(b'\\{tags % "{tag}"}') |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1301 '\\\\{tags % "{tag}"}' |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1302 |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1303 but inner strings follow the template rules (i.e. '\' is taken as an |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1304 escape character): |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1305 |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1306 >>> _buildfntemplate(br'{"c:\tmp"}', seqno=0) |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1307 '{"c:\\tmp"}' |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1308 """ |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1309 expander = { |
36511
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1310 b'H': b'{node}', |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1311 b'R': b'{rev}', |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1312 b'h': b'{node|short}', |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1313 b'm': br'{sub(r"[^\w]", "_", desc|firstline)}', |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1314 b'r': b'{if(revwidth, pad(rev, revwidth, "0", left=True), rev)}', |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1315 b'%': b'%', |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1316 b'b': b'{reporoot|basename}', |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1317 } |
36239
428de1a59f2d
cmdutil: narrow scope of KeyError in makefilename()
Yuya Nishihara <yuya@tcha.org>
parents:
36207
diff
changeset
|
1318 if total is not None: |
36511
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1319 expander[b'N'] = b'{total}' |
36239
428de1a59f2d
cmdutil: narrow scope of KeyError in makefilename()
Yuya Nishihara <yuya@tcha.org>
parents:
36207
diff
changeset
|
1320 if seqno is not None: |
36511
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1321 expander[b'n'] = b'{seqno}' |
36239
428de1a59f2d
cmdutil: narrow scope of KeyError in makefilename()
Yuya Nishihara <yuya@tcha.org>
parents:
36207
diff
changeset
|
1322 if total is not None and seqno is not None: |
36511
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1323 expander[b'n'] = b'{pad(seqno, total|stringify|count, "0", left=True)}' |
36239
428de1a59f2d
cmdutil: narrow scope of KeyError in makefilename()
Yuya Nishihara <yuya@tcha.org>
parents:
36207
diff
changeset
|
1324 if pathname is not None: |
36511
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1325 expander[b's'] = b'{pathname|basename}' |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1326 expander[b'd'] = b'{if(pathname|dirname, pathname|dirname, ".")}' |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1327 expander[b'p'] = b'{pathname}' |
36239
428de1a59f2d
cmdutil: narrow scope of KeyError in makefilename()
Yuya Nishihara <yuya@tcha.org>
parents:
36207
diff
changeset
|
1328 |
428de1a59f2d
cmdutil: narrow scope of KeyError in makefilename()
Yuya Nishihara <yuya@tcha.org>
parents:
36207
diff
changeset
|
1329 newname = [] |
36511
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1330 for typ, start, end in templater.scantemplate(pat, raw=True): |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1331 if typ != b'string': |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1332 newname.append(pat[start:end]) |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1333 continue |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1334 i = start |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1335 while i < end: |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1336 n = pat.find(b'%', i, end) |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1337 if n < 0: |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36988
diff
changeset
|
1338 newname.append(stringutil.escapestr(pat[i:end])) |
36511
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1339 break |
37084
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36988
diff
changeset
|
1340 newname.append(stringutil.escapestr(pat[i:n])) |
36511
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1341 if n + 2 > end: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1342 raise error.Abort( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43106
diff
changeset
|
1343 _(b"incomplete format spec in output filename") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1344 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1345 c = pat[n + 1 : n + 2] |
36511
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1346 i = n + 2 |
36239
428de1a59f2d
cmdutil: narrow scope of KeyError in makefilename()
Yuya Nishihara <yuya@tcha.org>
parents:
36207
diff
changeset
|
1347 try: |
36511
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1348 newname.append(expander[c]) |
36239
428de1a59f2d
cmdutil: narrow scope of KeyError in makefilename()
Yuya Nishihara <yuya@tcha.org>
parents:
36207
diff
changeset
|
1349 except KeyError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1350 raise error.Abort( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43106
diff
changeset
|
1351 _(b"invalid format spec '%%%s' in output filename") % c |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1352 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1353 return b''.join(newname) |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1354 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1355 |
36511
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1356 def makefilename(ctx, pat, **props): |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1357 if not pat: |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1358 return pat |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1359 tmpl = _buildfntemplate(pat, **props) |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1360 # BUG: alias expansion shouldn't be made against template fragments |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1361 # rewritten from %-format strings, but we have no easy way to partially |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1362 # disable the expansion. |
aa3294027936
cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
36508
diff
changeset
|
1363 return rendertemplate(ctx, tmpl, pycompat.byteskwargs(props)) |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
1364 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1365 |
32539
447bbd970047
cmdutil: extract function checking if pattern should be taken as stdin/out
Yuya Nishihara <yuya@tcha.org>
parents:
32538
diff
changeset
|
1366 def isstdiofilename(pat): |
447bbd970047
cmdutil: extract function checking if pattern should be taken as stdin/out
Yuya Nishihara <yuya@tcha.org>
parents:
32538
diff
changeset
|
1367 """True if the given pat looks like a filename denoting stdin/stdout""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1368 return not pat or pat == b'-' |
32539
447bbd970047
cmdutil: extract function checking if pattern should be taken as stdin/out
Yuya Nishihara <yuya@tcha.org>
parents:
32538
diff
changeset
|
1369 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1370 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48913
diff
changeset
|
1371 class _unclosablefile: |
27418
2ce4661ac226
cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents:
27417
diff
changeset
|
1372 def __init__(self, fp): |
2ce4661ac226
cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents:
27417
diff
changeset
|
1373 self._fp = fp |
2ce4661ac226
cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents:
27417
diff
changeset
|
1374 |
2ce4661ac226
cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents:
27417
diff
changeset
|
1375 def close(self): |
2ce4661ac226
cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents:
27417
diff
changeset
|
1376 pass |
2ce4661ac226
cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents:
27417
diff
changeset
|
1377 |
2ce4661ac226
cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents:
27417
diff
changeset
|
1378 def __iter__(self): |
2ce4661ac226
cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents:
27417
diff
changeset
|
1379 return iter(self._fp) |
2ce4661ac226
cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents:
27417
diff
changeset
|
1380 |
2ce4661ac226
cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents:
27417
diff
changeset
|
1381 def __getattr__(self, attr): |
2ce4661ac226
cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents:
27417
diff
changeset
|
1382 return getattr(self._fp, attr) |
2ce4661ac226
cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents:
27417
diff
changeset
|
1383 |
30142
3dcaf1c4e90d
largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents:
30016
diff
changeset
|
1384 def __enter__(self): |
3dcaf1c4e90d
largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents:
30016
diff
changeset
|
1385 return self |
3dcaf1c4e90d
largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents:
30016
diff
changeset
|
1386 |
3dcaf1c4e90d
largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents:
30016
diff
changeset
|
1387 def __exit__(self, exc_type, exc_value, exc_tb): |
3dcaf1c4e90d
largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents:
30016
diff
changeset
|
1388 pass |
3dcaf1c4e90d
largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents:
30016
diff
changeset
|
1389 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1390 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1391 def makefileobj(ctx, pat, mode=b'wb', **props): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1392 writable = mode not in (b'r', b'rb') |
7319
eae1767cc6a8
export: fixed silent output file overwriting
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
7308
diff
changeset
|
1393 |
32539
447bbd970047
cmdutil: extract function checking if pattern should be taken as stdin/out
Yuya Nishihara <yuya@tcha.org>
parents:
32538
diff
changeset
|
1394 if isstdiofilename(pat): |
36205
976e1cfb2f64
cmdutil: pass ctx to makefileobj() in place of repo/node pair (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36204
diff
changeset
|
1395 repo = ctx.repo() |
24306
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24301
diff
changeset
|
1396 if writable: |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24301
diff
changeset
|
1397 fp = repo.ui.fout |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24301
diff
changeset
|
1398 else: |
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24301
diff
changeset
|
1399 fp = repo.ui.fin |
27419
7e2495bf0ad8
cmdutil: do not duplicate stdout by makefileobj()
Yuya Nishihara <yuya@tcha.org>
parents:
27418
diff
changeset
|
1400 return _unclosablefile(fp) |
36508
d7a23d6184a2
cmdutil: reorder optional arguments passed to makefileobj()
Yuya Nishihara <yuya@tcha.org>
parents:
36507
diff
changeset
|
1401 fn = makefilename(ctx, pat, **props) |
18613
1a2f4c633410
export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents:
18538
diff
changeset
|
1402 return open(fn, mode) |
2882
cf98cd70d2c4
move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2874
diff
changeset
|
1403 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1404 |
39278
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1405 def openstorage(repo, cmd, file_, opts, returnrevlog=False): |
14323
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1406 """opens the changelog, manifest, a filelog or a given revlog""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1407 cl = opts[b'changelog'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1408 mf = opts[b'manifest'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1409 dir = opts[b'dir'] |
14323
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1410 msg = None |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1411 if cl and mf: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1412 msg = _(b'cannot specify --changelog and --manifest at the same time') |
25119
49c583ca48c4
treemanifest: add --dir option to debug{revlog,data,index}
Martin von Zweigbergk <martinvonz@google.com>
parents:
25100
diff
changeset
|
1413 elif cl and dir: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1414 msg = _(b'cannot specify --changelog and --dir at the same time') |
29427
33a6b750b5b9
debug: make debug{revlog,index,data} --dir not just a flag
Martin von Zweigbergk <martinvonz@google.com>
parents:
29397
diff
changeset
|
1415 elif cl or mf or dir: |
14323
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1416 if file_: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1417 msg = _(b'cannot specify filename with --changelog or --manifest') |
14323
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1418 elif not repo: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1419 msg = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1420 b'cannot specify --changelog or --manifest or --dir ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1421 b'without a repository' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1422 ) |
14323
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1423 if msg: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1424 raise error.InputError(msg) |
14323
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1425 |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1426 r = None |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1427 if repo: |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1428 if cl: |
21033
254f55b64e31
debugrevlog: use unfiltered view for changelog
Matt Mackall <mpm@selenic.com>
parents:
21024
diff
changeset
|
1429 r = repo.unfiltered().changelog |
25119
49c583ca48c4
treemanifest: add --dir option to debug{revlog,data,index}
Martin von Zweigbergk <martinvonz@google.com>
parents:
25100
diff
changeset
|
1430 elif dir: |
45552
10284ce3d5ed
scmutil: introduce function to check whether repo uses treemanifest or not
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45480
diff
changeset
|
1431 if not scmutil.istreemanifest(repo): |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1432 raise error.InputError( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1433 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1434 b"--dir can only be used on repos with " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1435 b"treemanifest enabled" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1436 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1437 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1438 if not dir.endswith(b'/'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1439 dir = dir + b'/' |
39244
73cf21b2e8a6
manifest: add getstorage() to manifestlog and use it globally
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39090
diff
changeset
|
1440 dirlog = repo.manifestlog.getstorage(dir) |
25119
49c583ca48c4
treemanifest: add --dir option to debug{revlog,data,index}
Martin von Zweigbergk <martinvonz@google.com>
parents:
25100
diff
changeset
|
1441 if len(dirlog): |
49c583ca48c4
treemanifest: add --dir option to debug{revlog,data,index}
Martin von Zweigbergk <martinvonz@google.com>
parents:
25100
diff
changeset
|
1442 r = dirlog |
14323
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1443 elif mf: |
39244
73cf21b2e8a6
manifest: add getstorage() to manifestlog and use it globally
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39090
diff
changeset
|
1444 r = repo.manifestlog.getstorage(b'') |
14323
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1445 elif file_: |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1446 filelog = repo.file(file_) |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1447 if len(filelog): |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1448 r = filelog |
39278
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1449 |
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1450 # Not all storage may be revlogs. If requested, try to return an actual |
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1451 # revlog instance. |
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1452 if returnrevlog: |
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1453 if isinstance(r, revlog.revlog): |
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1454 pass |
50928
d718eddf01d9
safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50910
diff
changeset
|
1455 elif hasattr(r, '_revlog'): |
43491
9391784299e9
cmdutil: suppress bogus pytype errors
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
1456 r = r._revlog # pytype: disable=attribute-error |
39278
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1457 elif r is not None: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1458 raise error.InputError( |
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1459 _(b'%r does not appear to be a revlog') % r |
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1460 ) |
39278
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1461 |
14323
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1462 if not r: |
39278
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1463 if not returnrevlog: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1464 raise error.InputError(_(b'cannot give path to non-revlog')) |
39278
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1465 |
14323
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1466 if not file_: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1467 raise error.CommandError(cmd, _(b'invalid arguments')) |
14323
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1468 if not os.path.isfile(file_): |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1469 raise error.InputError(_(b"revlog '%s' not found") % file_) |
47072
4c041c71ec01
revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47021
diff
changeset
|
1470 |
4c041c71ec01
revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47021
diff
changeset
|
1471 target = (revlog_constants.KIND_OTHER, b'free-form:%s' % file_) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1472 r = revlog.revlog( |
47072
4c041c71ec01
revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47021
diff
changeset
|
1473 vfsmod.vfs(encoding.getcwd(), audit=False), |
4c041c71ec01
revlog: introduce an explicit tracking of what the revlog is about
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47021
diff
changeset
|
1474 target=target, |
47150
8d3c2f9d4af7
revlog: use a "radix" to address revlog
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47128
diff
changeset
|
1475 radix=file_[:-2], |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1476 ) |
14323
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1477 return r |
a79fea6b3e77
debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents:
14322
diff
changeset
|
1478 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1479 |
39278
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1480 def openrevlog(repo, cmd, file_, opts): |
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1481 """Obtain a revlog backing storage of an item. |
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1482 |
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1483 This is similar to ``openstorage()`` except it always returns a revlog. |
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1484 |
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1485 In most cases, a caller cares about the main storage object - not the |
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1486 revlog backing it. Therefore, this function should only be used by code |
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1487 that needs to examine low-level revlog implementation details. e.g. debug |
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1488 commands. |
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1489 """ |
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1490 return openstorage(repo, cmd, file_, opts, returnrevlog=True) |
53e532007878
cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39244
diff
changeset
|
1491 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1492 |
50093
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
1493 def copy(ui, repo, pats, opts: Dict[bytes, Any], rename=False): |
44364
8be0c63535b5
copy: add option to unmark file as copied
Martin von Zweigbergk <martinvonz@google.com>
parents:
44361
diff
changeset
|
1494 check_incompatible_arguments(opts, b'forget', [b'dry_run']) |
8be0c63535b5
copy: add option to unmark file as copied
Martin von Zweigbergk <martinvonz@google.com>
parents:
44361
diff
changeset
|
1495 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1496 # called with the repo lock held |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1497 # |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1498 # hgsep => pathname that uses "/" to separate directories |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1499 # ossep => pathname that uses os.sep to separate directories |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1500 cwd = repo.getcwd() |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1501 targets = {} |
44364
8be0c63535b5
copy: add option to unmark file as copied
Martin von Zweigbergk <martinvonz@google.com>
parents:
44361
diff
changeset
|
1502 forget = opts.get(b"forget") |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1503 after = opts.get(b"after") |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1504 dryrun = opts.get(b"dry_run") |
44367
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1505 rev = opts.get(b'at_rev') |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1506 if rev: |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1507 if not forget and not after: |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1508 # TODO: Remove this restriction and make it also create the copy |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1509 # targets (and remove the rename source if rename==True). |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1510 raise error.InputError(_(b'--at-rev requires --after')) |
48118
5105a9975407
errors: raise InputError from revsingle() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48116
diff
changeset
|
1511 ctx = logcmdutil.revsingle(repo, rev) |
44367
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1512 if len(ctx.parents()) > 1: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1513 raise error.InputError( |
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1514 _(b'cannot mark/unmark copy in merge commit') |
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1515 ) |
44367
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1516 else: |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1517 ctx = repo[None] |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1518 |
44361
27a78ea30b48
copy: rename `wctx` to `ctx` since it will not necessarily be working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
44360
diff
changeset
|
1519 pctx = ctx.p1() |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1520 |
41657
e41449818bee
copy: respect ui.relative-paths in copy/rename
Martin von Zweigbergk <martinvonz@google.com>
parents:
41653
diff
changeset
|
1521 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1522 |
44364
8be0c63535b5
copy: add option to unmark file as copied
Martin von Zweigbergk <martinvonz@google.com>
parents:
44361
diff
changeset
|
1523 if forget: |
44365
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1524 if ctx.rev() is None: |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1525 new_ctx = ctx |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1526 else: |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1527 if len(ctx.parents()) > 1: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1528 raise error.InputError(_(b'cannot unmark copy in merge commit')) |
44365
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1529 # avoid cycle context -> subrepo -> cmdutil |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1530 from . import context |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1531 |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1532 rewriteutil.precheck(repo, [ctx.rev()], b'uncopy') |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1533 new_ctx = context.overlayworkingctx(repo) |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1534 new_ctx.setbase(ctx.p1()) |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1535 mergemod.graft(repo, ctx, wctx=new_ctx) |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1536 |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1537 match = scmutil.match(ctx, pats, opts) |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1538 |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1539 current_copies = ctx.p1copies() |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1540 current_copies.update(ctx.p2copies()) |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1541 |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1542 uipathfn = scmutil.getuipathfn(repo) |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1543 for f in ctx.walk(match): |
44364
8be0c63535b5
copy: add option to unmark file as copied
Martin von Zweigbergk <martinvonz@google.com>
parents:
44361
diff
changeset
|
1544 if f in current_copies: |
44365
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1545 new_ctx[f].markcopied(None) |
44364
8be0c63535b5
copy: add option to unmark file as copied
Martin von Zweigbergk <martinvonz@google.com>
parents:
44361
diff
changeset
|
1546 elif match.exact(f): |
8be0c63535b5
copy: add option to unmark file as copied
Martin von Zweigbergk <martinvonz@google.com>
parents:
44361
diff
changeset
|
1547 ui.warn( |
8be0c63535b5
copy: add option to unmark file as copied
Martin von Zweigbergk <martinvonz@google.com>
parents:
44361
diff
changeset
|
1548 _( |
8be0c63535b5
copy: add option to unmark file as copied
Martin von Zweigbergk <martinvonz@google.com>
parents:
44361
diff
changeset
|
1549 b'%s: not unmarking as copy - file is not marked as copied\n' |
8be0c63535b5
copy: add option to unmark file as copied
Martin von Zweigbergk <martinvonz@google.com>
parents:
44361
diff
changeset
|
1550 ) |
8be0c63535b5
copy: add option to unmark file as copied
Martin von Zweigbergk <martinvonz@google.com>
parents:
44361
diff
changeset
|
1551 % uipathfn(f) |
8be0c63535b5
copy: add option to unmark file as copied
Martin von Zweigbergk <martinvonz@google.com>
parents:
44361
diff
changeset
|
1552 ) |
44365
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1553 |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1554 if ctx.rev() is not None: |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1555 with repo.lock(): |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1556 mem_ctx = new_ctx.tomemctx_for_amend(ctx) |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1557 new_node = mem_ctx.commit() |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1558 |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1559 if repo.dirstate.p1() == ctx.node(): |
49961
7a8bfc05b691
dirstate: rename parentchange to changing_parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49960
diff
changeset
|
1560 with repo.dirstate.changing_parents(repo): |
44365
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1561 scmutil.movedirstate(repo, repo[new_node]) |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1562 replacements = {ctx.node(): [new_node]} |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1563 scmutil.cleanupnodes( |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1564 repo, replacements, b'uncopy', fixphase=True |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1565 ) |
7c4b98a4e536
copy: add experimetal support for unmarking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44364
diff
changeset
|
1566 |
44364
8be0c63535b5
copy: add option to unmark file as copied
Martin von Zweigbergk <martinvonz@google.com>
parents:
44361
diff
changeset
|
1567 return |
8be0c63535b5
copy: add option to unmark file as copied
Martin von Zweigbergk <martinvonz@google.com>
parents:
44361
diff
changeset
|
1568 |
44366
d8b49bf6cfec
copy: move argument validation a little earlier
Martin von Zweigbergk <martinvonz@google.com>
parents:
44365
diff
changeset
|
1569 pats = scmutil.expandpats(pats) |
d8b49bf6cfec
copy: move argument validation a little earlier
Martin von Zweigbergk <martinvonz@google.com>
parents:
44365
diff
changeset
|
1570 if not pats: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1571 raise error.InputError(_(b'no source or destination specified')) |
44366
d8b49bf6cfec
copy: move argument validation a little earlier
Martin von Zweigbergk <martinvonz@google.com>
parents:
44365
diff
changeset
|
1572 if len(pats) == 1: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1573 raise error.InputError(_(b'no destination specified')) |
44366
d8b49bf6cfec
copy: move argument validation a little earlier
Martin von Zweigbergk <martinvonz@google.com>
parents:
44365
diff
changeset
|
1574 dest = pats.pop() |
d8b49bf6cfec
copy: move argument validation a little earlier
Martin von Zweigbergk <martinvonz@google.com>
parents:
44365
diff
changeset
|
1575 |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
1576 def walkpat(pat): |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
1577 srcs = [] |
44805
02bf61bb4a70
copy: to find copy source, walk parent of revision we're marking copies in
Martin von Zweigbergk <martinvonz@google.com>
parents:
44452
diff
changeset
|
1578 # TODO: Inline and simplify the non-working-copy version of this code |
02bf61bb4a70
copy: to find copy source, walk parent of revision we're marking copies in
Martin von Zweigbergk <martinvonz@google.com>
parents:
44452
diff
changeset
|
1579 # since it shares very little with the working-copy version of it. |
02bf61bb4a70
copy: to find copy source, walk parent of revision we're marking copies in
Martin von Zweigbergk <martinvonz@google.com>
parents:
44452
diff
changeset
|
1580 ctx_to_walk = ctx if ctx.rev() is None else pctx |
02bf61bb4a70
copy: to find copy source, walk parent of revision we're marking copies in
Martin von Zweigbergk <martinvonz@google.com>
parents:
44452
diff
changeset
|
1581 m = scmutil.match(ctx_to_walk, [pat], opts, globbed=True) |
02bf61bb4a70
copy: to find copy source, walk parent of revision we're marking copies in
Martin von Zweigbergk <martinvonz@google.com>
parents:
44452
diff
changeset
|
1582 for abs in ctx_to_walk.walk(m): |
41657
e41449818bee
copy: respect ui.relative-paths in copy/rename
Martin von Zweigbergk <martinvonz@google.com>
parents:
41653
diff
changeset
|
1583 rel = uipathfn(abs) |
6584
29c77e5dfb3c
walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents:
6582
diff
changeset
|
1584 exact = m.exact(abs) |
44361
27a78ea30b48
copy: rename `wctx` to `ctx` since it will not necessarily be working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
44360
diff
changeset
|
1585 if abs not in ctx: |
44360
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1586 if abs in pctx: |
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1587 if not after: |
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1588 if exact: |
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1589 ui.warn( |
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1590 _( |
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1591 b'%s: not copying - file has been marked ' |
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1592 b'for remove\n' |
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1593 ) |
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1594 % rel |
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1595 ) |
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1596 continue |
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1597 else: |
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1598 if exact: |
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1599 ui.warn( |
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1600 _(b'%s: not copying - file is not managed\n') % rel |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1601 ) |
44360
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1602 continue |
2bd3b95fdce0
copy: rewrite walkpat() to depend less on dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
44306
diff
changeset
|
1603 |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
1604 # abs: hgsep |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
1605 # rel: ossep |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
1606 srcs.append((abs, rel, exact)) |
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
1607 return srcs |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1608 |
44367
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1609 if ctx.rev() is not None: |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1610 rewriteutil.precheck(repo, [ctx.rev()], b'uncopy') |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1611 absdest = pathutil.canonpath(repo.root, cwd, dest) |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1612 if ctx.hasdir(absdest): |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1613 raise error.InputError( |
44367
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1614 _(b'%s: --at-rev does not support a directory as destination') |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1615 % uipathfn(absdest) |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1616 ) |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1617 if absdest not in ctx: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1618 raise error.InputError( |
44367
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1619 _(b'%s: copy destination does not exist in %s') |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1620 % (uipathfn(absdest), ctx) |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1621 ) |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1622 |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1623 # avoid cycle context -> subrepo -> cmdutil |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1624 from . import context |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1625 |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1626 copylist = [] |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1627 for pat in pats: |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1628 srcs = walkpat(pat) |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1629 if not srcs: |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1630 continue |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1631 for abs, rel, exact in srcs: |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1632 copylist.append(abs) |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1633 |
44807
16596f5e1afa
copy: give better error message when no source paths found with --at-rev
Martin von Zweigbergk <martinvonz@google.com>
parents:
44805
diff
changeset
|
1634 if not copylist: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1635 raise error.InputError(_(b'no files to copy')) |
44367
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1636 # TODO: Add support for `hg cp --at-rev . foo bar dir` and |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1637 # `hg cp --at-rev . dir1 dir2`, preferably unifying the code with the |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1638 # existing functions below. |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1639 if len(copylist) != 1: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1640 raise error.InputError(_(b'--at-rev requires a single source')) |
44367
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1641 |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1642 new_ctx = context.overlayworkingctx(repo) |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1643 new_ctx.setbase(ctx.p1()) |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1644 mergemod.graft(repo, ctx, wctx=new_ctx) |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1645 |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1646 new_ctx.markcopied(absdest, copylist[0]) |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1647 |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1648 with repo.lock(): |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1649 mem_ctx = new_ctx.tomemctx_for_amend(ctx) |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1650 new_node = mem_ctx.commit() |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1651 |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1652 if repo.dirstate.p1() == ctx.node(): |
49961
7a8bfc05b691
dirstate: rename parentchange to changing_parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49960
diff
changeset
|
1653 with repo.dirstate.changing_parents(repo): |
44367
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1654 scmutil.movedirstate(repo, repo[new_node]) |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1655 replacements = {ctx.node(): [new_node]} |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1656 scmutil.cleanupnodes(repo, replacements, b'copy', fixphase=True) |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1657 |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1658 return |
9dab3fa64325
copy: add experimental support for marking committed copies
Martin von Zweigbergk <martinvonz@google.com>
parents:
44366
diff
changeset
|
1659 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1660 # abssrc: hgsep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1661 # relsrc: ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1662 # otarget: ossep |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
1663 def copyfile(abssrc, relsrc, otarget, exact): |
20033
f962870712da
pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
19944
diff
changeset
|
1664 abstarget = pathutil.canonpath(repo.root, cwd, otarget) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1665 if b'/' in abstarget: |
16542
e596a631210e
dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents:
16458
diff
changeset
|
1666 # We cannot normalize abstarget itself, this would prevent |
e596a631210e
dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents:
16458
diff
changeset
|
1667 # case only renames, like a => A. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1668 abspath, absname = abstarget.rsplit(b'/', 1) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1669 abstarget = repo.dirstate.normalize(abspath) + b'/' + absname |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1670 reltarget = repo.pathto(abstarget, cwd) |
5607 | 1671 target = repo.wjoin(abstarget) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1672 src = repo.wjoin(abssrc) |
48102
304267b077de
dirstate-item: use item's property instead of `state` in copy
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48100
diff
changeset
|
1673 entry = repo.dirstate.get_entry(abstarget) |
304267b077de
dirstate-item: use item's property instead of `state` in copy
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48100
diff
changeset
|
1674 |
304267b077de
dirstate-item: use item's property instead of `state` in copy
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48100
diff
changeset
|
1675 already_commited = entry.tracked and not entry.added |
5607 | 1676 |
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
13945
diff
changeset
|
1677 scmutil.checkportable(ui, abstarget) |
13945
03f3ce7ca2a8
copy: do not copy file if name is disallowed anyway
Adrian Buehlmann <adrian@cadifra.com>
parents:
13878
diff
changeset
|
1678 |
5607 | 1679 # check for collisions |
1680 prevsrc = targets.get(abstarget) | |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1681 if prevsrc is not None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1682 ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1683 _(b'%s: not overwriting - %s collides with %s\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1684 % ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1685 reltarget, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1686 repo.pathto(abssrc, cwd), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1687 repo.pathto(prevsrc, cwd), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1688 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1689 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1690 return True # report a failure |
5607 | 1691 |
1692 # check for overwrites | |
12342
70236d6fd844
rename: do not overwrite existing broken symlinks
Patrick Mezard <pmezard@gmail.com>
parents:
11950
diff
changeset
|
1693 exists = os.path.lexists(target) |
16283
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
1694 samefile = False |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
1695 if exists and abssrc != abstarget: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1696 if repo.dirstate.normalize(abssrc) == repo.dirstate.normalize( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1697 abstarget |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1698 ): |
16283
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
1699 if not rename: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1700 ui.warn(_(b"%s: can't copy - same file\n") % reltarget) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1701 return True # report a failure |
16283
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
1702 exists = False |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
1703 samefile = True |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
1704 |
48102
304267b077de
dirstate-item: use item's property instead of `state` in copy
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48100
diff
changeset
|
1705 if not after and exists or after and already_commited: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1706 if not opts[b'force']: |
48102
304267b077de
dirstate-item: use item's property instead of `state` in copy
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48100
diff
changeset
|
1707 if already_commited: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1708 msg = _(b'%s: not overwriting - file already committed\n') |
48247
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1709 # Check if if the target was added in the parent and the |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1710 # source already existed in the grandparent. |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1711 looks_like_copy_in_pctx = abstarget in pctx and any( |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1712 abssrc in gpctx and abstarget not in gpctx |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1713 for gpctx in pctx.parents() |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1714 ) |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1715 if looks_like_copy_in_pctx: |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1716 if rename: |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1717 hint = _( |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1718 b"('hg rename --at-rev .' to record the rename " |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1719 b"in the parent of the working copy)\n" |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1720 ) |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1721 else: |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1722 hint = _( |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1723 b"('hg copy --at-rev .' to record the copy in " |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1724 b"the parent of the working copy)\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1725 ) |
30151
381293e1135e
copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents:
30142
diff
changeset
|
1726 else: |
48247
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1727 if after: |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1728 flags = b'--after --force' |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1729 else: |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1730 flags = b'--force' |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1731 if rename: |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1732 hint = ( |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1733 _( |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1734 b"('hg rename %s' to replace the file by " |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1735 b'recording a rename)\n' |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1736 ) |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1737 % flags |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1738 ) |
48247
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1739 else: |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1740 hint = ( |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1741 _( |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1742 b"('hg copy %s' to replace the file by " |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1743 b'recording a copy)\n' |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1744 ) |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1745 % flags |
c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
48118
diff
changeset
|
1746 ) |
30151
381293e1135e
copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents:
30142
diff
changeset
|
1747 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1748 msg = _(b'%s: not overwriting - file exists\n') |
30151
381293e1135e
copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents:
30142
diff
changeset
|
1749 if rename: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1750 hint = _( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1751 b"('hg rename --after' to record the rename)\n" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1752 ) |
30151
381293e1135e
copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents:
30142
diff
changeset
|
1753 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1754 hint = _(b"('hg copy --after' to record the copy)\n") |
30151
381293e1135e
copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents:
30142
diff
changeset
|
1755 ui.warn(msg % reltarget) |
381293e1135e
copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents:
30142
diff
changeset
|
1756 ui.warn(hint) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1757 return True # report a failure |
5607 | 1758 |
1759 if after: | |
5608 | 1760 if not exists: |
11152
e8d10d085f47
cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents:
11061
diff
changeset
|
1761 if rename: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1762 ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1763 _(b'%s: not recording move - %s does not exist\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1764 % (relsrc, reltarget) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1765 ) |
11152
e8d10d085f47
cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents:
11061
diff
changeset
|
1766 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1767 ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1768 _(b'%s: not recording copy - %s does not exist\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1769 % (relsrc, reltarget) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1770 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1771 return True # report a failure |
5608 | 1772 elif not dryrun: |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1773 try: |
5608 | 1774 if exists: |
1775 os.unlink(target) | |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1776 targetdir = os.path.dirname(target) or b'.' |
5608 | 1777 if not os.path.isdir(targetdir): |
1778 os.makedirs(targetdir) | |
16283
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
1779 if samefile: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1780 tmp = target + b"~hgrename" |
16283
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
1781 os.rename(src, tmp) |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
1782 os.rename(tmp, target) |
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
1783 else: |
37088
08890706366e
copyfile: preserve stat info (mtime, etc.) when doing copies/renames
Kyle Lippincott <spectral@google.com>
parents:
37084
diff
changeset
|
1784 # Preserve stat info on renames, not on copies; this matches |
08890706366e
copyfile: preserve stat info (mtime, etc.) when doing copies/renames
Kyle Lippincott <spectral@google.com>
parents:
37084
diff
changeset
|
1785 # Linux CLI behavior. |
08890706366e
copyfile: preserve stat info (mtime, etc.) when doing copies/renames
Kyle Lippincott <spectral@google.com>
parents:
37084
diff
changeset
|
1786 util.copyfile(src, target, copystat=rename) |
14518
a67e866f46f9
workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents:
14442
diff
changeset
|
1787 srcexists = True |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25657
diff
changeset
|
1788 except IOError as inst: |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1789 if inst.errno == errno.ENOENT: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1790 ui.warn(_(b'%s: deleted in working directory\n') % relsrc) |
14518
a67e866f46f9
workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents:
14442
diff
changeset
|
1791 srcexists = False |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1792 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1793 ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1794 _(b'%s: cannot copy - %s\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1795 % (relsrc, encoding.strtolocal(inst.strerror)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1796 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1797 return True # report a failure |
5607 | 1798 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1799 if ui.verbose or not exact: |
7894
caef5fdf1375
cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents:
7879
diff
changeset
|
1800 if rename: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1801 ui.status(_(b'moving %s to %s\n') % (relsrc, reltarget)) |
7894
caef5fdf1375
cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents:
7879
diff
changeset
|
1802 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1803 ui.status(_(b'copying %s to %s\n') % (relsrc, reltarget)) |
5608 | 1804 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1805 targets[abstarget] = abssrc |
5607 | 1806 |
1807 # fix up dirstate | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1808 scmutil.dirstatecopy( |
44361
27a78ea30b48
copy: rename `wctx` to `ctx` since it will not necessarily be working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
44360
diff
changeset
|
1809 ui, repo, ctx, abssrc, abstarget, dryrun=dryrun, cwd=cwd |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1810 ) |
5610
2493a478f395
copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents:
5609
diff
changeset
|
1811 if rename and not dryrun: |
16283
6c4dbe28dda3
rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents:
16165
diff
changeset
|
1812 if not after and srcexists and not samefile: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1813 rmdir = repo.ui.configbool(b'experimental', b'removeemptydirs') |
38493
da2a7d8354b2
unlinkpath: make empty directory removal optional (issue5901) (issue5826)
Kyle Lippincott <spectral@google.com>
parents:
38461
diff
changeset
|
1814 repo.wvfs.unlinkpath(abssrc, rmdir=rmdir) |
44361
27a78ea30b48
copy: rename `wctx` to `ctx` since it will not necessarily be working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
44360
diff
changeset
|
1815 ctx.forget([abssrc]) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1816 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1817 # pat: ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1818 # dest ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1819 # srcs: list of (hgsep, hgsep, ossep, bool) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1820 # return: function that takes hgsep and returns ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1821 def targetpathfn(pat, dest, srcs): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1822 if os.path.isdir(pat): |
20033
f962870712da
pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
19944
diff
changeset
|
1823 abspfx = pathutil.canonpath(repo.root, cwd, pat) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1824 abspfx = util.localpath(abspfx) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1825 if destdirexists: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1826 striplen = len(os.path.split(abspfx)[0]) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1827 else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1828 striplen = len(abspfx) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1829 if striplen: |
30615
bb77654dc7ae
py3: replace os.sep with pycompat.ossep (part 3 of 4)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30534
diff
changeset
|
1830 striplen += len(pycompat.ossep) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1831 res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1832 elif destdirexists: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1833 res = lambda p: os.path.join( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1834 dest, os.path.basename(util.localpath(p)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1835 ) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1836 else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1837 res = lambda p: dest |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1838 return res |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1839 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1840 # pat: ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1841 # dest ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1842 # srcs: list of (hgsep, hgsep, ossep, bool) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1843 # return: function that takes hgsep and returns ossep |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1844 def targetpathafterfn(pat, dest, srcs): |
12085
6f833fc3ccab
Consistently import foo as foomod when foo to avoid shadowing
Martin Geisler <mg@aragost.com>
parents:
12032
diff
changeset
|
1845 if matchmod.patkind(pat): |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1846 # a mercurial pattern |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1847 res = lambda p: os.path.join( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1848 dest, os.path.basename(util.localpath(p)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1849 ) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1850 else: |
20033
f962870712da
pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
19944
diff
changeset
|
1851 abspfx = pathutil.canonpath(repo.root, cwd, pat) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1852 if len(abspfx) < len(srcs[0][0]): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1853 # A directory. Either the target path contains the last |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1854 # component of the source path or it does not. |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1855 def evalpath(striplen): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1856 score = 0 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1857 for s in srcs: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1858 t = os.path.join(dest, util.localpath(s[0])[striplen:]) |
12357
cb59654c2c7a
Restore lexists() changes lost in e0ee3e822a9a merge
Patrick Mezard <pmezard@gmail.com>
parents:
12345
diff
changeset
|
1859 if os.path.lexists(t): |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1860 score += 1 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1861 return score |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1862 |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1863 abspfx = util.localpath(abspfx) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1864 striplen = len(abspfx) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1865 if striplen: |
30615
bb77654dc7ae
py3: replace os.sep with pycompat.ossep (part 3 of 4)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30534
diff
changeset
|
1866 striplen += len(pycompat.ossep) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1867 if os.path.isdir(os.path.join(dest, os.path.split(abspfx)[1])): |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1868 score = evalpath(striplen) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1869 striplen1 = len(os.path.split(abspfx)[0]) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1870 if striplen1: |
30615
bb77654dc7ae
py3: replace os.sep with pycompat.ossep (part 3 of 4)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30534
diff
changeset
|
1871 striplen1 += len(pycompat.ossep) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1872 if evalpath(striplen1) > score: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1873 striplen = striplen1 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1874 res = lambda p: os.path.join(dest, util.localpath(p)[striplen:]) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1875 else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1876 # a file |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1877 if destdirexists: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1878 res = lambda p: os.path.join( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1879 dest, os.path.basename(util.localpath(p)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1880 ) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1881 else: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1882 res = lambda p: dest |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1883 return res |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1884 |
6258
c24f4b3f156b
Fix issue995 (copy --after and symlinks pointing to a directory)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
6211
diff
changeset
|
1885 destdirexists = os.path.isdir(dest) and not os.path.islink(dest) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1886 if not destdirexists: |
12085
6f833fc3ccab
Consistently import foo as foomod when foo to avoid shadowing
Martin Geisler <mg@aragost.com>
parents:
12032
diff
changeset
|
1887 if len(pats) > 1 or matchmod.patkind(pats[0]): |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1888 raise error.InputError( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1889 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1890 b'with multiple sources, destination must be an ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1891 b'existing directory' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1892 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1893 ) |
5843
83c354c4d529
Add endswithsep() and use it instead of using os.sep and os.altsep directly.
Shun-ichi GOTO <shunichi.goto@gmail.com>
parents:
5836
diff
changeset
|
1894 if util.endswithsep(dest): |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1895 raise error.InputError( |
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1896 _(b'destination %s is not a directory') % dest |
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
1897 ) |
5607 | 1898 |
1899 tfn = targetpathfn | |
1900 if after: | |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1901 tfn = targetpathafterfn |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1902 copylist = [] |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1903 for pat in pats: |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
1904 srcs = walkpat(pat) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1905 if not srcs: |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1906 continue |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1907 copylist.append((tfn(pat, dest, srcs), srcs)) |
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1908 if not copylist: |
47127
5ffc6c18fb96
rename: add hint about --at-rev if source file doesn't exist
Martin von Zweigbergk <martinvonz@google.com>
parents:
47072
diff
changeset
|
1909 hint = None |
5ffc6c18fb96
rename: add hint about --at-rev if source file doesn't exist
Martin von Zweigbergk <martinvonz@google.com>
parents:
47072
diff
changeset
|
1910 if rename: |
5ffc6c18fb96
rename: add hint about --at-rev if source file doesn't exist
Martin von Zweigbergk <martinvonz@google.com>
parents:
47072
diff
changeset
|
1911 hint = _(b'maybe you meant to use --after --at-rev=.') |
5ffc6c18fb96
rename: add hint about --at-rev if source file doesn't exist
Martin von Zweigbergk <martinvonz@google.com>
parents:
47072
diff
changeset
|
1912 raise error.InputError(_(b'no files to copy'), hint=hint) |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1913 |
5606
447ea621e50e
copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents:
5605
diff
changeset
|
1914 errors = 0 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1915 for targetpath, srcs in copylist: |
5605
e7a9ad999308
copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents:
5604
diff
changeset
|
1916 for abssrc, relsrc, exact in srcs: |
5606
447ea621e50e
copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents:
5605
diff
changeset
|
1917 if copyfile(abssrc, relsrc, targetpath(abssrc), exact): |
447ea621e50e
copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents:
5605
diff
changeset
|
1918 errors += 1 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1919 |
11177
6a64813276ed
commands: initial audit of exit codes
Matt Mackall <mpm@selenic.com>
parents:
11152
diff
changeset
|
1920 return errors != 0 |
5589
9981b6b19ecf
move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents:
5550
diff
changeset
|
1921 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1922 |
26561
1f14920a892c
import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26547
diff
changeset
|
1923 ## facility to let extension process additional data into an import patch |
1f14920a892c
import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26547
diff
changeset
|
1924 # list of identifier to be executed in order |
1f14920a892c
import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26547
diff
changeset
|
1925 extrapreimport = [] # run before commit |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1926 extrapostimport = [] # run after commit |
26561
1f14920a892c
import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26547
diff
changeset
|
1927 # mapping from identifier to actual import function |
1f14920a892c
import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26547
diff
changeset
|
1928 # |
1f14920a892c
import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26547
diff
changeset
|
1929 # 'preimport' are run before the commit is made and are provided the following |
1f14920a892c
import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26547
diff
changeset
|
1930 # arguments: |
1f14920a892c
import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26547
diff
changeset
|
1931 # - repo: the localrepository instance, |
1f14920a892c
import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26547
diff
changeset
|
1932 # - patchdata: data extracted from patch header (cf m.patch.patchheadermap), |
26781
1aee2ab0f902
spelling: trivial spell checking
Mads Kiilerich <madski@unity3d.com>
parents:
26750
diff
changeset
|
1933 # - extra: the future extra dictionary of the changeset, please mutate it, |
26561
1f14920a892c
import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26547
diff
changeset
|
1934 # - opts: the import options. |
1f14920a892c
import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26547
diff
changeset
|
1935 # XXX ideally, we would just pass an ctx ready to be computed, that would allow |
1f14920a892c
import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26547
diff
changeset
|
1936 # mutation of in memory commit and more. Feel free to rework the code to get |
1f14920a892c
import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26547
diff
changeset
|
1937 # there. |
1f14920a892c
import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26547
diff
changeset
|
1938 extrapreimportmap = {} |
26562
dd2f5e014806
import: allow processing of extra part header after import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26561
diff
changeset
|
1939 # 'postimport' are run after the commit is made and are provided the following |
dd2f5e014806
import: allow processing of extra part header after import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26561
diff
changeset
|
1940 # argument: |
dd2f5e014806
import: allow processing of extra part header after import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26561
diff
changeset
|
1941 # - ctx: the changectx created by import. |
dd2f5e014806
import: allow processing of extra part header after import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26561
diff
changeset
|
1942 extrapostimportmap = {} |
26561
1f14920a892c
import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26547
diff
changeset
|
1943 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
1944 |
37620
fd1dd79cff20
cmdutil: pass in parsed patch to tryimportone() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37604
diff
changeset
|
1945 def tryimportone(ui, repo, patchdata, parents, opts, msgs, updatefunc): |
20500
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1946 """Utility function used by commands.import to import a single patch |
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1947 |
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1948 This function is explicitly defined here to help the evolve extension to |
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1949 wrap this part of the import logic. |
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1950 |
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1951 The API is currently a bit ugly because it a simple code translation from |
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1952 the import command. Feel free to make it better. |
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1953 |
37620
fd1dd79cff20
cmdutil: pass in parsed patch to tryimportone() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37604
diff
changeset
|
1954 :patchdata: a dictionary containing parsed patch data (such as from |
fd1dd79cff20
cmdutil: pass in parsed patch to tryimportone() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37604
diff
changeset
|
1955 ``patch.extract()``) |
20500
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1956 :parents: nodes that will be parent of the created commit |
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1957 :opts: the full dict of option passed to the import command |
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1958 :msgs: list to save commit message to. |
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1959 (used in case we need to save it when failing) |
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1960 :updatefunc: a function that update a repo to a given node |
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1961 updatefunc(<repo>, <node>) |
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1962 """ |
25930
221491bbaf7e
cmdutil: break import cycle
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25795
diff
changeset
|
1963 # avoid cycle context -> subrepo -> cmdutil |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
1964 from . import context |
37620
fd1dd79cff20
cmdutil: pass in parsed patch to tryimportone() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37604
diff
changeset
|
1965 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1966 tmpname = patchdata.get(b'filename') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1967 message = patchdata.get(b'message') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1968 user = opts.get(b'user') or patchdata.get(b'user') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1969 date = opts.get(b'date') or patchdata.get(b'date') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1970 branch = patchdata.get(b'branch') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1971 nodeid = patchdata.get(b'nodeid') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1972 p1 = patchdata.get(b'p1') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1973 p2 = patchdata.get(b'p2') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1974 |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1975 nocommit = opts.get(b'no_commit') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1976 importbranch = opts.get(b'import_branch') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1977 update = not opts.get(b'bypass') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1978 strip = opts[b"strip"] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1979 prefix = opts[b"prefix"] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1980 sim = float(opts.get(b'similarity') or 0) |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
1981 |
20500
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1982 if not tmpname: |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
1983 return None, None, False |
20500
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
1984 |
21553
bee0e1cffdd3
import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21419
diff
changeset
|
1985 rejects = False |
bee0e1cffdd3
import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21419
diff
changeset
|
1986 |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
1987 cmdline_message = logmessage(ui, opts) |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
1988 if cmdline_message: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
1989 # pickup the cmdline msg |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
1990 message = cmdline_message |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
1991 elif message: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
1992 # pickup the patch msg |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
1993 message = message.strip() |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
1994 else: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
1995 # launch the editor |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
1996 message = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1997 ui.debug(b'message:\n%s\n' % (message or b'')) |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
1998 |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
1999 if len(parents) == 1: |
46842
ad878e3f282b
refactor: prefer lookup by revision, even for null
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
2000 parents.append(repo[nullrev]) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2001 if opts.get(b'exact'): |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2002 if not nodeid or not p1: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
2003 raise error.InputError(_(b'not a Mercurial patch')) |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2004 p1 = repo[p1] |
46842
ad878e3f282b
refactor: prefer lookup by revision, even for null
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
2005 p2 = repo[p2 or nullrev] |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2006 elif p2: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2007 try: |
20500
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
2008 p1 = repo[p1] |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2009 p2 = repo[p2] |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2010 # Without any options, consider p2 only if the |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2011 # patch is being applied on top of the recorded |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2012 # first parent. |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2013 if p1 != parents[0]: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2014 p1 = parents[0] |
46842
ad878e3f282b
refactor: prefer lookup by revision, even for null
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
2015 p2 = repo[nullrev] |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2016 except error.RepoError: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2017 p1, p2 = parents |
46842
ad878e3f282b
refactor: prefer lookup by revision, even for null
Joerg Sonnenberger <joerg@bec.de>
parents:
46819
diff
changeset
|
2018 if p2.rev() == nullrev: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2019 ui.warn( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2020 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2021 b"warning: import the patch as a normal revision\n" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2022 b"(use --exact to import the patch as a merge)\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2023 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2024 ) |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2025 else: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2026 p1, p2 = parents |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2027 |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2028 n = None |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2029 if update: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2030 if p1 != parents[0]: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2031 updatefunc(repo, p1.node()) |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2032 if p2 != parents[1]: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2033 repo.setparents(p1.node(), p2.node()) |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2034 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2035 if opts.get(b'exact') or importbranch: |
50263
798e4314ddd9
branch: pass current transaction when writing branch in import
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50203
diff
changeset
|
2036 repo.dirstate.setbranch( |
798e4314ddd9
branch: pass current transaction when writing branch in import
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50203
diff
changeset
|
2037 branch or b'default', repo.currenttransaction() |
798e4314ddd9
branch: pass current transaction when writing branch in import
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50203
diff
changeset
|
2038 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2039 |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2040 partial = opts.get(b'partial', False) |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2041 files = set() |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2042 try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2043 patch.patch( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2044 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2045 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2046 tmpname, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2047 strip=strip, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2048 prefix=prefix, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2049 files=files, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2050 eolmode=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2051 similarity=sim / 100.0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2052 ) |
48363
6a454e7053a1
errors: return more detailed errors when failing to parse or apply patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48247
diff
changeset
|
2053 except error.PatchParseError as e: |
48364
220506bb213e
patch: add hint about mangled whitespace on bad patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48363
diff
changeset
|
2054 raise error.InputError( |
220506bb213e
patch: add hint about mangled whitespace on bad patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48363
diff
changeset
|
2055 pycompat.bytestr(e), |
220506bb213e
patch: add hint about mangled whitespace on bad patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48363
diff
changeset
|
2056 hint=_( |
220506bb213e
patch: add hint about mangled whitespace on bad patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48363
diff
changeset
|
2057 b'check that whitespace in the patch has not been mangled' |
220506bb213e
patch: add hint about mangled whitespace on bad patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48363
diff
changeset
|
2058 ), |
220506bb213e
patch: add hint about mangled whitespace on bad patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48363
diff
changeset
|
2059 ) |
48363
6a454e7053a1
errors: return more detailed errors when failing to parse or apply patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48247
diff
changeset
|
2060 except error.PatchApplicationError as e: |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2061 if not partial: |
48363
6a454e7053a1
errors: return more detailed errors when failing to parse or apply patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48247
diff
changeset
|
2062 raise error.StateError(pycompat.bytestr(e)) |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2063 if partial: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2064 rejects = True |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2065 |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2066 files = list(files) |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2067 if nocommit: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2068 if message: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2069 msgs.append(message) |
20500
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
2070 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2071 if opts.get(b'exact') or p2: |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2072 # If you got here, you either use --force and know what |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2073 # you are doing or used --exact or a merge patch while |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2074 # being updated to its first parent. |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2075 m = None |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2076 else: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2077 m = scmutil.matchfiles(repo, files or []) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2078 editform = mergeeditform(repo[None], b'import.normal') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2079 if opts.get(b'exact'): |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2080 editor = None |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2081 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2082 editor = getcommiteditor( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2083 editform=editform, **pycompat.strkwargs(opts) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2084 ) |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2085 extra = {} |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2086 for idfunc in extrapreimport: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2087 extrapreimportmap[idfunc](repo, patchdata, extra, opts) |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2088 overrides = {} |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2089 if partial: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2090 overrides[(b'ui', b'allowemptycommit')] = True |
43725
71dbd6f6fcb8
import: add a --secret option
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
43712
diff
changeset
|
2091 if opts.get(b'secret'): |
71dbd6f6fcb8
import: add a --secret option
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
43712
diff
changeset
|
2092 overrides[(b'phases', b'new-commit')] = b'secret' |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2093 with repo.ui.configoverride(overrides, b'import'): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2094 n = repo.commit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2095 message, user, date, match=m, editor=editor, extra=extra |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2096 ) |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2097 for idfunc in extrapostimport: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2098 extrapostimportmap[idfunc](repo[n]) |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2099 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2100 if opts.get(b'exact') or importbranch: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2101 branch = branch or b'default' |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2102 else: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2103 branch = p1.branch() |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2104 store = patch.filestore() |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2105 try: |
20500
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
2106 files = set() |
21553
bee0e1cffdd3
import: add --partial flag to create a changeset despite failed hunks
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21419
diff
changeset
|
2107 try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2108 patch.patchrepo( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2109 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2110 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2111 p1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2112 store, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2113 tmpname, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2114 strip, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2115 prefix, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2116 files, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2117 eolmode=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2118 ) |
48363
6a454e7053a1
errors: return more detailed errors when failing to parse or apply patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48247
diff
changeset
|
2119 except error.PatchParseError as e: |
48364
220506bb213e
patch: add hint about mangled whitespace on bad patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48363
diff
changeset
|
2120 raise error.InputError( |
220506bb213e
patch: add hint about mangled whitespace on bad patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48363
diff
changeset
|
2121 stringutil.forcebytestr(e), |
220506bb213e
patch: add hint about mangled whitespace on bad patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48363
diff
changeset
|
2122 hint=_( |
220506bb213e
patch: add hint about mangled whitespace on bad patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48363
diff
changeset
|
2123 b'check that whitespace in the patch has not been mangled' |
220506bb213e
patch: add hint about mangled whitespace on bad patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48363
diff
changeset
|
2124 ), |
220506bb213e
patch: add hint about mangled whitespace on bad patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48363
diff
changeset
|
2125 ) |
48363
6a454e7053a1
errors: return more detailed errors when failing to parse or apply patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48247
diff
changeset
|
2126 except error.PatchApplicationError as e: |
6a454e7053a1
errors: return more detailed errors when failing to parse or apply patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48247
diff
changeset
|
2127 raise error.StateError(stringutil.forcebytestr(e)) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2128 if opts.get(b'exact'): |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2129 editor = None |
20500
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
2130 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2131 editor = getcommiteditor(editform=b'import.bypass') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2132 memctx = context.memctx( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2133 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2134 (p1.node(), p2.node()), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2135 message, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2136 files=files, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2137 filectxfn=store, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2138 user=user, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2139 date=date, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2140 branch=branch, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2141 editor=editor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2142 ) |
44330
b339faf3f843
import: don't ignore `--secret` when `--bypass` is specified
Matt Harbison <matt_harbison@yahoo.com>
parents:
44098
diff
changeset
|
2143 |
b339faf3f843
import: don't ignore `--secret` when `--bypass` is specified
Matt Harbison <matt_harbison@yahoo.com>
parents:
44098
diff
changeset
|
2144 overrides = {} |
b339faf3f843
import: don't ignore `--secret` when `--bypass` is specified
Matt Harbison <matt_harbison@yahoo.com>
parents:
44098
diff
changeset
|
2145 if opts.get(b'secret'): |
b339faf3f843
import: don't ignore `--secret` when `--bypass` is specified
Matt Harbison <matt_harbison@yahoo.com>
parents:
44098
diff
changeset
|
2146 overrides[(b'phases', b'new-commit')] = b'secret' |
b339faf3f843
import: don't ignore `--secret` when `--bypass` is specified
Matt Harbison <matt_harbison@yahoo.com>
parents:
44098
diff
changeset
|
2147 with repo.ui.configoverride(overrides, b'import'): |
b339faf3f843
import: don't ignore `--secret` when `--bypass` is specified
Matt Harbison <matt_harbison@yahoo.com>
parents:
44098
diff
changeset
|
2148 n = memctx.commit() |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2149 finally: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2150 store.close() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2151 if opts.get(b'exact') and nocommit: |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2152 # --exact with --no-commit is still useful in that it does merge |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2153 # and branch bits |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2154 ui.warn(_(b"warning: can't check exact import with --no-commit\n")) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2155 elif opts.get(b'exact') and (not n or hex(n) != nodeid): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2156 raise error.Abort(_(b'patch is damaged or loses information')) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2157 msg = _(b'applied to working directory') |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2158 if n: |
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2159 # i18n: refers to a short changeset id |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2160 msg = _(b'created %s') % short(n) |
37621
5537d8f5e989
patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37620
diff
changeset
|
2161 return msg, n, rejects |
20500
ce3f3082ec45
import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
20470
diff
changeset
|
2162 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2163 |
26545
e99c3846d78a
export: introduce a generic way to add patch header on export
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26533
diff
changeset
|
2164 # facility to let extensions include additional data in an exported patch |
e99c3846d78a
export: introduce a generic way to add patch header on export
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26533
diff
changeset
|
2165 # list of identifiers to be executed in order |
e99c3846d78a
export: introduce a generic way to add patch header on export
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26533
diff
changeset
|
2166 extraexport = [] |
e99c3846d78a
export: introduce a generic way to add patch header on export
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26533
diff
changeset
|
2167 # mapping from identifier to actual export function |
e99c3846d78a
export: introduce a generic way to add patch header on export
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26533
diff
changeset
|
2168 # function as to return a string to be added to the header or None |
e99c3846d78a
export: introduce a generic way to add patch header on export
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26533
diff
changeset
|
2169 # it is given two arguments (sequencenumber, changectx) |
e99c3846d78a
export: introduce a generic way to add patch header on export
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26533
diff
changeset
|
2170 extraexportmap = {} |
e99c3846d78a
export: introduce a generic way to add patch header on export
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26533
diff
changeset
|
2171 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2172 |
37602
52670eaa14b4
export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
37601
diff
changeset
|
2173 def _exportsingle(repo, ctx, fm, match, switch_parent, seqno, diffopts): |
32662
9d201b39ccd9
export: map wctx.node() to 'ff...' node id (issue5438)
Yuya Nishihara <yuya@tcha.org>
parents:
32658
diff
changeset
|
2174 node = scmutil.binnode(ctx) |
32433
7feaf5550a9e
cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents:
32432
diff
changeset
|
2175 parents = [p.node() for p in ctx.parents() if p] |
7feaf5550a9e
cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents:
32432
diff
changeset
|
2176 branch = ctx.branch() |
7feaf5550a9e
cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents:
32432
diff
changeset
|
2177 if switch_parent: |
7feaf5550a9e
cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents:
32432
diff
changeset
|
2178 parents.reverse() |
7feaf5550a9e
cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents:
32432
diff
changeset
|
2179 |
7feaf5550a9e
cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents:
32432
diff
changeset
|
2180 if parents: |
7feaf5550a9e
cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents:
32432
diff
changeset
|
2181 prev = parents[0] |
7feaf5550a9e
cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents:
32432
diff
changeset
|
2182 else: |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46969
diff
changeset
|
2183 prev = repo.nullid |
32433
7feaf5550a9e
cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents:
32432
diff
changeset
|
2184 |
37602
52670eaa14b4
export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
37601
diff
changeset
|
2185 fm.context(ctx=ctx) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2186 fm.plain(b'# HG changeset patch\n') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2187 fm.write(b'user', b'# User %s\n', ctx.user()) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2188 fm.plain(b'# Date %d %d\n' % ctx.date()) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2189 fm.write(b'date', b'# %s\n', fm.formatdate(ctx.date())) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2190 fm.condwrite( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2191 branch and branch != b'default', b'branch', b'# Branch %s\n', branch |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2192 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2193 fm.write(b'node', b'# Node ID %s\n', hex(node)) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2194 fm.plain(b'# Parent %s\n' % hex(prev)) |
32433
7feaf5550a9e
cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents:
32432
diff
changeset
|
2195 if len(parents) > 1: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2196 fm.plain(b'# Parent %s\n' % hex(parents[1])) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2197 fm.data(parents=fm.formatlist(pycompat.maplist(hex, parents), name=b'node')) |
37602
52670eaa14b4
export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
37601
diff
changeset
|
2198 |
52670eaa14b4
export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
37601
diff
changeset
|
2199 # TODO: redesign extraexportmap function to support formatter |
32433
7feaf5550a9e
cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents:
32432
diff
changeset
|
2200 for headerid in extraexport: |
7feaf5550a9e
cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents:
32432
diff
changeset
|
2201 header = extraexportmap[headerid](seqno, ctx) |
7feaf5550a9e
cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents:
32432
diff
changeset
|
2202 if header is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2203 fm.plain(b'# %s\n' % header) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2204 |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2205 fm.write(b'desc', b'%s\n', ctx.description().rstrip()) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2206 fm.plain(b'\n') |
37602
52670eaa14b4
export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
37601
diff
changeset
|
2207 |
52670eaa14b4
export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
37601
diff
changeset
|
2208 if fm.isplain(): |
52670eaa14b4
export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
37601
diff
changeset
|
2209 chunkiter = patch.diffui(repo, prev, node, match, opts=diffopts) |
52670eaa14b4
export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
37601
diff
changeset
|
2210 for chunk, label in chunkiter: |
52670eaa14b4
export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
37601
diff
changeset
|
2211 fm.plain(chunk, label=label) |
52670eaa14b4
export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
37601
diff
changeset
|
2212 else: |
52670eaa14b4
export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
37601
diff
changeset
|
2213 chunkiter = patch.diff(repo, prev, node, match, opts=diffopts) |
52670eaa14b4
export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
37601
diff
changeset
|
2214 # TODO: make it structured? |
52670eaa14b4
export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
37601
diff
changeset
|
2215 fm.data(diff=b''.join(chunkiter)) |
32433
7feaf5550a9e
cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents:
32432
diff
changeset
|
2216 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2217 |
37604
daafaff4e5be
export: enable formatter support (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37603
diff
changeset
|
2218 def _exportfile(repo, revs, fm, dest, switch_parent, diffopts, match): |
37600
7800ed2e4980
export: split cmdutil.export() to single-file and maybe-multiple-files cases
Yuya Nishihara <yuya@tcha.org>
parents:
37599
diff
changeset
|
2219 """Export changesets to stdout or a single file""" |
7800ed2e4980
export: split cmdutil.export() to single-file and maybe-multiple-files cases
Yuya Nishihara <yuya@tcha.org>
parents:
37599
diff
changeset
|
2220 for seqno, rev in enumerate(revs, 1): |
7800ed2e4980
export: split cmdutil.export() to single-file and maybe-multiple-files cases
Yuya Nishihara <yuya@tcha.org>
parents:
37599
diff
changeset
|
2221 ctx = repo[rev] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2222 if not dest.startswith(b'<'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2223 repo.ui.note(b"%s\n" % dest) |
37602
52670eaa14b4
export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
37601
diff
changeset
|
2224 fm.startitem() |
52670eaa14b4
export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
37601
diff
changeset
|
2225 _exportsingle(repo, ctx, fm, match, switch_parent, seqno, diffopts) |
37604
daafaff4e5be
export: enable formatter support (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37603
diff
changeset
|
2226 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2227 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2228 def _exportfntemplate( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2229 repo, revs, basefm, fntemplate, switch_parent, diffopts, match |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2230 ): |
37600
7800ed2e4980
export: split cmdutil.export() to single-file and maybe-multiple-files cases
Yuya Nishihara <yuya@tcha.org>
parents:
37599
diff
changeset
|
2231 """Export changesets to possibly multiple files""" |
7800ed2e4980
export: split cmdutil.export() to single-file and maybe-multiple-files cases
Yuya Nishihara <yuya@tcha.org>
parents:
37599
diff
changeset
|
2232 total = len(revs) |
7800ed2e4980
export: split cmdutil.export() to single-file and maybe-multiple-files cases
Yuya Nishihara <yuya@tcha.org>
parents:
37599
diff
changeset
|
2233 revwidth = max(len(str(rev)) for rev in revs) |
37601
2e0e61312a25
export: serialize revisions to be exported per destination file
Yuya Nishihara <yuya@tcha.org>
parents:
37600
diff
changeset
|
2234 filemap = util.sortdict() # filename: [(seqno, rev), ...] |
37600
7800ed2e4980
export: split cmdutil.export() to single-file and maybe-multiple-files cases
Yuya Nishihara <yuya@tcha.org>
parents:
37599
diff
changeset
|
2235 |
7800ed2e4980
export: split cmdutil.export() to single-file and maybe-multiple-files cases
Yuya Nishihara <yuya@tcha.org>
parents:
37599
diff
changeset
|
2236 for seqno, rev in enumerate(revs, 1): |
7800ed2e4980
export: split cmdutil.export() to single-file and maybe-multiple-files cases
Yuya Nishihara <yuya@tcha.org>
parents:
37599
diff
changeset
|
2237 ctx = repo[rev] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2238 dest = makefilename( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2239 ctx, fntemplate, total=total, seqno=seqno, revwidth=revwidth |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2240 ) |
37601
2e0e61312a25
export: serialize revisions to be exported per destination file
Yuya Nishihara <yuya@tcha.org>
parents:
37600
diff
changeset
|
2241 filemap.setdefault(dest, []).append((seqno, rev)) |
2e0e61312a25
export: serialize revisions to be exported per destination file
Yuya Nishihara <yuya@tcha.org>
parents:
37600
diff
changeset
|
2242 |
2e0e61312a25
export: serialize revisions to be exported per destination file
Yuya Nishihara <yuya@tcha.org>
parents:
37600
diff
changeset
|
2243 for dest in filemap: |
37604
daafaff4e5be
export: enable formatter support (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37603
diff
changeset
|
2244 with formatter.maybereopen(basefm, dest) as fm: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2245 repo.ui.note(b"%s\n" % dest) |
37601
2e0e61312a25
export: serialize revisions to be exported per destination file
Yuya Nishihara <yuya@tcha.org>
parents:
37600
diff
changeset
|
2246 for seqno, rev in filemap[dest]: |
37602
52670eaa14b4
export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
37601
diff
changeset
|
2247 fm.startitem() |
37601
2e0e61312a25
export: serialize revisions to be exported per destination file
Yuya Nishihara <yuya@tcha.org>
parents:
37600
diff
changeset
|
2248 ctx = repo[rev] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2249 _exportsingle( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2250 repo, ctx, fm, match, switch_parent, seqno, diffopts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2251 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2252 |
37600
7800ed2e4980
export: split cmdutil.export() to single-file and maybe-multiple-files cases
Yuya Nishihara <yuya@tcha.org>
parents:
37599
diff
changeset
|
2253 |
42473
307f67d4aee3
export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
42399
diff
changeset
|
2254 def _prefetchchangedfiles(repo, revs, match): |
307f67d4aee3
export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
42399
diff
changeset
|
2255 allfiles = set() |
307f67d4aee3
export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
42399
diff
changeset
|
2256 for rev in revs: |
307f67d4aee3
export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
42399
diff
changeset
|
2257 for file in repo[rev].files(): |
307f67d4aee3
export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
42399
diff
changeset
|
2258 if not match or match(file): |
307f67d4aee3
export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
42399
diff
changeset
|
2259 allfiles.add(file) |
45072
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
45037
diff
changeset
|
2260 match = scmutil.matchfiles(repo, allfiles) |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
45037
diff
changeset
|
2261 revmatches = [(rev, match) for rev in revs] |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
45037
diff
changeset
|
2262 scmutil.prefetchfiles(repo, revmatches) |
42473
307f67d4aee3
export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
42399
diff
changeset
|
2263 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2264 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2265 def export( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2266 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2267 revs, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2268 basefm, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2269 fntemplate=b'hg-%h.patch', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2270 switch_parent=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2271 opts=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2272 match=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2273 ): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
2274 """export changesets as hg patches |
32430
1f4be037f558
cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents:
32382
diff
changeset
|
2275 |
1f4be037f558
cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents:
32382
diff
changeset
|
2276 Args: |
1f4be037f558
cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents:
32382
diff
changeset
|
2277 repo: The repository from which we're exporting revisions. |
1f4be037f558
cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents:
32382
diff
changeset
|
2278 revs: A list of revisions to export as revision numbers. |
37604
daafaff4e5be
export: enable formatter support (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37603
diff
changeset
|
2279 basefm: A formatter to which patches should be written. |
32431
9fd9f91b0c43
cmdutil: rename template param to export to fntemplate
Augie Fackler <augie@google.com>
parents:
32430
diff
changeset
|
2280 fntemplate: An optional string to use for generating patch file names. |
32430
1f4be037f558
cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents:
32382
diff
changeset
|
2281 switch_parent: If True, show diffs against second parent when not nullid. |
1f4be037f558
cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents:
32382
diff
changeset
|
2282 Default is false, which always shows diff against p1. |
1f4be037f558
cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents:
32382
diff
changeset
|
2283 opts: diff options to use for generating the patch. |
1f4be037f558
cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents:
32382
diff
changeset
|
2284 match: If specified, only export changes to files matching this matcher. |
1f4be037f558
cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents:
32382
diff
changeset
|
2285 |
1f4be037f558
cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents:
32382
diff
changeset
|
2286 Returns: |
1f4be037f558
cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents:
32382
diff
changeset
|
2287 Nothing. |
1f4be037f558
cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents:
32382
diff
changeset
|
2288 |
1f4be037f558
cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents:
32382
diff
changeset
|
2289 Side Effect: |
1f4be037f558
cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents:
32382
diff
changeset
|
2290 "HG Changeset Patch" data is emitted to one of the following |
1f4be037f558
cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents:
32382
diff
changeset
|
2291 destinations: |
32431
9fd9f91b0c43
cmdutil: rename template param to export to fntemplate
Augie Fackler <augie@google.com>
parents:
32430
diff
changeset
|
2292 fntemplate specified: Each rev is written to a unique file named using |
32430
1f4be037f558
cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents:
32382
diff
changeset
|
2293 the given template. |
37604
daafaff4e5be
export: enable formatter support (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37603
diff
changeset
|
2294 Otherwise: All revs will be written to basefm. |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
2295 """ |
42473
307f67d4aee3
export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
42399
diff
changeset
|
2296 _prefetchchangedfiles(repo, revs, match) |
37763
b54404d66f7e
export: invoke the file prefetch hook
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
2297 |
37603
678d760c71ff
export: extract function to write patch to file object (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37602
diff
changeset
|
2298 if not fntemplate: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2299 _exportfile( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2300 repo, revs, basefm, b'<unnamed>', switch_parent, opts, match |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2301 ) |
37600
7800ed2e4980
export: split cmdutil.export() to single-file and maybe-multiple-files cases
Yuya Nishihara <yuya@tcha.org>
parents:
37599
diff
changeset
|
2302 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2303 _exportfntemplate( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2304 repo, revs, basefm, fntemplate, switch_parent, opts, match |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2305 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2306 |
10611
e764f24a45ee
patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10608
diff
changeset
|
2307 |
37603
678d760c71ff
export: extract function to write patch to file object (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37602
diff
changeset
|
2308 def exportfile(repo, revs, fp, switch_parent=False, opts=None, match=None): |
678d760c71ff
export: extract function to write patch to file object (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37602
diff
changeset
|
2309 """Export changesets to the given file stream""" |
42473
307f67d4aee3
export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents:
42399
diff
changeset
|
2310 _prefetchchangedfiles(repo, revs, match) |
37763
b54404d66f7e
export: invoke the file prefetch hook
Matt Harbison <matt_harbison@yahoo.com>
parents:
37762
diff
changeset
|
2311 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2312 dest = getattr(fp, 'name', b'<unnamed>') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2313 with formatter.formatter(repo.ui, fp, b'export', {}) as fm: |
37604
daafaff4e5be
export: enable formatter support (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37603
diff
changeset
|
2314 _exportfile(repo, revs, fm, dest, switch_parent, opts, match) |
37603
678d760c71ff
export: extract function to write patch to file object (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37602
diff
changeset
|
2315 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2316 |
29795
142ae01820a3
debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents:
29758
diff
changeset
|
2317 def showmarker(fm, marker, index=None): |
20470
78f4c2b7052f
debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20392
diff
changeset
|
2318 """utility function to display obsolescence marker in a readable way |
78f4c2b7052f
debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20392
diff
changeset
|
2319 |
78f4c2b7052f
debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20392
diff
changeset
|
2320 To be used by debug function.""" |
28613
6433da9c96a9
debugobsolete: add an option to show marker index
Kostia Balytskyi <ikostia@fb.com>
parents:
28608
diff
changeset
|
2321 if index is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2322 fm.write(b'index', b'%i ', index) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2323 fm.write(b'prednode', b'%s ', hex(marker.prednode())) |
29795
142ae01820a3
debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents:
29758
diff
changeset
|
2324 succs = marker.succnodes() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2325 fm.condwrite( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2326 succs, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2327 b'succnodes', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2328 b'%s ', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2329 fm.formatlist(map(hex, succs), name=b'node'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2330 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2331 fm.write(b'flag', b'%X ', marker.flags()) |
22260
2229d757802d
debugobsolete: display parents information from markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22250
diff
changeset
|
2332 parents = marker.parentnodes() |
2229d757802d
debugobsolete: display parents information from markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22250
diff
changeset
|
2333 if parents is not None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2334 fm.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2335 b'parentnodes', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2336 b'{%s} ', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2337 fm.formatlist(map(hex, parents), name=b'node', sep=b', '), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2338 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2339 fm.write(b'date', b'(%s) ', fm.formatdate(marker.date())) |
29795
142ae01820a3
debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents:
29758
diff
changeset
|
2340 meta = marker.metadata().copy() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2341 meta.pop(b'date', None) |
38575
152f4822d210
pycompat: move rapply() from util
Yuya Nishihara <yuya@tcha.org>
parents:
38542
diff
changeset
|
2342 smeta = pycompat.rapply(pycompat.maybebytestr, meta) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2343 fm.write( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2344 b'metadata', b'{%s}', fm.formatdict(smeta, fmt=b'%r: %r', sep=b', ') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2345 ) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2346 fm.plain(b'\n') |
20470
78f4c2b7052f
debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
20392
diff
changeset
|
2347 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2348 |
3814
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
2349 def finddate(ui, repo, date): |
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
2350 """Find the tipmost changeset that matches the given date spec""" |
45457
d2b5a7659fff
cmdutil: reimplement finddate() without using walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents:
45388
diff
changeset
|
2351 mrevs = repo.revs(b'date(%s)', date) |
d2b5a7659fff
cmdutil: reimplement finddate() without using walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents:
45388
diff
changeset
|
2352 try: |
d2b5a7659fff
cmdutil: reimplement finddate() without using walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents:
45388
diff
changeset
|
2353 rev = mrevs.max() |
d2b5a7659fff
cmdutil: reimplement finddate() without using walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents:
45388
diff
changeset
|
2354 except ValueError: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
2355 raise error.InputError(_(b"revision matching date not found")) |
45457
d2b5a7659fff
cmdutil: reimplement finddate() without using walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents:
45388
diff
changeset
|
2356 |
d2b5a7659fff
cmdutil: reimplement finddate() without using walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents:
45388
diff
changeset
|
2357 ui.status( |
d2b5a7659fff
cmdutil: reimplement finddate() without using walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents:
45388
diff
changeset
|
2358 _(b"found revision %d from %s\n") |
d2b5a7659fff
cmdutil: reimplement finddate() without using walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents:
45388
diff
changeset
|
2359 % (rev, dateutil.datestr(repo[rev].date())) |
d2b5a7659fff
cmdutil: reimplement finddate() without using walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents:
45388
diff
changeset
|
2360 ) |
d2b5a7659fff
cmdutil: reimplement finddate() without using walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents:
45388
diff
changeset
|
2361 return b'%d' % rev |
3814
120be84f33de
Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents:
3738
diff
changeset
|
2362 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2363 |
41650
f8b18583049f
add: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41649
diff
changeset
|
2364 def add(ui, repo, match, prefix, uipathfn, explicitonly, **opts): |
12269
877236cdd437
add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents:
12266
diff
changeset
|
2365 bad = [] |
25436
9724cbe2d546
add: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25424
diff
changeset
|
2366 |
9724cbe2d546
add: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25424
diff
changeset
|
2367 badfn = lambda x, y: bad.append(x) or match.bad(x, y) |
12269
877236cdd437
add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents:
12266
diff
changeset
|
2368 names = [] |
12270
166b9866580a
add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12269
diff
changeset
|
2369 wctx = repo[None] |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14129
diff
changeset
|
2370 cca = None |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14129
diff
changeset
|
2371 abort, warn = scmutil.checkportabilityalert(ui) |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14129
diff
changeset
|
2372 if abort or warn: |
17201
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17182
diff
changeset
|
2373 cca = scmutil.casecollisionauditor(ui, abort, repo.dirstate) |
25436
9724cbe2d546
add: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25424
diff
changeset
|
2374 |
40087
1d09ba0d2ed3
narrow: move remaining narrow-limited dirstate walks to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
40029
diff
changeset
|
2375 match = repo.narrowmatch(match, includeexact=True) |
26206
ab1c6e4efda4
add: pass full=False to dirstate walk
Durham Goode <durham@fb.com>
parents:
26098
diff
changeset
|
2376 badmatch = matchmod.badmatch(match, badfn) |
ab1c6e4efda4
add: pass full=False to dirstate walk
Durham Goode <durham@fb.com>
parents:
26098
diff
changeset
|
2377 dirstate = repo.dirstate |
ab1c6e4efda4
add: pass full=False to dirstate walk
Durham Goode <durham@fb.com>
parents:
26098
diff
changeset
|
2378 # We don't want to just call wctx.walk here, since it would return a lot of |
ab1c6e4efda4
add: pass full=False to dirstate walk
Durham Goode <durham@fb.com>
parents:
26098
diff
changeset
|
2379 # clean files, which we aren't interested in and takes time. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2380 for f in sorted( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2381 dirstate.walk( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2382 badmatch, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2383 subrepos=sorted(wctx.substate), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2384 unknown=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2385 ignored=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2386 full=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2387 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2388 ): |
51163
b8f9911c8dca
add: don't attempt to add back removed files unless explicitly listed
Martin von Zweigbergk <martinvonz@google.com>
parents:
50929
diff
changeset
|
2389 entry = dirstate.get_entry(f) |
b8f9911c8dca
add: don't attempt to add back removed files unless explicitly listed
Martin von Zweigbergk <martinvonz@google.com>
parents:
50929
diff
changeset
|
2390 # We don't want to even attmpt to add back files that have been removed |
b8f9911c8dca
add: don't attempt to add back removed files unless explicitly listed
Martin von Zweigbergk <martinvonz@google.com>
parents:
50929
diff
changeset
|
2391 # It would lead to a misleading message saying we're adding the path, |
b8f9911c8dca
add: don't attempt to add back removed files unless explicitly listed
Martin von Zweigbergk <martinvonz@google.com>
parents:
50929
diff
changeset
|
2392 # and can also lead to file/dir conflicts when attempting to add it. |
b8f9911c8dca
add: don't attempt to add back removed files unless explicitly listed
Martin von Zweigbergk <martinvonz@google.com>
parents:
50929
diff
changeset
|
2393 removed = entry and entry.removed |
12269
877236cdd437
add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents:
12266
diff
changeset
|
2394 exact = match.exact(f) |
51163
b8f9911c8dca
add: don't attempt to add back removed files unless explicitly listed
Martin von Zweigbergk <martinvonz@google.com>
parents:
50929
diff
changeset
|
2395 if ( |
b8f9911c8dca
add: don't attempt to add back removed files unless explicitly listed
Martin von Zweigbergk <martinvonz@google.com>
parents:
50929
diff
changeset
|
2396 exact |
b8f9911c8dca
add: don't attempt to add back removed files unless explicitly listed
Martin von Zweigbergk <martinvonz@google.com>
parents:
50929
diff
changeset
|
2397 or not explicitonly |
b8f9911c8dca
add: don't attempt to add back removed files unless explicitly listed
Martin von Zweigbergk <martinvonz@google.com>
parents:
50929
diff
changeset
|
2398 and f not in wctx |
b8f9911c8dca
add: don't attempt to add back removed files unless explicitly listed
Martin von Zweigbergk <martinvonz@google.com>
parents:
50929
diff
changeset
|
2399 and repo.wvfs.lexists(f) |
b8f9911c8dca
add: don't attempt to add back removed files unless explicitly listed
Martin von Zweigbergk <martinvonz@google.com>
parents:
50929
diff
changeset
|
2400 and not removed |
b8f9911c8dca
add: don't attempt to add back removed files unless explicitly listed
Martin von Zweigbergk <martinvonz@google.com>
parents:
50929
diff
changeset
|
2401 ): |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14129
diff
changeset
|
2402 if cca: |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14129
diff
changeset
|
2403 cca(f) |
12269
877236cdd437
add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents:
12266
diff
changeset
|
2404 names.append(f) |
877236cdd437
add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents:
12266
diff
changeset
|
2405 if ui.verbose or not exact: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2406 ui.status( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2407 _(b'adding %s\n') % uipathfn(f), label=b'ui.addremove.added' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2408 ) |
12270
166b9866580a
add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12269
diff
changeset
|
2409 |
18364
6252b4f1c4b4
subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents:
18340
diff
changeset
|
2410 for subpath in sorted(wctx.substate): |
15410
9e99d2bbb1b1
add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents:
15231
diff
changeset
|
2411 sub = wctx.sub(subpath) |
9e99d2bbb1b1
add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents:
15231
diff
changeset
|
2412 try: |
28017
d3f1b7ee5e70
match: rename "narrowmatcher" to "subdirmatcher" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
27985
diff
changeset
|
2413 submatch = matchmod.subdirmatcher(subpath, match) |
41628
ed046348675c
subrepo: adjust subrepo prefix before calling subrepo.add() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41627
diff
changeset
|
2414 subprefix = repo.wvfs.reljoin(prefix, subpath) |
41650
f8b18583049f
add: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41649
diff
changeset
|
2415 subuipathfn = scmutil.subdiruipathfn(subpath, uipathfn) |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43491
diff
changeset
|
2416 if opts.get('subrepos'): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2417 bad.extend( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2418 sub.add(ui, submatch, subprefix, subuipathfn, False, **opts) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2419 ) |
15410
9e99d2bbb1b1
add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents:
15231
diff
changeset
|
2420 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2421 bad.extend( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2422 sub.add(ui, submatch, subprefix, subuipathfn, True, **opts) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2423 ) |
15410
9e99d2bbb1b1
add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents:
15231
diff
changeset
|
2424 except error.LookupError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2425 ui.status( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2426 _(b"skipping missing subrepository: %s\n") % uipathfn(subpath) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2427 ) |
12270
166b9866580a
add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12269
diff
changeset
|
2428 |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43491
diff
changeset
|
2429 if not opts.get('dry_run'): |
12270
166b9866580a
add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12269
diff
changeset
|
2430 rejected = wctx.add(names, prefix) |
12269
877236cdd437
add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents:
12266
diff
changeset
|
2431 bad.extend(f for f in rejected if f in match.files()) |
877236cdd437
add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents:
12266
diff
changeset
|
2432 return bad |
877236cdd437
add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents:
12266
diff
changeset
|
2433 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2434 |
32005
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31807
diff
changeset
|
2435 def addwebdirpath(repo, serverpath, webconf): |
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31807
diff
changeset
|
2436 webconf[serverpath] = repo.root |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2437 repo.ui.debug(b'adding %s = %s\n' % (serverpath, repo.root)) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2438 |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2439 for r in repo.revs(b'filelog("path:.hgsub")'): |
32005
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31807
diff
changeset
|
2440 ctx = repo[r] |
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31807
diff
changeset
|
2441 for subpath in ctx.substate: |
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31807
diff
changeset
|
2442 ctx.sub(subpath).addwebdirpath(serverpath, webconf) |
2406dbba49bd
serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents:
31807
diff
changeset
|
2443 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2444 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2445 def forget( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2446 ui, repo, match, prefix, uipathfn, explicitonly, dryrun, interactive |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2447 ): |
37778
f10cb49951e1
forget: rename --confirm to --interactive
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37774
diff
changeset
|
2448 if dryrun and interactive: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
2449 raise error.InputError( |
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
2450 _(b"cannot specify both --dry-run and --interactive") |
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
2451 ) |
15912
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2452 bad = [] |
25437
9c1bcd95b3ff
forget: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25436
diff
changeset
|
2453 badfn = lambda x, y: bad.append(x) or match.bad(x, y) |
15912
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2454 wctx = repo[None] |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2455 forgot = [] |
25437
9c1bcd95b3ff
forget: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25436
diff
changeset
|
2456 |
9c1bcd95b3ff
forget: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25436
diff
changeset
|
2457 s = repo.status(match=matchmod.badmatch(match, badfn), clean=True) |
32174
e4a4ebfd9d8e
forget: access status fields by name, not index
Martin von Zweigbergk <martinvonz@google.com>
parents:
32155
diff
changeset
|
2458 forget = sorted(s.modified + s.added + s.deleted + s.clean) |
15912
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2459 if explicitonly: |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2460 forget = [f for f in forget if match.exact(f)] |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2461 |
18364
6252b4f1c4b4
subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents:
18340
diff
changeset
|
2462 for subpath in sorted(wctx.substate): |
15912
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2463 sub = wctx.sub(subpath) |
41627
f92844cb942c
subrepo: adjust subrepo prefix before calling subrepo.forget() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41626
diff
changeset
|
2464 submatch = matchmod.subdirmatcher(subpath, match) |
f92844cb942c
subrepo: adjust subrepo prefix before calling subrepo.forget() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41626
diff
changeset
|
2465 subprefix = repo.wvfs.reljoin(prefix, subpath) |
41653
16a49c778bde
forget: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41652
diff
changeset
|
2466 subuipathfn = scmutil.subdiruipathfn(subpath, uipathfn) |
15912
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2467 try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2468 subbad, subforgot = sub.forget( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2469 submatch, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2470 subprefix, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2471 subuipathfn, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2472 dryrun=dryrun, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2473 interactive=interactive, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2474 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2475 bad.extend([subpath + b'/' + f for f in subbad]) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2476 forgot.extend([subpath + b'/' + f for f in subforgot]) |
15912
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2477 except error.LookupError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2478 ui.status( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2479 _(b"skipping missing subrepository: %s\n") % uipathfn(subpath) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2480 ) |
15912
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2481 |
16070
f11eee00c652
forget: show warning messages for forgetting in subrepo correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15912
diff
changeset
|
2482 if not explicitonly: |
f11eee00c652
forget: show warning messages for forgetting in subrepo correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15912
diff
changeset
|
2483 for f in match.files(): |
23673
69cd91d04117
forget: use vfs instead of os.path + match.rel() for filesystem checks
Matt Harbison <matt_harbison@yahoo.com>
parents:
23579
diff
changeset
|
2484 if f not in repo.dirstate and not repo.wvfs.isdir(f): |
15912
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2485 if f not in forgot: |
23673
69cd91d04117
forget: use vfs instead of os.path + match.rel() for filesystem checks
Matt Harbison <matt_harbison@yahoo.com>
parents:
23579
diff
changeset
|
2486 if repo.wvfs.exists(f): |
24548
c780a63f61ca
forget: cleanup the output for an inexact case match on icasefs
Matt Harbison <matt_harbison@yahoo.com>
parents:
24169
diff
changeset
|
2487 # Don't complain if the exact case match wasn't given. |
c780a63f61ca
forget: cleanup the output for an inexact case match on icasefs
Matt Harbison <matt_harbison@yahoo.com>
parents:
24169
diff
changeset
|
2488 # But don't do this until after checking 'forgot', so |
c780a63f61ca
forget: cleanup the output for an inexact case match on icasefs
Matt Harbison <matt_harbison@yahoo.com>
parents:
24169
diff
changeset
|
2489 # that subrepo files aren't normalized, and this op is |
c780a63f61ca
forget: cleanup the output for an inexact case match on icasefs
Matt Harbison <matt_harbison@yahoo.com>
parents:
24169
diff
changeset
|
2490 # purely from data cached by the status walk above. |
c780a63f61ca
forget: cleanup the output for an inexact case match on icasefs
Matt Harbison <matt_harbison@yahoo.com>
parents:
24169
diff
changeset
|
2491 if repo.dirstate.normalize(f) in repo.dirstate: |
c780a63f61ca
forget: cleanup the output for an inexact case match on icasefs
Matt Harbison <matt_harbison@yahoo.com>
parents:
24169
diff
changeset
|
2492 continue |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2493 ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2494 _( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2495 b'not removing %s: ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2496 b'file is already untracked\n' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2497 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2498 % uipathfn(f) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2499 ) |
15912
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2500 bad.append(f) |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2501 |
37778
f10cb49951e1
forget: rename --confirm to --interactive
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37774
diff
changeset
|
2502 if interactive: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2503 responses = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2504 b'[Ynsa?]' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2505 b'$$ &Yes, forget this file' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2506 b'$$ &No, skip this file' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2507 b'$$ &Skip remaining files' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2508 b'$$ Include &all remaining files' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2509 b'$$ &? (display help)' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2510 ) |
37756
e7bf5a73e4e1
forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37621
diff
changeset
|
2511 for filename in forget[:]: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2512 r = ui.promptchoice( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2513 _(b'forget %s %s') % (uipathfn(filename), responses) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2514 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2515 if r == 4: # ? |
37756
e7bf5a73e4e1
forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37621
diff
changeset
|
2516 while r == 4: |
e7bf5a73e4e1
forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37621
diff
changeset
|
2517 for c, t in ui.extractchoices(responses)[1]: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2518 ui.write(b'%s - %s\n' % (c, encoding.lower(t))) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2519 r = ui.promptchoice( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2520 _(b'forget %s %s') % (uipathfn(filename), responses) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2521 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2522 if r == 0: # yes |
37756
e7bf5a73e4e1
forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37621
diff
changeset
|
2523 continue |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2524 elif r == 1: # no |
37756
e7bf5a73e4e1
forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37621
diff
changeset
|
2525 forget.remove(filename) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2526 elif r == 2: # Skip |
37756
e7bf5a73e4e1
forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37621
diff
changeset
|
2527 fnindex = forget.index(filename) |
e7bf5a73e4e1
forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37621
diff
changeset
|
2528 del forget[fnindex:] |
e7bf5a73e4e1
forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37621
diff
changeset
|
2529 break |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2530 elif r == 3: # All |
37756
e7bf5a73e4e1
forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37621
diff
changeset
|
2531 break |
e7bf5a73e4e1
forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37621
diff
changeset
|
2532 |
15912
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2533 for f in forget: |
37778
f10cb49951e1
forget: rename --confirm to --interactive
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37774
diff
changeset
|
2534 if ui.verbose or not match.exact(f) or interactive: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2535 ui.status( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2536 _(b'removing %s\n') % uipathfn(f), label=b'ui.addremove.removed' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2537 ) |
15912
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2538 |
36939
45bfcd16f27e
forget: add --dry-run mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
36719
diff
changeset
|
2539 if not dryrun: |
45bfcd16f27e
forget: add --dry-run mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
36719
diff
changeset
|
2540 rejected = wctx.forget(forget, prefix) |
45bfcd16f27e
forget: add --dry-run mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
36719
diff
changeset
|
2541 bad.extend(f for f in rejected if f in match.files()) |
45bfcd16f27e
forget: add --dry-run mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
36719
diff
changeset
|
2542 forgot.extend(f for f in forget if f not in rejected) |
15912
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2543 return bad, forgot |
2bd54ffaa27e
forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents:
15911
diff
changeset
|
2544 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2545 |
41748
980e05204ed8
subrepo: use root-repo-relative path from `hg files` with ui.relative-paths=no
Martin von Zweigbergk <martinvonz@google.com>
parents:
41685
diff
changeset
|
2546 def files(ui, ctx, m, uipathfn, fm, fmt, subrepos): |
24275
e1cb460a3524
files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents:
24272
diff
changeset
|
2547 ret = 1 |
e1cb460a3524
files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents:
24272
diff
changeset
|
2548 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2549 needsfctx = ui.verbose or {b'size', b'flags'} & fm.datahint() |
44861
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2550 if fm.isplain() and not needsfctx: |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2551 # Fast path. The speed-up comes from skipping the formatter, and batching |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2552 # calls to ui.write. |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2553 buf = [] |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2554 for f in ctx.matches(m): |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2555 buf.append(fmt % uipathfn(f)) |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2556 if len(buf) > 100: |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2557 ui.write(b''.join(buf)) |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2558 del buf[:] |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2559 ret = 0 |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2560 if buf: |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2561 ui.write(b''.join(buf)) |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2562 else: |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2563 for f in ctx.matches(m): |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2564 fm.startitem() |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2565 fm.context(ctx=ctx) |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2566 if needsfctx: |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2567 fc = ctx[f] |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2568 fm.write(b'size flags', b'% 10d % 1s ', fc.size(), fc.flags()) |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2569 fm.data(path=f) |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2570 fm.plain(fmt % uipathfn(f)) |
065421e12248
files: speed up `hg files` when no flags change display
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44856
diff
changeset
|
2571 ret = 0 |
24275
e1cb460a3524
files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents:
24272
diff
changeset
|
2572 |
25228
63a57a2727b6
files: recurse into subrepos automatically with an explicit path
Matt Harbison <matt_harbison@yahoo.com>
parents:
25169
diff
changeset
|
2573 for subpath in sorted(ctx.substate): |
29802
35560189677c
subrepo: cleanup of subrepo filematcher logic
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29795
diff
changeset
|
2574 submatch = matchmod.subdirmatcher(subpath, m) |
41748
980e05204ed8
subrepo: use root-repo-relative path from `hg files` with ui.relative-paths=no
Martin von Zweigbergk <martinvonz@google.com>
parents:
41685
diff
changeset
|
2575 subuipathfn = scmutil.subdiruipathfn(subpath, uipathfn) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2576 if subrepos or m.exact(subpath) or any(submatch.files()): |
24413
a8595176dd64
subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents:
24391
diff
changeset
|
2577 sub = ctx.sub(subpath) |
a8595176dd64
subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents:
24391
diff
changeset
|
2578 try: |
28387
97175d9bf7cf
files: don't recurse into subrepos without a path or -S (issue5127)
Matt Harbison <matt_harbison@yahoo.com>
parents:
28253
diff
changeset
|
2579 recurse = m.exact(subpath) or subrepos |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2580 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2581 sub.printfiles(ui, submatch, subuipathfn, fm, fmt, recurse) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2582 == 0 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2583 ): |
24413
a8595176dd64
subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents:
24391
diff
changeset
|
2584 ret = 0 |
a8595176dd64
subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents:
24391
diff
changeset
|
2585 except error.LookupError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2586 ui.status( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2587 _(b"skipping missing subrepository: %s\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2588 % uipathfn(subpath) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2589 ) |
24413
a8595176dd64
subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents:
24391
diff
changeset
|
2590 |
24275
e1cb460a3524
files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents:
24272
diff
changeset
|
2591 return ret |
e1cb460a3524
files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents:
24272
diff
changeset
|
2592 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2593 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2594 def remove( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2595 ui, repo, m, prefix, uipathfn, after, force, subrepos, dryrun, warnings=None |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2596 ): |
23289
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2597 ret = 0 |
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2598 s = repo.status(match=m, clean=True) |
43644
e01e0641f18a
cmdutil: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents:
43523
diff
changeset
|
2599 modified, added, deleted, clean = s.modified, s.added, s.deleted, s.clean |
23289
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2600 |
23325
4165cfd67519
remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents:
23289
diff
changeset
|
2601 wctx = repo[None] |
4165cfd67519
remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents:
23289
diff
changeset
|
2602 |
28607
a88959ae5938
remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents:
28601
diff
changeset
|
2603 if warnings is None: |
a88959ae5938
remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents:
28601
diff
changeset
|
2604 warnings = [] |
a88959ae5938
remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents:
28601
diff
changeset
|
2605 warn = True |
a88959ae5938
remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents:
28601
diff
changeset
|
2606 else: |
a88959ae5938
remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents:
28601
diff
changeset
|
2607 warn = False |
a88959ae5938
remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents:
28601
diff
changeset
|
2608 |
28608
62e73d42bd14
remove: add progress support
timeless <timeless@mozdev.org>
parents:
28607
diff
changeset
|
2609 subs = sorted(wctx.substate) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2610 progress = ui.makeprogress( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2611 _(b'searching'), total=len(subs), unit=_(b'subrepos') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2612 ) |
28608
62e73d42bd14
remove: add progress support
timeless <timeless@mozdev.org>
parents:
28607
diff
changeset
|
2613 for subpath in subs: |
29802
35560189677c
subrepo: cleanup of subrepo filematcher logic
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29795
diff
changeset
|
2614 submatch = matchmod.subdirmatcher(subpath, m) |
41626
2c549abc6b85
subrepo: adjust subrepo prefix before calling subrepo.removefiles() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41625
diff
changeset
|
2615 subprefix = repo.wvfs.reljoin(prefix, subpath) |
41651
b2df5dc3ebfb
remove: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41650
diff
changeset
|
2616 subuipathfn = scmutil.subdiruipathfn(subpath, uipathfn) |
29802
35560189677c
subrepo: cleanup of subrepo filematcher logic
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29795
diff
changeset
|
2617 if subrepos or m.exact(subpath) or any(submatch.files()): |
38347
89db59e5cf3e
remove: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38342
diff
changeset
|
2618 progress.increment() |
23325
4165cfd67519
remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents:
23289
diff
changeset
|
2619 sub = wctx.sub(subpath) |
4165cfd67519
remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents:
23289
diff
changeset
|
2620 try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2621 if sub.removefiles( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2622 submatch, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2623 subprefix, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2624 subuipathfn, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2625 after, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2626 force, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2627 subrepos, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2628 dryrun, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2629 warnings, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2630 ): |
23325
4165cfd67519
remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents:
23289
diff
changeset
|
2631 ret = 1 |
4165cfd67519
remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents:
23289
diff
changeset
|
2632 except error.LookupError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2633 warnings.append( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2634 _(b"skipping missing subrepository: %s\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2635 % uipathfn(subpath) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2636 ) |
38373
ef692614e601
progress: hide update(None) in a new complete() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
38347
diff
changeset
|
2637 progress.complete() |
23325
4165cfd67519
remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents:
23289
diff
changeset
|
2638 |
23289
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2639 # warn about failure to delete explicit files/dirs |
43523
c21aca51b392
utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43506
diff
changeset
|
2640 deleteddirs = pathutil.dirs(deleted) |
28608
62e73d42bd14
remove: add progress support
timeless <timeless@mozdev.org>
parents:
28607
diff
changeset
|
2641 files = m.files() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2642 progress = ui.makeprogress( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2643 _(b'deleting'), total=len(files), unit=_(b'files') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2644 ) |
28608
62e73d42bd14
remove: add progress support
timeless <timeless@mozdev.org>
parents:
28607
diff
changeset
|
2645 for f in files: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2646 |
23325
4165cfd67519
remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents:
23289
diff
changeset
|
2647 def insubrepo(): |
4165cfd67519
remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents:
23289
diff
changeset
|
2648 for subpath in wctx.substate: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2649 if f.startswith(subpath + b'/'): |
23325
4165cfd67519
remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents:
23289
diff
changeset
|
2650 return True |
4165cfd67519
remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents:
23289
diff
changeset
|
2651 return False |
4165cfd67519
remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents:
23289
diff
changeset
|
2652 |
38347
89db59e5cf3e
remove: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38342
diff
changeset
|
2653 progress.increment() |
24955
1df233bcb7f6
remove: use ctx.hasdir(f) instead of 'f in ctx.dirs()'
Martin von Zweigbergk <martinvonz@google.com>
parents:
24947
diff
changeset
|
2654 isdir = f in deleteddirs or wctx.hasdir(f) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2655 if f in repo.dirstate or isdir or f == b'.' or insubrepo() or f in subs: |
23289
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2656 continue |
23325
4165cfd67519
remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents:
23289
diff
changeset
|
2657 |
23674
6e36b9fc7869
remove: use vfs instead of os.path + match.rel() for filesystem checks
Matt Harbison <matt_harbison@yahoo.com>
parents:
23673
diff
changeset
|
2658 if repo.wvfs.exists(f): |
6e36b9fc7869
remove: use vfs instead of os.path + match.rel() for filesystem checks
Matt Harbison <matt_harbison@yahoo.com>
parents:
23673
diff
changeset
|
2659 if repo.wvfs.isdir(f): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2660 warnings.append( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2661 _(b'not removing %s: no tracked files\n') % uipathfn(f) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2662 ) |
23289
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2663 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2664 warnings.append( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2665 _(b'not removing %s: file is untracked\n') % uipathfn(f) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2666 ) |
23289
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2667 # missing files will generate a warning elsewhere |
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2668 ret = 1 |
38373
ef692614e601
progress: hide update(None) in a new complete() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
38347
diff
changeset
|
2669 progress.complete() |
23289
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2670 |
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2671 if force: |
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2672 list = modified + deleted + clean + added |
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2673 elif after: |
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2674 list = deleted |
28608
62e73d42bd14
remove: add progress support
timeless <timeless@mozdev.org>
parents:
28607
diff
changeset
|
2675 remaining = modified + added + clean |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2676 progress = ui.makeprogress( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2677 _(b'skipping'), total=len(remaining), unit=_(b'files') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2678 ) |
28608
62e73d42bd14
remove: add progress support
timeless <timeless@mozdev.org>
parents:
28607
diff
changeset
|
2679 for f in remaining: |
38347
89db59e5cf3e
remove: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38342
diff
changeset
|
2680 progress.increment() |
35123
7a58608281dd
remove: print message for each file in verbose mode only while using `-A` (BC)
pavanpc@fb.com
parents:
35107
diff
changeset
|
2681 if ui.verbose or (f in files): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2682 warnings.append( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2683 _(b'not removing %s: file still exists\n') % uipathfn(f) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2684 ) |
23289
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2685 ret = 1 |
38373
ef692614e601
progress: hide update(None) in a new complete() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
38347
diff
changeset
|
2686 progress.complete() |
23289
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2687 else: |
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2688 list = deleted + clean |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2689 progress = ui.makeprogress( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2690 _(b'skipping'), total=(len(modified) + len(added)), unit=_(b'files') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2691 ) |
23289
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2692 for f in modified: |
38347
89db59e5cf3e
remove: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38342
diff
changeset
|
2693 progress.increment() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2694 warnings.append( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2695 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2696 b'not removing %s: file is modified (use -f' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2697 b' to force removal)\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2698 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2699 % uipathfn(f) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2700 ) |
23289
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2701 ret = 1 |
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2702 for f in added: |
38347
89db59e5cf3e
remove: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38342
diff
changeset
|
2703 progress.increment() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2704 warnings.append( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2705 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2706 b"not removing %s: file has been marked for add" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2707 b" (use 'hg forget' to undo add)\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2708 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2709 % uipathfn(f) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2710 ) |
23289
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2711 ret = 1 |
38373
ef692614e601
progress: hide update(None) in a new complete() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
38347
diff
changeset
|
2712 progress.complete() |
28608
62e73d42bd14
remove: add progress support
timeless <timeless@mozdev.org>
parents:
28607
diff
changeset
|
2713 |
62e73d42bd14
remove: add progress support
timeless <timeless@mozdev.org>
parents:
28607
diff
changeset
|
2714 list = sorted(list) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2715 progress = ui.makeprogress( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2716 _(b'deleting'), total=len(list), unit=_(b'files') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2717 ) |
28608
62e73d42bd14
remove: add progress support
timeless <timeless@mozdev.org>
parents:
28607
diff
changeset
|
2718 for f in list: |
23289
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2719 if ui.verbose or not m.exact(f): |
38347
89db59e5cf3e
remove: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents:
38342
diff
changeset
|
2720 progress.increment() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2721 ui.status( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2722 _(b'removing %s\n') % uipathfn(f), label=b'ui.addremove.removed' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2723 ) |
38373
ef692614e601
progress: hide update(None) in a new complete() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
38347
diff
changeset
|
2724 progress.complete() |
23289
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2725 |
37150
335e19c6b7fa
remove: add dry-run functionality
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37103
diff
changeset
|
2726 if not dryrun: |
335e19c6b7fa
remove: add dry-run functionality
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37103
diff
changeset
|
2727 with repo.wlock(): |
335e19c6b7fa
remove: add dry-run functionality
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37103
diff
changeset
|
2728 if not after: |
335e19c6b7fa
remove: add dry-run functionality
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37103
diff
changeset
|
2729 for f in list: |
335e19c6b7fa
remove: add dry-run functionality
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37103
diff
changeset
|
2730 if f in added: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2731 continue # we never unlink added files on remove |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2732 rmdir = repo.ui.configbool( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2733 b'experimental', b'removeemptydirs' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2734 ) |
38493
da2a7d8354b2
unlinkpath: make empty directory removal optional (issue5901) (issue5826)
Kyle Lippincott <spectral@google.com>
parents:
38461
diff
changeset
|
2735 repo.wvfs.unlinkpath(f, ignoremissing=True, rmdir=rmdir) |
37150
335e19c6b7fa
remove: add dry-run functionality
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
37103
diff
changeset
|
2736 repo[None].forget(list) |
23289
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2737 |
28607
a88959ae5938
remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents:
28601
diff
changeset
|
2738 if warn: |
a88959ae5938
remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents:
28601
diff
changeset
|
2739 for warning in warnings: |
a88959ae5938
remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents:
28601
diff
changeset
|
2740 ui.warn(warning) |
a88959ae5938
remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents:
28601
diff
changeset
|
2741 |
23289
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2742 return ret |
ae5d0a22ee7e
remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents:
23258
diff
changeset
|
2743 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2744 |
42478
561cd02c58ff
cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents:
42473
diff
changeset
|
2745 def _catfmtneedsdata(fm): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2746 return not fm.datahint() or b'data' in fm.datahint() |
42478
561cd02c58ff
cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents:
42473
diff
changeset
|
2747 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2748 |
35662
91f0979f16c0
cat: factor out a function that populates the formatter
Matt Harbison <matt_harbison@yahoo.com>
parents:
35645
diff
changeset
|
2749 def _updatecatformatter(fm, ctx, matcher, path, decode): |
91f0979f16c0
cat: factor out a function that populates the formatter
Matt Harbison <matt_harbison@yahoo.com>
parents:
35645
diff
changeset
|
2750 """Hook for adding data to the formatter used by ``hg cat``. |
91f0979f16c0
cat: factor out a function that populates the formatter
Matt Harbison <matt_harbison@yahoo.com>
parents:
35645
diff
changeset
|
2751 |
91f0979f16c0
cat: factor out a function that populates the formatter
Matt Harbison <matt_harbison@yahoo.com>
parents:
35645
diff
changeset
|
2752 Extensions (e.g., lfs) can wrap this to inject keywords/data, but must call |
91f0979f16c0
cat: factor out a function that populates the formatter
Matt Harbison <matt_harbison@yahoo.com>
parents:
35645
diff
changeset
|
2753 this method first.""" |
42478
561cd02c58ff
cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents:
42473
diff
changeset
|
2754 |
561cd02c58ff
cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents:
42473
diff
changeset
|
2755 # data() can be expensive to fetch (e.g. lfs), so don't fetch it if it |
561cd02c58ff
cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents:
42473
diff
changeset
|
2756 # wasn't requested. |
561cd02c58ff
cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents:
42473
diff
changeset
|
2757 data = b'' |
561cd02c58ff
cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents:
42473
diff
changeset
|
2758 if _catfmtneedsdata(fm): |
561cd02c58ff
cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents:
42473
diff
changeset
|
2759 data = ctx[path].data() |
561cd02c58ff
cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents:
42473
diff
changeset
|
2760 if decode: |
561cd02c58ff
cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents:
42473
diff
changeset
|
2761 data = ctx.repo().wwritedata(path, data) |
35662
91f0979f16c0
cat: factor out a function that populates the formatter
Matt Harbison <matt_harbison@yahoo.com>
parents:
35645
diff
changeset
|
2762 fm.startitem() |
38539
b1bbff1dd99a
cat: add support for log-like template keywords and functions
Yuya Nishihara <yuya@tcha.org>
parents:
38493
diff
changeset
|
2763 fm.context(ctx=ctx) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2764 fm.write(b'data', b'%s', data) |
39369
34ba47117164
formatter: rename {abspath}/{file} to {path}, and drop relative {path} (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
39350
diff
changeset
|
2765 fm.data(path=path) |
35662
91f0979f16c0
cat: factor out a function that populates the formatter
Matt Harbison <matt_harbison@yahoo.com>
parents:
35645
diff
changeset
|
2766 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2767 |
32584
746e12a767b3
cat: add formatter support
Yuya Nishihara <yuya@tcha.org>
parents:
32583
diff
changeset
|
2768 def cat(ui, repo, ctx, matcher, basefm, fntemplate, prefix, **opts): |
21040
bdf5ed5246d2
cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents:
21036
diff
changeset
|
2769 err = 1 |
bdf5ed5246d2
cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents:
21036
diff
changeset
|
2770 |
bdf5ed5246d2
cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents:
21036
diff
changeset
|
2771 def write(path): |
32584
746e12a767b3
cat: add formatter support
Yuya Nishihara <yuya@tcha.org>
parents:
32583
diff
changeset
|
2772 filename = None |
32582
7f4435078a8f
cat: stop using makefileobj()
Yuya Nishihara <yuya@tcha.org>
parents:
32540
diff
changeset
|
2773 if fntemplate: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2774 filename = makefilename( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2775 ctx, fntemplate, pathname=os.path.join(prefix, path) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2776 ) |
35007
407ec7f3ff02
cmdutil: create dirs for templated cat file output
Ryan McElroy <rmcelroy@fb.com>
parents:
34996
diff
changeset
|
2777 # attempt to create the directory if it does not already exist |
407ec7f3ff02
cmdutil: create dirs for templated cat file output
Ryan McElroy <rmcelroy@fb.com>
parents:
34996
diff
changeset
|
2778 try: |
407ec7f3ff02
cmdutil: create dirs for templated cat file output
Ryan McElroy <rmcelroy@fb.com>
parents:
34996
diff
changeset
|
2779 os.makedirs(os.path.dirname(filename)) |
407ec7f3ff02
cmdutil: create dirs for templated cat file output
Ryan McElroy <rmcelroy@fb.com>
parents:
34996
diff
changeset
|
2780 except OSError: |
407ec7f3ff02
cmdutil: create dirs for templated cat file output
Ryan McElroy <rmcelroy@fb.com>
parents:
34996
diff
changeset
|
2781 pass |
37597
d110167610db
formatter: carry opts to file-based formatters by basefm
Yuya Nishihara <yuya@tcha.org>
parents:
37470
diff
changeset
|
2782 with formatter.maybereopen(basefm, filename) as fm: |
50373
4fafc6642bee
cat: drop unnecessary internal roundtrip of kwargs
Matt Harbison <matt_harbison@yahoo.com>
parents:
50263
diff
changeset
|
2783 _updatecatformatter(fm, ctx, matcher, path, opts.get('decode')) |
21040
bdf5ed5246d2
cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents:
21036
diff
changeset
|
2784 |
bdf5ed5246d2
cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents:
21036
diff
changeset
|
2785 # Automation often uses hg cat on single files, so special case it |
bdf5ed5246d2
cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents:
21036
diff
changeset
|
2786 # for performance to avoid the cost of parsing the manifest. |
bdf5ed5246d2
cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents:
21036
diff
changeset
|
2787 if len(matcher.files()) == 1 and not matcher.anypats(): |
bdf5ed5246d2
cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents:
21036
diff
changeset
|
2788 file = matcher.files()[0] |
30340
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30332
diff
changeset
|
2789 mfl = repo.manifestlog |
24718
a4191e0c728f
cat: use ctx.manifestnode() in place of ctx._changeset[0]
Yuya Nishihara <yuya@tcha.org>
parents:
24711
diff
changeset
|
2790 mfnode = ctx.manifestnode() |
30340
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30332
diff
changeset
|
2791 try: |
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30332
diff
changeset
|
2792 if mfnode and mfl[mfnode].find(file)[0]: |
42478
561cd02c58ff
cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents:
42473
diff
changeset
|
2793 if _catfmtneedsdata(basefm): |
45072
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
45037
diff
changeset
|
2794 scmutil.prefetchfiles(repo, [(ctx.rev(), matcher)]) |
30340
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30332
diff
changeset
|
2795 write(file) |
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30332
diff
changeset
|
2796 return 0 |
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30332
diff
changeset
|
2797 except KeyError: |
608ba935e041
manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents:
30332
diff
changeset
|
2798 pass |
21040
bdf5ed5246d2
cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents:
21036
diff
changeset
|
2799 |
42478
561cd02c58ff
cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents:
42473
diff
changeset
|
2800 if _catfmtneedsdata(basefm): |
45072
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
45037
diff
changeset
|
2801 scmutil.prefetchfiles(repo, [(ctx.rev(), matcher)]) |
37762
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37756
diff
changeset
|
2802 |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37756
diff
changeset
|
2803 for abs in ctx.walk(matcher): |
21040
bdf5ed5246d2
cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents:
21036
diff
changeset
|
2804 write(abs) |
bdf5ed5246d2
cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents:
21036
diff
changeset
|
2805 err = 0 |
21041
a2cc3c08c3ac
cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
21040
diff
changeset
|
2806 |
41663
28ce9184d495
cat: respect ui.relative-paths for "skipping missing subrepository"
Martin von Zweigbergk <martinvonz@google.com>
parents:
41661
diff
changeset
|
2807 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) |
21041
a2cc3c08c3ac
cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
21040
diff
changeset
|
2808 for subpath in sorted(ctx.substate): |
a2cc3c08c3ac
cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
21040
diff
changeset
|
2809 sub = ctx.sub(subpath) |
a2cc3c08c3ac
cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
21040
diff
changeset
|
2810 try: |
28017
d3f1b7ee5e70
match: rename "narrowmatcher" to "subdirmatcher" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
27985
diff
changeset
|
2811 submatch = matchmod.subdirmatcher(subpath, matcher) |
41649
799e156785f7
subrepo: (mostly) use relative path in "skipping missing subrepository"
Martin von Zweigbergk <martinvonz@google.com>
parents:
41628
diff
changeset
|
2812 subprefix = os.path.join(prefix, subpath) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2813 if not sub.cat( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2814 submatch, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2815 basefm, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2816 fntemplate, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2817 subprefix, |
50373
4fafc6642bee
cat: drop unnecessary internal roundtrip of kwargs
Matt Harbison <matt_harbison@yahoo.com>
parents:
50263
diff
changeset
|
2818 **opts, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2819 ): |
21041
a2cc3c08c3ac
cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
21040
diff
changeset
|
2820 err = 0 |
a2cc3c08c3ac
cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
21040
diff
changeset
|
2821 except error.RepoLookupError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2822 ui.status( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2823 _(b"skipping missing subrepository: %s\n") % uipathfn(subpath) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2824 ) |
21041
a2cc3c08c3ac
cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
21040
diff
changeset
|
2825 |
21040
bdf5ed5246d2
cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents:
21036
diff
changeset
|
2826 return err |
bdf5ed5246d2
cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents:
21036
diff
changeset
|
2827 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2828 |
50029
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2829 class _AddRemoveContext: |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2830 """a small (hacky) context to deal with lazy opening of context |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2831 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2832 This is to be used in the `commit` function right below. This deals with |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2833 lazily open a `changing_files` context inside a `transaction` that span the |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2834 full commit operation. |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2835 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2836 We need : |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2837 - a `changing_files` context to wrap the dirstate change within the |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2838 "addremove" operation, |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2839 - a transaction to make sure these change are not written right after the |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2840 addremove, but when the commit operation succeed. |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2841 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2842 However it get complicated because: |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2843 - opening a transaction "this early" shuffle hooks order, especially the |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2844 `precommit` one happening after the `pretxtopen` one which I am not too |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2845 enthusiastic about. |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2846 - the `mq` extensions + the `record` extension stacks many layers of call |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2847 to implement `qrefresh --interactive` and this result with `mq` calling a |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2848 `strip` in the middle of this function. Which prevent the existence of |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2849 transaction wrapping all of its function code. (however, `qrefresh` never |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2850 call the `addremove` bits. |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2851 - the largefile extensions (and maybe other extensions?) wraps `addremove` |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2852 so slicing `addremove` in smaller bits is a complex endeavour. |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2853 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2854 So I eventually took a this shortcut that open the transaction if we |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2855 actually needs it, not disturbing much of the rest of the code. |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2856 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2857 It will result in some hooks order change for `hg commit --addremove`, |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2858 however it seems a corner case enough to ignore that for now (hopefully). |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2859 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2860 Notes that None of the above problems seems insurmountable, however I have |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2861 been fighting with this specific piece of code for a couple of day already |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2862 and I need a solution to keep moving forward on the bigger work around |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2863 `changing_files` context that is being introduced at the same time as this |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2864 hack. |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2865 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2866 Each problem seems to have a solution: |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2867 - the hook order issue could be solved by refactoring the many-layer stack |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2868 that currently composes a commit and calling them earlier, |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2869 - the mq issue could be solved by refactoring `mq` so that the final strip |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2870 is done after transaction closure. Be warned that the mq code is quite |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2871 antic however. |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2872 - large-file could be reworked in parallel of the `addremove` to be |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2873 friendlier to this. |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2874 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2875 However each of these tasks are too much a diversion right now. In addition |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2876 they will be much easier to undertake when the `changing_files` dust has |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2877 settled.""" |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2878 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2879 def __init__(self, repo): |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2880 self._repo = repo |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2881 self._transaction = None |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2882 self._dirstate_context = None |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2883 self._state = None |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2884 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2885 def __enter__(self): |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2886 assert self._state is None |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2887 self._state = True |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2888 return self |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2889 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2890 def open_transaction(self): |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2891 """open a `transaction` and `changing_files` context |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2892 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2893 Call this when you know that change to the dirstate will be needed and |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2894 we need to open the transaction early |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2895 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2896 This will also open the dirstate `changing_files` context, so you should |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2897 call `close_dirstate_context` when the distate changes are done. |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2898 """ |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2899 assert self._state is not None |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2900 if self._transaction is None: |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2901 self._transaction = self._repo.transaction(b'commit') |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2902 self._transaction.__enter__() |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2903 if self._dirstate_context is None: |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2904 self._dirstate_context = self._repo.dirstate.changing_files( |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2905 self._repo |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2906 ) |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2907 self._dirstate_context.__enter__() |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2908 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2909 def close_dirstate_context(self): |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2910 """close the change_files if any |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2911 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2912 Call this after the (potential) `open_transaction` call to close the |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2913 (potential) changing_files context. |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2914 """ |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2915 if self._dirstate_context is not None: |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2916 self._dirstate_context.__exit__(None, None, None) |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2917 self._dirstate_context = None |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2918 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2919 def __exit__(self, *args): |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2920 if self._dirstate_context is not None: |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2921 self._dirstate_context.__exit__(*args) |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2922 if self._transaction is not None: |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2923 self._transaction.__exit__(*args) |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2924 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2925 |
5034
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
2926 def commit(ui, repo, commitfunc, pats, opts): |
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
2927 '''commit the specified files or all outstanding changes''' |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2928 date = opts.get(b'date') |
6139
989467e8e3a9
Fix bad behaviour when specifying an invalid date (issue700)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6112
diff
changeset
|
2929 if date: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2930 opts[b'date'] = dateutil.parsedate(date) |
5034
c0417a319e39
commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents:
4965
diff
changeset
|
2931 |
50029
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2932 with repo.wlock(), repo.lock(): |
50028
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2933 message = logmessage(ui, opts) |
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2934 matcher = scmutil.match(repo[None], pats, opts) |
50029
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2935 |
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2936 with _AddRemoveContext(repo) as c: |
50028
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2937 # extract addremove carefully -- this function can be called from a |
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2938 # command that doesn't support addremove |
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2939 if opts.get(b'addremove'): |
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2940 relative = scmutil.anypats(pats, opts) |
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2941 uipathfn = scmutil.getuipathfn( |
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2942 repo, |
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2943 legacyrelativevalue=relative, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2944 ) |
50028
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2945 r = scmutil.addremove( |
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2946 repo, |
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2947 matcher, |
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2948 b"", |
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2949 uipathfn, |
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2950 opts, |
50029
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2951 open_tr=c.open_transaction, |
50028
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2952 ) |
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2953 m = _(b"failed to mark all new/missing files as added/removed") |
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2954 if r != 0: |
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2955 raise error.Abort(m) |
50029
28dfb2df4ab9
commit: use `dirstate.change_files` to scope the associated `addremove`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50028
diff
changeset
|
2956 c.close_dirstate_context() |
50028
a46dfc2b58a3
commit: move the addremove logic around to make the next changeset clearer
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49961
diff
changeset
|
2957 return commitfunc(ui, repo, message, matcher, opts) |
8407
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
2958 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2959 |
29819
2cec6eaf3610
cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29802
diff
changeset
|
2960 def samefile(f, ctx1, ctx2): |
2cec6eaf3610
cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29802
diff
changeset
|
2961 if f in ctx1.manifest(): |
2cec6eaf3610
cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29802
diff
changeset
|
2962 a = ctx1.filectx(f) |
2cec6eaf3610
cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29802
diff
changeset
|
2963 if f in ctx2.manifest(): |
2cec6eaf3610
cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29802
diff
changeset
|
2964 b = ctx2.filectx(f) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2965 return not a.cmp(b) and a.flags() == b.flags() |
29819
2cec6eaf3610
cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29802
diff
changeset
|
2966 else: |
2cec6eaf3610
cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29802
diff
changeset
|
2967 return False |
2cec6eaf3610
cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29802
diff
changeset
|
2968 else: |
2cec6eaf3610
cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29802
diff
changeset
|
2969 return f not in ctx2.manifest() |
2cec6eaf3610
cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29802
diff
changeset
|
2970 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2971 |
50093
ce60c8d4ac87
typing: add type hints to argument checking functions in cmdutil
Matt Harbison <matt_harbison@yahoo.com>
parents:
50042
diff
changeset
|
2972 def amend(ui, repo, old, extra, pats, opts: Dict[str, Any]): |
25930
221491bbaf7e
cmdutil: break import cycle
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25795
diff
changeset
|
2973 # avoid cycle context -> subrepo -> cmdutil |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
2974 from . import context |
25930
221491bbaf7e
cmdutil: break import cycle
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25795
diff
changeset
|
2975 |
23101
b564330d4b1f
amend: abort early if no username is configured with evolve enabled (issue4211)
Matt Harbison <matt_harbison@yahoo.com>
parents:
22951
diff
changeset
|
2976 # amend will reuse the existing user if not specified, but the obsolete |
b564330d4b1f
amend: abort early if no username is configured with evolve enabled (issue4211)
Matt Harbison <matt_harbison@yahoo.com>
parents:
22951
diff
changeset
|
2977 # marker creation requires that the current user's name is specified. |
24379
8c445d8a915b
obsolete: remove last instance of _enabled
Durham Goode <durham@fb.com>
parents:
24364
diff
changeset
|
2978 if obsolete.isenabled(repo, obsolete.createmarkersopt): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
2979 ui.username() # raise exception if username not set |
23101
b564330d4b1f
amend: abort early if no username is configured with evolve enabled (issue4211)
Matt Harbison <matt_harbison@yahoo.com>
parents:
22951
diff
changeset
|
2980 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2981 ui.note(_(b'amending changeset %s\n') % old) |
16458
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
2982 base = old.p1() |
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
2983 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2984 with repo.wlock(), repo.lock(), repo.transaction(b'amend'): |
33438 | 2985 # Participating changesets: |
2986 # | |
34085
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
2987 # wctx o - workingctx that contains changes from working copy |
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
2988 # | to go into amending commit |
33438 | 2989 # | |
2990 # old o - changeset to amend | |
2991 # | | |
34056 | 2992 # base o - first parent of the changeset to amend |
34085
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
2993 wctx = repo[None] |
33438 | 2994 |
35196
5cc14407a739
amend: make a copy of "extra" to avoid mutating an input
Martin von Zweigbergk <martinvonz@google.com>
parents:
35163
diff
changeset
|
2995 # Copy to avoid mutating input |
5cc14407a739
amend: make a copy of "extra" to avoid mutating an input
Martin von Zweigbergk <martinvonz@google.com>
parents:
35163
diff
changeset
|
2996 extra = extra.copy() |
33438 | 2997 # Update extra dict from amended commit (e.g. to preserve graft |
2998 # source) | |
2999 extra.update(old.extra()) | |
3000 | |
34085
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3001 # Also update it from the from the wctx |
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3002 extra.update(wctx.extra()) |
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3003 |
42932
e4803231f538
amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents:
42921
diff
changeset
|
3004 # date-only change should be ignored? |
47432
7f7457f84311
cmdutil: make resolvecommitoptions() work on str-keyed opts
Martin von Zweigbergk <martinvonz@google.com>
parents:
47431
diff
changeset
|
3005 datemaydiffer = resolve_commit_options(ui, opts) |
7f7457f84311
cmdutil: make resolvecommitoptions() work on str-keyed opts
Martin von Zweigbergk <martinvonz@google.com>
parents:
47431
diff
changeset
|
3006 opts = pycompat.byteskwargs(opts) |
42932
e4803231f538
amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents:
42921
diff
changeset
|
3007 |
e4803231f538
amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents:
42921
diff
changeset
|
3008 date = old.date() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3009 if opts.get(b'date'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3010 date = dateutil.parsedate(opts.get(b'date')) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3011 user = opts.get(b'user') or old.user() |
34121
ae95853c250a
cmdutil: fix amend when passing a date
Boris Feld <boris.feld@octobus.net>
parents:
34086
diff
changeset
|
3012 |
33438 | 3013 if len(old.parents()) > 1: |
3014 # ctx.files() isn't reliable for merges, so fall back to the | |
3015 # slower repo.status() method | |
43644
e01e0641f18a
cmdutil: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents:
43523
diff
changeset
|
3016 st = base.status(old) |
e01e0641f18a
cmdutil: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents:
43523
diff
changeset
|
3017 files = set(st.modified) | set(st.added) | set(st.removed) |
33438 | 3018 else: |
3019 files = set(old.files()) | |
3020 | |
34085
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3021 # add/remove the files to the working copy if the "addremove" option |
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3022 # was specified. |
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3023 matcher = scmutil.match(wctx, pats, opts) |
41652
6a447a3d1bd0
addremove: pass around uipathfn and use instead of m.uipath() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41651
diff
changeset
|
3024 relative = scmutil.anypats(pats, opts) |
41685
b81ecf3571d5
addremove: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41683
diff
changeset
|
3025 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=relative) |
50042
237e9d2e1c71
dirstate: use `dirstate.change_files` to scope the change in `amend`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50038
diff
changeset
|
3026 if opts.get(b'addremove'): |
237e9d2e1c71
dirstate: use `dirstate.change_files` to scope the change in `amend`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50038
diff
changeset
|
3027 with repo.dirstate.changing_files(repo): |
237e9d2e1c71
dirstate: use `dirstate.change_files` to scope the change in `amend`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50038
diff
changeset
|
3028 if scmutil.addremove(repo, matcher, b"", uipathfn, opts) != 0: |
237e9d2e1c71
dirstate: use `dirstate.change_files` to scope the change in `amend`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50038
diff
changeset
|
3029 m = _( |
237e9d2e1c71
dirstate: use `dirstate.change_files` to scope the change in `amend`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50038
diff
changeset
|
3030 b"failed to mark all new/missing files as added/removed" |
237e9d2e1c71
dirstate: use `dirstate.change_files` to scope the change in `amend`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50038
diff
changeset
|
3031 ) |
237e9d2e1c71
dirstate: use `dirstate.change_files` to scope the change in `amend`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50038
diff
changeset
|
3032 raise error.Abort(m) |
34085
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3033 |
35026
691524f0bbf6
amend: update .hgsubstate before committing a memctx (issue5677)
Yuya Nishihara <yuya@tcha.org>
parents:
35023
diff
changeset
|
3034 # Check subrepos. This depends on in-place wctx._status update in |
691524f0bbf6
amend: update .hgsubstate before committing a memctx (issue5677)
Yuya Nishihara <yuya@tcha.org>
parents:
35023
diff
changeset
|
3035 # subrepo.precommit(). To minimize the risk of this hack, we do |
691524f0bbf6
amend: update .hgsubstate before committing a memctx (issue5677)
Yuya Nishihara <yuya@tcha.org>
parents:
35023
diff
changeset
|
3036 # nothing if .hgsub does not exist. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3037 if b'.hgsub' in wctx or b'.hgsub' in old: |
36009
55e8efa2451a
subrepo: split non-core functions to new module
Yuya Nishihara <yuya@tcha.org>
parents:
35954
diff
changeset
|
3038 subs, commitsubs, newsubstate = subrepoutil.precommit( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3039 ui, wctx, wctx._status, matcher |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3040 ) |
35026
691524f0bbf6
amend: update .hgsubstate before committing a memctx (issue5677)
Yuya Nishihara <yuya@tcha.org>
parents:
35023
diff
changeset
|
3041 # amend should abort if commitsubrepos is enabled |
691524f0bbf6
amend: update .hgsubstate before committing a memctx (issue5677)
Yuya Nishihara <yuya@tcha.org>
parents:
35023
diff
changeset
|
3042 assert not commitsubs |
691524f0bbf6
amend: update .hgsubstate before committing a memctx (issue5677)
Yuya Nishihara <yuya@tcha.org>
parents:
35023
diff
changeset
|
3043 if subs: |
36009
55e8efa2451a
subrepo: split non-core functions to new module
Yuya Nishihara <yuya@tcha.org>
parents:
35954
diff
changeset
|
3044 subrepoutil.writestate(repo, newsubstate) |
35026
691524f0bbf6
amend: update .hgsubstate before committing a memctx (issue5677)
Yuya Nishihara <yuya@tcha.org>
parents:
35023
diff
changeset
|
3045 |
44856
b7808443ed6a
mergestate: split out merge state handling code from main merge module
Augie Fackler <augie@google.com>
parents:
44807
diff
changeset
|
3046 ms = mergestatemod.mergestate.read(repo) |
36844
eeb87b24aea7
amend: abort if unresolved merge conflicts found (issue5805)
Yuya Nishihara <yuya@tcha.org>
parents:
35746
diff
changeset
|
3047 mergeutil.checkunresolved(ms) |
eeb87b24aea7
amend: abort if unresolved merge conflicts found (issue5805)
Yuya Nishihara <yuya@tcha.org>
parents:
35746
diff
changeset
|
3048 |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44440
diff
changeset
|
3049 filestoamend = {f for f in wctx.files() if matcher(f)} |
34085
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3050 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3051 changes = len(filestoamend) > 0 |
48976
877d7e1a4223
amend: fix amend with copies in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
48384
diff
changeset
|
3052 changeset_copies = ( |
877d7e1a4223
amend: fix amend with copies in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
48384
diff
changeset
|
3053 repo.ui.config(b'experimental', b'copies.read-from') |
877d7e1a4223
amend: fix amend with copies in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
48384
diff
changeset
|
3054 != b'filelog-only' |
877d7e1a4223
amend: fix amend with copies in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
48384
diff
changeset
|
3055 ) |
877d7e1a4223
amend: fix amend with copies in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
48384
diff
changeset
|
3056 # If there are changes to amend or if copy information needs to be read |
877d7e1a4223
amend: fix amend with copies in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
48384
diff
changeset
|
3057 # from the changeset extras, we cannot take the fast path of using |
877d7e1a4223
amend: fix amend with copies in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
48384
diff
changeset
|
3058 # filectxs from the old commit. |
877d7e1a4223
amend: fix amend with copies in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
48384
diff
changeset
|
3059 if changes or changeset_copies: |
33438 | 3060 # Recompute copies (avoid recording a -> b -> a) |
49179
df68d64b0d50
amend: stop specifying matcher, get all copies in wctx
Kyle Lippincott <spectral@google.com>
parents:
49067
diff
changeset
|
3061 copied = copies.pathcopies(base, wctx) |
df68d64b0d50
amend: stop specifying matcher, get all copies in wctx
Kyle Lippincott <spectral@google.com>
parents:
49067
diff
changeset
|
3062 if old.p2(): |
df68d64b0d50
amend: stop specifying matcher, get all copies in wctx
Kyle Lippincott <spectral@google.com>
parents:
49067
diff
changeset
|
3063 copied.update(copies.pathcopies(old.p2(), wctx)) |
33438 | 3064 |
3065 # Prune files which were reverted by the updates: if old | |
34085
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3066 # introduced file X and the file was renamed in the working |
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3067 # copy, then those two files are the same and |
33438 | 3068 # we can discard X from our list of files. Likewise if X |
35023
5f40efa472db
amend: do not drop missing files (issue5732)
Yuya Nishihara <yuya@tcha.org>
parents:
35022
diff
changeset
|
3069 # was removed, it's no longer relevant. If X is missing (aka |
5f40efa472db
amend: do not drop missing files (issue5732)
Yuya Nishihara <yuya@tcha.org>
parents:
35022
diff
changeset
|
3070 # deleted), old X must be preserved. |
34085
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3071 files.update(filestoamend) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3072 files = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3073 f |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3074 for f in files |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3075 if (f not in filestoamend or not samefile(f, wctx, base)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3076 ] |
33438 | 3077 |
3078 def filectxfn(repo, ctx_, path): | |
3079 try: | |
34085
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3080 # If the file being considered is not amongst the files |
48976
877d7e1a4223
amend: fix amend with copies in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
48384
diff
changeset
|
3081 # to be amended, we should use the file context from the |
34085
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3082 # old changeset. This avoids issues when only some files in |
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3083 # the working copy are being amended but there are also |
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3084 # changes to other files from the old changeset. |
48976
877d7e1a4223
amend: fix amend with copies in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
48384
diff
changeset
|
3085 if path in filestoamend: |
49144
f45e1618cbf6
amend: move "return None for removed files" into block handling filestoamend
Kyle Lippincott <spectral@google.com>
parents:
49084
diff
changeset
|
3086 # Return None for removed files. |
f45e1618cbf6
amend: move "return None for removed files" into block handling filestoamend
Kyle Lippincott <spectral@google.com>
parents:
49084
diff
changeset
|
3087 if path in wctx.removed(): |
f45e1618cbf6
amend: move "return None for removed files" into block handling filestoamend
Kyle Lippincott <spectral@google.com>
parents:
49084
diff
changeset
|
3088 return None |
48976
877d7e1a4223
amend: fix amend with copies in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
48384
diff
changeset
|
3089 fctx = wctx[path] |
877d7e1a4223
amend: fix amend with copies in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
48384
diff
changeset
|
3090 else: |
877d7e1a4223
amend: fix amend with copies in extras
Martin von Zweigbergk <martinvonz@google.com>
parents:
48384
diff
changeset
|
3091 fctx = old.filectx(path) |
33438 | 3092 flags = fctx.flags() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3093 mctx = context.memfilectx( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3094 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3095 ctx_, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3096 fctx.path(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3097 fctx.data(), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3098 islink=b'l' in flags, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3099 isexec=b'x' in flags, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3100 copysource=copied.get(path), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3101 ) |
33438 | 3102 return mctx |
3103 except KeyError: | |
3104 return None | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3105 |
33438 | 3106 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3107 ui.note(_(b'copying changeset %s to %s\n') % (old, base)) |
33438 | 3108 |
3109 # Use version of files as in the old cset | |
3110 def filectxfn(repo, ctx_, path): | |
3111 try: | |
3112 return old.filectx(path) | |
3113 except KeyError: | |
3114 return None | |
3115 | |
34085
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3116 # See if we got a message from -m or -l, if not, open the editor with |
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3117 # the message of the changeset to amend. |
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3118 message = logmessage(ui, opts) |
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3119 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3120 editform = mergeeditform(old, b'commit.amend') |
34085
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3121 |
33438 | 3122 if not message: |
3123 message = old.description() | |
42399
64ed405dd342
commit: respect --no-edit in combination with --amend
Kyle Lippincott <spectral@google.com>
parents:
42270
diff
changeset
|
3124 # Default if message isn't provided and --edit is not passed is to |
64ed405dd342
commit: respect --no-edit in combination with --amend
Kyle Lippincott <spectral@google.com>
parents:
42270
diff
changeset
|
3125 # invoke editor, but allow --no-edit. If somehow we don't have any |
64ed405dd342
commit: respect --no-edit in combination with --amend
Kyle Lippincott <spectral@google.com>
parents:
42270
diff
changeset
|
3126 # description, let's always start the editor. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3127 doedit = not message or opts.get(b'edit') in [True, None] |
42399
64ed405dd342
commit: respect --no-edit in combination with --amend
Kyle Lippincott <spectral@google.com>
parents:
42270
diff
changeset
|
3128 else: |
64ed405dd342
commit: respect --no-edit in combination with --amend
Kyle Lippincott <spectral@google.com>
parents:
42270
diff
changeset
|
3129 # Default if message is provided is to not invoke editor, but allow |
64ed405dd342
commit: respect --no-edit in combination with --amend
Kyle Lippincott <spectral@google.com>
parents:
42270
diff
changeset
|
3130 # --edit. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3131 doedit = opts.get(b'edit') is True |
42399
64ed405dd342
commit: respect --no-edit in combination with --amend
Kyle Lippincott <spectral@google.com>
parents:
42270
diff
changeset
|
3132 editor = getcommiteditor(edit=doedit, editform=editform) |
33438 | 3133 |
3134 pureextra = extra.copy() | |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3135 extra[b'amend_source'] = old.hex() |
33438 | 3136 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3137 new = context.memctx( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3138 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3139 parents=[base.node(), old.p2().node()], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3140 text=message, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3141 files=files, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3142 filectxfn=filectxfn, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3143 user=user, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3144 date=date, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3145 extra=extra, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3146 editor=editor, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3147 ) |
33438 | 3148 |
3149 newdesc = changelog.stripdesc(new.description()) | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3150 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3151 (not changes) |
33438 | 3152 and newdesc == old.description() |
3153 and user == old.user() | |
41124
cffa8e0ba77a
amend: add boolean to ignore date-only change
Yuya Nishihara <yuya@tcha.org>
parents:
41123
diff
changeset
|
3154 and (date == old.date() or datemaydiffer) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3155 and pureextra == old.extra() |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3156 ): |
33438 | 3157 # nothing changed. continuing here would create a new node |
3158 # anyway because of the amend_source noise. | |
17472
965fbe04fd96
amend: wrap all commit operations in a single transaction
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
17471
diff
changeset
|
3159 # |
33438 | 3160 # This not what we expect from amend. |
41124
cffa8e0ba77a
amend: add boolean to ignore date-only change
Yuya Nishihara <yuya@tcha.org>
parents:
41123
diff
changeset
|
3161 return old.node() |
33438 | 3162 |
38423
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38373
diff
changeset
|
3163 commitphase = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3164 if opts.get(b'secret'): |
38423
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38373
diff
changeset
|
3165 commitphase = phases.secret |
49772
e78a41686464
amend: add a --draft option to set phase to draft
Martin von Zweigbergk <martinvonz@google.com>
parents:
49456
diff
changeset
|
3166 elif opts.get(b'draft'): |
e78a41686464
amend: add a --draft option to set phase to draft
Martin von Zweigbergk <martinvonz@google.com>
parents:
49456
diff
changeset
|
3167 commitphase = phases.draft |
38423
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38373
diff
changeset
|
3168 newid = repo.commitctx(new) |
45388
6ba7190ff863
commit: clear mergestate also with --amend (issue6304)
Martin von Zweigbergk <martinvonz@google.com>
parents:
45375
diff
changeset
|
3169 ms.reset() |
34055
ae92e5c0441c
amend: removing redundant if condition
Saurabh Singh <singhsrb@fb.com>
parents:
34029
diff
changeset
|
3170 |
49961
7a8bfc05b691
dirstate: rename parentchange to changing_parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49960
diff
changeset
|
3171 with repo.dirstate.changing_parents(repo): |
47608
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3172 # Reroute the working copy parent to the new changeset |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3173 repo.setparents(newid, repo.nullid) |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3174 |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3175 # Fixing the dirstate because localrepo.commitctx does not update |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3176 # it. This is rather convenient because we did not need to update |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3177 # the dirstate for all the files in the new commit which commitctx |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3178 # could have done if it updated the dirstate. Now, we can |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3179 # selectively update the dirstate only for the amended files. |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3180 dirstate = repo.dirstate |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3181 |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3182 # Update the state of the files which were added and modified in the |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3183 # amend to "normal" in the dirstate. We need to use "normallookup" since |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3184 # the files may have changed since the command started; using "normal" |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3185 # would mark them as clean but with uncommitted contents. |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3186 normalfiles = set(wctx.modified() + wctx.added()) & filestoamend |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3187 for f in normalfiles: |
47728
4d1ae9cba551
amend: use `update_file` instead of `normallookup`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47707
diff
changeset
|
3188 dirstate.update_file( |
4d1ae9cba551
amend: use `update_file` instead of `normallookup`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47707
diff
changeset
|
3189 f, p1_tracked=True, wc_tracked=True, possibly_dirty=True |
4d1ae9cba551
amend: use `update_file` instead of `normallookup`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47707
diff
changeset
|
3190 ) |
47608
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3191 |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3192 # Update the state of files which were removed in the amend |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3193 # to "removed" in the dirstate. |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3194 removedfiles = set(wctx.removed()) & filestoamend |
3c0efa0eeea6
amend: adjust the dirstate within a `parentchange` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47603
diff
changeset
|
3195 for f in removedfiles: |
47746
56297381af90
amend: use `update_file` instead of `drop`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47732
diff
changeset
|
3196 dirstate.update_file(f, p1_tracked=False, wc_tracked=False) |
34085
e8a7c1a0565a
cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents:
34083
diff
changeset
|
3197 |
46765
62c2857a174b
amend: mark commit obsolete after moving working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
46475
diff
changeset
|
3198 mapping = {old.node(): (newid,)} |
62c2857a174b
amend: mark commit obsolete after moving working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
46475
diff
changeset
|
3199 obsmetadata = None |
62c2857a174b
amend: mark commit obsolete after moving working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
46475
diff
changeset
|
3200 if opts.get(b'note'): |
62c2857a174b
amend: mark commit obsolete after moving working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
46475
diff
changeset
|
3201 obsmetadata = {b'note': encoding.fromlocal(opts[b'note'])} |
62c2857a174b
amend: mark commit obsolete after moving working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
46475
diff
changeset
|
3202 backup = ui.configbool(b'rewrite', b'backup-bundle') |
62c2857a174b
amend: mark commit obsolete after moving working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
46475
diff
changeset
|
3203 scmutil.cleanupnodes( |
62c2857a174b
amend: mark commit obsolete after moving working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
46475
diff
changeset
|
3204 repo, |
62c2857a174b
amend: mark commit obsolete after moving working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
46475
diff
changeset
|
3205 mapping, |
62c2857a174b
amend: mark commit obsolete after moving working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
46475
diff
changeset
|
3206 b'amend', |
62c2857a174b
amend: mark commit obsolete after moving working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
46475
diff
changeset
|
3207 metadata=obsmetadata, |
62c2857a174b
amend: mark commit obsolete after moving working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
46475
diff
changeset
|
3208 fixphase=True, |
62c2857a174b
amend: mark commit obsolete after moving working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
46475
diff
changeset
|
3209 targetphase=commitphase, |
62c2857a174b
amend: mark commit obsolete after moving working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
46475
diff
changeset
|
3210 backup=backup, |
62c2857a174b
amend: mark commit obsolete after moving working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
46475
diff
changeset
|
3211 ) |
62c2857a174b
amend: mark commit obsolete after moving working copy
Martin von Zweigbergk <martinvonz@google.com>
parents:
46475
diff
changeset
|
3212 |
16458
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
3213 return newid |
55982f62651f
commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents:
16430
diff
changeset
|
3214 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3215 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3216 def commiteditor(repo, ctx, subs, editform=b''): |
8407
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
3217 if ctx.description(): |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
3218 return ctx.description() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3219 return commitforceeditor( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3220 repo, ctx, subs, editform=editform, unchangedmessagedetection=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3221 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3222 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3223 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3224 def commitforceeditor( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3225 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3226 ctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3227 subs, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3228 finishdesc=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3229 extramsg=None, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3230 editform=b'', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3231 unchangedmessagedetection=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3232 ): |
21923
e582e20cd3e6
commiteditor: refactor default extramsg
Matt Mackall <mpm@selenic.com>
parents:
21878
diff
changeset
|
3233 if not extramsg: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3234 extramsg = _(b"Leave message empty to abort commit.") |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3235 |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3236 forms = [e for e in editform.split(b'.') if e] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3237 forms.insert(0, b'changeset') |
26742
bec1a579ebc4
commit: abort when a committemplate is not changed
Tony Tung <tonytung@fb.com>
parents:
26639
diff
changeset
|
3238 templatetext = None |
22012
9d92b9d1e282
cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22011
diff
changeset
|
3239 while forms: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3240 ref = b'.'.join(forms) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3241 if repo.ui.config(b'committemplate', ref): |
26742
bec1a579ebc4
commit: abort when a committemplate is not changed
Tony Tung <tonytung@fb.com>
parents:
26639
diff
changeset
|
3242 templatetext = committext = buildcommittemplate( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3243 repo, ctx, subs, extramsg, ref |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3244 ) |
22012
9d92b9d1e282
cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22011
diff
changeset
|
3245 break |
9d92b9d1e282
cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22011
diff
changeset
|
3246 forms.pop() |
21924
5375ba75df40
cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21923
diff
changeset
|
3247 else: |
5375ba75df40
cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21923
diff
changeset
|
3248 committext = buildcommittext(repo, ctx, subs, extramsg) |
21869
e353fac7db26
cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21832
diff
changeset
|
3249 |
e353fac7db26
cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21832
diff
changeset
|
3250 # run editor in the repository root |
39818
24e493ec2229
py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
39737
diff
changeset
|
3251 olddir = encoding.getcwd() |
21869
e353fac7db26
cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21832
diff
changeset
|
3252 os.chdir(repo.root) |
26750
9f9ec4abe700
cmdutil: make in-memory changes visible to external editor (issue4378)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26746
diff
changeset
|
3253 |
9f9ec4abe700
cmdutil: make in-memory changes visible to external editor (issue4378)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26746
diff
changeset
|
3254 # make in-memory changes visible to external process |
9f9ec4abe700
cmdutil: make in-memory changes visible to external editor (issue4378)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26746
diff
changeset
|
3255 tr = repo.currenttransaction() |
9f9ec4abe700
cmdutil: make in-memory changes visible to external editor (issue4378)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26746
diff
changeset
|
3256 repo.dirstate.write(tr) |
9f9ec4abe700
cmdutil: make in-memory changes visible to external editor (issue4378)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26746
diff
changeset
|
3257 pending = tr and tr.writepending() and repo.root |
9f9ec4abe700
cmdutil: make in-memory changes visible to external editor (issue4378)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26746
diff
changeset
|
3258 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3259 editortext = repo.ui.edit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3260 committext, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3261 ctx.user(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3262 ctx.extra(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3263 editform=editform, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3264 pending=pending, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3265 repopath=repo.path, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3266 action=b'commit', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3267 ) |
30724
ee47e951c6f9
commit: fix unmodified message detection for the "--- >8 ----" magic
Yuya Nishihara <yuya@tcha.org>
parents:
30720
diff
changeset
|
3268 text = editortext |
30703
5c85c93cdd61
cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents:
30695
diff
changeset
|
3269 |
5c85c93cdd61
cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents:
30695
diff
changeset
|
3270 # strip away anything below this special string (used for editors that want |
5c85c93cdd61
cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents:
30695
diff
changeset
|
3271 # to display the diff) |
30724
ee47e951c6f9
commit: fix unmodified message detection for the "--- >8 ----" magic
Yuya Nishihara <yuya@tcha.org>
parents:
30720
diff
changeset
|
3272 stripbelow = re.search(_linebelow, text, flags=re.MULTILINE) |
30703
5c85c93cdd61
cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents:
30695
diff
changeset
|
3273 if stripbelow: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3274 text = text[: stripbelow.start()] |
30724
ee47e951c6f9
commit: fix unmodified message detection for the "--- >8 ----" magic
Yuya Nishihara <yuya@tcha.org>
parents:
30720
diff
changeset
|
3275 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3276 text = re.sub(b"(?m)^HG:.*(\n|$)", b"", text) |
21869
e353fac7db26
cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21832
diff
changeset
|
3277 os.chdir(olddir) |
e353fac7db26
cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21832
diff
changeset
|
3278 |
e353fac7db26
cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21832
diff
changeset
|
3279 if finishdesc: |
e353fac7db26
cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21832
diff
changeset
|
3280 text = finishdesc(text) |
e353fac7db26
cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21832
diff
changeset
|
3281 if not text.strip(): |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
3282 raise error.InputError(_(b"empty commit message")) |
26742
bec1a579ebc4
commit: abort when a committemplate is not changed
Tony Tung <tonytung@fb.com>
parents:
26639
diff
changeset
|
3283 if unchangedmessagedetection and editortext == templatetext: |
45827
8d72e29ad1e0
errors: introduce InputError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45812
diff
changeset
|
3284 raise error.InputError(_(b"commit message unchanged")) |
21869
e353fac7db26
cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21832
diff
changeset
|
3285 |
e353fac7db26
cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21832
diff
changeset
|
3286 return text |
e353fac7db26
cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21832
diff
changeset
|
3287 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3288 |
32878
a3a36bcf122e
commit: select template by spec.ref name
Yuya Nishihara <yuya@tcha.org>
parents:
32877
diff
changeset
|
3289 def buildcommittemplate(repo, ctx, subs, extramsg, ref): |
21924
5375ba75df40
cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21923
diff
changeset
|
3290 ui = repo.ui |
45264
8cce9f77ca73
templatespec: create a factory function for each type there is
Martin von Zweigbergk <martinvonz@google.com>
parents:
45072
diff
changeset
|
3291 spec = formatter.reference_templatespec(ref) |
35954
386c1e45e671
logcmdutil: drop default arguments from changesetdisplayer/templater() calls
Yuya Nishihara <yuya@tcha.org>
parents:
35926
diff
changeset
|
3292 t = logcmdutil.changesettemplater(ui, repo, spec) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3293 t.t.cache.update( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3294 (k, templater.unquotestring(v)) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3295 for k, v in repo.ui.configitems(b'committemplate') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3296 ) |
22013
de5cee8ba088
cmdutil: use '[committemplate]' section like as map file for style definition
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
22012
diff
changeset
|
3297 |
21924
5375ba75df40
cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21923
diff
changeset
|
3298 if not extramsg: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3299 extramsg = b'' # ensure that extramsg is string |
21924
5375ba75df40
cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21923
diff
changeset
|
3300 |
5375ba75df40
cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21923
diff
changeset
|
3301 ui.pushbuffer() |
5375ba75df40
cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21923
diff
changeset
|
3302 t.show(ctx, extramsg=extramsg) |
5375ba75df40
cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21923
diff
changeset
|
3303 return ui.popbuffer() |
5375ba75df40
cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21923
diff
changeset
|
3304 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3305 |
26426
0486c16ce621
cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents:
26389
diff
changeset
|
3306 def hgprefix(msg): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3307 return b"\n".join([b"HG: %s" % a for a in msg.split(b"\n") if a]) |
26426
0486c16ce621
cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents:
26389
diff
changeset
|
3308 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3309 |
21869
e353fac7db26
cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21832
diff
changeset
|
3310 def buildcommittext(repo, ctx, subs, extramsg): |
8407
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
3311 edittext = [] |
8707
0550dfe4fca1
commit: editor reads file lists from provided context
Matt Mackall <mpm@selenic.com>
parents:
8680
diff
changeset
|
3312 modified, added, removed = ctx.modified(), ctx.added(), ctx.removed() |
8407
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
3313 if ctx.description(): |
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
3314 edittext.append(ctx.description()) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3315 edittext.append(b"") |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3316 edittext.append(b"") # Empty line between message and comments. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3317 edittext.append( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3318 hgprefix( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3319 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3320 b"Enter commit message." |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3321 b" Lines beginning with 'HG:' are removed." |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3322 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3323 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3324 ) |
26426
0486c16ce621
cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents:
26389
diff
changeset
|
3325 edittext.append(hgprefix(extramsg)) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3326 edittext.append(b"HG: --") |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3327 edittext.append(hgprefix(_(b"user: %s") % ctx.user())) |
8407
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
3328 if ctx.p2(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3329 edittext.append(hgprefix(_(b"branch merge"))) |
8407
223000a687b0
commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents:
8390
diff
changeset
|
3330 if ctx.branch(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3331 edittext.append(hgprefix(_(b"branch '%s'") % ctx.branch())) |
24986
fb9b7b937b3e
bookmarks: simplify iscurrent to isactivewdirparent (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24955
diff
changeset
|
3332 if bookmarks.isactivewdirparent(repo): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3333 edittext.append(hgprefix(_(b"bookmark '%s'") % repo._activebookmark)) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3334 edittext.extend([hgprefix(_(b"subrepo %s") % s) for s in subs]) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3335 edittext.extend([hgprefix(_(b"added %s") % f) for f in added]) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3336 edittext.extend([hgprefix(_(b"changed %s") % f) for f in modified]) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3337 edittext.extend([hgprefix(_(b"removed %s") % f) for f in removed]) |
8707
0550dfe4fca1
commit: editor reads file lists from provided context
Matt Mackall <mpm@selenic.com>
parents:
8680
diff
changeset
|
3338 if not added and not modified and not removed: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3339 edittext.append(hgprefix(_(b"no files changed"))) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3340 edittext.append(b"") |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3341 |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3342 return b"\n".join(edittext) |
14297
2daa5179e73f
commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents:
14291
diff
changeset
|
3343 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3344 |
50824
489268c8ee7e
cmdutil: migrate `opts` on commitstatus() to native kwargs
Matt Harbison <matt_harbison@yahoo.com>
parents:
50556
diff
changeset
|
3345 def commitstatus(repo, node, branch, bheads=None, tip=None, **opts): |
18688
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3346 ctx = repo[node] |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3347 parents = ctx.parents() |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3348 |
45812
976b26bdd0d8
commit: warn the user when a commit already exists
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
45796
diff
changeset
|
3349 if tip is not None and repo.changelog.tip() == tip: |
976b26bdd0d8
commit: warn the user when a commit already exists
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
45796
diff
changeset
|
3350 # avoid reporting something like "committed new head" when |
976b26bdd0d8
commit: warn the user when a commit already exists
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
45796
diff
changeset
|
3351 # recommitting old changesets, and issue a helpful warning |
976b26bdd0d8
commit: warn the user when a commit already exists
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
45796
diff
changeset
|
3352 # for most instances |
46475
f0982c76ef1b
cmdutil: add a missing byte prefix to string introduce in 976b26bdd0d8
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46241
diff
changeset
|
3353 repo.ui.warn(_(b"warning: commit already existed in the repository!\n")) |
45812
976b26bdd0d8
commit: warn the user when a commit already exists
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
45796
diff
changeset
|
3354 elif ( |
50824
489268c8ee7e
cmdutil: migrate `opts` on commitstatus() to native kwargs
Matt Harbison <matt_harbison@yahoo.com>
parents:
50556
diff
changeset
|
3355 not opts.get('amend') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3356 and bheads |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3357 and node not in bheads |
45036
c05ac059749f
cleanup: use any() instead of checking truthiness of temporary list
Manuel Jacob <me@manueljacob.de>
parents:
44861
diff
changeset
|
3358 and not any( |
45037
0c40d2d151cb
cleanup: use slightly more meaningful name for temporary variable
Manuel Jacob <me@manueljacob.de>
parents:
45036
diff
changeset
|
3359 p.node() in bheads and p.branch() == branch for p in parents |
45036
c05ac059749f
cleanup: use any() instead of checking truthiness of temporary list
Manuel Jacob <me@manueljacob.de>
parents:
44861
diff
changeset
|
3360 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3361 ): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3362 repo.ui.status(_(b'created new head\n')) |
18688
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3363 # The message is not printed for initial roots. For the other |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3364 # changesets, it is printed in the following situations: |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3365 # |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3366 # Par column: for the 2 parents with ... |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3367 # N: null or no parent |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3368 # B: parent is on another named branch |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3369 # C: parent is a regular non head changeset |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3370 # H: parent was a branch head of the current branch |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3371 # Msg column: whether we print "created new head" message |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3372 # In the following, it is assumed that there already exists some |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3373 # initial branch heads of the current branch, otherwise nothing is |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3374 # printed anyway. |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3375 # |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3376 # Par Msg Comment |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3377 # N N y additional topo root |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3378 # |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3379 # B N y additional branch root |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3380 # C N y additional topo head |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3381 # H N n usual case |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3382 # |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3383 # B B y weird additional branch root |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3384 # C B y branch merge |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3385 # H B n merge with named branch |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3386 # |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3387 # C C y additional head from merge |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3388 # C H n merge with a head |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3389 # |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3390 # H H n head merge: head count decreases |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3391 |
50824
489268c8ee7e
cmdutil: migrate `opts` on commitstatus() to native kwargs
Matt Harbison <matt_harbison@yahoo.com>
parents:
50556
diff
changeset
|
3392 if not opts.get('close_branch'): |
18688
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3393 for r in parents: |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3394 if r.closesbranch() and r.branch() == branch: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3395 repo.ui.status( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3396 _(b'reopening closed branch head %d\n') % r.rev() |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3397 ) |
18688
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3398 |
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3399 if repo.ui.debugflag: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3400 repo.ui.write( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3401 _(b'committed changeset %d:%s\n') % (ctx.rev(), ctx.hex()) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3402 ) |
18688
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3403 elif repo.ui.verbose: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3404 repo.ui.write(_(b'committed changeset %d:%s\n') % (ctx.rev(), ctx)) |
18688
79107fad06aa
commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents:
18648
diff
changeset
|
3405 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3406 |
27943
02c5f8ad00ac
commit: factor the post commit status check into a cmdutil method
Matt Harbison <matt_harbison@yahoo.com>
parents:
27868
diff
changeset
|
3407 def postcommitstatus(repo, pats, opts): |
02c5f8ad00ac
commit: factor the post commit status check into a cmdutil method
Matt Harbison <matt_harbison@yahoo.com>
parents:
27868
diff
changeset
|
3408 return repo.status(match=scmutil.match(repo[None], pats, opts)) |
02c5f8ad00ac
commit: factor the post commit status check into a cmdutil method
Matt Harbison <matt_harbison@yahoo.com>
parents:
27868
diff
changeset
|
3409 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3410 |
45375
8c466bcb0879
revert: remove dangerous `parents` argument from `cmdutil.revert()`
Martin von Zweigbergk <martinvonz@google.com>
parents:
45372
diff
changeset
|
3411 def revert(ui, repo, ctx, *pats, **opts): |
35147
3da4bd50103d
py3: fix handling of keyword arguments in revert
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35123
diff
changeset
|
3412 opts = pycompat.byteskwargs(opts) |
45375
8c466bcb0879
revert: remove dangerous `parents` argument from `cmdutil.revert()`
Martin von Zweigbergk <martinvonz@google.com>
parents:
45372
diff
changeset
|
3413 parent, p2 = repo.dirstate.parents() |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3414 node = ctx.node() |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3415 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3416 mf = ctx.manifest() |
21579
87a972b5c039
revert: use p2 as parent when reverting against it
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21578
diff
changeset
|
3417 if node == p2: |
87a972b5c039
revert: use p2 as parent when reverting against it
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21578
diff
changeset
|
3418 parent = p2 |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3419 |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3420 # need all matching names in dirstate and manifest of target rev, |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3421 # so have to walk both. do not print errors if files exist in one |
24451
c3bbafef25d6
revert: comment that filesets are always evaluated against workingctx
Yuya Nishihara <yuya@tcha.org>
parents:
24450
diff
changeset
|
3422 # but not other. in both cases, filesets should be evaluated against |
c3bbafef25d6
revert: comment that filesets are always evaluated against workingctx
Yuya Nishihara <yuya@tcha.org>
parents:
24450
diff
changeset
|
3423 # workingctx to get consistent result (issue4497). this means 'set:**' |
c3bbafef25d6
revert: comment that filesets are always evaluated against workingctx
Yuya Nishihara <yuya@tcha.org>
parents:
24450
diff
changeset
|
3424 # cannot be used to select missing files from target rev. |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3425 |
21575
8262c2a39ab8
revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21574
diff
changeset
|
3426 # `names` is a mapping for all elements in working copy and target revision |
8262c2a39ab8
revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21574
diff
changeset
|
3427 # The mapping is in the form: |
39287
6b81d2ff118f
cmdutil: fix typo in revert()
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
39278
diff
changeset
|
3428 # <abs path in repo> -> (<path from CWD>, <exactly specified by matcher?>) |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3429 names = {} |
41605
7068c6b0114b
revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41597
diff
changeset
|
3430 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3431 |
50038
6cdcab3ae3fa
dirstate: use `dirstate.change_files` to scope the change in `revert`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50029
diff
changeset
|
3432 with repo.wlock(), repo.dirstate.changing_files(repo): |
21575
8262c2a39ab8
revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21574
diff
changeset
|
3433 ## filling of the `names` mapping |
8262c2a39ab8
revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21574
diff
changeset
|
3434 # walk dirstate to fill `names` |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3435 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3436 interactive = opts.get(b'interactive', False) |
24449
bab983bb6fd1
revert: define 'wctx' a little earlier and use it more
Martin von Zweigbergk <martinvonz@google.com>
parents:
24438
diff
changeset
|
3437 wctx = repo[None] |
bab983bb6fd1
revert: define 'wctx' a little earlier and use it more
Martin von Zweigbergk <martinvonz@google.com>
parents:
24438
diff
changeset
|
3438 m = scmutil.match(wctx, pats, opts) |
24479
871485bd03fd
revert: move calculation of targetsubs earlier
Matt Mackall <mpm@selenic.com>
parents:
24476
diff
changeset
|
3439 |
871485bd03fd
revert: move calculation of targetsubs earlier
Matt Mackall <mpm@selenic.com>
parents:
24476
diff
changeset
|
3440 # we'll need this later |
871485bd03fd
revert: move calculation of targetsubs earlier
Matt Mackall <mpm@selenic.com>
parents:
24476
diff
changeset
|
3441 targetsubs = sorted(s for s in wctx.substate if m(s)) |
871485bd03fd
revert: move calculation of targetsubs earlier
Matt Mackall <mpm@selenic.com>
parents:
24476
diff
changeset
|
3442 |
24450
961790c35b4f
revert: take fast path also when not reverting to '.'
Martin von Zweigbergk <martinvonz@google.com>
parents:
24449
diff
changeset
|
3443 if not m.always(): |
32362
7b3c27af90c2
cmdutil: use repo[None].walk instead of repo.walk
Augie Fackler <augie@google.com>
parents:
32343
diff
changeset
|
3444 matcher = matchmod.badmatch(m, lambda x, y: False) |
32382
c87db79b9507
cleanup: reuse existing wctx variables instead of calling repo[None]
Martin von Zweigbergk <martinvonz@google.com>
parents:
32375
diff
changeset
|
3445 for abs in wctx.walk(matcher): |
41605
7068c6b0114b
revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41597
diff
changeset
|
3446 names[abs] = m.exact(abs) |
22573
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3447 |
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3448 # walk target manifest to fill `names` |
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3449 |
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3450 def badfn(path, msg): |
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3451 if path in names: |
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3452 return |
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3453 if path in ctx.substate: |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3454 return |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3455 path_ = path + b'/' |
22573
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3456 for f in names: |
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3457 if f.startswith(path_): |
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3458 return |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3459 ui.warn(b"%s: %s\n" % (uipathfn(path), msg)) |
22573
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3460 |
25439
aaede04c0ba6
revert: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25438
diff
changeset
|
3461 for abs in ctx.walk(matchmod.badmatch(m, badfn)): |
22573
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3462 if abs not in names: |
41605
7068c6b0114b
revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41597
diff
changeset
|
3463 names[abs] = m.exact(abs) |
22573
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3464 |
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3465 # Find status of all file in `names`. |
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3466 m = scmutil.matchfiles(repo, names) |
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3467 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3468 changes = repo.status( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3469 node1=node, match=m, unknown=True, ignored=True, clean=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3470 ) |
22573
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3471 else: |
24450
961790c35b4f
revert: take fast path also when not reverting to '.'
Martin von Zweigbergk <martinvonz@google.com>
parents:
24449
diff
changeset
|
3472 changes = repo.status(node1=node, match=m) |
22573
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3473 for kind in changes: |
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3474 for abs in kind: |
41605
7068c6b0114b
revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41597
diff
changeset
|
3475 names[abs] = m.exact(abs) |
22573
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3476 |
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3477 m = scmutil.matchfiles(repo, names) |
f528bfb25b45
revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents:
22551
diff
changeset
|
3478 |
23374
aa0a430d9c75
revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents:
23327
diff
changeset
|
3479 modified = set(changes.modified) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3480 added = set(changes.added) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3481 removed = set(changes.removed) |
23374
aa0a430d9c75
revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents:
23327
diff
changeset
|
3482 _deleted = set(changes.deleted) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3483 unknown = set(changes.unknown) |
23374
aa0a430d9c75
revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents:
23327
diff
changeset
|
3484 unknown.update(changes.ignored) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3485 clean = set(changes.clean) |
22610
0f323ed8effd
revert: track added files with local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22609
diff
changeset
|
3486 modadded = set() |
22185
afead12e724b
revert: triage "deleted" files into more appropriate categories
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22173
diff
changeset
|
3487 |
24180
d8e0c591781c
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
24176
diff
changeset
|
3488 # We need to account for the state of the file in the dirstate, |
d8e0c591781c
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
24176
diff
changeset
|
3489 # even when we revert against something else than parent. This will |
22155
530390629842
revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22154
diff
changeset
|
3490 # slightly alter the behavior of revert (doing back up or not, delete |
23139
e53f6b72a0e4
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
23101
diff
changeset
|
3491 # or just forget etc). |
22155
530390629842
revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22154
diff
changeset
|
3492 if parent == node: |
530390629842
revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22154
diff
changeset
|
3493 dsmodified = modified |
530390629842
revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22154
diff
changeset
|
3494 dsadded = added |
530390629842
revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22154
diff
changeset
|
3495 dsremoved = removed |
23403
edf29f9c15f0
revert: look for copy information for all local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23101
diff
changeset
|
3496 # store all local modifications, useful later for rename detection |
edf29f9c15f0
revert: look for copy information for all local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23101
diff
changeset
|
3497 localchanges = dsmodified | dsadded |
22155
530390629842
revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22154
diff
changeset
|
3498 modified, added, removed = set(), set(), set() |
530390629842
revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22154
diff
changeset
|
3499 else: |
530390629842
revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22154
diff
changeset
|
3500 changes = repo.status(node1=parent, match=m) |
23374
aa0a430d9c75
revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents:
23327
diff
changeset
|
3501 dsmodified = set(changes.modified) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3502 dsadded = set(changes.added) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3503 dsremoved = set(changes.removed) |
23403
edf29f9c15f0
revert: look for copy information for all local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23101
diff
changeset
|
3504 # store all local modifications, useful later for rename detection |
edf29f9c15f0
revert: look for copy information for all local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23101
diff
changeset
|
3505 localchanges = dsmodified | dsadded |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3506 |
22188
0ad619c5e1a4
revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22187
diff
changeset
|
3507 # only take into account for removes between wc and target |
0ad619c5e1a4
revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22187
diff
changeset
|
3508 clean |= dsremoved - removed |
0ad619c5e1a4
revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22187
diff
changeset
|
3509 dsremoved &= removed |
0ad619c5e1a4
revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22187
diff
changeset
|
3510 # distinct between dirstate remove and other |
0ad619c5e1a4
revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22187
diff
changeset
|
3511 removed -= dsremoved |
0ad619c5e1a4
revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22187
diff
changeset
|
3512 |
22610
0f323ed8effd
revert: track added files with local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22609
diff
changeset
|
3513 modadded = added & dsmodified |
0f323ed8effd
revert: track added files with local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22609
diff
changeset
|
3514 added -= modadded |
0f323ed8effd
revert: track added files with local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22609
diff
changeset
|
3515 |
22190
55308ab8117c
revert: use modified information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22189
diff
changeset
|
3516 # tell newly modified apart. |
55308ab8117c
revert: use modified information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22189
diff
changeset
|
3517 dsmodified &= modified |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3518 dsmodified |= modified & dsadded # dirstate added may need backup |
22190
55308ab8117c
revert: use modified information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22189
diff
changeset
|
3519 modified -= dsmodified |
55308ab8117c
revert: use modified information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22189
diff
changeset
|
3520 |
22488
6c52ed3f888e
revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22485
diff
changeset
|
3521 # We need to wait for some post-processing to update this set |
6c52ed3f888e
revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22485
diff
changeset
|
3522 # before making the distinction. The dirstate will be used for |
6c52ed3f888e
revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22485
diff
changeset
|
3523 # that purpose. |
22208
d3659b3795e9
revert: simplify handling of `added` files
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22205
diff
changeset
|
3524 dsadded = added |
d3659b3795e9
revert: simplify handling of `added` files
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22205
diff
changeset
|
3525 |
22209
06fbd9518bc5
revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22208
diff
changeset
|
3526 # in case of merge, files that are actually added can be reported as |
06fbd9518bc5
revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22208
diff
changeset
|
3527 # modified, we need to post process the result |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46969
diff
changeset
|
3528 if p2 != repo.nullid: |
31134
c22253c4c1b8
revert: remove set(mf) because it's O(manifest)
Durham Goode <durham@fb.com>
parents:
31078
diff
changeset
|
3529 mergeadd = set(dsmodified) |
c22253c4c1b8
revert: remove set(mf) because it's O(manifest)
Durham Goode <durham@fb.com>
parents:
31078
diff
changeset
|
3530 for path in dsmodified: |
c22253c4c1b8
revert: remove set(mf) because it's O(manifest)
Durham Goode <durham@fb.com>
parents:
31078
diff
changeset
|
3531 if path in mf: |
c22253c4c1b8
revert: remove set(mf) because it's O(manifest)
Durham Goode <durham@fb.com>
parents:
31078
diff
changeset
|
3532 mergeadd.remove(path) |
22209
06fbd9518bc5
revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22208
diff
changeset
|
3533 dsadded |= mergeadd |
06fbd9518bc5
revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22208
diff
changeset
|
3534 dsmodified -= mergeadd |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3535 |
21575
8262c2a39ab8
revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21574
diff
changeset
|
3536 # if f is a rename, update `names` to also revert the source |
23403
edf29f9c15f0
revert: look for copy information for all local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
23101
diff
changeset
|
3537 for f in localchanges: |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3538 src = repo.dirstate.copied(f) |
22213
f1debbcd71cd
revert: add an XXX about rename tracking
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22212
diff
changeset
|
3539 # XXX should we check for rename down to target node? |
48104
e8d6261513b9
dirstate-item: use item's property instead of `state` in revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48102
diff
changeset
|
3540 if ( |
e8d6261513b9
dirstate-item: use item's property instead of `state` in revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48102
diff
changeset
|
3541 src |
e8d6261513b9
dirstate-item: use item's property instead of `state` in revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48102
diff
changeset
|
3542 and src not in names |
e8d6261513b9
dirstate-item: use item's property instead of `state` in revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48102
diff
changeset
|
3543 and repo.dirstate.get_entry(src).removed |
e8d6261513b9
dirstate-item: use item's property instead of `state` in revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48102
diff
changeset
|
3544 ): |
22154
fc422de25773
revert: prefix variable names for dirstate status with "ds"
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22153
diff
changeset
|
3545 dsremoved.add(src) |
41605
7068c6b0114b
revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41597
diff
changeset
|
3546 names[src] = True |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3547 |
31157
accdd5e62066
revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents:
31134
diff
changeset
|
3548 # determine the exact nature of the deleted changesets |
accdd5e62066
revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents:
31134
diff
changeset
|
3549 deladded = set(_deleted) |
accdd5e62066
revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents:
31134
diff
changeset
|
3550 for path in _deleted: |
accdd5e62066
revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents:
31134
diff
changeset
|
3551 if path in mf: |
accdd5e62066
revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents:
31134
diff
changeset
|
3552 deladded.remove(path) |
accdd5e62066
revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents:
31134
diff
changeset
|
3553 deleted = _deleted - deladded |
accdd5e62066
revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents:
31134
diff
changeset
|
3554 |
22488
6c52ed3f888e
revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22485
diff
changeset
|
3555 # distinguish between file to forget and the other |
6c52ed3f888e
revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22485
diff
changeset
|
3556 added = set() |
6c52ed3f888e
revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22485
diff
changeset
|
3557 for abs in dsadded: |
48104
e8d6261513b9
dirstate-item: use item's property instead of `state` in revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48102
diff
changeset
|
3558 if not repo.dirstate.get_entry(abs).added: |
22488
6c52ed3f888e
revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22485
diff
changeset
|
3559 added.add(abs) |
6c52ed3f888e
revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22485
diff
changeset
|
3560 dsadded -= added |
6c52ed3f888e
revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22485
diff
changeset
|
3561 |
22490
bcab7bc7280e
revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22489
diff
changeset
|
3562 for abs in deladded: |
48104
e8d6261513b9
dirstate-item: use item's property instead of `state` in revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48102
diff
changeset
|
3563 if repo.dirstate.get_entry(abs).added: |
22490
bcab7bc7280e
revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22489
diff
changeset
|
3564 dsadded.add(abs) |
bcab7bc7280e
revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22489
diff
changeset
|
3565 deladded -= dsadded |
bcab7bc7280e
revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22489
diff
changeset
|
3566 |
22396
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3567 # For files marked as removed, we check if an unknown file is present at |
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3568 # the same path. If a such file exists it may need to be backed up. |
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3569 # Making the distinction at this stage helps have simpler backup |
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3570 # logic. |
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3571 removunk = set() |
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3572 for abs in removed: |
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3573 target = repo.wjoin(abs) |
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3574 if os.path.lexists(target): |
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3575 removunk.add(abs) |
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3576 removed -= removunk |
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3577 |
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3578 dsremovunk = set() |
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3579 for abs in dsremoved: |
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3580 target = repo.wjoin(abs) |
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3581 if os.path.lexists(target): |
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3582 dsremovunk.add(abs) |
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3583 dsremoved -= dsremovunk |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3584 |
21575
8262c2a39ab8
revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21574
diff
changeset
|
3585 # action to be actually performed by revert |
8262c2a39ab8
revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21574
diff
changeset
|
3586 # (<list of file>, message>) tuple |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3587 actions = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3588 b'revert': ([], _(b'reverting %s\n')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3589 b'add': ([], _(b'adding %s\n')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3590 b'remove': ([], _(b'removing %s\n')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3591 b'drop': ([], _(b'removing %s\n')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3592 b'forget': ([], _(b'forgetting %s\n')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3593 b'undelete': ([], _(b'undeleting %s\n')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3594 b'noop': (None, _(b'no changes needed to %s\n')), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3595 b'unknown': (None, _(b'file not managed: %s\n')), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3596 } |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3597 |
22608
bf0ecb224316
revert: small refactoring in the way backup value are handled
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22588
diff
changeset
|
3598 # "constant" that convey the backup strategy. |
bf0ecb224316
revert: small refactoring in the way backup value are handled
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22588
diff
changeset
|
3599 # All set to `discard` if `no-backup` is set do avoid checking |
bf0ecb224316
revert: small refactoring in the way backup value are handled
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22588
diff
changeset
|
3600 # no_backup lower in the code. |
22609
3760ebf786b8
revert: distinguish between "check" and "backup" strategy
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22608
diff
changeset
|
3601 # These values are ordered for comparison purposes |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3602 backupinteractive = 3 # do backup if interactively modified |
22608
bf0ecb224316
revert: small refactoring in the way backup value are handled
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22588
diff
changeset
|
3603 backup = 2 # unconditionally do backup |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3604 check = 1 # check if the existing file differs from target |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3605 discard = 0 # never do backup |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3606 if opts.get(b'no_backup'): |
29498
1b38cfde9530
revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents:
29427
diff
changeset
|
3607 backupinteractive = backup = check = discard |
1b38cfde9530
revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents:
29427
diff
changeset
|
3608 if interactive: |
1b38cfde9530
revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents:
29427
diff
changeset
|
3609 dsmodifiedbackup = backupinteractive |
1b38cfde9530
revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents:
29427
diff
changeset
|
3610 else: |
1b38cfde9530
revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents:
29427
diff
changeset
|
3611 dsmodifiedbackup = backup |
1b38cfde9530
revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents:
29427
diff
changeset
|
3612 tobackup = set() |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3613 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3614 backupanddel = actions[b'remove'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3615 if not opts.get(b'no_backup'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3616 backupanddel = actions[b'drop'] |
22611
2ff28e07d7d6
revert: properly back up added files with local modification
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22610
diff
changeset
|
3617 |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3618 disptable = ( |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3619 # dispatch table: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3620 # file state |
22153
fc8bc2787528
revert: move manifest membership condition outside of the loop
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22013
diff
changeset
|
3621 # action |
fc8bc2787528
revert: move manifest membership condition outside of the loop
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22013
diff
changeset
|
3622 # make backup |
22371
81ad62defef5
revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22370
diff
changeset
|
3623 ## Sets that results that will change file on disk |
81ad62defef5
revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22370
diff
changeset
|
3624 # Modified compared to target, no local change |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3625 (modified, actions[b'revert'], discard), |
22397
1db04829bdc1
revert: distinguish between deleted file and locally modified
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22396
diff
changeset
|
3626 # Modified compared to target, but local file is deleted |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3627 (deleted, actions[b'revert'], discard), |
22371
81ad62defef5
revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22370
diff
changeset
|
3628 # Modified compared to target, local change |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3629 (dsmodified, actions[b'revert'], dsmodifiedbackup), |
22371
81ad62defef5
revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22370
diff
changeset
|
3630 # Added since target |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3631 (added, actions[b'remove'], discard), |
22488
6c52ed3f888e
revert: split between newly added file and file added in other changeset
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22485
diff
changeset
|
3632 # Added in working directory |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3633 (dsadded, actions[b'forget'], discard), |
22610
0f323ed8effd
revert: track added files with local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22609
diff
changeset
|
3634 # Added since target, have local modification |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3635 (modadded, backupanddel, backup), |
22490
bcab7bc7280e
revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22489
diff
changeset
|
3636 # Added since target but file is missing in working directory |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3637 (deladded, actions[b'drop'], discard), |
22371
81ad62defef5
revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22370
diff
changeset
|
3638 # Removed since target, before working copy parent |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3639 (removed, actions[b'add'], discard), |
22396
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3640 # Same as `removed` but an unknown file exists at the same path |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3641 (removunk, actions[b'add'], check), |
22371
81ad62defef5
revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22370
diff
changeset
|
3642 # Removed since targe, marked as such in working copy parent |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3643 (dsremoved, actions[b'undelete'], discard), |
22396
c0213f2cb942
revert: detect unknown files in the same path as files marked as removed
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22395
diff
changeset
|
3644 # Same as `dsremoved` but an unknown file exists at the same path |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3645 (dsremovunk, actions[b'undelete'], check), |
22371
81ad62defef5
revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22370
diff
changeset
|
3646 ## the following sets does not result in any file changes |
81ad62defef5
revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22370
diff
changeset
|
3647 # File with no modification |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3648 (clean, actions[b'noop'], discard), |
22371
81ad62defef5
revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22370
diff
changeset
|
3649 # Existing file, not tracked anywhere |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3650 (unknown, actions[b'unknown'], discard), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3651 ) |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3652 |
41605
7068c6b0114b
revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41597
diff
changeset
|
3653 for abs, exact in sorted(names.items()): |
21575
8262c2a39ab8
revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21574
diff
changeset
|
3654 # target file to be touch on disk (relative to cwd) |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3655 target = repo.wjoin(abs) |
21575
8262c2a39ab8
revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21574
diff
changeset
|
3656 # search the entry in the dispatch table. |
22212
f18aca03ddd9
revert: inline a now useless closure
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22211
diff
changeset
|
3657 # if the file is in any of these sets, it was touched in the working |
21575
8262c2a39ab8
revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21574
diff
changeset
|
3658 # directory parent and we are sure it needs to be reverted. |
22232
91df98701e9e
revert: explode the action tuple in the for loop
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22231
diff
changeset
|
3659 for table, (xlist, msg), dobackup in disptable: |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3660 if abs not in table: |
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3661 continue |
22233
4ab61b24e20c
revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22232
diff
changeset
|
3662 if xlist is not None: |
4ab61b24e20c
revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22232
diff
changeset
|
3663 xlist.append(abs) |
29498
1b38cfde9530
revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents:
29427
diff
changeset
|
3664 if dobackup: |
1b38cfde9530
revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents:
29427
diff
changeset
|
3665 # If in interactive mode, don't automatically create |
1b38cfde9530
revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents:
29427
diff
changeset
|
3666 # .orig files (issue4793) |
1b38cfde9530
revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents:
29427
diff
changeset
|
3667 if dobackup == backupinteractive: |
1b38cfde9530
revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents:
29427
diff
changeset
|
3668 tobackup.add(abs) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3669 elif backup <= dobackup or wctx[abs].cmp(ctx[abs]): |
41605
7068c6b0114b
revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41597
diff
changeset
|
3670 absbakname = scmutil.backuppath(ui, repo, abs) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3671 bakname = os.path.relpath( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3672 absbakname, start=repo.root |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3673 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3674 ui.note( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3675 _(b'saving current version of %s as %s\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3676 % (uipathfn(abs), uipathfn(bakname)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3677 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3678 if not opts.get(b'dry_run'): |
24475
06cbff4674a3
revert: fix --interactive on local modification (issue4576)
Laurent Charignon <lcharignon@fb.com>
parents:
24472
diff
changeset
|
3679 if interactive: |
41605
7068c6b0114b
revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41597
diff
changeset
|
3680 util.copyfile(target, absbakname) |
24475
06cbff4674a3
revert: fix --interactive on local modification (issue4576)
Laurent Charignon <lcharignon@fb.com>
parents:
24472
diff
changeset
|
3681 else: |
41605
7068c6b0114b
revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41597
diff
changeset
|
3682 util.rename(target, absbakname) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3683 if opts.get(b'dry_run'): |
39405
cb70501d8b71
revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
39404
diff
changeset
|
3684 if ui.verbose or not exact: |
41605
7068c6b0114b
revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41597
diff
changeset
|
3685 ui.status(msg % uipathfn(abs)) |
22233
4ab61b24e20c
revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22232
diff
changeset
|
3686 elif exact: |
41605
7068c6b0114b
revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41597
diff
changeset
|
3687 ui.warn(msg % uipathfn(abs)) |
16304
a740fa28d718
revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
16283
diff
changeset
|
3688 break |
21575
8262c2a39ab8
revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21574
diff
changeset
|
3689 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3690 if not opts.get(b'dry_run'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3691 needdata = (b'revert', b'add', b'undelete') |
35923
efbd04238029
cmdutil: convert _revertprefetch() to a generic stored file hook (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
35910
diff
changeset
|
3692 oplist = [actions[name][0] for name in needdata] |
37762
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37756
diff
changeset
|
3693 prefetch = scmutil.prefetchfiles |
45072
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
45037
diff
changeset
|
3694 matchfiles = scmutil.matchfiles( |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
45037
diff
changeset
|
3695 repo, [f for sublist in oplist for f in sublist] |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
45037
diff
changeset
|
3696 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3697 prefetch( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
3698 repo, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
3699 [(ctx.rev(), matchfiles)], |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3700 ) |
42071
db72f9f6580e
interactive: do not prompt about files given in command line
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
42057
diff
changeset
|
3701 match = scmutil.match(repo[None], pats) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3702 _performrevert( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3703 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3704 ctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3705 names, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3706 uipathfn, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3707 actions, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3708 match, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3709 interactive, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3710 tobackup, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3711 ) |
19129
bd19587a3347
revert: ensure that copies and renames are honored (issue3920)
Bryan O'Sullivan <bryano@fb.com>
parents:
19024
diff
changeset
|
3712 |
24134
afed5d2e7985
revert: display full subrepo output with --dry-run
Matt Harbison <matt_harbison@yahoo.com>
parents:
24064
diff
changeset
|
3713 if targetsubs: |
afed5d2e7985
revert: display full subrepo output with --dry-run
Matt Harbison <matt_harbison@yahoo.com>
parents:
24064
diff
changeset
|
3714 # Revert the subrepos on the revert list |
afed5d2e7985
revert: display full subrepo output with --dry-run
Matt Harbison <matt_harbison@yahoo.com>
parents:
24064
diff
changeset
|
3715 for sub in targetsubs: |
24463
06d199e66bbc
revert: handle subrepos missing in the given --rev
Matt Harbison <matt_harbison@yahoo.com>
parents:
24455
diff
changeset
|
3716 try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3717 wctx.sub(sub).revert( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3718 ctx.substate[sub], *pats, **pycompat.strkwargs(opts) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3719 ) |
24463
06d199e66bbc
revert: handle subrepos missing in the given --rev
Matt Harbison <matt_harbison@yahoo.com>
parents:
24455
diff
changeset
|
3720 except KeyError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3721 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3722 b"subrepository '%s' does not exist in %s!" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3723 % (sub, short(ctx.node())) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3724 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3725 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3726 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3727 def _performrevert( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3728 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3729 ctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3730 names, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3731 uipathfn, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3732 actions, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3733 match, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3734 interactive=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3735 tobackup=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3736 ): |
21576
33395a7e5527
revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21575
diff
changeset
|
3737 """function that actually perform all the actions computed for revert |
20571
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3738 |
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3739 This is an independent function to let extension to plug in and react to |
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3740 the imminent revert. |
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3741 |
21024
7731a2281cf0
spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents:
20790
diff
changeset
|
3742 Make sure you have the working directory locked when calling this function. |
20571
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3743 """ |
45375
8c466bcb0879
revert: remove dangerous `parents` argument from `cmdutil.revert()`
Martin von Zweigbergk <martinvonz@google.com>
parents:
45372
diff
changeset
|
3744 parent, p2 = repo.dirstate.parents() |
20571
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3745 node = ctx.node() |
27985
79139c7a88bd
revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents:
27973
diff
changeset
|
3746 excluded_files = [] |
79139c7a88bd
revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents:
27973
diff
changeset
|
3747 |
20571
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3748 def checkout(f): |
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3749 fc = ctx[f] |
25755
72d395e399c1
cmdutil: remove useless dirstate.normallookup() invocation in revert()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25739
diff
changeset
|
3750 repo.wwrite(f, fc.data(), fc.flags()) |
20571
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3751 |
30532
66b162fa3ffa
revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30531
diff
changeset
|
3752 def doremove(f): |
66b162fa3ffa
revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30531
diff
changeset
|
3753 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3754 rmdir = repo.ui.configbool(b'experimental', b'removeemptydirs') |
38493
da2a7d8354b2
unlinkpath: make empty directory removal optional (issue5901) (issue5826)
Kyle Lippincott <spectral@google.com>
parents:
38461
diff
changeset
|
3755 repo.wvfs.unlinkpath(f, rmdir=rmdir) |
30532
66b162fa3ffa
revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30531
diff
changeset
|
3756 except OSError: |
66b162fa3ffa
revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30531
diff
changeset
|
3757 pass |
47602
8f0c3533e28c
revert: use `set_untracked` when performing a revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47596
diff
changeset
|
3758 repo.dirstate.set_untracked(f) |
30532
66b162fa3ffa
revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30531
diff
changeset
|
3759 |
39405
cb70501d8b71
revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
39404
diff
changeset
|
3760 def prntstatusmsg(action, f): |
41605
7068c6b0114b
revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41597
diff
changeset
|
3761 exact = names[f] |
39405
cb70501d8b71
revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
39404
diff
changeset
|
3762 if repo.ui.verbose or not exact: |
41605
7068c6b0114b
revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41597
diff
changeset
|
3763 repo.ui.status(actions[action][1] % uipathfn(f)) |
39405
cb70501d8b71
revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
39404
diff
changeset
|
3764 |
33649
377e8ddaebef
pathauditor: disable cache of audited paths by default (issue5628)
Yuya Nishihara <yuya@tcha.org>
parents:
33617
diff
changeset
|
3765 audit_path = pathutil.pathauditor(repo.root, cached=True) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3766 for f in actions[b'forget'][0]: |
27985
79139c7a88bd
revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents:
27973
diff
changeset
|
3767 if interactive: |
30530
74013a831872
style: avoid an unnecessary line split
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30519
diff
changeset
|
3768 choice = repo.ui.promptchoice( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3769 _(b"forget added file %s (Yn)?$$ &Yes $$ &No") % uipathfn(f) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3770 ) |
27985
79139c7a88bd
revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents:
27973
diff
changeset
|
3771 if choice == 0: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3772 prntstatusmsg(b'forget', f) |
47603
7c64688e554d
revert: use `set_untracked` instead of `drop` when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47602
diff
changeset
|
3773 repo.dirstate.set_untracked(f) |
27985
79139c7a88bd
revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents:
27973
diff
changeset
|
3774 else: |
36194
39b3aab6231e
revert: use an exact matcher in interactive diff selection (issue5789)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
36141
diff
changeset
|
3775 excluded_files.append(f) |
27985
79139c7a88bd
revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents:
27973
diff
changeset
|
3776 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3777 prntstatusmsg(b'forget', f) |
47603
7c64688e554d
revert: use `set_untracked` instead of `drop` when applicable
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47602
diff
changeset
|
3778 repo.dirstate.set_untracked(f) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3779 for f in actions[b'remove'][0]: |
20571
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3780 audit_path(f) |
30532
66b162fa3ffa
revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30531
diff
changeset
|
3781 if interactive: |
66b162fa3ffa
revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30531
diff
changeset
|
3782 choice = repo.ui.promptchoice( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3783 _(b"remove added file %s (Yn)?$$ &Yes $$ &No") % uipathfn(f) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3784 ) |
30532
66b162fa3ffa
revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30531
diff
changeset
|
3785 if choice == 0: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3786 prntstatusmsg(b'remove', f) |
30532
66b162fa3ffa
revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30531
diff
changeset
|
3787 doremove(f) |
66b162fa3ffa
revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30531
diff
changeset
|
3788 else: |
36194
39b3aab6231e
revert: use an exact matcher in interactive diff selection (issue5789)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
36141
diff
changeset
|
3789 excluded_files.append(f) |
30532
66b162fa3ffa
revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30531
diff
changeset
|
3790 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3791 prntstatusmsg(b'remove', f) |
30532
66b162fa3ffa
revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30531
diff
changeset
|
3792 doremove(f) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3793 for f in actions[b'drop'][0]: |
22491
5e16fe6fdd32
revert: add a `drop` action
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22490
diff
changeset
|
3794 audit_path(f) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3795 prntstatusmsg(b'drop', f) |
47602
8f0c3533e28c
revert: use `set_untracked` when performing a revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47596
diff
changeset
|
3796 repo.dirstate.set_untracked(f) |
20571
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3797 |
48384
9f1b9e128788
dirstate: do no use `set_clean` in revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48364
diff
changeset
|
3798 # We are reverting to our parent. If possible, we had like `hg status` |
9f1b9e128788
dirstate: do no use `set_clean` in revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48364
diff
changeset
|
3799 # to report the file as clean. We have to be less agressive for |
9f1b9e128788
dirstate: do no use `set_clean` in revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48364
diff
changeset
|
3800 # merges to avoid losing information about copy introduced by the merge. |
9f1b9e128788
dirstate: do no use `set_clean` in revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48364
diff
changeset
|
3801 # This might comes with bugs ? |
9f1b9e128788
dirstate: do no use `set_clean` in revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48364
diff
changeset
|
3802 reset_copy = p2 == repo.nullid |
9f1b9e128788
dirstate: do no use `set_clean` in revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48364
diff
changeset
|
3803 |
9f1b9e128788
dirstate: do no use `set_clean` in revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48364
diff
changeset
|
3804 def normal(filename): |
9f1b9e128788
dirstate: do no use `set_clean` in revert
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48364
diff
changeset
|
3805 return repo.dirstate.set_tracked(filename, reset_copy=reset_copy) |
24359
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3806 |
25259
5b05f10c5024
revert: fix edition of newly added file during --interactive
Laurent Charignon <lcharignon@fb.com>
parents:
25258
diff
changeset
|
3807 newlyaddedandmodifiedfiles = set() |
24359
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3808 if interactive: |
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3809 # Prompt the user for changes to revert |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3810 torevert = [f for f in actions[b'revert'][0] if f not in excluded_files] |
36194
39b3aab6231e
revert: use an exact matcher in interactive diff selection (issue5789)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
36141
diff
changeset
|
3811 m = scmutil.matchfiles(repo, torevert) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3812 diffopts = patch.difffeatureopts( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3813 repo.ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3814 whitespace=True, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3815 section=b'commands', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3816 configprefix=b'revert.interactive.', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3817 ) |
25258
f37a69ec3f47
revert: make revert --interactive use git style diff
Laurent Charignon <lcharignon@fb.com>
parents:
25257
diff
changeset
|
3818 diffopts.nodates = True |
f37a69ec3f47
revert: make revert --interactive use git style diff
Laurent Charignon <lcharignon@fb.com>
parents:
25257
diff
changeset
|
3819 diffopts.git = True |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3820 operation = b'apply' |
41987
c1d83d916e85
revert: option to choose what to keep, not what to discard
Martin von Zweigbergk <martinvonz@google.com>
parents:
41985
diff
changeset
|
3821 if node == parent: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3822 if repo.ui.configbool( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3823 b'experimental', b'revert.interactive.select-to-keep' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3824 ): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3825 operation = b'keep' |
41987
c1d83d916e85
revert: option to choose what to keep, not what to discard
Martin von Zweigbergk <martinvonz@google.com>
parents:
41985
diff
changeset
|
3826 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3827 operation = b'discard' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3828 |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3829 if operation == b'apply': |
41987
c1d83d916e85
revert: option to choose what to keep, not what to discard
Martin von Zweigbergk <martinvonz@google.com>
parents:
41985
diff
changeset
|
3830 diff = patch.diff(repo, None, ctx.node(), m, opts=diffopts) |
c1d83d916e85
revert: option to choose what to keep, not what to discard
Martin von Zweigbergk <martinvonz@google.com>
parents:
41985
diff
changeset
|
3831 else: |
25424
69609f43c752
revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents:
25358
diff
changeset
|
3832 diff = patch.diff(repo, ctx.node(), None, m, opts=diffopts) |
47565
00ae1fb6c459
cmdutil: fix newandmodified file accounting for --interactive commits
Daniel Ploch <dploch@google.com>
parents:
47432
diff
changeset
|
3833 original_headers = patch.parsepatch(diff) |
25424
69609f43c752
revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents:
25358
diff
changeset
|
3834 |
24359
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3835 try: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3836 chunks, opts = recordfilter( |
47565
00ae1fb6c459
cmdutil: fix newandmodified file accounting for --interactive commits
Daniel Ploch <dploch@google.com>
parents:
47432
diff
changeset
|
3837 repo.ui, original_headers, match, operation=operation |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3838 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3839 if operation == b'discard': |
25424
69609f43c752
revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents:
25358
diff
changeset
|
3840 chunks = patch.reversehunks(chunks) |
69609f43c752
revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents:
25358
diff
changeset
|
3841 |
48363
6a454e7053a1
errors: return more detailed errors when failing to parse or apply patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48247
diff
changeset
|
3842 except error.PatchParseError as err: |
6a454e7053a1
errors: return more detailed errors when failing to parse or apply patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48247
diff
changeset
|
3843 raise error.InputError(_(b'error parsing patch: %s') % err) |
6a454e7053a1
errors: return more detailed errors when failing to parse or apply patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48247
diff
changeset
|
3844 except error.PatchApplicationError as err: |
6a454e7053a1
errors: return more detailed errors when failing to parse or apply patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48247
diff
changeset
|
3845 raise error.StateError(_(b'error applying patch: %s') % err) |
24359
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3846 |
42856
3cf091843b4f
split: handle partial commit of renames when doing split or record (issue5723)
Kyle Lippincott <spectral@google.com>
parents:
42643
diff
changeset
|
3847 # FIXME: when doing an interactive revert of a copy, there's no way of |
3cf091843b4f
split: handle partial commit of renames when doing split or record (issue5723)
Kyle Lippincott <spectral@google.com>
parents:
42643
diff
changeset
|
3848 # performing a partial revert of the added file, the only option is |
3cf091843b4f
split: handle partial commit of renames when doing split or record (issue5723)
Kyle Lippincott <spectral@google.com>
parents:
42643
diff
changeset
|
3849 # "remove added file <name> (Yn)?", so we don't need to worry about the |
3cf091843b4f
split: handle partial commit of renames when doing split or record (issue5723)
Kyle Lippincott <spectral@google.com>
parents:
42643
diff
changeset
|
3850 # alsorestore value. Ideally we'd be able to partially revert |
3cf091843b4f
split: handle partial commit of renames when doing split or record (issue5723)
Kyle Lippincott <spectral@google.com>
parents:
42643
diff
changeset
|
3851 # copied/renamed files. |
47565
00ae1fb6c459
cmdutil: fix newandmodified file accounting for --interactive commits
Daniel Ploch <dploch@google.com>
parents:
47432
diff
changeset
|
3852 newlyaddedandmodifiedfiles, unusedalsorestore = newandmodified(chunks) |
29498
1b38cfde9530
revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents:
29427
diff
changeset
|
3853 if tobackup is None: |
1b38cfde9530
revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents:
29427
diff
changeset
|
3854 tobackup = set() |
24359
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3855 # Apply changes |
28861
86db5cb55d46
pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents:
28837
diff
changeset
|
3856 fp = stringio() |
39414
1cbe19eb496d
revert: stabilize status message of chunks selected interactively
Yuya Nishihara <yuya@tcha.org>
parents:
39405
diff
changeset
|
3857 # chunks are serialized per file, but files aren't sorted |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44440
diff
changeset
|
3858 for f in sorted({c.header.filename() for c in chunks if ishunk(c)}): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3859 prntstatusmsg(b'revert', f) |
41987
c1d83d916e85
revert: option to choose what to keep, not what to discard
Martin von Zweigbergk <martinvonz@google.com>
parents:
41985
diff
changeset
|
3860 files = set() |
24359
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3861 for c in chunks: |
39405
cb70501d8b71
revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
39404
diff
changeset
|
3862 if ishunk(c): |
29498
1b38cfde9530
revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents:
29427
diff
changeset
|
3863 abs = c.header.filename() |
39405
cb70501d8b71
revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
39404
diff
changeset
|
3864 # Create a backup file only if this hunk should be backed up |
cb70501d8b71
revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
39404
diff
changeset
|
3865 if c.header.filename() in tobackup: |
cb70501d8b71
revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
39404
diff
changeset
|
3866 target = repo.wjoin(abs) |
41597
9e545c9a4dfe
revert: migrate to scmutil.backuppath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41591
diff
changeset
|
3867 bakname = scmutil.backuppath(repo.ui, repo, abs) |
39405
cb70501d8b71
revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
39404
diff
changeset
|
3868 util.copyfile(target, bakname) |
cb70501d8b71
revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
39404
diff
changeset
|
3869 tobackup.remove(abs) |
41987
c1d83d916e85
revert: option to choose what to keep, not what to discard
Martin von Zweigbergk <martinvonz@google.com>
parents:
41985
diff
changeset
|
3870 if abs not in files: |
c1d83d916e85
revert: option to choose what to keep, not what to discard
Martin von Zweigbergk <martinvonz@google.com>
parents:
41985
diff
changeset
|
3871 files.add(abs) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3872 if operation == b'keep': |
41987
c1d83d916e85
revert: option to choose what to keep, not what to discard
Martin von Zweigbergk <martinvonz@google.com>
parents:
41985
diff
changeset
|
3873 checkout(abs) |
24359
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3874 c.write(fp) |
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3875 dopatch = fp.tell() |
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3876 fp.seek(0) |
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3877 if dopatch: |
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3878 try: |
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3879 patch.internalpatch(repo.ui, repo, fp, 1, eolmode=None) |
48363
6a454e7053a1
errors: return more detailed errors when failing to parse or apply patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48247
diff
changeset
|
3880 except error.PatchParseError as err: |
6a454e7053a1
errors: return more detailed errors when failing to parse or apply patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48247
diff
changeset
|
3881 raise error.InputError(pycompat.bytestr(err)) |
6a454e7053a1
errors: return more detailed errors when failing to parse or apply patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48247
diff
changeset
|
3882 except error.PatchApplicationError as err: |
6a454e7053a1
errors: return more detailed errors when failing to parse or apply patch
Martin von Zweigbergk <martinvonz@google.com>
parents:
48247
diff
changeset
|
3883 raise error.StateError(pycompat.bytestr(err)) |
24359
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3884 del fp |
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3885 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3886 for f in actions[b'revert'][0]: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3887 prntstatusmsg(b'revert', f) |
25755
72d395e399c1
cmdutil: remove useless dirstate.normallookup() invocation in revert()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25739
diff
changeset
|
3888 checkout(f) |
24359
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3889 if normal: |
521fe8287dd5
revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents:
24358
diff
changeset
|
3890 normal(f) |
20571
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3891 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3892 for f in actions[b'add'][0]: |
25259
5b05f10c5024
revert: fix edition of newly added file during --interactive
Laurent Charignon <lcharignon@fb.com>
parents:
25258
diff
changeset
|
3893 # Don't checkout modified files, they are already created by the diff |
49031
9be7da341885
revert: use a `continue` to reduce indentation
Martin von Zweigbergk <martinvonz@google.com>
parents:
48978
diff
changeset
|
3894 if f in newlyaddedandmodifiedfiles: |
9be7da341885
revert: use a `continue` to reduce indentation
Martin von Zweigbergk <martinvonz@google.com>
parents:
48978
diff
changeset
|
3895 continue |
9be7da341885
revert: use a `continue` to reduce indentation
Martin von Zweigbergk <martinvonz@google.com>
parents:
48978
diff
changeset
|
3896 |
49032
3f6ef67e7a60
revert: ask user to confirm before tracking new file when interactive
Martin von Zweigbergk <martinvonz@google.com>
parents:
49031
diff
changeset
|
3897 if interactive: |
3f6ef67e7a60
revert: ask user to confirm before tracking new file when interactive
Martin von Zweigbergk <martinvonz@google.com>
parents:
49031
diff
changeset
|
3898 choice = repo.ui.promptchoice( |
3f6ef67e7a60
revert: ask user to confirm before tracking new file when interactive
Martin von Zweigbergk <martinvonz@google.com>
parents:
49031
diff
changeset
|
3899 _(b"add new file %s (Yn)?$$ &Yes $$ &No") % uipathfn(f) |
3f6ef67e7a60
revert: ask user to confirm before tracking new file when interactive
Martin von Zweigbergk <martinvonz@google.com>
parents:
49031
diff
changeset
|
3900 ) |
3f6ef67e7a60
revert: ask user to confirm before tracking new file when interactive
Martin von Zweigbergk <martinvonz@google.com>
parents:
49031
diff
changeset
|
3901 if choice != 0: |
3f6ef67e7a60
revert: ask user to confirm before tracking new file when interactive
Martin von Zweigbergk <martinvonz@google.com>
parents:
49031
diff
changeset
|
3902 continue |
49031
9be7da341885
revert: use a `continue` to reduce indentation
Martin von Zweigbergk <martinvonz@google.com>
parents:
48978
diff
changeset
|
3903 prntstatusmsg(b'add', f) |
9be7da341885
revert: use a `continue` to reduce indentation
Martin von Zweigbergk <martinvonz@google.com>
parents:
48978
diff
changeset
|
3904 checkout(f) |
9be7da341885
revert: use a `continue` to reduce indentation
Martin von Zweigbergk <martinvonz@google.com>
parents:
48978
diff
changeset
|
3905 repo.dirstate.set_tracked(f) |
20571
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3906 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3907 for f in actions[b'undelete'][0]: |
41522
d783c937aa53
revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents:
41374
diff
changeset
|
3908 if interactive: |
d783c937aa53
revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents:
41374
diff
changeset
|
3909 choice = repo.ui.promptchoice( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3910 _(b"add back removed file %s (Yn)?$$ &Yes $$ &No") % f |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3911 ) |
41522
d783c937aa53
revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents:
41374
diff
changeset
|
3912 if choice == 0: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3913 prntstatusmsg(b'undelete', f) |
41522
d783c937aa53
revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents:
41374
diff
changeset
|
3914 checkout(f) |
d783c937aa53
revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents:
41374
diff
changeset
|
3915 normal(f) |
d783c937aa53
revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents:
41374
diff
changeset
|
3916 else: |
d783c937aa53
revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents:
41374
diff
changeset
|
3917 excluded_files.append(f) |
d783c937aa53
revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents:
41374
diff
changeset
|
3918 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3919 prntstatusmsg(b'undelete', f) |
41522
d783c937aa53
revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents:
41374
diff
changeset
|
3920 checkout(f) |
d783c937aa53
revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents:
41374
diff
changeset
|
3921 normal(f) |
20571
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3922 |
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3923 copied = copies.pathcopies(repo[parent], ctx) |
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3924 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3925 for f in ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3926 actions[b'add'][0] + actions[b'undelete'][0] + actions[b'revert'][0] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3927 ): |
20571
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3928 if f in copied: |
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3929 repo.dirstate.copy(copied[f], f) |
d4893e64f300
revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20553
diff
changeset
|
3930 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3931 |
21051
1004d3cd65fd
outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21047
diff
changeset
|
3932 # a list of (ui, repo, otherpeer, opts, missing) functions called by |
1004d3cd65fd
outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21047
diff
changeset
|
3933 # commands.outgoing. "missing" is "missing" of the result of |
1004d3cd65fd
outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21047
diff
changeset
|
3934 # "findcommonoutgoing()" |
1004d3cd65fd
outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21047
diff
changeset
|
3935 outgoinghooks = util.hooks() |
1004d3cd65fd
outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21047
diff
changeset
|
3936 |
19211
3bfd7f1e7485
summary: augment output with info from extensions
Bryan O'Sullivan <bryano@fb.com>
parents:
19129
diff
changeset
|
3937 # a list of (ui, repo) functions called by commands.summary |
3bfd7f1e7485
summary: augment output with info from extensions
Bryan O'Sullivan <bryano@fb.com>
parents:
19129
diff
changeset
|
3938 summaryhooks = util.hooks() |
19474
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
3939 |
21047
f0003f989e72
summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21041
diff
changeset
|
3940 # a list of (ui, repo, opts, changes) functions called by commands.summary. |
f0003f989e72
summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21041
diff
changeset
|
3941 # |
f0003f989e72
summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21041
diff
changeset
|
3942 # functions should return tuple of booleans below, if 'changes' is None: |
f0003f989e72
summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21041
diff
changeset
|
3943 # (whether-incomings-are-needed, whether-outgoings-are-needed) |
f0003f989e72
summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21041
diff
changeset
|
3944 # |
f0003f989e72
summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21041
diff
changeset
|
3945 # otherwise, 'changes' is a tuple of tuples below: |
f0003f989e72
summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21041
diff
changeset
|
3946 # - (sourceurl, sourcebranch, sourcepeer, incoming) |
f0003f989e72
summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21041
diff
changeset
|
3947 # - (desturl, destbranch, destpeer, outgoing) |
f0003f989e72
summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21041
diff
changeset
|
3948 summaryremotehooks = util.hooks() |
f0003f989e72
summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21041
diff
changeset
|
3949 |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
3950 |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
3951 def checkunfinished(repo, commit=False, skipmerge=False): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
3952 """Look for an unfinished multistep operation, like graft, and abort |
19474
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
3953 if found. It's probably good to check this right before |
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
3954 bailifchanged(). |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
3955 """ |
38182
79c54e7c0c52
rebase: prioritize indicating an interrupted rebase over update (issue5838)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37815
diff
changeset
|
3956 # Check for non-clearable states first, so things like rebase will take |
79c54e7c0c52
rebase: prioritize indicating an interrupted rebase over update (issue5838)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37815
diff
changeset
|
3957 # precedence over update. |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
3958 for state in statemod._unfinishedstates: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3959 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3960 state._clearable |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3961 or (commit and state._allowcommit) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3962 or state._reportonly |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3963 ): |
38182
79c54e7c0c52
rebase: prioritize indicating an interrupted rebase over update (issue5838)
Matt Harbison <matt_harbison@yahoo.com>
parents:
37815
diff
changeset
|
3964 continue |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
3965 if state.isunfinished(repo): |
45840
527ce85c2e60
errors: introduce StateError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45827
diff
changeset
|
3966 raise error.StateError(state.msg(), hint=state.hint()) |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
3967 |
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
3968 for s in statemod._unfinishedstates: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3969 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3970 not s._clearable |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3971 or (commit and s._allowcommit) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
3972 or (s._opname == b'merge' and skipmerge) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3973 or s._reportonly |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3974 ): |
19496
607191a45f8c
checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents:
19482
diff
changeset
|
3975 continue |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
3976 if s.isunfinished(repo): |
45840
527ce85c2e60
errors: introduce StateError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45827
diff
changeset
|
3977 raise error.StateError(s.msg(), hint=s.hint()) |
19474
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
3978 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3979 |
19474
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
3980 def clearunfinished(repo): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
3981 """Check for unfinished operations (as above), and clear the ones |
19474
894fd1a7c533
cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents:
19293
diff
changeset
|
3982 that are clearable. |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
3983 """ |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
3984 for state in statemod._unfinishedstates: |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
3985 if state._reportonly: |
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
3986 continue |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
3987 if not state._clearable and state.isunfinished(repo): |
45840
527ce85c2e60
errors: introduce StateError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45827
diff
changeset
|
3988 raise error.StateError(state.msg(), hint=state.hint()) |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
3989 |
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
3990 for s in statemod._unfinishedstates: |
46969
d9531094cf8e
cmdutil: fix an uninitialize variable usage in clearunfinished()
Matt Harbison <matt_harbison@yahoo.com>
parents:
46842
diff
changeset
|
3991 if s._opname == b'merge' or s._reportonly: |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
3992 continue |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
3993 if s._clearable and s.isunfinished(repo): |
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
3994 util.unlink(repo.vfs.join(s._fname)) |
24991
4169a4f83548
cmdutil: add class to restore dirstate during unexpected failure
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
24988
diff
changeset
|
3995 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
3996 |
42579
b8d54f4625cb
merge: disallow merge abort in case of an unfinished operation (issue6160)
Taapas Agrawal <taapas2897@gmail.com>
parents:
42577
diff
changeset
|
3997 def getunfinishedstate(repo): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
3998 """Checks for unfinished operations and returns statecheck object |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
3999 for it""" |
42579
b8d54f4625cb
merge: disallow merge abort in case of an unfinished operation (issue6160)
Taapas Agrawal <taapas2897@gmail.com>
parents:
42577
diff
changeset
|
4000 for state in statemod._unfinishedstates: |
b8d54f4625cb
merge: disallow merge abort in case of an unfinished operation (issue6160)
Taapas Agrawal <taapas2897@gmail.com>
parents:
42577
diff
changeset
|
4001 if state.isunfinished(repo): |
b8d54f4625cb
merge: disallow merge abort in case of an unfinished operation (issue6160)
Taapas Agrawal <taapas2897@gmail.com>
parents:
42577
diff
changeset
|
4002 return state |
b8d54f4625cb
merge: disallow merge abort in case of an unfinished operation (issue6160)
Taapas Agrawal <taapas2897@gmail.com>
parents:
42577
diff
changeset
|
4003 return None |
b8d54f4625cb
merge: disallow merge abort in case of an unfinished operation (issue6160)
Taapas Agrawal <taapas2897@gmail.com>
parents:
42577
diff
changeset
|
4004 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
4005 |
28120
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4006 def howtocontinue(repo): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
4007 """Check for an unfinished operation and return the command to finish |
28120
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4008 it. |
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4009 |
42577
ceb31d96d3ae
statecheck: updated docstrings related to afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42568
diff
changeset
|
4010 statemod._unfinishedstates list is checked for an unfinished operation |
ceb31d96d3ae
statecheck: updated docstrings related to afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42568
diff
changeset
|
4011 and the corresponding message to finish it is generated if a method to |
ceb31d96d3ae
statecheck: updated docstrings related to afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42568
diff
changeset
|
4012 continue is supported by the operation. |
28120
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4013 |
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4014 Returns a (msg, warning) tuple. 'msg' is a string and 'warning' is |
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4015 a boolean. |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
4016 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4017 contmsg = _(b"continue: %s") |
42533
0231032729c4
statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42532
diff
changeset
|
4018 for state in statemod._unfinishedstates: |
0231032729c4
statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42532
diff
changeset
|
4019 if not state._continueflag: |
0231032729c4
statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42532
diff
changeset
|
4020 continue |
0231032729c4
statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42532
diff
changeset
|
4021 if state.isunfinished(repo): |
0231032729c4
statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42532
diff
changeset
|
4022 return contmsg % state.continuemsg(), True |
33362
e48fb90f80c8
cmdutil: simplify the dirty check in howtocontinue()
Matt Harbison <matt_harbison@yahoo.com>
parents:
33334
diff
changeset
|
4023 if repo[None].dirty(missing=True, merge=False, branch=False): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4024 return contmsg % _(b"hg commit"), False |
28120
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4025 return None, None |
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4026 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
4027 |
28120
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4028 def checkafterresolved(repo): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
4029 """Inform the user about the next action after completing hg resolve |
28120
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4030 |
42577
ceb31d96d3ae
statecheck: updated docstrings related to afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42568
diff
changeset
|
4031 If there's a an unfinished operation that supports continue flag, |
ceb31d96d3ae
statecheck: updated docstrings related to afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42568
diff
changeset
|
4032 howtocontinue will yield repo.ui.warn as the reporter. |
28120
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4033 |
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4034 Otherwise, it will yield repo.ui.note. |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
4035 """ |
28120
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4036 msg, warning = howtocontinue(repo) |
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4037 if msg is not None: |
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4038 if warning: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4039 repo.ui.warn(b"%s\n" % msg) |
28120
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4040 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4041 repo.ui.note(b"%s\n" % msg) |
28120
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4042 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
4043 |
28120
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4044 def wrongtooltocontinue(repo, task): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
4045 """Raise an abort suggesting how to properly continue if there is an |
28120
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4046 active task. |
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4047 |
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4048 Uses howtocontinue() to find the active task. |
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4049 |
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4050 If there's no task (repo.ui.note for 'hg commit'), it does not offer |
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4051 a hint. |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45846
diff
changeset
|
4052 """ |
28120
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4053 after = howtocontinue(repo) |
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4054 hint = None |
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4055 if after[1]: |
ed4d06f180b8
cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents:
28027
diff
changeset
|
4056 hint = after[0] |
45840
527ce85c2e60
errors: introduce StateError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45827
diff
changeset
|
4057 raise error.StateError(_(b'no %s in progress') % task, hint=hint) |
42568
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4058 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
4059 |
42568
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4060 def abortgraft(ui, repo, graftstate): |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4061 """abort the interrupted graft and rollbacks to the state before interrupted |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4062 graft""" |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4063 if not graftstate.exists(): |
45840
527ce85c2e60
errors: introduce StateError and use it from commands and cmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45827
diff
changeset
|
4064 raise error.StateError(_(b"no interrupted graft to abort")) |
42568
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4065 statedata = readgraftstate(repo, graftstate) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4066 newnodes = statedata.get(b'newnodes') |
42568
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4067 if newnodes is None: |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4068 # and old graft state which does not have all the data required to abort |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4069 # the graft |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4070 raise error.Abort(_(b"cannot abort using an old graftstate")) |
42568
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4071 |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4072 # changeset from which graft operation was started |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4073 if len(newnodes) > 0: |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4074 startctx = repo[newnodes[0]].p1() |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4075 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4076 startctx = repo[b'.'] |
42568
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4077 # whether to strip or not |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4078 cleanup = False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
4079 |
42568
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4080 if newnodes: |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4081 newnodes = [repo[r].rev() for r in newnodes] |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4082 cleanup = True |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4083 # checking that none of the newnodes turned public or is public |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4084 immutable = [c for c in newnodes if not repo[c].mutable()] |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4085 if immutable: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
4086 repo.ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4087 _(b"cannot clean up public changesets %s\n") |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4088 % b', '.join(bytes(repo[r]) for r in immutable), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4089 hint=_(b"see 'hg help phases' for details"), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
4090 ) |
42568
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4091 cleanup = False |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4092 |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4093 # checking that no new nodes are created on top of grafted revs |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4094 desc = set(repo.changelog.descendants(newnodes)) |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4095 if desc - set(newnodes): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
4096 repo.ui.warn( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
4097 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4098 b"new changesets detected on destination " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4099 b"branch, can't strip\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
4100 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
4101 ) |
42568
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4102 cleanup = False |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4103 |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4104 if cleanup: |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4105 with repo.wlock(), repo.lock(): |
45556
03726f5b6092
merge: use merge.clean_update() when applicable
Martin von Zweigbergk <martinvonz@google.com>
parents:
45552
diff
changeset
|
4106 mergemod.clean_update(startctx) |
42568
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4107 # stripping the new nodes created |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
4108 strippoints = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4109 c.node() for c in repo.set(b"roots(%ld)", newnodes) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
4110 ] |
42568
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4111 repair.strip(repo.ui, repo, strippoints, backup=False) |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4112 |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4113 if not cleanup: |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4114 # we don't update to the startnode if we can't strip |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4115 startctx = repo[b'.'] |
45556
03726f5b6092
merge: use merge.clean_update() when applicable
Martin von Zweigbergk <martinvonz@google.com>
parents:
45552
diff
changeset
|
4116 mergemod.clean_update(startctx) |
42568
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4117 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4118 ui.status(_(b"graft aborted\n")) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4119 ui.status(_(b"working directory is now at %s\n") % startctx.hex()[:12]) |
42568
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4120 graftstate.delete() |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4121 return 0 |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4122 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
4123 |
51287
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51285
diff
changeset
|
4124 def readgraftstate( |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51285
diff
changeset
|
4125 repo: Any, |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51285
diff
changeset
|
4126 graftstate: statemod.cmdstate, |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51285
diff
changeset
|
4127 ) -> Dict[bytes, Any]: |
42568
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4128 """read the graft state file and return a dict of the data stored in it""" |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4129 try: |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4130 return graftstate.read() |
f9da9d5f3f5a
graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
4131 except error.CorruptedState: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4132 nodes = repo.vfs.read(b'graftstate').splitlines() |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4133 return {b'nodes': nodes} |
42582
5171937ad0f9
abort: added support for graft
Taapas Agrawal <taapas2897@gmail.com>
parents:
42579
diff
changeset
|
4134 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42933
diff
changeset
|
4135 |
42582
5171937ad0f9
abort: added support for graft
Taapas Agrawal <taapas2897@gmail.com>
parents:
42579
diff
changeset
|
4136 def hgabortgraft(ui, repo): |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
46969
diff
changeset
|
4137 """abort logic for aborting graft using 'hg abort'""" |
42582
5171937ad0f9
abort: added support for graft
Taapas Agrawal <taapas2897@gmail.com>
parents:
42579
diff
changeset
|
4138 with repo.wlock(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
4139 graftstate = statemod.cmdstate(repo, b'graftstate') |
42582
5171937ad0f9
abort: added support for graft
Taapas Agrawal <taapas2897@gmail.com>
parents:
42579
diff
changeset
|
4140 return abortgraft(ui, repo, graftstate) |
51554
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4141 |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4142 |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4143 def postincoming(ui, repo, modheads, optupdate, checkout, brev): |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4144 """Run after a changegroup has been added via pull/unbundle |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4145 |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4146 This takes arguments below: |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4147 |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4148 :modheads: change of heads by pull/unbundle |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4149 :optupdate: updating working directory is needed or not |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4150 :checkout: update destination revision (or None to default destination) |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4151 :brev: a name, which might be a bookmark to be activated after updating |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4152 |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4153 return True if update raise any conflict, False otherwise. |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4154 """ |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4155 if modheads == 0: |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4156 return False |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4157 if optupdate: |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4158 # avoid circular import |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4159 from . import hg |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4160 |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4161 try: |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4162 return hg.updatetotally(ui, repo, checkout, brev) |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4163 except error.UpdateAbort as inst: |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4164 msg = _(b"not updating: %s") % stringutil.forcebytestr(inst) |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4165 hint = inst.hint |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4166 raise error.UpdateAbort(msg, hint=hint) |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4167 if ui.quiet: |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4168 pass # we won't report anything so the other clause are useless. |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4169 elif modheads is not None and modheads > 1: |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4170 currentbranchheads = len(repo.branchheads()) |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4171 if currentbranchheads == modheads: |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4172 ui.status( |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4173 _(b"(run 'hg heads' to see heads, 'hg merge' to merge)\n") |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4174 ) |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4175 elif currentbranchheads > 1: |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4176 ui.status( |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4177 _(b"(run 'hg heads .' to see heads, 'hg merge' to merge)\n") |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4178 ) |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4179 else: |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4180 ui.status(_(b"(run 'hg heads' to see heads)\n")) |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4181 elif not ui.configbool(b'commands', b'update.requiredest'): |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4182 ui.status(_(b"(run 'hg update' to get a working copy)\n")) |
a151fd01e98c
postincoming: move to cmdutil
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51287
diff
changeset
|
4183 return False |
51555
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4184 |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4185 |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4186 def unbundle_files(ui, repo, fnames, unbundle_source=b'unbundle'): |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4187 """utility for `hg unbundle` and `hg debug::unbundle`""" |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4188 assert fnames |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4189 # avoid circular import |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4190 from . import hg |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4191 |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4192 with repo.lock(): |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4193 for fname in fnames: |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4194 f = hg.openpath(ui, fname) |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4195 gen = exchange.readbundle(ui, f, fname) |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4196 if isinstance(gen, streamclone.streamcloneapplier): |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4197 raise error.InputError( |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4198 _( |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4199 b'packed bundles cannot be applied with ' |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4200 b'"hg unbundle"' |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4201 ), |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4202 hint=_(b'use "hg debugapplystreamclonebundle"'), |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4203 ) |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4204 url = b'bundle:' + fname |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4205 try: |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4206 txnname = b'unbundle' |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4207 if not isinstance(gen, bundle2.unbundle20): |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4208 txnname = b'unbundle\n%s' % urlutil.hidepassword(url) |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4209 with repo.transaction(txnname) as tr: |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4210 op = bundle2.applybundle( |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4211 repo, |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4212 gen, |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4213 tr, |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4214 source=unbundle_source, # used by debug::unbundle |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4215 url=url, |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4216 ) |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4217 except error.BundleUnknownFeatureError as exc: |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4218 raise error.Abort( |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4219 _(b'%s: unknown bundle feature, %s') % (fname, exc), |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4220 hint=_( |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4221 b"see https://mercurial-scm.org/" |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4222 b"wiki/BundleFeature for more " |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4223 b"information" |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4224 ), |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4225 ) |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4226 modheads = bundle2.combinechangegroupresults(op) |
15e680a44502
unbundle: move most of the logic on cmdutil to help debug::unbundle reuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51554
diff
changeset
|
4227 return modheads |