annotate mercurial/cmdutil.py @ 43087:66f2cc210a29

py3: manually import pycompat.setattr where it is needed Continuing to eliminate the implicit import of symbols in the Python 3 source transformer so we can eliminate it. Differential Revision: https://phab.mercurial-scm.org/D7007
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 06 Oct 2019 14:58:42 -0400
parents eef9a2d67051
children c59eb1560c44
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2957
6e062d9b188f fix comment.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2885
diff changeset
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 #
4635
63b9d2deed48 Updated copyright notices and add "and others" to "hg version"
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4633
diff changeset
3 # Copyright 2005-2007 Matt Mackall <mpm@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
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 10249
diff changeset
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 from __future__ import absolute_import
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
9
41330
4ea21df312ec record: prevent commits that don't pick up dirty subrepo changes (issue6102)
Matt Harbison <matt_harbison@yahoo.com>
parents: 41206
diff changeset
10 import copy as copymod
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
11 import errno
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
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
15 from .i18n import _
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
16 from .node import (
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
17 hex,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
18 nullid,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
19 nullrev,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
20 short,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
21 )
43087
66f2cc210a29 py3: manually import pycompat.setattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
22 from .pycompat import (
66f2cc210a29 py3: manually import pycompat.setattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
23 open,
66f2cc210a29 py3: manually import pycompat.setattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
24 setattr,
66f2cc210a29 py3: manually import pycompat.setattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
25 )
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
26
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
27 from . import (
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
28 bookmarks,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
29 changelog,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
30 copies,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
31 crecord as crecordmod,
33616
5ac845ca059a commit: don't let failed commit with --addremove update dirstate (issue5645)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33548
diff changeset
32 dirstateguard,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
33 encoding,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
34 error,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
35 formatter,
35925
7625b4f7db70 cmdutil: split functions of log-like commands to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35914
diff changeset
36 logcmdutil,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
37 match as matchmod,
36048
46a54de96a54 merge: cut import cycle at merge -> extensions
Yuya Nishihara <yuya@tcha.org>
parents: 36047
diff changeset
38 merge as mergemod,
35853
eeb87b24aea7 amend: abort if unresolved merge conflicts found (issue5805)
Yuya Nishihara <yuya@tcha.org>
parents: 35746
diff changeset
39 mergeutil,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
40 obsolete,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
41 patch,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
42 pathutil,
38429
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 38379
diff changeset
43 phases,
30528
20a42325fdef py3: use pycompat.getcwd() instead of os.getcwd()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30515
diff changeset
44 pycompat,
42568
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
45 repair,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
46 revlog,
35745
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
47 rewriteutil,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
48 scmutil,
31043
aea06029919e revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents: 30909
diff changeset
49 smartset,
42536
5f2f6912c9e6 states: moved cmdutil.unfinishedstates to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 42494
diff changeset
50 state as statemod,
36047
55e8efa2451a subrepo: split non-core functions to new module
Yuya Nishihara <yuya@tcha.org>
parents: 35993
diff changeset
51 subrepoutil,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
52 templatekw,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
53 templater,
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
54 util,
31247
1b08aca7870a vfs: use 'vfs' module directly in 'mercurial.cmdutil'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31226
diff changeset
55 vfs as vfsmod,
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
56 )
37087
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36991
diff changeset
57
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36991
diff changeset
58 from .utils import (
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36991
diff changeset
59 dateutil,
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36991
diff changeset
60 stringutil,
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36991
diff changeset
61 )
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36991
diff changeset
62
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28837
diff changeset
63 stringio = util.stringio
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
64
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
65 # templates of common command options
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
66
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
67 dryrunopts = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
68 (b'n', b'dry-run', None, _(b'do not perform actions, just print output')),
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
69 ]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
70
38667
572dff5c946e rebase: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38648
diff changeset
71 confirmopts = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
72 (b'', b'confirm', None, _(b'ask before applying actions')),
38667
572dff5c946e rebase: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38648
diff changeset
73 ]
572dff5c946e rebase: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38648
diff changeset
74
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
75 remoteopts = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
76 (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: 42937
diff changeset
77 (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
78 b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
79 b'remotecmd',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
80 b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
81 _(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
82 _(b'CMD'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
83 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
84 (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
85 b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
86 b'insecure',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
87 None,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
88 _(b'do not verify server certificate (ignoring web.cacerts config)'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
89 ),
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
90 ]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
91
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
92 walkopts = [
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
93 (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
94 b'I',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
95 b'include',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
96 [],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
97 _(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
98 _(b'PATTERN'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
99 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
100 (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
101 b'X',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
102 b'exclude',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
103 [],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
104 _(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
105 _(b'PATTERN'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
106 ),
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
107 ]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
108
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
109 commitopts = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
110 (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
111 (b'l', b'logfile', b'', _(b'read commit message from file'), _(b'FILE')),
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
112 ]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
113
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
114 commitopts2 = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
115 (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
116 b'd',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
117 b'date',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
118 b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
119 _(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
120 _(b'DATE'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
121 ),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
122 (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
123 b'u',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
124 b'user',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
125 b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
126 _(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
127 _(b'USER'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
128 ),
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
129 ]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
130
42909
66048f6b5d0d uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents: 42898
diff changeset
131 commitopts3 = [
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
132 (b'D', b'currentdate', None, _(b'record the current date as commit date')),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
133 (b'U', b'currentuser', None, _(b'record the current user as committer')),
42909
66048f6b5d0d uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents: 42898
diff changeset
134 ]
66048f6b5d0d uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents: 42898
diff changeset
135
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
136 formatteropts = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
137 (b'T', b'template', b'', _(b'display with template'), _(b'TEMPLATE')),
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
138 ]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
139
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
140 templateopts = [
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
141 (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
142 b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
143 b'style',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
144 b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
145 _(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
146 _(b'STYLE'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
147 ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
148 (b'T', b'template', b'', _(b'display with template'), _(b'TEMPLATE')),
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
149 ]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
150
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
151 logopts = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
152 (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
153 (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
154 (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
155 (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
156 (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
157 (b'G', b'graph', None, _(b"show the revision DAG")),
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
158 ] + templateopts
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
159
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
160 diffopts = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
161 (b'a', b'text', None, _(b'treat all files as text')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
162 (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
163 (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
164 (b'', b'nodates', None, _(b'omit dates from diff headers')),
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
165 ]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
166
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
167 diffwsopts = [
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
168 (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
169 b'w',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
170 b'ignore-all-space',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
171 None,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
172 _(b'ignore white space when comparing lines'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
173 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
174 (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
175 b'b',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
176 b'ignore-space-change',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
177 None,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
178 _(b'ignore changes in the amount of white space'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
179 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
180 (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
181 b'B',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
182 b'ignore-blank-lines',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
183 None,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
184 _(b'ignore changes whose lines are all blank'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
185 ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
186 (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
187 b'Z',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
188 b'ignore-space-at-eol',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
189 None,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
190 _(b'ignore changes in whitespace at EOL'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
191 ),
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
192 ]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
193
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
194 diffopts2 = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
195 [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
196 (b'', b'noprefix', None, _(b'omit a/ and b/ prefixes from filenames')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
197 (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
198 b'p',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
199 b'show-function',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
200 None,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
201 _(b'show which function each change is in'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
202 ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
203 (b'', b'reverse', None, _(b'produce a diff that undoes the changes')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
204 ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
205 + diffwsopts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
206 + [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
207 (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
208 b'U',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
209 b'unified',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
210 b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
211 _(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
212 _(b'NUM'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
213 ),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
214 (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
215 (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
216 b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
217 b'root',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
218 b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
219 _(b'produce diffs relative to subdirectory'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
220 _(b'DIR'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
221 ),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
222 ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
223 )
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
224
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
225 mergetoolopts = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
226 (b't', b'tool', b'', _(b'specify merge tool'), _(b'TOOL')),
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
227 ]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
228
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
229 similarityopts = [
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
230 (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
231 b's',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
232 b'similarity',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
233 b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
234 _(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
235 _(b'SIMILARITY'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
236 )
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
237 ]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
238
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
239 subrepoopts = [(b'S', b'subrepos', None, _(b'recurse into subrepositories'))]
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
240
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
241 debugrevlogopts = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
242 (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
243 (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
244 (b'', b'dir', b'', _(b'open directory manifest')),
32414
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
245 ]
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32401
diff changeset
246
30703
5c85c93cdd61 cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents: 30695
diff changeset
247 # 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
248 # editor text
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
249 _linebelow = b"^HG: ------------------------ >8 ------------------------$"
30703
5c85c93cdd61 cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents: 30695
diff changeset
250
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
251
42909
66048f6b5d0d uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents: 42898
diff changeset
252 def resolvecommitoptions(ui, opts):
66048f6b5d0d uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents: 42898
diff changeset
253 """modify commit options dict to handle related options
42936
e4803231f538 amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents: 42925
diff changeset
254
e4803231f538 amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents: 42925
diff changeset
255 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: 42925
diff changeset
256 the ``date`` option is set.
42909
66048f6b5d0d uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents: 42898
diff changeset
257 """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
258 if opts.get(b'date') and opts.get(b'currentdate'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
259 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
260 _(b'--date and --currentdate are mutually ' b'exclusive')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
261 )
42925
4690902850df uncommit: make -D/--date and -U/--user mutually exclusive
Matt Harbison <matt_harbison@yahoo.com>
parents: 42924
diff changeset
262 if opts.get(b'user') and opts.get(b'currentuser'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
263 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
264 _(b'--user and --currentuser are mutually ' b'exclusive')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
265 )
42925
4690902850df uncommit: make -D/--date and -U/--user mutually exclusive
Matt Harbison <matt_harbison@yahoo.com>
parents: 42924
diff changeset
266
42936
e4803231f538 amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents: 42925
diff changeset
267 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: 42925
diff changeset
268
42925
4690902850df uncommit: make -D/--date and -U/--user mutually exclusive
Matt Harbison <matt_harbison@yahoo.com>
parents: 42924
diff changeset
269 if opts.get(b'currentdate'):
42909
66048f6b5d0d uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents: 42898
diff changeset
270 opts[b'date'] = b'%d %d' % dateutil.makedate()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
271 elif (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
272 not opts.get(b'date')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
273 and ui.configbool(b'rewrite', b'update-timestamp')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
274 and opts.get(b'currentdate') is None
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
275 ):
42936
e4803231f538 amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents: 42925
diff changeset
276 opts[b'date'] = b'%d %d' % dateutil.makedate()
e4803231f538 amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents: 42925
diff changeset
277 datemaydiffer = True
e4803231f538 amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents: 42925
diff changeset
278
42925
4690902850df uncommit: make -D/--date and -U/--user mutually exclusive
Matt Harbison <matt_harbison@yahoo.com>
parents: 42924
diff changeset
279 if opts.get(b'currentuser'):
42909
66048f6b5d0d uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents: 42898
diff changeset
280 opts[b'user'] = ui.username()
66048f6b5d0d uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents: 42898
diff changeset
281
42936
e4803231f538 amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents: 42925
diff changeset
282 return datemaydiffer
e4803231f538 amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents: 42925
diff changeset
283
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
284
42937
7e9997041781 amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents: 42936
diff changeset
285 def checknotesize(ui, opts):
7e9997041781 amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents: 42936
diff changeset
286 """ make sure note is of valid format """
7e9997041781 amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents: 42936
diff changeset
287
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
288 note = opts.get(b'note')
42937
7e9997041781 amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents: 42936
diff changeset
289 if not note:
7e9997041781 amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents: 42936
diff changeset
290 return
7e9997041781 amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents: 42936
diff changeset
291
7e9997041781 amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents: 42936
diff changeset
292 if len(note) > 255:
7e9997041781 amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents: 42936
diff changeset
293 raise error.Abort(_(b"cannot store a note of more than 255 bytes"))
7e9997041781 amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents: 42936
diff changeset
294 if b'\n' in note:
7e9997041781 amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents: 42936
diff changeset
295 raise error.Abort(_(b"note cannot contain a newline"))
7e9997041781 amend: prevent '\n' in the note string
Matt Harbison <matt_harbison@yahoo.com>
parents: 42936
diff changeset
296
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
297
25256
5a8398b085ed record: extract ishunk to a function
Laurent Charignon <lcharignon@fb.com>
parents: 25228
diff changeset
298 def ishunk(x):
5a8398b085ed record: extract ishunk to a function
Laurent Charignon <lcharignon@fb.com>
parents: 25228
diff changeset
299 hunkclasses = (crecordmod.uihunk, patch.recordhunk)
5a8398b085ed record: extract ishunk to a function
Laurent Charignon <lcharignon@fb.com>
parents: 25228
diff changeset
300 return isinstance(x, hunkclasses)
5a8398b085ed record: extract ishunk to a function
Laurent Charignon <lcharignon@fb.com>
parents: 25228
diff changeset
301
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
302
25257
07326d76f19d record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents: 25256
diff changeset
303 def newandmodified(chunks, originalchunks):
07326d76f19d record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents: 25256
diff changeset
304 newlyaddedandmodifiedfiles = set()
42862
3cf091843b4f split: handle partial commit of renames when doing split or record (issue5723)
Kyle Lippincott <spectral@google.com>
parents: 42643
diff changeset
305 alsorestore = set()
25257
07326d76f19d record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents: 25256
diff changeset
306 for chunk in chunks:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
307 if (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
308 ishunk(chunk)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
309 and chunk.header.isnewfile()
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
310 and chunk not in originalchunks
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
311 ):
25257
07326d76f19d record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents: 25256
diff changeset
312 newlyaddedandmodifiedfiles.add(chunk.header.filename())
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
313 alsorestore.update(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
314 set(chunk.header.files()) - {chunk.header.filename()}
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
315 )
42862
3cf091843b4f split: handle partial commit of renames when doing split or record (issue5723)
Kyle Lippincott <spectral@google.com>
parents: 42643
diff changeset
316 return newlyaddedandmodifiedfiles, alsorestore
25257
07326d76f19d record: extract code to compute newly added and modified files
Laurent Charignon <lcharignon@fb.com>
parents: 25256
diff changeset
317
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
318
10401
6252852b4332 mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents: 10344
diff changeset
319 def parsealiases(cmd):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
320 return cmd.split(b"|")
10401
6252852b4332 mq: add -Q option to all commands not in norepo
Brendan Cully <brendan@kublai.com>
parents: 10344
diff changeset
321
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
322
24356
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
323 def setupwrapcolorwrite(ui):
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
324 # 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
325 def wrapwrite(orig, *args, **kw):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
326 label = kw.pop(r'label', b'')
24356
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
327 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
328 orig(chunk, label=label + l)
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
329
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
330 oldwrite = ui.write
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
331
24356
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
332 def wrap(*args, **kwargs):
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
333 return wrapwrite(oldwrite, *args, **kwargs)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
334
24356
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
335 setattr(ui, 'write', wrap)
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
336 return oldwrite
a38f384f2a57 record: consolidate ui.write wrapping in a function
Laurent Charignon <lcharignon@fb.com>
parents: 24345
diff changeset
337
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
338
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
339 def filterchunks(ui, originalhunks, usecurses, testfile, match, operation=None):
38080
dabc2237963c crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents: 38002
diff changeset
340 try:
dabc2237963c crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents: 38002
diff changeset
341 if usecurses:
dabc2237963c crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents: 38002
diff changeset
342 if testfile:
dabc2237963c crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents: 38002
diff changeset
343 recordfn = crecordmod.testdecorator(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
344 testfile, crecordmod.testchunkselector
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
345 )
38080
dabc2237963c crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents: 38002
diff changeset
346 else:
dabc2237963c crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents: 38002
diff changeset
347 recordfn = crecordmod.chunkselector
dabc2237963c crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents: 38002
diff changeset
348
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
349 return crecordmod.filterpatch(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
350 ui, originalhunks, recordfn, operation
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
351 )
38080
dabc2237963c crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents: 38002
diff changeset
352 except crecordmod.fallbackerror as e:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
353 ui.warn(b'%s\n' % e.message)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
354 ui.warn(_(b'falling back to text mode\n'))
38080
dabc2237963c crecord: fallback to text mode if diffs are too big for curses mode
Kyle Lippincott <spectral@google.com>
parents: 38002
diff changeset
355
42071
db72f9f6580e interactive: do not prompt about files given in command line
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 42057
diff changeset
356 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
357
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
358
42071
db72f9f6580e interactive: do not prompt about files given in command line
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 42057
diff changeset
359 def recordfilter(ui, originalhunks, match, operation=None):
25310
c1f5ef76d1c2 record: add an operation arguments to customize recording ui
Laurent Charignon <lcharignon@fb.com>
parents: 25273
diff changeset
360 """ Prompts the user to filter the originalhunks and return a list of
c1f5ef76d1c2 record: add an operation arguments to customize recording ui
Laurent Charignon <lcharignon@fb.com>
parents: 25273
diff changeset
361 selected hunks.
29326
d48fc6f318a3 patch: define full messages for interactive record/revert
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 29283
diff changeset
362 *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
363 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
364 (see patch.filterpatch).
25310
c1f5ef76d1c2 record: add an operation arguments to customize recording ui
Laurent Charignon <lcharignon@fb.com>
parents: 25273
diff changeset
365 """
27531
84d686cb62c4 cmdutil: use crecordmod.checkcurses
Sean Farley <sean@farley.io>
parents: 27370
diff changeset
366 usecurses = crecordmod.checkcurses(ui)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
367 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
368 oldwrite = setupwrapcolorwrite(ui)
8d9e9063b040 record: move ui.write wrapping where it should be
Laurent Charignon <lcharignon@fb.com>
parents: 24357
diff changeset
369 try:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
370 newchunks, newopts = filterchunks(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
371 ui, originalhunks, usecurses, testfile, match, operation
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
372 )
24358
8d9e9063b040 record: move ui.write wrapping where it should be
Laurent Charignon <lcharignon@fb.com>
parents: 24357
diff changeset
373 finally:
8d9e9063b040 record: move ui.write wrapping where it should be
Laurent Charignon <lcharignon@fb.com>
parents: 24357
diff changeset
374 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
375 return newchunks, newopts
24357
2da601ab3125 record: refactor the filtering code
Laurent Charignon <lcharignon@fb.com>
parents: 24356
diff changeset
376
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
377
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
378 def dorecord(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
379 ui, repo, commitfunc, cmdsuggest, backupall, filterfn, *pats, **opts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
380 ):
32193
93155367a2a6 py3: convert opts to bytes in cmdutil.dorecord()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32046
diff changeset
381 opts = pycompat.byteskwargs(opts)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
382 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
383 if cmdsuggest:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
384 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
385 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
386 msg = _(b'running non-interactively')
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
387 raise error.Abort(msg)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
388
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
389 # 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
390 if not opts.get(b'user'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
391 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
392
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
393 def recordfunc(ui, repo, message, match, opts):
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
394 """This is generic record driver.
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
395
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
396 Its job is to interactively filter local changes, and
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
397 accordingly prepare working directory into a state in which the
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
398 job can be delegated to a non-interactive commit command such as
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
399 'commit' or 'qrefresh'.
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
400
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
401 After the actual job is done by non-interactive command, the
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
402 working directory is restored to its original state.
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
403
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
404 In the end we'll record interesting changes, and everything else
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
405 will be left in place, so the user can continue working.
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
406 """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
407 if not opts.get(b'interactive-unshelve'):
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42582
diff changeset
408 checkunfinished(repo, commit=True)
28815
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
409 wctx = repo[None]
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
410 merge = len(wctx.parents()) > 1
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
411 if merge:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
412 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
413 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
414 b'cannot partially commit a merge '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
415 b'(use "hg commit" instead)'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
416 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
417 )
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
418
42163
e45c6b153e51 commit: allow --interactive to work again when naming a directory (issue6131)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42071
diff changeset
419 def fail(f, msg):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
420 raise error.Abort(b'%s: %s' % (f, msg))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
421
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
422 force = opts.get(b'force')
42163
e45c6b153e51 commit: allow --interactive to work again when naming a directory (issue6131)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42071
diff changeset
423 if not force:
e45c6b153e51 commit: allow --interactive to work again when naming a directory (issue6131)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42071
diff changeset
424 vdirs = []
42297
19b95afb0c01 record: avoid modifying the matcher passed as a method parameter
Matt Harbison <matt_harbison@yahoo.com>
parents: 42163
diff changeset
425 match = matchmod.badmatch(match, fail)
42163
e45c6b153e51 commit: allow --interactive to work again when naming a directory (issue6131)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42071
diff changeset
426 match.explicitdir = vdirs.append
e45c6b153e51 commit: allow --interactive to work again when naming a directory (issue6131)
Matt Harbison <matt_harbison@yahoo.com>
parents: 42071
diff changeset
427
41330
4ea21df312ec record: prevent commits that don't pick up dirty subrepo changes (issue6102)
Matt Harbison <matt_harbison@yahoo.com>
parents: 41206
diff changeset
428 status = repo.status(match=match)
4ea21df312ec record: prevent commits that don't pick up dirty subrepo changes (issue6102)
Matt Harbison <matt_harbison@yahoo.com>
parents: 41206
diff changeset
429
4ea21df312ec record: prevent commits that don't pick up dirty subrepo changes (issue6102)
Matt Harbison <matt_harbison@yahoo.com>
parents: 41206
diff changeset
430 overrides = {(b'ui', b'commitsubrepos'): True}
4ea21df312ec record: prevent commits that don't pick up dirty subrepo changes (issue6102)
Matt Harbison <matt_harbison@yahoo.com>
parents: 41206
diff changeset
431
4ea21df312ec record: prevent commits that don't pick up dirty subrepo changes (issue6102)
Matt Harbison <matt_harbison@yahoo.com>
parents: 41206
diff changeset
432 with repo.ui.configoverride(overrides, b'record'):
4ea21df312ec record: prevent commits that don't pick up dirty subrepo changes (issue6102)
Matt Harbison <matt_harbison@yahoo.com>
parents: 41206
diff changeset
433 # subrepoutil.precommit() modifies the status
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
434 tmpstatus = scmutil.status(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
435 copymod.copy(status[0]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
436 copymod.copy(status[1]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
437 copymod.copy(status[2]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
438 copymod.copy(status[3]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
439 copymod.copy(status[4]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
440 copymod.copy(status[5]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
441 copymod.copy(status[6]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
442 )
41330
4ea21df312ec record: prevent commits that don't pick up dirty subrepo changes (issue6102)
Matt Harbison <matt_harbison@yahoo.com>
parents: 41206
diff changeset
443
4ea21df312ec record: prevent commits that don't pick up dirty subrepo changes (issue6102)
Matt Harbison <matt_harbison@yahoo.com>
parents: 41206
diff changeset
444 # Force allows -X subrepo to skip the subrepo.
4ea21df312ec record: prevent commits that don't pick up dirty subrepo changes (issue6102)
Matt Harbison <matt_harbison@yahoo.com>
parents: 41206
diff changeset
445 subs, commitsubs, newstate = subrepoutil.precommit(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
446 repo.ui, wctx, tmpstatus, match, force=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
447 )
41330
4ea21df312ec record: prevent commits that don't pick up dirty subrepo changes (issue6102)
Matt Harbison <matt_harbison@yahoo.com>
parents: 41206
diff changeset
448 for s in subs:
4ea21df312ec record: prevent commits that don't pick up dirty subrepo changes (issue6102)
Matt Harbison <matt_harbison@yahoo.com>
parents: 41206
diff changeset
449 if s in commitsubs:
4ea21df312ec record: prevent commits that don't pick up dirty subrepo changes (issue6102)
Matt Harbison <matt_harbison@yahoo.com>
parents: 41206
diff changeset
450 dirtyreason = wctx.sub(s).dirtyreason(True)
4ea21df312ec record: prevent commits that don't pick up dirty subrepo changes (issue6102)
Matt Harbison <matt_harbison@yahoo.com>
parents: 41206
diff changeset
451 raise error.Abort(dirtyreason)
4ea21df312ec record: prevent commits that don't pick up dirty subrepo changes (issue6102)
Matt Harbison <matt_harbison@yahoo.com>
parents: 41206
diff changeset
452
28815
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
453 if not force:
44611ad4fbd9 crecord: check for untracked arguments
timeless <timeless@mozdev.org>
parents: 28638
diff changeset
454 repo.checkcommitpatterns(wctx, vdirs, match, status, fail)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
455 diffopts = patch.difffeatureopts(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
456 ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
457 opts=opts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
458 whitespace=True,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
459 section=b'commands',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
460 configprefix=b'commit.interactive.',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
461 )
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
462 diffopts.nodates = True
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
463 diffopts.git = True
27411
c84a07530040 record: turn on showfunc
timeless <timeless@mozdev.org>
parents: 27391
diff changeset
464 diffopts.showfunc = True
27637
b502138f5faa cleanup: remove superfluous space after space after equals (python)
timeless <timeless@mozdev.org>
parents: 27625
diff changeset
465 originaldiff = patch.diff(repo, changes=status, opts=diffopts)
24341
616c01b69898 record: change interface of the filtering function
Laurent Charignon <lcharignon@fb.com>
parents: 24311
diff changeset
466 originalchunks = patch.parsepatch(originaldiff)
42071
db72f9f6580e interactive: do not prompt about files given in command line
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 42057
diff changeset
467 match = scmutil.match(repo[None], pats)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
468
28570
5508cf9a52fe crecord: rewrite a comment about filtering patches
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28452
diff changeset
469 # 1. filter patch, since we are intending to apply subset of it
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
470 try:
42071
db72f9f6580e interactive: do not prompt about files given in command line
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 42057
diff changeset
471 chunks, newopts = filterfn(ui, originalchunks, match)
34258
61714510220d error: move patch.PatchError so it can easily implement __bytes__ (API)
Yuya Nishihara <yuya@tcha.org>
parents: 34201
diff changeset
472 except error.PatchError as err:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
473 raise error.Abort(_(b'error parsing patch: %s') % err)
27155
8d3c5797a175 commit: add a way to return more information from the chunkselector
Laurent Charignon <lcharignon@fb.com>
parents: 27148
diff changeset
474 opts.update(newopts)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
475
24845
8133494accf1 record: edit patch of newly added files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents: 24843
diff changeset
476 # We need to keep a backup of files that have been newly added and
8133494accf1 record: edit patch of newly added files (issue4304)
Laurent Charignon <lcharignon@fb.com>
parents: 24843
diff changeset
477 # modified during the recording process because there is a previous
42862
3cf091843b4f split: handle partial commit of renames when doing split or record (issue5723)
Kyle Lippincott <spectral@google.com>
parents: 42643
diff changeset
478 # version without the edit in the workdir. We also will need to restore
3cf091843b4f split: handle partial commit of renames when doing split or record (issue5723)
Kyle Lippincott <spectral@google.com>
parents: 42643
diff changeset
479 # files that were the sources of renames so that the patch application
3cf091843b4f split: handle partial commit of renames when doing split or record (issue5723)
Kyle Lippincott <spectral@google.com>
parents: 42643
diff changeset
480 # works.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
481 newlyaddedandmodifiedfiles, alsorestore = newandmodified(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
482 chunks, originalchunks
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
483 )
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
484 contenders = set()
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
485 for h in chunks:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
486 try:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
487 contenders.update(set(h.files()))
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
488 except AttributeError:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
489 pass
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
490
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
491 changed = status.modified + status.added + status.removed
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
492 newfiles = [f for f in changed if f in contenders]
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
493 if not newfiles:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
494 ui.status(_(b'no changes to record\n'))
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
495 return 0
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
496
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
497 modified = set(status.modified)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
498
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
499 # 2. backup changed files, so we can restore them in the end
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
500
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
501 if backupall:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
502 tobackup = changed
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
503 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
504 tobackup = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
505 f
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
506 for f in newfiles
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
507 if f in modified or f in newlyaddedandmodifiedfiles
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
508 ]
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
509 backups = {}
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
510 if tobackup:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
511 backupdir = repo.vfs.join(b'record-backups')
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
512 try:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
513 os.mkdir(backupdir)
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25657
diff changeset
514 except OSError as err:
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
515 if err.errno != errno.EEXIST:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
516 raise
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
517 try:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
518 # backup continues
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
519 for f in tobackup:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
520 fd, tmpname = pycompat.mkstemp(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
521 prefix=f.replace(b'/', b'_') + b'.', dir=backupdir
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
522 )
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
523 os.close(fd)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
524 ui.debug(b'backup %r as %r\n' % (f, tmpname))
27370
d9e3ebe56970 record: don't dereference symlinks while copying over stat data
Siddharth Agarwal <sid0@fb.com>
parents: 26781
diff changeset
525 util.copyfile(repo.wjoin(f), tmpname, copystat=True)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
526 backups[f] = tmpname
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
527
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28837
diff changeset
528 fp = stringio()
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
529 for c in chunks:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
530 fname = c.filename()
24837
edf907bd8144 record: fix record with change on moved file crashes (issue4619)
Laurent Charignon <lcharignon@fb.com>
parents: 24720
diff changeset
531 if fname in backups:
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
532 c.write(fp)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
533 dopatch = fp.tell()
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
534 fp.seek(0)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
535
28638
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28630
diff changeset
536 # 2.5 optionally review / modify patch in text editor
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
537 if opts.get(b'review', False):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
538 patchtext = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
539 crecordmod.diffhelptext
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
540 + crecordmod.patchhelptext
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
541 + fp.read()
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
542 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
543 reviewedpatch = ui.edit(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
544 patchtext, b"", action=b"diff", repopath=repo.path
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
545 )
28638
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28630
diff changeset
546 fp.truncate(0)
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28630
diff changeset
547 fp.write(reviewedpatch)
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28630
diff changeset
548 fp.seek(0)
44319097e7b9 crecord: re-enable reviewing a patch before comitting it
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 28630
diff changeset
549
24866
e1ec3d075c67 record: fix adding new file with record from within a subdir (issue4626)
Laurent Charignon <lcharignon@fb.com>
parents: 24864
diff changeset
550 [os.unlink(repo.wjoin(c)) for c in newlyaddedandmodifiedfiles]
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
551 # 3a. apply filtered patch to clean repo (clean)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
552 if backups:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
553 # Equivalent to hg.revert
42862
3cf091843b4f split: handle partial commit of renames when doing split or record (issue5723)
Kyle Lippincott <spectral@google.com>
parents: 42643
diff changeset
554 m = scmutil.matchfiles(repo, set(backups.keys()) | alsorestore)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
555 mergemod.update(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
556 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
557 repo.dirstate.p1(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
558 branchmerge=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
559 force=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
560 matcher=m,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
561 )
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
562
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
563 # 3b. (apply)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
564 if dopatch:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
565 try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
566 ui.debug(b'applying patch\n')
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
567 ui.debug(fp.getvalue())
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
568 patch.internalpatch(ui, repo, fp, 1, eolmode=None)
34258
61714510220d error: move patch.PatchError so it can easily implement __bytes__ (API)
Yuya Nishihara <yuya@tcha.org>
parents: 34201
diff changeset
569 except error.PatchError as err:
36742
390d16ea7c76 py3: use pycompat.bytestr instead of str
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36692
diff changeset
570 raise error.Abort(pycompat.bytestr(err))
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
571 del fp
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
572
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
573 # 4. We prepared working directory according to filtered
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
574 # patch. Now is the time to delegate the job to
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
575 # commit/qrefresh or the like!
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
576
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
577 # Make all of the pathnames absolute.
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
578 newfiles = [repo.wjoin(nf) for nf in newfiles]
35359
82ee401135dd py3: handle keyword arguments correctly in cmdutil.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35286
diff changeset
579 return commitfunc(ui, repo, *newfiles, **pycompat.strkwargs(opts))
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
580 finally:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
581 # 5. finally restore backed-up files
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
582 try:
25759
ff11c1565c04 cmdutil: apply dirstate.normallookup on (maybe partially) committed files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25758
diff changeset
583 dirstate = repo.dirstate
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
584 for realname, tmpname in backups.iteritems():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
585 ui.debug(b'restoring %r to %r\n' % (tmpname, realname))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
586
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
587 if dirstate[realname] == b'n':
25759
ff11c1565c04 cmdutil: apply dirstate.normallookup on (maybe partially) committed files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25758
diff changeset
588 # without normallookup, restoring timestamp
ff11c1565c04 cmdutil: apply dirstate.normallookup on (maybe partially) committed files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25758
diff changeset
589 # may cause partially committed files
ff11c1565c04 cmdutil: apply dirstate.normallookup on (maybe partially) committed files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25758
diff changeset
590 # to be treated as unmodified
ff11c1565c04 cmdutil: apply dirstate.normallookup on (maybe partially) committed files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25758
diff changeset
591 dirstate.normallookup(realname)
ff11c1565c04 cmdutil: apply dirstate.normallookup on (maybe partially) committed files
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25758
diff changeset
592
27370
d9e3ebe56970 record: don't dereference symlinks while copying over stat data
Siddharth Agarwal <sid0@fb.com>
parents: 26781
diff changeset
593 # copystat=True here and above are a hack to trick any
d9e3ebe56970 record: don't dereference symlinks while copying over stat data
Siddharth Agarwal <sid0@fb.com>
parents: 26781
diff changeset
594 # editors that have f open that we haven't modified them.
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
595 #
27370
d9e3ebe56970 record: don't dereference symlinks while copying over stat data
Siddharth Agarwal <sid0@fb.com>
parents: 26781
diff changeset
596 # Also note that this racy as an editor could notice the
d9e3ebe56970 record: don't dereference symlinks while copying over stat data
Siddharth Agarwal <sid0@fb.com>
parents: 26781
diff changeset
597 # file's mtime before we've finished writing it.
d9e3ebe56970 record: don't dereference symlinks while copying over stat data
Siddharth Agarwal <sid0@fb.com>
parents: 26781
diff changeset
598 util.copyfile(tmpname, repo.wjoin(realname), copystat=True)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
599 os.unlink(tmpname)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
600 if tobackup:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
601 os.rmdir(backupdir)
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
602 except OSError:
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
603 pass
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
604
25758
c5dfa47ad7ee cmdutil: put recordfunc invocation into wlock scope for consistency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25755
diff changeset
605 def recordinwlock(ui, repo, message, match, opts):
27801
7be6371c732e with: use context manager for wlock in recordinwlock
Bryan O'Sullivan <bryano@fb.com>
parents: 27698
diff changeset
606 with repo.wlock():
25758
c5dfa47ad7ee cmdutil: put recordfunc invocation into wlock scope for consistency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25755
diff changeset
607 return recordfunc(ui, repo, message, match, opts)
c5dfa47ad7ee cmdutil: put recordfunc invocation into wlock scope for consistency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25755
diff changeset
608
c5dfa47ad7ee cmdutil: put recordfunc invocation into wlock scope for consistency
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25755
diff changeset
609 return commit(ui, repo, recordinwlock, pats, opts)
24272
26a1c617e047 record: move dorecord from record to cmdutil
Laurent Charignon <lcharignon@fb.com>
parents: 24260
diff changeset
610
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
611
34682
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
612 class dirnode(object):
33548
4cd4344a53c4 status: add a flag to terse the output (issue4119)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33509
diff changeset
613 """
34698
23eb03f46929 tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents: 34684
diff changeset
614 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
615 the purpose of tersing its status.
34682
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
616
38231
51e420a7a41a cmdutil: use internal separators when building the terse list
Matt Harbison <matt_harbison@yahoo.com>
parents: 38197
diff changeset
617 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: 34373
diff changeset
618
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
619 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: 34373
diff changeset
620 all the files in all the subdirectories too)
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
621
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
622 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: 34373
diff changeset
623
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
624 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: 34373
diff changeset
625 dirnode object as the value
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
626 """
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
627
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
628 def __init__(self, dirpath):
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
629 self.path = dirpath
42057
566daffc607d cleanup: use set literals where possible
Martin von Zweigbergk <martinvonz@google.com>
parents: 41994
diff changeset
630 self.statuses = set()
34682
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
631 self.files = []
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
632 self.subdirs = {}
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
633
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
634 def _addfileindir(self, filename, status):
34698
23eb03f46929 tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents: 34684
diff changeset
635 """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: 34373
diff changeset
636 self.files.append((filename, status))
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
637
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
638 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
639 """
34698
23eb03f46929 tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents: 34684
diff changeset
640 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
641
23eb03f46929 tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents: 34684
diff changeset
642 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
643 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
644 there.
33548
4cd4344a53c4 status: add a flag to terse the output (issue4119)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33509
diff changeset
645 """
34682
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
646
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
647 # 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: 34373
diff changeset
648 # child of this directory
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
649 if b'/' in filename:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
650 subdir, filep = filename.split(b'/', 1)
34682
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
651
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
652 # does the dirnode object for subdir exists
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
653 if subdir not in self.subdirs:
38231
51e420a7a41a cmdutil: use internal separators when building the terse list
Matt Harbison <matt_harbison@yahoo.com>
parents: 38197
diff changeset
654 subdirpath = pathutil.join(self.path, subdir)
34682
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
655 self.subdirs[subdir] = dirnode(subdirpath)
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
656
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
657 # try adding the file in subdir
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
658 self.subdirs[subdir].addfile(filep, status)
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
659
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
660 else:
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
661 self._addfileindir(filename, status)
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
662
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
663 if status not in self.statuses:
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
664 self.statuses.add(status)
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
665
34684
5d98674df18a tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents: 34683
diff changeset
666 def iterfilepaths(self):
34698
23eb03f46929 tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents: 34684
diff changeset
667 """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
668 for f, st in self.files:
38231
51e420a7a41a cmdutil: use internal separators when building the terse list
Matt Harbison <matt_harbison@yahoo.com>
parents: 38197
diff changeset
669 yield st, pathutil.join(self.path, f)
34684
5d98674df18a tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents: 34683
diff changeset
670
5d98674df18a tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents: 34683
diff changeset
671 def tersewalk(self, terseargs):
34683
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
672 """
34698
23eb03f46929 tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents: 34684
diff changeset
673 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
674 dirnode.
34683
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
675
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
676 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
677 flag.
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
678
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
679 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
680
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
681 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
682 subdirectories) share the same status and the user has asked us to terse
38231
51e420a7a41a cmdutil: use internal separators when building the terse list
Matt Harbison <matt_harbison@yahoo.com>
parents: 38197
diff changeset
683 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
684
34698
23eb03f46929 tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents: 34684
diff changeset
685 2) Otherwise, we do following:
34683
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
686
34684
5d98674df18a tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents: 34683
diff changeset
687 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
688 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
689
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
690 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
691 directory
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
692 """
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
693
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
694 if len(self.statuses) == 1:
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
695 onlyst = self.statuses.pop()
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
696
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
697 # 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
698 # passed as terse argument
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
699 if onlyst in terseargs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
700 yield onlyst, self.path + b'/'
34683
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
701 return
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
702
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
703 # add the files to status list
34684
5d98674df18a tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents: 34683
diff changeset
704 for st, fpath in self.iterfilepaths():
5d98674df18a tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents: 34683
diff changeset
705 yield st, fpath
34683
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
706
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
707 # recurse on the subdirs
34683
3d6d4b12128e tersestatus: make methods part of the dirnode class
Denis Laxalde <denis@laxalde.org>
parents: 34682
diff changeset
708 for dirobj in self.subdirs.values():
34684
5d98674df18a tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents: 34683
diff changeset
709 for st, fpath in dirobj.tersewalk(terseargs):
5d98674df18a tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents: 34683
diff changeset
710 yield st, fpath
34682
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
711
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
712
34682
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
713 def tersedir(statuslist, terseargs):
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
714 """
34698
23eb03f46929 tersestatus: rework dirnode and tersedir docstrings
Denis Laxalde <denis@laxalde.org>
parents: 34684
diff changeset
715 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: 34373
diff changeset
716
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
717 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: 34373
diff changeset
718 each status.
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
719 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: 34373
diff changeset
720 flag.
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
721
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
722 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: 34373
diff changeset
723 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: 34373
diff changeset
724 directory or not.
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
725 """
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
726 # 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
727 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: 34373
diff changeset
728
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
729 # checking the argument validity
34893
068e0e531584 cmdutil: fix status tersing on Python 3
Augie Fackler <augie@google.com>
parents: 34857
diff changeset
730 for s in pycompat.bytestr(terseargs):
34682
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
731 if s not in allst:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
732 raise error.Abort(_(b"'%s' not recognized") % s)
34682
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
733
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
734 # 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
735 rootobj = dirnode(b'')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
736 pstatus = (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
737 b'modified',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
738 b'added',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
739 b'deleted',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
740 b'clean',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
741 b'unknown',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
742 b'ignored',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
743 b'removed',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
744 )
34682
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
745
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
746 tersedict = {}
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
747 for attrname in pstatus:
34893
068e0e531584 cmdutil: fix status tersing on Python 3
Augie Fackler <augie@google.com>
parents: 34857
diff changeset
748 statuschar = attrname[0:1]
34682
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
749 for f in getattr(statuslist, attrname):
34893
068e0e531584 cmdutil: fix status tersing on Python 3
Augie Fackler <augie@google.com>
parents: 34857
diff changeset
750 rootobj.addfile(f, statuschar)
068e0e531584 cmdutil: fix status tersing on Python 3
Augie Fackler <augie@google.com>
parents: 34857
diff changeset
751 tersedict[statuschar] = []
34682
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
752
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
753 # 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
754 for st, fpath in rootobj.iterfilepaths():
5d98674df18a tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents: 34683
diff changeset
755 tersedict[st].append(fpath)
34682
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
756
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
757 # process each sub-directory and build tersedict
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
758 for subdir in rootobj.subdirs.values():
34684
5d98674df18a tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents: 34683
diff changeset
759 for st, f in subdir.tersewalk(terseargs):
5d98674df18a tersestatus: avoid modifying tersedict
Denis Laxalde <denis@laxalde.org>
parents: 34683
diff changeset
760 tersedict[st].append(f)
34682
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
761
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
762 tersedlist = []
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
763 for st in allst:
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
764 tersedict[st].sort()
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
765 tersedlist.append(tersedict[st])
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
766
7e3001b74ab3 tersestatus: re-implement the functionality to terse the status
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34373
diff changeset
767 return tersedlist
33548
4cd4344a53c4 status: add a flag to terse the output (issue4119)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33509
diff changeset
768
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
769
33792
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
770 def _commentlines(raw):
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
771 '''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: 33763
diff changeset
772 lines = raw.splitlines()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
773 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
774 return b'\n'.join(commentedlines) + b'\n'
33792
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
775
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
776
33792
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
777 def _conflictsmsg(repo):
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
778 mergestate = mergemod.mergestate.read(repo)
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
779 if not mergestate.active():
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
780 return
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
781
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
782 m = scmutil.match(repo[None])
34019
3340efe80803 morestatus: simplify check for unresolved merge conflicts
Martin von Zweigbergk <martinvonz@google.com>
parents: 33902
diff changeset
783 unresolvedlist = [f for f in mergestate.unresolved() if m(f)]
33792
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
784 if unresolvedlist:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
785 mergeliststr = b'\n'.join(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
786 [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
787 b' %s' % util.pathto(repo.root, encoding.getcwd(), path)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
788 for path in sorted(unresolvedlist)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
789 ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
790 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
791 msg = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
792 _(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
793 '''Unresolved merge conflicts:
33792
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
794
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
795 %s
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
796
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
797 To mark files as resolved: hg resolve --mark FILE'''
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
798 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
799 % mergeliststr
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
800 )
33792
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
801 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
802 msg = _(b'No unresolved merge conflicts.')
33792
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
803
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
804 return _commentlines(msg)
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
805
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
806
33792
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
807 def morestatus(repo, fm):
42538
5bddd2244814 state: moved cmdutil.STATES and utilities to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents: 42537
diff changeset
808 statetuple = statemod.getrepostate(repo)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
809 label = b'status.morestatus'
33792
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
810 if statetuple:
42539
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42538
diff changeset
811 state, helpfulmsg = statetuple
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
812 statemsg = _(b'The repository is in an unfinished *%s* state.') % state
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
813 fm.plain(b'%s\n' % _commentlines(statemsg), label=label)
33792
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
814 conmsg = _conflictsmsg(repo)
33902
e5d104c35e51 morestatus: check whether the conflict message is None before printing
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33879
diff changeset
815 if conmsg:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
816 fm.plain(b'%s\n' % conmsg, label=label)
33792
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
817 if helpfulmsg:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
818 fm.plain(b'%s\n' % _commentlines(helpfulmsg), label=label)
33792
96f43981c1c4 morestatus: move fb extension to core by plugging to `hg status --verbose`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33763
diff changeset
819
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
820
7213
b4c035057d34 findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents: 7121
diff changeset
821 def findpossible(cmd, table, strict=False):
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
822 """
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
823 Return cmd -> (aliases, command table entry)
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
824 for each matching command.
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
825 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
826 """
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
827 choice = {}
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
828 debugchoice = {}
15600
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
829
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
830 if cmd in table:
40295
fa88170c10bb help: adding a proper declaration for shortlist/basic commands (API)
Rodrigo Damazio <rdamazio@google.com>
parents: 40102
diff changeset
831 # 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
832 keys = [cmd]
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
833 else:
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
834 keys = table.keys()
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
835
24222
02d7b5cd373b dispatch: offer suggestions of similar-named commands
Augie Fackler <augie@google.com>
parents: 24216
diff changeset
836 allcmds = []
15600
195dbd1cef0c alias: shortcut command matching show shadowing works properly (issue3104)
Matt Mackall <mpm@selenic.com>
parents: 15231
diff changeset
837 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
838 aliases = parsealiases(e)
24222
02d7b5cd373b dispatch: offer suggestions of similar-named commands
Augie Fackler <augie@google.com>
parents: 24216
diff changeset
839 allcmds.extend(aliases)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
840 found = None
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
841 if cmd in aliases:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
842 found = cmd
7213
b4c035057d34 findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents: 7121
diff changeset
843 elif not strict:
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
844 for a in aliases:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
845 if a.startswith(cmd):
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
846 found = a
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
847 break
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
848 if found is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
849 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
850 debugchoice[found] = (aliases, table[e])
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
851 else:
5178
18a9fbb5cd78 dispatch: move command dispatching into its own module
Matt Mackall <mpm@selenic.com>
parents: 5177
diff changeset
852 choice[found] = (aliases, table[e])
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
853
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
854 if not choice and debugchoice:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
855 choice = debugchoice
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
856
24222
02d7b5cd373b dispatch: offer suggestions of similar-named commands
Augie Fackler <augie@google.com>
parents: 24216
diff changeset
857 return choice, allcmds
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
858
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
859
7213
b4c035057d34 findcmd: have dispatch look up strict flag
Matt Mackall <mpm@selenic.com>
parents: 7121
diff changeset
860 def findcmd(cmd, table, strict=True):
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
861 """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
862 choice, allcmds = findpossible(cmd, table, strict)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
863
5915
d0576d065993 Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents: 5843
diff changeset
864 if cmd in choice:
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
865 return choice[cmd]
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
866
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
867 if len(choice) > 1:
32561
9f56d462634c cmdutil: use sorted(dict) instead of x = dict.keys(); x.sort()
Augie Fackler <raf@durin42.com>
parents: 32472
diff changeset
868 clist = sorted(choice)
7643
9a1ea6587557 error: move UnknownCommand and AmbiguousCommand
Matt Mackall <mpm@selenic.com>
parents: 7404
diff changeset
869 raise error.AmbiguousCommand(cmd, clist)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
870
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
871 if choice:
32880
e4a43b810528 py3: explicitly convert dict.values() to a list on py3
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32860
diff changeset
872 return list(choice.values())[0]
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
873
24222
02d7b5cd373b dispatch: offer suggestions of similar-named commands
Augie Fackler <augie@google.com>
parents: 24216
diff changeset
874 raise error.UnknownCommand(cmd, allcmds)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
875
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
876
35745
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
877 def changebranch(ui, repo, revs, label):
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
878 """ Change the branch name of given revs to label """
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
879
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
880 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
881 # 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
882 bailifchanged(repo)
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
883 revs = scmutil.revrange(repo, revs)
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
884 if not revs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
885 raise error.Abort(b"empty revision set")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
886 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
887 if len(roots) > 1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
888 raise error.Abort(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
889 _(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
890 )
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
891 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
892
e5b6ba786d83 branch: allow changing branch name to existing name if possible
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35745
diff changeset
893 root = repo[roots.first()]
40707
69268a13ffa5 branch: allow changing branch of merge commits with --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 40367
diff changeset
894 rpb = {parent.branch() for parent in root.parents()}
69268a13ffa5 branch: allow changing branch of merge commits with --rev
Anton Shestakov <av6@dwimlabs.net>
parents: 40367
diff changeset
895 if label not in rpb and label in repo.branchmap():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
896 raise error.Abort(_(b"a branch of the same name already exists"))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
897
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
898 if repo.revs(b'obsolete() and %ld', revs):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
899 raise error.Abort(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
900 _(b"cannot change branch of a obsolete changeset")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
901 )
35745
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
902
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
903 # make sure only topological heads
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
904 if repo.revs(b'heads(%ld) - head()', revs):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
905 raise error.Abort(_(b"cannot change branch in middle of a stack"))
35745
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
906
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
907 replacements = {}
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
908 # 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
909 # 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
910 from . import context
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
911
35745
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
912 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
913 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
914 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
915 # 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
916 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
917 continue
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
918
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
919 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
920 try:
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
921 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
922 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
923 return None
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
924
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
925 ui.debug(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
926 b"changing branch of '%s' from '%s' to '%s'\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
927 % (hex(ctx.node()), oldbranch, label)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
928 )
35745
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
929 extra = ctx.extra()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
930 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
931 # 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
932 # 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
933 # 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
934 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
935 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
936 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
937 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
938 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
939 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
940
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
941 mc = context.memctx(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
942 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
943 (p1, p2),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
944 ctx.description(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
945 ctx.files(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
946 filectxfn,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
947 user=ctx.user(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
948 date=ctx.date(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
949 extra=extra,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
950 branch=label,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
951 )
35745
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
952
38429
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 38379
diff changeset
953 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
954 replacements[ctx.node()] = (newnode,)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
955 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
956
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
957 # create obsmarkers and move bookmarks
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
958 scmutil.cleanupnodes(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
959 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
960 )
35745
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
961
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
962 # 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
963 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
964 # 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
965 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
966 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
967 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
968 # 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
969 # mercurial.cmdutil
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
970 from . import hg
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
971
35745
3bd8ab4c80a5 branch: add a --rev flag to change branch name of given revisions
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35743
diff changeset
972 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
973
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
974 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
975
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
976
10402
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
977 def findrepo(p):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
978 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
979 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
980 if p == oldp:
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
981 return None
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
982
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
983 return p
d216fa04e48a mq: make init -Q do what qinit -c did
Brendan Cully <brendan@kublai.com>
parents: 10401
diff changeset
984
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
985
30755
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
986 def bailifchanged(repo, merge=True, hint=None):
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
987 """ enforce the precondition that working directory must be clean.
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
988
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
989 '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
990 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
991
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
992 '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
993 """
0fbb3a5c188e rebase: provide detailed hint to abort message if working dir is not clean
Valters Vingolds <valters@vingolds.ch>
parents: 30724
diff changeset
994
24472
1bf71faf042e cmdutil: allow bailifchanged to ignore merging in progress
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 24471
diff changeset
995 if merge and repo.dirstate.p2() != nullid:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
996 raise error.Abort(_(b'outstanding uncommitted merge'), hint=hint)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
997 modified, added, removed, deleted = repo.status()[:4]
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
998 if modified or added or removed or deleted:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
999 raise error.Abort(_(b'uncommitted changes'), hint=hint)
15231
cd6f10dccf16 cmdutil.bailifchanged: abort for dirty subrepos
Eric Roshan Eisner <ede@alum.mit.edu>
parents: 15214
diff changeset
1000 ctx = repo[None]
18364
6252b4f1c4b4 subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 18340
diff changeset
1001 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
1002 ctx.sub(s).bailifchanged(hint=hint)
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
1003
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1004
14635
217b7d83afc3 cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents: 14518
diff changeset
1005 def logmessage(ui, opts):
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
1006 """ get the log message according to -m and -l option """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1007 message = opts.get(b'message')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1008 logfile = opts.get(b'logfile')
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
1009
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
1010 if message and logfile:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1011 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1012 _(b'options --message and --logfile are mutually ' b'exclusive')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1013 )
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
1014 if not message and logfile:
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
1015 try:
32641
d3e1c5b4986c cmdutil: use isstdiofilename() where appropriate
Yuya Nishihara <yuya@tcha.org>
parents: 32610
diff changeset
1016 if isstdiofilename(logfile):
14635
217b7d83afc3 cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents: 14518
diff changeset
1017 message = ui.fin.read()
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
1018 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1019 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
1020 except IOError as inst:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1021 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1022 _(b"can't read commit message '%s': %s")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1023 % (logfile, encoding.strtolocal(inst.strerror))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1024 )
4549
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
1025 return message
0c61124ad877 dispatch: move dispatching code to cmdutil
Matt Mackall <mpm@selenic.com>
parents: 4548
diff changeset
1026
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1027
24180
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
1028 def mergeeditform(ctxorbool, baseformname):
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
1029 """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
1030
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
1031 '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
1032 merging is committed.
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
1033
24180
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
1034 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
1035 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
1036 """
75618a223e18 commit: change "editform" to distinguish merge commits from others
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22237
diff changeset
1037 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
1038 if ctxorbool:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1039 return baseformname + b".merge"
40030
e2697acd9381 cleanup: some Yoda conditions, this patch removes
Martin von Zweigbergk <martinvonz@google.com>
parents: 39936
diff changeset
1040 elif len(ctxorbool.parents()) > 1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1041 return baseformname + b".merge"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1042
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1043 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
1044
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1045
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1046 def getcommiteditor(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1047 edit=False, finishdesc=None, extramsg=None, editform=b'', **opts
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1048 ):
21419
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
1049 """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
1050
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
1051 '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
1052 (= '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
1053 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
1054 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
1055 storing.
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
1056
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
1057 '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
1058 '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
1059 is automatically added.
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
1060
21999
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
1061 '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
1062 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
1063
21419
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
1064 '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
1065 '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
1066 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
1067 """
272785489ed3 cmdutil: enhance "getcommiteditor()" for specific usages in MQ
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21417
diff changeset
1068 if edit or finishdesc or extramsg:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1069 return lambda r, c, s: commitforceeditor(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1070 r, c, s, finishdesc=finishdesc, extramsg=extramsg, editform=editform
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1071 )
21999
6ce282ed801e cmdutil: introduce 'editform' to distinguish the purpose of commit text editing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21998
diff changeset
1072 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
1073 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
1074 else:
dcf20f244c2a cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21241
diff changeset
1075 return commiteditor
dcf20f244c2a cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21241
diff changeset
1076
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1077
37774
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1078 def _escapecommandtemplate(tmpl):
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1079 parts = []
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1080 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
1081 if typ == b'string':
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1082 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
1083 else:
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1084 parts.append(tmpl[start:end])
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1085 return b''.join(parts)
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1086
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1087
37774
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1088 def rendercommandtemplate(ui, tmpl, props):
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1089 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
1090
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1091 '\' 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
1092 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
1093
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1094 >>> from . import ui as uimod
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1095 >>> ui = uimod.ui()
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1096 >>> 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
1097 'c:\\foo'
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1098 >>> 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
1099 'c:{path}'
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1100 """
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1101 if not tmpl:
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1102 return tmpl
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1103 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
1104 return t.renderdefault(props)
d6970628b95f fix: use templater to substitute values in command string
Yuya Nishihara <yuya@tcha.org>
parents: 37763
diff changeset
1105
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1106
36540
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1107 def rendertemplate(ctx, tmpl, props=None):
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1108 """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: 36538
diff changeset
1109
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1110 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: 36538
diff changeset
1111 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: 36538
diff changeset
1112 """
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1113 repo = ctx.repo()
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1114 tres = formatter.templateresources(repo.ui, repo)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1115 t = formatter.maketemplater(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1116 repo.ui, tmpl, defaults=templatekw.keywords, resources=tres
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1117 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1118 mapping = {b'ctx': ctx}
36540
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1119 if props:
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1120 mapping.update(props)
36991
317382151ac3 templater: rename .render(mapping) to .renderdefault(mapping) (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36989
diff changeset
1121 return t.renderdefault(mapping)
36540
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1122
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1123
36540
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1124 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: 36538
diff changeset
1125 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: 36538
diff changeset
1126
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1127 >>> _buildfntemplate(b'foo-%b-%n.patch', seqno=0)
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1128 'foo-{reporoot|basename}-{seqno}.patch'
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1129 >>> _buildfntemplate(b'%R{tags % "{tag}"}%H')
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1130 '{rev}{tags % "{tag}"}{node}'
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1131
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1132 '\' 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: 36538
diff changeset
1133 separator on Windows:
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1134
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1135 >>> _buildfntemplate(b'c:\\tmp\\%R\\%n.patch', seqno=0)
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1136 'c:\\\\tmp\\\\{rev}\\\\{seqno}.patch'
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1137 >>> _buildfntemplate(b'\\\\foo\\bar.patch')
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1138 '\\\\\\\\foo\\\\bar.patch'
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1139 >>> _buildfntemplate(b'\\{tags % "{tag}"}')
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1140 '\\\\{tags % "{tag}"}'
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1141
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1142 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: 36538
diff changeset
1143 escape character):
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1144
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1145 >>> _buildfntemplate(br'{"c:\tmp"}', seqno=0)
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1146 '{"c:\\tmp"}'
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1147 """
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
1148 expander = {
36540
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1149 b'H': b'{node}',
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1150 b'R': b'{rev}',
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1151 b'h': b'{node|short}',
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1152 b'm': br'{sub(r"[^\w]", "_", desc|firstline)}',
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1153 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: 36538
diff changeset
1154 b'%': b'%',
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1155 b'b': b'{reporoot|basename}',
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1156 }
36276
428de1a59f2d cmdutil: narrow scope of KeyError in makefilename()
Yuya Nishihara <yuya@tcha.org>
parents: 36245
diff changeset
1157 if total is not None:
36540
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1158 expander[b'N'] = b'{total}'
36276
428de1a59f2d cmdutil: narrow scope of KeyError in makefilename()
Yuya Nishihara <yuya@tcha.org>
parents: 36245
diff changeset
1159 if seqno is not None:
36540
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1160 expander[b'n'] = b'{seqno}'
36276
428de1a59f2d cmdutil: narrow scope of KeyError in makefilename()
Yuya Nishihara <yuya@tcha.org>
parents: 36245
diff changeset
1161 if total is not None and seqno is not None:
36540
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1162 expander[b'n'] = b'{pad(seqno, total|stringify|count, "0", left=True)}'
36276
428de1a59f2d cmdutil: narrow scope of KeyError in makefilename()
Yuya Nishihara <yuya@tcha.org>
parents: 36245
diff changeset
1163 if pathname is not None:
36540
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1164 expander[b's'] = b'{pathname|basename}'
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1165 expander[b'd'] = b'{if(pathname|dirname, pathname|dirname, ".")}'
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1166 expander[b'p'] = b'{pathname}'
36276
428de1a59f2d cmdutil: narrow scope of KeyError in makefilename()
Yuya Nishihara <yuya@tcha.org>
parents: 36245
diff changeset
1167
428de1a59f2d cmdutil: narrow scope of KeyError in makefilename()
Yuya Nishihara <yuya@tcha.org>
parents: 36245
diff changeset
1168 newname = []
36540
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1169 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: 36538
diff changeset
1170 if typ != b'string':
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1171 newname.append(pat[start:end])
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1172 continue
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1173 i = start
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1174 while i < end:
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1175 n = pat.find(b'%', i, end)
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1176 if n < 0:
37087
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36991
diff changeset
1177 newname.append(stringutil.escapestr(pat[i:end]))
36540
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1178 break
37087
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36991
diff changeset
1179 newname.append(stringutil.escapestr(pat[i:n]))
36540
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1180 if n + 2 > end:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1181 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1182 _(b"incomplete format spec in output " b"filename")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1183 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1184 c = pat[n + 1 : n + 2]
36540
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1185 i = n + 2
36276
428de1a59f2d cmdutil: narrow scope of KeyError in makefilename()
Yuya Nishihara <yuya@tcha.org>
parents: 36245
diff changeset
1186 try:
36540
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1187 newname.append(expander[c])
36276
428de1a59f2d cmdutil: narrow scope of KeyError in makefilename()
Yuya Nishihara <yuya@tcha.org>
parents: 36245
diff changeset
1188 except KeyError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1189 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1190 _(b"invalid format spec '%%%s' in output " b"filename") % c
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1191 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1192 return b''.join(newname)
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
1193
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1194
36540
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1195 def makefilename(ctx, pat, **props):
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1196 if not pat:
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1197 return pat
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1198 tmpl = _buildfntemplate(pat, **props)
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1199 # 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: 36538
diff changeset
1200 # 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: 36538
diff changeset
1201 # disable the expansion.
aa3294027936 cmdutil: expand filename format string by templater (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36538
diff changeset
1202 return rendertemplate(ctx, tmpl, pycompat.byteskwargs(props))
2874
4ec58b157265 refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff changeset
1203
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1204
32572
447bbd970047 cmdutil: extract function checking if pattern should be taken as stdin/out
Yuya Nishihara <yuya@tcha.org>
parents: 32571
diff changeset
1205 def isstdiofilename(pat):
447bbd970047 cmdutil: extract function checking if pattern should be taken as stdin/out
Yuya Nishihara <yuya@tcha.org>
parents: 32571
diff changeset
1206 """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
1207 return not pat or pat == b'-'
32572
447bbd970047 cmdutil: extract function checking if pattern should be taken as stdin/out
Yuya Nishihara <yuya@tcha.org>
parents: 32571
diff changeset
1208
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1209
27418
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
1210 class _unclosablefile(object):
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
1211 def __init__(self, fp):
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
1212 self._fp = fp
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
1213
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
1214 def close(self):
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
1215 pass
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
1216
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
1217 def __iter__(self):
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
1218 return iter(self._fp)
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
1219
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
1220 def __getattr__(self, attr):
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
1221 return getattr(self._fp, attr)
2ce4661ac226 cmdutil: reimplement file wrapper that disables close()
Yuya Nishihara <yuya@tcha.org>
parents: 27417
diff changeset
1222
30142
3dcaf1c4e90d largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents: 30018
diff changeset
1223 def __enter__(self):
3dcaf1c4e90d largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents: 30018
diff changeset
1224 return self
3dcaf1c4e90d largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents: 30018
diff changeset
1225
3dcaf1c4e90d largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents: 30018
diff changeset
1226 def __exit__(self, exc_type, exc_value, exc_tb):
3dcaf1c4e90d largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents: 30018
diff changeset
1227 pass
3dcaf1c4e90d largefiles: use context for file closing
Mads Kiilerich <madski@unity3d.com>
parents: 30018
diff changeset
1228
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1229
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1230 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
1231 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
1232
32572
447bbd970047 cmdutil: extract function checking if pattern should be taken as stdin/out
Yuya Nishihara <yuya@tcha.org>
parents: 32571
diff changeset
1233 if isstdiofilename(pat):
36243
976e1cfb2f64 cmdutil: pass ctx to makefileobj() in place of repo/node pair (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36242
diff changeset
1234 repo = ctx.repo()
24306
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
1235 if writable:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
1236 fp = repo.ui.fout
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
1237 else:
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
1238 fp = repo.ui.fin
27419
7e2495bf0ad8 cmdutil: do not duplicate stdout by makefileobj()
Yuya Nishihara <yuya@tcha.org>
parents: 27418
diff changeset
1239 return _unclosablefile(fp)
36538
d7a23d6184a2 cmdutil: reorder optional arguments passed to makefileobj()
Yuya Nishihara <yuya@tcha.org>
parents: 36537
diff changeset
1240 fn = makefilename(ctx, pat, **props)
18613
1a2f4c633410 export: clobber files with -o (bc) (issue3652)
Augie Fackler <raf@durin42.com>
parents: 18538
diff changeset
1241 return open(fn, mode)
2882
cf98cd70d2c4 move walk and matchpats from commands to cmdutil.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2874
diff changeset
1242
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1243
39305
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1244 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
1245 """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
1246 cl = opts[b'changelog']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1247 mf = opts[b'manifest']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1248 dir = opts[b'dir']
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1249 msg = None
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1250 if cl and mf:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1251 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
1252 elif cl and dir:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1253 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
1254 elif cl or mf or dir:
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1255 if file_:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1256 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
1257 elif not repo:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1258 msg = _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1259 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
1260 b'without a repository'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1261 )
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1262 if msg:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
1263 raise error.Abort(msg)
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1264
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1265 r = None
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1266 if repo:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1267 if cl:
21033
254f55b64e31 debugrevlog: use unfiltered view for changelog
Matt Mackall <mpm@selenic.com>
parents: 21024
diff changeset
1268 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
1269 elif dir:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1270 if b'treemanifest' not in repo.requirements:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1271 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1272 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1273 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
1274 b"treemanifest enabled"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1275 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1276 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1277 if not dir.endswith(b'/'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1278 dir = dir + b'/'
39272
73cf21b2e8a6 manifest: add getstorage() to manifestlog and use it globally
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39127
diff changeset
1279 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
1280 if len(dirlog):
49c583ca48c4 treemanifest: add --dir option to debug{revlog,data,index}
Martin von Zweigbergk <martinvonz@google.com>
parents: 25100
diff changeset
1281 r = dirlog
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1282 elif mf:
39272
73cf21b2e8a6 manifest: add getstorage() to manifestlog and use it globally
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39127
diff changeset
1283 r = repo.manifestlog.getstorage(b'')
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1284 elif file_:
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1285 filelog = repo.file(file_)
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1286 if len(filelog):
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1287 r = filelog
39305
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1288
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1289 # 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: 39272
diff changeset
1290 # revlog instance.
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1291 if returnrevlog:
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1292 if isinstance(r, revlog.revlog):
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1293 pass
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1294 elif util.safehasattr(r, b'_revlog'):
39305
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1295 r = r._revlog
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1296 elif r is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1297 raise error.Abort(_(b'%r does not appear to be a revlog') % r)
39305
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1298
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1299 if not r:
39305
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1300 if not returnrevlog:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1301 raise error.Abort(_(b'cannot give path to non-revlog'))
39305
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1302
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1303 if not file_:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1304 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
1305 if not os.path.isfile(file_):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1306 raise error.Abort(_(b"revlog '%s' not found") % file_)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1307 r = revlog.revlog(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1308 vfsmod.vfs(encoding.getcwd(), audit=False), file_[:-2] + b".i"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1309 )
14323
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1310 return r
a79fea6b3e77 debugindex etc.: add --changelog and --manifest options
Sune Foldager <cryo@cyanite.org>
parents: 14322
diff changeset
1311
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1312
39305
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1313 def openrevlog(repo, cmd, file_, opts):
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1314 """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: 39272
diff changeset
1315
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1316 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: 39272
diff changeset
1317
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1318 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: 39272
diff changeset
1319 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: 39272
diff changeset
1320 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: 39272
diff changeset
1321 commands.
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1322 """
53e532007878 cmdutil: return a revlog from openrevlog() and split function
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39272
diff changeset
1323 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: 39272
diff changeset
1324
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1325
5610
2493a478f395 copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents: 5609
diff changeset
1326 def copy(ui, repo, pats, opts, rename=False):
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1327 # called with the repo lock held
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1328 #
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1329 # hgsep => pathname that uses "/" to separate directories
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1330 # 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
1331 cwd = repo.getcwd()
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1332 targets = {}
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1333 after = opts.get(b"after")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1334 dryrun = opts.get(b"dry_run")
11303
a1aad8333864 move working dir/dirstate methods from localrepo to workingctx
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 11290
diff changeset
1335 wctx = repo[None]
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1336
41668
e41449818bee copy: respect ui.relative-paths in copy/rename
Martin von Zweigbergk <martinvonz@google.com>
parents: 41664
diff changeset
1337 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1338
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
1339 def walkpat(pat):
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
1340 srcs = []
24306
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
1341 if after:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1342 badstates = b'?'
24306
6ddc86eedc3b style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 24301
diff changeset
1343 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1344 badstates = b'?r'
32421
c87db79b9507 cleanup: reuse existing wctx variables instead of calling repo[None]
Martin von Zweigbergk <martinvonz@google.com>
parents: 32414
diff changeset
1345 m = scmutil.match(wctx, [pat], opts, globbed=True)
c87db79b9507 cleanup: reuse existing wctx variables instead of calling repo[None]
Martin von Zweigbergk <martinvonz@google.com>
parents: 32414
diff changeset
1346 for abs in wctx.walk(m):
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
1347 state = repo.dirstate[abs]
41668
e41449818bee copy: respect ui.relative-paths in copy/rename
Martin von Zweigbergk <martinvonz@google.com>
parents: 41664
diff changeset
1348 rel = uipathfn(abs)
6584
29c77e5dfb3c walk: remove rel and exact returns
Matt Mackall <mpm@selenic.com>
parents: 6582
diff changeset
1349 exact = m.exact(abs)
11223
0d09f2244805 rename: make --after work if source is already in R state
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 11177
diff changeset
1350 if state in badstates:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1351 if exact and state == b'?':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1352 ui.warn(_(b'%s: not copying - file is not managed\n') % rel)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1353 if exact and state == b'r':
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1354 ui.warn(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1355 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1356 b'%s: not copying - file has been marked for'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1357 b' remove\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1358 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1359 % rel
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1360 )
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
1361 continue
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
1362 # abs: hgsep
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
1363 # rel: ossep
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
1364 srcs.append((abs, rel, exact))
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
1365 return srcs
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1366
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1367 # abssrc: hgsep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1368 # relsrc: ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1369 # otarget: ossep
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
1370 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
1371 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
1372 if b'/' in abstarget:
16542
e596a631210e dirstate: preserve path components case on renames (issue3402)
Patrick Mezard <patrick@mezard.eu>
parents: 16458
diff changeset
1373 # 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
1374 # 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
1375 abspath, absname = abstarget.rsplit(b'/', 1)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1376 abstarget = repo.dirstate.normalize(abspath) + b'/' + absname
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1377 reltarget = repo.pathto(abstarget, cwd)
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
1378 target = repo.wjoin(abstarget)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1379 src = repo.wjoin(abssrc)
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
1380 state = repo.dirstate[abstarget]
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
1381
13962
8b252e826c68 add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents: 13945
diff changeset
1382 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
1383
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
1384 # check for collisions
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
1385 prevsrc = targets.get(abstarget)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1386 if prevsrc is not None:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1387 ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1388 _(b'%s: not overwriting - %s collides with %s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1389 % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1390 reltarget,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1391 repo.pathto(abssrc, cwd),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1392 repo.pathto(prevsrc, cwd),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1393 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1394 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1395 return True # report a failure
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
1396
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
1397 # check for overwrites
12342
70236d6fd844 rename: do not overwrite existing broken symlinks
Patrick Mezard <pmezard@gmail.com>
parents: 11950
diff changeset
1398 exists = os.path.lexists(target)
16283
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
1399 samefile = False
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
1400 if exists and abssrc != abstarget:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1401 if repo.dirstate.normalize(abssrc) == repo.dirstate.normalize(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1402 abstarget
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1403 ):
16283
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
1404 if not rename:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1405 ui.warn(_(b"%s: can't copy - same file\n") % reltarget)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1406 return True # report a failure
16283
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
1407 exists = False
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
1408 samefile = True
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
1409
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1410 if not after and exists or after and state in b'mn':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1411 if not opts[b'force']:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1412 if state in b'mn':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1413 msg = _(b'%s: not overwriting - file already committed\n')
30151
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
1414 if after:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1415 flags = b'--after --force'
30151
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
1416 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1417 flags = b'--force'
30151
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
1418 if rename:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1419 hint = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1420 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1421 b"('hg rename %s' to replace the file by "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1422 b'recording a rename)\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1423 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1424 % flags
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1425 )
30151
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
1426 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1427 hint = (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1428 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1429 b"('hg copy %s' to replace the file by "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1430 b'recording a copy)\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1431 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1432 % flags
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1433 )
30151
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
1434 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1435 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
1436 if rename:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1437 hint = _(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1438 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
1439 )
30151
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
1440 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1441 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
1442 ui.warn(msg % reltarget)
381293e1135e copy: distinguish "file exists" cases and add a hint (BC)
Augie Fackler <augie@google.com>
parents: 30142
diff changeset
1443 ui.warn(hint)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1444 return True # report a failure
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
1445
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
1446 if after:
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
1447 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
1448 if rename:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1449 ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1450 _(b'%s: not recording move - %s does not exist\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1451 % (relsrc, reltarget)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1452 )
11152
e8d10d085f47 cmdutil: Warn when trying to copy/rename --after to a nonexistant file.
Steve Losh <steve@stevelosh.com>
parents: 11061
diff changeset
1453 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1454 ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1455 _(b'%s: not recording copy - %s does not exist\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1456 % (relsrc, reltarget)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1457 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1458 return True # report a failure
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
1459 elif not dryrun:
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1460 try:
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
1461 if exists:
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
1462 os.unlink(target)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1463 targetdir = os.path.dirname(target) or b'.'
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
1464 if not os.path.isdir(targetdir):
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
1465 os.makedirs(targetdir)
16283
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
1466 if samefile:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1467 tmp = target + b"~hgrename"
16283
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
1468 os.rename(src, tmp)
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
1469 os.rename(tmp, target)
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
1470 else:
37091
08890706366e copyfile: preserve stat info (mtime, etc.) when doing copies/renames
Kyle Lippincott <spectral@google.com>
parents: 37087
diff changeset
1471 # 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: 37087
diff changeset
1472 # Linux CLI behavior.
08890706366e copyfile: preserve stat info (mtime, etc.) when doing copies/renames
Kyle Lippincott <spectral@google.com>
parents: 37087
diff changeset
1473 util.copyfile(src, target, copystat=rename)
14518
a67e866f46f9 workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents: 14442
diff changeset
1474 srcexists = True
25660
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25657
diff changeset
1475 except IOError as inst:
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1476 if inst.errno == errno.ENOENT:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1477 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
1478 srcexists = False
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1479 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1480 ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1481 _(b'%s: cannot copy - %s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1482 % (relsrc, encoding.strtolocal(inst.strerror))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1483 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1484 return True # report a failure
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
1485
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1486 if ui.verbose or not exact:
7894
caef5fdf1375 cmdutil: fix untranslatable string in copy
Martin Geisler <mg@daimi.au.dk>
parents: 7879
diff changeset
1487 if rename:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1488 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
1489 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1490 ui.status(_(b'copying %s to %s\n') % (relsrc, reltarget))
5608
784eadabd985 copy: simplify inner copy
Matt Mackall <mpm@selenic.com>
parents: 5607
diff changeset
1491
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1492 targets[abstarget] = abssrc
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
1493
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
1494 # fix up dirstate
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1495 scmutil.dirstatecopy(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1496 ui, repo, wctx, abssrc, abstarget, dryrun=dryrun, cwd=cwd
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1497 )
5610
2493a478f395 copy: handle rename internally
Matt Mackall <mpm@selenic.com>
parents: 5609
diff changeset
1498 if rename and not dryrun:
16283
6c4dbe28dda3 rename: handle case-changing (issue1717)
Matt Mackall <mpm@selenic.com>
parents: 16165
diff changeset
1499 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
1500 rmdir = repo.ui.configbool(b'experimental', b'removeemptydirs')
38497
da2a7d8354b2 unlinkpath: make empty directory removal optional (issue5901) (issue5826)
Kyle Lippincott <spectral@google.com>
parents: 38465
diff changeset
1501 repo.wvfs.unlinkpath(abssrc, rmdir=rmdir)
14518
a67e866f46f9 workingctx: eliminate remove function
Adrian Buehlmann <adrian@cadifra.com>
parents: 14442
diff changeset
1502 wctx.forget([abssrc])
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1503
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1504 # pat: ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1505 # dest ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1506 # srcs: list of (hgsep, hgsep, ossep, bool)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1507 # return: function that takes hgsep and returns ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1508 def targetpathfn(pat, dest, srcs):
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1509 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
1510 abspfx = pathutil.canonpath(repo.root, cwd, pat)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1511 abspfx = util.localpath(abspfx)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1512 if destdirexists:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1513 striplen = len(os.path.split(abspfx)[0])
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1514 else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1515 striplen = len(abspfx)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1516 if striplen:
30620
bb77654dc7ae py3: replace os.sep with pycompat.ossep (part 3 of 4)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30543
diff changeset
1517 striplen += len(pycompat.ossep)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1518 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
1519 elif destdirexists:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1520 res = lambda p: os.path.join(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1521 dest, os.path.basename(util.localpath(p))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1522 )
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1523 else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1524 res = lambda p: dest
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1525 return res
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1526
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1527 # pat: ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1528 # dest ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1529 # srcs: list of (hgsep, hgsep, ossep, bool)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1530 # return: function that takes hgsep and returns ossep
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1531 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
1532 if matchmod.patkind(pat):
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1533 # a mercurial pattern
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1534 res = lambda p: os.path.join(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1535 dest, os.path.basename(util.localpath(p))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1536 )
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1537 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
1538 abspfx = pathutil.canonpath(repo.root, cwd, pat)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1539 if len(abspfx) < len(srcs[0][0]):
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1540 # 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
1541 # 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
1542 def evalpath(striplen):
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1543 score = 0
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1544 for s in srcs:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1545 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
1546 if os.path.lexists(t):
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1547 score += 1
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1548 return score
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1549
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1550 abspfx = util.localpath(abspfx)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1551 striplen = len(abspfx)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1552 if striplen:
30620
bb77654dc7ae py3: replace os.sep with pycompat.ossep (part 3 of 4)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30543
diff changeset
1553 striplen += len(pycompat.ossep)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1554 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
1555 score = evalpath(striplen)
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1556 striplen1 = len(os.path.split(abspfx)[0])
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1557 if striplen1:
30620
bb77654dc7ae py3: replace os.sep with pycompat.ossep (part 3 of 4)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30543
diff changeset
1558 striplen1 += len(pycompat.ossep)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1559 if evalpath(striplen1) > score:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1560 striplen = striplen1
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1561 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
1562 else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1563 # a file
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1564 if destdirexists:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1565 res = lambda p: os.path.join(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1566 dest, os.path.basename(util.localpath(p))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1567 )
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1568 else:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1569 res = lambda p: dest
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1570 return res
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1571
14321
003d63bb4fa5 scmutil: drop some aliases in cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14320
diff changeset
1572 pats = scmutil.expandpats(pats)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1573 if not pats:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1574 raise error.Abort(_(b'no source or destination specified'))
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1575 if len(pats) == 1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1576 raise error.Abort(_(b'no destination specified'))
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1577 dest = pats.pop()
6258
c24f4b3f156b Fix issue995 (copy --after and symlinks pointing to a directory)
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 6211
diff changeset
1578 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
1579 if not destdirexists:
12085
6f833fc3ccab Consistently import foo as foomod when foo to avoid shadowing
Martin Geisler <mg@aragost.com>
parents: 12032
diff changeset
1580 if len(pats) > 1 or matchmod.patkind(pats[0]):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1581 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1582 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1583 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
1584 b'existing directory'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1585 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1586 )
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
1587 if util.endswithsep(dest):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1588 raise error.Abort(_(b'destination %s is not a directory') % dest)
5607
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
1589
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
1590 tfn = targetpathfn
e9bae5c80ab4 copy: minor cleanups
Matt Mackall <mpm@selenic.com>
parents: 5606
diff changeset
1591 if after:
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1592 tfn = targetpathafterfn
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1593 copylist = []
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1594 for pat in pats:
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
1595 srcs = walkpat(pat)
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1596 if not srcs:
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1597 continue
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1598 copylist.append((tfn(pat, dest, srcs), srcs))
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1599 if not copylist:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1600 raise error.Abort(_(b'no files to copy'))
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1601
5606
447ea621e50e copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents: 5605
diff changeset
1602 errors = 0
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1603 for targetpath, srcs in copylist:
5605
e7a9ad999308 copy: refactor okaytocopy into walkpat
Matt Mackall <mpm@selenic.com>
parents: 5604
diff changeset
1604 for abssrc, relsrc, exact in srcs:
5606
447ea621e50e copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents: 5605
diff changeset
1605 if copyfile(abssrc, relsrc, targetpath(abssrc), exact):
447ea621e50e copy: propagate errors properly
Matt Mackall <mpm@selenic.com>
parents: 5605
diff changeset
1606 errors += 1
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1607
11177
6a64813276ed commands: initial audit of exit codes
Matt Mackall <mpm@selenic.com>
parents: 11152
diff changeset
1608 return errors != 0
5589
9981b6b19ecf move commands.docopy to cmdutil.copy
Matt Mackall <mpm@selenic.com>
parents: 5550
diff changeset
1609
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1610
26561
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
1611 ## 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
1612 # 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
1613 extrapreimport = [] # run before commit
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1614 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
1615 # 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
1616 #
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
1617 # '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
1618 # arguments:
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
1619 # - 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
1620 # - 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
1621 # - 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
1622 # - 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
1623 # 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
1624 # 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
1625 # there.
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
1626 extrapreimportmap = {}
26562
dd2f5e014806 import: allow processing of extra part header after import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26561
diff changeset
1627 # '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
1628 # argument:
dd2f5e014806 import: allow processing of extra part header after import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26561
diff changeset
1629 # - 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
1630 extrapostimportmap = {}
26561
1f14920a892c import: allow processing of extra part header during import
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26547
diff changeset
1631
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1632
37620
fd1dd79cff20 cmdutil: pass in parsed patch to tryimportone() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37604
diff changeset
1633 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
1634 """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
1635
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
1636 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
1637 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
1638
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
1639 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
1640 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
1641
37620
fd1dd79cff20 cmdutil: pass in parsed patch to tryimportone() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37604
diff changeset
1642 :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
1643 ``patch.extract()``)
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
1644 :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
1645 :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
1646 :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
1647 (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
1648 :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
1649 updatefunc(<repo>, <node>)
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
1650 """
25930
221491bbaf7e cmdutil: break import cycle
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25795
diff changeset
1651 # avoid cycle context -> subrepo -> cmdutil
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
1652 from . import context
37620
fd1dd79cff20 cmdutil: pass in parsed patch to tryimportone() (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37604
diff changeset
1653
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1654 tmpname = patchdata.get(b'filename')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1655 message = patchdata.get(b'message')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1656 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
1657 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
1658 branch = patchdata.get(b'branch')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1659 nodeid = patchdata.get(b'nodeid')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1660 p1 = patchdata.get(b'p1')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1661 p2 = patchdata.get(b'p2')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1662
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1663 nocommit = opts.get(b'no_commit')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1664 importbranch = opts.get(b'import_branch')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1665 update = not opts.get(b'bypass')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1666 strip = opts[b"strip"]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1667 prefix = opts[b"prefix"]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1668 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
1669
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
1670 if not tmpname:
37621
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1671 return None, None, False
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
1672
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
1673 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
1674
37621
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1675 cmdline_message = logmessage(ui, opts)
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1676 if cmdline_message:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1677 # pickup the cmdline msg
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1678 message = cmdline_message
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1679 elif message:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1680 # pickup the patch msg
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1681 message = message.strip()
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1682 else:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1683 # launch the editor
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1684 message = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1685 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
1686
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1687 if len(parents) == 1:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1688 parents.append(repo[nullid])
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1689 if opts.get(b'exact'):
37621
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1690 if not nodeid or not p1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1691 raise error.Abort(_(b'not a Mercurial patch'))
37621
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1692 p1 = repo[p1]
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1693 p2 = repo[p2 or nullid]
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1694 elif p2:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1695 try:
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
1696 p1 = repo[p1]
37621
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1697 p2 = repo[p2]
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1698 # 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
1699 # 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
1700 # first parent.
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1701 if p1 != parents[0]:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1702 p1 = parents[0]
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1703 p2 = repo[nullid]
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1704 except error.RepoError:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1705 p1, p2 = parents
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1706 if p2.node() == nullid:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1707 ui.warn(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1708 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1709 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
1710 b"(use --exact to import the patch as a merge)\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1711 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1712 )
37621
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1713 else:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1714 p1, p2 = parents
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1715
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1716 n = None
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1717 if update:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1718 if p1 != parents[0]:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1719 updatefunc(repo, p1.node())
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1720 if p2 != parents[1]:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1721 repo.setparents(p1.node(), p2.node())
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1722
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1723 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
1724 repo.dirstate.setbranch(branch or b'default')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1725
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1726 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
1727 files = set()
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1728 try:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1729 patch.patch(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1730 ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1731 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1732 tmpname,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1733 strip=strip,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1734 prefix=prefix,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1735 files=files,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1736 eolmode=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1737 similarity=sim / 100.0,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1738 )
37621
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1739 except error.PatchError as e:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1740 if not partial:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1741 raise error.Abort(pycompat.bytestr(e))
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1742 if partial:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1743 rejects = True
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1744
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1745 files = list(files)
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1746 if nocommit:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1747 if message:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1748 msgs.append(message)
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
1749 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1750 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
1751 # 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
1752 # 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
1753 # being updated to its first parent.
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1754 m = None
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1755 else:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1756 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
1757 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
1758 if opts.get(b'exact'):
37621
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1759 editor = None
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1760 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1761 editor = getcommiteditor(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1762 editform=editform, **pycompat.strkwargs(opts)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1763 )
37621
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1764 extra = {}
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1765 for idfunc in extrapreimport:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1766 extrapreimportmap[idfunc](repo, patchdata, extra, opts)
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1767 overrides = {}
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1768 if partial:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1769 overrides[(b'ui', b'allowemptycommit')] = True
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1770 with repo.ui.configoverride(overrides, b'import'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1771 n = repo.commit(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1772 message, user, date, match=m, editor=editor, extra=extra
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1773 )
37621
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1774 for idfunc in extrapostimport:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1775 extrapostimportmap[idfunc](repo[n])
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1776 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1777 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
1778 branch = branch or b'default'
37621
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1779 else:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1780 branch = p1.branch()
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1781 store = patch.filestore()
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1782 try:
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
1783 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
1784 try:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1785 patch.patchrepo(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1786 ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1787 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1788 p1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1789 store,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1790 tmpname,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1791 strip,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1792 prefix,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1793 files,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1794 eolmode=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1795 )
34258
61714510220d error: move patch.PatchError so it can easily implement __bytes__ (API)
Yuya Nishihara <yuya@tcha.org>
parents: 34201
diff changeset
1796 except error.PatchError as e:
37621
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1797 raise error.Abort(stringutil.forcebytestr(e))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1798 if opts.get(b'exact'):
37621
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1799 editor = None
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
1800 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1801 editor = getcommiteditor(editform=b'import.bypass')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1802 memctx = context.memctx(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1803 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1804 (p1.node(), p2.node()),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1805 message,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1806 files=files,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1807 filectxfn=store,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1808 user=user,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1809 date=date,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1810 branch=branch,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1811 editor=editor,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1812 )
37621
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1813 n = memctx.commit()
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1814 finally:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1815 store.close()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1816 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
1817 # --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
1818 # and branch bits
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1819 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
1820 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
1821 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
1822 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
1823 if n:
5537d8f5e989 patch: make extract() a context manager (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37620
diff changeset
1824 # 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
1825 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
1826 return msg, n, rejects
20500
ce3f3082ec45 import: move tryone closure in cmdutil
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 20470
diff changeset
1827
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1828
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
1829 # 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
1830 # 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
1831 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
1832 # 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
1833 # 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
1834 # 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
1835 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
1836
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1837
37602
52670eaa14b4 export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents: 37601
diff changeset
1838 def _exportsingle(repo, ctx, fm, match, switch_parent, seqno, diffopts):
32682
9d201b39ccd9 export: map wctx.node() to 'ff...' node id (issue5438)
Yuya Nishihara <yuya@tcha.org>
parents: 32678
diff changeset
1839 node = scmutil.binnode(ctx)
32471
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32470
diff changeset
1840 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: 32470
diff changeset
1841 branch = ctx.branch()
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32470
diff changeset
1842 if switch_parent:
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32470
diff changeset
1843 parents.reverse()
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32470
diff changeset
1844
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32470
diff changeset
1845 if parents:
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32470
diff changeset
1846 prev = parents[0]
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32470
diff changeset
1847 else:
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32470
diff changeset
1848 prev = nullid
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32470
diff changeset
1849
37602
52670eaa14b4 export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents: 37601
diff changeset
1850 fm.context(ctx=ctx)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1851 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
1852 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
1853 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
1854 fm.write(b'date', b'# %s\n', fm.formatdate(ctx.date()))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1855 fm.condwrite(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1856 branch and branch != b'default', b'branch', b'# Branch %s\n', branch
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1857 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1858 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
1859 fm.plain(b'# Parent %s\n' % hex(prev))
32471
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32470
diff changeset
1860 if len(parents) > 1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1861 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
1862 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
1863
52670eaa14b4 export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents: 37601
diff changeset
1864 # TODO: redesign extraexportmap function to support formatter
32471
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32470
diff changeset
1865 for headerid in extraexport:
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32470
diff changeset
1866 header = extraexportmap[headerid](seqno, ctx)
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32470
diff changeset
1867 if header is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1868 fm.plain(b'# %s\n' % header)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1869
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1870 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
1871 fm.plain(b'\n')
37602
52670eaa14b4 export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents: 37601
diff changeset
1872
52670eaa14b4 export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents: 37601
diff changeset
1873 if fm.isplain():
52670eaa14b4 export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents: 37601
diff changeset
1874 chunkiter = patch.diffui(repo, prev, node, match, opts=diffopts)
52670eaa14b4 export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents: 37601
diff changeset
1875 for chunk, label in chunkiter:
52670eaa14b4 export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents: 37601
diff changeset
1876 fm.plain(chunk, label=label)
52670eaa14b4 export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents: 37601
diff changeset
1877 else:
52670eaa14b4 export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents: 37601
diff changeset
1878 chunkiter = patch.diff(repo, prev, node, match, opts=diffopts)
52670eaa14b4 export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents: 37601
diff changeset
1879 # TODO: make it structured?
52670eaa14b4 export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents: 37601
diff changeset
1880 fm.data(diff=b''.join(chunkiter))
32471
7feaf5550a9e cmdutil: extract closure that performs the actual export formatting
Augie Fackler <augie@google.com>
parents: 32470
diff changeset
1881
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1882
37604
daafaff4e5be export: enable formatter support (API)
Yuya Nishihara <yuya@tcha.org>
parents: 37603
diff changeset
1883 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
1884 """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
1885 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
1886 ctx = repo[rev]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1887 if not dest.startswith(b'<'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1888 repo.ui.note(b"%s\n" % dest)
37602
52670eaa14b4 export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents: 37601
diff changeset
1889 fm.startitem()
52670eaa14b4 export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents: 37601
diff changeset
1890 _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
1891
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1892
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1893 def _exportfntemplate(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1894 repo, revs, basefm, fntemplate, switch_parent, diffopts, match
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1895 ):
37600
7800ed2e4980 export: split cmdutil.export() to single-file and maybe-multiple-files cases
Yuya Nishihara <yuya@tcha.org>
parents: 37599
diff changeset
1896 """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
1897 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
1898 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
1899 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
1900
7800ed2e4980 export: split cmdutil.export() to single-file and maybe-multiple-files cases
Yuya Nishihara <yuya@tcha.org>
parents: 37599
diff changeset
1901 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
1902 ctx = repo[rev]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1903 dest = makefilename(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1904 ctx, fntemplate, total=total, seqno=seqno, revwidth=revwidth
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1905 )
37601
2e0e61312a25 export: serialize revisions to be exported per destination file
Yuya Nishihara <yuya@tcha.org>
parents: 37600
diff changeset
1906 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
1907
2e0e61312a25 export: serialize revisions to be exported per destination file
Yuya Nishihara <yuya@tcha.org>
parents: 37600
diff changeset
1908 for dest in filemap:
37604
daafaff4e5be export: enable formatter support (API)
Yuya Nishihara <yuya@tcha.org>
parents: 37603
diff changeset
1909 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
1910 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
1911 for seqno, rev in filemap[dest]:
37602
52670eaa14b4 export: port _exportsingle() to formatter
Yuya Nishihara <yuya@tcha.org>
parents: 37601
diff changeset
1912 fm.startitem()
37601
2e0e61312a25 export: serialize revisions to be exported per destination file
Yuya Nishihara <yuya@tcha.org>
parents: 37600
diff changeset
1913 ctx = repo[rev]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1914 _exportsingle(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1915 repo, ctx, fm, match, switch_parent, seqno, diffopts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1916 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1917
37600
7800ed2e4980 export: split cmdutil.export() to single-file and maybe-multiple-files cases
Yuya Nishihara <yuya@tcha.org>
parents: 37599
diff changeset
1918
42489
307f67d4aee3 export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 42418
diff changeset
1919 def _prefetchchangedfiles(repo, revs, match):
307f67d4aee3 export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 42418
diff changeset
1920 allfiles = set()
307f67d4aee3 export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 42418
diff changeset
1921 for rev in revs:
307f67d4aee3 export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 42418
diff changeset
1922 for file in repo[rev].files():
307f67d4aee3 export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 42418
diff changeset
1923 if not match or match(file):
307f67d4aee3 export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 42418
diff changeset
1924 allfiles.add(file)
307f67d4aee3 export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 42418
diff changeset
1925 scmutil.prefetchfiles(repo, revs, scmutil.matchfiles(repo, allfiles))
307f67d4aee3 export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 42418
diff changeset
1926
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1927
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1928 def export(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1929 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1930 revs,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1931 basefm,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1932 fntemplate=b'hg-%h.patch',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1933 switch_parent=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1934 opts=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1935 match=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1936 ):
32468
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32421
diff changeset
1937 '''export changesets as hg patches
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32421
diff changeset
1938
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32421
diff changeset
1939 Args:
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32421
diff changeset
1940 repo: The repository from which we're exporting revisions.
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32421
diff changeset
1941 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
1942 basefm: A formatter to which patches should be written.
32469
9fd9f91b0c43 cmdutil: rename template param to export to fntemplate
Augie Fackler <augie@google.com>
parents: 32468
diff changeset
1943 fntemplate: An optional string to use for generating patch file names.
32468
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32421
diff changeset
1944 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: 32421
diff changeset
1945 Default is false, which always shows diff against p1.
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32421
diff changeset
1946 opts: diff options to use for generating the patch.
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32421
diff changeset
1947 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: 32421
diff changeset
1948
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32421
diff changeset
1949 Returns:
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32421
diff changeset
1950 Nothing.
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32421
diff changeset
1951
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32421
diff changeset
1952 Side Effect:
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32421
diff changeset
1953 "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: 32421
diff changeset
1954 destinations:
32469
9fd9f91b0c43 cmdutil: rename template param to export to fntemplate
Augie Fackler <augie@google.com>
parents: 32468
diff changeset
1955 fntemplate specified: Each rev is written to a unique file named using
32468
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32421
diff changeset
1956 the given template.
37604
daafaff4e5be export: enable formatter support (API)
Yuya Nishihara <yuya@tcha.org>
parents: 37603
diff changeset
1957 Otherwise: All revs will be written to basefm.
32468
1f4be037f558 cmdutil: comprehensively document the interface of export
Augie Fackler <augie@google.com>
parents: 32421
diff changeset
1958 '''
42489
307f67d4aee3 export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 42418
diff changeset
1959 _prefetchchangedfiles(repo, revs, match)
37763
b54404d66f7e export: invoke the file prefetch hook
Matt Harbison <matt_harbison@yahoo.com>
parents: 37762
diff changeset
1960
37603
678d760c71ff export: extract function to write patch to file object (API)
Yuya Nishihara <yuya@tcha.org>
parents: 37602
diff changeset
1961 if not fntemplate:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1962 _exportfile(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1963 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
1964 )
37600
7800ed2e4980 export: split cmdutil.export() to single-file and maybe-multiple-files cases
Yuya Nishihara <yuya@tcha.org>
parents: 37599
diff changeset
1965 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1966 _exportfntemplate(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1967 repo, revs, basefm, fntemplate, switch_parent, opts, match
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1968 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1969
10611
e764f24a45ee patch/diff: move patch.export() to cmdutil.export()
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10608
diff changeset
1970
37603
678d760c71ff export: extract function to write patch to file object (API)
Yuya Nishihara <yuya@tcha.org>
parents: 37602
diff changeset
1971 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
1972 """Export changesets to the given file stream"""
42489
307f67d4aee3 export: don't prefetch *all* files in manifest
Martin von Zweigbergk <martinvonz@google.com>
parents: 42418
diff changeset
1973 _prefetchchangedfiles(repo, revs, match)
37763
b54404d66f7e export: invoke the file prefetch hook
Matt Harbison <matt_harbison@yahoo.com>
parents: 37762
diff changeset
1974
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1975 dest = getattr(fp, 'name', b'<unnamed>')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1976 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
1977 _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
1978
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1979
29806
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29770
diff changeset
1980 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
1981 """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
1982
78f4c2b7052f debugobsolete: extract marker display in a dedicated function
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 20392
diff changeset
1983 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
1984 if index is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1985 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
1986 fm.write(b'prednode', b'%s ', hex(marker.prednode()))
29806
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29770
diff changeset
1987 succs = marker.succnodes()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1988 fm.condwrite(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1989 succs,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1990 b'succnodes',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1991 b'%s ',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1992 fm.formatlist(map(hex, succs), name=b'node'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1993 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1994 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
1995 parents = marker.parentnodes()
2229d757802d debugobsolete: display parents information from markers
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22250
diff changeset
1996 if parents is not None:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
1997 fm.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1998 b'parentnodes',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1999 b'{%s} ',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2000 fm.formatlist(map(hex, parents), name=b'node', sep=b', '),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2001 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2002 fm.write(b'date', b'(%s) ', fm.formatdate(marker.date()))
29806
142ae01820a3 debugobsolete: add formatter support (issue5134)
Yuya Nishihara <yuya@tcha.org>
parents: 29770
diff changeset
2003 meta = marker.metadata().copy()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2004 meta.pop(b'date', None)
38576
152f4822d210 pycompat: move rapply() from util
Yuya Nishihara <yuya@tcha.org>
parents: 38543
diff changeset
2005 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
2006 fm.write(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2007 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
2008 )
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2009 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
2010
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2011
3814
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
2012 def finddate(ui, repo, date):
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
2013 """Find the tipmost changeset that matches the given date spec"""
9667
8743f2e1bc54 merge changes from mpm
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9666 9665
diff changeset
2014
36636
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36540
diff changeset
2015 df = dateutil.matchdate(date)
14322
a90131b85fd8 scmutil: drop aliases in cmdutil for match functions
Matt Mackall <mpm@selenic.com>
parents: 14321
diff changeset
2016 m = scmutil.matchall(repo)
3814
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
2017 results = {}
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
2018
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
2019 def prep(ctx, fns):
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
2020 d = ctx.date()
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
2021 if df(d[0]):
9668
2c24471d478c cmdutil: fix bug in finddate() implementation
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9667
diff changeset
2022 results[ctx.rev()] = d
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
2023
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2024 for ctx in walkchangerevs(repo, m, {b'rev': None}, prep):
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
2025 rev = ctx.rev()
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
2026 if rev in results:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2027 ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2028 _(b"found revision %s from %s\n")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2029 % (rev, dateutil.datestr(results[rev]))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2030 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2031 return b'%d' % rev
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2032
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2033 raise error.Abort(_(b"revision matching date not found"))
3814
120be84f33de Add --date support to update and revert
Matt Mackall <mpm@selenic.com>
parents: 3738
diff changeset
2034
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2035
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2036 def increasingwindows(windowsize=8, sizelimit=512):
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2037 while True:
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2038 yield windowsize
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2039 if windowsize < sizelimit:
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2040 windowsize *= 2
16776
5088d0b9a9a1 cmdutil: extract increasing_windows() from walkchangerevs()
Patrick Mezard <patrick@mezard.eu>
parents: 16701
diff changeset
2041
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2042
35682
8273c1a47282 log: duplicate _logrevs() dedicated for walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35662
diff changeset
2043 def _walkrevs(repo, opts):
8273c1a47282 log: duplicate _logrevs() dedicated for walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35662
diff changeset
2044 # Default --rev value depends on --follow but --follow behavior
8273c1a47282 log: duplicate _logrevs() dedicated for walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35662
diff changeset
2045 # depends on revisions resolved from --rev...
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2046 follow = opts.get(b'follow') or opts.get(b'follow_first')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2047 if opts.get(b'rev'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2048 revs = scmutil.revrange(repo, opts[b'rev'])
35682
8273c1a47282 log: duplicate _logrevs() dedicated for walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35662
diff changeset
2049 elif follow and repo.dirstate.p1() == nullid:
8273c1a47282 log: duplicate _logrevs() dedicated for walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35662
diff changeset
2050 revs = smartset.baseset()
8273c1a47282 log: duplicate _logrevs() dedicated for walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35662
diff changeset
2051 elif follow:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2052 revs = repo.revs(b'reverse(:.)')
35682
8273c1a47282 log: duplicate _logrevs() dedicated for walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35662
diff changeset
2053 else:
8273c1a47282 log: duplicate _logrevs() dedicated for walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35662
diff changeset
2054 revs = smartset.spanset(repo)
8273c1a47282 log: duplicate _logrevs() dedicated for walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35662
diff changeset
2055 revs.reverse()
8273c1a47282 log: duplicate _logrevs() dedicated for walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35662
diff changeset
2056 return revs
8273c1a47282 log: duplicate _logrevs() dedicated for walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35662
diff changeset
2057
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2058
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2059 class FileWalkError(Exception):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2060 pass
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2061
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2062
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2063 def walkfilerevs(repo, match, follow, revs, fncache):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2064 '''Walks the file history for the matched files.
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2065
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2066 Returns the changeset revs that are involved in the file history.
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2067
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2068 Throws FileWalkError if the file history can't be walked using
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2069 filelogs alone.
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2070 '''
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2071 wanted = set()
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2072 copies = []
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2073 minrev, maxrev = min(revs), max(revs)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2074
41843
dcbb1b4dc93a walkfilerevs: rename filerevgen() to filerevs() since it's not a generator
Martin von Zweigbergk <martinvonz@google.com>
parents: 41768
diff changeset
2075 def filerevs(filelog, last):
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2076 """
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2077 Only files, no patterns. Check the history of each file.
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2078
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2079 Examines filelog entries within minrev, maxrev linkrev range
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2080 Returns an iterator yielding (linkrev, parentlinkrevs, copied)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2081 tuples in backwards order
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2082 """
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2083 cl_count = len(repo)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2084 revs = []
38823
e7aa113b14f7 global: use pycompat.xrange()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38810
diff changeset
2085 for j in pycompat.xrange(0, last + 1):
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2086 linkrev = filelog.linkrev(j)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2087 if linkrev < minrev:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2088 continue
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2089 # only yield rev for which we have the changelog, it can
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2090 # happen while doing "hg log" during a pull or commit
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2091 if linkrev >= cl_count:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2092 break
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2093
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2094 parentlinkrevs = []
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2095 for p in filelog.parentrevs(j):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2096 if p != nullrev:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2097 parentlinkrevs.append(filelog.linkrev(p))
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2098 n = filelog.node(j)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2099 revs.append(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2100 (linkrev, parentlinkrevs, follow and filelog.renamed(n))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2101 )
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2102
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2103 return reversed(revs)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2104
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2105 def iterfiles():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2106 pctx = repo[b'.']
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2107 for filename in match.files():
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2108 if follow:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2109 if filename not in pctx:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2110 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2111 _(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2112 b'cannot follow file not in parent '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2113 b'revision: "%s"'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2114 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2115 % filename
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2116 )
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2117 yield filename, pctx[filename].filenode()
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2118 else:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2119 yield filename, None
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2120 for filename_node in copies:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2121 yield filename_node
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2122
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2123 for file_, node in iterfiles():
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2124 filelog = repo.file(file_)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2125 if not len(filelog):
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2126 if node is None:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2127 # A zero count may be a directory or deleted file, so
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2128 # try to find matching entries on the slow path.
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2129 if follow:
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26579
diff changeset
2130 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2131 _(b'cannot follow nonexistent file: "%s"') % file_
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2132 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2133 raise FileWalkError(b"Cannot walk via filelog")
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2134 else:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2135 continue
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2136
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2137 if node is None:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2138 last = len(filelog) - 1
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2139 else:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2140 last = filelog.rev(node)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2141
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2142 # keep track of all ancestors of the file
32331
bd872f64a8ba cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents: 32329
diff changeset
2143 ancestors = {filelog.linkrev(last)}
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2144
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2145 # iterate from latest to oldest revision
41843
dcbb1b4dc93a walkfilerevs: rename filerevgen() to filerevs() since it's not a generator
Martin von Zweigbergk <martinvonz@google.com>
parents: 41768
diff changeset
2146 for rev, flparentlinkrevs, copied in filerevs(filelog, last):
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2147 if not follow:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2148 if rev > maxrev:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2149 continue
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2150 else:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2151 # Note that last might not be the first interesting
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2152 # rev to us:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2153 # if the file has been changed after maxrev, we'll
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2154 # have linkrev(last) > maxrev, and we still need
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2155 # to explore the file graph
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2156 if rev not in ancestors:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2157 continue
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2158 # XXX insert 1327 fix here
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2159 if flparentlinkrevs:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2160 ancestors.update(flparentlinkrevs)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2161
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2162 fncache.setdefault(rev, []).append(file_)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2163 wanted.add(rev)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2164 if copied:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2165 copies.append(copied)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2166
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2167 return wanted
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2168
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2169
24391
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2170 class _followfilter(object):
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2171 def __init__(self, repo, onlyfirst=False):
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2172 self.repo = repo
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2173 self.startrev = nullrev
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2174 self.roots = set()
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2175 self.onlyfirst = onlyfirst
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2176
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2177 def match(self, rev):
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2178 def realparents(rev):
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2179 if self.onlyfirst:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2180 return self.repo.changelog.parentrevs(rev)[0:1]
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2181 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2182 return filter(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2183 lambda x: x != nullrev, self.repo.changelog.parentrevs(rev)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2184 )
24391
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2185
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2186 if self.startrev == nullrev:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2187 self.startrev = rev
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2188 return True
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2189
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2190 if rev > self.startrev:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2191 # forward: all descendants
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2192 if not self.roots:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2193 self.roots.add(self.startrev)
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2194 for parent in realparents(rev):
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2195 if parent in self.roots:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2196 self.roots.add(rev)
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2197 return True
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2198 else:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2199 # backwards: all parents
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2200 if not self.roots:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2201 self.roots.update(realparents(self.startrev))
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2202 if rev in self.roots:
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2203 self.roots.remove(rev)
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2204 self.roots.update(realparents(rev))
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2205 return True
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2206
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2207 return False
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2208
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2209
9665
1de5ebfa5585 walkchangerevs: drop ui arg
Matt Mackall <mpm@selenic.com>
parents: 9664
diff changeset
2210 def walkchangerevs(repo, match, opts, prepare):
7807
bd8f44638847 help: miscellaneous language fixes
timeless <timeless@gmail.com>
parents: 7779
diff changeset
2211 '''Iterate over files and the revs in which they changed.
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2212
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2213 Callers most commonly need to iterate backwards over the history
7807
bd8f44638847 help: miscellaneous language fixes
timeless <timeless@gmail.com>
parents: 7779
diff changeset
2214 in which they are interested. Doing so has awful (quadratic-looking)
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2215 performance, so we use iterators in a "windowed" way.
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2216
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2217 We walk a window of revisions in the desired order. Within the
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2218 window, we first walk forwards to gather data, then in the desired
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2219 order (usually backwards) to display it.
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2220
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
2221 This function returns an iterator yielding contexts. Before
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
2222 yielding each context, the iterator will first call the prepare
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
2223 function on each context in the window in forward order.'''
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2224
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2225 allfiles = opts.get(b'all_files')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2226 follow = opts.get(b'follow') or opts.get(b'follow_first')
35682
8273c1a47282 log: duplicate _logrevs() dedicated for walkchangerevs()
Yuya Nishihara <yuya@tcha.org>
parents: 35662
diff changeset
2227 revs = _walkrevs(repo, opts)
11281
b724b8467b82 walkchangerevs: allow empty query sets
Matt Mackall <mpm@selenic.com>
parents: 11277
diff changeset
2228 if not revs:
b724b8467b82 walkchangerevs: allow empty query sets
Matt Mackall <mpm@selenic.com>
parents: 11277
diff changeset
2229 return []
8152
08e1baf924ca replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents: 8119
diff changeset
2230 wanted = set()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2231 slowpath = match.anypats() or (not match.always() and opts.get(b'removed'))
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2232 fncache = {}
37303
8823615f68a5 log: remove dependence on repo.changectx()
Martin von Zweigbergk <martinvonz@google.com>
parents: 37272
diff changeset
2233 change = repo.__getitem__
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2234
11632
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
2235 # First step is to fill wanted, the set of revisions that we want to yield.
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
2236 # When it does not induce extra cost, we also fill fncache for revisions in
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
2237 # wanted: a cache of filenames that were changed (ctx.files()) and that
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
2238 # match the file filtering conditions.
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
2239
38998
d99468d2b09a grep: search all commits in allfiles mode
Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com>
parents: 38984
diff changeset
2240 if match.always() or allfiles:
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2241 # No files, no patterns. Display all revs.
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2242 wanted = revs
25271
1b1eaf1885df walkchangerevs: simplify with an 'elif'
Martin von Zweigbergk <martinvonz@google.com>
parents: 25259
diff changeset
2243 elif not slowpath:
11632
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
2244 # We only have to read through the filelog to find wanted revisions
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
2245
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2246 try:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2247 wanted = walkfilerevs(repo, match, follow, revs, fncache)
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2248 except FileWalkError:
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2249 slowpath = True
11608
183e63112698 log: remove increasing windows usage in fastpath
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11607
diff changeset
2250
19290
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2251 # We decided to fall back to the slowpath because at least one
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2252 # of the paths was not a file. Check to see if at least one of them
f21f4a1b6c24 log: move log file walk to its own function
Durham Goode <durham@fb.com>
parents: 19211
diff changeset
2253 # existed in history, otherwise simply return
17746
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
2254 for path in match.files():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2255 if path == b'.' or path in repo.store:
17746
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
2256 break
18340
8802277c40ee log: make log work even if first parameter doesn't exist
Mads Kiilerich <mads@kiilerich.com>
parents: 18267
diff changeset
2257 else:
8802277c40ee log: make log work even if first parameter doesn't exist
Mads Kiilerich <mads@kiilerich.com>
parents: 18267
diff changeset
2258 return []
17746
6d218e47cf9b log: speed up hg log for untracked files (issue1340)
smuralid
parents: 17676
diff changeset
2259
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2260 if slowpath:
11632
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
2261 # We have to read the changelog to match filenames against
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
2262 # changed files
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
2263
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2264 if follow:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2265 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2266 _(b'can only follow copies/renames for explicit ' b'filenames')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2267 )
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2268
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2269 # The slow path checks files modified in every changeset.
19730
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2270 # This is really slow on large repos, so compute the set lazily.
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2271 class lazywantedset(object):
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2272 def __init__(self):
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2273 self.set = set()
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2274 self.revs = set(revs)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2275
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2276 # No need to worry about locality here because it will be accessed
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2277 # in the same order as the increasing window below.
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2278 def __contains__(self, value):
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2279 if value in self.set:
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2280 return True
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2281 elif not value in self.revs:
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2282 return False
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2283 else:
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2284 self.revs.discard(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2285 ctx = change(value)
41694
5d383d9636d0 walkchangerevs: obey allfiles parameter when taking the slow path
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 41675
diff changeset
2286 if allfiles:
5d383d9636d0 walkchangerevs: obey allfiles parameter when taking the slow path
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 41675
diff changeset
2287 matches = list(ctx.manifest().walk(match))
5d383d9636d0 walkchangerevs: obey allfiles parameter when taking the slow path
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 41675
diff changeset
2288 else:
5d383d9636d0 walkchangerevs: obey allfiles parameter when taking the slow path
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 41675
diff changeset
2289 matches = [f for f in ctx.files() if match(f)]
19730
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2290 if matches:
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2291 fncache[value] = matches
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2292 self.set.add(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2293 return True
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2294 return False
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2295
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2296 def discard(self, value):
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2297 self.revs.discard(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2298 self.set.discard(value)
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2299
d184bae667e4 log: make file log slow path usable on large repos
Durham Goode <durham@fb.com>
parents: 19511
diff changeset
2300 wanted = lazywantedset()
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2301
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2302 # it might be worthwhile to do this in the iterator if the rev range
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2303 # is descending and the prune args are all within that range
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2304 for rev in opts.get(b'prune', ()):
16380
84ba30e8c790 cmdutil: use context instead of lookup
Matt Mackall <mpm@selenic.com>
parents: 16304
diff changeset
2305 rev = repo[rev].rev()
24391
6c3a93e690c7 walkchangerevs: make followfilter a top-level class
Martin von Zweigbergk <martinvonz@google.com>
parents: 24384
diff changeset
2306 ff = _followfilter(repo)
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2307 stop = min(revs[0], revs[-1])
38823
e7aa113b14f7 global: use pycompat.xrange()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38810
diff changeset
2308 for x in pycompat.xrange(rev, stop - 1, -1):
8152
08e1baf924ca replace set-like dictionaries with real sets
Martin Geisler <mg@lazybytes.net>
parents: 8119
diff changeset
2309 if ff.match(x):
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2310 wanted = wanted - [x]
18710
49ef9d0ca815 cmdutil: use a small initial window with --limit
Bryan O'Sullivan <bryano@fb.com>
parents: 18688
diff changeset
2311
11632
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
2312 # Now that wanted is correctly initialized, we can iterate over the
f418d2570920 log: document the different phases in walkchangerevs
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11631
diff changeset
2313 # revision range, yielding only revisions in wanted.
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2314 def iterate():
25272
6c76c42a5893 walkchangerevs: avoid match.files() in conditions
Martin von Zweigbergk <martinvonz@google.com>
parents: 25271
diff changeset
2315 if follow and match.always():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2316 ff = _followfilter(repo, onlyfirst=opts.get(b'follow_first'))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2317
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2318 def want(rev):
8119
af44d0b953c6 cmdutil: return boolean result directly in want function
Martin Geisler <mg@lazybytes.net>
parents: 8117
diff changeset
2319 return ff.match(rev) and rev in wanted
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2320
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2321 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2322
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2323 def want(rev):
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2324 return rev in wanted
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2325
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2326 it = iter(revs)
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2327 stopiteration = False
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2328 for windowsize in increasingwindows():
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2329 nrevs = []
38823
e7aa113b14f7 global: use pycompat.xrange()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38810
diff changeset
2330 for i in pycompat.xrange(windowsize):
25147
fb7b9a765bb9 walkchangerevs: replace try/except with 'next'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25119
diff changeset
2331 rev = next(it, None)
fb7b9a765bb9 walkchangerevs: replace try/except with 'next'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25119
diff changeset
2332 if rev is None:
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2333 stopiteration = True
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2334 break
25147
fb7b9a765bb9 walkchangerevs: replace try/except with 'next'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25119
diff changeset
2335 elif want(rev):
fb7b9a765bb9 walkchangerevs: replace try/except with 'next'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25119
diff changeset
2336 nrevs.append(rev)
8209
a1a5a57efe90 replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents: 8189
diff changeset
2337 for rev in sorted(nrevs):
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2338 fns = fncache.get(rev)
9654
96fe91be9c1e walkchangerevs: yield contexts
Matt Mackall <mpm@selenic.com>
parents: 9653
diff changeset
2339 ctx = change(rev)
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2340 if not fns:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2341
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2342 def fns_generator():
38348
b8f45fc27370 grep: adds allfiles mode
Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com>
parents: 38347
diff changeset
2343 if allfiles:
b8f45fc27370 grep: adds allfiles mode
Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com>
parents: 38347
diff changeset
2344 fiter = iter(ctx)
b8f45fc27370 grep: adds allfiles mode
Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com>
parents: 38347
diff changeset
2345 else:
b8f45fc27370 grep: adds allfiles mode
Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com>
parents: 38347
diff changeset
2346 fiter = ctx.files()
b8f45fc27370 grep: adds allfiles mode
Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com>
parents: 38347
diff changeset
2347 for f in fiter:
9652
2cb0cab10d2e walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents: 9547
diff changeset
2348 if match(f):
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2349 yield f
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2350
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2351 fns = fns_generator()
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
2352 prepare(ctx, fns)
3650
731e739b8659 move walkchangerevs to cmdutils
Matt Mackall <mpm@selenic.com>
parents: 3649
diff changeset
2353 for rev in nrevs:
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9656
diff changeset
2354 yield change(rev)
20553
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2355
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2356 if stopiteration:
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2357 break
86cefb15e7b5 cmdutil: implemented new lazy increasingwindows
Lucas Moscovicz <lmoscovicz@fb.com>
parents: 20500
diff changeset
2358
9652
2cb0cab10d2e walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents: 9547
diff changeset
2359 return iterate()
5034
c0417a319e39 commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents: 4965
diff changeset
2360
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2361
41661
f8b18583049f add: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41660
diff changeset
2362 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
2363 bad = []
25436
9724cbe2d546 add: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25424
diff changeset
2364
9724cbe2d546 add: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25424
diff changeset
2365 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
2366 names = []
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
2367 wctx = repo[None]
14138
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
2368 cca = None
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
2369 abort, warn = scmutil.checkportabilityalert(ui)
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
2370 if abort or warn:
17201
afd75476939e scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents: 17182
diff changeset
2371 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
2372
40088
1d09ba0d2ed3 narrow: move remaining narrow-limited dirstate walks to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 40030
diff changeset
2373 match = repo.narrowmatch(match, includeexact=True)
26206
ab1c6e4efda4 add: pass full=False to dirstate walk
Durham Goode <durham@fb.com>
parents: 26098
diff changeset
2374 badmatch = matchmod.badmatch(match, badfn)
ab1c6e4efda4 add: pass full=False to dirstate walk
Durham Goode <durham@fb.com>
parents: 26098
diff changeset
2375 dirstate = repo.dirstate
ab1c6e4efda4 add: pass full=False to dirstate walk
Durham Goode <durham@fb.com>
parents: 26098
diff changeset
2376 # 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
2377 # clean files, which we aren't interested in and takes time.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2378 for f in sorted(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2379 dirstate.walk(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2380 badmatch,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2381 subrepos=sorted(wctx.substate),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2382 unknown=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2383 ignored=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2384 full=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2385 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2386 ):
12269
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
2387 exact = match.exact(f)
23462
afa3fbbcabd3 add: use lexists so that broken symbolic links are added
John Coomes <john.coomes@oracle.com>
parents: 23453
diff changeset
2388 if exact or not explicitonly and f not in wctx and repo.wvfs.lexists(f):
14138
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
2389 if cca:
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14129
diff changeset
2390 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
2391 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
2392 if ui.verbose or not exact:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2393 ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2394 _(b'adding %s\n') % uipathfn(f), label=b'ui.addremove.added'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2395 )
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
2396
18364
6252b4f1c4b4 subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 18340
diff changeset
2397 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
2398 sub = wctx.sub(subpath)
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
2399 try:
28017
d3f1b7ee5e70 match: rename "narrowmatcher" to "subdirmatcher" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27985
diff changeset
2400 submatch = matchmod.subdirmatcher(subpath, match)
41639
ed046348675c subrepo: adjust subrepo prefix before calling subrepo.add() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41638
diff changeset
2401 subprefix = repo.wvfs.reljoin(prefix, subpath)
41661
f8b18583049f add: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41660
diff changeset
2402 subuipathfn = scmutil.subdiruipathfn(subpath, uipathfn)
32196
a77e61b45384 py3: handle opts correctly for `hg add`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32193
diff changeset
2403 if opts.get(r'subrepos'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2404 bad.extend(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2405 sub.add(ui, submatch, subprefix, subuipathfn, False, **opts)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2406 )
15410
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
2407 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2408 bad.extend(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2409 sub.add(ui, submatch, subprefix, subuipathfn, True, **opts)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2410 )
15410
9e99d2bbb1b1 add: support adding explicit files in subrepos
David M. Carr <david@carrclan.us>
parents: 15231
diff changeset
2411 except error.LookupError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2412 ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2413 _(b"skipping missing subrepository: %s\n") % uipathfn(subpath)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2414 )
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
2415
32196
a77e61b45384 py3: handle opts correctly for `hg add`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32193
diff changeset
2416 if not opts.get(r'dry_run'):
12270
166b9866580a add: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents: 12269
diff changeset
2417 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
2418 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
2419 return bad
877236cdd437 add: move main part to cmdutil to make it easier to reuse
Martin Geisler <mg@lazybytes.net>
parents: 12266
diff changeset
2420
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2421
32005
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
2422 def addwebdirpath(repo, serverpath, webconf):
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
2423 webconf[serverpath] = repo.root
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2424 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
2425
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2426 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
2427 ctx = repo[r]
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
2428 for subpath in ctx.substate:
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
2429 ctx.sub(subpath).addwebdirpath(serverpath, webconf)
2406dbba49bd serve: add support for Mercurial subrepositories
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
2430
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2431
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2432 def forget(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2433 ui, repo, match, prefix, uipathfn, explicitonly, dryrun, interactive
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2434 ):
37778
f10cb49951e1 forget: rename --confirm to --interactive
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37774
diff changeset
2435 if dryrun and interactive:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2436 raise error.Abort(_(b"cannot specify both --dry-run and --interactive"))
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
2437 bad = []
25437
9c1bcd95b3ff forget: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25436
diff changeset
2438 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
2439 wctx = repo[None]
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
2440 forgot = []
25437
9c1bcd95b3ff forget: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25436
diff changeset
2441
9c1bcd95b3ff forget: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25436
diff changeset
2442 s = repo.status(match=matchmod.badmatch(match, badfn), clean=True)
32223
e4a4ebfd9d8e forget: access status fields by name, not index
Martin von Zweigbergk <martinvonz@google.com>
parents: 32204
diff changeset
2443 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
2444 if explicitonly:
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
2445 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
2446
18364
6252b4f1c4b4 subrepos: process subrepos in sorted order
Mads Kiilerich <mads@kiilerich.com>
parents: 18340
diff changeset
2447 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
2448 sub = wctx.sub(subpath)
41638
f92844cb942c subrepo: adjust subrepo prefix before calling subrepo.forget() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41637
diff changeset
2449 submatch = matchmod.subdirmatcher(subpath, match)
f92844cb942c subrepo: adjust subrepo prefix before calling subrepo.forget() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41637
diff changeset
2450 subprefix = repo.wvfs.reljoin(prefix, subpath)
41664
16a49c778bde forget: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41663
diff changeset
2451 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
2452 try:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2453 subbad, subforgot = sub.forget(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2454 submatch,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2455 subprefix,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2456 subuipathfn,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2457 dryrun=dryrun,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2458 interactive=interactive,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2459 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2460 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
2461 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
2462 except error.LookupError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2463 ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2464 _(b"skipping missing subrepository: %s\n") % uipathfn(subpath)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2465 )
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
2466
16070
f11eee00c652 forget: show warning messages for forgetting in subrepo correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15912
diff changeset
2467 if not explicitonly:
f11eee00c652 forget: show warning messages for forgetting in subrepo correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 15912
diff changeset
2468 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
2469 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
2470 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
2471 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
2472 # 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
2473 # 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
2474 # 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
2475 # 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
2476 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
2477 continue
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2478 ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2479 _(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2480 b'not removing %s: '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2481 b'file is already untracked\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2482 )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2483 % uipathfn(f)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2484 )
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
2485 bad.append(f)
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
2486
37778
f10cb49951e1 forget: rename --confirm to --interactive
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37774
diff changeset
2487 if interactive:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2488 responses = _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2489 b'[Ynsa?]'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2490 b'$$ &Yes, forget this file'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2491 b'$$ &No, skip this file'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2492 b'$$ &Skip remaining files'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2493 b'$$ Include &all remaining files'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2494 b'$$ &? (display help)'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2495 )
37756
e7bf5a73e4e1 forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37621
diff changeset
2496 for filename in forget[:]:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2497 r = ui.promptchoice(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2498 _(b'forget %s %s') % (uipathfn(filename), responses)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2499 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2500 if r == 4: # ?
37756
e7bf5a73e4e1 forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37621
diff changeset
2501 while r == 4:
e7bf5a73e4e1 forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37621
diff changeset
2502 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
2503 ui.write(b'%s - %s\n' % (c, encoding.lower(t)))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2504 r = ui.promptchoice(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2505 _(b'forget %s %s') % (uipathfn(filename), responses)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2506 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2507 if r == 0: # yes
37756
e7bf5a73e4e1 forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37621
diff changeset
2508 continue
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2509 elif r == 1: # no
37756
e7bf5a73e4e1 forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37621
diff changeset
2510 forget.remove(filename)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2511 elif r == 2: # Skip
37756
e7bf5a73e4e1 forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37621
diff changeset
2512 fnindex = forget.index(filename)
e7bf5a73e4e1 forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37621
diff changeset
2513 del forget[fnindex:]
e7bf5a73e4e1 forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37621
diff changeset
2514 break
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2515 elif r == 3: # All
37756
e7bf5a73e4e1 forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37621
diff changeset
2516 break
e7bf5a73e4e1 forget: add --confirm option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37621
diff changeset
2517
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
2518 for f in forget:
37778
f10cb49951e1 forget: rename --confirm to --interactive
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37774
diff changeset
2519 if ui.verbose or not match.exact(f) or interactive:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2520 ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2521 _(b'removing %s\n') % uipathfn(f), label=b'ui.addremove.removed'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2522 )
15912
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
2523
36945
45bfcd16f27e forget: add --dry-run mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 36742
diff changeset
2524 if not dryrun:
45bfcd16f27e forget: add --dry-run mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 36742
diff changeset
2525 rejected = wctx.forget(forget, prefix)
45bfcd16f27e forget: add --dry-run mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 36742
diff changeset
2526 bad.extend(f for f in rejected if f in match.files())
45bfcd16f27e forget: add --dry-run mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 36742
diff changeset
2527 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
2528 return bad, forgot
2bd54ffaa27e forget: fix subrepo recursion for explicit path handling
David M. Carr <david@carrclan.us>
parents: 15911
diff changeset
2529
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2530
41757
980e05204ed8 subrepo: use root-repo-relative path from `hg files` with ui.relative-paths=no
Martin von Zweigbergk <martinvonz@google.com>
parents: 41696
diff changeset
2531 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
2532 ret = 1
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
2533
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2534 needsfctx = ui.verbose or {b'size', b'flags'} & fm.datahint()
24275
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
2535 for f in ctx.matches(m):
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
2536 fm.startitem()
38543
7ae0ea739770 files: add support for log-like template keywords and functions
Yuya Nishihara <yuya@tcha.org>
parents: 38542
diff changeset
2537 fm.context(ctx=ctx)
38542
475f5f86eaed files: automatically populate fields referenced from template
Yuya Nishihara <yuya@tcha.org>
parents: 38540
diff changeset
2538 if needsfctx:
24275
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
2539 fc = ctx[f]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2540 fm.write(b'size flags', b'% 10d % 1s ', fc.size(), fc.flags())
39396
34ba47117164 formatter: rename {abspath}/{file} to {path}, and drop relative {path} (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 39377
diff changeset
2541 fm.data(path=f)
41590
15f63ac122ea files: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41574
diff changeset
2542 fm.plain(fmt % uipathfn(f))
24275
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
2543 ret = 0
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
2544
25228
63a57a2727b6 files: recurse into subrepos automatically with an explicit path
Matt Harbison <matt_harbison@yahoo.com>
parents: 25169
diff changeset
2545 for subpath in sorted(ctx.substate):
29813
35560189677c subrepo: cleanup of subrepo filematcher logic
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29806
diff changeset
2546 submatch = matchmod.subdirmatcher(subpath, m)
41757
980e05204ed8 subrepo: use root-repo-relative path from `hg files` with ui.relative-paths=no
Martin von Zweigbergk <martinvonz@google.com>
parents: 41696
diff changeset
2547 subuipathfn = scmutil.subdiruipathfn(subpath, uipathfn)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2548 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
2549 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
2550 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
2551 recurse = m.exact(subpath) or subrepos
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2552 if (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2553 sub.printfiles(ui, submatch, subuipathfn, fm, fmt, recurse)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2554 == 0
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2555 ):
24413
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24391
diff changeset
2556 ret = 0
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24391
diff changeset
2557 except error.LookupError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2558 ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2559 _(b"skipping missing subrepository: %s\n")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2560 % uipathfn(subpath)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2561 )
24413
a8595176dd64 subrepo: add basic support to hgsubrepo for the files command
Matt Harbison <matt_harbison@yahoo.com>
parents: 24391
diff changeset
2562
24275
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
2563 return ret
e1cb460a3524 files: split reusable implementation into cmdutil for subrepo support
Matt Harbison <matt_harbison@yahoo.com>
parents: 24272
diff changeset
2564
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2565
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2566 def remove(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2567 ui, repo, m, prefix, uipathfn, after, force, subrepos, dryrun, warnings=None
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2568 ):
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2569 ret = 0
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2570 s = repo.status(match=m, clean=True)
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2571 modified, added, deleted, clean = s[0], s[1], s[3], s[6]
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2572
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
2573 wctx = repo[None]
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
2574
28607
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
2575 if warnings is None:
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
2576 warnings = []
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
2577 warn = True
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
2578 else:
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
2579 warn = False
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
2580
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
2581 subs = sorted(wctx.substate)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2582 progress = ui.makeprogress(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2583 _(b'searching'), total=len(subs), unit=_(b'subrepos')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2584 )
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
2585 for subpath in subs:
29813
35560189677c subrepo: cleanup of subrepo filematcher logic
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29806
diff changeset
2586 submatch = matchmod.subdirmatcher(subpath, m)
41637
2c549abc6b85 subrepo: adjust subrepo prefix before calling subrepo.removefiles() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41636
diff changeset
2587 subprefix = repo.wvfs.reljoin(prefix, subpath)
41662
b2df5dc3ebfb remove: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41661
diff changeset
2588 subuipathfn = scmutil.subdiruipathfn(subpath, uipathfn)
29813
35560189677c subrepo: cleanup of subrepo filematcher logic
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29806
diff changeset
2589 if subrepos or m.exact(subpath) or any(submatch.files()):
38353
89db59e5cf3e remove: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38348
diff changeset
2590 progress.increment()
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
2591 sub = wctx.sub(subpath)
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
2592 try:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2593 if sub.removefiles(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2594 submatch,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2595 subprefix,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2596 subuipathfn,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2597 after,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2598 force,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2599 subrepos,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2600 dryrun,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2601 warnings,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2602 ):
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
2603 ret = 1
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
2604 except error.LookupError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2605 warnings.append(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2606 _(b"skipping missing subrepository: %s\n")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2607 % uipathfn(subpath)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2608 )
38379
ef692614e601 progress: hide update(None) in a new complete() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 38353
diff changeset
2609 progress.complete()
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
2610
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2611 # warn about failure to delete explicit files/dirs
24635
21e1ece30f8c util: move dirs() and finddirs() from scmutil to util
Drew Gottlieb <drgott@google.com>
parents: 24603
diff changeset
2612 deleteddirs = util.dirs(deleted)
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
2613 files = m.files()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2614 progress = ui.makeprogress(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2615 _(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
2616 )
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
2617 for f in files:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2618
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
2619 def insubrepo():
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
2620 for subpath in wctx.substate:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2621 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
2622 return True
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
2623 return False
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
2624
38353
89db59e5cf3e remove: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38348
diff changeset
2625 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
2626 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
2627 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
2628 continue
23325
4165cfd67519 remove: recurse into subrepositories with --subrepos/-S flag
Matt Harbison <matt_harbison@yahoo.com>
parents: 23289
diff changeset
2629
23674
6e36b9fc7869 remove: use vfs instead of os.path + match.rel() for filesystem checks
Matt Harbison <matt_harbison@yahoo.com>
parents: 23673
diff changeset
2630 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
2631 if repo.wvfs.isdir(f):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2632 warnings.append(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2633 _(b'not removing %s: no tracked files\n') % uipathfn(f)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2634 )
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2635 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2636 warnings.append(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2637 _(b'not removing %s: file is untracked\n') % uipathfn(f)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
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 # 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
2640 ret = 1
38379
ef692614e601 progress: hide update(None) in a new complete() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 38353
diff changeset
2641 progress.complete()
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2642
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2643 if force:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2644 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
2645 elif after:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2646 list = deleted
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
2647 remaining = modified + added + clean
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2648 progress = ui.makeprogress(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2649 _(b'skipping'), total=len(remaining), unit=_(b'files')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2650 )
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
2651 for f in remaining:
38353
89db59e5cf3e remove: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38348
diff changeset
2652 progress.increment()
35144
7a58608281dd remove: print message for each file in verbose mode only while using `-A` (BC)
pavanpc@fb.com
parents: 35130
diff changeset
2653 if ui.verbose or (f in files):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2654 warnings.append(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2655 _(b'not removing %s: file still exists\n') % uipathfn(f)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2656 )
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2657 ret = 1
38379
ef692614e601 progress: hide update(None) in a new complete() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 38353
diff changeset
2658 progress.complete()
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2659 else:
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2660 list = deleted + clean
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2661 progress = ui.makeprogress(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2662 _(b'skipping'), total=(len(modified) + len(added)), unit=_(b'files')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2663 )
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2664 for f in modified:
38353
89db59e5cf3e remove: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38348
diff changeset
2665 progress.increment()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2666 warnings.append(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2667 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2668 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
2669 b' to force removal)\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2670 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2671 % uipathfn(f)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2672 )
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2673 ret = 1
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2674 for f in added:
38353
89db59e5cf3e remove: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38348
diff changeset
2675 progress.increment()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2676 warnings.append(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2677 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2678 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
2679 b" (use 'hg forget' to undo add)\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2680 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2681 % uipathfn(f)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2682 )
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2683 ret = 1
38379
ef692614e601 progress: hide update(None) in a new complete() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 38353
diff changeset
2684 progress.complete()
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
2685
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
2686 list = sorted(list)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2687 progress = ui.makeprogress(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2688 _(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
2689 )
28608
62e73d42bd14 remove: add progress support
timeless <timeless@mozdev.org>
parents: 28607
diff changeset
2690 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
2691 if ui.verbose or not m.exact(f):
38353
89db59e5cf3e remove: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38348
diff changeset
2692 progress.increment()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2693 ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2694 _(b'removing %s\n') % uipathfn(f), label=b'ui.addremove.removed'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2695 )
38379
ef692614e601 progress: hide update(None) in a new complete() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 38353
diff changeset
2696 progress.complete()
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2697
37153
335e19c6b7fa remove: add dry-run functionality
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37106
diff changeset
2698 if not dryrun:
335e19c6b7fa remove: add dry-run functionality
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37106
diff changeset
2699 with repo.wlock():
335e19c6b7fa remove: add dry-run functionality
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37106
diff changeset
2700 if not after:
335e19c6b7fa remove: add dry-run functionality
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37106
diff changeset
2701 for f in list:
335e19c6b7fa remove: add dry-run functionality
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37106
diff changeset
2702 if f in added:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2703 continue # we never unlink added files on remove
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2704 rmdir = repo.ui.configbool(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2705 b'experimental', b'removeemptydirs'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2706 )
38497
da2a7d8354b2 unlinkpath: make empty directory removal optional (issue5901) (issue5826)
Kyle Lippincott <spectral@google.com>
parents: 38465
diff changeset
2707 repo.wvfs.unlinkpath(f, ignoremissing=True, rmdir=rmdir)
37153
335e19c6b7fa remove: add dry-run functionality
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 37106
diff changeset
2708 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
2709
28607
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
2710 if warn:
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
2711 for warning in warnings:
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
2712 ui.warn(warning)
a88959ae5938 remove: queue warnings until after status messages (issue5140) (API)
timeless <timeless@mozdev.org>
parents: 28601
diff changeset
2713
23289
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2714 return ret
ae5d0a22ee7e remove: move most of the implementation into cmdutils.remove()
Matt Harbison <matt_harbison@yahoo.com>
parents: 23258
diff changeset
2715
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2716
42494
561cd02c58ff cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents: 42489
diff changeset
2717 def _catfmtneedsdata(fm):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2718 return not fm.datahint() or b'data' in fm.datahint()
42494
561cd02c58ff cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents: 42489
diff changeset
2719
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2720
35662
91f0979f16c0 cat: factor out a function that populates the formatter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35645
diff changeset
2721 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
2722 """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
2723
91f0979f16c0 cat: factor out a function that populates the formatter
Matt Harbison <matt_harbison@yahoo.com>
parents: 35645
diff changeset
2724 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
2725 this method first."""
42494
561cd02c58ff cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents: 42489
diff changeset
2726
561cd02c58ff cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents: 42489
diff changeset
2727 # 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: 42489
diff changeset
2728 # wasn't requested.
561cd02c58ff cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents: 42489
diff changeset
2729 data = b''
561cd02c58ff cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents: 42489
diff changeset
2730 if _catfmtneedsdata(fm):
561cd02c58ff cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents: 42489
diff changeset
2731 data = ctx[path].data()
561cd02c58ff cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents: 42489
diff changeset
2732 if decode:
561cd02c58ff cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents: 42489
diff changeset
2733 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
2734 fm.startitem()
38540
b1bbff1dd99a cat: add support for log-like template keywords and functions
Yuya Nishihara <yuya@tcha.org>
parents: 38497
diff changeset
2735 fm.context(ctx=ctx)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2736 fm.write(b'data', b'%s', data)
39396
34ba47117164 formatter: rename {abspath}/{file} to {path}, and drop relative {path} (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 39377
diff changeset
2737 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
2738
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2739
32610
746e12a767b3 cat: add formatter support
Yuya Nishihara <yuya@tcha.org>
parents: 32609
diff changeset
2740 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
2741 err = 1
35359
82ee401135dd py3: handle keyword arguments correctly in cmdutil.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35286
diff changeset
2742 opts = pycompat.byteskwargs(opts)
21040
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
2743
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
2744 def write(path):
32610
746e12a767b3 cat: add formatter support
Yuya Nishihara <yuya@tcha.org>
parents: 32609
diff changeset
2745 filename = None
32608
7f4435078a8f cat: stop using makefileobj()
Yuya Nishihara <yuya@tcha.org>
parents: 32573
diff changeset
2746 if fntemplate:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2747 filename = makefilename(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2748 ctx, fntemplate, pathname=os.path.join(prefix, path)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2749 )
35048
407ec7f3ff02 cmdutil: create dirs for templated cat file output
Ryan McElroy <rmcelroy@fb.com>
parents: 35037
diff changeset
2750 # 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: 35037
diff changeset
2751 try:
407ec7f3ff02 cmdutil: create dirs for templated cat file output
Ryan McElroy <rmcelroy@fb.com>
parents: 35037
diff changeset
2752 os.makedirs(os.path.dirname(filename))
407ec7f3ff02 cmdutil: create dirs for templated cat file output
Ryan McElroy <rmcelroy@fb.com>
parents: 35037
diff changeset
2753 except OSError:
407ec7f3ff02 cmdutil: create dirs for templated cat file output
Ryan McElroy <rmcelroy@fb.com>
parents: 35037
diff changeset
2754 pass
37597
d110167610db formatter: carry opts to file-based formatters by basefm
Yuya Nishihara <yuya@tcha.org>
parents: 37470
diff changeset
2755 with formatter.maybereopen(basefm, filename) as fm:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2756 _updatecatformatter(fm, ctx, matcher, path, opts.get(b'decode'))
21040
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
2757
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
2758 # 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
2759 # 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
2760 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
2761 file = matcher.files()[0]
30350
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30342
diff changeset
2762 mfl = repo.manifestlog
24718
a4191e0c728f cat: use ctx.manifestnode() in place of ctx._changeset[0]
Yuya Nishihara <yuya@tcha.org>
parents: 24711
diff changeset
2763 mfnode = ctx.manifestnode()
30350
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30342
diff changeset
2764 try:
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30342
diff changeset
2765 if mfnode and mfl[mfnode].find(file)[0]:
42494
561cd02c58ff cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents: 42489
diff changeset
2766 if _catfmtneedsdata(basefm):
561cd02c58ff cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents: 42489
diff changeset
2767 scmutil.prefetchfiles(repo, [ctx.rev()], matcher)
30350
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30342
diff changeset
2768 write(file)
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30342
diff changeset
2769 return 0
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30342
diff changeset
2770 except KeyError:
608ba935e041 manifest: remove manifest.find
Durham Goode <durham@fb.com>
parents: 30342
diff changeset
2771 pass
21040
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
2772
42494
561cd02c58ff cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents: 42489
diff changeset
2773 if _catfmtneedsdata(basefm):
561cd02c58ff cat: don't prefetch files unless the output requires it
Matt Harbison <matt_harbison@yahoo.com>
parents: 42489
diff changeset
2774 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
2775
7269b87f817c scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 37756
diff changeset
2776 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
2777 write(abs)
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
2778 err = 0
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
2779
41674
28ce9184d495 cat: respect ui.relative-paths for "skipping missing subrepository"
Martin von Zweigbergk <martinvonz@google.com>
parents: 41672
diff changeset
2780 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
2781 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
2782 sub = ctx.sub(subpath)
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
2783 try:
28017
d3f1b7ee5e70 match: rename "narrowmatcher" to "subdirmatcher" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 27985
diff changeset
2784 submatch = matchmod.subdirmatcher(subpath, matcher)
41660
799e156785f7 subrepo: (mostly) use relative path in "skipping missing subrepository"
Martin von Zweigbergk <martinvonz@google.com>
parents: 41639
diff changeset
2785 subprefix = os.path.join(prefix, subpath)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2786 if not sub.cat(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2787 submatch,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2788 basefm,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2789 fntemplate,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2790 subprefix,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2791 **pycompat.strkwargs(opts)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2792 ):
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
2793 err = 0
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
2794 except error.RepoLookupError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2795 ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2796 _(b"skipping missing subrepository: %s\n") % uipathfn(subpath)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2797 )
21041
a2cc3c08c3ac cat: support cat with explicit paths in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents: 21040
diff changeset
2798
21040
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
2799 return err
bdf5ed5246d2 cat: move most of the implementation into cmdutils.cat()
Matt Harbison <matt_harbison@yahoo.com>
parents: 21036
diff changeset
2800
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2801
5034
c0417a319e39 commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents: 4965
diff changeset
2802 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
2803 '''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
2804 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
2805 if date:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2806 opts[b'date'] = dateutil.parsedate(date)
14635
217b7d83afc3 cmdutil, logmessage: use ui.fin when reading from '-'
Idan Kamara <idankk86@gmail.com>
parents: 14518
diff changeset
2807 message = logmessage(ui, opts)
23533
891aaa7c0c70 scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns
Matt Harbison <matt_harbison@yahoo.com>
parents: 23509
diff changeset
2808 matcher = scmutil.match(repo[None], pats, opts)
5034
c0417a319e39 commands: move commit to cmdutil as wrapper for commit-like functions
Bryan O'Sullivan <bos@serpentine.com>
parents: 4965
diff changeset
2809
33616
5ac845ca059a commit: don't let failed commit with --addremove update dirstate (issue5645)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33548
diff changeset
2810 dsguard = None
5829
784073457a0f cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents: 5797
diff changeset
2811 # extract addremove carefully -- this function can be called from a command
784073457a0f cmdutil.commit: extract 'addremove' from opts carefully
Kirill Smelkov <kirr@mns.spb.ru>
parents: 5797
diff changeset
2812 # that doesn't support addremove
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2813 if opts.get(b'addremove'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2814 dsguard = dirstateguard.dirstateguard(repo, b'commit')
33845
158dddc635ff commit: use context manager with dirstateguard
Martin von Zweigbergk <martinvonz@google.com>
parents: 33844
diff changeset
2815 with dsguard or util.nullcontextmanager():
33844
5d286eb7009f commit: move dirstateguard creation out of try-block
Martin von Zweigbergk <martinvonz@google.com>
parents: 33804
diff changeset
2816 if dsguard:
41663
6a447a3d1bd0 addremove: pass around uipathfn and use instead of m.uipath() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41662
diff changeset
2817 relative = scmutil.anypats(pats, opts)
41696
b81ecf3571d5 addremove: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41694
diff changeset
2818 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=relative)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2819 if scmutil.addremove(repo, matcher, b"", uipathfn, opts) != 0:
33616
5ac845ca059a commit: don't let failed commit with --addremove update dirstate (issue5645)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33548
diff changeset
2820 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2821 _(b"failed to mark all new/missing files as added/removed")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2822 )
33616
5ac845ca059a commit: don't let failed commit with --addremove update dirstate (issue5645)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33548
diff changeset
2823
33845
158dddc635ff commit: use context manager with dirstateguard
Martin von Zweigbergk <martinvonz@google.com>
parents: 33844
diff changeset
2824 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
2825
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2826
29830
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29813
diff changeset
2827 def samefile(f, ctx1, ctx2):
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29813
diff changeset
2828 if f in ctx1.manifest():
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29813
diff changeset
2829 a = ctx1.filectx(f)
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29813
diff changeset
2830 if f in ctx2.manifest():
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29813
diff changeset
2831 b = ctx2.filectx(f)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2832 return not a.cmp(b) and a.flags() == b.flags()
29830
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29813
diff changeset
2833 else:
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29813
diff changeset
2834 return False
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29813
diff changeset
2835 else:
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29813
diff changeset
2836 return f not in ctx2.manifest()
2cec6eaf3610 cmdutil: extract samefile function from amend()
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 29813
diff changeset
2837
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2838
34103
a39dce4a76b8 cmdutil: remove redundant commitfunc parameter in amend (API)
Saurabh Singh <singhsrb@fb.com>
parents: 34102
diff changeset
2839 def amend(ui, repo, old, extra, pats, opts):
25930
221491bbaf7e cmdutil: break import cycle
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25795
diff changeset
2840 # avoid cycle context -> subrepo -> cmdutil
28322
ebd0e86bdf89 cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28313
diff changeset
2841 from . import context
25930
221491bbaf7e cmdutil: break import cycle
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25795
diff changeset
2842
23101
b564330d4b1f amend: abort early if no username is configured with evolve enabled (issue4211)
Matt Harbison <matt_harbison@yahoo.com>
parents: 22951
diff changeset
2843 # 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
2844 # 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
2845 if obsolete.isenabled(repo, obsolete.createmarkersopt):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2846 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
2847
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2848 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
2849 base = old.p1()
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
2850
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2851 with repo.wlock(), repo.lock(), repo.transaction(b'amend'):
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2852 # Participating changesets:
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2853 #
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2854 # wctx o - workingctx that contains changes from working copy
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2855 # | to go into amending commit
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2856 # |
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2857 # old o - changeset to amend
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2858 # |
34073
7e9ccb1670e3 amend: rectify comment
Saurabh Singh <singhsrb@fb.com>
parents: 34072
diff changeset
2859 # base o - first parent of the changeset to amend
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2860 wctx = repo[None]
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2861
35207
5cc14407a739 amend: make a copy of "extra" to avoid mutating an input
Martin von Zweigbergk <martinvonz@google.com>
parents: 35184
diff changeset
2862 # Copy to avoid mutating input
5cc14407a739 amend: make a copy of "extra" to avoid mutating an input
Martin von Zweigbergk <martinvonz@google.com>
parents: 35184
diff changeset
2863 extra = extra.copy()
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2864 # Update extra dict from amended commit (e.g. to preserve graft
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2865 # source)
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2866 extra.update(old.extra())
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2867
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2868 # Also update it from the from the wctx
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2869 extra.update(wctx.extra())
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2870
42936
e4803231f538 amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents: 42925
diff changeset
2871 # date-only change should be ignored?
e4803231f538 amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents: 42925
diff changeset
2872 datemaydiffer = resolvecommitoptions(ui, opts)
e4803231f538 amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents: 42925
diff changeset
2873
e4803231f538 amend: add option to update to the current user
Matt Harbison <matt_harbison@yahoo.com>
parents: 42925
diff changeset
2874 date = old.date()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2875 if opts.get(b'date'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2876 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
2877 user = opts.get(b'user') or old.user()
34136
ae95853c250a cmdutil: fix amend when passing a date
Boris Feld <boris.feld@octobus.net>
parents: 34103
diff changeset
2878
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2879 if len(old.parents()) > 1:
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2880 # ctx.files() isn't reliable for merges, so fall back to the
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2881 # slower repo.status() method
42057
566daffc607d cleanup: use set literals where possible
Martin von Zweigbergk <martinvonz@google.com>
parents: 41994
diff changeset
2882 files = {fn for st in base.status(old)[:3] for fn in st}
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2883 else:
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2884 files = set(old.files())
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2885
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2886 # 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: 34100
diff changeset
2887 # was specified.
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2888 matcher = scmutil.match(wctx, pats, opts)
41663
6a447a3d1bd0 addremove: pass around uipathfn and use instead of m.uipath() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 41662
diff changeset
2889 relative = scmutil.anypats(pats, opts)
41696
b81ecf3571d5 addremove: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41694
diff changeset
2890 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=relative)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2891 if opts.get(b'addremove') and scmutil.addremove(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2892 repo, matcher, b"", uipathfn, opts
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2893 ):
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2894 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2895 _(b"failed to mark all new/missing files as added/removed")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2896 )
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2897
34978
691524f0bbf6 amend: update .hgsubstate before committing a memctx (issue5677)
Yuya Nishihara <yuya@tcha.org>
parents: 34975
diff changeset
2898 # 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: 34975
diff changeset
2899 # 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: 34975
diff changeset
2900 # 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
2901 if b'.hgsub' in wctx or b'.hgsub' in old:
36047
55e8efa2451a subrepo: split non-core functions to new module
Yuya Nishihara <yuya@tcha.org>
parents: 35993
diff changeset
2902 subs, commitsubs, newsubstate = subrepoutil.precommit(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2903 ui, wctx, wctx._status, matcher
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2904 )
34978
691524f0bbf6 amend: update .hgsubstate before committing a memctx (issue5677)
Yuya Nishihara <yuya@tcha.org>
parents: 34975
diff changeset
2905 # amend should abort if commitsubrepos is enabled
691524f0bbf6 amend: update .hgsubstate before committing a memctx (issue5677)
Yuya Nishihara <yuya@tcha.org>
parents: 34975
diff changeset
2906 assert not commitsubs
691524f0bbf6 amend: update .hgsubstate before committing a memctx (issue5677)
Yuya Nishihara <yuya@tcha.org>
parents: 34975
diff changeset
2907 if subs:
36047
55e8efa2451a subrepo: split non-core functions to new module
Yuya Nishihara <yuya@tcha.org>
parents: 35993
diff changeset
2908 subrepoutil.writestate(repo, newsubstate)
34978
691524f0bbf6 amend: update .hgsubstate before committing a memctx (issue5677)
Yuya Nishihara <yuya@tcha.org>
parents: 34975
diff changeset
2909
35853
eeb87b24aea7 amend: abort if unresolved merge conflicts found (issue5805)
Yuya Nishihara <yuya@tcha.org>
parents: 35746
diff changeset
2910 ms = mergemod.mergestate.read(repo)
eeb87b24aea7 amend: abort if unresolved merge conflicts found (issue5805)
Yuya Nishihara <yuya@tcha.org>
parents: 35746
diff changeset
2911 mergeutil.checkunresolved(ms)
eeb87b24aea7 amend: abort if unresolved merge conflicts found (issue5805)
Yuya Nishihara <yuya@tcha.org>
parents: 35746
diff changeset
2912
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2913 filestoamend = set(f for f in wctx.files() if matcher(f))
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2914
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2915 changes = len(filestoamend) > 0
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2916 if changes:
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2917 # Recompute copies (avoid recording a -> b -> a)
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2918 copied = copies.pathcopies(base, wctx, matcher)
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2919 if old.p2:
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2920 copied.update(copies.pathcopies(old.p2(), wctx, matcher))
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2921
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2922 # Prune files which were reverted by the updates: if old
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2923 # 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: 34100
diff changeset
2924 # copy, then those two files are the same and
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2925 # we can discard X from our list of files. Likewise if X
34975
5f40efa472db amend: do not drop missing files (issue5732)
Yuya Nishihara <yuya@tcha.org>
parents: 34974
diff changeset
2926 # 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: 34974
diff changeset
2927 # deleted), old X must be preserved.
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2928 files.update(filestoamend)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2929 files = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2930 f
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2931 for f in files
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2932 if (f not in filestoamend or not samefile(f, wctx, base))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2933 ]
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2934
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2935 def filectxfn(repo, ctx_, path):
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2936 try:
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2937 # If the file being considered is not amongst the files
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2938 # to be amended, we should return the file context from the
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2939 # old changeset. This avoids issues when only some files in
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2940 # the working copy are being amended but there are also
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2941 # changes to other files from the old changeset.
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2942 if path not in filestoamend:
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2943 return old.filectx(path)
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2944
34974
0ba3b928f9a9 amend: do not take untracked files as modified or clean (issue5732)
Yuya Nishihara <yuya@tcha.org>
parents: 34959
diff changeset
2945 # Return None for removed files.
0ba3b928f9a9 amend: do not take untracked files as modified or clean (issue5732)
Yuya Nishihara <yuya@tcha.org>
parents: 34959
diff changeset
2946 if path in wctx.removed():
0ba3b928f9a9 amend: do not take untracked files as modified or clean (issue5732)
Yuya Nishihara <yuya@tcha.org>
parents: 34959
diff changeset
2947 return None
0ba3b928f9a9 amend: do not take untracked files as modified or clean (issue5732)
Yuya Nishihara <yuya@tcha.org>
parents: 34959
diff changeset
2948
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2949 fctx = wctx[path]
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2950 flags = fctx.flags()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2951 mctx = context.memfilectx(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2952 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2953 ctx_,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2954 fctx.path(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2955 fctx.data(),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2956 islink=b'l' in flags,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2957 isexec=b'x' in flags,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2958 copysource=copied.get(path),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2959 )
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2960 return mctx
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2961 except KeyError:
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2962 return None
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2963
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2964 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2965 ui.note(_(b'copying changeset %s to %s\n') % (old, base))
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2966
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2967 # Use version of files as in the old cset
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2968 def filectxfn(repo, ctx_, path):
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2969 try:
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2970 return old.filectx(path)
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2971 except KeyError:
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2972 return None
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2973
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2974 # 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: 34100
diff changeset
2975 # the message of the changeset to amend.
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2976 message = logmessage(ui, opts)
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2977
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2978 editform = mergeeditform(old, b'commit.amend')
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
2979
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2980 if not message:
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2981 message = old.description()
42418
64ed405dd342 commit: respect --no-edit in combination with --amend
Kyle Lippincott <spectral@google.com>
parents: 42297
diff changeset
2982 # 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: 42297
diff changeset
2983 # 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: 42297
diff changeset
2984 # 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
2985 doedit = not message or opts.get(b'edit') in [True, None]
42418
64ed405dd342 commit: respect --no-edit in combination with --amend
Kyle Lippincott <spectral@google.com>
parents: 42297
diff changeset
2986 else:
64ed405dd342 commit: respect --no-edit in combination with --amend
Kyle Lippincott <spectral@google.com>
parents: 42297
diff changeset
2987 # 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: 42297
diff changeset
2988 # --edit.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2989 doedit = opts.get(b'edit') is True
42418
64ed405dd342 commit: respect --no-edit in combination with --amend
Kyle Lippincott <spectral@google.com>
parents: 42297
diff changeset
2990 editor = getcommiteditor(edit=doedit, editform=editform)
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2991
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2992 pureextra = extra.copy()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
2993 extra[b'amend_source'] = old.hex()
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
2994
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2995 new = context.memctx(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2996 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2997 parents=[base.node(), old.p2().node()],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2998 text=message,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
2999 files=files,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3000 filectxfn=filectxfn,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3001 user=user,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3002 date=date,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3003 extra=extra,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3004 editor=editor,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3005 )
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
3006
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
3007 newdesc = changelog.stripdesc(new.description())
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3008 if (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3009 (not changes)
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
3010 and newdesc == old.description()
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
3011 and user == old.user()
41127
cffa8e0ba77a amend: add boolean to ignore date-only change
Yuya Nishihara <yuya@tcha.org>
parents: 41126
diff changeset
3012 and (date == old.date() or datemaydiffer)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3013 and pureextra == old.extra()
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3014 ):
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
3015 # nothing changed. continuing here would create a new node
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
3016 # 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
3017 #
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
3018 # This not what we expect from amend.
41127
cffa8e0ba77a amend: add boolean to ignore date-only change
Yuya Nishihara <yuya@tcha.org>
parents: 41126
diff changeset
3019 return old.node()
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33362
diff changeset
3020
38429
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 38379
diff changeset
3021 commitphase = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3022 if opts.get(b'secret'):
38429
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 38379
diff changeset
3023 commitphase = phases.secret
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 38379
diff changeset
3024 newid = repo.commitctx(new)
34072
ae92e5c0441c amend: removing redundant if condition
Saurabh Singh <singhsrb@fb.com>
parents: 34046
diff changeset
3025
ae92e5c0441c amend: removing redundant if condition
Saurabh Singh <singhsrb@fb.com>
parents: 34046
diff changeset
3026 # Reroute the working copy parent to the new changeset
ae92e5c0441c amend: removing redundant if condition
Saurabh Singh <singhsrb@fb.com>
parents: 34046
diff changeset
3027 repo.setparents(newid, nullid)
ae92e5c0441c amend: removing redundant if condition
Saurabh Singh <singhsrb@fb.com>
parents: 34046
diff changeset
3028 mapping = {old.node(): (newid,)}
34794
5781e0931c16 cmdutil: pass metadata from amend() to cleanupnodes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34698
diff changeset
3029 obsmetadata = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3030 if opts.get(b'note'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3031 obsmetadata = {b'note': encoding.fromlocal(opts[b'note'])}
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3032 backup = ui.configbool(b'rewrite', b'backup-bundle')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3033 scmutil.cleanupnodes(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3034 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3035 mapping,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3036 b'amend',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3037 metadata=obsmetadata,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3038 fixphase=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3039 targetphase=commitphase,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3040 backup=backup,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3041 )
34072
ae92e5c0441c amend: removing redundant if condition
Saurabh Singh <singhsrb@fb.com>
parents: 34046
diff changeset
3042
34102
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3043 # Fixing the dirstate because localrepo.commitctx does not update
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3044 # it. This is rather convenient because we did not need to update
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3045 # the dirstate for all the files in the new commit which commitctx
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3046 # could have done if it updated the dirstate. Now, we can
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3047 # selectively update the dirstate only for the amended files.
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3048 dirstate = repo.dirstate
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3049
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3050 # Update the state of the files which were added and
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3051 # and modified in the amend to "normal" in the dirstate.
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3052 normalfiles = set(wctx.modified() + wctx.added()) & filestoamend
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3053 for f in normalfiles:
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3054 dirstate.normal(f)
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3055
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3056 # Update the state of files which were removed in the amend
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3057 # to "removed" in the dirstate.
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3058 removedfiles = set(wctx.removed()) & filestoamend
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3059 for f in removedfiles:
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3060 dirstate.drop(f)
e8a7c1a0565a cmdutil: remove the redundant commit during amend
Saurabh Singh <singhsrb@fb.com>
parents: 34100
diff changeset
3061
16458
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
3062 return newid
55982f62651f commit: add option to amend the working dir parent
Idan Kamara <idankk86@gmail.com>
parents: 16430
diff changeset
3063
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3064
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3065 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
3066 if ctx.description():
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
3067 return ctx.description()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3068 return commitforceeditor(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3069 repo, ctx, subs, editform=editform, unchangedmessagedetection=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3070 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3071
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3072
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3073 def commitforceeditor(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3074 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3075 ctx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3076 subs,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3077 finishdesc=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3078 extramsg=None,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3079 editform=b'',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3080 unchangedmessagedetection=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3081 ):
21923
e582e20cd3e6 commiteditor: refactor default extramsg
Matt Mackall <mpm@selenic.com>
parents: 21878
diff changeset
3082 if not extramsg:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3083 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
3084
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3085 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
3086 forms.insert(0, b'changeset')
26742
bec1a579ebc4 commit: abort when a committemplate is not changed
Tony Tung <tonytung@fb.com>
parents: 26639
diff changeset
3087 templatetext = None
22012
9d92b9d1e282 cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22011
diff changeset
3088 while forms:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3089 ref = b'.'.join(forms)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3090 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
3091 templatetext = committext = buildcommittemplate(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3092 repo, ctx, subs, extramsg, ref
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3093 )
22012
9d92b9d1e282 cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22011
diff changeset
3094 break
9d92b9d1e282 cmdutil: look commit template definition up by specified 'editform'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22011
diff changeset
3095 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
3096 else:
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
3097 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
3098
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
3099 # run editor in the repository root
39823
24e493ec2229 py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 39753
diff changeset
3100 olddir = encoding.getcwd()
21869
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
3101 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
3102
9f9ec4abe700 cmdutil: make in-memory changes visible to external editor (issue4378)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26746
diff changeset
3103 # 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
3104 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
3105 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
3106 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
3107
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3108 editortext = repo.ui.edit(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3109 committext,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3110 ctx.user(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3111 ctx.extra(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3112 editform=editform,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3113 pending=pending,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3114 repopath=repo.path,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3115 action=b'commit',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3116 )
30724
ee47e951c6f9 commit: fix unmodified message detection for the "--- >8 ----" magic
Yuya Nishihara <yuya@tcha.org>
parents: 30720
diff changeset
3117 text = editortext
30703
5c85c93cdd61 cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents: 30695
diff changeset
3118
5c85c93cdd61 cmdutil: add special string that ignores rest of text
Sean Farley <sean@farley.io>
parents: 30695
diff changeset
3119 # 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
3120 # to display the diff)
30724
ee47e951c6f9 commit: fix unmodified message detection for the "--- >8 ----" magic
Yuya Nishihara <yuya@tcha.org>
parents: 30720
diff changeset
3121 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
3122 if stripbelow:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3123 text = text[: stripbelow.start()]
30724
ee47e951c6f9 commit: fix unmodified message detection for the "--- >8 ----" magic
Yuya Nishihara <yuya@tcha.org>
parents: 30720
diff changeset
3124
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3125 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
3126 os.chdir(olddir)
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
3127
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
3128 if finishdesc:
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
3129 text = finishdesc(text)
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
3130 if not text.strip():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3131 raise error.Abort(_(b"empty commit message"))
26742
bec1a579ebc4 commit: abort when a committemplate is not changed
Tony Tung <tonytung@fb.com>
parents: 26639
diff changeset
3132 if unchangedmessagedetection and editortext == templatetext:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3133 raise error.Abort(_(b"commit message unchanged"))
21869
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
3134
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
3135 return text
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
3136
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3137
32896
a3a36bcf122e commit: select template by spec.ref name
Yuya Nishihara <yuya@tcha.org>
parents: 32895
diff changeset
3138 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
3139 ui = repo.ui
32896
a3a36bcf122e commit: select template by spec.ref name
Yuya Nishihara <yuya@tcha.org>
parents: 32895
diff changeset
3140 spec = formatter.templatespec(ref, None, None)
35993
386c1e45e671 logcmdutil: drop default arguments from changesetdisplayer/templater() calls
Yuya Nishihara <yuya@tcha.org>
parents: 35966
diff changeset
3141 t = logcmdutil.changesettemplater(ui, repo, spec)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3142 t.t.cache.update(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3143 (k, templater.unquotestring(v))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3144 for k, v in repo.ui.configitems(b'committemplate')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3145 )
22013
de5cee8ba088 cmdutil: use '[committemplate]' section like as map file for style definition
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 22012
diff changeset
3146
21924
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
3147 if not extramsg:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3148 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
3149
5375ba75df40 cmdutil: make commit message shown in text editor customizable by template
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21923
diff changeset
3150 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
3151 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
3152 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
3153
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3154
26426
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
3155 def hgprefix(msg):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3156 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
3157
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3158
21869
e353fac7db26 cmdutil: separate building commit text from 'commitforceeditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21832
diff changeset
3159 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
3160 edittext = []
8707
0550dfe4fca1 commit: editor reads file lists from provided context
Matt Mackall <mpm@selenic.com>
parents: 8680
diff changeset
3161 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
3162 if ctx.description():
223000a687b0 commit: move commit editor to cmdutil, pass as function
Matt Mackall <mpm@selenic.com>
parents: 8390
diff changeset
3163 edittext.append(ctx.description())
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3164 edittext.append(b"")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3165 edittext.append(b"") # Empty line between message and comments.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3166 edittext.append(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3167 hgprefix(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3168 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3169 b"Enter commit message."
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3170 b" Lines beginning with 'HG:' are removed."
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3171 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3172 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3173 )
26426
0486c16ce621 cmdutil: handle multiline translations of HG: messages safely
timeless@mozdev.org
parents: 26389
diff changeset
3174 edittext.append(hgprefix(extramsg))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3175 edittext.append(b"HG: --")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3176 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
3177 if ctx.p2():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3178 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
3179 if ctx.branch():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3180 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
3181 if bookmarks.isactivewdirparent(repo):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3182 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
3183 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
3184 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
3185 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
3186 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
3187 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
3188 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
3189 edittext.append(b"")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3190
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3191 return b"\n".join(edittext)
14297
2daa5179e73f commands: use a decorator to build table incrementally
Adrian Buehlmann <adrian@cadifra.com>
parents: 14291
diff changeset
3192
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3193
26324
4a8e21578e14 addremove: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26229
diff changeset
3194 def commitstatus(repo, node, branch, bheads=None, opts=None):
4a8e21578e14 addremove: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26229
diff changeset
3195 if opts is None:
4a8e21578e14 addremove: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26229
diff changeset
3196 opts = {}
18688
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3197 ctx = repo[node]
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3198 parents = ctx.parents()
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3199
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3200 if (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3201 not opts.get(b'amend')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3202 and bheads
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3203 and node not in bheads
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3204 and not [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3205 x for x in parents if x.node() in bheads and x.branch() == branch
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3206 ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3207 ):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3208 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
3209 # 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
3210 # 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
3211 #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3212 # 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
3213 # N: null or no parent
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3214 # 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
3215 # 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
3216 # 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
3217 # 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
3218 # 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
3219 # 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
3220 # printed anyway.
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3221 #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3222 # Par Msg Comment
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3223 # 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
3224 #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3225 # 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
3226 # 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
3227 # H N n usual case
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3228 #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3229 # 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
3230 # C B y branch merge
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3231 # 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
3232 #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3233 # 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
3234 # 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
3235 #
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3236 # 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
3237
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3238 if not opts.get(b'close_branch'):
18688
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3239 for r in parents:
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3240 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
3241 repo.ui.status(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3242 _(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
3243 )
18688
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3244
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3245 if repo.ui.debugflag:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3246 repo.ui.write(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3247 _(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
3248 )
18688
79107fad06aa commit: factor out status printing into a helper function
Kevin Bullock <kbullock@ringworld.org>
parents: 18648
diff changeset
3249 elif repo.ui.verbose:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3250 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
3251
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3252
27943
02c5f8ad00ac commit: factor the post commit status check into a cmdutil method
Matt Harbison <matt_harbison@yahoo.com>
parents: 27868
diff changeset
3253 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
3254 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
3255
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3256
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
3257 def revert(ui, repo, ctx, parents, *pats, **opts):
35168
3da4bd50103d py3: fix handling of keyword arguments in revert
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35144
diff changeset
3258 opts = pycompat.byteskwargs(opts)
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
3259 parent, p2 = parents
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
3260 node = ctx.node()
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
3261
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
3262 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
3263 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
3264 parent = p2
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
3265
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
3266 # 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
3267 # 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
3268 # 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
3269 # 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
3270 # 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
3271
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
3272 # `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
3273 # The mapping is in the form:
39314
6b81d2ff118f cmdutil: fix typo in revert()
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 39305
diff changeset
3274 # <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
3275 names = {}
41618
7068c6b0114b revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41610
diff changeset
3276 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
3277
27803
a8e8950ebd4d with: use context manager for wlock in revert
Bryan O'Sullivan <bryano@fb.com>
parents: 27802
diff changeset
3278 with repo.wlock():
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
3279 ## filling of the `names` mapping
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
3280 # 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
3281
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3282 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
3283 wctx = repo[None]
bab983bb6fd1 revert: define 'wctx' a little earlier and use it more
Martin von Zweigbergk <martinvonz@google.com>
parents: 24438
diff changeset
3284 m = scmutil.match(wctx, pats, opts)
24479
871485bd03fd revert: move calculation of targetsubs earlier
Matt Mackall <mpm@selenic.com>
parents: 24476
diff changeset
3285
871485bd03fd revert: move calculation of targetsubs earlier
Matt Mackall <mpm@selenic.com>
parents: 24476
diff changeset
3286 # we'll need this later
871485bd03fd revert: move calculation of targetsubs earlier
Matt Mackall <mpm@selenic.com>
parents: 24476
diff changeset
3287 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
3288
24450
961790c35b4f revert: take fast path also when not reverting to '.'
Martin von Zweigbergk <martinvonz@google.com>
parents: 24449
diff changeset
3289 if not m.always():
32401
7b3c27af90c2 cmdutil: use repo[None].walk instead of repo.walk
Augie Fackler <augie@google.com>
parents: 32382
diff changeset
3290 matcher = matchmod.badmatch(m, lambda x, y: False)
32421
c87db79b9507 cleanup: reuse existing wctx variables instead of calling repo[None]
Martin von Zweigbergk <martinvonz@google.com>
parents: 32414
diff changeset
3291 for abs in wctx.walk(matcher):
41618
7068c6b0114b revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41610
diff changeset
3292 names[abs] = m.exact(abs)
22573
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3293
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3294 # walk target manifest to fill `names`
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3295
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3296 def badfn(path, msg):
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3297 if path in names:
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3298 return
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3299 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
3300 return
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3301 path_ = path + b'/'
22573
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3302 for f in names:
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3303 if f.startswith(path_):
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3304 return
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3305 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
3306
25439
aaede04c0ba6 revert: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25438
diff changeset
3307 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
3308 if abs not in names:
41618
7068c6b0114b revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41610
diff changeset
3309 names[abs] = m.exact(abs)
22573
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3310
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3311 # Find status of all file in `names`.
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3312 m = scmutil.matchfiles(repo, names)
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3313
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3314 changes = repo.status(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3315 node1=node, match=m, unknown=True, ignored=True, clean=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3316 )
22573
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3317 else:
24450
961790c35b4f revert: take fast path also when not reverting to '.'
Martin von Zweigbergk <martinvonz@google.com>
parents: 24449
diff changeset
3318 changes = repo.status(node1=node, match=m)
22573
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3319 for kind in changes:
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3320 for abs in kind:
41618
7068c6b0114b revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41610
diff changeset
3321 names[abs] = m.exact(abs)
22573
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3322
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3323 m = scmutil.matchfiles(repo, names)
f528bfb25b45 revert: special case 'hg revert --all'
Durham Goode <durham@fb.com>
parents: 22551
diff changeset
3324
23374
aa0a430d9c75 revert: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@google.com>
parents: 23327
diff changeset
3325 modified = set(changes.modified)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3326 added = set(changes.added)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3327 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
3328 _deleted = set(changes.deleted)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3329 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
3330 unknown.update(changes.ignored)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3331 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
3332 modadded = set()
22185
afead12e724b revert: triage "deleted" files into more appropriate categories
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22173
diff changeset
3333
24180
d8e0c591781c spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 24176
diff changeset
3334 # 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
3335 # 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
3336 # 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
3337 # 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
3338 if parent == node:
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
3339 dsmodified = modified
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
3340 dsadded = added
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
3341 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
3342 # 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
3343 localchanges = dsmodified | dsadded
22155
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
3344 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
3345 else:
530390629842 revert: call status against revert target too
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22154
diff changeset
3346 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
3347 dsmodified = set(changes.modified)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3348 dsadded = set(changes.added)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3349 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
3350 # 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
3351 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
3352
22188
0ad619c5e1a4 revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22187
diff changeset
3353 # 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
3354 clean |= dsremoved - removed
0ad619c5e1a4 revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22187
diff changeset
3355 dsremoved &= removed
0ad619c5e1a4 revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22187
diff changeset
3356 # 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
3357 removed -= dsremoved
0ad619c5e1a4 revert: use "remove" information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22187
diff changeset
3358
22610
0f323ed8effd revert: track added files with local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22609
diff changeset
3359 modadded = added & dsmodified
0f323ed8effd revert: track added files with local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22609
diff changeset
3360 added -= modadded
0f323ed8effd revert: track added files with local modifications
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22609
diff changeset
3361
22190
55308ab8117c revert: use modified information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22189
diff changeset
3362 # tell newly modified apart.
55308ab8117c revert: use modified information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22189
diff changeset
3363 dsmodified &= modified
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3364 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
3365 modified -= dsmodified
55308ab8117c revert: use modified information from both statuses
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22189
diff changeset
3366
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
3367 # 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
3368 # 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
3369 # that purpose.
22208
d3659b3795e9 revert: simplify handling of `added` files
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22205
diff changeset
3370 dsadded = added
d3659b3795e9 revert: simplify handling of `added` files
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22205
diff changeset
3371
22209
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
3372 # 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
3373 # modified, we need to post process the result
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
3374 if p2 != nullid:
31149
c22253c4c1b8 revert: remove set(mf) because it's O(manifest)
Durham Goode <durham@fb.com>
parents: 31095
diff changeset
3375 mergeadd = set(dsmodified)
c22253c4c1b8 revert: remove set(mf) because it's O(manifest)
Durham Goode <durham@fb.com>
parents: 31095
diff changeset
3376 for path in dsmodified:
c22253c4c1b8 revert: remove set(mf) because it's O(manifest)
Durham Goode <durham@fb.com>
parents: 31095
diff changeset
3377 if path in mf:
c22253c4c1b8 revert: remove set(mf) because it's O(manifest)
Durham Goode <durham@fb.com>
parents: 31095
diff changeset
3378 mergeadd.remove(path)
22209
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
3379 dsadded |= mergeadd
06fbd9518bc5 revert: detect files added during a merge
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22208
diff changeset
3380 dsmodified -= mergeadd
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
3381
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
3382 # 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
3383 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
3384 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
3385 # XXX should we check for rename down to target node?
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3386 if src and src not in names and repo.dirstate[src] == b'r':
22154
fc422de25773 revert: prefix variable names for dirstate status with "ds"
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22153
diff changeset
3387 dsremoved.add(src)
41618
7068c6b0114b revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41610
diff changeset
3388 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
3389
31167
accdd5e62066 revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents: 31149
diff changeset
3390 # determine the exact nature of the deleted changesets
accdd5e62066 revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents: 31149
diff changeset
3391 deladded = set(_deleted)
accdd5e62066 revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents: 31149
diff changeset
3392 for path in _deleted:
accdd5e62066 revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents: 31149
diff changeset
3393 if path in mf:
accdd5e62066 revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents: 31149
diff changeset
3394 deladded.remove(path)
accdd5e62066 revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents: 31149
diff changeset
3395 deleted = _deleted - deladded
accdd5e62066 revert: move code dealing with deletions closer together
Martin von Zweigbergk <martinvonz@google.com>
parents: 31149
diff changeset
3396
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
3397 # 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
3398 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
3399 for abs in dsadded:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3400 if repo.dirstate[abs] != b'a':
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
3401 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
3402 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
3403
22490
bcab7bc7280e revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22489
diff changeset
3404 for abs in deladded:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3405 if repo.dirstate[abs] == b'a':
22490
bcab7bc7280e revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22489
diff changeset
3406 dsadded.add(abs)
bcab7bc7280e revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22489
diff changeset
3407 deladded -= dsadded
bcab7bc7280e revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22489
diff changeset
3408
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
3409 # 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
3410 # 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
3411 # 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
3412 # 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
3413 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
3414 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
3415 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
3416 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
3417 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
3418 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
3419
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
3420 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
3421 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
3422 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
3423 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
3424 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
3425 dsremoved -= dsremovunk
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
3426
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
3427 # 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
3428 # (<list of file>, message>) tuple
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3429 actions = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3430 b'revert': ([], _(b'reverting %s\n')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3431 b'add': ([], _(b'adding %s\n')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3432 b'remove': ([], _(b'removing %s\n')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3433 b'drop': ([], _(b'removing %s\n')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3434 b'forget': ([], _(b'forgetting %s\n')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3435 b'undelete': ([], _(b'undeleting %s\n')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3436 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
3437 b'unknown': (None, _(b'file not managed: %s\n')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3438 }
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
3439
22608
bf0ecb224316 revert: small refactoring in the way backup value are handled
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22588
diff changeset
3440 # "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
3441 # 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
3442 # 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
3443 # These values are ordered for comparison purposes
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3444 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
3445 backup = 2 # unconditionally do backup
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3446 check = 1 # check if the existing file differs from target
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3447 discard = 0 # never do backup
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3448 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
3449 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
3450 if interactive:
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
3451 dsmodifiedbackup = backupinteractive
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
3452 else:
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
3453 dsmodifiedbackup = backup
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
3454 tobackup = set()
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
3455
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3456 backupanddel = actions[b'remove']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3457 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
3458 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
3459
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
3460 disptable = (
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
3461 # dispatch table:
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
3462 # 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
3463 # action
fc8bc2787528 revert: move manifest membership condition outside of the loop
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22013
diff changeset
3464 # make backup
22371
81ad62defef5 revert: add documentation in the dispatch table
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22370
diff changeset
3465 ## 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
3466 # 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
3467 (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
3468 # 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
3469 (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
3470 # 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
3471 (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
3472 # Added since target
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3473 (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
3474 # Added in working directory
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3475 (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
3476 # Added since target, have local modification
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3477 (modadded, backupanddel, backup),
22490
bcab7bc7280e revert: explicitly track added but deleted file
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22489
diff changeset
3478 # 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
3479 (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
3480 # 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
3481 (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
3482 # 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
3483 (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
3484 # 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
3485 (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
3486 # 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
3487 (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
3488 ## 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
3489 # File with no modification
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3490 (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
3491 # Existing file, not tracked anywhere
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3492 (unknown, actions[b'unknown'], discard),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3493 )
16304
a740fa28d718 revert: move bulk of revert command from commands to cmdutil
Angel Ezquerra <angel.ezquerra@gmail.com>
parents: 16283
diff changeset
3494
41618
7068c6b0114b revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41610
diff changeset
3495 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
3496 # 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
3497 target = repo.wjoin(abs)
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
3498 # 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
3499 # 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
3500 # 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
3501 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
3502 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
3503 continue
22233
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
3504 if xlist is not None:
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
3505 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
3506 if dobackup:
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
3507 # 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
3508 # .orig files (issue4793)
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
3509 if dobackup == backupinteractive:
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
3510 tobackup.add(abs)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3511 elif backup <= dobackup or wctx[abs].cmp(ctx[abs]):
41618
7068c6b0114b revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41610
diff changeset
3512 absbakname = scmutil.backuppath(ui, repo, abs)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3513 bakname = os.path.relpath(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3514 absbakname, start=repo.root
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3515 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3516 ui.note(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3517 _(b'saving current version of %s as %s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3518 % (uipathfn(abs), uipathfn(bakname))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3519 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3520 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
3521 if interactive:
41618
7068c6b0114b revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41610
diff changeset
3522 util.copyfile(target, absbakname)
24475
06cbff4674a3 revert: fix --interactive on local modification (issue4576)
Laurent Charignon <lcharignon@fb.com>
parents: 24472
diff changeset
3523 else:
41618
7068c6b0114b revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41610
diff changeset
3524 util.rename(target, absbakname)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3525 if opts.get(b'dry_run'):
39432
cb70501d8b71 revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 39431
diff changeset
3526 if ui.verbose or not exact:
41618
7068c6b0114b revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41610
diff changeset
3527 ui.status(msg % uipathfn(abs))
22233
4ab61b24e20c revert: simplify loop conditional
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22232
diff changeset
3528 elif exact:
41618
7068c6b0114b revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41610
diff changeset
3529 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
3530 break
21575
8262c2a39ab8 revert: add some inline comments
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21574
diff changeset
3531
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3532 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
3533 needdata = (b'revert', b'add', b'undelete')
35963
efbd04238029 cmdutil: convert _revertprefetch() to a generic stored file hook (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 35950
diff changeset
3534 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
3535 prefetch = scmutil.prefetchfiles
7269b87f817c scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 37756
diff changeset
3536 matchfiles = scmutil.matchfiles
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3537 prefetch(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3538 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3539 [ctx.rev()],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3540 matchfiles(repo, [f for sublist in oplist for f in sublist]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3541 )
42071
db72f9f6580e interactive: do not prompt about files given in command line
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 42057
diff changeset
3542 match = scmutil.match(repo[None], pats)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3543 _performrevert(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3544 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3545 parents,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3546 ctx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3547 names,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3548 uipathfn,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3549 actions,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3550 match,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3551 interactive,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3552 tobackup,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3553 )
19129
bd19587a3347 revert: ensure that copies and renames are honored (issue3920)
Bryan O'Sullivan <bryano@fb.com>
parents: 19024
diff changeset
3554
24134
afed5d2e7985 revert: display full subrepo output with --dry-run
Matt Harbison <matt_harbison@yahoo.com>
parents: 24064
diff changeset
3555 if targetsubs:
afed5d2e7985 revert: display full subrepo output with --dry-run
Matt Harbison <matt_harbison@yahoo.com>
parents: 24064
diff changeset
3556 # 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
3557 for sub in targetsubs:
24463
06d199e66bbc revert: handle subrepos missing in the given --rev
Matt Harbison <matt_harbison@yahoo.com>
parents: 24455
diff changeset
3558 try:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3559 wctx.sub(sub).revert(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3560 ctx.substate[sub], *pats, **pycompat.strkwargs(opts)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3561 )
24463
06d199e66bbc revert: handle subrepos missing in the given --rev
Matt Harbison <matt_harbison@yahoo.com>
parents: 24455
diff changeset
3562 except KeyError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3563 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3564 b"subrepository '%s' does not exist in %s!"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3565 % (sub, short(ctx.node()))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3566 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3567
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3568
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3569 def _performrevert(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3570 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3571 parents,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3572 ctx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3573 names,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3574 uipathfn,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3575 actions,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3576 match,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3577 interactive=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3578 tobackup=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3579 ):
21576
33395a7e5527 revert: group action into a single dictionary
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 21575
diff changeset
3580 """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
3581
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3582 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
3583 the imminent revert.
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3584
21024
7731a2281cf0 spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents: 20790
diff changeset
3585 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
3586 """
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3587 parent, p2 = parents
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3588 node = ctx.node()
27985
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
3589 excluded_files = []
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
3590
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3591 def checkout(f):
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3592 fc = ctx[f]
25755
72d395e399c1 cmdutil: remove useless dirstate.normallookup() invocation in revert()
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 25739
diff changeset
3593 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
3594
30541
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30540
diff changeset
3595 def doremove(f):
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30540
diff changeset
3596 try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3597 rmdir = repo.ui.configbool(b'experimental', b'removeemptydirs')
38497
da2a7d8354b2 unlinkpath: make empty directory removal optional (issue5901) (issue5826)
Kyle Lippincott <spectral@google.com>
parents: 38465
diff changeset
3598 repo.wvfs.unlinkpath(f, rmdir=rmdir)
30541
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30540
diff changeset
3599 except OSError:
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30540
diff changeset
3600 pass
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30540
diff changeset
3601 repo.dirstate.remove(f)
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30540
diff changeset
3602
39432
cb70501d8b71 revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 39431
diff changeset
3603 def prntstatusmsg(action, f):
41618
7068c6b0114b revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41610
diff changeset
3604 exact = names[f]
39432
cb70501d8b71 revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 39431
diff changeset
3605 if repo.ui.verbose or not exact:
41618
7068c6b0114b revert: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41610
diff changeset
3606 repo.ui.status(actions[action][1] % uipathfn(f))
39432
cb70501d8b71 revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 39431
diff changeset
3607
33647
377e8ddaebef pathauditor: disable cache of audited paths by default (issue5628)
Yuya Nishihara <yuya@tcha.org>
parents: 33616
diff changeset
3608 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
3609 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
3610 if interactive:
30539
74013a831872 style: avoid an unnecessary line split
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30528
diff changeset
3611 choice = repo.ui.promptchoice(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3612 _(b"forget added file %s (Yn)?$$ &Yes $$ &No") % uipathfn(f)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3613 )
27985
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
3614 if choice == 0:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3615 prntstatusmsg(b'forget', f)
27985
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
3616 repo.dirstate.drop(f)
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
3617 else:
36232
39b3aab6231e revert: use an exact matcher in interactive diff selection (issue5789)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 36179
diff changeset
3618 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
3619 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3620 prntstatusmsg(b'forget', f)
27985
79139c7a88bd revert: makes interactive mode ask to forget added files (issue4936)
liscju <piotr.listkiewicz@gmail.com>
parents: 27973
diff changeset
3621 repo.dirstate.drop(f)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3622 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
3623 audit_path(f)
30541
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30540
diff changeset
3624 if interactive:
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30540
diff changeset
3625 choice = repo.ui.promptchoice(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3626 _(b"remove added file %s (Yn)?$$ &Yes $$ &No") % uipathfn(f)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3627 )
30541
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30540
diff changeset
3628 if choice == 0:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3629 prntstatusmsg(b'remove', f)
30541
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30540
diff changeset
3630 doremove(f)
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30540
diff changeset
3631 else:
36232
39b3aab6231e revert: use an exact matcher in interactive diff selection (issue5789)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 36179
diff changeset
3632 excluded_files.append(f)
30541
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30540
diff changeset
3633 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3634 prntstatusmsg(b'remove', f)
30541
66b162fa3ffa revert: prompt before removing files in interactive mode
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30540
diff changeset
3635 doremove(f)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3636 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
3637 audit_path(f)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3638 prntstatusmsg(b'drop', f)
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3639 repo.dirstate.remove(f)
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3640
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3641 normal = None
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3642 if node == parent:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3643 # We're reverting to our parent. If possible, we'd like status
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3644 # to report the file as clean. We have to use normallookup for
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3645 # merges to avoid losing information about merged/dirty files.
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3646 if p2 != nullid:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3647 normal = repo.dirstate.normallookup
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3648 else:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3649 normal = repo.dirstate.normal
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3650
25259
5b05f10c5024 revert: fix edition of newly added file during --interactive
Laurent Charignon <lcharignon@fb.com>
parents: 25258
diff changeset
3651 newlyaddedandmodifiedfiles = set()
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3652 if interactive:
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3653 # 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
3654 torevert = [f for f in actions[b'revert'][0] if f not in excluded_files]
36232
39b3aab6231e revert: use an exact matcher in interactive diff selection (issue5789)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 36179
diff changeset
3655 m = scmutil.matchfiles(repo, torevert)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3656 diffopts = patch.difffeatureopts(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3657 repo.ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3658 whitespace=True,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3659 section=b'commands',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3660 configprefix=b'revert.interactive.',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3661 )
25258
f37a69ec3f47 revert: make revert --interactive use git style diff
Laurent Charignon <lcharignon@fb.com>
parents: 25257
diff changeset
3662 diffopts.nodates = True
f37a69ec3f47 revert: make revert --interactive use git style diff
Laurent Charignon <lcharignon@fb.com>
parents: 25257
diff changeset
3663 diffopts.git = True
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3664 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
3665 if node == parent:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3666 if repo.ui.configbool(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3667 b'experimental', b'revert.interactive.select-to-keep'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3668 ):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3669 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
3670 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3671 operation = b'discard'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3672
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3673 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
3674 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
3675 else:
25424
69609f43c752 revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents: 25358
diff changeset
3676 diff = patch.diff(repo, ctx.node(), None, m, opts=diffopts)
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3677 originalchunks = patch.parsepatch(diff)
25424
69609f43c752 revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents: 25358
diff changeset
3678
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3679 try:
25424
69609f43c752 revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents: 25358
diff changeset
3680
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3681 chunks, opts = recordfilter(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3682 repo.ui, originalchunks, match, operation=operation
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3683 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3684 if operation == b'discard':
25424
69609f43c752 revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents: 25358
diff changeset
3685 chunks = patch.reversehunks(chunks)
69609f43c752 revert: add an experimental config to use inverted selection
Laurent Charignon <lcharignon@fb.com>
parents: 25358
diff changeset
3686
34258
61714510220d error: move patch.PatchError so it can easily implement __bytes__ (API)
Yuya Nishihara <yuya@tcha.org>
parents: 34201
diff changeset
3687 except error.PatchError as err:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3688 raise error.Abort(_(b'error parsing patch: %s') % err)
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3689
42862
3cf091843b4f split: handle partial commit of renames when doing split or record (issue5723)
Kyle Lippincott <spectral@google.com>
parents: 42643
diff changeset
3690 # 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
3691 # 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
3692 # "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
3693 # 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
3694 # copied/renamed files.
3cf091843b4f split: handle partial commit of renames when doing split or record (issue5723)
Kyle Lippincott <spectral@google.com>
parents: 42643
diff changeset
3695 newlyaddedandmodifiedfiles, unusedalsorestore = newandmodified(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3696 chunks, originalchunks
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3697 )
29498
1b38cfde9530 revert: don't backup if no files reverted in interactive mode (issue4793)
skarlage <skarlage@fb.com>
parents: 29427
diff changeset
3698 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
3699 tobackup = set()
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3700 # Apply changes
28861
86db5cb55d46 pycompat: switch to util.stringio for py3 compat
timeless <timeless@mozdev.org>
parents: 28837
diff changeset
3701 fp = stringio()
39441
1cbe19eb496d revert: stabilize status message of chunks selected interactively
Yuya Nishihara <yuya@tcha.org>
parents: 39432
diff changeset
3702 # chunks are serialized per file, but files aren't sorted
1cbe19eb496d revert: stabilize status message of chunks selected interactively
Yuya Nishihara <yuya@tcha.org>
parents: 39432
diff changeset
3703 for f in sorted(set(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
3704 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
3705 files = set()
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3706 for c in chunks:
39432
cb70501d8b71 revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 39431
diff changeset
3707 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
3708 abs = c.header.filename()
39432
cb70501d8b71 revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 39431
diff changeset
3709 # 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: 39431
diff changeset
3710 if c.header.filename() in tobackup:
cb70501d8b71 revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 39431
diff changeset
3711 target = repo.wjoin(abs)
41610
9e545c9a4dfe revert: migrate to scmutil.backuppath()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41604
diff changeset
3712 bakname = scmutil.backuppath(repo.ui, repo, abs)
39432
cb70501d8b71 revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 39431
diff changeset
3713 util.copyfile(target, bakname)
cb70501d8b71 revert: fix the inconsistency of status msgs in --interactive mode
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 39431
diff changeset
3714 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
3715 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
3716 files.add(abs)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3717 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
3718 checkout(abs)
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3719 c.write(fp)
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3720 dopatch = fp.tell()
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3721 fp.seek(0)
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3722 if dopatch:
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3723 try:
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3724 patch.internalpatch(repo.ui, repo, fp, 1, eolmode=None)
34258
61714510220d error: move patch.PatchError so it can easily implement __bytes__ (API)
Yuya Nishihara <yuya@tcha.org>
parents: 34201
diff changeset
3725 except error.PatchError as err:
36742
390d16ea7c76 py3: use pycompat.bytestr instead of str
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36692
diff changeset
3726 raise error.Abort(pycompat.bytestr(err))
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3727 del fp
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3728 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3729 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
3730 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
3731 checkout(f)
24359
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3732 if normal:
521fe8287dd5 revert: add flag to make revert interactive
Laurent Charignon <lcharignon@fb.com>
parents: 24358
diff changeset
3733 normal(f)
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3734
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3735 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
3736 # Don't checkout modified files, they are already created by the diff
5b05f10c5024 revert: fix edition of newly added file during --interactive
Laurent Charignon <lcharignon@fb.com>
parents: 25258
diff changeset
3737 if f not in newlyaddedandmodifiedfiles:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3738 prntstatusmsg(b'add', f)
25259
5b05f10c5024 revert: fix edition of newly added file during --interactive
Laurent Charignon <lcharignon@fb.com>
parents: 25258
diff changeset
3739 checkout(f)
5b05f10c5024 revert: fix edition of newly added file during --interactive
Laurent Charignon <lcharignon@fb.com>
parents: 25258
diff changeset
3740 repo.dirstate.add(f)
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3741
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3742 normal = repo.dirstate.normallookup
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3743 if node == parent and p2 == nullid:
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3744 normal = repo.dirstate.normal
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3745 for f in actions[b'undelete'][0]:
41536
d783c937aa53 revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents: 41396
diff changeset
3746 if interactive:
d783c937aa53 revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents: 41396
diff changeset
3747 choice = repo.ui.promptchoice(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3748 _(b"add back removed file %s (Yn)?$$ &Yes $$ &No") % f
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3749 )
41536
d783c937aa53 revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents: 41396
diff changeset
3750 if choice == 0:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3751 prntstatusmsg(b'undelete', f)
41536
d783c937aa53 revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents: 41396
diff changeset
3752 checkout(f)
d783c937aa53 revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents: 41396
diff changeset
3753 normal(f)
d783c937aa53 revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents: 41396
diff changeset
3754 else:
d783c937aa53 revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents: 41396
diff changeset
3755 excluded_files.append(f)
d783c937aa53 revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents: 41396
diff changeset
3756 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3757 prntstatusmsg(b'undelete', f)
41536
d783c937aa53 revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents: 41396
diff changeset
3758 checkout(f)
d783c937aa53 revert: add prompt before undeleting a file in -i (issue6008)
Taapas Agrawal <taapas2897@gmail.com>
parents: 41396
diff changeset
3759 normal(f)
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3760
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3761 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
3762
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3763 for f in (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3764 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
3765 ):
20571
d4893e64f300 revert: extract actual revert in its own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20553
diff changeset
3766 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
3767 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
3768
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3769
21051
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21047
diff changeset
3770 # 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
3771 # 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
3772 # "findcommonoutgoing()"
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21047
diff changeset
3773 outgoinghooks = util.hooks()
1004d3cd65fd outgoing: introduce "outgoinghooks" to avoid redundant outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21047
diff changeset
3774
19211
3bfd7f1e7485 summary: augment output with info from extensions
Bryan O'Sullivan <bryano@fb.com>
parents: 19129
diff changeset
3775 # 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
3776 summaryhooks = util.hooks()
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
3777
21047
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
3778 # 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
3779 #
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
3780 # 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
3781 # (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
3782 #
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
3783 # 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
3784 # - (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
3785 # - (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
3786 summaryremotehooks = util.hooks()
f0003f989e72 summary: introduce "summaryremotehooks" to avoid redundant incoming/outgoing check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21041
diff changeset
3787
42537
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
3788
42539
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42538
diff changeset
3789 def checkunfinished(repo, commit=False, skipmerge=False):
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
3790 '''Look for an unfinished multistep operation, like graft, and abort
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
3791 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
3792 bailifchanged().
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
3793 '''
37855
79c54e7c0c52 rebase: prioritize indicating an interrupted rebase over update (issue5838)
Matt Harbison <matt_harbison@yahoo.com>
parents: 37815
diff changeset
3794 # 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
3795 # precedence over update.
42537
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
3796 for state in statemod._unfinishedstates:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3797 if (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3798 state._clearable
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3799 or (commit and state._allowcommit)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3800 or state._reportonly
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3801 ):
37855
79c54e7c0c52 rebase: prioritize indicating an interrupted rebase over update (issue5838)
Matt Harbison <matt_harbison@yahoo.com>
parents: 37815
diff changeset
3802 continue
42537
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
3803 if state.isunfinished(repo):
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
3804 raise error.Abort(state.msg(), hint=state.hint())
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
3805
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
3806 for s in statemod._unfinishedstates:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3807 if (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3808 not s._clearable
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3809 or (commit and s._allowcommit)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3810 or (s._opname == b'merge' and skipmerge)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3811 or s._reportonly
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3812 ):
19496
607191a45f8c checkunfinished: accommodate histedit quirk
Matt Mackall <mpm@selenic.com>
parents: 19482
diff changeset
3813 continue
42537
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
3814 if s.isunfinished(repo):
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
3815 raise error.Abort(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
3816
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3817
19474
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
3818 def clearunfinished(repo):
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
3819 '''Check for unfinished operations (as above), and clear the ones
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
3820 that are clearable.
894fd1a7c533 cmdutil: core functionality to block during multistep commands (issue3955)
Matt Mackall <mpm@selenic.com>
parents: 19293
diff changeset
3821 '''
42537
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
3822 for state in statemod._unfinishedstates:
42539
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42538
diff changeset
3823 if state._reportonly:
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42538
diff changeset
3824 continue
42537
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
3825 if not state._clearable and state.isunfinished(repo):
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
3826 raise error.Abort(state.msg(), hint=state.hint())
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
3827
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
3828 for s in statemod._unfinishedstates:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3829 if s._opname == b'merge' or state._reportonly:
42539
12243f15d53e statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents: 42538
diff changeset
3830 continue
42537
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
3831 if s._clearable and s.isunfinished(repo):
dc3fdd1b5af4 state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42536
diff changeset
3832 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
3833
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3834
42579
b8d54f4625cb merge: disallow merge abort in case of an unfinished operation (issue6160)
Taapas Agrawal <taapas2897@gmail.com>
parents: 42577
diff changeset
3835 def getunfinishedstate(repo):
b8d54f4625cb merge: disallow merge abort in case of an unfinished operation (issue6160)
Taapas Agrawal <taapas2897@gmail.com>
parents: 42577
diff changeset
3836 ''' Checks for unfinished operations and returns statecheck object
b8d54f4625cb merge: disallow merge abort in case of an unfinished operation (issue6160)
Taapas Agrawal <taapas2897@gmail.com>
parents: 42577
diff changeset
3837 for it'''
b8d54f4625cb merge: disallow merge abort in case of an unfinished operation (issue6160)
Taapas Agrawal <taapas2897@gmail.com>
parents: 42577
diff changeset
3838 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
3839 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
3840 return state
b8d54f4625cb merge: disallow merge abort in case of an unfinished operation (issue6160)
Taapas Agrawal <taapas2897@gmail.com>
parents: 42577
diff changeset
3841 return None
b8d54f4625cb merge: disallow merge abort in case of an unfinished operation (issue6160)
Taapas Agrawal <taapas2897@gmail.com>
parents: 42577
diff changeset
3842
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3843
28120
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3844 def howtocontinue(repo):
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3845 '''Check for an unfinished operation and return the command to finish
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3846 it.
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3847
42577
ceb31d96d3ae statecheck: updated docstrings related to afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42568
diff changeset
3848 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
3849 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
3850 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
3851
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3852 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
3853 a boolean.
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3854 '''
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3855 contmsg = _(b"continue: %s")
42540
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42539
diff changeset
3856 for state in statemod._unfinishedstates:
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42539
diff changeset
3857 if not state._continueflag:
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42539
diff changeset
3858 continue
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42539
diff changeset
3859 if state.isunfinished(repo):
0231032729c4 statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42539
diff changeset
3860 return contmsg % state.continuemsg(), True
33362
e48fb90f80c8 cmdutil: simplify the dirty check in howtocontinue()
Matt Harbison <matt_harbison@yahoo.com>
parents: 33334
diff changeset
3861 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
3862 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
3863 return None, None
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3864
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3865
28120
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3866 def checkafterresolved(repo):
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3867 '''Inform the user about the next action after completing hg resolve
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3868
42577
ceb31d96d3ae statecheck: updated docstrings related to afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents: 42568
diff changeset
3869 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
3870 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
3871
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3872 Otherwise, it will yield repo.ui.note.
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3873 '''
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3874 msg, warning = howtocontinue(repo)
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3875 if msg is not None:
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3876 if warning:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3877 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
3878 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3879 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
3880
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3881
28120
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3882 def wrongtooltocontinue(repo, task):
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3883 '''Raise an abort suggesting how to properly continue if there is an
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3884 active task.
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3885
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3886 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
3887
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3888 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
3889 a hint.
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3890 '''
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3891 after = howtocontinue(repo)
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3892 hint = None
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3893 if after[1]:
ed4d06f180b8 cmdutil: provide a way to report how to continue
timeless <timeless@mozdev.org>
parents: 28027
diff changeset
3894 hint = after[0]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3895 raise error.Abort(_(b'no %s in progress') % task, hint=hint)
42568
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3896
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3897
42568
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3898 def abortgraft(ui, repo, graftstate):
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3899 """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: 42540
diff changeset
3900 graft"""
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3901 if not graftstate.exists():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3902 raise error.Abort(_(b"no interrupted graft to abort"))
42568
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3903 statedata = readgraftstate(repo, graftstate)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3904 newnodes = statedata.get(b'newnodes')
42568
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3905 if newnodes is None:
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3906 # 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: 42540
diff changeset
3907 # the graft
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3908 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: 42540
diff changeset
3909
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3910 # changeset from which graft operation was started
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3911 if len(newnodes) > 0:
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3912 startctx = repo[newnodes[0]].p1()
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3913 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3914 startctx = repo[b'.']
42568
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3915 # whether to strip or not
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3916 cleanup = False
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3917 from . import hg
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3918
42568
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3919 if newnodes:
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3920 newnodes = [repo[r].rev() for r in newnodes]
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3921 cleanup = True
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3922 # 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: 42540
diff changeset
3923 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: 42540
diff changeset
3924 if immutable:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3925 repo.ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3926 _(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
3927 % 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
3928 hint=_(b"see 'hg help phases' for details"),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3929 )
42568
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3930 cleanup = False
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3931
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3932 # 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: 42540
diff changeset
3933 desc = set(repo.changelog.descendants(newnodes))
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3934 if desc - set(newnodes):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3935 repo.ui.warn(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3936 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3937 b"new changesets detected on destination "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3938 b"branch, can't strip\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3939 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3940 )
42568
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3941 cleanup = False
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3942
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3943 if cleanup:
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3944 with repo.wlock(), repo.lock():
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3945 hg.updaterepo(repo, startctx.node(), overwrite=True)
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3946 # stripping the new nodes created
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3947 strippoints = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3948 c.node() for c in repo.set(b"roots(%ld)", newnodes)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3949 ]
42568
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3950 repair.strip(repo.ui, repo, strippoints, backup=False)
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3951
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3952 if not cleanup:
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3953 # 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
3954 startctx = repo[b'.']
42568
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3955 hg.updaterepo(repo, startctx.node(), overwrite=True)
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3956
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3957 ui.status(_(b"graft aborted\n"))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3958 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: 42540
diff changeset
3959 graftstate.delete()
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3960 return 0
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3961
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3962
42568
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3963 def readgraftstate(repo, graftstate):
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3964 """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: 42540
diff changeset
3965 try:
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3966 return graftstate.read()
f9da9d5f3f5a graft: moved abortgraft and readgraft to cmdutil
Taapas Agrawal <taapas2897@gmail.com>
parents: 42540
diff changeset
3967 except error.CorruptedState:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3968 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
3969 return {b'nodes': nodes}
42582
5171937ad0f9 abort: added support for graft
Taapas Agrawal <taapas2897@gmail.com>
parents: 42579
diff changeset
3970
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42937
diff changeset
3971
42582
5171937ad0f9 abort: added support for graft
Taapas Agrawal <taapas2897@gmail.com>
parents: 42579
diff changeset
3972 def hgabortgraft(ui, repo):
5171937ad0f9 abort: added support for graft
Taapas Agrawal <taapas2897@gmail.com>
parents: 42579
diff changeset
3973 """ abort logic for aborting graft using 'hg abort'"""
5171937ad0f9 abort: added support for graft
Taapas Agrawal <taapas2897@gmail.com>
parents: 42579
diff changeset
3974 with repo.wlock():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
3975 graftstate = statemod.cmdstate(repo, b'graftstate')
42582
5171937ad0f9 abort: added support for graft
Taapas Agrawal <taapas2897@gmail.com>
parents: 42579
diff changeset
3976 return abortgraft(ui, repo, graftstate)