Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/logcmdutil.py @ 53040:cdd7bf612c7b stable tip
bundle-spec: properly format boolean parameter (issue6960)
This was breaking automatic clone bundle generation. This changeset fixes it and
add a test to catch it in the future.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 11 Mar 2025 02:29:42 +0100 |
parents | 5c48fd4c0e68 |
children |
rev | line source |
---|---|
35925
7625b4f7db70
cmdutil: split functions of log-like commands to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35914
diff
changeset
|
1 # logcmdutil.py - utility for log-like commands |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
2 # |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Rapha?l Gom?s <rgomes@octobus.net>
parents:
46796
diff
changeset
|
3 # Copyright 2005-2007 Olivia Mackall <olivia@selenic.com> |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
4 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8210
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
diff
changeset
|
7 |
51901
f4733654f144
typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents:
51858
diff
changeset
|
8 from __future__ import annotations |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
9 |
31807
e6eb86b154c5
templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents:
31703
diff
changeset
|
10 import itertools |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
11 import os |
41657
d4c9eebdd72d
patch: replace "prefix" and "relroot" arguments by "pathfn" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41641
diff
changeset
|
12 import posixpath |
51788
278af66e6595
typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents:
51307
diff
changeset
|
13 import typing |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
14 |
51302
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51185
diff
changeset
|
15 from typing import ( |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51185
diff
changeset
|
16 Any, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51185
diff
changeset
|
17 Callable, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51185
diff
changeset
|
18 Dict, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51185
diff
changeset
|
19 Optional, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51185
diff
changeset
|
20 Sequence, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51185
diff
changeset
|
21 Tuple, |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51185
diff
changeset
|
22 ) |
9d3721552b6c
pytype: import typing directly
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51185
diff
changeset
|
23 |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
24 from .i18n import _ |
52755
5c48fd4c0e68
typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52669
diff
changeset
|
25 from .interfaces.types import ( |
5c48fd4c0e68
typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52669
diff
changeset
|
26 MatcherT, |
5c48fd4c0e68
typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52669
diff
changeset
|
27 ) |
51185
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
51184
diff
changeset
|
28 from .node import wdirrev |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
29 |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
30 from .thirdparty import attr |
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
31 |
51788
278af66e6595
typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents:
51307
diff
changeset
|
32 # Force pytype to use the non-vendored package |
278af66e6595
typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents:
51307
diff
changeset
|
33 if typing.TYPE_CHECKING: |
278af66e6595
typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents:
51307
diff
changeset
|
34 # noinspection PyPackageRequirements |
278af66e6595
typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents:
51307
diff
changeset
|
35 import attr |
278af66e6595
typing: induce pytype to use the standard `attr` instead of the vendored copy
Matt Harbison <matt_harbison@yahoo.com>
parents:
51307
diff
changeset
|
36 |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
37 from . import ( |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
38 dagop, |
51185
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
51184
diff
changeset
|
39 diffutil, |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
40 error, |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
41 formatter, |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
42 graphmod, |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
43 match as matchmod, |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
44 mdiff, |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
45 patch, |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
46 pathutil, |
30528
20a42325fdef
py3: use pycompat.getcwd() instead of os.getcwd()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30515
diff
changeset
|
47 pycompat, |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
48 revset, |
35644
7a0a90d63a8c
log: use revsetlang.formatspec() to concatenate list expression
Yuya Nishihara <yuya@tcha.org>
parents:
35643
diff
changeset
|
49 revsetlang, |
28322
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
50 scmutil, |
31043
aea06029919e
revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents:
30909
diff
changeset
|
51 smartset, |
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, |
ebd0e86bdf89
cmdutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28313
diff
changeset
|
55 ) |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37075
diff
changeset
|
56 from .utils import ( |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37075
diff
changeset
|
57 dateutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37075
diff
changeset
|
58 stringutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37075
diff
changeset
|
59 ) |
21405
dcf20f244c2a
cmdutil: introduce "getcommiteditor()" to simplify code paths to choose editor
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21241
diff
changeset
|
60 |
43741
c9301ac73b95
logcmdutil: add a type annotation
Augie Fackler <augie@google.com>
parents:
43692
diff
changeset
|
61 |
35927
572f36e9a780
logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35926
diff
changeset
|
62 def getlimit(opts): |
6190
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
63 """get the log limit according to option -l/--limit""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
64 limit = opts.get(b'limit') |
6190
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
65 if limit: |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
66 try: |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
67 limit = int(limit) |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
68 except ValueError: |
48580
91017508a785
logcmdutil: raise `InputError` on bad CLI arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
48130
diff
changeset
|
69 raise error.InputError(_(b'limit must be a positive integer')) |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10264
diff
changeset
|
70 if limit <= 0: |
48580
91017508a785
logcmdutil: raise `InputError` on bad CLI arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
48130
diff
changeset
|
71 raise error.InputError(_(b'limit must be positive')) |
6190
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
72 else: |
10111
27457d31ae3f
cmdutil: replace sys.maxint with None as default value in loglimit
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10061
diff
changeset
|
73 limit = None |
6190
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
74 return limit |
a79d9408806f
Move finding/checking the log limit to cmdutil
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6145
diff
changeset
|
75 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
76 |
51184
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
77 def get_diff_chunks( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
78 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
79 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
80 diffopts, |
44889
3b7aabd02e11
cleanup: avoid extra node/ctx conversions in logcmdutil.diffordiffstat
Augie Fackler <augie@google.com>
parents:
44379
diff
changeset
|
81 ctx1, |
3b7aabd02e11
cleanup: avoid extra node/ctx conversions in logcmdutil.diffordiffstat
Augie Fackler <augie@google.com>
parents:
44379
diff
changeset
|
82 ctx2, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
83 match, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
84 changes=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
85 stat=False, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
86 prefix=b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
87 root=b'', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
88 hunksfilterfn=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
89 ): |
24455
16961d43dc89
diff: rename --relative option to --root
Sean Farley <sean@farley.io>
parents:
24451
diff
changeset
|
90 if root: |
16961d43dc89
diff: rename --relative option to --root
Sean Farley <sean@farley.io>
parents:
24451
diff
changeset
|
91 relroot = pathutil.canonpath(repo.root, repo.getcwd(), root) |
24431
a0004402776b
cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents:
24422
diff
changeset
|
92 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
93 relroot = b'' |
41631
74f53d3bd685
patch: accept second matcher that applies only to copy sources (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41630
diff
changeset
|
94 copysourcematch = None |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
95 |
41658
ec37db02fc72
diff: make `hg diff --root=subrepo` work
Martin von Zweigbergk <martinvonz@google.com>
parents:
41657
diff
changeset
|
96 def compose(f, g): |
ec37db02fc72
diff: make `hg diff --root=subrepo` work
Martin von Zweigbergk <martinvonz@google.com>
parents:
41657
diff
changeset
|
97 return lambda x: f(g(x)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
98 |
41657
d4c9eebdd72d
patch: replace "prefix" and "relroot" arguments by "pathfn" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41641
diff
changeset
|
99 def pathfn(f): |
d4c9eebdd72d
patch: replace "prefix" and "relroot" arguments by "pathfn" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41641
diff
changeset
|
100 return posixpath.join(prefix, f) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
101 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
102 if relroot != b'': |
24431
a0004402776b
cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents:
24422
diff
changeset
|
103 # XXX relative roots currently don't work if the root is within a |
a0004402776b
cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents:
24422
diff
changeset
|
104 # subrepo |
41666
df59b1078983
diff: respect ui.relative-paths for warning about path outside --root
Martin von Zweigbergk <martinvonz@google.com>
parents:
41658
diff
changeset
|
105 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) |
df59b1078983
diff: respect ui.relative-paths for warning about path outside --root
Martin von Zweigbergk <martinvonz@google.com>
parents:
41658
diff
changeset
|
106 uirelroot = uipathfn(pathfn(relroot)) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
107 relroot += b'/' |
24431
a0004402776b
cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents:
24422
diff
changeset
|
108 for matchroot in match.files(): |
a0004402776b
cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents:
24422
diff
changeset
|
109 if not matchroot.startswith(relroot): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
110 ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
111 _(b'warning: %s not inside relative root %s\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
112 % (uipathfn(pathfn(matchroot)), uirelroot) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
113 ) |
24431
a0004402776b
cmdutil.diffordiffstat: add support for diffs relative to a subdirectory
Siddharth Agarwal <sid0@fb.com>
parents:
24422
diff
changeset
|
114 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
115 relrootmatch = scmutil.match(ctx2, pats=[relroot], default=b'path') |
41630
035cae1d197f
patch: let caller pass in root-filtering matcher (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41623
diff
changeset
|
116 match = matchmod.intersectmatchers(match, relrootmatch) |
41631
74f53d3bd685
patch: accept second matcher that applies only to copy sources (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41630
diff
changeset
|
117 copysourcematch = relrootmatch |
41630
035cae1d197f
patch: let caller pass in root-filtering matcher (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41623
diff
changeset
|
118 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
119 checkroot = repo.ui.configbool( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
120 b'devel', b'all-warnings' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
121 ) or repo.ui.configbool(b'devel', b'check-relroot') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
122 |
41658
ec37db02fc72
diff: make `hg diff --root=subrepo` work
Martin von Zweigbergk <martinvonz@google.com>
parents:
41657
diff
changeset
|
123 def relrootpathfn(f): |
41657
d4c9eebdd72d
patch: replace "prefix" and "relroot" arguments by "pathfn" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41641
diff
changeset
|
124 if checkroot and not f.startswith(relroot): |
d4c9eebdd72d
patch: replace "prefix" and "relroot" arguments by "pathfn" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41641
diff
changeset
|
125 raise AssertionError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
126 b"file %s doesn't start with relroot %s" % (f, relroot) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
127 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
128 return f[len(relroot) :] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
129 |
41658
ec37db02fc72
diff: make `hg diff --root=subrepo` work
Martin von Zweigbergk <martinvonz@google.com>
parents:
41657
diff
changeset
|
130 pathfn = compose(relrootpathfn, pathfn) |
41657
d4c9eebdd72d
patch: replace "prefix" and "relroot" arguments by "pathfn" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41641
diff
changeset
|
131 |
11050
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
132 if stat: |
35007
058c725925e3
diff: disable diff.noprefix option for diffstat (issue5759)
Yuya Nishihara <yuya@tcha.org>
parents:
34978
diff
changeset
|
133 diffopts = diffopts.copy(context=0, noprefix=False) |
41681
db69a763bc89
diff: make --stat respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41666
diff
changeset
|
134 # If an explicit --root was given, don't respect ui.relative-paths |
db69a763bc89
diff: make --stat respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41666
diff
changeset
|
135 if not relroot: |
db69a763bc89
diff: make --stat respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41666
diff
changeset
|
136 pathfn = compose(scmutil.getuipathfn(repo), pathfn) |
36000
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35994
diff
changeset
|
137 |
51184
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
138 return ctx2.diff( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
139 ctx1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
140 match, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
141 changes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
142 opts=diffopts, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
143 pathfn=pathfn, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
144 copysourcematch=copysourcematch, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
145 hunksfilterfn=hunksfilterfn, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
146 ) |
36000
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35994
diff
changeset
|
147 |
51184
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
148 |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
149 def diffordiffstat( |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
150 ui, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
151 repo, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
152 diffopts, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
153 ctx1, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
154 ctx2, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
155 match, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
156 changes=None, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
157 stat=False, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
158 fp=None, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
159 graphwidth=0, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
160 prefix=b'', |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
161 root=b'', |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
162 listsubrepos=False, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
163 hunksfilterfn=None, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
164 ): |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
165 '''show diff or diffstat.''' |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
166 |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
167 chunks = get_diff_chunks( |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
168 ui, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
169 repo, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
170 diffopts, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
171 ctx1, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
172 ctx2, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
173 match, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
174 changes=changes, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
175 stat=stat, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
176 prefix=prefix, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
177 root=root, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
178 hunksfilterfn=hunksfilterfn, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
179 ) |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
180 |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
181 if stat: |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
182 diffopts = diffopts.copy(context=0, noprefix=False) |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
183 width = 80 |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
184 if not ui.plain(): |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
185 width = ui.termwidth() - graphwidth |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
186 |
36000
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35994
diff
changeset
|
187 if fp is not None or ui.canwritewithoutlabels(): |
36046
006ff7268c5c
diff: remove fp.write() wrapper which drops label argument
Yuya Nishihara <yuya@tcha.org>
parents:
36045
diff
changeset
|
188 out = fp or ui |
36000
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35994
diff
changeset
|
189 if stat: |
36153
c1104fe76e69
py3: preserve chunks as an iterable of bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36046
diff
changeset
|
190 chunks = [patch.diffstat(util.iterlines(chunks), width=width)] |
36000
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35994
diff
changeset
|
191 for chunk in util.filechunkiter(util.chunkbuffer(chunks)): |
36046
006ff7268c5c
diff: remove fp.write() wrapper which drops label argument
Yuya Nishihara <yuya@tcha.org>
parents:
36045
diff
changeset
|
192 out.write(chunk) |
11050
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
193 else: |
36000
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35994
diff
changeset
|
194 if stat: |
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35994
diff
changeset
|
195 chunks = patch.diffstatui(util.iterlines(chunks), width=width) |
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35994
diff
changeset
|
196 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
197 chunks = patch.difflabel( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
198 lambda chunks, **kwargs: chunks, chunks, opts=diffopts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
199 ) |
36000
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35994
diff
changeset
|
200 if ui.canbatchlabeledwrites(): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
201 |
36000
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35994
diff
changeset
|
202 def gen(): |
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35994
diff
changeset
|
203 for chunk, label in chunks: |
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35994
diff
changeset
|
204 yield ui.label(chunk, label=label) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
205 |
36000
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35994
diff
changeset
|
206 for chunk in util.filechunkiter(util.chunkbuffer(gen())): |
36046
006ff7268c5c
diff: remove fp.write() wrapper which drops label argument
Yuya Nishihara <yuya@tcha.org>
parents:
36045
diff
changeset
|
207 ui.write(chunk) |
36000
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35994
diff
changeset
|
208 else: |
0ff41ced4c12
diff: improve ui.write performance when not coloring on Windows
Joerg Sonnenberger <joerg@bec.de>
parents:
35994
diff
changeset
|
209 for chunk, label in chunks: |
36046
006ff7268c5c
diff: remove fp.write() wrapper which drops label argument
Yuya Nishihara <yuya@tcha.org>
parents:
36045
diff
changeset
|
210 ui.write(chunk, label=label) |
11050
5d35f7d93514
commands: refactor diff --stat and qdiff --stat
Yuya Nishihara <yuya@tcha.org>
parents:
11017
diff
changeset
|
211 |
44889
3b7aabd02e11
cleanup: avoid extra node/ctx conversions in logcmdutil.diffordiffstat
Augie Fackler <augie@google.com>
parents:
44379
diff
changeset
|
212 node2 = ctx2.node() |
42010
db26dbbee74d
diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
41996
diff
changeset
|
213 for subpath, sub in scmutil.itersubrepos(ctx1, ctx2): |
db26dbbee74d
diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
41996
diff
changeset
|
214 tempnode2 = node2 |
db26dbbee74d
diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
41996
diff
changeset
|
215 try: |
db26dbbee74d
diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
41996
diff
changeset
|
216 if node2 is not None: |
db26dbbee74d
diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
41996
diff
changeset
|
217 tempnode2 = ctx2.substate[subpath][1] |
db26dbbee74d
diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
41996
diff
changeset
|
218 except KeyError: |
db26dbbee74d
diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
41996
diff
changeset
|
219 # A subrepo that existed in node1 was deleted between node1 and |
db26dbbee74d
diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
41996
diff
changeset
|
220 # node2 (inclusive). Thus, ctx2's substate won't contain that |
db26dbbee74d
diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
41996
diff
changeset
|
221 # subpath. The best we can do is to ignore it. |
db26dbbee74d
diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
41996
diff
changeset
|
222 tempnode2 = None |
db26dbbee74d
diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
41996
diff
changeset
|
223 submatch = matchmod.subdirmatcher(subpath, match) |
db26dbbee74d
diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
41996
diff
changeset
|
224 subprefix = repo.wvfs.reljoin(prefix, subpath) |
db26dbbee74d
diff: support diffing explicit files in subrepos
Matt Harbison <matt_harbison@yahoo.com>
parents:
41996
diff
changeset
|
225 if listsubrepos or match.exact(subpath) or any(submatch.files()): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
226 sub.diff( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
227 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
228 diffopts, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
229 tempnode2, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
230 submatch, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
231 changes=changes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
232 stat=stat, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
233 fp=fp, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
234 prefix=subprefix, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
235 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
236 |
12167
d2c5b0927c28
diff: recurse into subrepositories with --subrepos/-S flag
Martin Geisler <mg@lazybytes.net>
parents:
12164
diff
changeset
|
237 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49004
diff
changeset
|
238 class changesetdiffer: |
36045
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
239 """Generate diff of changeset with pre-configured filtering functions""" |
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
240 |
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
241 def _makefilematcher(self, ctx): |
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
242 return scmutil.matchall(ctx.repo()) |
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
243 |
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
244 def _makehunksfilter(self, ctx): |
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
245 return None |
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
246 |
41100
6a63ba61e71f
log: fix line wrap on diffstat with -G/--graph (issue5800)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
40285
diff
changeset
|
247 def showdiff(self, ui, ctx, diffopts, graphwidth=0, stat=False): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
248 diffordiffstat( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
249 ui, |
44889
3b7aabd02e11
cleanup: avoid extra node/ctx conversions in logcmdutil.diffordiffstat
Augie Fackler <augie@google.com>
parents:
44379
diff
changeset
|
250 ctx.repo(), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
251 diffopts, |
51185
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
51184
diff
changeset
|
252 diffutil.diff_parent(ctx), |
44889
3b7aabd02e11
cleanup: avoid extra node/ctx conversions in logcmdutil.diffordiffstat
Augie Fackler <augie@google.com>
parents:
44379
diff
changeset
|
253 ctx, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
254 match=self._makefilematcher(ctx), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
255 stat=stat, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
256 graphwidth=graphwidth, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
257 hunksfilterfn=self._makehunksfilter(ctx), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
258 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
259 |
51184
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
260 def getdiffstats(self, ui, ctx, diffopts, stat=False): |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
261 chunks = get_diff_chunks( |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
262 ui, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
263 ctx.repo(), |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
264 diffopts, |
51185
d6e5bec550f1
util: move diff_parent from logcmdutil to diffutil
pacien <pacien.trangirard@pacien.net>
parents:
51184
diff
changeset
|
265 diffutil.diff_parent(ctx), |
51184
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
266 ctx, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
267 match=self._makefilematcher(ctx), |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
268 stat=stat, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
269 hunksfilterfn=self._makehunksfilter(ctx), |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
270 ) |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
271 |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
272 diffdata = [] |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
273 for filename, additions, removals, binary in patch.diffstatdata( |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
274 util.iterlines(chunks) |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
275 ): |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
276 diffdata.append( |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
277 { |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
278 b"name": filename, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
279 b"additions": additions, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
280 b"removals": removals, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
281 b"binary": binary, |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
282 } |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
283 ) |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
284 |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
285 return diffdata |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
286 |
36045
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
287 |
35926
b0014780c7fc
logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35925
diff
changeset
|
288 def changesetlabels(ctx): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
289 labels = [b'log.changeset', b'changeset.%s' % ctx.phasestr()] |
31703
9b3577796291
cmdutil: add a "changeset.obsolete" label in changeset_printer
Denis Laxalde <denis@laxalde.org>
parents:
31493
diff
changeset
|
290 if ctx.obsolete(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
291 labels.append(b'changeset.obsolete') |
33756
52c5ff856b49
context: rename troubled into isunstable
Boris Feld <boris.feld@octobus.net>
parents:
33752
diff
changeset
|
292 if ctx.isunstable(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
293 labels.append(b'changeset.unstable') |
33752
ab0c55c2ad9a
context: rename troubles into instabilities
Boris Feld <boris.feld@octobus.net>
parents:
33720
diff
changeset
|
294 for instability in ctx.instabilities(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
295 labels.append(b'instability.%s' % instability) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
296 return b' '.join(labels) |
30694
5289fd78017a
cmdutil: extract a _changesetlabels function out of changeset_printer._show()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30620
diff
changeset
|
297 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
298 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49004
diff
changeset
|
299 class changesetprinter: |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
300 '''show changeset information when templating not requested.''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
301 |
36045
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
302 def __init__(self, ui, repo, differ=None, diffopts=None, buffered=False): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
303 self.ui = ui |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
304 self.repo = repo |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
305 self.buffered = buffered |
36045
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
306 self._differ = differ or changesetdiffer() |
37885
e0f30c91dfd8
log: cache diffopts instance
Yuya Nishihara <yuya@tcha.org>
parents:
37773
diff
changeset
|
307 self._diffopts = patch.diffallopts(ui, diffopts) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
308 self._includestat = diffopts and diffopts.get(b'stat') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
309 self._includediff = diffopts and diffopts.get(b'patch') |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
310 self.header = {} |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
311 self.hunk = {} |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
312 self.lastheader = None |
10152
56284451a22c
Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents:
10111
diff
changeset
|
313 self.footer = None |
35222
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35221
diff
changeset
|
314 self._columns = templatekw.getlogcolumns() |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
315 |
25763
60c791592aa7
changeset_printer: change flush() to accept ctx instead of rev
Yuya Nishihara <yuya@tcha.org>
parents:
25762
diff
changeset
|
316 def flush(self, ctx): |
60c791592aa7
changeset_printer: change flush() to accept ctx instead of rev
Yuya Nishihara <yuya@tcha.org>
parents:
25762
diff
changeset
|
317 rev = ctx.rev() |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
318 if rev in self.header: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
319 h = self.header[rev] |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
320 if h != self.lastheader: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
321 self.lastheader = h |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
322 self.ui.write(h) |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
323 del self.header[rev] |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
324 if rev in self.hunk: |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
325 self.ui.write(self.hunk[rev]) |
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
326 del self.hunk[rev] |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
327 |
10152
56284451a22c
Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents:
10111
diff
changeset
|
328 def close(self): |
56284451a22c
Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents:
10111
diff
changeset
|
329 if self.footer: |
56284451a22c
Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents:
10111
diff
changeset
|
330 self.ui.write(self.footer) |
56284451a22c
Added support for templatevar "footer" to cmdutil.py
Robert Bachmann <rbachm@gmail.com>
parents:
10111
diff
changeset
|
331 |
36041
fcde8946c553
logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36040
diff
changeset
|
332 def show(self, ctx, copies=None, **props): |
33112
05906b8e1d23
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33057
diff
changeset
|
333 props = pycompat.byteskwargs(props) |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
334 if self.buffered: |
27107
c57ebef70f6f
cmdutil: pass labeled=True to pushbuffer()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27065
diff
changeset
|
335 self.ui.pushbuffer(labeled=True) |
36041
fcde8946c553
logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36040
diff
changeset
|
336 self._show(ctx, copies, props) |
27109
a93d53f79e6e
ui: remove labeled argument from popbuffer
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27107
diff
changeset
|
337 self.hunk[ctx.rev()] = self.ui.popbuffer() |
3738
cb48cd27d3f4
use ui buffering in changeset printer
Matt Mackall <mpm@selenic.com>
parents:
3718
diff
changeset
|
338 else: |
36041
fcde8946c553
logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36040
diff
changeset
|
339 self._show(ctx, copies, props) |
34856
890afefa7296
diff: pass a diff hunks filter function from changeset_printer to patch.diff()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34852
diff
changeset
|
340 |
36041
fcde8946c553
logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36040
diff
changeset
|
341 def _show(self, ctx, copies, props): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
342 '''show a single changeset or file revision''' |
7369
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7361
diff
changeset
|
343 changenode = ctx.node() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
344 graphwidth = props.get(b'graphwidth', 0) |
24584
5a40b5d45396
changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents:
24583
diff
changeset
|
345 |
5a40b5d45396
changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents:
24583
diff
changeset
|
346 if self.ui.quiet: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
347 self.ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
348 b"%s\n" % scmutil.formatchangeid(ctx), label=b'log.node' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
349 ) |
24584
5a40b5d45396
changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents:
24583
diff
changeset
|
350 return |
5a40b5d45396
changeset_printer: display p1rev:p1node with "+" suffix for workingctx
Yuya Nishihara <yuya@tcha.org>
parents:
24583
diff
changeset
|
351 |
35222
c7b45db8f317
log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents:
35221
diff
changeset
|
352 columns = self._columns |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
353 self.ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
354 columns[b'changeset'] % scmutil.formatchangeid(ctx), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
355 label=changesetlabels(ctx), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
356 ) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
357 |
23772
07309e527df7
log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents:
23735
diff
changeset
|
358 # branches are shown first before any other names due to backwards |
07309e527df7
log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents:
23735
diff
changeset
|
359 # compatibility |
9637
64425c5a9257
cmdutil: minor refactoring of changeset_printer._show
Adrian Buehlmann <adrian@cadifra.com>
parents:
9547
diff
changeset
|
360 branch = ctx.branch() |
4176
f9bbcebcacea
"default" is the default branch name
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
4055
diff
changeset
|
361 # don't show the default branch name |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
362 if branch != b'default': |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
363 self.ui.write(columns[b'branch'] % branch, label=b'log.branch') |
23772
07309e527df7
log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents:
23735
diff
changeset
|
364 |
49004
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48966
diff
changeset
|
365 for nsname, ns in self.repo.names.items(): |
23772
07309e527df7
log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents:
23735
diff
changeset
|
366 # branches has special logic already handled above, so here we just |
07309e527df7
log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents:
23735
diff
changeset
|
367 # skip it |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
368 if nsname == b'branches': |
23772
07309e527df7
log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents:
23735
diff
changeset
|
369 continue |
07309e527df7
log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents:
23735
diff
changeset
|
370 # we will use the templatename as the color name since those two |
07309e527df7
log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents:
23735
diff
changeset
|
371 # should be the same |
07309e527df7
log: use new namespaces api to display names
Sean Farley <sean.michael.farley@gmail.com>
parents:
23735
diff
changeset
|
372 for name in ns.names(self.repo, changenode): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
373 self.ui.write(ns.logfmt % name, label=b'log.%s' % ns.colorname) |
22765
55dcc7fb731c
log: do not hide the public phase in debug mode (BC)
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
22764
diff
changeset
|
374 if self.ui.debugflag: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
375 self.ui.write( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
376 columns[b'phase'] % ctx.phasestr(), label=b'log.phase' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
377 ) |
26433
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26426
diff
changeset
|
378 for pctx in scmutil.meaningfulparents(self.repo, ctx): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
379 label = b'log.parent changeset.%s' % pctx.phasestr() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
380 self.ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
381 columns[b'parent'] % scmutil.formatchangeid(pctx), label=label |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
382 ) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
383 |
39812
94ca3579e84e
log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents:
39811
diff
changeset
|
384 if self.ui.debugflag: |
9547
f57640bf10d4
cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents:
9536
diff
changeset
|
385 mnode = ctx.manifestnode() |
39812
94ca3579e84e
log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents:
39811
diff
changeset
|
386 if mnode is None: |
47055
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46843
diff
changeset
|
387 mnode = self.repo.nodeconstants.wdirid |
39812
94ca3579e84e
log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents:
39811
diff
changeset
|
388 mrev = wdirrev |
94ca3579e84e
log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents:
39811
diff
changeset
|
389 else: |
94ca3579e84e
log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents:
39811
diff
changeset
|
390 mrev = self.repo.manifestlog.rev(mnode) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
391 self.ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
392 columns[b'manifest'] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
393 % scmutil.formatrevnode(self.ui, mrev, mnode), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
394 label=b'ui.debug log.manifest', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
395 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
396 self.ui.write(columns[b'user'] % ctx.user(), label=b'log.user') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
397 self.ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
398 columns[b'date'] % dateutil.datestr(ctx.date()), label=b'log.date' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
399 ) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
400 |
33756
52c5ff856b49
context: rename troubled into isunstable
Boris Feld <boris.feld@octobus.net>
parents:
33752
diff
changeset
|
401 if ctx.isunstable(): |
33752
ab0c55c2ad9a
context: rename troubles into instabilities
Boris Feld <boris.feld@octobus.net>
parents:
33720
diff
changeset
|
402 instabilities = ctx.instabilities() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
403 self.ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
404 columns[b'instability'] % b', '.join(instabilities), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
405 label=b'log.instability', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
406 ) |
30695
f05ede08dcf7
cmdutil: add support for evolution "troubles" display in changeset_printer
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
30694
diff
changeset
|
407 |
34852
d45236f3d38e
log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents:
34794
diff
changeset
|
408 elif ctx.obsolete(): |
d45236f3d38e
log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents:
34794
diff
changeset
|
409 self._showobsfate(ctx) |
d45236f3d38e
log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents:
34794
diff
changeset
|
410 |
33160
4ecc6047d45f
log: add an extension hook-point in changeset_printer
Boris Feld <boris.feld@octobus.net>
parents:
33114
diff
changeset
|
411 self._exthook(ctx) |
4ecc6047d45f
log: add an extension hook-point in changeset_printer
Boris Feld <boris.feld@octobus.net>
parents:
33114
diff
changeset
|
412 |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
413 if self.ui.debugflag: |
43692
4093fc1777c2
logcmdutil: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents:
43674
diff
changeset
|
414 for key, value in zip( |
4093fc1777c2
logcmdutil: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents:
43674
diff
changeset
|
415 [b'files', b'files+', b'files-'], |
48891
2f326ea19fbc
logcmdutil: use the same data as {file*} template keywords (issue6642)
Anton Shestakov <av6@dwimlabs.net>
parents:
48581
diff
changeset
|
416 [ctx.filesmodified(), ctx.filesadded(), ctx.filesremoved()], |
43692
4093fc1777c2
logcmdutil: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents:
43674
diff
changeset
|
417 ): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
418 if value: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
419 self.ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
420 columns[key] % b" ".join(value), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
421 label=b'ui.debug log.files', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
422 ) |
9547
f57640bf10d4
cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents:
9536
diff
changeset
|
423 elif ctx.files() and self.ui.verbose: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
424 self.ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
425 columns[b'files'] % b" ".join(ctx.files()), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
426 label=b'ui.note log.files', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
427 ) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
428 if copies and self.ui.verbose: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
429 copies = [b'%s (%s)' % c for c in copies] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
430 self.ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
431 columns[b'copies'] % b' '.join(copies), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
432 label=b'ui.note log.copies', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
433 ) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
434 |
9637
64425c5a9257
cmdutil: minor refactoring of changeset_printer._show
Adrian Buehlmann <adrian@cadifra.com>
parents:
9547
diff
changeset
|
435 extra = ctx.extra() |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
436 if extra and self.ui.debugflag: |
8209
a1a5a57efe90
replace util.sort with sorted built-in
Matt Mackall <mpm@selenic.com>
parents:
8189
diff
changeset
|
437 for key, value in sorted(extra.items()): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
438 self.ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
439 columns[b'extra'] % (key, stringutil.escapestr(value)), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
440 label=b'ui.debug log.extra', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
441 ) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
442 |
9547
f57640bf10d4
cmdutil: changeset_printer: use methods of filectx/changectx.
Greg Ward <greg-hg@gerg.ca>
parents:
9536
diff
changeset
|
443 description = ctx.description().strip() |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
444 if description: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
445 if self.ui.verbose: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
446 self.ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
447 _(b"description:\n"), label=b'ui.note log.description' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
448 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
449 self.ui.write(description, label=b'ui.note log.description') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
450 self.ui.write(b"\n\n") |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
451 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
452 self.ui.write( |
49094
eb8aed493a56
logcmdutil: use new function for getting first line of string
Martin von Zweigbergk <martinvonz@google.com>
parents:
49037
diff
changeset
|
453 columns[b'summary'] % stringutil.firstline(description), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
454 label=b'log.summary', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
455 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
456 self.ui.write(b"\n") |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
457 |
41100
6a63ba61e71f
log: fix line wrap on diffstat with -G/--graph (issue5800)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
40285
diff
changeset
|
458 self._showpatch(ctx, graphwidth) |
27065
93bcc73df8d5
cmdutil.changeset_printer: pass context into showpatch()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26938
diff
changeset
|
459 |
34852
d45236f3d38e
log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents:
34794
diff
changeset
|
460 def _showobsfate(self, ctx): |
36546
69477bac8926
log: do not invoke templatekw.showobsfate() as a function
Yuya Nishihara <yuya@tcha.org>
parents:
36542
diff
changeset
|
461 # TODO: do not depend on templater |
69477bac8926
log: do not invoke templatekw.showobsfate() as a function
Yuya Nishihara <yuya@tcha.org>
parents:
36542
diff
changeset
|
462 tres = formatter.templateresources(self.repo.ui, self.repo) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
463 t = formatter.maketemplater( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
464 self.repo.ui, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
465 b'{join(obsfate, "\n")}', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
466 defaults=templatekw.keywords, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
467 resources=tres, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
468 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
469 obsfate = t.renderdefault({b'ctx': ctx}).splitlines() |
34852
d45236f3d38e
log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents:
34794
diff
changeset
|
470 |
d45236f3d38e
log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents:
34794
diff
changeset
|
471 if obsfate: |
d45236f3d38e
log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents:
34794
diff
changeset
|
472 for obsfateline in obsfate: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
473 self.ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
474 self._columns[b'obsolete'] % obsfateline, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
475 label=b'log.obsfate', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
476 ) |
34852
d45236f3d38e
log: add obsfate by default in changeset printer
Boris Feld <boris.feld@octobus.net>
parents:
34794
diff
changeset
|
477 |
33160
4ecc6047d45f
log: add an extension hook-point in changeset_printer
Boris Feld <boris.feld@octobus.net>
parents:
33114
diff
changeset
|
478 def _exthook(self, ctx): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45915
diff
changeset
|
479 """empty method used by extension as a hook point""" |
33160
4ecc6047d45f
log: add an extension hook-point in changeset_printer
Boris Feld <boris.feld@octobus.net>
parents:
33114
diff
changeset
|
480 |
41100
6a63ba61e71f
log: fix line wrap on diffstat with -G/--graph (issue5800)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
40285
diff
changeset
|
481 def _showpatch(self, ctx, graphwidth=0): |
37886
3fe1c9263024
log: consume --stat/patch options at constructor of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents:
37885
diff
changeset
|
482 if self._includestat: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
483 self._differ.showdiff( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
484 self.ui, ctx, self._diffopts, graphwidth, stat=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
485 ) |
37886
3fe1c9263024
log: consume --stat/patch options at constructor of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents:
37885
diff
changeset
|
486 if self._includestat and self._includediff: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
487 self.ui.write(b"\n") |
37886
3fe1c9263024
log: consume --stat/patch options at constructor of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents:
37885
diff
changeset
|
488 if self._includediff: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
489 self._differ.showdiff( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
490 self.ui, ctx, self._diffopts, graphwidth, stat=False |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
491 ) |
37886
3fe1c9263024
log: consume --stat/patch options at constructor of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents:
37885
diff
changeset
|
492 if self._includestat or self._includediff: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
493 self.ui.write(b"\n") |
3645
b984dcb1df71
Refactor log ui buffering and patch display
Matt Mackall <mpm@selenic.com>
parents:
3643
diff
changeset
|
494 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
495 |
37773
0f084741cd66
logcmdutil: pass formatter to jsonchangeset as argument
Yuya Nishihara <yuya@tcha.org>
parents:
37772
diff
changeset
|
496 class changesetformatter(changesetprinter): |
0f084741cd66
logcmdutil: pass formatter to jsonchangeset as argument
Yuya Nishihara <yuya@tcha.org>
parents:
37772
diff
changeset
|
497 """Format changeset information by generic formatter""" |
22427
bd15932846a4
cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents:
22405
diff
changeset
|
498 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
499 def __init__( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
500 self, ui, repo, fm, differ=None, diffopts=None, buffered=False |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
501 ): |
36045
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
502 changesetprinter.__init__(self, ui, repo, differ, diffopts, buffered) |
37885
e0f30c91dfd8
log: cache diffopts instance
Yuya Nishihara <yuya@tcha.org>
parents:
37773
diff
changeset
|
503 self._diffopts = patch.difffeatureopts(ui, diffopts, git=True) |
37773
0f084741cd66
logcmdutil: pass formatter to jsonchangeset as argument
Yuya Nishihara <yuya@tcha.org>
parents:
37772
diff
changeset
|
504 self._fm = fm |
22427
bd15932846a4
cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents:
22405
diff
changeset
|
505 |
bd15932846a4
cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents:
22405
diff
changeset
|
506 def close(self): |
37772
814151cd8c4a
logcmdutil: rewrite jsonchangeset printer to be backed by jsonformatter
Yuya Nishihara <yuya@tcha.org>
parents:
37771
diff
changeset
|
507 self._fm.end() |
22427
bd15932846a4
cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents:
22405
diff
changeset
|
508 |
36041
fcde8946c553
logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36040
diff
changeset
|
509 def _show(self, ctx, copies, props): |
22427
bd15932846a4
cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents:
22405
diff
changeset
|
510 '''show a single changeset or file revision''' |
37772
814151cd8c4a
logcmdutil: rewrite jsonchangeset printer to be backed by jsonformatter
Yuya Nishihara <yuya@tcha.org>
parents:
37771
diff
changeset
|
511 fm = self._fm |
814151cd8c4a
logcmdutil: rewrite jsonchangeset printer to be backed by jsonformatter
Yuya Nishihara <yuya@tcha.org>
parents:
37771
diff
changeset
|
512 fm.startitem() |
39721
fa681452b249
log: make changesetformatter pass in changectx to formatter
Yuya Nishihara <yuya@tcha.org>
parents:
38571
diff
changeset
|
513 fm.context(ctx=ctx) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
514 fm.data(rev=scmutil.intrev(ctx), node=fm.hexfunc(scmutil.binnode(ctx))) |
22427
bd15932846a4
cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents:
22405
diff
changeset
|
515 |
43102
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
516 datahint = fm.datahint() |
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
517 if self.ui.quiet and not datahint: |
22427
bd15932846a4
cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents:
22405
diff
changeset
|
518 return |
bd15932846a4
cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents:
22405
diff
changeset
|
519 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
520 fm.data( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
521 branch=ctx.branch(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
522 phase=ctx.phasestr(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
523 user=ctx.user(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
524 date=fm.formatdate(ctx.date()), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
525 desc=ctx.description(), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
526 bookmarks=fm.formatlist(ctx.bookmarks(), name=b'bookmark'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
527 tags=fm.formatlist(ctx.tags(), name=b'tag'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
528 parents=fm.formatlist( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
529 [fm.hexfunc(c.node()) for c in ctx.parents()], name=b'node' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
530 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
531 ) |
22427
bd15932846a4
cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents:
22405
diff
changeset
|
532 |
43102
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
533 if self.ui.debugflag or b'manifest' in datahint: |
47055
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46843
diff
changeset
|
534 fm.data( |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46843
diff
changeset
|
535 manifest=fm.hexfunc( |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46843
diff
changeset
|
536 ctx.manifestnode() or self.repo.nodeconstants.wdirid |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46843
diff
changeset
|
537 ) |
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46843
diff
changeset
|
538 ) |
43102
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
539 if self.ui.debugflag or b'extra' in datahint: |
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
540 fm.data(extra=fm.formatdict(ctx.extra())) |
22427
bd15932846a4
cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents:
22405
diff
changeset
|
541 |
43102
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
542 if ( |
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
543 self.ui.debugflag |
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
544 or b'modified' in datahint |
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
545 or b'added' in datahint |
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
546 or b'removed' in datahint |
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
547 ): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
548 fm.data( |
48891
2f326ea19fbc
logcmdutil: use the same data as {file*} template keywords (issue6642)
Anton Shestakov <av6@dwimlabs.net>
parents:
48581
diff
changeset
|
549 modified=fm.formatlist(ctx.filesmodified(), name=b'file'), |
2f326ea19fbc
logcmdutil: use the same data as {file*} template keywords (issue6642)
Anton Shestakov <av6@dwimlabs.net>
parents:
48581
diff
changeset
|
550 added=fm.formatlist(ctx.filesadded(), name=b'file'), |
2f326ea19fbc
logcmdutil: use the same data as {file*} template keywords (issue6642)
Anton Shestakov <av6@dwimlabs.net>
parents:
48581
diff
changeset
|
551 removed=fm.formatlist(ctx.filesremoved(), name=b'file'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
552 ) |
22427
bd15932846a4
cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents:
22405
diff
changeset
|
553 |
43102
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
554 verbose = not self.ui.debugflag and self.ui.verbose |
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
555 if verbose or b'files' in datahint: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
556 fm.data(files=fm.formatlist(ctx.files(), name=b'file')) |
43102
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
557 if verbose and copies or b'copies' in datahint: |
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
558 fm.data( |
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
559 copies=fm.formatdict(copies or {}, key=b'name', value=b'source') |
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
560 ) |
22427
bd15932846a4
cmdutil: add json style to log-like commands
Matt Mackall <mpm@selenic.com>
parents:
22405
diff
changeset
|
561 |
43102
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
562 if self._includestat or b'diffstat' in datahint: |
51184
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
563 data = self._differ.getdiffstats( |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
564 self.ui, ctx, self._diffopts, stat=True |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
565 ) |
204af2aa4931
logcmdutil: return structured diffstat data for json
zegervdv <zeger@vandevan.net>
parents:
49586
diff
changeset
|
566 fm.data(diffstat=fm.formatlist(data, name=b'diffstat')) |
43102
829088e87032
log: populate keywords if specified in custom -Tjson(...) or -Tcbor(...)
Yuya Nishihara <yuya@tcha.org>
parents:
43100
diff
changeset
|
567 if self._includediff or b'diff' in datahint: |
36042
d4c210ee894f
logcmdutil: unindent diff generator of changesetprinter
Yuya Nishihara <yuya@tcha.org>
parents:
36041
diff
changeset
|
568 self.ui.pushbuffer() |
37885
e0f30c91dfd8
log: cache diffopts instance
Yuya Nishihara <yuya@tcha.org>
parents:
37773
diff
changeset
|
569 self._differ.showdiff(self.ui, ctx, self._diffopts, stat=False) |
37772
814151cd8c4a
logcmdutil: rewrite jsonchangeset printer to be backed by jsonformatter
Yuya Nishihara <yuya@tcha.org>
parents:
37771
diff
changeset
|
570 fm.data(diff=self.ui.popbuffer()) |
4825
3cf94964c56b
hg log: Move filtering implicit parents to own method and use it in templater.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
4824
diff
changeset
|
571 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
572 |
35926
b0014780c7fc
logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35925
diff
changeset
|
573 class changesettemplater(changesetprinter): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45915
diff
changeset
|
574 """format changeset information. |
35130
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
35048
diff
changeset
|
575 |
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
35048
diff
changeset
|
576 Note: there are a variety of convenience functions to build a |
35926
b0014780c7fc
logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35925
diff
changeset
|
577 changesettemplater for common cases. See functions such as: |
35927
572f36e9a780
logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35926
diff
changeset
|
578 maketemplater, changesetdisplayer, buildcommittemplate, or other |
35130
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
35048
diff
changeset
|
579 functions that use changesest_templater. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45915
diff
changeset
|
580 """ |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
581 |
51858
460e80488cf0
typing: lock in correct changes from pytype 2023.04.11 -> 2023.06.16
Matt Harbison <matt_harbison@yahoo.com>
parents:
51788
diff
changeset
|
582 _tresources: formatter.templateresources |
460e80488cf0
typing: lock in correct changes from pytype 2023.04.11 -> 2023.06.16
Matt Harbison <matt_harbison@yahoo.com>
parents:
51788
diff
changeset
|
583 lastheader: Optional[bytes] |
460e80488cf0
typing: lock in correct changes from pytype 2023.04.11 -> 2023.06.16
Matt Harbison <matt_harbison@yahoo.com>
parents:
51788
diff
changeset
|
584 t: templater.templater |
460e80488cf0
typing: lock in correct changes from pytype 2023.04.11 -> 2023.06.16
Matt Harbison <matt_harbison@yahoo.com>
parents:
51788
diff
changeset
|
585 |
33057
99c6c9fa9e6d
cmdutil: use named arguments for changeset_templater.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32971
diff
changeset
|
586 # Arguments before "buffered" used to be positional. Consider not |
99c6c9fa9e6d
cmdutil: use named arguments for changeset_templater.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32971
diff
changeset
|
587 # adding/removing arguments before "buffered" to not break callers. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
588 def __init__( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
589 self, ui, repo, tmplspec, differ=None, diffopts=None, buffered=False |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
590 ): |
36045
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
591 changesetprinter.__init__(self, ui, repo, differ, diffopts, buffered) |
37075
d64ae4fef471
log: do no expect templateresources() returning a dict
Yuya Nishihara <yuya@tcha.org>
parents:
36992
diff
changeset
|
592 # tres is shared with _graphnodeformatter() |
d64ae4fef471
log: do no expect templateresources() returning a dict
Yuya Nishihara <yuya@tcha.org>
parents:
36992
diff
changeset
|
593 self._tresources = tres = formatter.templateresources(ui, repo) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
594 self.t = formatter.loadtemplater( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
595 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
596 tmplspec, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
597 defaults=templatekw.keywords, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
598 resources=tres, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
599 cache=templatekw.defaulttempl, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
600 ) |
31807
e6eb86b154c5
templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents:
31703
diff
changeset
|
601 self._counter = itertools.count() |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
602 |
32860
97a4d09f5140
changeset_templater: render template specified by templatespec tuple
Yuya Nishihara <yuya@tcha.org>
parents:
32858
diff
changeset
|
603 self._tref = tmplspec.ref |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
604 self._parts = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
605 b'header': b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
606 b'footer': b'', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
607 tmplspec.ref: tmplspec.ref, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
608 b'docheader': b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
609 b'docfooter': b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
610 b'separator': b'', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
611 } |
32965
3f07f12c6e10
changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents:
32964
diff
changeset
|
612 if tmplspec.mapfile: |
3f07f12c6e10
changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents:
32964
diff
changeset
|
613 # find correct templates for current mode, for backward |
3f07f12c6e10
changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents:
32964
diff
changeset
|
614 # compatibility with 'log -v/-q/--debug' using a mapfile |
3f07f12c6e10
changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents:
32964
diff
changeset
|
615 tmplmodes = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
616 (True, b''), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
617 (self.ui.verbose, b'_verbose'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
618 (self.ui.quiet, b'_quiet'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
619 (self.ui.debugflag, b'_debug'), |
32965
3f07f12c6e10
changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents:
32964
diff
changeset
|
620 ] |
3f07f12c6e10
changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents:
32964
diff
changeset
|
621 for mode, postfix in tmplmodes: |
3f07f12c6e10
changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents:
32964
diff
changeset
|
622 for t in self._parts: |
3f07f12c6e10
changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents:
32964
diff
changeset
|
623 cur = t + postfix |
3f07f12c6e10
changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents:
32964
diff
changeset
|
624 if mode and cur in self.t: |
3f07f12c6e10
changeset_templater: do not enable verbosity postfix for [templates] section
Yuya Nishihara <yuya@tcha.org>
parents:
32964
diff
changeset
|
625 self._parts[t] = cur |
32971
6d79e9109908
changeset_templater: backport parts map of [templates] section from formatter
Yuya Nishihara <yuya@tcha.org>
parents:
32969
diff
changeset
|
626 else: |
6d79e9109908
changeset_templater: backport parts map of [templates] section from formatter
Yuya Nishihara <yuya@tcha.org>
parents:
32969
diff
changeset
|
627 partnames = [p for p in self._parts.keys() if p != tmplspec.ref] |
6d79e9109908
changeset_templater: backport parts map of [templates] section from formatter
Yuya Nishihara <yuya@tcha.org>
parents:
32969
diff
changeset
|
628 m = formatter.templatepartsmap(tmplspec, self.t, partnames) |
6d79e9109908
changeset_templater: backport parts map of [templates] section from formatter
Yuya Nishihara <yuya@tcha.org>
parents:
32969
diff
changeset
|
629 self._parts.update(m) |
26086
3670efdc7088
templater: move verbosity-to-template matcher to constructor
Matt Mackall <mpm@selenic.com>
parents:
26085
diff
changeset
|
630 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
631 if self._parts[b'docheader']: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
632 self.ui.write(self.t.render(self._parts[b'docheader'], {})) |
26222
3095b1027661
templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents:
26206
diff
changeset
|
633 |
3095b1027661
templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents:
26206
diff
changeset
|
634 def close(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
635 if self._parts[b'docfooter']: |
26222
3095b1027661
templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents:
26206
diff
changeset
|
636 if not self.footer: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
637 self.footer = b"" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
638 self.footer += self.t.render(self._parts[b'docfooter'], {}) |
52668
5cc8deb96b48
pyupgrade: modernize calls to superclass methods
Matt Harbison <matt_harbison@yahoo.com>
parents:
51901
diff
changeset
|
639 return super().close() |
26222
3095b1027661
templater: add new docheader/footer components for XML (issue4135)
Matt Mackall <mpm@selenic.com>
parents:
26206
diff
changeset
|
640 |
36041
fcde8946c553
logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36040
diff
changeset
|
641 def _show(self, ctx, copies, props): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
642 '''show a single changeset or file revision''' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
643 props = props.copy() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
644 props[b'ctx'] = ctx |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
645 props[b'index'] = index = next(self._counter) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
646 props[b'revcache'] = {b'copies': copies} |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
647 graphwidth = props.get(b'graphwidth', 0) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
648 |
32969
050efe9a1644
changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents:
32965
diff
changeset
|
649 # write separator, which wouldn't work well with the header part below |
050efe9a1644
changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents:
32965
diff
changeset
|
650 # since there's inherently a conflict between header (across items) and |
050efe9a1644
changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents:
32965
diff
changeset
|
651 # separator (per item) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
652 if self._parts[b'separator'] and index > 0: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
653 self.ui.write(self.t.render(self._parts[b'separator'], {})) |
32969
050efe9a1644
changeset_templater: backport separator template from formatter
Yuya Nishihara <yuya@tcha.org>
parents:
32965
diff
changeset
|
654 |
28837
d54a7410307f
templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
28815
diff
changeset
|
655 # write header |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
656 if self._parts[b'header']: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
657 h = self.t.render(self._parts[b'header'], props) |
28837
d54a7410307f
templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
28815
diff
changeset
|
658 if self.buffered: |
d54a7410307f
templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
28815
diff
changeset
|
659 self.header[ctx.rev()] = h |
d54a7410307f
templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
28815
diff
changeset
|
660 else: |
d54a7410307f
templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
28815
diff
changeset
|
661 if self.lastheader != h: |
d54a7410307f
templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
28815
diff
changeset
|
662 self.lastheader = h |
d54a7410307f
templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
28815
diff
changeset
|
663 self.ui.write(h) |
d54a7410307f
templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
28815
diff
changeset
|
664 |
d54a7410307f
templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
28815
diff
changeset
|
665 # write changeset metadata, then patch if requested |
32860
97a4d09f5140
changeset_templater: render template specified by templatespec tuple
Yuya Nishihara <yuya@tcha.org>
parents:
32858
diff
changeset
|
666 key = self._parts[self._tref] |
36992
de117f579431
templater: factor out helper that renders named template as string
Yuya Nishihara <yuya@tcha.org>
parents:
36991
diff
changeset
|
667 self.ui.write(self.t.render(key, props)) |
43848
6331a6fc3304
logcmdutil: call _exthook() in changesettemplater
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
43811
diff
changeset
|
668 self._exthook(ctx) |
41100
6a63ba61e71f
log: fix line wrap on diffstat with -G/--graph (issue5800)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
40285
diff
changeset
|
669 self._showpatch(ctx, graphwidth) |
28837
d54a7410307f
templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
28815
diff
changeset
|
670 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
671 if self._parts[b'footer']: |
28837
d54a7410307f
templater: drop deprecated handling of KeyError from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents:
28815
diff
changeset
|
672 if not self.footer: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
673 self.footer = self.t.render(self._parts[b'footer'], props) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
674 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
675 |
51858
460e80488cf0
typing: lock in correct changes from pytype 2023.04.11 -> 2023.06.16
Matt Harbison <matt_harbison@yahoo.com>
parents:
51788
diff
changeset
|
676 def templatespec(tmpl, mapfile) -> formatter.templatespec: |
45289
dfb67cd1da7f
templatespec: logcmdutil.templatespec() gets either template or mapfile
Martin von Zweigbergk <martinvonz@google.com>
parents:
44889
diff
changeset
|
677 assert not (tmpl and mapfile) |
32893
c8f2cf18b82e
formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents:
32891
diff
changeset
|
678 if mapfile: |
45289
dfb67cd1da7f
templatespec: logcmdutil.templatespec() gets either template or mapfile
Martin von Zweigbergk <martinvonz@google.com>
parents:
44889
diff
changeset
|
679 return formatter.mapfile_templatespec(b'changeset', mapfile) |
32893
c8f2cf18b82e
formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents:
32891
diff
changeset
|
680 else: |
45289
dfb67cd1da7f
templatespec: logcmdutil.templatespec() gets either template or mapfile
Martin von Zweigbergk <martinvonz@google.com>
parents:
44889
diff
changeset
|
681 return formatter.literal_templatespec(tmpl) |
32856
615ec3f14aa9
formatter: wrap (tmpl, mapfile) by named tuple
Yuya Nishihara <yuya@tcha.org>
parents:
32855
diff
changeset
|
682 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
683 |
51858
460e80488cf0
typing: lock in correct changes from pytype 2023.04.11 -> 2023.06.16
Matt Harbison <matt_harbison@yahoo.com>
parents:
51788
diff
changeset
|
684 def _lookuptemplate(ui, tmpl, style) -> formatter.templatespec: |
32853
9d76812f9b0b
formatter: document lookuptemplate()
Yuya Nishihara <yuya@tcha.org>
parents:
32852
diff
changeset
|
685 """Find the template matching the given template spec or style |
9d76812f9b0b
formatter: document lookuptemplate()
Yuya Nishihara <yuya@tcha.org>
parents:
32852
diff
changeset
|
686 |
9d76812f9b0b
formatter: document lookuptemplate()
Yuya Nishihara <yuya@tcha.org>
parents:
32852
diff
changeset
|
687 See formatter.lookuptemplate() for details. |
20666
e3eb480a9391
cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents:
20604
diff
changeset
|
688 """ |
e3eb480a9391
cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents:
20604
diff
changeset
|
689 |
e3eb480a9391
cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents:
20604
diff
changeset
|
690 # ui settings |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
691 if not tmpl and not style: # template are stronger than style |
45788
ed84a4d48910
config: add a new [command-templates] section for templates defined by hg
Martin von Zweigbergk <martinvonz@google.com>
parents:
45653
diff
changeset
|
692 tmpl = ui.config(b'command-templates', b'log') |
20666
e3eb480a9391
cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents:
20604
diff
changeset
|
693 if tmpl: |
45291
c1915cfa8080
templatespec: use new factory functions in logcmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45290
diff
changeset
|
694 return formatter.literal_templatespec(templater.unquotestring(tmpl)) |
20666
e3eb480a9391
cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents:
20604
diff
changeset
|
695 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
696 style = util.expandpath(ui.config(b'ui', b'style')) |
20666
e3eb480a9391
cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents:
20604
diff
changeset
|
697 |
22582
4fe5fa49eac8
templater: fix precedence of --style and --template options
Yuya Nishihara <yuya@tcha.org>
parents:
22303
diff
changeset
|
698 if not tmpl and style: |
20666
e3eb480a9391
cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents:
20604
diff
changeset
|
699 mapfile = style |
45331
f3481e4fcc3a
templater: pass opened file-like object to templatespec
Martin von Zweigbergk <martinvonz@google.com>
parents:
45330
diff
changeset
|
700 fp = None |
20666
e3eb480a9391
cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents:
20604
diff
changeset
|
701 if not os.path.split(mapfile)[0]: |
45341
4aa484efc926
templater: add exception-raising version of open_template()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45331
diff
changeset
|
702 (mapname, fp) = templater.try_open_template( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
703 b'map-cmdline.' + mapfile |
45341
4aa484efc926
templater: add exception-raising version of open_template()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45331
diff
changeset
|
704 ) or templater.try_open_template(mapfile) |
20666
e3eb480a9391
cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents:
20604
diff
changeset
|
705 if mapname: |
e3eb480a9391
cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents:
20604
diff
changeset
|
706 mapfile = mapname |
45331
f3481e4fcc3a
templater: pass opened file-like object to templatespec
Martin von Zweigbergk <martinvonz@google.com>
parents:
45330
diff
changeset
|
707 return formatter.mapfile_templatespec(b'changeset', mapfile, fp) |
20666
e3eb480a9391
cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents:
20604
diff
changeset
|
708 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
709 return formatter.lookuptemplate(ui, b'changeset', tmpl) |
20666
e3eb480a9391
cmdutil: make helper function to process template args
Matt Mackall <mpm@selenic.com>
parents:
20604
diff
changeset
|
710 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
711 |
35927
572f36e9a780
logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35926
diff
changeset
|
712 def maketemplater(ui, repo, tmpl, buffered=False): |
35926
b0014780c7fc
logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35925
diff
changeset
|
713 """Create a changesettemplater from a literal template 'tmpl' |
35130
b22a0d9e0a83
docs: add args/returns docs for some cmdutil, context, and registrar functions
rlevasseur@google.com
parents:
35048
diff
changeset
|
714 byte-string.""" |
45291
c1915cfa8080
templatespec: use new factory functions in logcmdutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
45290
diff
changeset
|
715 spec = formatter.literal_templatespec(tmpl) |
35926
b0014780c7fc
logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35925
diff
changeset
|
716 return changesettemplater(ui, repo, spec, buffered=buffered) |
32855
50586a0a946f
cmdutil: factor out helper to create changeset_templater with literal template
Yuya Nishihara <yuya@tcha.org>
parents:
32853
diff
changeset
|
717 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
718 |
36045
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
719 def changesetdisplayer(ui, repo, opts, differ=None, buffered=False): |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
720 """show one changeset using template or regular display. |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
721 |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
722 Display format will be the first non-empty hit of: |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
723 1. option 'template' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
724 2. option 'style' |
45788
ed84a4d48910
config: add a new [command-templates] section for templates defined by hg
Martin von Zweigbergk <martinvonz@google.com>
parents:
45653
diff
changeset
|
725 3. [command-templates] setting 'log' |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
726 4. [ui] setting 'style' |
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
727 If all of these values are either the unset or the empty string, |
35926
b0014780c7fc
logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35925
diff
changeset
|
728 regular display via changesetprinter() is done. |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
729 """ |
36045
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
730 postargs = (differ, opts, buffered) |
43100
90b9a7e06c2c
formatter: parse name of built-in formatter templates in standard way
Yuya Nishihara <yuya@tcha.org>
parents:
43077
diff
changeset
|
731 spec = _lookuptemplate(ui, opts.get(b'template'), opts.get(b'style')) |
90b9a7e06c2c
formatter: parse name of built-in formatter templates in standard way
Yuya Nishihara <yuya@tcha.org>
parents:
43077
diff
changeset
|
732 |
90b9a7e06c2c
formatter: parse name of built-in formatter templates in standard way
Yuya Nishihara <yuya@tcha.org>
parents:
43077
diff
changeset
|
733 # machine-readable formats have slightly different keyword set than |
90b9a7e06c2c
formatter: parse name of built-in formatter templates in standard way
Yuya Nishihara <yuya@tcha.org>
parents:
43077
diff
changeset
|
734 # plain templates, which are handled by changesetformatter. |
90b9a7e06c2c
formatter: parse name of built-in formatter templates in standard way
Yuya Nishihara <yuya@tcha.org>
parents:
43077
diff
changeset
|
735 # note that {b'pickle', b'debug'} can also be added to the list if needed. |
90b9a7e06c2c
formatter: parse name of built-in formatter templates in standard way
Yuya Nishihara <yuya@tcha.org>
parents:
43077
diff
changeset
|
736 if spec.ref in {b'cbor', b'json'}: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
737 fm = ui.formatter(b'log', opts) |
37773
0f084741cd66
logcmdutil: pass formatter to jsonchangeset as argument
Yuya Nishihara <yuya@tcha.org>
parents:
37772
diff
changeset
|
738 return changesetformatter(ui, repo, fm, *postargs) |
3837
7df171ea50cd
Fix log regression where log -p file showed diffs for other files
Matt Mackall <mpm@selenic.com>
parents:
3827
diff
changeset
|
739 |
32893
c8f2cf18b82e
formatter: load templates section like a map file
Yuya Nishihara <yuya@tcha.org>
parents:
32891
diff
changeset
|
740 if not spec.ref and not spec.tmpl and not spec.mapfile: |
36041
fcde8946c553
logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36040
diff
changeset
|
741 return changesetprinter(ui, repo, *postargs) |
34100
08346a8fa65f
cleanup: rename "matchfn" to "match" where obviously a matcher
Martin von Zweigbergk <martinvonz@google.com>
parents:
34098
diff
changeset
|
742 |
36041
fcde8946c553
logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36040
diff
changeset
|
743 return changesettemplater(ui, repo, spec, *postargs) |
3643
b4ad640a3bcf
templates: move changeset templating bits to cmdutils
Matt Mackall <mpm@selenic.com>
parents:
3531
diff
changeset
|
744 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
745 |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
746 @attr.s |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49004
diff
changeset
|
747 class walkopts: |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
748 """Options to configure a set of revisions and file matcher factory |
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
749 to scan revision/file history |
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
750 """ |
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
751 |
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
752 # raw command-line parameters, which a matcher will be built from |
48037
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
753 pats = attr.ib() |
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
754 opts = attr.ib() |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
755 |
45571
9a26fea2b518
log: pass around --rev option by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45570
diff
changeset
|
756 # a list of revset expressions to be traversed; if follow, it specifies |
9a26fea2b518
log: pass around --rev option by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45570
diff
changeset
|
757 # the start revisions |
48037
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
758 revspec = attr.ib() |
45571
9a26fea2b518
log: pass around --rev option by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45570
diff
changeset
|
759 |
45629
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
760 # miscellaneous queries to filter revisions (see "hg help log" for details) |
48037
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
761 bookmarks = attr.ib(default=attr.Factory(list)) |
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
762 branches = attr.ib(default=attr.Factory(list)) |
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
763 date = attr.ib(default=None) |
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
764 keywords = attr.ib(default=attr.Factory(list)) |
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
765 no_merges = attr.ib(default=False) |
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
766 only_merges = attr.ib(default=False) |
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
767 prune_ancestors = attr.ib(default=attr.Factory(list)) |
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
768 users = attr.ib(default=attr.Factory(list)) |
45629
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
769 |
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
770 # miscellaneous matcher arguments |
48037
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
771 include_pats = attr.ib(default=attr.Factory(list)) |
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
772 exclude_pats = attr.ib(default=attr.Factory(list)) |
45629
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
773 |
45569
24df19a9ab87
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45568
diff
changeset
|
774 # 0: no follow, 1: follow first, 2: follow both parents |
48037
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
775 follow = attr.ib(default=0) |
45569
24df19a9ab87
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45568
diff
changeset
|
776 |
45628
c11099cc1de4
log: map --removed to walkopts.force_changelog_traversal
Yuya Nishihara <yuya@tcha.org>
parents:
45571
diff
changeset
|
777 # do not attempt filelog-based traversal, which may be fast but cannot |
c11099cc1de4
log: map --removed to walkopts.force_changelog_traversal
Yuya Nishihara <yuya@tcha.org>
parents:
45571
diff
changeset
|
778 # include revisions where files were removed |
48037
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
779 force_changelog_traversal = attr.ib(default=False) |
45628
c11099cc1de4
log: map --removed to walkopts.force_changelog_traversal
Yuya Nishihara <yuya@tcha.org>
parents:
45571
diff
changeset
|
780 |
45649
9fead7d97069
grep: add option for logcmdutil.makewalker() to not filter revs by file pats
Yuya Nishihara <yuya@tcha.org>
parents:
45631
diff
changeset
|
781 # filter revisions by file patterns, which should be disabled only if |
9fead7d97069
grep: add option for logcmdutil.makewalker() to not filter revs by file pats
Yuya Nishihara <yuya@tcha.org>
parents:
45631
diff
changeset
|
782 # you want to include revisions where files were unmodified |
48037
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
783 filter_revisions_by_pats = attr.ib(default=True) |
45649
9fead7d97069
grep: add option for logcmdutil.makewalker() to not filter revs by file pats
Yuya Nishihara <yuya@tcha.org>
parents:
45631
diff
changeset
|
784 |
45630
224c786f4fce
log: move --graph and topo sort options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45629
diff
changeset
|
785 # sort revisions prior to traversal: 'desc', 'topo', or None |
48037
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
786 sort_revisions = attr.ib(default=None) |
45630
224c786f4fce
log: move --graph and topo sort options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45629
diff
changeset
|
787 |
45570
bddf70c93614
log: parse --limit option by logcmdutil.parseopts()
Yuya Nishihara <yuya@tcha.org>
parents:
45569
diff
changeset
|
788 # limit number of changes displayed; None means unlimited |
48037
0dc4cc654d96
typing: drop annotations on `mercurial/logcmdutil.walkopts` attributes
Matt Harbison <matt_harbison@yahoo.com>
parents:
47443
diff
changeset
|
789 limit = attr.ib(default=None) |
45570
bddf70c93614
log: parse --limit option by logcmdutil.parseopts()
Yuya Nishihara <yuya@tcha.org>
parents:
45569
diff
changeset
|
790 |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
791 |
51304
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
792 def parseopts( |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
793 ui: Any, |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
794 pats: Sequence[bytes], |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
795 opts: Dict[bytes, Any], |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
796 ) -> walkopts: |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
797 """Parse log command options into walkopts |
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
798 |
45631
7f033a587414
log: extract function that builds (revs, makefilematcher) from walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45630
diff
changeset
|
799 The returned walkopts will be passed in to getrevs() or makewalker(). |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
800 """ |
45569
24df19a9ab87
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45568
diff
changeset
|
801 if opts.get(b'follow_first'): |
24df19a9ab87
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45568
diff
changeset
|
802 follow = 1 |
24df19a9ab87
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45568
diff
changeset
|
803 elif opts.get(b'follow'): |
24df19a9ab87
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45568
diff
changeset
|
804 follow = 2 |
24df19a9ab87
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45568
diff
changeset
|
805 else: |
24df19a9ab87
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45568
diff
changeset
|
806 follow = 0 |
24df19a9ab87
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45568
diff
changeset
|
807 |
45630
224c786f4fce
log: move --graph and topo sort options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45629
diff
changeset
|
808 if opts.get(b'graph'): |
224c786f4fce
log: move --graph and topo sort options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45629
diff
changeset
|
809 if ui.configbool(b'experimental', b'log.topo'): |
224c786f4fce
log: move --graph and topo sort options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45629
diff
changeset
|
810 sort_revisions = b'topo' |
224c786f4fce
log: move --graph and topo sort options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45629
diff
changeset
|
811 else: |
224c786f4fce
log: move --graph and topo sort options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45629
diff
changeset
|
812 sort_revisions = b'desc' |
224c786f4fce
log: move --graph and topo sort options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45629
diff
changeset
|
813 else: |
224c786f4fce
log: move --graph and topo sort options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45629
diff
changeset
|
814 sort_revisions = None |
224c786f4fce
log: move --graph and topo sort options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45629
diff
changeset
|
815 |
45571
9a26fea2b518
log: pass around --rev option by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45570
diff
changeset
|
816 return walkopts( |
9a26fea2b518
log: pass around --rev option by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45570
diff
changeset
|
817 pats=pats, |
9a26fea2b518
log: pass around --rev option by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45570
diff
changeset
|
818 opts=opts, |
9a26fea2b518
log: pass around --rev option by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45570
diff
changeset
|
819 revspec=opts.get(b'rev', []), |
46045
9c0db3671008
log: do not override other filtering and sorting options by --bookmark
Yuya Nishihara <yuya@tcha.org>
parents:
45957
diff
changeset
|
820 bookmarks=opts.get(b'bookmark', []), |
45629
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
821 # branch and only_branch are really aliases and must be handled at |
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
822 # the same time |
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
823 branches=opts.get(b'branch', []) + opts.get(b'only_branch', []), |
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
824 date=opts.get(b'date'), |
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
825 keywords=opts.get(b'keyword', []), |
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
826 no_merges=bool(opts.get(b'no_merges')), |
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
827 only_merges=bool(opts.get(b'only_merges')), |
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
828 prune_ancestors=opts.get(b'prune', []), |
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
829 users=opts.get(b'user', []), |
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
830 include_pats=opts.get(b'include', []), |
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
831 exclude_pats=opts.get(b'exclude', []), |
45571
9a26fea2b518
log: pass around --rev option by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45570
diff
changeset
|
832 follow=follow, |
45628
c11099cc1de4
log: map --removed to walkopts.force_changelog_traversal
Yuya Nishihara <yuya@tcha.org>
parents:
45571
diff
changeset
|
833 force_changelog_traversal=bool(opts.get(b'removed')), |
45630
224c786f4fce
log: move --graph and topo sort options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45629
diff
changeset
|
834 sort_revisions=sort_revisions, |
45571
9a26fea2b518
log: pass around --rev option by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45570
diff
changeset
|
835 limit=getlimit(opts), |
9a26fea2b518
log: pass around --rev option by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45570
diff
changeset
|
836 ) |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
837 |
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
838 |
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
839 def _makematcher(repo, revs, wopts): |
35685
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
840 """Build matcher and expanded patterns from log options |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
841 |
35687
67893a516272
log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents:
35686
diff
changeset
|
842 If --follow, revs are the revisions to follow from. |
67893a516272
log: follow file history across copies even with -rREV (BC) (issue4959)
Yuya Nishihara <yuya@tcha.org>
parents:
35686
diff
changeset
|
843 |
35685
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
844 Returns (match, pats, slowpath) where |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
845 - match: a matcher built from the given pats and -I/-X opts |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
846 - pats: patterns used (globs are expanded on Windows) |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
847 - slowpath: True if patterns aren't as simple as scanning filelogs |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
848 """ |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
849 # pats/include/exclude are passed to match.match() directly in |
45653
c7413ffe0402
cmdutil: remove remainder of old walkchangerevs() implementation
Yuya Nishihara <yuya@tcha.org>
parents:
45649
diff
changeset
|
850 # _matchfiles() revset, but a log-like command should build its matcher |
c7413ffe0402
cmdutil: remove remainder of old walkchangerevs() implementation
Yuya Nishihara <yuya@tcha.org>
parents:
45649
diff
changeset
|
851 # with scmutil.match(). The difference is input pats are globbed on |
35685
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
852 # platforms without shell expansion (windows). |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
853 wctx = repo[None] |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
854 match, pats = scmutil.matchandpats(wctx, wopts.pats, wopts.opts) |
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
855 slowpath = match.anypats() or ( |
45628
c11099cc1de4
log: map --removed to walkopts.force_changelog_traversal
Yuya Nishihara <yuya@tcha.org>
parents:
45571
diff
changeset
|
856 not match.always() and wopts.force_changelog_traversal |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
857 ) |
35685
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
858 if not slowpath: |
45571
9a26fea2b518
log: pass around --rev option by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45570
diff
changeset
|
859 if wopts.follow and wopts.revspec: |
45484
5f0eeda2005d
log: make -frREV PATH detect missing files before falling back to slow path
Yuya Nishihara <yuya@tcha.org>
parents:
45483
diff
changeset
|
860 # There may be the case that a path doesn't exist in some (but |
5f0eeda2005d
log: make -frREV PATH detect missing files before falling back to slow path
Yuya Nishihara <yuya@tcha.org>
parents:
45483
diff
changeset
|
861 # not all) of the specified start revisions, but let's consider |
5f0eeda2005d
log: make -frREV PATH detect missing files before falling back to slow path
Yuya Nishihara <yuya@tcha.org>
parents:
45483
diff
changeset
|
862 # the path is valid. Missing files will be warned by the matcher. |
49586
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
863 all_files = list(match.files()) |
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
864 missing_files = set(all_files) |
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
865 files = all_files |
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
866 for r in revs: |
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
867 if not files: |
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
868 # We don't have any file to check anymore. |
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
869 break |
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
870 ctx = repo[r] |
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
871 for f in files: |
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
872 if f in ctx: |
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
873 missing_files.discard(f) |
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
874 elif ctx.hasdir(f): |
45484
5f0eeda2005d
log: make -frREV PATH detect missing files before falling back to slow path
Yuya Nishihara <yuya@tcha.org>
parents:
45483
diff
changeset
|
875 # If a directory exists in any of the start revisions, |
5f0eeda2005d
log: make -frREV PATH detect missing files before falling back to slow path
Yuya Nishihara <yuya@tcha.org>
parents:
45483
diff
changeset
|
876 # take the slow path. |
49586
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
877 missing_files.discard(f) |
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
878 slowpath = True |
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
879 # we found on slow path, no need to search for more. |
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
880 files = missing_files |
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
881 for f in all_files: |
dcb2581e33be
memory-usage: fix `hg log --follow --rev R F` space complexity
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49365
diff
changeset
|
882 if f in missing_files: |
48581
3b6b43a7ace4
logcmdutil: raise `StateError` when file to follow doesn't exist
Martin von Zweigbergk <martinvonz@google.com>
parents:
48580
diff
changeset
|
883 raise error.StateError( |
45484
5f0eeda2005d
log: make -frREV PATH detect missing files before falling back to slow path
Yuya Nishihara <yuya@tcha.org>
parents:
45483
diff
changeset
|
884 _( |
5f0eeda2005d
log: make -frREV PATH detect missing files before falling back to slow path
Yuya Nishihara <yuya@tcha.org>
parents:
45483
diff
changeset
|
885 b'cannot follow file not in any of the specified ' |
5f0eeda2005d
log: make -frREV PATH detect missing files before falling back to slow path
Yuya Nishihara <yuya@tcha.org>
parents:
45483
diff
changeset
|
886 b'revisions: "%s"' |
5f0eeda2005d
log: make -frREV PATH detect missing files before falling back to slow path
Yuya Nishihara <yuya@tcha.org>
parents:
45483
diff
changeset
|
887 ) |
5f0eeda2005d
log: make -frREV PATH detect missing files before falling back to slow path
Yuya Nishihara <yuya@tcha.org>
parents:
45483
diff
changeset
|
888 % f |
5f0eeda2005d
log: make -frREV PATH detect missing files before falling back to slow path
Yuya Nishihara <yuya@tcha.org>
parents:
45483
diff
changeset
|
889 ) |
45569
24df19a9ab87
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45568
diff
changeset
|
890 elif wopts.follow: |
45482
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
891 for f in match.files(): |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
892 if f not in wctx: |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
893 # If the file exists, it may be a directory, so let it |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
894 # take the slow path. |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
895 if os.path.exists(repo.wjoin(f)): |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
896 slowpath = True |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
897 continue |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
898 else: |
48581
3b6b43a7ace4
logcmdutil: raise `StateError` when file to follow doesn't exist
Martin von Zweigbergk <martinvonz@google.com>
parents:
48580
diff
changeset
|
899 raise error.StateError( |
45482
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
900 _( |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
901 b'cannot follow file not in parent ' |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
902 b'revision: "%s"' |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
903 ) |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
904 % f |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
905 ) |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
906 filelog = repo.file(f) |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
907 if not filelog: |
45483
07324227f6b7
log: fix -fr'wdir()' PATH to follow newly added file
Yuya Nishihara <yuya@tcha.org>
parents:
45482
diff
changeset
|
908 # A file exists in wdir but not in history, which means |
07324227f6b7
log: fix -fr'wdir()' PATH to follow newly added file
Yuya Nishihara <yuya@tcha.org>
parents:
45482
diff
changeset
|
909 # the file isn't committed yet. |
48581
3b6b43a7ace4
logcmdutil: raise `StateError` when file to follow doesn't exist
Martin von Zweigbergk <martinvonz@google.com>
parents:
48580
diff
changeset
|
910 raise error.StateError( |
45482
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
911 _(b'cannot follow nonexistent file: "%s"') % f |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
912 ) |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
913 else: |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
914 for f in match.files(): |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
915 filelog = repo.file(f) |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
916 if not filelog: |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
917 # A zero count may be a directory or deleted file, so |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
918 # try to find matching entries on the slow path. |
a03fde1077ce
log: reorganize if-else and for loop in logcmdutil._makematcher()
Yuya Nishihara <yuya@tcha.org>
parents:
45469
diff
changeset
|
919 slowpath = True |
35685
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
920 |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
921 # We decided to fall back to the slowpath because at least one |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
922 # of the paths was not a file. Check to see if at least one of them |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
923 # existed in history - in that case, we'll continue down the |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
924 # slowpath; otherwise, we can turn off the slowpath |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
925 if slowpath: |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
926 for path in match.files(): |
46378
9842c00f0252
log: fix handling of root (or empty) path provided by matcher (issue6478)
Yuya Nishihara <yuya@tcha.org>
parents:
46046
diff
changeset
|
927 if not path or path in repo.store: |
35685
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
928 break |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
929 else: |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
930 slowpath = False |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
931 |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
932 return match, pats, slowpath |
659dfbd852e2
log: extract function that processes log file patterns
Yuya Nishihara <yuya@tcha.org>
parents:
35684
diff
changeset
|
933 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
934 |
35686
b25fa5da4ca2
log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents:
35685
diff
changeset
|
935 def _fileancestors(repo, revs, match, followfirst): |
b25fa5da4ca2
log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents:
35685
diff
changeset
|
936 fctxs = [] |
b25fa5da4ca2
log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents:
35685
diff
changeset
|
937 for r in revs: |
b25fa5da4ca2
log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents:
35685
diff
changeset
|
938 ctx = repo[r] |
b25fa5da4ca2
log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents:
35685
diff
changeset
|
939 fctxs.extend(ctx[f].introfilectx() for f in ctx.walk(match)) |
35690
3e394e0558d7
log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents:
35689
diff
changeset
|
940 |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
941 # When displaying a revision with --patch --follow FILE, we have |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
942 # to know which file of the revision must be diffed. With |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
943 # --follow, we want the names of the ancestors of FILE in the |
35690
3e394e0558d7
log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents:
35689
diff
changeset
|
944 # revision, stored in "fcache". "fcache" is populated as a side effect |
3e394e0558d7
log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents:
35689
diff
changeset
|
945 # of the graph traversal. |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
946 fcache = {} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
947 |
36040
f8ad57d24252
log: pass ctx to makefilematcher() and makehunksfilter() functions
Yuya Nishihara <yuya@tcha.org>
parents:
36000
diff
changeset
|
948 def filematcher(ctx): |
45216
4ebc5f325bed
log: fix crash and bad filematcher lookup by -fr'wdir()' PATH
Yuya Nishihara <yuya@tcha.org>
parents:
44889
diff
changeset
|
949 return scmutil.matchfiles(repo, fcache.get(scmutil.intrev(ctx), [])) |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
950 |
35690
3e394e0558d7
log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents:
35689
diff
changeset
|
951 def revgen(): |
3e394e0558d7
log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents:
35689
diff
changeset
|
952 for rev, cs in dagop.filectxancestors(fctxs, followfirst=followfirst): |
3e394e0558d7
log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents:
35689
diff
changeset
|
953 fcache[rev] = [c.path() for c in cs] |
3e394e0558d7
log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents:
35689
diff
changeset
|
954 yield rev |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
955 |
35690
3e394e0558d7
log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents:
35689
diff
changeset
|
956 return smartset.generatorset(revgen(), iterasc=False), filematcher |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
957 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
958 |
35927
572f36e9a780
logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35926
diff
changeset
|
959 def _makenofollowfilematcher(repo, pats, opts): |
22167
d4bc38f6eab7
cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents:
22166
diff
changeset
|
960 '''hook for extensions to override the filematcher for non-follow cases''' |
d4bc38f6eab7
cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents:
22166
diff
changeset
|
961 return None |
d4bc38f6eab7
cmdutil: add a hook for making custom non-follow log file matchers
Siddharth Agarwal <sid0@fb.com>
parents:
22166
diff
changeset
|
962 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
963 |
48130
5105a9975407
errors: raise InputError from revsingle() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48129
diff
changeset
|
964 def revsingle(repo, revspec, default=b'.', localalias=None): |
5105a9975407
errors: raise InputError from revsingle() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48129
diff
changeset
|
965 """Resolves user-provided revset(s) into a single revision. |
5105a9975407
errors: raise InputError from revsingle() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48129
diff
changeset
|
966 |
5105a9975407
errors: raise InputError from revsingle() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48129
diff
changeset
|
967 This just wraps the lower-level scmutil.revsingle() in order to raise an |
5105a9975407
errors: raise InputError from revsingle() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48129
diff
changeset
|
968 exception indicating user error. |
5105a9975407
errors: raise InputError from revsingle() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48129
diff
changeset
|
969 """ |
5105a9975407
errors: raise InputError from revsingle() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48129
diff
changeset
|
970 try: |
5105a9975407
errors: raise InputError from revsingle() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48129
diff
changeset
|
971 return scmutil.revsingle(repo, revspec, default, localalias) |
5105a9975407
errors: raise InputError from revsingle() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48129
diff
changeset
|
972 except error.RepoLookupError as e: |
5105a9975407
errors: raise InputError from revsingle() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48129
diff
changeset
|
973 raise error.InputError(e.args[0], hint=e.hint) |
5105a9975407
errors: raise InputError from revsingle() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48129
diff
changeset
|
974 |
5105a9975407
errors: raise InputError from revsingle() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48129
diff
changeset
|
975 |
48129
b74e128676d4
errors: raise InputError from revpair() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48128
diff
changeset
|
976 def revpair(repo, revs): |
b74e128676d4
errors: raise InputError from revpair() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48128
diff
changeset
|
977 """Resolves user-provided revset(s) into two revisions. |
b74e128676d4
errors: raise InputError from revpair() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48128
diff
changeset
|
978 |
b74e128676d4
errors: raise InputError from revpair() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48128
diff
changeset
|
979 This just wraps the lower-level scmutil.revpair() in order to raise an |
b74e128676d4
errors: raise InputError from revpair() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48128
diff
changeset
|
980 exception indicating user error. |
b74e128676d4
errors: raise InputError from revpair() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48128
diff
changeset
|
981 """ |
b74e128676d4
errors: raise InputError from revpair() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48128
diff
changeset
|
982 try: |
b74e128676d4
errors: raise InputError from revpair() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48128
diff
changeset
|
983 return scmutil.revpair(repo, revs) |
b74e128676d4
errors: raise InputError from revpair() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48128
diff
changeset
|
984 except error.RepoLookupError as e: |
b74e128676d4
errors: raise InputError from revpair() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48128
diff
changeset
|
985 raise error.InputError(e.args[0], hint=e.hint) |
b74e128676d4
errors: raise InputError from revpair() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48128
diff
changeset
|
986 |
b74e128676d4
errors: raise InputError from revpair() iff revset provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48128
diff
changeset
|
987 |
48128
5ced12cfa41b
errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48037
diff
changeset
|
988 def revrange(repo, specs, localalias=None): |
5ced12cfa41b
errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48037
diff
changeset
|
989 """Resolves user-provided revset(s). |
5ced12cfa41b
errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48037
diff
changeset
|
990 |
5ced12cfa41b
errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48037
diff
changeset
|
991 This just wraps the lower-level scmutil.revrange() in order to raise an |
5ced12cfa41b
errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48037
diff
changeset
|
992 exception indicating user error. |
5ced12cfa41b
errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48037
diff
changeset
|
993 """ |
5ced12cfa41b
errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48037
diff
changeset
|
994 try: |
5ced12cfa41b
errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48037
diff
changeset
|
995 return scmutil.revrange(repo, specs, localalias) |
5ced12cfa41b
errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48037
diff
changeset
|
996 except error.RepoLookupError as e: |
5ced12cfa41b
errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48037
diff
changeset
|
997 raise error.InputError(e.args[0], hint=e.hint) |
5ced12cfa41b
errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48037
diff
changeset
|
998 |
5ced12cfa41b
errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48037
diff
changeset
|
999 |
35642
e64baf32782a
log: make opt2revset table a module constant
Yuya Nishihara <yuya@tcha.org>
parents:
35548
diff
changeset
|
1000 _opt2logrevset = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1001 b'no_merges': (b'not merge()', None), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1002 b'only_merges': (b'merge()', None), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1003 b'_matchfiles': (None, b'_matchfiles(%ps)'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1004 b'date': (b'date(%s)', None), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1005 b'branch': (b'branch(%s)', b'%lr'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1006 b'_patslog': (b'filelog(%s)', b'%lr'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1007 b'keyword': (b'keyword(%s)', b'%lr'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1008 b'prune': (b'ancestors(%s)', b'not %lr'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1009 b'user': (b'user(%s)', b'%lr'), |
35642
e64baf32782a
log: make opt2revset table a module constant
Yuya Nishihara <yuya@tcha.org>
parents:
35548
diff
changeset
|
1010 } |
e64baf32782a
log: make opt2revset table a module constant
Yuya Nishihara <yuya@tcha.org>
parents:
35548
diff
changeset
|
1011 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1012 |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
1013 def _makerevset(repo, wopts, slowpath): |
35690
3e394e0558d7
log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents:
35689
diff
changeset
|
1014 """Return a revset string built from log options and file patterns""" |
45629
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
1015 opts = { |
46046
1bf2b44c4007
log: do not accept string-matcher pattern as -u/-b/-B parameter
Yuya Nishihara <yuya@tcha.org>
parents:
46045
diff
changeset
|
1016 b'branch': [b'literal:' + repo.lookupbranch(b) for b in wopts.branches], |
45629
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
1017 b'date': wopts.date, |
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
1018 b'keyword': wopts.keywords, |
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
1019 b'no_merges': wopts.no_merges, |
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
1020 b'only_merges': wopts.only_merges, |
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
1021 b'prune': wopts.prune_ancestors, |
46046
1bf2b44c4007
log: do not accept string-matcher pattern as -u/-b/-B parameter
Yuya Nishihara <yuya@tcha.org>
parents:
46045
diff
changeset
|
1022 b'user': [b'literal:' + v for v in wopts.users], |
45629
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
1023 } |
17746
6d218e47cf9b
log: speed up hg log for untracked files (issue1340)
smuralid
parents:
17676
diff
changeset
|
1024 |
45649
9fead7d97069
grep: add option for logcmdutil.makewalker() to not filter revs by file pats
Yuya Nishihara <yuya@tcha.org>
parents:
45631
diff
changeset
|
1025 if wopts.filter_revisions_by_pats and slowpath: |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1026 # pats/include/exclude cannot be represented as separate |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1027 # revset expressions as their filtering logic applies at file |
35743
3c2a6246fd63
log: fix typo in comment about _matchfiles()
Yuya Nishihara <yuya@tcha.org>
parents:
35690
diff
changeset
|
1028 # level. For instance "-I a -X b" matches a revision touching |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1029 # "a" and "b" while "file(a) and not file(b)" does |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1030 # not. Besides, filesets are evaluated against the working |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1031 # directory. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1032 matchargs = [b'r:', b'd:relpath'] |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
1033 for p in wopts.pats: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1034 matchargs.append(b'p:' + p) |
45629
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
1035 for p in wopts.include_pats: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1036 matchargs.append(b'i:' + p) |
45629
8fe09005ed88
log: move miscellaneous filter/matcher options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45628
diff
changeset
|
1037 for p in wopts.exclude_pats: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1038 matchargs.append(b'x:' + p) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1039 opts[b'_matchfiles'] = matchargs |
45649
9fead7d97069
grep: add option for logcmdutil.makewalker() to not filter revs by file pats
Yuya Nishihara <yuya@tcha.org>
parents:
45631
diff
changeset
|
1040 elif wopts.filter_revisions_by_pats and not wopts.follow: |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
1041 opts[b'_patslog'] = list(wopts.pats) |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1042 |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1043 expr = [] |
49004
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48966
diff
changeset
|
1044 for op, val in sorted(opts.items()): |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1045 if not val: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1046 continue |
35644
7a0a90d63a8c
log: use revsetlang.formatspec() to concatenate list expression
Yuya Nishihara <yuya@tcha.org>
parents:
35643
diff
changeset
|
1047 revop, listop = _opt2logrevset[op] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1048 if revop and b'%' not in revop: |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1049 expr.append(revop) |
35645
b6b7855c79aa
log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents:
35644
diff
changeset
|
1050 elif not listop: |
b6b7855c79aa
log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents:
35644
diff
changeset
|
1051 expr.append(revsetlang.formatspec(revop, val)) |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1052 else: |
35645
b6b7855c79aa
log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents:
35644
diff
changeset
|
1053 if revop: |
b6b7855c79aa
log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents:
35644
diff
changeset
|
1054 val = [revsetlang.formatspec(revop, v) for v in val] |
b6b7855c79aa
log: use revsetlang.formatspec() thoroughly
Yuya Nishihara <yuya@tcha.org>
parents:
35644
diff
changeset
|
1055 expr.append(revsetlang.formatspec(listop, val)) |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1056 |
46045
9c0db3671008
log: do not override other filtering and sorting options by --bookmark
Yuya Nishihara <yuya@tcha.org>
parents:
45957
diff
changeset
|
1057 if wopts.bookmarks: |
9c0db3671008
log: do not override other filtering and sorting options by --bookmark
Yuya Nishihara <yuya@tcha.org>
parents:
45957
diff
changeset
|
1058 expr.append( |
9c0db3671008
log: do not override other filtering and sorting options by --bookmark
Yuya Nishihara <yuya@tcha.org>
parents:
45957
diff
changeset
|
1059 revsetlang.formatspec( |
9c0db3671008
log: do not override other filtering and sorting options by --bookmark
Yuya Nishihara <yuya@tcha.org>
parents:
45957
diff
changeset
|
1060 b'%lr', |
9c0db3671008
log: do not override other filtering and sorting options by --bookmark
Yuya Nishihara <yuya@tcha.org>
parents:
45957
diff
changeset
|
1061 [scmutil.format_bookmark_revspec(v) for v in wopts.bookmarks], |
9c0db3671008
log: do not override other filtering and sorting options by --bookmark
Yuya Nishihara <yuya@tcha.org>
parents:
45957
diff
changeset
|
1062 ) |
9c0db3671008
log: do not override other filtering and sorting options by --bookmark
Yuya Nishihara <yuya@tcha.org>
parents:
45957
diff
changeset
|
1063 ) |
9c0db3671008
log: do not override other filtering and sorting options by --bookmark
Yuya Nishihara <yuya@tcha.org>
parents:
45957
diff
changeset
|
1064 |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1065 if expr: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1066 expr = b'(' + b' and '.join(expr) + b')' |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1067 else: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1068 expr = None |
35690
3e394e0558d7
log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents:
35689
diff
changeset
|
1069 return expr |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1070 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1071 |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
1072 def _initialrevs(repo, wopts): |
35686
b25fa5da4ca2
log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents:
35685
diff
changeset
|
1073 """Return the initial set of revisions to be filtered or followed""" |
45571
9a26fea2b518
log: pass around --rev option by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45570
diff
changeset
|
1074 if wopts.revspec: |
48128
5ced12cfa41b
errors: raise InputError on bad revset to revrange() iff provided by the user
Martin von Zweigbergk <martinvonz@google.com>
parents:
48037
diff
changeset
|
1075 revs = revrange(repo, wopts.revspec) |
47055
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46843
diff
changeset
|
1076 elif wopts.follow and repo.dirstate.p1() == repo.nullid: |
31043
aea06029919e
revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents:
30909
diff
changeset
|
1077 revs = smartset.baseset() |
45569
24df19a9ab87
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45568
diff
changeset
|
1078 elif wopts.follow: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1079 revs = repo.revs(b'.') |
24062
f576addb5b77
log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents:
24061
diff
changeset
|
1080 else: |
31043
aea06029919e
revset: import set classes directly from smartset module
Yuya Nishihara <yuya@tcha.org>
parents:
30909
diff
changeset
|
1081 revs = smartset.spanset(repo) |
24062
f576addb5b77
log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents:
24061
diff
changeset
|
1082 revs.reverse() |
f576addb5b77
log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents:
24061
diff
changeset
|
1083 return revs |
f576addb5b77
log: extract common part from getgraphlogrevs() and getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents:
24061
diff
changeset
|
1084 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1085 |
51304
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
1086 def makewalker( |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
1087 repo: Any, |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
1088 wopts: walkopts, |
52755
5c48fd4c0e68
typing: introduce a `types` module and a MatcherT alias
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52669
diff
changeset
|
1089 ) -> Tuple[smartset.abstractsmartset, Optional[Callable[[Any], MatcherT]]]: |
45631
7f033a587414
log: extract function that builds (revs, makefilematcher) from walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45630
diff
changeset
|
1090 """Build (revs, makefilematcher) to scan revision/file history |
35548
b14c8bcfbad9
log: drop unused expr from return value of getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents:
35547
diff
changeset
|
1091 |
45631
7f033a587414
log: extract function that builds (revs, makefilematcher) from walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45630
diff
changeset
|
1092 - revs is the smartset to be traversed. |
7f033a587414
log: extract function that builds (revs, makefilematcher) from walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45630
diff
changeset
|
1093 - makefilematcher is a function to map ctx to a matcher for that revision |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1094 """ |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
1095 revs = _initialrevs(repo, wopts) |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1096 if not revs: |
35548
b14c8bcfbad9
log: drop unused expr from return value of getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents:
35547
diff
changeset
|
1097 return smartset.baseset(), None |
45628
c11099cc1de4
log: map --removed to walkopts.force_changelog_traversal
Yuya Nishihara <yuya@tcha.org>
parents:
45571
diff
changeset
|
1098 # TODO: might want to merge slowpath with wopts.force_changelog_traversal |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
1099 match, pats, slowpath = _makematcher(repo, revs, wopts) |
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
1100 wopts = attr.evolve(wopts, pats=pats) |
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
1101 |
35690
3e394e0558d7
log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents:
35689
diff
changeset
|
1102 filematcher = None |
45569
24df19a9ab87
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45568
diff
changeset
|
1103 if wopts.follow: |
35688
84d0e99c063a
log: replace "not pats" with matcher attribute for consistency
Yuya Nishihara <yuya@tcha.org>
parents:
35687
diff
changeset
|
1104 if slowpath or match.always(): |
45569
24df19a9ab87
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45568
diff
changeset
|
1105 revs = dagop.revancestors(repo, revs, followfirst=wopts.follow == 1) |
35686
b25fa5da4ca2
log: resolve --follow thoroughly in getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents:
35685
diff
changeset
|
1106 else: |
45628
c11099cc1de4
log: map --removed to walkopts.force_changelog_traversal
Yuya Nishihara <yuya@tcha.org>
parents:
45571
diff
changeset
|
1107 assert not wopts.force_changelog_traversal |
45569
24df19a9ab87
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45568
diff
changeset
|
1108 revs, filematcher = _fileancestors( |
24df19a9ab87
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45568
diff
changeset
|
1109 repo, revs, match, followfirst=wopts.follow == 1 |
24df19a9ab87
log: pass around --follow/--follow-first options by walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45568
diff
changeset
|
1110 ) |
35684
1c929b4942a3
log: resolve --follow with -rREV in cmdutil.getlogrevs()
Yuya Nishihara <yuya@tcha.org>
parents:
35683
diff
changeset
|
1111 revs.reverse() |
35690
3e394e0558d7
log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents:
35689
diff
changeset
|
1112 if filematcher is None: |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
1113 filematcher = _makenofollowfilematcher(repo, wopts.pats, wopts.opts) |
35690
3e394e0558d7
log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents:
35689
diff
changeset
|
1114 if filematcher is None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1115 |
36040
f8ad57d24252
log: pass ctx to makefilematcher() and makehunksfilter() functions
Yuya Nishihara <yuya@tcha.org>
parents:
36000
diff
changeset
|
1116 def filematcher(ctx): |
35690
3e394e0558d7
log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents:
35689
diff
changeset
|
1117 return match |
3e394e0558d7
log: build follow-log filematcher at once
Yuya Nishihara <yuya@tcha.org>
parents:
35689
diff
changeset
|
1118 |
45568
c1d0f83d62c4
log: introduce struct that carries log traversal options
Yuya Nishihara <yuya@tcha.org>
parents:
45567
diff
changeset
|
1119 expr = _makerevset(repo, wopts, slowpath) |
45630
224c786f4fce
log: move --graph and topo sort options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45629
diff
changeset
|
1120 if wopts.sort_revisions: |
224c786f4fce
log: move --graph and topo sort options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45629
diff
changeset
|
1121 assert wopts.sort_revisions in {b'topo', b'desc'} |
224c786f4fce
log: move --graph and topo sort options to walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45629
diff
changeset
|
1122 if wopts.sort_revisions == b'topo': |
42336
604c086ddde6
log: add config for making `hg log -G` always topo-sorted
Martin von Zweigbergk <martinvonz@google.com>
parents:
42335
diff
changeset
|
1123 if not revs.istopo(): |
604c086ddde6
log: add config for making `hg log -G` always topo-sorted
Martin von Zweigbergk <martinvonz@google.com>
parents:
42335
diff
changeset
|
1124 revs = dagop.toposort(revs, repo.changelog.parentrevs) |
604c086ddde6
log: add config for making `hg log -G` always topo-sorted
Martin von Zweigbergk <martinvonz@google.com>
parents:
42335
diff
changeset
|
1125 # TODO: try to iterate the set lazily |
42346
b162229ebe0d
log: flag topo-sorted set as such
Yuya Nishihara <yuya@tcha.org>
parents:
42336
diff
changeset
|
1126 revs = revset.baseset(list(revs), istopo=True) |
42336
604c086ddde6
log: add config for making `hg log -G` always topo-sorted
Martin von Zweigbergk <martinvonz@google.com>
parents:
42335
diff
changeset
|
1127 elif not (revs.isdescending() or revs.istopo()): |
45566
142f0dcf90d0
log: remove stale comment about order of user revset
Yuya Nishihara <yuya@tcha.org>
parents:
45484
diff
changeset
|
1128 # User-specified revs might be unsorted |
29335
631617262e55
graphmod: avoid sorting when already sorted
Martijn Pieters <mjpieters@fb.com>
parents:
29327
diff
changeset
|
1129 revs.sort(reverse=True) |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1130 if expr: |
35547
b6dbc860570d
log: don't expand aliases in revset built from command options
Yuya Nishihara <yuya@tcha.org>
parents:
35545
diff
changeset
|
1131 matcher = revset.match(None, expr) |
34037
205c47e30a93
revset: make match function follow given subset if specified (API)
Yuya Nishihara <yuya@tcha.org>
parents:
34036
diff
changeset
|
1132 revs = matcher(repo, revs) |
45570
bddf70c93614
log: parse --limit option by logcmdutil.parseopts()
Yuya Nishihara <yuya@tcha.org>
parents:
45569
diff
changeset
|
1133 if wopts.limit is not None: |
bddf70c93614
log: parse --limit option by logcmdutil.parseopts()
Yuya Nishihara <yuya@tcha.org>
parents:
45569
diff
changeset
|
1134 revs = revs.slice(0, wopts.limit) |
36045
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
1135 |
45631
7f033a587414
log: extract function that builds (revs, makefilematcher) from walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45630
diff
changeset
|
1136 return revs, filematcher |
7f033a587414
log: extract function that builds (revs, makefilematcher) from walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45630
diff
changeset
|
1137 |
7f033a587414
log: extract function that builds (revs, makefilematcher) from walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45630
diff
changeset
|
1138 |
51304
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
1139 def getrevs( |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
1140 repo: Any, |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
1141 wopts: walkopts, |
f15cb5111a1e
pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51302
diff
changeset
|
1142 ) -> Tuple[smartset.abstractsmartset, Optional[changesetdiffer]]: |
45631
7f033a587414
log: extract function that builds (revs, makefilematcher) from walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45630
diff
changeset
|
1143 """Return (revs, differ) where revs is a smartset |
7f033a587414
log: extract function that builds (revs, makefilematcher) from walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45630
diff
changeset
|
1144 |
7f033a587414
log: extract function that builds (revs, makefilematcher) from walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45630
diff
changeset
|
1145 differ is a changesetdiffer with pre-configured file matcher. |
7f033a587414
log: extract function that builds (revs, makefilematcher) from walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45630
diff
changeset
|
1146 """ |
7f033a587414
log: extract function that builds (revs, makefilematcher) from walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45630
diff
changeset
|
1147 revs, filematcher = makewalker(repo, wopts) |
7f033a587414
log: extract function that builds (revs, makefilematcher) from walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45630
diff
changeset
|
1148 if not revs: |
7f033a587414
log: extract function that builds (revs, makefilematcher) from walkopts
Yuya Nishihara <yuya@tcha.org>
parents:
45630
diff
changeset
|
1149 return revs, None |
36045
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
1150 differ = changesetdiffer() |
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
1151 differ._makefilematcher = filematcher |
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
1152 return revs, differ |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1153 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1154 |
35927
572f36e9a780
logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35926
diff
changeset
|
1155 def _parselinerangeopt(repo, opts): |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1156 """Parse --line-range log option and return a list of tuples (filename, |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1157 (fromline, toline)). |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1158 """ |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1159 linerangebyfname = [] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1160 for pat in opts.get(b'line_range', []): |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1161 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1162 pat, linerange = pat.rsplit(b',', 1) |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1163 except ValueError: |
48580
91017508a785
logcmdutil: raise `InputError` on bad CLI arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
48130
diff
changeset
|
1164 raise error.InputError( |
91017508a785
logcmdutil: raise `InputError` on bad CLI arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
48130
diff
changeset
|
1165 _(b'malformatted line-range pattern %s') % pat |
91017508a785
logcmdutil: raise `InputError` on bad CLI arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
48130
diff
changeset
|
1166 ) |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1167 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1168 fromline, toline = map(int, linerange.split(b':')) |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1169 except ValueError: |
48580
91017508a785
logcmdutil: raise `InputError` on bad CLI arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
48130
diff
changeset
|
1170 raise error.InputError(_(b"invalid line range for %s") % pat) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1171 msg = _(b"line range pattern '%s' must match exactly one file") % pat |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1172 fname = scmutil.parsefollowlinespattern(repo, None, pat, msg) |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1173 linerangebyfname.append( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1174 (fname, util.processlinerange(fromline, toline)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1175 ) |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1176 return linerangebyfname |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1177 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1178 |
35927
572f36e9a780
logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35926
diff
changeset
|
1179 def getlinerangerevs(repo, userrevs, opts): |
36045
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
1180 """Return (revs, differ). |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1181 |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1182 "revs" are revisions obtained by processing "line-range" log options and |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1183 walking block ancestors of each specified file/line-range. |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1184 |
36045
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
1185 "differ" is a changesetdiffer with pre-configured file matcher and hunks |
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
1186 filter. |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1187 """ |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1188 wctx = repo[None] |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1189 |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1190 # Two-levels map of "rev -> file ctx -> [line range]". |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1191 linerangesbyrev = {} |
35927
572f36e9a780
logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35926
diff
changeset
|
1192 for fname, (fromline, toline) in _parselinerangeopt(repo, opts): |
34907
0ccfc468423a
log: handle removed files with --line-range patterns
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34905
diff
changeset
|
1193 if fname not in wctx: |
48581
3b6b43a7ace4
logcmdutil: raise `StateError` when file to follow doesn't exist
Martin von Zweigbergk <martinvonz@google.com>
parents:
48580
diff
changeset
|
1194 raise error.StateError( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43106
diff
changeset
|
1195 _(b'cannot follow file not in parent revision: "%s"') % fname |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1196 ) |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1197 fctx = wctx.filectx(fname) |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1198 for fctx, linerange in dagop.blockancestors(fctx, fromline, toline): |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1199 rev = fctx.introrev() |
43445
d1b9d2c6ec96
log: map None rev to wdirrev when filtering revisions with --line-range
Denis Laxalde <denis@laxalde.org>
parents:
43117
diff
changeset
|
1200 if rev is None: |
d1b9d2c6ec96
log: map None rev to wdirrev when filtering revisions with --line-range
Denis Laxalde <denis@laxalde.org>
parents:
43117
diff
changeset
|
1201 rev = wdirrev |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1202 if rev not in userrevs: |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1203 continue |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1204 linerangesbyrev.setdefault(rev, {}).setdefault( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1205 fctx.path(), [] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1206 ).append(linerange) |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1207 |
36043
dd77e36eabb6
logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents:
36042
diff
changeset
|
1208 def nofilterhunksfn(fctx, hunks): |
dd77e36eabb6
logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents:
36042
diff
changeset
|
1209 return hunks |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1210 |
36043
dd77e36eabb6
logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents:
36042
diff
changeset
|
1211 def hunksfilter(ctx): |
43445
d1b9d2c6ec96
log: map None rev to wdirrev when filtering revisions with --line-range
Denis Laxalde <denis@laxalde.org>
parents:
43117
diff
changeset
|
1212 fctxlineranges = linerangesbyrev.get(scmutil.intrev(ctx)) |
36043
dd77e36eabb6
logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents:
36042
diff
changeset
|
1213 if fctxlineranges is None: |
dd77e36eabb6
logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents:
36042
diff
changeset
|
1214 return nofilterhunksfn |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1215 |
36043
dd77e36eabb6
logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents:
36042
diff
changeset
|
1216 def filterfn(fctx, hunks): |
dd77e36eabb6
logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents:
36042
diff
changeset
|
1217 lineranges = fctxlineranges.get(fctx.path()) |
dd77e36eabb6
logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents:
36042
diff
changeset
|
1218 if lineranges is not None: |
dd77e36eabb6
logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents:
36042
diff
changeset
|
1219 for hr, lines in hunks: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1220 if hr is None: # binary |
36043
dd77e36eabb6
logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents:
36042
diff
changeset
|
1221 yield hr, lines |
dd77e36eabb6
logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents:
36042
diff
changeset
|
1222 continue |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1223 if any(mdiff.hunkinrange(hr[2:], lr) for lr in lineranges): |
36043
dd77e36eabb6
logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents:
36042
diff
changeset
|
1224 yield hr, lines |
dd77e36eabb6
logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents:
36042
diff
changeset
|
1225 else: |
52669
e627cc25b6f3
pyupgrade: rewrite `yield` statements in a loop to `yield from`
Matt Harbison <matt_harbison@yahoo.com>
parents:
52668
diff
changeset
|
1226 yield from hunks |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1227 |
36043
dd77e36eabb6
logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents:
36042
diff
changeset
|
1228 return filterfn |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1229 |
36043
dd77e36eabb6
logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents:
36042
diff
changeset
|
1230 def filematcher(ctx): |
43445
d1b9d2c6ec96
log: map None rev to wdirrev when filtering revisions with --line-range
Denis Laxalde <denis@laxalde.org>
parents:
43117
diff
changeset
|
1231 files = list(linerangesbyrev.get(scmutil.intrev(ctx), [])) |
36043
dd77e36eabb6
logcmdutil: create hunksfilter and filematcher even if no diff option given
Yuya Nishihara <yuya@tcha.org>
parents:
36042
diff
changeset
|
1232 return scmutil.matchfiles(repo, files) |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1233 |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1234 revs = sorted(linerangesbyrev, reverse=True) |
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1235 |
36045
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
1236 differ = changesetdiffer() |
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
1237 differ._makefilematcher = filematcher |
29b83c08afe0
log: pack filematcher and hunksfilter into changesetdiffer object
Yuya Nishihara <yuya@tcha.org>
parents:
36043
diff
changeset
|
1238 differ._makehunksfilter = hunksfilter |
43674
af9c73f26371
logcmdutil: let getlinerangerevs() return "revs" as a smartset
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
43117
diff
changeset
|
1239 return smartset.baseset(revs), differ |
34857
84c6b9384d6a
log: add -L/--line-range option to follow file history by line range
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34856
diff
changeset
|
1240 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1241 |
27216
8117e2cd959e
graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents:
27214
diff
changeset
|
1242 def _graphnodeformatter(ui, displayer): |
45789
1f7c077e0640
config: rename ui.graphnodetemplate to command-templates.graphnode
Martin von Zweigbergk <martinvonz@google.com>
parents:
45788
diff
changeset
|
1243 spec = ui.config(b'command-templates', b'graphnode') |
27216
8117e2cd959e
graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents:
27214
diff
changeset
|
1244 if not spec: |
36542
6ad140dc4269
templatekw: extract non-templatekw function as getgraphnode()
Yuya Nishihara <yuya@tcha.org>
parents:
36471
diff
changeset
|
1245 return templatekw.getgraphnode # fast path for "{graphnode}" |
27216
8117e2cd959e
graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents:
27214
diff
changeset
|
1246 |
32045
3eceeede26e9
graphlog: optionally strip quotes from graphnode template (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
32005
diff
changeset
|
1247 spec = templater.unquotestring(spec) |
35926
b0014780c7fc
logcmdutil: rename classes and functions to conform to our coding style (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35925
diff
changeset
|
1248 if isinstance(displayer, changesettemplater): |
36985
255f635c3204
templater: convert resources to a table of callables for future extension
Yuya Nishihara <yuya@tcha.org>
parents:
36926
diff
changeset
|
1249 # reuse cache of slow templates |
37075
d64ae4fef471
log: do no expect templateresources() returning a dict
Yuya Nishihara <yuya@tcha.org>
parents:
36992
diff
changeset
|
1250 tres = displayer._tresources |
d64ae4fef471
log: do no expect templateresources() returning a dict
Yuya Nishihara <yuya@tcha.org>
parents:
36992
diff
changeset
|
1251 else: |
d64ae4fef471
log: do no expect templateresources() returning a dict
Yuya Nishihara <yuya@tcha.org>
parents:
36992
diff
changeset
|
1252 tres = formatter.templateresources(ui) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1253 templ = formatter.maketemplater( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1254 ui, spec, defaults=templatekw.keywords, resources=tres |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1255 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1256 |
44379
14d0e89520a2
graphlog: use '%' for other context in merge conflict
Martin von Zweigbergk <martinvonz@google.com>
parents:
43848
diff
changeset
|
1257 def formatnode(repo, ctx, cache): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1258 props = {b'ctx': ctx, b'repo': repo} |
36991
317382151ac3
templater: rename .render(mapping) to .renderdefault(mapping) (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36985
diff
changeset
|
1259 return templ.renderdefault(props) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1260 |
27216
8117e2cd959e
graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents:
27214
diff
changeset
|
1261 return formatnode |
8117e2cd959e
graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents:
27214
diff
changeset
|
1262 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1263 |
42519
a68350a7fc55
log: pass getcopies() function instead of getrenamed() to displayer (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
42517
diff
changeset
|
1264 def displaygraph(ui, repo, dag, displayer, edgefn, getcopies=None, props=None): |
34201
e9898ad31115
cmdutil: allow extra properties to be added to each context
Gregory Szorc <gregory.szorc@gmail.com>
parents:
34136
diff
changeset
|
1265 props = props or {} |
27216
8117e2cd959e
graphlog: make node symbol templatable by ui.graphnodetemplate option
Yuya Nishihara <yuya@tcha.org>
parents:
27214
diff
changeset
|
1266 formatnode = _graphnodeformatter(ui, displayer) |
28375
97cb1aeaca78
graphmod: refactor state handling
Martijn Pieters <mjpieters@fb.com>
parents:
28322
diff
changeset
|
1267 state = graphmod.asciistate() |
43796
faa8a59f4a06
graphlog: change state dict to attr struct
Yuya Nishihara <yuya@tcha.org>
parents:
43794
diff
changeset
|
1268 styles = state.styles |
28999
790c076cd4a2
graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents:
28955
diff
changeset
|
1269 |
790c076cd4a2
graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents:
28955
diff
changeset
|
1270 # only set graph styling if HGPLAIN is not set. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1271 if ui.plain(b'graph'): |
28999
790c076cd4a2
graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents:
28955
diff
changeset
|
1272 # set all edge styles to |, the default pre-3.8 behaviour |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1273 styles.update(dict.fromkeys(styles, b'|')) |
28999
790c076cd4a2
graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents:
28955
diff
changeset
|
1274 else: |
790c076cd4a2
graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents:
28955
diff
changeset
|
1275 edgetypes = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1276 b'parent': graphmod.PARENT, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1277 b'grandparent': graphmod.GRANDPARENT, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1278 b'missing': graphmod.MISSINGPARENT, |
28999
790c076cd4a2
graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents:
28955
diff
changeset
|
1279 } |
790c076cd4a2
graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents:
28955
diff
changeset
|
1280 for name, key in edgetypes.items(): |
790c076cd4a2
graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents:
28955
diff
changeset
|
1281 # experimental config: experimental.graphstyle.* |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1282 styles[key] = ui.config( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1283 b'experimental', b'graphstyle.%s' % name, styles[key] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1284 ) |
28999
790c076cd4a2
graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents:
28955
diff
changeset
|
1285 if not styles[key]: |
790c076cd4a2
graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents:
28955
diff
changeset
|
1286 styles[key] = None |
790c076cd4a2
graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents:
28955
diff
changeset
|
1287 |
790c076cd4a2
graphmod: disable graph styling when HGPLAIN is set (issue5212)
Martijn Pieters <mjpieters@fb.com>
parents:
28955
diff
changeset
|
1288 # experimental config: experimental.graphshorten |
43796
faa8a59f4a06
graphlog: change state dict to attr struct
Yuya Nishihara <yuya@tcha.org>
parents:
43794
diff
changeset
|
1289 state.graphshorten = ui.configbool(b'experimental', b'graphshorten') |
28891
ac30adb260ea
graphmod: shorten graph
santiagopim <santiagopim@gmail.com>
parents:
28861
diff
changeset
|
1290 |
44379
14d0e89520a2
graphlog: use '%' for other context in merge conflict
Martin von Zweigbergk <martinvonz@google.com>
parents:
43848
diff
changeset
|
1291 formatnode_cache = {} |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1292 for rev, type, ctx, parents in dag: |
44379
14d0e89520a2
graphlog: use '%' for other context in merge conflict
Martin von Zweigbergk <martinvonz@google.com>
parents:
43848
diff
changeset
|
1293 char = formatnode(repo, ctx, formatnode_cache) |
42519
a68350a7fc55
log: pass getcopies() function instead of getrenamed() to displayer (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
42517
diff
changeset
|
1294 copies = getcopies(ctx) if getcopies else None |
33879
6f6c87888b22
log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents:
33877
diff
changeset
|
1295 edges = edgefn(type, char, state, rev, parents) |
6f6c87888b22
log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents:
33877
diff
changeset
|
1296 firstedge = next(edges) |
6f6c87888b22
log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents:
33877
diff
changeset
|
1297 width = firstedge[2] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1298 displayer.show( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1299 ctx, copies=copies, graphwidth=width, **pycompat.strkwargs(props) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1300 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1301 lines = displayer.hunk.pop(rev).split(b'\n') |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1302 if not lines[-1]: |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1303 del lines[-1] |
25763
60c791592aa7
changeset_printer: change flush() to accept ctx instead of rev
Yuya Nishihara <yuya@tcha.org>
parents:
25762
diff
changeset
|
1304 displayer.flush(ctx) |
33879
6f6c87888b22
log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents:
33877
diff
changeset
|
1305 for type, char, width, coldata in itertools.chain([firstedge], edges): |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1306 graphmod.ascii(ui, state, type, char, lines, coldata) |
33879
6f6c87888b22
log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents:
33877
diff
changeset
|
1307 lines = [] |
17180
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1308 displayer.close() |
ae0629161090
graphlog: extract revset/support functions into cmdutil
Patrick Mezard <patrick@mezard.eu>
parents:
17059
diff
changeset
|
1309 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1310 |
36236
7bc10d3f68b4
log: factor out function to feed revisions to displayer
Yuya Nishihara <yuya@tcha.org>
parents:
36234
diff
changeset
|
1311 def displaygraphrevs(ui, repo, revs, displayer, getrenamed): |
17181
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1312 revdag = graphmod.dagwalker(repo, revs) |
36041
fcde8946c553
logcmdutil: hold makefilematcher/makehunksfilter() by changesetpriner (API)
Yuya Nishihara <yuya@tcha.org>
parents:
36040
diff
changeset
|
1313 displaygraph(ui, repo, revdag, displayer, graphmod.asciiedges, getrenamed) |
17181
6f71167292f2
log: support --graph without graphlog extension
Patrick Mezard <patrick@mezard.eu>
parents:
17180
diff
changeset
|
1314 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1315 |
42519
a68350a7fc55
log: pass getcopies() function instead of getrenamed() to displayer (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
42517
diff
changeset
|
1316 def displayrevs(ui, repo, revs, displayer, getcopies): |
36236
7bc10d3f68b4
log: factor out function to feed revisions to displayer
Yuya Nishihara <yuya@tcha.org>
parents:
36234
diff
changeset
|
1317 for rev in revs: |
7bc10d3f68b4
log: factor out function to feed revisions to displayer
Yuya Nishihara <yuya@tcha.org>
parents:
36234
diff
changeset
|
1318 ctx = repo[rev] |
42519
a68350a7fc55
log: pass getcopies() function instead of getrenamed() to displayer (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
42517
diff
changeset
|
1319 copies = getcopies(ctx) if getcopies else None |
36236
7bc10d3f68b4
log: factor out function to feed revisions to displayer
Yuya Nishihara <yuya@tcha.org>
parents:
36234
diff
changeset
|
1320 displayer.show(ctx, copies=copies) |
7bc10d3f68b4
log: factor out function to feed revisions to displayer
Yuya Nishihara <yuya@tcha.org>
parents:
36234
diff
changeset
|
1321 displayer.flush(ctx) |
7bc10d3f68b4
log: factor out function to feed revisions to displayer
Yuya Nishihara <yuya@tcha.org>
parents:
36234
diff
changeset
|
1322 displayer.close() |
7bc10d3f68b4
log: factor out function to feed revisions to displayer
Yuya Nishihara <yuya@tcha.org>
parents:
36234
diff
changeset
|
1323 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1324 |
17182
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1325 def checkunsupportedgraphflags(pats, opts): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1326 for op in [b"newest_first"]: |
17182
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1327 if op in opts and opts[op]: |
48580
91017508a785
logcmdutil: raise `InputError` on bad CLI arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
48130
diff
changeset
|
1328 raise error.InputError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1329 _(b"-G/--graph option is incompatible with --%s") |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1330 % op.replace(b"_", b"-") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1331 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42519
diff
changeset
|
1332 |
17182
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1333 |
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1334 def graphrevs(repo, nodes, opts): |
35927
572f36e9a780
logcmdutil: drop redundant "log" from function names (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35926
diff
changeset
|
1335 limit = getlimit(opts) |
17182
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1336 nodes.reverse() |
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1337 if limit is not None: |
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1338 nodes = nodes[:limit] |
cdf1532d89c6
incoming/outgoing: handle --graph in core
Patrick Mezard <patrick@mezard.eu>
parents:
17181
diff
changeset
|
1339 return graphmod.nodes(repo, nodes) |