Mercurial > hg-stable
annotate mercurial/scmutil.py @ 49037:642e31cb55f0
py3: use class X: instead of class X(object):
The inheritance from object is implied in Python 3. So this should
be equivalent.
This change was generated via an automated search and replace. So there
may have been some accidental changes.
Differential Revision: https://phab.mercurial-scm.org/D12352
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 21 Feb 2022 13:08:28 -0700 |
parents | 06de08b36c82 |
children | 63fd0282ad40 |
rev | line source |
---|---|
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
1 # scmutil.py - Mercurial core utility functions |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
2 # |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents:
46711
diff
changeset
|
3 # Copyright Olivia Mackall <olivia@selenic.com> |
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
4 # |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
7 |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
8 |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
9 import errno |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
10 import glob |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
11 import os |
41661
f8b18583049f
add: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41660
diff
changeset
|
12 import posixpath |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
13 import re |
34462
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34461
diff
changeset
|
14 import subprocess |
33252
53b3a1968aa6
obsolete: reports the number of local changeset obsoleted when unbundling
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33246
diff
changeset
|
15 import weakref |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
16 |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
17 from .i18n import _ |
32678
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32676
diff
changeset
|
18 from .node import ( |
37528
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
19 bin, |
33100
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
20 hex, |
39899
d739f423bf06
repo: look up nullrev context by revnum, not symbolic name
Martin von Zweigbergk <martinvonz@google.com>
parents:
39896
diff
changeset
|
21 nullrev, |
34334
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34158
diff
changeset
|
22 short, |
32678
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32676
diff
changeset
|
23 wdirrev, |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32676
diff
changeset
|
24 ) |
43089
c59eb1560c44
py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
25 from .pycompat import getattr |
43698
c5548b0b6847
scmutil: convert status data object from a tuple to an attrs (API)
Augie Fackler <augie@google.com>
parents:
43677
diff
changeset
|
26 from .thirdparty import attr |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
27 from . import ( |
41942
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
28 copies as copiesmod, |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
29 encoding, |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
30 error, |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
31 match as matchmod, |
33100
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
32 obsolete, |
33252
53b3a1968aa6
obsolete: reports the number of local changeset obsoleted when unbundling
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33246
diff
changeset
|
33 obsutil, |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
34 pathutil, |
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
35 phases, |
39254
7a759ad2d06d
shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
39125
diff
changeset
|
36 policy, |
30318
af7c60988f6e
py3: make scmutil.rcpath() return bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30109
diff
changeset
|
37 pycompat, |
45493
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
38 requirements as requirementsmod, |
31044
0b8356705de6
revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30644
diff
changeset
|
39 revsetlang, |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
40 similar, |
39902
a477679f6323
pullreport: skip filtered revs instead of obsolete ones
Boris Feld <boris.feld@octobus.net>
parents:
39899
diff
changeset
|
41 smartset, |
34457
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
42 url, |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
43 util, |
34543
6fad8059a970
scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents:
34542
diff
changeset
|
44 vfs, |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
45 ) |
18690
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
18678
diff
changeset
|
46 |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36844
diff
changeset
|
47 from .utils import ( |
44060
a61287a95dc3
core: migrate uses of hashlib.sha1 to hashutil.sha1
Augie Fackler <augie@google.com>
parents:
44039
diff
changeset
|
48 hashutil, |
37123
a8a902d7176e
procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
37097
diff
changeset
|
49 procutil, |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36844
diff
changeset
|
50 stringutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36844
diff
changeset
|
51 ) |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36844
diff
changeset
|
52 |
34645 | 53 if pycompat.iswindows: |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
54 from . import scmwindows as scmplatform |
18690
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
18678
diff
changeset
|
55 else: |
27482
dde3da2246f1
scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27093
diff
changeset
|
56 from . import scmposix as scmplatform |
18690
4c6f7f0dadab
scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents:
18678
diff
changeset
|
57 |
43554
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43365
diff
changeset
|
58 parsers = policy.importmod('parsers') |
44016
992f0d6e7f33
rust-index: use the new method in shortesthexnodeidprefix
Georges Racinet <georges.racinet@octobus.net>
parents:
44003
diff
changeset
|
59 rustrevlog = policy.importrust('revlog') |
39254
7a759ad2d06d
shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
39125
diff
changeset
|
60 |
30327
365812902904
scmutil: extend termwidth() to return terminal height, renamed to termsize()
Yuya Nishihara <yuya@tcha.org>
parents:
30322
diff
changeset
|
61 termsize = scmplatform.termsize |
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
62 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
63 |
43698
c5548b0b6847
scmutil: convert status data object from a tuple to an attrs (API)
Augie Fackler <augie@google.com>
parents:
43677
diff
changeset
|
64 @attr.s(slots=True, repr=False) |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49025
diff
changeset
|
65 class status: |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
66 """Struct with a list of files per status. |
43698
c5548b0b6847
scmutil: convert status data object from a tuple to an attrs (API)
Augie Fackler <augie@google.com>
parents:
43677
diff
changeset
|
67 |
c5548b0b6847
scmutil: convert status data object from a tuple to an attrs (API)
Augie Fackler <augie@google.com>
parents:
43677
diff
changeset
|
68 The 'deleted', 'unknown' and 'ignored' properties are only |
c5548b0b6847
scmutil: convert status data object from a tuple to an attrs (API)
Augie Fackler <augie@google.com>
parents:
43677
diff
changeset
|
69 relevant to the working copy. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
70 """ |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
71 |
43795
b5f183eedd98
status: fix default value of status struct
Yuya Nishihara <yuya@tcha.org>
parents:
43760
diff
changeset
|
72 modified = attr.ib(default=attr.Factory(list)) |
b5f183eedd98
status: fix default value of status struct
Yuya Nishihara <yuya@tcha.org>
parents:
43760
diff
changeset
|
73 added = attr.ib(default=attr.Factory(list)) |
b5f183eedd98
status: fix default value of status struct
Yuya Nishihara <yuya@tcha.org>
parents:
43760
diff
changeset
|
74 removed = attr.ib(default=attr.Factory(list)) |
b5f183eedd98
status: fix default value of status struct
Yuya Nishihara <yuya@tcha.org>
parents:
43760
diff
changeset
|
75 deleted = attr.ib(default=attr.Factory(list)) |
b5f183eedd98
status: fix default value of status struct
Yuya Nishihara <yuya@tcha.org>
parents:
43760
diff
changeset
|
76 unknown = attr.ib(default=attr.Factory(list)) |
b5f183eedd98
status: fix default value of status struct
Yuya Nishihara <yuya@tcha.org>
parents:
43760
diff
changeset
|
77 ignored = attr.ib(default=attr.Factory(list)) |
b5f183eedd98
status: fix default value of status struct
Yuya Nishihara <yuya@tcha.org>
parents:
43760
diff
changeset
|
78 clean = attr.ib(default=attr.Factory(list)) |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
79 |
43698
c5548b0b6847
scmutil: convert status data object from a tuple to an attrs (API)
Augie Fackler <augie@google.com>
parents:
43677
diff
changeset
|
80 def __iter__(self): |
c5548b0b6847
scmutil: convert status data object from a tuple to an attrs (API)
Augie Fackler <augie@google.com>
parents:
43677
diff
changeset
|
81 yield self.modified |
c5548b0b6847
scmutil: convert status data object from a tuple to an attrs (API)
Augie Fackler <augie@google.com>
parents:
43677
diff
changeset
|
82 yield self.added |
c5548b0b6847
scmutil: convert status data object from a tuple to an attrs (API)
Augie Fackler <augie@google.com>
parents:
43677
diff
changeset
|
83 yield self.removed |
c5548b0b6847
scmutil: convert status data object from a tuple to an attrs (API)
Augie Fackler <augie@google.com>
parents:
43677
diff
changeset
|
84 yield self.deleted |
c5548b0b6847
scmutil: convert status data object from a tuple to an attrs (API)
Augie Fackler <augie@google.com>
parents:
43677
diff
changeset
|
85 yield self.unknown |
c5548b0b6847
scmutil: convert status data object from a tuple to an attrs (API)
Augie Fackler <augie@google.com>
parents:
43677
diff
changeset
|
86 yield self.ignored |
c5548b0b6847
scmutil: convert status data object from a tuple to an attrs (API)
Augie Fackler <augie@google.com>
parents:
43677
diff
changeset
|
87 yield self.clean |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
88 |
43698
c5548b0b6847
scmutil: convert status data object from a tuple to an attrs (API)
Augie Fackler <augie@google.com>
parents:
43677
diff
changeset
|
89 def __repr__(self): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
90 return ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
91 r'<status modified=%s, added=%s, removed=%s, deleted=%s, ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
92 r'unknown=%s, ignored=%s, clean=%s>' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
93 ) % tuple(pycompat.sysstr(stringutil.pprint(v)) for v in self) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
94 |
22913
cb4449921a1d
status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22816
diff
changeset
|
95 |
20392
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
96 def itersubrepos(ctx1, ctx2): |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
97 """find subrepos in ctx1 or ctx2""" |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
98 # Create a (subpath, ctx) mapping where we prefer subpaths from |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
99 # ctx1. The subpaths from ctx2 are important when the .hgsub file |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
100 # has been modified (in ctx2) but not yet committed (in ctx1). |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
101 subpaths = dict.fromkeys(ctx2.substate, ctx2) |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
102 subpaths.update(dict.fromkeys(ctx1.substate, ctx1)) |
25418
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
103 |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
104 missing = set() |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
105 |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
106 for subpath in ctx2.substate: |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
107 if subpath not in ctx1.substate: |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
108 del subpaths[subpath] |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
109 missing.add(subpath) |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
110 |
49004
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48966
diff
changeset
|
111 for subpath, ctx in sorted(subpaths.items()): |
20392
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
112 yield subpath, ctx.sub(subpath) |
d4f804caa0ed
itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents:
20364
diff
changeset
|
113 |
25418
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
114 # Yield an empty subrepo based on ctx1 for anything only in ctx2. That way, |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
115 # status and diff will have an accurate result when it does |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
116 # 'sub.{status|diff}(rev2)'. Otherwise, the ctx2 subrepo is compared |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
117 # against itself. |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
118 for subpath in missing: |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
119 yield subpath, ctx2.nullsub(subpath, ctx1) |
c0995cd8ff6f
scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25386
diff
changeset
|
120 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
121 |
17248
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
122 def nochangesfound(ui, repo, excluded=None): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
123 """Report no changes for push/pull, excluded is None or a list of |
17248
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
124 nodes excluded from the push/pull. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
125 """ |
17248
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
126 secretlist = [] |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
127 if excluded: |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
128 for n in excluded: |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
129 ctx = repo[n] |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
130 if ctx.phase() >= phases.secret and not ctx.extinct(): |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
131 secretlist.append(n) |
6ffb35b2284c
discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents:
17201
diff
changeset
|
132 |
15993
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
133 if secretlist: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
134 ui.status( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
135 _(b"no changes found (ignored %d secret changesets)\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
136 % len(secretlist) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
137 ) |
15993
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
138 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
139 ui.status(_(b"no changes found\n")) |
15993
0b05e0bfdc1c
scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents:
15797
diff
changeset
|
140 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
141 |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
142 def callcatch(ui, func): |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
143 """call func() with global exception handling |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
144 |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
145 return func() if no exception happens. otherwise do some error handling |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
146 and return an exit code accordingly. does not handle all exceptions. |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
147 """ |
45845
21733e8c924f
errors: add config that lets user get more detailed exit codes
Martin von Zweigbergk <martinvonz@google.com>
parents:
45844
diff
changeset
|
148 coarse_exit_code = -1 |
21733e8c924f
errors: add config that lets user get more detailed exit codes
Martin von Zweigbergk <martinvonz@google.com>
parents:
45844
diff
changeset
|
149 detailed_exit_code = -1 |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
150 try: |
32041
38963a53ab0d
dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents:
31951
diff
changeset
|
151 try: |
38963a53ab0d
dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents:
31951
diff
changeset
|
152 return func() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
153 except: # re-raises |
32041
38963a53ab0d
dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents:
31951
diff
changeset
|
154 ui.traceback() |
38963a53ab0d
dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents:
31951
diff
changeset
|
155 raise |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
156 # Global exception handling, alphabetically |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
157 # Mercurial-specific first, followed by built-in and library exceptions |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
158 except error.LockHeld as inst: |
45847
e0dbfbd4062c
errors: set detailed exit code to 20 for locking errors
Martin von Zweigbergk <martinvonz@google.com>
parents:
45846
diff
changeset
|
159 detailed_exit_code = 20 |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
160 if inst.errno == errno.ETIMEDOUT: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
161 reason = _(b'timed out waiting for lock held by %r') % ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
162 pycompat.bytestr(inst.locker) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
163 ) |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
164 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
165 reason = _(b'lock held by %r') % inst.locker |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
166 ui.error( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
167 _(b"abort: %s: %s\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
168 % (inst.desc or stringutil.forcebytestr(inst.filename), reason) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
169 ) |
32088
0d892d820a51
lock: avoid unintentional lock acquisition at failure of readlock
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
32041
diff
changeset
|
170 if not inst.locker: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
171 ui.error(_(b"(lock might be very busy)\n")) |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
172 except error.LockUnavailable as inst: |
45847
e0dbfbd4062c
errors: set detailed exit code to 20 for locking errors
Martin von Zweigbergk <martinvonz@google.com>
parents:
45846
diff
changeset
|
173 detailed_exit_code = 20 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
174 ui.error( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
175 _(b"abort: could not lock %s: %s\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
176 % ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
177 inst.desc or stringutil.forcebytestr(inst.filename), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
178 encoding.strtolocal(inst.strerror), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
179 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
180 ) |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
181 except error.RepoError as inst: |
48416
8c4881c07f57
errors: use detailed exit code for RepoLookupError
Martin von Zweigbergk <martinvonz@google.com>
parents:
48415
diff
changeset
|
182 if isinstance(inst, error.RepoLookupError): |
8c4881c07f57
errors: use detailed exit code for RepoLookupError
Martin von Zweigbergk <martinvonz@google.com>
parents:
48415
diff
changeset
|
183 detailed_exit_code = 10 |
45921
95c4cca641f6
errors: remove trailing "!" from some error messages for consistency
Martin von Zweigbergk <martinvonz@google.com>
parents:
45910
diff
changeset
|
184 ui.error(_(b"abort: %s\n") % inst) |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
185 if inst.hint: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
186 ui.error(_(b"(%s)\n") % inst.hint) |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
187 except error.ResponseError as inst: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
188 ui.error(_(b"abort: %s") % inst.args[0]) |
36690
b76248e51605
scmutil: avoid using basestring and add explicit handling of unicodes
Augie Fackler <augie@google.com>
parents:
36687
diff
changeset
|
189 msg = inst.args[1] |
b76248e51605
scmutil: avoid using basestring and add explicit handling of unicodes
Augie Fackler <augie@google.com>
parents:
36687
diff
changeset
|
190 if isinstance(msg, type(u'')): |
b76248e51605
scmutil: avoid using basestring and add explicit handling of unicodes
Augie Fackler <augie@google.com>
parents:
36687
diff
changeset
|
191 msg = pycompat.sysbytes(msg) |
46711
aa2e38147e8b
wireprotov1peer: don't raise internal errors in some cases
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
46485
diff
changeset
|
192 if msg is None: |
aa2e38147e8b
wireprotov1peer: don't raise internal errors in some cases
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
46485
diff
changeset
|
193 ui.error(b"\n") |
aa2e38147e8b
wireprotov1peer: don't raise internal errors in some cases
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
46485
diff
changeset
|
194 elif not isinstance(msg, bytes): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
195 ui.error(b" %r\n" % (msg,)) |
36720
c442c4a92ae8
scmutil: fix oversight in b76248e51605c6 where I forgot to use msg
Augie Fackler <augie@google.com>
parents:
36690
diff
changeset
|
196 elif not msg: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
197 ui.error(_(b" empty string\n")) |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
198 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
199 ui.error(b"\n%r\n" % pycompat.bytestr(stringutil.ellipsis(msg))) |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
200 except error.CensoredNodeError as inst: |
45921
95c4cca641f6
errors: remove trailing "!" from some error messages for consistency
Martin von Zweigbergk <martinvonz@google.com>
parents:
45910
diff
changeset
|
201 ui.error(_(b"abort: file censored %s\n") % inst) |
32679
7b17f9de6d3e
revlog: map rev(wdirid) to WdirUnsupported exception
Yuya Nishihara <yuya@tcha.org>
parents:
32678
diff
changeset
|
202 except error.WdirUnsupported: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
203 ui.error(_(b"abort: working directory revision cannot be specified\n")) |
47304
7a769ac49637
errors: catch the new Error class in scmutil and chgserver
Martin von Zweigbergk <martinvonz@google.com>
parents:
47302
diff
changeset
|
204 except error.Error as inst: |
47300
33c0c25d0b0f
errors: let each Abort subclass define its error code
Martin von Zweigbergk <martinvonz@google.com>
parents:
47142
diff
changeset
|
205 if inst.detailed_exit_code is not None: |
33c0c25d0b0f
errors: let each Abort subclass define its error code
Martin von Zweigbergk <martinvonz@google.com>
parents:
47142
diff
changeset
|
206 detailed_exit_code = inst.detailed_exit_code |
47302
d9c71bbe20f7
errors: make InterventionRequired subclass Abort
Martin von Zweigbergk <martinvonz@google.com>
parents:
47300
diff
changeset
|
207 if inst.coarse_exit_code is not None: |
d9c71bbe20f7
errors: make InterventionRequired subclass Abort
Martin von Zweigbergk <martinvonz@google.com>
parents:
47300
diff
changeset
|
208 coarse_exit_code = inst.coarse_exit_code |
45900
600aec73f309
errors: format "abort: " text in a new Abort.format() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
45899
diff
changeset
|
209 ui.error(inst.format()) |
45844
8f07f5a9c3de
worker: raise exception instead of calling sys.exit() with child's code
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
210 except error.WorkerError as inst: |
8f07f5a9c3de
worker: raise exception instead of calling sys.exit() with child's code
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
211 # Don't print a message -- the worker already should have |
8f07f5a9c3de
worker: raise exception instead of calling sys.exit() with child's code
Martin von Zweigbergk <martinvonz@google.com>
parents:
45720
diff
changeset
|
212 return inst.status_code |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
213 except ImportError as inst: |
45921
95c4cca641f6
errors: remove trailing "!" from some error messages for consistency
Martin von Zweigbergk <martinvonz@google.com>
parents:
45910
diff
changeset
|
214 ui.error(_(b"abort: %s\n") % stringutil.forcebytestr(inst)) |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36844
diff
changeset
|
215 m = stringutil.forcebytestr(inst).split()[-1] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
216 if m in b"mpatch bdiff".split(): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
217 ui.error(_(b"(did you forget to compile extensions?)\n")) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
218 elif m in b"zlib".split(): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
219 ui.error(_(b"(is your Python install correct?)\n")) |
45857
ae00e170f2d1
errors: catch urllib errors specifically instead of using safehasattr()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45847
diff
changeset
|
220 except util.urlerr.httperror as inst: |
45858
ebee234d952a
errors: set detailed exit code to 100 for some remote errors
Martin von Zweigbergk <martinvonz@google.com>
parents:
45857
diff
changeset
|
221 detailed_exit_code = 100 |
45857
ae00e170f2d1
errors: catch urllib errors specifically instead of using safehasattr()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45847
diff
changeset
|
222 ui.error(_(b"abort: %s\n") % stringutil.forcebytestr(inst)) |
ae00e170f2d1
errors: catch urllib errors specifically instead of using safehasattr()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45847
diff
changeset
|
223 except util.urlerr.urlerror as inst: |
45858
ebee234d952a
errors: set detailed exit code to 100 for some remote errors
Martin von Zweigbergk <martinvonz@google.com>
parents:
45857
diff
changeset
|
224 detailed_exit_code = 100 |
45857
ae00e170f2d1
errors: catch urllib errors specifically instead of using safehasattr()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45847
diff
changeset
|
225 try: # usually it is in the form (errno, strerror) |
ae00e170f2d1
errors: catch urllib errors specifically instead of using safehasattr()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45847
diff
changeset
|
226 reason = inst.reason.args[1] |
ae00e170f2d1
errors: catch urllib errors specifically instead of using safehasattr()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45847
diff
changeset
|
227 except (AttributeError, IndexError): |
ae00e170f2d1
errors: catch urllib errors specifically instead of using safehasattr()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45847
diff
changeset
|
228 # it might be anything, for example a string |
ae00e170f2d1
errors: catch urllib errors specifically instead of using safehasattr()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45847
diff
changeset
|
229 reason = inst.reason |
49025
06de08b36c82
py3: use str instead of pycompat.unicode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49004
diff
changeset
|
230 if isinstance(reason, str): |
45857
ae00e170f2d1
errors: catch urllib errors specifically instead of using safehasattr()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45847
diff
changeset
|
231 # SSLError of Python 2.7.9 contains a unicode |
ae00e170f2d1
errors: catch urllib errors specifically instead of using safehasattr()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45847
diff
changeset
|
232 reason = encoding.unitolocal(reason) |
ae00e170f2d1
errors: catch urllib errors specifically instead of using safehasattr()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45847
diff
changeset
|
233 ui.error(_(b"abort: error: %s\n") % stringutil.forcebytestr(reason)) |
41443
f83b230b7fb3
dispatch: unify handler of IOError and OSError
Yuya Nishihara <yuya@tcha.org>
parents:
41442
diff
changeset
|
234 except (IOError, OSError) as inst: |
45857
ae00e170f2d1
errors: catch urllib errors specifically instead of using safehasattr()
Martin von Zweigbergk <martinvonz@google.com>
parents:
45847
diff
changeset
|
235 if ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
236 util.safehasattr(inst, b"args") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
237 and inst.args |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
238 and inst.args[0] == errno.EPIPE |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
239 ): |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
240 pass |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
241 elif getattr(inst, "strerror", None): # common IOError or OSError |
41442
b6673e9bdcf6
dispatch: quote filename in IOError as well
Yuya Nishihara <yuya@tcha.org>
parents:
41441
diff
changeset
|
242 if getattr(inst, "filename", None) is not None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
243 ui.error( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
244 _(b"abort: %s: '%s'\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
245 % ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
246 encoding.strtolocal(inst.strerror), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
247 stringutil.forcebytestr(inst.filename), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
248 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
249 ) |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
250 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
251 ui.error(_(b"abort: %s\n") % encoding.strtolocal(inst.strerror)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
252 else: # suspicious IOError |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
253 raise |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
254 except MemoryError: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
255 ui.error(_(b"abort: out of memory\n")) |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
256 except SystemExit as inst: |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
257 # Commands shouldn't sys.exit directly, but give a return code. |
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
258 # Just in case catch this and and pass exit code to caller. |
45845
21733e8c924f
errors: add config that lets user get more detailed exit codes
Martin von Zweigbergk <martinvonz@google.com>
parents:
45844
diff
changeset
|
259 detailed_exit_code = 254 |
21733e8c924f
errors: add config that lets user get more detailed exit codes
Martin von Zweigbergk <martinvonz@google.com>
parents:
45844
diff
changeset
|
260 coarse_exit_code = inst.code |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
261 |
45845
21733e8c924f
errors: add config that lets user get more detailed exit codes
Martin von Zweigbergk <martinvonz@google.com>
parents:
45844
diff
changeset
|
262 if ui.configbool(b'ui', b'detailed-exit-code'): |
21733e8c924f
errors: add config that lets user get more detailed exit codes
Martin von Zweigbergk <martinvonz@google.com>
parents:
45844
diff
changeset
|
263 return detailed_exit_code |
21733e8c924f
errors: add config that lets user get more detailed exit codes
Martin von Zweigbergk <martinvonz@google.com>
parents:
45844
diff
changeset
|
264 else: |
21733e8c924f
errors: add config that lets user get more detailed exit codes
Martin von Zweigbergk <martinvonz@google.com>
parents:
45844
diff
changeset
|
265 return coarse_exit_code |
30529
4338f87dbf6f
dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents:
30427
diff
changeset
|
266 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
267 |
17821
361ab1e2086f
scmutil: add bad character checking to checknewlabel
Kevin Bullock <kbullock@ringworld.org>
parents:
17817
diff
changeset
|
268 def checknewlabel(repo, lbl, kind): |
19070
290a61833b99
translations: change label integer error to not specify the kind of label
Durham Goode <durham@fb.com>
parents:
18951
diff
changeset
|
269 # Do not use the "kind" parameter in ui output. |
290a61833b99
translations: change label integer error to not specify the kind of label
Durham Goode <durham@fb.com>
parents:
18951
diff
changeset
|
270 # It makes strings difficult to translate. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
271 if lbl in [b'tip', b'.', b'null']: |
45864
f96fa4de5055
errors: use InputError for errors about bad label names (tags etc)
Martin von Zweigbergk <martinvonz@google.com>
parents:
45863
diff
changeset
|
272 raise error.InputError(_(b"the name '%s' is reserved") % lbl) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
273 for c in (b':', b'\0', b'\n', b'\r'): |
17821
361ab1e2086f
scmutil: add bad character checking to checknewlabel
Kevin Bullock <kbullock@ringworld.org>
parents:
17817
diff
changeset
|
274 if c in lbl: |
45864
f96fa4de5055
errors: use InputError for errors about bad label names (tags etc)
Martin von Zweigbergk <martinvonz@google.com>
parents:
45863
diff
changeset
|
275 raise error.InputError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
276 _(b"%r cannot be used in a name") % pycompat.bytestr(c) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
277 ) |
18566
341868ef0cf6
bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents:
18560
diff
changeset
|
278 try: |
341868ef0cf6
bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents:
18560
diff
changeset
|
279 int(lbl) |
45864
f96fa4de5055
errors: use InputError for errors about bad label names (tags etc)
Martin von Zweigbergk <martinvonz@google.com>
parents:
45863
diff
changeset
|
280 raise error.InputError(_(b"cannot use an integer as a name")) |
18566
341868ef0cf6
bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents:
18560
diff
changeset
|
281 except ValueError: |
341868ef0cf6
bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents:
18560
diff
changeset
|
282 pass |
36183
4f3e989536c3
label: enforce the lack of leading or trailing white space
Boris Feld <boris.feld@octobus.net>
parents:
36175
diff
changeset
|
283 if lbl.strip() != lbl: |
45864
f96fa4de5055
errors: use InputError for errors about bad label names (tags etc)
Martin von Zweigbergk <martinvonz@google.com>
parents:
45863
diff
changeset
|
284 raise error.InputError( |
f96fa4de5055
errors: use InputError for errors about bad label names (tags etc)
Martin von Zweigbergk <martinvonz@google.com>
parents:
45863
diff
changeset
|
285 _(b"leading or trailing whitespace in name %r") % lbl |
f96fa4de5055
errors: use InputError for errors about bad label names (tags etc)
Martin von Zweigbergk <martinvonz@google.com>
parents:
45863
diff
changeset
|
286 ) |
17817
b17be267b59c
scmutil: add function to validate new branch, tag, and bookmark names
Kevin Bullock <kbullock@ringworld.org>
parents:
17768
diff
changeset
|
287 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
288 |
13974
23f2736abce3
move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13973
diff
changeset
|
289 def checkfilename(f): |
23f2736abce3
move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13973
diff
changeset
|
290 '''Check that the filename f is an acceptable filename for a tracked file''' |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
291 if b'\r' in f or b'\n' in f: |
45863
3175b0e0058b
errors: use InputError for errors about bad paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
45860
diff
changeset
|
292 raise error.InputError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
293 _(b"'\\n' and '\\r' disallowed in filenames: %r") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
294 % pycompat.bytestr(f) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
295 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
296 |
13974
23f2736abce3
move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13973
diff
changeset
|
297 |
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
298 def checkportable(ui, f): |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
299 '''Check if filename f is portable and warn or abort depending on config''' |
13974
23f2736abce3
move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13973
diff
changeset
|
300 checkfilename(f) |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
301 abort, warn = checkportabilityalert(ui) |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
302 if abort or warn: |
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
303 msg = util.checkwinfilename(f) |
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
304 if msg: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
305 msg = b"%s: %s" % (msg, procutil.shellquote(f)) |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
306 if abort: |
45863
3175b0e0058b
errors: use InputError for errors about bad paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
45860
diff
changeset
|
307 raise error.InputError(msg) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
308 ui.warn(_(b"warning: %s\n") % msg) |
14068
04ce8fa1015d
add: notify when adding a file that would cause a case-folding collision
Kevin Gessner <kevin@kevingessner.com>
parents:
14067
diff
changeset
|
309 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
310 |
14067
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
311 def checkportabilityalert(ui): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
312 """check if the user's config requests nothing, a warning, or abort for |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
313 non-portable filenames""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
314 val = ui.config(b'ui', b'portablefilenames') |
14067
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
315 lval = val.lower() |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36844
diff
changeset
|
316 bval = stringutil.parsebool(val) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
317 abort = pycompat.iswindows or lval == b'abort' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
318 warn = bval or lval == b'warn' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
319 if bval is None and not (warn or abort or lval == b'ignore'): |
13962
8b252e826c68
add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff
changeset
|
320 raise error.ConfigError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
321 _(b"ui.portablefilenames value is invalid ('%s')") % val |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
322 ) |
14067
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
323 return abort, warn |
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
324 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
325 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49025
diff
changeset
|
326 class casecollisionauditor: |
17201
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
327 def __init__(self, ui, abort, dirstate): |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
328 self._ui = ui |
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
329 self._abort = abort |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
330 allfiles = b'\0'.join(dirstate) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
331 self._loweredfiles = set(encoding.lower(allfiles).split(b'\0')) |
17201
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
332 self._dirstate = dirstate |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
333 # The purpose of _newfiles is so that we don't complain about |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
334 # case collisions if someone were to call this object with the |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
335 # same filename twice. |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
336 self._newfiles = set() |
14067
e88a4958a6b7
scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents:
13986
diff
changeset
|
337 |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
338 def __call__(self, f): |
20006
9276014db865
scmutil: skip checks in "casecollisionauditor" if filename is already checked
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19900
diff
changeset
|
339 if f in self._newfiles: |
9276014db865
scmutil: skip checks in "casecollisionauditor" if filename is already checked
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19900
diff
changeset
|
340 return |
14980
28e98a8b173d
i18n: use UTF-8 string to lower filename for case collision check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
14861
diff
changeset
|
341 fl = encoding.lower(f) |
20006
9276014db865
scmutil: skip checks in "casecollisionauditor" if filename is already checked
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19900
diff
changeset
|
342 if fl in self._loweredfiles and f not in self._dirstate: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
343 msg = _(b'possible case-folding collision for %s') % f |
14138
c18204fd35b0
scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents:
14097
diff
changeset
|
344 if self._abort: |
48415
0b8e076e878c
errors: use detailed exit code for detected case-collision
Martin von Zweigbergk <martinvonz@google.com>
parents:
48315
diff
changeset
|
345 raise error.StateError(msg) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
346 self._ui.warn(_(b"warning: %s\n") % msg) |
17201
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
347 self._loweredfiles.add(fl) |
afd75476939e
scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents:
17161
diff
changeset
|
348 self._newfiles.add(f) |
13970
d13913355390
move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13962
diff
changeset
|
349 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
350 |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
351 def filteredhash(repo, maxrev, needobsolete=False): |
24723
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
352 """build hash of filtered revisions in the current repoview. |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
353 |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
354 Multiple caches perform up-to-date validation by checking that the |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
355 tiprev and tipnode stored in the cache file match the current repository. |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
356 However, this is not sufficient for validating repoviews because the set |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
357 of revisions in the view may change without the repository tiprev and |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
358 tipnode changing. |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
359 |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
360 This function hashes all the revs filtered from the view (and, optionally, |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
361 all obsolete revs) up to maxrev and returns that SHA-1 digest. |
24723
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
362 """ |
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
363 cl = repo.changelog |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
364 if needobsolete: |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
365 obsrevs = obsolete.getrevs(repo, b'obsolete') |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
366 if not cl.filteredrevs and not obsrevs: |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
367 return None |
48737
c7e675848027
scmutil: obsrevs is already a frozenset
Anton Shestakov <av6@dwimlabs.net>
parents:
48701
diff
changeset
|
368 key = (maxrev, hash(cl.filteredrevs), hash(obsrevs)) |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
369 else: |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
370 if not cl.filteredrevs: |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
371 return None |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
372 key = maxrev |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
373 obsrevs = frozenset() |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
374 |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
375 result = cl._filteredrevs_hashcache.get(key) |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
376 if not result: |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
377 revs = sorted(r for r in cl.filteredrevs | obsrevs if r <= maxrev) |
45523
89f0d9f87701
branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents:
45494
diff
changeset
|
378 if revs: |
89f0d9f87701
branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents:
45494
diff
changeset
|
379 s = hashutil.sha1() |
89f0d9f87701
branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents:
45494
diff
changeset
|
380 for rev in revs: |
89f0d9f87701
branchmap: add a cache validation cache, avoid expensive re-hash on every use
Kyle Lippincott <spectral@google.com>
parents:
45494
diff
changeset
|
381 s.update(b'%d;' % rev) |
48701
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
382 result = s.digest() |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
383 cl._filteredrevs_hashcache[key] = result |
f8f2ecdde4b5
branchmap: skip obsolete revisions while computing heads
Anton Shestakov <av6@dwimlabs.net>
parents:
48499
diff
changeset
|
384 return result |
24723
467a33142425
repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24693
diff
changeset
|
385 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
386 |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
387 def walkrepos(path, followsym=False, seen_dirs=None, recurse=False): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
388 """yield every hg repository under path, always recursively. |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
389 The recurse flag will only control recursion into repo working dirs""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
390 |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
391 def errhandler(err): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
392 if err.filename == path: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
393 raise err |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
394 |
14961
5523529bd1af
walkrepos: use getattr instead of hasattr for samestat
Augie Fackler <durin42@gmail.com>
parents:
14928
diff
changeset
|
395 samestat = getattr(os.path, 'samestat', None) |
5523529bd1af
walkrepos: use getattr instead of hasattr for samestat
Augie Fackler <durin42@gmail.com>
parents:
14928
diff
changeset
|
396 if followsym and samestat is not None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
397 |
14227
94985b5a8278
scmutil: rename local function _add_dir_if_not_there
Adrian Buehlmann <adrian@cadifra.com>
parents:
14226
diff
changeset
|
398 def adddir(dirlst, dirname): |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
399 dirstat = os.stat(dirname) |
36371
ddd9474d2e08
walkrepos: don't reimplement any()
Martin von Zweigbergk <martinvonz@google.com>
parents:
36346
diff
changeset
|
400 match = any(samestat(dirstat, lstdirstat) for lstdirstat in dirlst) |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
401 if not match: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
402 dirlst.append(dirstat) |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
403 return not match |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
404 |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
405 else: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
406 followsym = False |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
407 |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
408 if (seen_dirs is None) and followsym: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
409 seen_dirs = [] |
14227
94985b5a8278
scmutil: rename local function _add_dir_if_not_there
Adrian Buehlmann <adrian@cadifra.com>
parents:
14226
diff
changeset
|
410 adddir(seen_dirs, path) |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
411 for root, dirs, files in os.walk(path, topdown=True, onerror=errhandler): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
412 dirs.sort() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
413 if b'.hg' in dirs: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
414 yield root # found a repository |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
415 qroot = os.path.join(root, b'.hg', b'patches') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
416 if os.path.isdir(os.path.join(qroot, b'.hg')): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
417 yield qroot # we have a patch queue repo here |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
418 if recurse: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
419 # avoid recursing inside the .hg directory |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
420 dirs.remove(b'.hg') |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
421 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
422 dirs[:] = [] # don't descend further |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
423 elif followsym: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
424 newdirs = [] |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
425 for d in dirs: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
426 fname = os.path.join(root, d) |
14227
94985b5a8278
scmutil: rename local function _add_dir_if_not_there
Adrian Buehlmann <adrian@cadifra.com>
parents:
14226
diff
changeset
|
427 if adddir(seen_dirs, fname): |
13975
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
428 if os.path.islink(fname): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
429 for hgname in walkrepos(fname, True, seen_dirs): |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
430 yield hgname |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
431 else: |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
432 newdirs.append(d) |
938fbeacac84
move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13974
diff
changeset
|
433 dirs[:] = newdirs |
13984
af60153b5e3b
move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents:
13975
diff
changeset
|
434 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
435 |
32678
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32676
diff
changeset
|
436 def binnode(ctx): |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32676
diff
changeset
|
437 """Return binary node id for a given basectx""" |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32676
diff
changeset
|
438 node = ctx.node() |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32676
diff
changeset
|
439 if node is None: |
47055
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46976
diff
changeset
|
440 return ctx.repo().nodeconstants.wdirid |
32678
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32676
diff
changeset
|
441 return node |
55ff67ffcead
scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents:
32676
diff
changeset
|
442 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
443 |
32676
4bec8cce6a09
scmutil: pass ctx object to intrev()
Yuya Nishihara <yuya@tcha.org>
parents:
32310
diff
changeset
|
444 def intrev(ctx): |
4bec8cce6a09
scmutil: pass ctx object to intrev()
Yuya Nishihara <yuya@tcha.org>
parents:
32310
diff
changeset
|
445 """Return integer for a given basectx that can be used in comparison or |
24582
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
446 arithmetic operation""" |
32676
4bec8cce6a09
scmutil: pass ctx object to intrev()
Yuya Nishihara <yuya@tcha.org>
parents:
32310
diff
changeset
|
447 rev = ctx.rev() |
24582
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
448 if rev is None: |
25739
3dabc9b7494a
changeset_printer: use node.wdirrev to calculate meaningful parentrevs
Yuya Nishihara <yuya@tcha.org>
parents:
25660
diff
changeset
|
449 return wdirrev |
24582
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
450 return rev |
56fff44cce98
scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents:
24447
diff
changeset
|
451 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
452 |
34334
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34158
diff
changeset
|
453 def formatchangeid(ctx): |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34158
diff
changeset
|
454 """Format changectx as '{rev}:{node|formatnode}', which is the default |
35928
c8e2d6ed1f9e
cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents:
35748
diff
changeset
|
455 template provided by logcmdutil.changesettemplater""" |
34334
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34158
diff
changeset
|
456 repo = ctx.repo() |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34158
diff
changeset
|
457 return formatrevnode(repo.ui, intrev(ctx), binnode(ctx)) |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34158
diff
changeset
|
458 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
459 |
34334
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34158
diff
changeset
|
460 def formatrevnode(ui, rev, node): |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34158
diff
changeset
|
461 """Format given revision and node depending on the current verbosity""" |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34158
diff
changeset
|
462 if ui.debugflag: |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34158
diff
changeset
|
463 hexfunc = hex |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34158
diff
changeset
|
464 else: |
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34158
diff
changeset
|
465 hexfunc = short |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
466 return b'%d:%s' % (rev, hexfunc(node)) |
34334
4647e0a8d3d7
scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents:
34158
diff
changeset
|
467 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
468 |
37678
5f8f013e7d52
scmutil: rename resolvepartialhexnodeid() to resolvehexnodeidprefix()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37677
diff
changeset
|
469 def resolvehexnodeidprefix(repo, prefix): |
44887
62435a5b46fe
revisions: parse "x123" as "nodeid starting with 123" without prefixhexnode
Martin von Zweigbergk <martinvonz@google.com>
parents:
44558
diff
changeset
|
470 if prefix.startswith(b'x'): |
38894
7848f284b211
revisions: allow "x123" to refer to nodeid prefix "123"
Martin von Zweigbergk <martinvonz@google.com>
parents:
38893
diff
changeset
|
471 prefix = prefix[1:] |
38881
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
472 try: |
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
473 # Uses unfiltered repo because it's faster when prefix is ambiguous/ |
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
474 # This matches the shortesthexnodeidprefix() function below. |
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
475 node = repo.unfiltered().changelog._partialmatch(prefix) |
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
476 except error.AmbiguousPrefixLookupError: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
477 revset = repo.ui.config( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
478 b'experimental', b'revisions.disambiguatewithin' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
479 ) |
38881
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
480 if revset: |
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
481 # Clear config to avoid infinite recursion |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
482 configoverrides = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
483 (b'experimental', b'revisions.disambiguatewithin'): None |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
484 } |
38881
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
485 with repo.ui.configoverride(configoverrides): |
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
486 revs = repo.anyrevs([revset], user=True) |
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
487 matches = [] |
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
488 for rev in revs: |
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
489 node = repo.changelog.node(rev) |
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
490 if hex(node).startswith(prefix): |
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
491 matches.append(node) |
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
492 if len(matches) == 1: |
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
493 return matches[0] |
503f936489dd
lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38880
diff
changeset
|
494 raise |
37504
901e749ca0e1
context: extract partial nodeid lookup method to scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
37463
diff
changeset
|
495 if node is None: |
901e749ca0e1
context: extract partial nodeid lookup method to scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
37463
diff
changeset
|
496 return |
901e749ca0e1
context: extract partial nodeid lookup method to scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
37463
diff
changeset
|
497 repo.changelog.rev(node) # make sure node isn't filtered |
901e749ca0e1
context: extract partial nodeid lookup method to scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
37463
diff
changeset
|
498 return node |
901e749ca0e1
context: extract partial nodeid lookup method to scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
37463
diff
changeset
|
499 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
500 |
38893
531b86cc8fb3
shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents:
38892
diff
changeset
|
501 def mayberevnum(repo, prefix): |
531b86cc8fb3
shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents:
38892
diff
changeset
|
502 """Checks if the given prefix may be mistaken for a revision number""" |
531b86cc8fb3
shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents:
38892
diff
changeset
|
503 try: |
531b86cc8fb3
shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents:
38892
diff
changeset
|
504 i = int(prefix) |
531b86cc8fb3
shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents:
38892
diff
changeset
|
505 # if we are a pure int, then starting with zero will not be |
531b86cc8fb3
shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents:
38892
diff
changeset
|
506 # confused as a rev; or, obviously, if the int is larger |
40341
d916ed3ca951
revisions: when using prefixhexnode, ensure we prefix "0"
Kyle Lippincott <spectral@google.com>
parents:
40167
diff
changeset
|
507 # than the value of the tip rev. We still need to disambiguate if |
d916ed3ca951
revisions: when using prefixhexnode, ensure we prefix "0"
Kyle Lippincott <spectral@google.com>
parents:
40167
diff
changeset
|
508 # prefix == '0', since that *is* a valid revnum. |
d916ed3ca951
revisions: when using prefixhexnode, ensure we prefix "0"
Kyle Lippincott <spectral@google.com>
parents:
40167
diff
changeset
|
509 if (prefix != b'0' and prefix[0:1] == b'0') or i >= len(repo): |
38893
531b86cc8fb3
shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents:
38892
diff
changeset
|
510 return False |
531b86cc8fb3
shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents:
38892
diff
changeset
|
511 return True |
531b86cc8fb3
shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents:
38892
diff
changeset
|
512 except ValueError: |
531b86cc8fb3
shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents:
38892
diff
changeset
|
513 return False |
531b86cc8fb3
shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents:
38892
diff
changeset
|
514 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
515 |
38892
3588e41f796d
shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38882
diff
changeset
|
516 def shortesthexnodeidprefix(repo, node, minlength=1, cache=None): |
3588e41f796d
shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38882
diff
changeset
|
517 """Find the shortest unambiguous prefix that matches hexnode. |
3588e41f796d
shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38882
diff
changeset
|
518 |
3588e41f796d
shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38882
diff
changeset
|
519 If "cache" is not None, it must be a dictionary that can be used for |
3588e41f796d
shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38882
diff
changeset
|
520 caching between calls to this method. |
3588e41f796d
shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38882
diff
changeset
|
521 """ |
37708
8e8541610d85
scmutil: make shortesthexnodeidprefix() use unfiltered repo
Martin von Zweigbergk <martinvonz@google.com>
parents:
37680
diff
changeset
|
522 # _partialmatch() of filtered changelog could take O(len(repo)) time, |
8e8541610d85
scmutil: make shortesthexnodeidprefix() use unfiltered repo
Martin von Zweigbergk <martinvonz@google.com>
parents:
37680
diff
changeset
|
523 # which would be unacceptably slow. so we look for hash collision in |
8e8541610d85
scmutil: make shortesthexnodeidprefix() use unfiltered repo
Martin von Zweigbergk <martinvonz@google.com>
parents:
37680
diff
changeset
|
524 # unfiltered space, which means some hashes may be slightly longer. |
38015
3ac950cd5978
shortest: move revnum-disambiguation out of revlog
Martin von Zweigbergk <martinvonz@google.com>
parents:
38004
diff
changeset
|
525 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
526 minlength = max(minlength, 1) |
40403
bf249bb60087
shortest: never emit 0-length prefix even if unique
Martin von Zweigbergk <martinvonz@google.com>
parents:
40367
diff
changeset
|
527 |
38015
3ac950cd5978
shortest: move revnum-disambiguation out of revlog
Martin von Zweigbergk <martinvonz@google.com>
parents:
38004
diff
changeset
|
528 def disambiguate(prefix): |
3ac950cd5978
shortest: move revnum-disambiguation out of revlog
Martin von Zweigbergk <martinvonz@google.com>
parents:
38004
diff
changeset
|
529 """Disambiguate against revnums.""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
530 if repo.ui.configbool(b'experimental', b'revisions.prefixhexnode'): |
38895
a01200b25da6
shortest: use 'x' prefix to disambiguate from revnum if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
38894
diff
changeset
|
531 if mayberevnum(repo, prefix): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
532 return b'x' + prefix |
38895
a01200b25da6
shortest: use 'x' prefix to disambiguate from revnum if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
38894
diff
changeset
|
533 else: |
a01200b25da6
shortest: use 'x' prefix to disambiguate from revnum if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
38894
diff
changeset
|
534 return prefix |
a01200b25da6
shortest: use 'x' prefix to disambiguate from revnum if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
38894
diff
changeset
|
535 |
38015
3ac950cd5978
shortest: move revnum-disambiguation out of revlog
Martin von Zweigbergk <martinvonz@google.com>
parents:
38004
diff
changeset
|
536 hexnode = hex(node) |
38023
5ac72e07692a
shortest: avoid magic number "41"
Martin von Zweigbergk <martinvonz@google.com>
parents:
38015
diff
changeset
|
537 for length in range(len(prefix), len(hexnode) + 1): |
38015
3ac950cd5978
shortest: move revnum-disambiguation out of revlog
Martin von Zweigbergk <martinvonz@google.com>
parents:
38004
diff
changeset
|
538 prefix = hexnode[:length] |
38893
531b86cc8fb3
shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents:
38892
diff
changeset
|
539 if not mayberevnum(repo, prefix): |
38015
3ac950cd5978
shortest: move revnum-disambiguation out of revlog
Martin von Zweigbergk <martinvonz@google.com>
parents:
38004
diff
changeset
|
540 return prefix |
3ac950cd5978
shortest: move revnum-disambiguation out of revlog
Martin von Zweigbergk <martinvonz@google.com>
parents:
38004
diff
changeset
|
541 |
38893
531b86cc8fb3
shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents:
38892
diff
changeset
|
542 cl = repo.unfiltered().changelog |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
543 revset = repo.ui.config(b'experimental', b'revisions.disambiguatewithin') |
38882
6f7c9527030b
scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38881
diff
changeset
|
544 if revset: |
38892
3588e41f796d
shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38882
diff
changeset
|
545 revs = None |
3588e41f796d
shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38882
diff
changeset
|
546 if cache is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
547 revs = cache.get(b'disambiguationrevset') |
38892
3588e41f796d
shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38882
diff
changeset
|
548 if revs is None: |
3588e41f796d
shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38882
diff
changeset
|
549 revs = repo.anyrevs([revset], user=True) |
3588e41f796d
shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38882
diff
changeset
|
550 if cache is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
551 cache[b'disambiguationrevset'] = revs |
38882
6f7c9527030b
scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38881
diff
changeset
|
552 if cl.rev(node) in revs: |
6f7c9527030b
scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38881
diff
changeset
|
553 hexnode = hex(node) |
39254
7a759ad2d06d
shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
39125
diff
changeset
|
554 nodetree = None |
7a759ad2d06d
shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
39125
diff
changeset
|
555 if cache is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
556 nodetree = cache.get(b'disambiguationnodetree') |
39254
7a759ad2d06d
shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
39125
diff
changeset
|
557 if not nodetree: |
43917
f2de8dc9c52f
nodetree: simplify a conditionnal in shortesthexnodeidprefix
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43795
diff
changeset
|
558 if util.safehasattr(parsers, 'nodetree'): |
f2de8dc9c52f
nodetree: simplify a conditionnal in shortesthexnodeidprefix
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43795
diff
changeset
|
559 # The CExt is the only implementation to provide a nodetree |
f2de8dc9c52f
nodetree: simplify a conditionnal in shortesthexnodeidprefix
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43795
diff
changeset
|
560 # class so far. |
44016
992f0d6e7f33
rust-index: use the new method in shortesthexnodeidprefix
Georges Racinet <georges.racinet@octobus.net>
parents:
44003
diff
changeset
|
561 index = cl.index |
992f0d6e7f33
rust-index: use the new method in shortesthexnodeidprefix
Georges Racinet <georges.racinet@octobus.net>
parents:
44003
diff
changeset
|
562 if util.safehasattr(index, 'get_cindex'): |
992f0d6e7f33
rust-index: use the new method in shortesthexnodeidprefix
Georges Racinet <georges.racinet@octobus.net>
parents:
44003
diff
changeset
|
563 # the rust wrapped need to give access to its internal index |
992f0d6e7f33
rust-index: use the new method in shortesthexnodeidprefix
Georges Racinet <georges.racinet@octobus.net>
parents:
44003
diff
changeset
|
564 index = index.get_cindex() |
992f0d6e7f33
rust-index: use the new method in shortesthexnodeidprefix
Georges Racinet <georges.racinet@octobus.net>
parents:
44003
diff
changeset
|
565 nodetree = parsers.nodetree(index, len(revs)) |
39254
7a759ad2d06d
shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
39125
diff
changeset
|
566 for r in revs: |
7a759ad2d06d
shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
39125
diff
changeset
|
567 nodetree.insert(r) |
7a759ad2d06d
shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
39125
diff
changeset
|
568 if cache is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
569 cache[b'disambiguationnodetree'] = nodetree |
39254
7a759ad2d06d
shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
39125
diff
changeset
|
570 if nodetree is not None: |
7a759ad2d06d
shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
39125
diff
changeset
|
571 length = max(nodetree.shortest(node), minlength) |
7a759ad2d06d
shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
39125
diff
changeset
|
572 prefix = hexnode[:length] |
7a759ad2d06d
shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
39125
diff
changeset
|
573 return disambiguate(prefix) |
38882
6f7c9527030b
scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38881
diff
changeset
|
574 for length in range(minlength, len(hexnode) + 1): |
6f7c9527030b
scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38881
diff
changeset
|
575 matches = [] |
6f7c9527030b
scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38881
diff
changeset
|
576 prefix = hexnode[:length] |
6f7c9527030b
scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38881
diff
changeset
|
577 for rev in revs: |
6f7c9527030b
scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38881
diff
changeset
|
578 otherhexnode = repo[rev].hex() |
6f7c9527030b
scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38881
diff
changeset
|
579 if prefix == otherhexnode[:length]: |
6f7c9527030b
scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38881
diff
changeset
|
580 matches.append(otherhexnode) |
6f7c9527030b
scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38881
diff
changeset
|
581 if len(matches) == 1: |
6f7c9527030b
scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38881
diff
changeset
|
582 return disambiguate(prefix) |
6f7c9527030b
scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
38881
diff
changeset
|
583 |
37909
da083d9fafab
shortest: don't keep checking for longer prefix if node doesn't exist (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37767
diff
changeset
|
584 try: |
38015
3ac950cd5978
shortest: move revnum-disambiguation out of revlog
Martin von Zweigbergk <martinvonz@google.com>
parents:
38004
diff
changeset
|
585 return disambiguate(cl.shortest(node, minlength)) |
37909
da083d9fafab
shortest: don't keep checking for longer prefix if node doesn't exist (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37767
diff
changeset
|
586 except error.LookupError: |
da083d9fafab
shortest: don't keep checking for longer prefix if node doesn't exist (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37767
diff
changeset
|
587 raise error.RepoLookupError() |
37680
e743b8524d60
scmutil: introduce shortesthexnodeidprefix()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37679
diff
changeset
|
588 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
589 |
37350
e32dfff71529
revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37306
diff
changeset
|
590 def isrevsymbol(repo, symbol): |
37677
41ac707322ba
scmutil: document that isrevsymbol() raises on ambiguous node prefix
Martin von Zweigbergk <martinvonz@google.com>
parents:
37531
diff
changeset
|
591 """Checks if a symbol exists in the repo. |
41ac707322ba
scmutil: document that isrevsymbol() raises on ambiguous node prefix
Martin von Zweigbergk <martinvonz@google.com>
parents:
37531
diff
changeset
|
592 |
38880
df0873ab5c14
revlog: use specialized exception for ambiguous prefix lookup
Martin von Zweigbergk <martinvonz@google.com>
parents:
38839
diff
changeset
|
593 See revsymbol() for details. Raises error.AmbiguousPrefixLookupError if the |
df0873ab5c14
revlog: use specialized exception for ambiguous prefix lookup
Martin von Zweigbergk <martinvonz@google.com>
parents:
38839
diff
changeset
|
594 symbol is an ambiguous nodeid prefix. |
37677
41ac707322ba
scmutil: document that isrevsymbol() raises on ambiguous node prefix
Martin von Zweigbergk <martinvonz@google.com>
parents:
37531
diff
changeset
|
595 """ |
37350
e32dfff71529
revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37306
diff
changeset
|
596 try: |
e32dfff71529
revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37306
diff
changeset
|
597 revsymbol(repo, symbol) |
e32dfff71529
revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37306
diff
changeset
|
598 return True |
e32dfff71529
revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37306
diff
changeset
|
599 except error.RepoLookupError: |
e32dfff71529
revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37306
diff
changeset
|
600 return False |
e32dfff71529
revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents:
37306
diff
changeset
|
601 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
602 |
37273
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37271
diff
changeset
|
603 def revsymbol(repo, symbol): |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37271
diff
changeset
|
604 """Returns a context given a single revision symbol (as string). |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37271
diff
changeset
|
605 |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37271
diff
changeset
|
606 This is similar to revsingle(), but accepts only a single revision symbol, |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37271
diff
changeset
|
607 i.e. things like ".", "tip", "1234", "deadbeef", "my-bookmark" work, but |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37271
diff
changeset
|
608 not "max(public())". |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37271
diff
changeset
|
609 """ |
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37271
diff
changeset
|
610 if not isinstance(symbol, bytes): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
611 msg = ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
612 b"symbol (%s of type %s) was not a string, did you mean " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
613 b"repo[symbol]?" % (symbol, type(symbol)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
614 ) |
37273
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37271
diff
changeset
|
615 raise error.ProgrammingError(msg) |
37385
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
616 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
617 if symbol in (b'.', b'tip', b'null'): |
37527
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
618 return repo[symbol] |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
619 |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
620 try: |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
621 r = int(symbol) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
622 if b'%d' % r != symbol: |
37527
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
623 raise ValueError |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
624 l = len(repo.changelog) |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
625 if r < 0: |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
626 r += l |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
627 if r < 0 or r >= l and r != wdirrev: |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
628 raise ValueError |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
629 return repo[r] |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
630 except error.FilteredIndexError: |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
631 raise |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
632 except (ValueError, OverflowError, IndexError): |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
633 pass |
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
634 |
47081
a407fe56d6e8
core: don't hard-code hex node lengths
Joerg Sonnenberger <joerg@bec.de>
parents:
47055
diff
changeset
|
635 if len(symbol) == 2 * repo.nodeconstants.nodelen: |
37528
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
636 try: |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
637 node = bin(symbol) |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
638 rev = repo.changelog.rev(node) |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
639 return repo[rev] |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
640 except error.FilteredLookupError: |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
641 raise |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
642 except (TypeError, LookupError): |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
643 pass |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
644 |
37529
45667439439e
context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37528
diff
changeset
|
645 # look up bookmarks through the name interface |
45667439439e
context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37528
diff
changeset
|
646 try: |
45667439439e
context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37528
diff
changeset
|
647 node = repo.names.singlenode(repo, symbol) |
45667439439e
context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37528
diff
changeset
|
648 rev = repo.changelog.rev(node) |
45667439439e
context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37528
diff
changeset
|
649 return repo[rev] |
45667439439e
context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37528
diff
changeset
|
650 except KeyError: |
45667439439e
context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37528
diff
changeset
|
651 pass |
45667439439e
context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37528
diff
changeset
|
652 |
37679
ab828755e1ea
scmutil: use resolvehexnodeidprefix() from revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37678
diff
changeset
|
653 node = resolvehexnodeidprefix(repo, symbol) |
37530
35b34202dd3b
context: handle partial nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37529
diff
changeset
|
654 if node is not None: |
35b34202dd3b
context: handle partial nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37529
diff
changeset
|
655 rev = repo.changelog.rev(node) |
35b34202dd3b
context: handle partial nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37529
diff
changeset
|
656 return repo[rev] |
35b34202dd3b
context: handle partial nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37529
diff
changeset
|
657 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
658 raise error.RepoLookupError(_(b"unknown revision '%s'") % symbol) |
37527
1c09481acdcc
context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37504
diff
changeset
|
659 |
37528
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
660 except error.WdirUnsupported: |
d2b484eed1ec
scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37527
diff
changeset
|
661 return repo[None] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
662 except ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
663 error.FilteredIndexError, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
664 error.FilteredLookupError, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
665 error.FilteredRepoLookupError, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
666 ): |
37385
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
667 raise _filterederror(repo, symbol) |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
668 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
669 |
37385
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
670 def _filterederror(repo, changeid): |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
671 """build an exception to be raised about a filtered changeid |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
672 |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
673 This is extracted in a function to help extensions (eg: evolve) to |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
674 experiment with various message variants.""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
675 if repo.filtername.startswith(b'visible'): |
37385
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
676 |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
677 # Check if the changeset is obsolete |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
678 unfilteredrepo = repo.unfiltered() |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
679 ctx = revsymbol(unfilteredrepo, changeid) |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
680 |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
681 # If the changeset is obsolete, enrich the message with the reason |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
682 # that made this changeset not visible |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
683 if ctx.obsolete(): |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
684 msg = obsutil._getfilteredreason(repo, changeid, ctx) |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
685 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
686 msg = _(b"hidden revision '%s'") % changeid |
37385
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
687 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
688 hint = _(b'use --hidden to access hidden revisions') |
37385
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
689 |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
690 return error.FilteredRepoLookupError(msg, hint=hint) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
691 msg = _(b"filtered revision '%s' (not in '%s' subset)") |
37385
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
692 msg %= (changeid, repo.filtername) |
ecd3f6909184
context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37360
diff
changeset
|
693 return error.FilteredRepoLookupError(msg) |
37273
0194dac77c93
scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents:
37271
diff
changeset
|
694 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
695 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
696 def revsingle(repo, revspec, default=b'.', localalias=None): |
19509
8963a706e075
revsingle: fix silly API issue (issue2992)
Matt Mackall <mpm@selenic.com>
parents:
19154
diff
changeset
|
697 if not revspec and revspec != 0: |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
698 return repo[default] |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
699 |
34023
5e83a8fe6bc4
rebase: initial support for multiple destinations
Jun Wu <quark@fb.com>
parents:
33819
diff
changeset
|
700 l = revrange(repo, [revspec], localalias=localalias) |
22814
8110405cf8ae
revset-limit: use boolean testing instead of `len(revs) < 1`
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21799
diff
changeset
|
701 if not l: |
48052
7d908ee19b5b
errors: use InputError for some invalid revsets and such
Martin von Zweigbergk <martinvonz@google.com>
parents:
47729
diff
changeset
|
702 raise error.InputError(_(b'empty revision set')) |
22815
4f81470e83bf
revsingle: use `last` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22814
diff
changeset
|
703 return repo[l.last()] |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
704 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
705 |
26020
cc3a30ff9490
revpair: restrict odd-range handling to top-level x:y expression (issue4774)
Yuya Nishihara <yuya@tcha.org>
parents:
25928
diff
changeset
|
706 def _pairspec(revspec): |
31044
0b8356705de6
revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30644
diff
changeset
|
707 tree = revsetlang.parse(revspec) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
708 return tree and tree[0] in ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
709 b'range', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
710 b'rangepre', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
711 b'rangepost', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
712 b'rangeall', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
713 ) |
26020
cc3a30ff9490
revpair: restrict odd-range handling to top-level x:y expression (issue4774)
Yuya Nishihara <yuya@tcha.org>
parents:
25928
diff
changeset
|
714 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
715 |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
716 def revpair(repo, revs): |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
717 if not revs: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
718 return repo[b'.'], repo[None] |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
719 |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
720 l = revrange(repo, revs) |
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
721 |
41392
a728ef2f9b15
revpair: clarify check for empty revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
41391
diff
changeset
|
722 if not l: |
48052
7d908ee19b5b
errors: use InputError for some invalid revsets and such
Martin von Zweigbergk <martinvonz@google.com>
parents:
47729
diff
changeset
|
723 raise error.InputError(_(b'empty revision range')) |
41392
a728ef2f9b15
revpair: clarify check for empty revset
Martin von Zweigbergk <martinvonz@google.com>
parents:
41391
diff
changeset
|
724 |
41391
5079242abef9
revpair: simplify revpair by always relying on smartset.first/last
Martin von Zweigbergk <martinvonz@google.com>
parents:
41288
diff
changeset
|
725 first = l.first() |
5079242abef9
revpair: simplify revpair by always relying on smartset.first/last
Martin von Zweigbergk <martinvonz@google.com>
parents:
41288
diff
changeset
|
726 second = l.last() |
20862
97b2f26dfc43
revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20820
diff
changeset
|
727 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
728 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
729 first == second |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
730 and len(revs) >= 2 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
731 and not all(revrange(repo, [r]) for r in revs) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
732 ): |
48052
7d908ee19b5b
errors: use InputError for some invalid revsets and such
Martin von Zweigbergk <martinvonz@google.com>
parents:
47729
diff
changeset
|
733 raise error.InputError(_(b'empty revision on one side of range')) |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
734 |
26020
cc3a30ff9490
revpair: restrict odd-range handling to top-level x:y expression (issue4774)
Yuya Nishihara <yuya@tcha.org>
parents:
25928
diff
changeset
|
735 # if top-level is range expression, the result must always be a pair |
cc3a30ff9490
revpair: restrict odd-range handling to top-level x:y expression (issue4774)
Yuya Nishihara <yuya@tcha.org>
parents:
25928
diff
changeset
|
736 if first == second and len(revs) == 1 and not _pairspec(revs[0]): |
37254
e9ee540af434
scmutil: make revpair() return context objects (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37253
diff
changeset
|
737 return repo[first], repo[None] |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
738 |
37254
e9ee540af434
scmutil: make revpair() return context objects (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
37253
diff
changeset
|
739 return repo[first], repo[second] |
14319
b33f3e35efb0
scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents:
14261
diff
changeset
|
740 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
741 |
34023
5e83a8fe6bc4
rebase: initial support for multiple destinations
Jun Wu <quark@fb.com>
parents:
33819
diff
changeset
|
742 def revrange(repo, specs, localalias=None): |
29417
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
743 """Execute 1 to many revsets and return the union. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
744 |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
745 This is the preferred mechanism for executing revsets using user-specified |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
746 config options, such as revset aliases. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
747 |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
748 The revsets specified by ``specs`` will be executed via a chained ``OR`` |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
749 expression. If ``specs`` is empty, an empty result is returned. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
750 |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
751 ``specs`` can contain integers, in which case they are assumed to be |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
752 revision numbers. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
753 |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
754 It is assumed the revsets are already formatted. If you have arguments |
31044
0b8356705de6
revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
30644
diff
changeset
|
755 that need to be expanded in the revset, call ``revsetlang.formatspec()`` |
29417
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
756 and pass the result as an element of ``specs``. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
757 |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
758 Specifying a single revset is allowed. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
759 |
44075
2122ffa903ea
doc: fix references to `revset.abstractsmartset`
Matt Harbison <matt_harbison@yahoo.com>
parents:
44063
diff
changeset
|
760 Returns a ``smartset.abstractsmartset`` which is a list-like interface over |
29417
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
761 integer revisions. |
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
762 """ |
25928
4ee4f7415095
revrange: evaluate all revset specs at once
Yuya Nishihara <yuya@tcha.org>
parents:
25904
diff
changeset
|
763 allspecs = [] |
29417
526b027b0130
scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
29389
diff
changeset
|
764 for spec in specs: |
25904
fbaa2de13cf6
revrange: drop old-style parser in favor of revset (API)
Yuya Nishihara <yuya@tcha.org>
parents:
25772
diff
changeset
|
765 if isinstance(spec, int): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
766 spec = revsetlang.formatspec(b'%d', spec) |
25928
4ee4f7415095
revrange: evaluate all revset specs at once
Yuya Nishihara <yuya@tcha.org>
parents:
25904
diff
changeset
|
767 allspecs.append(spec) |
34023
5e83a8fe6bc4
rebase: initial support for multiple destinations
Jun Wu <quark@fb.com>
parents:
33819
diff
changeset
|
768 return repo.anyrevs(allspecs, user=True, localalias=localalias) |
14320 | 769 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
770 |
45720
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
771 def increasingwindows(windowsize=8, sizelimit=512): |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
772 while True: |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
773 yield windowsize |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
774 if windowsize < sizelimit: |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
775 windowsize *= 2 |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
776 |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
777 |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
778 def walkchangerevs(repo, revs, makefilematcher, prepare): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
779 """Iterate over files and the revs in a "windowed" way. |
45720
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
780 |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
781 Callers most commonly need to iterate backwards over the history |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
782 in which they are interested. Doing so has awful (quadratic-looking) |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
783 performance, so we use iterators in a "windowed" way. |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
784 |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
785 We walk a window of revisions in the desired order. Within the |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
786 window, we first walk forwards to gather data, then in the desired |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
787 order (usually backwards) to display it. |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
788 |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
789 This function returns an iterator yielding contexts. Before |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
790 yielding each context, the iterator will first call the prepare |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
791 function on each context in the window in forward order.""" |
45720
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
792 |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
793 if not revs: |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
794 return [] |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
795 change = repo.__getitem__ |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
796 |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
797 def iterate(): |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
798 it = iter(revs) |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
799 stopiteration = False |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
800 for windowsize in increasingwindows(): |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
801 nrevs = [] |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
802 for i in pycompat.xrange(windowsize): |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
803 rev = next(it, None) |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
804 if rev is None: |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
805 stopiteration = True |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
806 break |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
807 nrevs.append(rev) |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
808 for rev in sorted(nrevs): |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
809 ctx = change(rev) |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
810 prepare(ctx, makefilematcher(ctx)) |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
811 for rev in nrevs: |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
812 yield change(rev) |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
813 |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
814 if stopiteration: |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
815 break |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
816 |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
817 return iterate() |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
818 |
508dfd1c18df
scmutil: move walkchangerevs() from cmdutil
Yuya Nishihara <yuya@tcha.org>
parents:
45682
diff
changeset
|
819 |
26433
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
820 def meaningfulparents(repo, ctx): |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
821 """Return list of meaningful (or all if debug) parentrevs for rev. |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
822 |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
823 For merges (two non-nullrev revisions) both parents are meaningful. |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
824 Otherwise the first parent revision is considered meaningful if it |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
825 is not the preceding revision. |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
826 """ |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
827 parents = ctx.parents() |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
828 if len(parents) > 1: |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
829 return parents |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
830 if repo.ui.debugflag: |
39899
d739f423bf06
repo: look up nullrev context by revnum, not symbolic name
Martin von Zweigbergk <martinvonz@google.com>
parents:
39896
diff
changeset
|
831 return [parents[0], repo[nullrev]] |
32676
4bec8cce6a09
scmutil: pass ctx object to intrev()
Yuya Nishihara <yuya@tcha.org>
parents:
32310
diff
changeset
|
832 if parents[0].rev() >= intrev(ctx) - 1: |
26433
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
833 return [] |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
834 return parents |
3ad41638b4b4
changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents:
26421
diff
changeset
|
835 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
836 |
41589
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
837 def getuipathfn(repo, legacyrelativevalue=False, forcerelativevalue=None): |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
838 """Return a function that produced paths for presenting to the user. |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
839 |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
840 The returned function takes a repo-relative path and produces a path |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
841 that can be presented in the UI. |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
842 |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
843 Depending on the value of ui.relative-paths, either a repo-relative or |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
844 cwd-relative path will be produced. |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
845 |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
846 legacyrelativevalue is the value to use if ui.relative-paths=legacy |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
847 |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
848 If forcerelativevalue is not None, then that value will be used regardless |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
849 of what ui.relative-paths is set to. |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
850 """ |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
851 if forcerelativevalue is not None: |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
852 relative = forcerelativevalue |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
853 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
854 config = repo.ui.config(b'ui', b'relative-paths') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
855 if config == b'legacy': |
41589
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
856 relative = legacyrelativevalue |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
857 else: |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
858 relative = stringutil.parsebool(config) |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
859 if relative is None: |
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
860 raise error.ConfigError( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
861 _(b"ui.relative-paths is not a boolean ('%s')") % config |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
862 ) |
41589
aec185af621e
config: introduce a new value for ui.relative-paths getting old behavior
Martin von Zweigbergk <martinvonz@google.com>
parents:
41506
diff
changeset
|
863 |
41505
e6ec0737b706
status: extract helper for producing relative or absolute path for UI
Martin von Zweigbergk <martinvonz@google.com>
parents:
41443
diff
changeset
|
864 if relative: |
e6ec0737b706
status: extract helper for producing relative or absolute path for UI
Martin von Zweigbergk <martinvonz@google.com>
parents:
41443
diff
changeset
|
865 cwd = repo.getcwd() |
44917
5d8ae9248a70
scmutil: speed up relativization of paths when it's a no-op
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44887
diff
changeset
|
866 if cwd != b'': |
44943
d044b66d8429
scmutil: clarify getuipathfn comment
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44917
diff
changeset
|
867 # this branch would work even if cwd == b'' (ie cwd = repo |
d044b66d8429
scmutil: clarify getuipathfn comment
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44917
diff
changeset
|
868 # root), but its generality makes the returned function slower |
44917
5d8ae9248a70
scmutil: speed up relativization of paths when it's a no-op
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44887
diff
changeset
|
869 pathto = repo.pathto |
5d8ae9248a70
scmutil: speed up relativization of paths when it's a no-op
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44887
diff
changeset
|
870 return lambda f: pathto(f, cwd) |
5d8ae9248a70
scmutil: speed up relativization of paths when it's a no-op
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
44887
diff
changeset
|
871 if repo.ui.configbool(b'ui', b'slash'): |
41695
a8d3a4be066e
windows: use util.localpath for repo-relative paths in getuipathfn()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41687
diff
changeset
|
872 return lambda f: f |
41505
e6ec0737b706
status: extract helper for producing relative or absolute path for UI
Martin von Zweigbergk <martinvonz@google.com>
parents:
41443
diff
changeset
|
873 else: |
41695
a8d3a4be066e
windows: use util.localpath for repo-relative paths in getuipathfn()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41687
diff
changeset
|
874 return util.localpath |
41505
e6ec0737b706
status: extract helper for producing relative or absolute path for UI
Martin von Zweigbergk <martinvonz@google.com>
parents:
41443
diff
changeset
|
875 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
876 |
41661
f8b18583049f
add: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41660
diff
changeset
|
877 def subdiruipathfn(subpath, uipathfn): |
f8b18583049f
add: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41660
diff
changeset
|
878 '''Create a new uipathfn that treats the file as relative to subpath.''' |
f8b18583049f
add: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41660
diff
changeset
|
879 return lambda f: uipathfn(posixpath.join(subpath, f)) |
f8b18583049f
add: pass around uipathfn and use instead of m.rel() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41660
diff
changeset
|
880 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
881 |
41663
6a447a3d1bd0
addremove: pass around uipathfn and use instead of m.uipath() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41661
diff
changeset
|
882 def anypats(pats, opts): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
883 """Checks if any patterns, including --include and --exclude were given. |
41663
6a447a3d1bd0
addremove: pass around uipathfn and use instead of m.uipath() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41661
diff
changeset
|
884 |
6a447a3d1bd0
addremove: pass around uipathfn and use instead of m.uipath() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41661
diff
changeset
|
885 Some commands (e.g. addremove) use this condition for deciding whether to |
6a447a3d1bd0
addremove: pass around uipathfn and use instead of m.uipath() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41661
diff
changeset
|
886 print absolute or relative paths. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
887 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
888 return bool(pats or opts.get(b'include') or opts.get(b'exclude')) |
41663
6a447a3d1bd0
addremove: pass around uipathfn and use instead of m.uipath() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41661
diff
changeset
|
889 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
890 |
14320 | 891 def expandpats(pats): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
892 """Expand bare globs when running on windows. |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
893 On posix we assume it already has already been done by sh.""" |
14320 | 894 if not util.expandglobs: |
895 return list(pats) | |
896 ret = [] | |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
897 for kindpat in pats: |
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
898 kind, pat = matchmod._patsplit(kindpat, None) |
14320 | 899 if kind is None: |
900 try: | |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
901 globbed = glob.glob(pat) |
14320 | 902 except re.error: |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
903 globbed = [pat] |
14320 | 904 if globbed: |
905 ret.extend(globbed) | |
906 continue | |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
907 ret.append(kindpat) |
14320 | 908 return ret |
909 | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
910 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
911 def matchandpats( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
912 ctx, pats=(), opts=None, globbed=False, default=b'relpath', badfn=None |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
913 ): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
914 """Return a matcher and the patterns that were used. |
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
915 The matcher will warn about bad matches, unless an alternate badfn callback |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
916 is provided.""" |
26326
58218b0e6005
match: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26325
diff
changeset
|
917 if opts is None: |
58218b0e6005
match: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26325
diff
changeset
|
918 opts = {} |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
919 if not globbed and default == b'relpath': |
14320 | 920 pats = expandpats(pats or []) |
14670
19197fa4c41c
scmutil: match now accepts a context or a repo
Matt Mackall <mpm@selenic.com>
parents:
14669
diff
changeset
|
921 |
41676
0ed7a8ac5711
scmutil: respect ui.relative-paths in default match.badfn
Martin von Zweigbergk <martinvonz@google.com>
parents:
41673
diff
changeset
|
922 uipathfn = getuipathfn(ctx.repo(), legacyrelativevalue=True) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
923 |
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
924 def bad(f, msg): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
925 ctx.repo().ui.warn(b"%s: %s\n" % (uipathfn(f), msg)) |
25466
007a1d53f7c3
scmutil: use the optional badfn argument when building a matcher
Matt Harbison <matt_harbison@yahoo.com>
parents:
25434
diff
changeset
|
926 |
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
927 if badfn is None: |
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
928 badfn = bad |
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
929 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
930 m = ctx.match( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
931 pats, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
932 opts.get(b'include'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
933 opts.get(b'exclude'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
934 default, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
935 listsubrepos=opts.get(b'subrepos'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
936 badfn=badfn, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
937 ) |
25466
007a1d53f7c3
scmutil: use the optional badfn argument when building a matcher
Matt Harbison <matt_harbison@yahoo.com>
parents:
25434
diff
changeset
|
938 |
24447
d44d53bc9a1e
matcher: make e.g. 'relpath:.' lead to fast paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
24338
diff
changeset
|
939 if m.always(): |
d44d53bc9a1e
matcher: make e.g. 'relpath:.' lead to fast paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
24338
diff
changeset
|
940 pats = [] |
16171
336e61875335
graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
16167
diff
changeset
|
941 return m, pats |
336e61875335
graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents:
16167
diff
changeset
|
942 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
943 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
944 def match( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
945 ctx, pats=(), opts=None, globbed=False, default=b'relpath', badfn=None |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
946 ): |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
947 '''Return a matcher that will warn about bad matches.''' |
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
948 return matchandpats(ctx, pats, opts, globbed, default, badfn=badfn)[0] |
14320 | 949 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
950 |
14320 | 951 def matchall(repo): |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
952 '''Return a matcher that will efficiently match everything.''' |
41687
0531dff73d0b
match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41677
diff
changeset
|
953 return matchmod.always() |
14320 | 954 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
955 |
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
956 def matchfiles(repo, files, badfn=None): |
21111
9d28fd795215
match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents:
20980
diff
changeset
|
957 '''Return a matcher that will efficiently match exactly these files.''' |
41687
0531dff73d0b
match: delete unused root and cwd arguments from {always,never,exact}() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41677
diff
changeset
|
958 return matchmod.exact(files, badfn=badfn) |
14320 | 959 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
960 |
34854
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
961 def parsefollowlinespattern(repo, rev, pat, msg): |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
962 """Return a file name from `pat` pattern suitable for usage in followlines |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
963 logic. |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
964 """ |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
965 if not matchmod.patkind(pat): |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
966 return pathutil.canonpath(repo.root, repo.getcwd(), pat) |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
967 else: |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
968 ctx = repo[rev] |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
969 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=ctx) |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
970 files = [f for f in ctx if m(f)] |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
971 if len(files) != 1: |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
972 raise error.ParseError(msg) |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
973 return files[0] |
39b094e4ae2c
revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34793
diff
changeset
|
974 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
975 |
40786
65591a513b9c
revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents:
40699
diff
changeset
|
976 def getorigvfs(ui, repo): |
65591a513b9c
revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents:
40699
diff
changeset
|
977 """return a vfs suitable to save 'orig' file |
65591a513b9c
revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents:
40699
diff
changeset
|
978 |
65591a513b9c
revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents:
40699
diff
changeset
|
979 return None if no special directory is configured""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
980 origbackuppath = ui.config(b'ui', b'origbackuppath') |
40786
65591a513b9c
revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents:
40699
diff
changeset
|
981 if not origbackuppath: |
65591a513b9c
revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents:
40699
diff
changeset
|
982 return None |
65591a513b9c
revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents:
40699
diff
changeset
|
983 return vfs.vfs(repo.wvfs.join(origbackuppath)) |
65591a513b9c
revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents:
40699
diff
changeset
|
984 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
985 |
41608
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
986 def backuppath(ui, repo, filepath): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
987 """customize where working copy backup files (.orig files) are created |
41608
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
988 |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
989 Fetch user defined path from config file: [ui] origbackuppath = <path> |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
990 Fall back to default (filepath with .orig suffix) if not specified |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
991 |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
992 filepath is repo-relative |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
993 |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
994 Returns an absolute path |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
995 """ |
41608
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
996 origvfs = getorigvfs(ui, repo) |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
997 if origvfs is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
998 return repo.wjoin(filepath + b".orig") |
41608
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
999 |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
1000 origbackupdir = origvfs.dirname(filepath) |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
1001 if not origvfs.isdir(origbackupdir) or origvfs.islink(origbackupdir): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1002 ui.note(_(b'creating directory: %s\n') % origvfs.join(origbackupdir)) |
41608
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
1003 |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
1004 # Remove any files that conflict with the backup file's path |
43677
0b7733719d21
utils: move finddirs() to pathutil
Martin von Zweigbergk <martinvonz@google.com>
parents:
43554
diff
changeset
|
1005 for f in reversed(list(pathutil.finddirs(filepath))): |
41608
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
1006 if origvfs.isfileorlink(f): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1007 ui.note(_(b'removing conflicting file: %s\n') % origvfs.join(f)) |
41608
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
1008 origvfs.unlink(f) |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
1009 break |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
1010 |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
1011 origvfs.makedirs(origbackupdir) |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
1012 |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
1013 if origvfs.isdir(filepath) and not origvfs.islink(filepath): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1014 ui.note( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1015 _(b'removing conflicting directory: %s\n') % origvfs.join(filepath) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1016 ) |
41608
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
1017 origvfs.rmtree(filepath, forcibly=True) |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
1018 |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
1019 return origvfs.join(filepath) |
8785188d1915
scmutil: introduce a new backuppath() to replace origpath()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41589
diff
changeset
|
1020 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1021 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49025
diff
changeset
|
1022 class _containsnode: |
33331
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
1023 """proxy __contains__(node) to container.__contains__ which accepts revs""" |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
1024 |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
1025 def __init__(self, repo, revcontainer): |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
1026 self._torev = repo.changelog.rev |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
1027 self._revcontains = revcontainer.__contains__ |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
1028 |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
1029 def __contains__(self, node): |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
1030 return self._revcontains(self._torev(node)) |
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
1031 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1032 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1033 def cleanupnodes( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1034 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1035 replacements, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1036 operation, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1037 moves=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1038 metadata=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1039 fixphase=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1040 targetphase=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1041 backup=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1042 ): |
33100
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1043 """do common cleanups when old nodes are replaced by new nodes |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1044 |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1045 That includes writing obsmarkers or stripping nodes, and moving bookmarks. |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1046 (we might also want to move working directory parent in the future) |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1047 |
33686
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
33685
diff
changeset
|
1048 By default, bookmark moves are calculated automatically from 'replacements', |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
33685
diff
changeset
|
1049 but 'moves' can be used to override that. Also, 'moves' may include |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
33685
diff
changeset
|
1050 additional bookmark moves that should not have associated obsmarkers. |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
33685
diff
changeset
|
1051 |
33685
2dbd6d259cd2
cleanupnodes: rename "mapping" to "replacements"
Martin von Zweigbergk <martinvonz@google.com>
parents:
33684
diff
changeset
|
1052 replacements is {oldnode: [newnode]} or a iterable of nodes if they do not |
2dbd6d259cd2
cleanupnodes: rename "mapping" to "replacements"
Martin von Zweigbergk <martinvonz@google.com>
parents:
33684
diff
changeset
|
1053 have replacements. operation is a string, like "rebase". |
34793
3df59451cdec
scmutil: add capability to cleanupnodes to take obsmarker metadata
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34737
diff
changeset
|
1054 |
3df59451cdec
scmutil: add capability to cleanupnodes to take obsmarker metadata
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34737
diff
changeset
|
1055 metadata is dictionary containing metadata to be stored in obsmarker if |
3df59451cdec
scmutil: add capability to cleanupnodes to take obsmarker metadata
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34737
diff
changeset
|
1056 obsolescence is enabled. |
33100
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1057 """ |
38429
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1058 assert fixphase or targetphase is None |
33686
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
33685
diff
changeset
|
1059 if not replacements and not moves: |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
33685
diff
changeset
|
1060 return |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
33685
diff
changeset
|
1061 |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
33685
diff
changeset
|
1062 # translate mapping's other forms |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1063 if not util.safehasattr(replacements, b'items'): |
39896
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1064 replacements = {(n,): () for n in replacements} |
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1065 else: |
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1066 # upgrading non tuple "source" to tuple ones for BC |
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1067 repls = {} |
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1068 for key, value in replacements.items(): |
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1069 if not isinstance(key, tuple): |
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1070 key = (key,) |
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1071 repls[key] = value |
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1072 replacements = repls |
33100
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1073 |
40873
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1074 # Unfiltered repo is needed since nodes in replacements might be hidden. |
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1075 unfi = repo.unfiltered() |
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1076 |
33684
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33647
diff
changeset
|
1077 # Calculate bookmark movements |
33686
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
33685
diff
changeset
|
1078 if moves is None: |
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
33685
diff
changeset
|
1079 moves = {} |
40873
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1080 for oldnodes, newnodes in replacements.items(): |
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1081 for oldnode in oldnodes: |
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1082 if oldnode in moves: |
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1083 continue |
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1084 if len(newnodes) > 1: |
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1085 # usually a split, take the one with biggest rev number |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1086 newnode = next(unfi.set(b'max(%ln)', newnodes)).node() |
40873
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1087 elif len(newnodes) == 0: |
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1088 # move bookmark backwards |
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1089 allreplaced = [] |
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1090 for rep in replacements: |
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1091 allreplaced.extend(rep) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1092 roots = list( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1093 unfi.set(b'max((::%n) - %ln)', oldnode, allreplaced) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1094 ) |
40873
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1095 if roots: |
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1096 newnode = roots[0].node() |
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1097 else: |
47055
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46976
diff
changeset
|
1098 newnode = repo.nullid |
39896
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1099 else: |
40873
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1100 newnode = newnodes[0] |
b7823bd59b07
cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents:
40786
diff
changeset
|
1101 moves[oldnode] = newnode |
33684
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33647
diff
changeset
|
1102 |
38429
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1103 allnewnodes = [n for ns in replacements.values() for n in ns] |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1104 toretract = {} |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1105 toadvance = {} |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1106 if fixphase: |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1107 precursors = {} |
39896
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1108 for oldnodes, newnodes in replacements.items(): |
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1109 for oldnode in oldnodes: |
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1110 for newnode in newnodes: |
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1111 precursors.setdefault(newnode, []).append(oldnode) |
38429
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1112 |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1113 allnewnodes.sort(key=lambda n: unfi[n].rev()) |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1114 newphases = {} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1115 |
38429
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1116 def phase(ctx): |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1117 return newphases.get(ctx.node(), ctx.phase()) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1118 |
38429
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1119 for newnode in allnewnodes: |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1120 ctx = unfi[newnode] |
38437
05b7dd11918e
cleanupnodes: preserve phase of parents of new nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
38429
diff
changeset
|
1121 parentphase = max(phase(p) for p in ctx.parents()) |
38429
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1122 if targetphase is None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1123 oldphase = max( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1124 unfi[oldnode].phase() for oldnode in precursors[newnode] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1125 ) |
38429
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1126 newphase = max(oldphase, parentphase) |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1127 else: |
38437
05b7dd11918e
cleanupnodes: preserve phase of parents of new nodes
Martin von Zweigbergk <martinvonz@google.com>
parents:
38429
diff
changeset
|
1128 newphase = max(targetphase, parentphase) |
38429
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1129 newphases[newnode] = newphase |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1130 if newphase > ctx.phase(): |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1131 toretract.setdefault(newphase, []).append(newnode) |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1132 elif newphase < ctx.phase(): |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1133 toadvance.setdefault(newphase, []).append(newnode) |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1134 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1135 with repo.transaction(b'cleanup') as tr: |
33100
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1136 # Move bookmarks |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1137 bmarks = repo._bookmarks |
33511
9689239d7c2b
bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents:
33505
diff
changeset
|
1138 bmarkchanges = [] |
33684
033a5befbaf7
cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents:
33647
diff
changeset
|
1139 for oldnode, newnode in moves.items(): |
33100
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1140 oldbmarks = repo.nodebookmarks(oldnode) |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1141 if not oldbmarks: |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1142 continue |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1143 from . import bookmarks # avoid import cycle |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1144 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1145 repo.ui.debug( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1146 b'moving bookmarks %r from %s to %s\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1147 % ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1148 pycompat.rapply(pycompat.maybebytestr, oldbmarks), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1149 hex(oldnode), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1150 hex(newnode), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1151 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1152 ) |
33331
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
1153 # Delete divergent bookmarks being parents of related newnodes |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1154 deleterevs = repo.revs( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1155 b'parents(roots(%ln & (::%n))) - parents(%n)', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1156 allnewnodes, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1157 newnode, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1158 oldnode, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1159 ) |
33331
4bae3c117b57
scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents:
33330
diff
changeset
|
1160 deletenodes = _containsnode(repo, deleterevs) |
33100
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1161 for name in oldbmarks: |
33511
9689239d7c2b
bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents:
33505
diff
changeset
|
1162 bmarkchanges.append((name, newnode)) |
9689239d7c2b
bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents:
33505
diff
changeset
|
1163 for b in bookmarks.divergent2delete(repo, deletenodes, name): |
9689239d7c2b
bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents:
33505
diff
changeset
|
1164 bmarkchanges.append((b, None)) |
9689239d7c2b
bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents:
33505
diff
changeset
|
1165 |
9689239d7c2b
bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents:
33505
diff
changeset
|
1166 if bmarkchanges: |
9689239d7c2b
bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents:
33505
diff
changeset
|
1167 bmarks.applychanges(repo, tr, bmarkchanges) |
33100
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1168 |
38429
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1169 for phase, nodes in toretract.items(): |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1170 phases.retractboundary(repo, tr, phase, nodes) |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1171 for phase, nodes in toadvance.items(): |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1172 phases.advanceboundary(repo, tr, phase, nodes) |
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
38425
diff
changeset
|
1173 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1174 mayusearchived = repo.ui.config(b'experimental', b'cleanup-as-archived') |
33100
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1175 # Obsolete or strip nodes |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1176 if obsolete.isenabled(repo, obsolete.createmarkersopt): |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1177 # If a node is already obsoleted, and we want to obsolete it |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1178 # without a successor, skip that obssolete request since it's |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1179 # unnecessary. That's the "if s or not isobs(n)" check below. |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1180 # Also sort the node in topology order, that might be useful for |
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1181 # some obsstore logic. |
40042
ca9d0c93acea
cleanupnodes: update comment to drop mention of filtering
Boris Feld <boris.feld@octobus.net>
parents:
39928
diff
changeset
|
1182 # NOTE: the sorting might belong to createmarkers. |
33330
ba43e5ee9c6d
scmutil: make cleanupnodes handle filtered node
Jun Wu <quark@fb.com>
parents:
33252
diff
changeset
|
1183 torev = unfi.changelog.rev |
39896
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1184 sortfunc = lambda ns: torev(ns[0][0]) |
39895
1c3f1491965f
scmutil: expand long "one-liner"
Boris Feld <boris.feld@octobus.net>
parents:
39841
diff
changeset
|
1185 rels = [] |
39896
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1186 for ns, s in sorted(replacements.items(), key=sortfunc): |
39928
61f39a892168
cleanupnodes: pass multiple predecessors to `createmarkers` directly
Boris Feld <boris.feld@octobus.net>
parents:
39921
diff
changeset
|
1187 rel = (tuple(unfi[n] for n in ns), tuple(unfi[m] for m in s)) |
61f39a892168
cleanupnodes: pass multiple predecessors to `createmarkers` directly
Boris Feld <boris.feld@octobus.net>
parents:
39921
diff
changeset
|
1188 rels.append(rel) |
33686
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
33685
diff
changeset
|
1189 if rels: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1190 obsolete.createmarkers( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1191 repo, rels, operation=operation, metadata=metadata |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1192 ) |
41804
64de5f44eec3
rewriting: add an option for rewrite commands to use the archived phase
Boris Feld <boris.feld@octobus.net>
parents:
41790
diff
changeset
|
1193 elif phases.supportinternal(repo) and mayusearchived: |
64de5f44eec3
rewriting: add an option for rewrite commands to use the archived phase
Boris Feld <boris.feld@octobus.net>
parents:
41790
diff
changeset
|
1194 # this assume we do not have "unstable" nodes above the cleaned ones |
64de5f44eec3
rewriting: add an option for rewrite commands to use the archived phase
Boris Feld <boris.feld@octobus.net>
parents:
41790
diff
changeset
|
1195 allreplaced = set() |
64de5f44eec3
rewriting: add an option for rewrite commands to use the archived phase
Boris Feld <boris.feld@octobus.net>
parents:
41790
diff
changeset
|
1196 for ns in replacements.keys(): |
64de5f44eec3
rewriting: add an option for rewrite commands to use the archived phase
Boris Feld <boris.feld@octobus.net>
parents:
41790
diff
changeset
|
1197 allreplaced.update(ns) |
64de5f44eec3
rewriting: add an option for rewrite commands to use the archived phase
Boris Feld <boris.feld@octobus.net>
parents:
41790
diff
changeset
|
1198 if backup: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1199 from . import repair # avoid import cycle |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1200 |
41804
64de5f44eec3
rewriting: add an option for rewrite commands to use the archived phase
Boris Feld <boris.feld@octobus.net>
parents:
41790
diff
changeset
|
1201 node = min(allreplaced, key=repo.changelog.rev) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1202 repair.backupbundle( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1203 repo, allreplaced, allreplaced, node, operation |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1204 ) |
41804
64de5f44eec3
rewriting: add an option for rewrite commands to use the archived phase
Boris Feld <boris.feld@octobus.net>
parents:
41790
diff
changeset
|
1205 phases.retractboundary(repo, tr, phases.archived, allreplaced) |
33100
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1206 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1207 from . import repair # avoid import cycle |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1208 |
39896
b99903534e06
scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents:
39895
diff
changeset
|
1209 tostrip = list(n for ns in replacements for n in ns) |
33686
2f427b57bf90
rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents:
33685
diff
changeset
|
1210 if tostrip: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1211 repair.delayedstrip( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1212 repo.ui, repo, tostrip, operation, backup=backup |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1213 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1214 |
33100
65cadeea6c22
scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents:
32679
diff
changeset
|
1215 |
41663
6a447a3d1bd0
addremove: pass around uipathfn and use instead of m.uipath() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41661
diff
changeset
|
1216 def addremove(repo, matcher, prefix, uipathfn, opts=None): |
26329
d9537ce64f3a
addremove: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26328
diff
changeset
|
1217 if opts is None: |
d9537ce64f3a
addremove: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26328
diff
changeset
|
1218 opts = {} |
23533
891aaa7c0c70
scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns
Matt Harbison <matt_harbison@yahoo.com>
parents:
23481
diff
changeset
|
1219 m = matcher |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1220 dry_run = opts.get(b'dry_run') |
37306
6942c73f0733
addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents:
37273
diff
changeset
|
1221 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1222 similarity = float(opts.get(b'similarity') or 0) |
37306
6942c73f0733
addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents:
37273
diff
changeset
|
1223 except ValueError: |
48053
5b89626c11e9
errors: use InputError for bad --similarity value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48052
diff
changeset
|
1224 raise error.InputError(_(b'similarity must be a number')) |
37306
6942c73f0733
addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents:
37273
diff
changeset
|
1225 if similarity < 0 or similarity > 100: |
48053
5b89626c11e9
errors: use InputError for bad --similarity value
Martin von Zweigbergk <martinvonz@google.com>
parents:
48052
diff
changeset
|
1226 raise error.InputError(_(b'similarity must be between 0 and 100')) |
37306
6942c73f0733
addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents:
37273
diff
changeset
|
1227 similarity /= 100.0 |
23533
891aaa7c0c70
scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns
Matt Harbison <matt_harbison@yahoo.com>
parents:
23481
diff
changeset
|
1228 |
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
1229 ret = 0 |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
1230 |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
1231 wctx = repo[None] |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
1232 for subpath in sorted(wctx.substate): |
29813
35560189677c
subrepo: cleanup of subrepo filematcher logic
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents:
29782
diff
changeset
|
1233 submatch = matchmod.subdirmatcher(subpath, m) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1234 if opts.get(b'subrepos') or m.exact(subpath) or any(submatch.files()): |
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
1235 sub = wctx.sub(subpath) |
41640
5ee3c49fc9cd
subrepo: adjust subrepo prefix before calling subrepo.addremove() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41617
diff
changeset
|
1236 subprefix = repo.wvfs.reljoin(prefix, subpath) |
41663
6a447a3d1bd0
addremove: pass around uipathfn and use instead of m.uipath() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41661
diff
changeset
|
1237 subuipathfn = subdiruipathfn(subpath, uipathfn) |
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
1238 try: |
41663
6a447a3d1bd0
addremove: pass around uipathfn and use instead of m.uipath() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41661
diff
changeset
|
1239 if sub.addremove(submatch, subprefix, subuipathfn, opts): |
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
1240 ret = 1 |
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
1241 except error.LookupError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1242 repo.ui.status( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1243 _(b"skipping missing subrepository: %s\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1244 % uipathfn(subpath) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1245 ) |
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
1246 |
16167
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
1247 rejected = [] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1248 |
23534
83bbedc16b3f
addremove: warn when addremove fails to operate on a named path
Matt Harbison <matt_harbison@yahoo.com>
parents:
23533
diff
changeset
|
1249 def badfn(f, msg): |
83bbedc16b3f
addremove: warn when addremove fails to operate on a named path
Matt Harbison <matt_harbison@yahoo.com>
parents:
23533
diff
changeset
|
1250 if f in m.files(): |
25434
5984dd42e140
addremove: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25418
diff
changeset
|
1251 m.bad(f, msg) |
23534
83bbedc16b3f
addremove: warn when addremove fails to operate on a named path
Matt Harbison <matt_harbison@yahoo.com>
parents:
23533
diff
changeset
|
1252 rejected.append(f) |
16167
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
1253 |
25434
5984dd42e140
addremove: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents:
25418
diff
changeset
|
1254 badmatch = matchmod.badmatch(m, badfn) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1255 added, unknown, deleted, removed, forgotten = _interestingfiles( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1256 repo, badmatch |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1257 ) |
18863
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
1258 |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
1259 unknownset = set(unknown + forgotten) |
18863
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
1260 toprint = unknownset.copy() |
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
1261 toprint.update(deleted) |
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
1262 for abs in sorted(toprint): |
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
1263 if repo.ui.verbose or not m.exact(abs): |
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
1264 if abs in unknownset: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1265 status = _(b'adding %s\n') % uipathfn(abs) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1266 label = b'ui.addremove.added' |
18863
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
1267 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1268 status = _(b'removing %s\n') % uipathfn(abs) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1269 label = b'ui.addremove.removed' |
39125
ad88726d6982
addremove: add labels for messages about added and removed files
Boris Feld <boris.feld@octobus.net>
parents:
38895
diff
changeset
|
1270 repo.ui.status(status, label=label) |
18863
1b70e5941ad7
scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents:
18862
diff
changeset
|
1271 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1272 renames = _findrenames( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1273 repo, m, added + unknown, removed + deleted, similarity, uipathfn |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1274 ) |
14320 | 1275 |
1276 if not dry_run: | |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
1277 _markchanges(repo, unknown + forgotten, deleted, renames) |
14320 | 1278 |
16167
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
1279 for f in rejected: |
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
1280 if f in m.files(): |
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
1281 return 1 |
23537
f1b06a8aad42
commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents:
23534
diff
changeset
|
1282 return ret |
16167
94a8396c9305
addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents:
16115
diff
changeset
|
1283 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1284 |
19154
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1285 def marktouched(repo, files, similarity=0.0): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
1286 """Assert that files have somehow been operated upon. files are relative to |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
1287 the repo root.""" |
25467
f64dbe06f3d0
scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents:
25466
diff
changeset
|
1288 m = matchfiles(repo, files, badfn=lambda x, y: rejected.append(x)) |
19154
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1289 rejected = [] |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1290 |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
1291 added, unknown, deleted, removed, forgotten = _interestingfiles(repo, m) |
19154
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1292 |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1293 if repo.ui.verbose: |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
1294 unknownset = set(unknown + forgotten) |
19154
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1295 toprint = unknownset.copy() |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1296 toprint.update(deleted) |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1297 for abs in sorted(toprint): |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1298 if abs in unknownset: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1299 status = _(b'adding %s\n') % abs |
19154
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1300 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1301 status = _(b'removing %s\n') % abs |
19154
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1302 repo.ui.status(status) |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1303 |
41673
0a5a6675c86c
addremove: use uipathfn instead of m.rel() for recorded similatity message
Martin von Zweigbergk <martinvonz@google.com>
parents:
41663
diff
changeset
|
1304 # TODO: We should probably have the caller pass in uipathfn and apply it to |
41708
e21183db2259
scmutil: fix a comment that doesn't match the code
Martin von Zweigbergk <martinvonz@google.com>
parents:
41696
diff
changeset
|
1305 # the messages above too. legacyrelativevalue=True is consistent with how |
41673
0a5a6675c86c
addremove: use uipathfn instead of m.rel() for recorded similatity message
Martin von Zweigbergk <martinvonz@google.com>
parents:
41663
diff
changeset
|
1306 # it used to work. |
41696
b81ecf3571d5
addremove: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents:
41695
diff
changeset
|
1307 uipathfn = getuipathfn(repo, legacyrelativevalue=True) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1308 renames = _findrenames( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1309 repo, m, added + unknown, removed + deleted, similarity, uipathfn |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1310 ) |
19154
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1311 |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
1312 _markchanges(repo, unknown + forgotten, deleted, renames) |
19154
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1313 |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1314 for f in rejected: |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1315 if f in m.files(): |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1316 return 1 |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1317 return 0 |
0c7cf411b390
scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents:
19153
diff
changeset
|
1318 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1319 |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
1320 def _interestingfiles(repo, matcher): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
1321 """Walk dirstate with matcher, looking for files that addremove would care |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
1322 about. |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
1323 |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
1324 This is different from dirstate.status because it doesn't care about |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
1325 whether files are modified or clean.""" |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
1326 added, unknown, deleted, removed, forgotten = [], [], [], [], [] |
33647
377e8ddaebef
pathauditor: disable cache of audited paths by default (issue5628)
Yuya Nishihara <yuya@tcha.org>
parents:
33542
diff
changeset
|
1327 audit_path = pathutil.pathauditor(repo.root, cached=True) |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
1328 |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
1329 ctx = repo[None] |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
1330 dirstate = repo.dirstate |
40088
1d09ba0d2ed3
narrow: move remaining narrow-limited dirstate walks to core
Martin von Zweigbergk <martinvonz@google.com>
parents:
40042
diff
changeset
|
1331 matcher = repo.narrowmatch(matcher, includeexact=True) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1332 walkresults = dirstate.walk( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1333 matcher, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1334 subrepos=sorted(ctx.substate), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1335 unknown=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1336 ignored=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1337 full=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1338 ) |
49004
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48966
diff
changeset
|
1339 for abs, st in walkresults.items(): |
48110
ba79d99ec1ae
dirstate-item: use item's property instead of `state` in addremove
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48056
diff
changeset
|
1340 entry = dirstate.get_entry(abs) |
ba79d99ec1ae
dirstate-item: use item's property instead of `state` in addremove
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48056
diff
changeset
|
1341 if (not entry.any_tracked) and audit_path.check(abs): |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
1342 unknown.append(abs) |
48110
ba79d99ec1ae
dirstate-item: use item's property instead of `state` in addremove
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48056
diff
changeset
|
1343 elif (not entry.removed) and not st: |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
1344 deleted.append(abs) |
48110
ba79d99ec1ae
dirstate-item: use item's property instead of `state` in addremove
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48056
diff
changeset
|
1345 elif entry.removed and st: |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
1346 forgotten.append(abs) |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
1347 # for finding renames |
48110
ba79d99ec1ae
dirstate-item: use item's property instead of `state` in addremove
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48056
diff
changeset
|
1348 elif entry.removed and not st: |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
1349 removed.append(abs) |
48110
ba79d99ec1ae
dirstate-item: use item's property instead of `state` in addremove
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48056
diff
changeset
|
1350 elif entry.added: |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
1351 added.append(abs) |
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
1352 |
23259
9f4778027bc2
addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents:
23142
diff
changeset
|
1353 return added, unknown, deleted, removed, forgotten |
19150
7a4eab2456de
scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents:
19070
diff
changeset
|
1354 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1355 |
41673
0a5a6675c86c
addremove: use uipathfn instead of m.rel() for recorded similatity message
Martin von Zweigbergk <martinvonz@google.com>
parents:
41663
diff
changeset
|
1356 def _findrenames(repo, matcher, added, removed, similarity, uipathfn): |
19152
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
1357 '''Find renames from removed files to added ones.''' |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
1358 renames = {} |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
1359 if similarity > 0: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1360 for old, new, score in similar.findrenames( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1361 repo, added, removed, similarity |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1362 ): |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1363 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1364 repo.ui.verbose |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1365 or not matcher.exact(old) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1366 or not matcher.exact(new) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1367 ): |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1368 repo.ui.status( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1369 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1370 b'recording removal of %s as rename to %s ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1371 b'(%d%% similar)\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1372 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1373 % (uipathfn(old), uipathfn(new), score * 100) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1374 ) |
19152
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
1375 renames[new] = old |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
1376 return renames |
7a1292523db3
scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents:
19151
diff
changeset
|
1377 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1378 |
19153
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
1379 def _markchanges(repo, unknown, deleted, renames): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
1380 """Marks the files in unknown as added, the files in deleted as removed, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
1381 and the files in renames as copied.""" |
19153
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
1382 wctx = repo[None] |
27851
4133a306606c
with: use context manager in _markchanges
Bryan O'Sullivan <bryano@fb.com>
parents:
27706
diff
changeset
|
1383 with repo.wlock(): |
19153
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
1384 wctx.forget(deleted) |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
1385 wctx.add(unknown) |
49004
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48966
diff
changeset
|
1386 for new, old in renames.items(): |
19153
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
1387 wctx.copy(old, new) |
9a4e219bda89
scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents:
19152
diff
changeset
|
1388 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1389 |
41790
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1390 def getrenamedfn(repo, endrev=None): |
42115
27475ae67676
copies: extract function for deciding whether to use changeset-centric algos
Martin von Zweigbergk <martinvonz@google.com>
parents:
42114
diff
changeset
|
1391 if copiesmod.usechangesetcentricalgo(repo): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1392 |
42114
aa84bc48c2f7
getrenamedfn: get copy data from context object if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
41943
diff
changeset
|
1393 def getrenamed(fn, rev): |
aa84bc48c2f7
getrenamedfn: get copy data from context object if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
41943
diff
changeset
|
1394 ctx = repo[rev] |
aa84bc48c2f7
getrenamedfn: get copy data from context object if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
41943
diff
changeset
|
1395 p1copies = ctx.p1copies() |
aa84bc48c2f7
getrenamedfn: get copy data from context object if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
41943
diff
changeset
|
1396 if fn in p1copies: |
aa84bc48c2f7
getrenamedfn: get copy data from context object if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
41943
diff
changeset
|
1397 return p1copies[fn] |
aa84bc48c2f7
getrenamedfn: get copy data from context object if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
41943
diff
changeset
|
1398 p2copies = ctx.p2copies() |
aa84bc48c2f7
getrenamedfn: get copy data from context object if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
41943
diff
changeset
|
1399 if fn in p2copies: |
aa84bc48c2f7
getrenamedfn: get copy data from context object if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
41943
diff
changeset
|
1400 return p2copies[fn] |
aa84bc48c2f7
getrenamedfn: get copy data from context object if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
41943
diff
changeset
|
1401 return None |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1402 |
42114
aa84bc48c2f7
getrenamedfn: get copy data from context object if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
41943
diff
changeset
|
1403 return getrenamed |
aa84bc48c2f7
getrenamedfn: get copy data from context object if configured
Martin von Zweigbergk <martinvonz@google.com>
parents:
41943
diff
changeset
|
1404 |
41790
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1405 rcache = {} |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1406 if endrev is None: |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1407 endrev = len(repo) |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1408 |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1409 def getrenamed(fn, rev): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
1410 """looks up all renames for a file (up to endrev) the first |
41790
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1411 time the file is given. It indexes on the changerev and only |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1412 parses the manifest if linkrev != changerev. |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
1413 Returns rename info for fn at changerev rev.""" |
41790
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1414 if fn not in rcache: |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1415 rcache[fn] = {} |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1416 fl = repo.file(fn) |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1417 for i in fl: |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1418 lr = fl.linkrev(i) |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1419 renamed = fl.renamed(fl.node(i)) |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1420 rcache[fn][lr] = renamed and renamed[0] |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1421 if lr >= endrev: |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1422 break |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1423 if rev in rcache[fn]: |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1424 return rcache[fn][rev] |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1425 |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1426 # If linkrev != rev (i.e. rev not found in rcache) fallback to |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1427 # filectx logic. |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1428 try: |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1429 return repo[rev][fn].copysource() |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1430 except error.LookupError: |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1431 return None |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1432 |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1433 return getrenamed |
e9b9ee9af4a9
templatekw: move getrenamedfn() to scmutil (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41708
diff
changeset
|
1434 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1435 |
42518
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1436 def getcopiesfn(repo, endrev=None): |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1437 if copiesmod.usechangesetcentricalgo(repo): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1438 |
42518
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1439 def copiesfn(ctx): |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1440 if ctx.p2copies(): |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1441 allcopies = ctx.p1copies().copy() |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1442 # There should be no overlap |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1443 allcopies.update(ctx.p2copies()) |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1444 return sorted(allcopies.items()) |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1445 else: |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1446 return sorted(ctx.p1copies().items()) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1447 |
42518
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1448 else: |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1449 getrenamed = getrenamedfn(repo, endrev) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1450 |
42518
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1451 def copiesfn(ctx): |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1452 copies = [] |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1453 for fn in ctx.files(): |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1454 rename = getrenamed(fn, ctx.rev()) |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1455 if rename: |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1456 copies.append((fn, rename)) |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1457 return copies |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1458 |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1459 return copiesfn |
88ba0ff94605
copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents:
42115
diff
changeset
|
1460 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1461 |
14320 | 1462 def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None): |
1463 """Update the dirstate to reflect the intent of copying src to dst. For | |
1464 different reasons it might not end with dst being marked as copied from src. | |
1465 """ | |
1466 origsrc = repo.dirstate.copied(src) or src | |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1467 if dst == origsrc: # copying back a copy? |
48115
8f452fecd0a4
dirstate-item: use item's property when computing a copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48110
diff
changeset
|
1468 entry = repo.dirstate.get_entry(dst) |
8f452fecd0a4
dirstate-item: use item's property when computing a copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48110
diff
changeset
|
1469 if (entry.added or not entry.tracked) and not dryrun: |
47729
b66ae4468c9a
copy: use `set_tracked` instead of `normallookup` in `dirstatecopy`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47693
diff
changeset
|
1470 repo.dirstate.set_tracked(dst) |
14320 | 1471 else: |
48115
8f452fecd0a4
dirstate-item: use item's property when computing a copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48110
diff
changeset
|
1472 if repo.dirstate.get_entry(origsrc).added and origsrc == src: |
14320 | 1473 if not ui.quiet: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1474 ui.warn( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1475 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1476 b"%s has not been committed yet, so no copy " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1477 b"data will be stored for %s.\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1478 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1479 % (repo.pathto(origsrc, cwd), repo.pathto(dst, cwd)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1480 ) |
48115
8f452fecd0a4
dirstate-item: use item's property when computing a copies
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48110
diff
changeset
|
1481 if not repo.dirstate.get_entry(dst).tracked and not dryrun: |
14320 | 1482 wctx.add([dst]) |
1483 elif not dryrun: | |
1484 wctx.copy(origsrc, dst) | |
14482
58b36e9ea783
introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents:
14435
diff
changeset
|
1485 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1486 |
41942
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
1487 def movedirstate(repo, newctx, match=None): |
41943
ad4a3e2eedb3
scmutil: document matcher argument of movedirstate()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41942
diff
changeset
|
1488 """Move the dirstate to newctx and adjust it as necessary. |
ad4a3e2eedb3
scmutil: document matcher argument of movedirstate()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41942
diff
changeset
|
1489 |
ad4a3e2eedb3
scmutil: document matcher argument of movedirstate()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41942
diff
changeset
|
1490 A matcher can be provided as an optimization. It is probably a bug to pass |
ad4a3e2eedb3
scmutil: document matcher argument of movedirstate()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41942
diff
changeset
|
1491 a matcher that doesn't match all the differences between the parent of the |
ad4a3e2eedb3
scmutil: document matcher argument of movedirstate()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41942
diff
changeset
|
1492 working copy and newctx. |
ad4a3e2eedb3
scmutil: document matcher argument of movedirstate()
Martin von Zweigbergk <martinvonz@google.com>
parents:
41942
diff
changeset
|
1493 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1494 oldctx = repo[b'.'] |
41942
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
1495 ds = repo.dirstate |
44039
0750cbffdb3b
movedirstate: get copies from dirstate before setting parents
Martin von Zweigbergk <martinvonz@google.com>
parents:
44016
diff
changeset
|
1496 copies = dict(ds.copies()) |
47055
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46976
diff
changeset
|
1497 ds.setparents(newctx.node(), repo.nullid) |
41942
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
1498 s = newctx.status(oldctx, match=match) |
47592
0f5c203eb5ab
dirstate: add a function to update tracking status while "moving" parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47306
diff
changeset
|
1499 |
41942
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
1500 for f in s.modified: |
47693
46c318b9b9a4
dirstate: rename `update_file_reference` to `update_file_p1`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47592
diff
changeset
|
1501 ds.update_file_p1(f, p1_tracked=True) |
41942
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
1502 |
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
1503 for f in s.added: |
47693
46c318b9b9a4
dirstate: rename `update_file_reference` to `update_file_p1`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47592
diff
changeset
|
1504 ds.update_file_p1(f, p1_tracked=False) |
41942
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
1505 |
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
1506 for f in s.removed: |
47693
46c318b9b9a4
dirstate: rename `update_file_reference` to `update_file_p1`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47592
diff
changeset
|
1507 ds.update_file_p1(f, p1_tracked=True) |
41942
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
1508 |
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
1509 # Merge old parent and old working dir copies |
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
1510 oldcopies = copiesmod.pathcopies(newctx, oldctx, match) |
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
1511 oldcopies.update(copies) |
49004
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48966
diff
changeset
|
1512 copies = {dst: oldcopies.get(src, src) for dst, src in oldcopies.items()} |
41942
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
1513 # Adjust the dirstate copies |
49004
f254fc73d956
global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48966
diff
changeset
|
1514 for dst, src in copies.items(): |
48117
207df24a31f6
dirstate-item: use `added` instead of `state` when moving dirstate
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48115
diff
changeset
|
1515 if src not in newctx or dst in newctx or not ds.get_entry(dst).added: |
41942
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
1516 src = None |
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
1517 ds.copy(src, dst) |
44104
85c4cd73996b
localrepo: also fastpath access to working copy parents when possible
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44075
diff
changeset
|
1518 repo._quick_access_changeid_invalidate() |
41942
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41804
diff
changeset
|
1519 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1520 |
45493
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1521 def filterrequirements(requirements): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
1522 """filters the requirements into two sets: |
45493
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1523 |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1524 wcreq: requirements which should be written in .hg/requires |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1525 storereq: which should be written in .hg/store/requires |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1526 |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1527 Returns (wcreq, storereq) |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1528 """ |
45494
d252f51ab032
share: introduce config option to store requires in .hg/store
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45493
diff
changeset
|
1529 if requirementsmod.SHARESAFE_REQUIREMENT in requirements: |
45493
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1530 wc, store = set(), set() |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1531 for r in requirements: |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1532 if r in requirementsmod.WORKING_DIR_REQUIREMENTS: |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1533 wc.add(r) |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1534 else: |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1535 store.add(r) |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1536 return wc, store |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1537 return requirements, None |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1538 |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1539 |
45558
10284ce3d5ed
scmutil: introduce function to check whether repo uses treemanifest or not
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45527
diff
changeset
|
1540 def istreemanifest(repo): |
47031
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
46976
diff
changeset
|
1541 """returns whether the repository is using treemanifest or not""" |
45558
10284ce3d5ed
scmutil: introduce function to check whether repo uses treemanifest or not
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45527
diff
changeset
|
1542 return requirementsmod.TREEMANIFEST_REQUIREMENT in repo.requirements |
10284ce3d5ed
scmutil: introduce function to check whether repo uses treemanifest or not
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45527
diff
changeset
|
1543 |
10284ce3d5ed
scmutil: introduce function to check whether repo uses treemanifest or not
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45527
diff
changeset
|
1544 |
45106
a03c177a4679
scmutil: add writereporequirements() and route requires writing through it
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45073
diff
changeset
|
1545 def writereporequirements(repo, requirements=None): |
46242
cb12658bf0e1
scmutil: improve documentation of writereporequirements()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46117
diff
changeset
|
1546 """writes requirements for the repo |
cb12658bf0e1
scmutil: improve documentation of writereporequirements()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46117
diff
changeset
|
1547 |
cb12658bf0e1
scmutil: improve documentation of writereporequirements()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46117
diff
changeset
|
1548 Requirements are written to .hg/requires and .hg/store/requires based |
cb12658bf0e1
scmutil: improve documentation of writereporequirements()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46117
diff
changeset
|
1549 on whether share-safe mode is enabled and which requirements are wdir |
cb12658bf0e1
scmutil: improve documentation of writereporequirements()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46117
diff
changeset
|
1550 requirements and which are store requirements |
cb12658bf0e1
scmutil: improve documentation of writereporequirements()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
46117
diff
changeset
|
1551 """ |
45106
a03c177a4679
scmutil: add writereporequirements() and route requires writing through it
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45073
diff
changeset
|
1552 if requirements: |
a03c177a4679
scmutil: add writereporequirements() and route requires writing through it
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45073
diff
changeset
|
1553 repo.requirements = requirements |
45493
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1554 wcreq, storereq = filterrequirements(repo.requirements) |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1555 if wcreq is not None: |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1556 writerequires(repo.vfs, wcreq) |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1557 if storereq is not None: |
9a99ab8217bd
scmutil: introduce filterrequirements() to split reqs into wc and store ones
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45106
diff
changeset
|
1558 writerequires(repo.svfs, storereq) |
45934
aba4f2c97e74
scmutil: try-delete `.hg/store/requires` if store requirements are empty
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45930
diff
changeset
|
1559 elif repo.ui.configbool(b'format', b'usestore'): |
aba4f2c97e74
scmutil: try-delete `.hg/store/requires` if store requirements are empty
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45930
diff
changeset
|
1560 # only remove store requires if we are using store |
aba4f2c97e74
scmutil: try-delete `.hg/store/requires` if store requirements are empty
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45930
diff
changeset
|
1561 repo.svfs.tryunlink(b'requires') |
45106
a03c177a4679
scmutil: add writereporequirements() and route requires writing through it
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45073
diff
changeset
|
1562 |
a03c177a4679
scmutil: add writereporequirements() and route requires writing through it
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45073
diff
changeset
|
1563 |
24934
5abd0a76bc8f
requires: move requires file writing func from localrepo to scmutil
Drew Gottlieb <drgott@google.com>
parents:
24755
diff
changeset
|
1564 def writerequires(opener, requirements): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1565 with opener(b'requires', b'w', atomictemp=True) as fp: |
27706
22e362da27cf
scmutil: use context managers for file handles
Gregory Szorc <gregory.szorc@gmail.com>
parents:
27651
diff
changeset
|
1566 for r in sorted(requirements): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1567 fp.write(b"%s\n" % r) |
24934
5abd0a76bc8f
requires: move requires file writing func from localrepo to scmutil
Drew Gottlieb <drgott@google.com>
parents:
24755
diff
changeset
|
1568 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1569 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49025
diff
changeset
|
1570 class filecachesubentry: |
20042
9a72d3886888
scmutil.filecacheentry: make stat argument to constructor mandatory
Siddharth Agarwal <sid0@fb.com>
parents:
20033
diff
changeset
|
1571 def __init__(self, path, stat): |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1572 self.path = path |
18315
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1573 self.cachestat = None |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1574 self._cacheable = None |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1575 |
18315
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1576 if stat: |
20043
88bd8df008f2
scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents:
20042
diff
changeset
|
1577 self.cachestat = filecachesubentry.stat(self.path) |
18315
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1578 |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1579 if self.cachestat: |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1580 self._cacheable = self.cachestat.cacheable() |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1581 else: |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1582 # None means we don't know yet |
216230643ae2
filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents:
18213
diff
changeset
|
1583 self._cacheable = None |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1584 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1585 def refresh(self): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1586 if self.cacheable(): |
20043
88bd8df008f2
scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents:
20042
diff
changeset
|
1587 self.cachestat = filecachesubentry.stat(self.path) |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1588 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1589 def cacheable(self): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1590 if self._cacheable is not None: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1591 return self._cacheable |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1592 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1593 # we don't know yet, assume it is for now |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1594 return True |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1595 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1596 def changed(self): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1597 # no point in going further if we can't cache it |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1598 if not self.cacheable(): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1599 return True |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1600 |
20043
88bd8df008f2
scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents:
20042
diff
changeset
|
1601 newstat = filecachesubentry.stat(self.path) |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1602 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1603 # we may not know if it's cacheable yet, check again now |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1604 if newstat and self._cacheable is None: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1605 self._cacheable = newstat.cacheable() |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1606 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1607 # check again |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1608 if not self._cacheable: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1609 return True |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1610 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1611 if self.cachestat != newstat: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1612 self.cachestat = newstat |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1613 return True |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1614 else: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1615 return False |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1616 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1617 @staticmethod |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1618 def stat(path): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1619 try: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1620 return util.cachestat(path) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25658
diff
changeset
|
1621 except OSError as e: |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1622 if e.errno != errno.ENOENT: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1623 raise |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1624 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1625 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49025
diff
changeset
|
1626 class filecacheentry: |
20044
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1627 def __init__(self, paths, stat=True): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1628 self._entries = [] |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1629 for path in paths: |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1630 self._entries.append(filecachesubentry(path, stat)) |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1631 |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1632 def changed(self): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1633 '''true if any entry has changed''' |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1634 for entry in self._entries: |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1635 if entry.changed(): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1636 return True |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1637 return False |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1638 |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1639 def refresh(self): |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1640 for entry in self._entries: |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1641 entry.refresh() |
d38de18d187a
scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents:
20043
diff
changeset
|
1642 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1643 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49025
diff
changeset
|
1644 class filecache: |
38676
3b072388ca78
scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38659
diff
changeset
|
1645 """A property like decorator that tracks files under .hg/ for updates. |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1646 |
38676
3b072388ca78
scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38659
diff
changeset
|
1647 On first access, the files defined as arguments are stat()ed and the |
3b072388ca78
scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38659
diff
changeset
|
1648 results cached. The decorated function is called. The results are stashed |
3b072388ca78
scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38659
diff
changeset
|
1649 away in a ``_filecache`` dict on the object whose method is decorated. |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1650 |
40493
7caf632e30c3
filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40492
diff
changeset
|
1651 On subsequent access, the cached result is used as it is set to the |
7caf632e30c3
filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40492
diff
changeset
|
1652 instance dictionary. |
38676
3b072388ca78
scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38659
diff
changeset
|
1653 |
40493
7caf632e30c3
filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40492
diff
changeset
|
1654 On external property set/delete operations, the caller must update the |
7caf632e30c3
filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40492
diff
changeset
|
1655 corresponding _filecache entry appropriately. Use __class__.<attr>.set() |
7caf632e30c3
filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40492
diff
changeset
|
1656 instead of directly setting <attr>. |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1657 |
40493
7caf632e30c3
filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40492
diff
changeset
|
1658 When using the property API, the cached data is always used if available. |
7caf632e30c3
filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40492
diff
changeset
|
1659 No stat() is performed to check if the file has changed. |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1660 |
38676
3b072388ca78
scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38659
diff
changeset
|
1661 Others can muck about with the state of the ``_filecache`` dict. e.g. they |
3b072388ca78
scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38659
diff
changeset
|
1662 can populate an entry before the property's getter is called. In this case, |
3b072388ca78
scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38659
diff
changeset
|
1663 entries in ``_filecache`` will be used during property operations, |
3b072388ca78
scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38659
diff
changeset
|
1664 if available. If the underlying file changes, it is up to external callers |
3b072388ca78
scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38659
diff
changeset
|
1665 to reflect this by e.g. calling ``delattr(obj, attr)`` to remove the cached |
3b072388ca78
scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38659
diff
changeset
|
1666 method result as well as possibly calling ``del obj._filecache[attr]`` to |
3b072388ca78
scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38659
diff
changeset
|
1667 remove the ``filecacheentry``. |
3b072388ca78
scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38659
diff
changeset
|
1668 """ |
3b072388ca78
scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38659
diff
changeset
|
1669 |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1670 def __init__(self, *paths): |
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1671 self.paths = paths |
16198
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1672 |
48056
37a41267d000
branching: merge stable into default
Raphaël Gomès <rgomes@octobus.net>
parents:
48053
diff
changeset
|
1673 def tracked_paths(self, obj): |
37a41267d000
branching: merge stable into default
Raphaël Gomès <rgomes@octobus.net>
parents:
48053
diff
changeset
|
1674 return [self.join(obj, path) for path in self.paths] |
37a41267d000
branching: merge stable into default
Raphaël Gomès <rgomes@octobus.net>
parents:
48053
diff
changeset
|
1675 |
16198
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1676 def join(self, obj, fname): |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1677 """Used to compute the runtime path of a cached file. |
16198
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1678 |
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1679 Users should subclass filecache and provide their own version of this |
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1680 function to call the appropriate join function on 'obj' (an instance |
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1681 of the class that its member function was decorated). |
fa8488565afd
filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents:
16115
diff
changeset
|
1682 """ |
31294
1937671105bc
filecache: make 'join' abstract
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31227
diff
changeset
|
1683 raise NotImplementedError |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1684 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1685 def __call__(self, func): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1686 self.func = func |
37913
73a74f29eb87
scmutil: clean up bytes/string cache decorator mess on Python 3 again
Augie Fackler <augie@google.com>
parents:
37912
diff
changeset
|
1687 self.sname = func.__name__ |
73a74f29eb87
scmutil: clean up bytes/string cache decorator mess on Python 3 again
Augie Fackler <augie@google.com>
parents:
37912
diff
changeset
|
1688 self.name = pycompat.sysbytes(self.sname) |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1689 return self |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1690 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1691 def __get__(self, obj, type=None): |
29373
36fbd72c2f39
scmutil: allow access to filecache descriptor on class
Martijn Pieters <mjpieters@fb.com>
parents:
29367
diff
changeset
|
1692 # if accessed on the class, return the descriptor itself. |
36fbd72c2f39
scmutil: allow access to filecache descriptor on class
Martijn Pieters <mjpieters@fb.com>
parents:
29367
diff
changeset
|
1693 if obj is None: |
36fbd72c2f39
scmutil: allow access to filecache descriptor on class
Martijn Pieters <mjpieters@fb.com>
parents:
29367
diff
changeset
|
1694 return self |
40493
7caf632e30c3
filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40492
diff
changeset
|
1695 |
7caf632e30c3
filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40492
diff
changeset
|
1696 assert self.sname not in obj.__dict__ |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1697 |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1698 entry = obj._filecache.get(self.name) |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1699 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1700 if entry: |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1701 if entry.changed(): |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1702 entry.obj = self.func(obj) |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1703 else: |
48056
37a41267d000
branching: merge stable into default
Raphaël Gomès <rgomes@octobus.net>
parents:
48053
diff
changeset
|
1704 paths = self.tracked_paths(obj) |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1705 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1706 # We stat -before- creating the object so our cache doesn't lie if |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1707 # a writer modified between the time we read and stat |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1708 entry = filecacheentry(paths, True) |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1709 entry.obj = self.func(obj) |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1710 |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1711 obj._filecache[self.name] = entry |
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1712 |
37913
73a74f29eb87
scmutil: clean up bytes/string cache decorator mess on Python 3 again
Augie Fackler <augie@google.com>
parents:
37912
diff
changeset
|
1713 obj.__dict__[self.sname] = entry.obj |
14928
dca59d5be12d
scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents:
14861
diff
changeset
|
1714 return entry.obj |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1715 |
40493
7caf632e30c3
filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40492
diff
changeset
|
1716 # don't implement __set__(), which would make __dict__ lookup as slow as |
7caf632e30c3
filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40492
diff
changeset
|
1717 # function call. |
7caf632e30c3
filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40492
diff
changeset
|
1718 |
7caf632e30c3
filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents:
40492
diff
changeset
|
1719 def set(self, obj, value): |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1720 if self.name not in obj._filecache: |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1721 # we add an entry for the missing value because X in __dict__ |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1722 # implies X in _filecache |
48056
37a41267d000
branching: merge stable into default
Raphaël Gomès <rgomes@octobus.net>
parents:
48053
diff
changeset
|
1723 paths = self.tracked_paths(obj) |
20045
b3684fd2ff1a
scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents:
20044
diff
changeset
|
1724 ce = filecacheentry(paths, False) |
18316
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1725 obj._filecache[self.name] = ce |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1726 else: |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1727 ce = obj._filecache[self.name] |
f36375576ed5
filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents:
18315
diff
changeset
|
1728 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1729 ce.obj = value # update cached copy |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1730 obj.__dict__[self.sname] = value # update copy returned by obj.x |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1731 |
16115
236bb604dc39
scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents:
16068
diff
changeset
|
1732 |
34457
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1733 def extdatasource(repo, source): |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1734 """Gather a map of rev -> value dict from the specified source |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1735 |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1736 A source spec is treated as a URL, with a special case shell: type |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1737 for parsing the output from a shell command. |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1738 |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1739 The data is parsed as a series of newline-separated records where |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1740 each record is a revision specifier optionally followed by a space |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1741 and a freeform string value. If the revision is known locally, it |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1742 is converted to a rev, otherwise the record is skipped. |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1743 |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1744 Note that both key and value are treated as UTF-8 and converted to |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1745 the local encoding. This allows uniformity between local and |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1746 remote data sources. |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1747 """ |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1748 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1749 spec = repo.ui.config(b"extdata", source) |
34457
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1750 if not spec: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1751 raise error.Abort(_(b"unknown extdata source '%s'") % source) |
34457
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1752 |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1753 data = {} |
34462
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34461
diff
changeset
|
1754 src = proc = None |
34457
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1755 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1756 if spec.startswith(b"shell:"): |
34462
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34461
diff
changeset
|
1757 # external commands should be run relative to the repo root |
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34461
diff
changeset
|
1758 cmd = spec[6:] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1759 proc = subprocess.Popen( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1760 procutil.tonativestr(cmd), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1761 shell=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1762 bufsize=-1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1763 close_fds=procutil.closefds, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1764 stdout=subprocess.PIPE, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1765 cwd=procutil.tonativestr(repo.root), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1766 ) |
34462
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34461
diff
changeset
|
1767 src = proc.stdout |
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34461
diff
changeset
|
1768 else: |
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34461
diff
changeset
|
1769 # treat as a URL or file |
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34461
diff
changeset
|
1770 src = url.open(repo.ui, spec) |
34461
910adadf08e8
extdata: just use iterator to read lines one by one
Yuya Nishihara <yuya@tcha.org>
parents:
34460
diff
changeset
|
1771 for l in src: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1772 if b" " in l: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1773 k, v = l.strip().split(b" ", 1) |
34457
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1774 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1775 k, v = l.strip(), b"" |
34457
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1776 |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1777 k = encoding.tolocal(k) |
34460
d5c5cc767b7e
extdata: ignore ambiguous identifier as well
Yuya Nishihara <yuya@tcha.org>
parents:
34457
diff
changeset
|
1778 try: |
37360
d0d55980ffa7
extdatasource: use revsymbol() for converting to node
Martin von Zweigbergk <martinvonz@google.com>
parents:
37350
diff
changeset
|
1779 data[revsingle(repo, k).rev()] = encoding.tolocal(v) |
46116
be3d8178251e
errors: raise InputError if an ambiguous revision id prefix is used
Martin von Zweigbergk <martinvonz@google.com>
parents:
46097
diff
changeset
|
1780 except (error.LookupError, error.RepoLookupError, error.InputError): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1781 pass # we ignore data for nodes that don't exist locally |
34457
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1782 finally: |
34462
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34461
diff
changeset
|
1783 if proc: |
42576
ea6558db1011
extdata: avoid crashing inside subprocess when we get a revset parse error
Augie Fackler <augie@google.com>
parents:
42518
diff
changeset
|
1784 try: |
ea6558db1011
extdata: avoid crashing inside subprocess when we get a revset parse error
Augie Fackler <augie@google.com>
parents:
42518
diff
changeset
|
1785 proc.communicate() |
ea6558db1011
extdata: avoid crashing inside subprocess when we get a revset parse error
Augie Fackler <augie@google.com>
parents:
42518
diff
changeset
|
1786 except ValueError: |
ea6558db1011
extdata: avoid crashing inside subprocess when we get a revset parse error
Augie Fackler <augie@google.com>
parents:
42518
diff
changeset
|
1787 # This happens if we started iterating src and then |
ea6558db1011
extdata: avoid crashing inside subprocess when we get a revset parse error
Augie Fackler <augie@google.com>
parents:
42518
diff
changeset
|
1788 # get a parse error on a line. It should be safe to ignore. |
ea6558db1011
extdata: avoid crashing inside subprocess when we get a revset parse error
Augie Fackler <augie@google.com>
parents:
42518
diff
changeset
|
1789 pass |
34462
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34461
diff
changeset
|
1790 if src: |
c67db5dc131d
extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents:
34461
diff
changeset
|
1791 src.close() |
35419
b1959391a088
extdata: abort if external command exits with non-zero status (BC)
Yuya Nishihara <yuya@tcha.org>
parents:
35317
diff
changeset
|
1792 if proc and proc.returncode != 0: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1793 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1794 _(b"extdata command '%s' failed: %s") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1795 % (cmd, procutil.explainexit(proc.returncode)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1796 ) |
34457
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1797 |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1798 return data |
7757cc48b766
extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents:
34368
diff
changeset
|
1799 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1800 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49025
diff
changeset
|
1801 class progress: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1802 def __init__(self, ui, updatebar, topic, unit=b"", total=None): |
38351
bec1212eceaa
progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
38340
diff
changeset
|
1803 self.ui = ui |
bec1212eceaa
progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
38340
diff
changeset
|
1804 self.pos = 0 |
bec1212eceaa
progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
38340
diff
changeset
|
1805 self.topic = topic |
bec1212eceaa
progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
38340
diff
changeset
|
1806 self.unit = unit |
bec1212eceaa
progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
38340
diff
changeset
|
1807 self.total = total |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1808 self.debug = ui.configbool(b'progress', b'debug') |
41146
963462786f6e
progress: check what type of progress bar to use only once per topic
Martin von Zweigbergk <martinvonz@google.com>
parents:
41145
diff
changeset
|
1809 self._updatebar = updatebar |
38351
bec1212eceaa
progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
38340
diff
changeset
|
1810 |
38380
800f5a2c869e
progress: make the progress helper a context manager
Martin von Zweigbergk <martinvonz@google.com>
parents:
38379
diff
changeset
|
1811 def __enter__(self): |
38507
077301ac69dc
scmutil: fix __enter__ in progress context manager
Danny Hooper <hooper@google.com>
parents:
38460
diff
changeset
|
1812 return self |
38380
800f5a2c869e
progress: make the progress helper a context manager
Martin von Zweigbergk <martinvonz@google.com>
parents:
38379
diff
changeset
|
1813 |
800f5a2c869e
progress: make the progress helper a context manager
Martin von Zweigbergk <martinvonz@google.com>
parents:
38379
diff
changeset
|
1814 def __exit__(self, exc_type, exc_value, exc_tb): |
800f5a2c869e
progress: make the progress helper a context manager
Martin von Zweigbergk <martinvonz@google.com>
parents:
38379
diff
changeset
|
1815 self.complete() |
800f5a2c869e
progress: make the progress helper a context manager
Martin von Zweigbergk <martinvonz@google.com>
parents:
38379
diff
changeset
|
1816 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1817 def update(self, pos, item=b"", total=None): |
38425
6dea017eb6ba
progress: enforce use of complete() on the helper class
Martin von Zweigbergk <martinvonz@google.com>
parents:
38380
diff
changeset
|
1818 assert pos is not None |
38351
bec1212eceaa
progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
38340
diff
changeset
|
1819 if total: |
bec1212eceaa
progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
38340
diff
changeset
|
1820 self.total = total |
bec1212eceaa
progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
38340
diff
changeset
|
1821 self.pos = pos |
41209
b223fc1c6b4c
progress: change _updatebar() to take parameters as arguments
Yuya Nishihara <yuya@tcha.org>
parents:
41146
diff
changeset
|
1822 self._updatebar(self.topic, self.pos, item, self.unit, self.total) |
41145
3025fd3c2e71
progress: split up _print() method in bar-updating and debug-printing
Martin von Zweigbergk <martinvonz@google.com>
parents:
41144
diff
changeset
|
1823 if self.debug: |
3025fd3c2e71
progress: split up _print() method in bar-updating and debug-printing
Martin von Zweigbergk <martinvonz@google.com>
parents:
41144
diff
changeset
|
1824 self._printdebug(item) |
38351
bec1212eceaa
progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
38340
diff
changeset
|
1825 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1826 def increment(self, step=1, item=b"", total=None): |
38351
bec1212eceaa
progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
38340
diff
changeset
|
1827 self.update(self.pos + step, item, total) |
bec1212eceaa
progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
38340
diff
changeset
|
1828 |
38379
ef692614e601
progress: hide update(None) in a new complete() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
38351
diff
changeset
|
1829 def complete(self): |
41143
8cf92ca92bfe
progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents:
40902
diff
changeset
|
1830 self.pos = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1831 self.unit = b"" |
41143
8cf92ca92bfe
progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents:
40902
diff
changeset
|
1832 self.total = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1833 self._updatebar(self.topic, self.pos, b"", self.unit, self.total) |
38379
ef692614e601
progress: hide update(None) in a new complete() method
Martin von Zweigbergk <martinvonz@google.com>
parents:
38351
diff
changeset
|
1834 |
41145
3025fd3c2e71
progress: split up _print() method in bar-updating and debug-printing
Martin von Zweigbergk <martinvonz@google.com>
parents:
41144
diff
changeset
|
1835 def _printdebug(self, item): |
44063
089255b1341e
scmutil: fix an unbound variable with progressbar debug enabled
Matt Harbison <matt_harbison@yahoo.com>
parents:
44060
diff
changeset
|
1836 unit = b'' |
41143
8cf92ca92bfe
progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents:
40902
diff
changeset
|
1837 if self.unit: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1838 unit = b' ' + self.unit |
41143
8cf92ca92bfe
progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents:
40902
diff
changeset
|
1839 if item: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1840 item = b' ' + item |
41143
8cf92ca92bfe
progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents:
40902
diff
changeset
|
1841 |
8cf92ca92bfe
progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents:
40902
diff
changeset
|
1842 if self.total: |
8cf92ca92bfe
progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents:
40902
diff
changeset
|
1843 pct = 100.0 * self.pos / self.total |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1844 self.ui.debug( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1845 b'%s:%s %d/%d%s (%4.2f%%)\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1846 % (self.topic, item, self.pos, self.total, unit, pct) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1847 ) |
41143
8cf92ca92bfe
progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents:
40902
diff
changeset
|
1848 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1849 self.ui.debug(b'%s:%s %d%s\n' % (self.topic, item, self.pos, unit)) |
38351
bec1212eceaa
progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents:
38340
diff
changeset
|
1850 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1851 |
26906
e40af07e518e
scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26836
diff
changeset
|
1852 def gdinitconfig(ui): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
1853 """helper function to know if a repo should be created as general delta""" |
26907
dfab6edb98e3
format: introduce 'format.usegeneraldelta`
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26906
diff
changeset
|
1854 # experimental config: format.generaldelta |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1855 return ui.configbool(b'format', b'generaldelta') or ui.configbool( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1856 b'format', b'usegeneraldelta' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1857 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1858 |
26906
e40af07e518e
scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26836
diff
changeset
|
1859 |
26907
dfab6edb98e3
format: introduce 'format.usegeneraldelta`
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26906
diff
changeset
|
1860 def gddeltaconfig(ui): |
45957
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45934
diff
changeset
|
1861 """helper function to know if incoming delta should be optimised""" |
26906
e40af07e518e
scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26836
diff
changeset
|
1862 # experimental config: format.generaldelta |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1863 return ui.configbool(b'format', b'generaldelta') |
31559
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1864 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1865 |
49037
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
49025
diff
changeset
|
1866 class simplekeyvaluefile: |
31559
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1867 """A simple file with key=value lines |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1868 |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1869 Keys must be alphanumerics and start with a letter, values must not |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1870 contain '\n' characters""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1871 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1872 firstlinekey = b'__firstline' |
31559
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1873 |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1874 def __init__(self, vfs, path, keys=None): |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1875 self.vfs = vfs |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1876 self.path = path |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1877 |
32310
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1878 def read(self, firstlinenonkeyval=False): |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1879 """Read the contents of a simple key-value file |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1880 |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1881 'firstlinenonkeyval' indicates whether the first line of file should |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1882 be treated as a key-value pair or reuturned fully under the |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1883 __firstline key.""" |
31559
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1884 lines = self.vfs.readlines(self.path) |
32310
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1885 d = {} |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1886 if firstlinenonkeyval: |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1887 if not lines: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1888 e = _(b"empty simplekeyvalue file") |
32310
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1889 raise error.CorruptedState(e) |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1890 # we don't want to include '\n' in the __firstline |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1891 d[self.firstlinekey] = lines[0][:-1] |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1892 del lines[0] |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1893 |
31559
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1894 try: |
32309
ed2c44741190
scmutil: add simplekeyvaluefile reading test
Kostia Balytskyi <ikostia@fb.com>
parents:
32221
diff
changeset
|
1895 # the 'if line.strip()' part prevents us from failing on empty |
ed2c44741190
scmutil: add simplekeyvaluefile reading test
Kostia Balytskyi <ikostia@fb.com>
parents:
32221
diff
changeset
|
1896 # lines which only contain '\n' therefore are not skipped |
ed2c44741190
scmutil: add simplekeyvaluefile reading test
Kostia Balytskyi <ikostia@fb.com>
parents:
32221
diff
changeset
|
1897 # by 'if line' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1898 updatedict = dict( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1899 line[:-1].split(b'=', 1) for line in lines if line.strip() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1900 ) |
32310
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1901 if self.firstlinekey in updatedict: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1902 e = _(b"%r can't be used as a key") |
32310
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1903 raise error.CorruptedState(e % self.firstlinekey) |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1904 d.update(updatedict) |
31559
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1905 except ValueError as e: |
43365
899e55e2d375
py3: fix exception message encoding in scmutil.py's simplekeyvaluefile.read
Emmanuel Leblond <emmanuel.leblond@gmail.com>
parents:
43147
diff
changeset
|
1906 raise error.CorruptedState(stringutil.forcebytestr(e)) |
31559
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1907 return d |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1908 |
32310
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1909 def write(self, data, firstline=None): |
31559
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1910 """Write key=>value mapping to a file |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1911 data is a dict. Keys must be alphanumerical and start with a letter. |
32310
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1912 Values must not contain newline characters. |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1913 |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1914 If 'firstline' is not None, it is written to file before |
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1915 everything else, as it is, not in a key=value form""" |
31559
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1916 lines = [] |
32310
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1917 if firstline is not None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1918 lines.append(b'%s\n' % firstline) |
32310
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1919 |
31559
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1920 for k, v in data.items(): |
32310
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1921 if k == self.firstlinekey: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1922 e = b"key name '%s' is reserved" % self.firstlinekey |
32310
218ca8526ec0
scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents:
32309
diff
changeset
|
1923 raise error.ProgrammingError(e) |
35953
558e01a23f40
py3: slice on bytes to prevent getting the ascii values
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35928
diff
changeset
|
1924 if not k[0:1].isalpha(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1925 e = b"keys must start with a letter in a key-value file" |
31559
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1926 raise error.ProgrammingError(e) |
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1927 if not k.isalnum(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1928 e = b"invalid key name in a simple key-value file" |
31559
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1929 raise error.ProgrammingError(e) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1930 if b'\n' in v: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1931 e = b"invalid value in a simple key-value file" |
31559
56acc4250900
scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents:
31428
diff
changeset
|
1932 raise error.ProgrammingError(e) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1933 lines.append(b"%s=%s\n" % (k, v)) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1934 with self.vfs(self.path, mode=b'wb', atomictemp=True) as fp: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1935 fp.write(b''.join(lines)) |
33252
53b3a1968aa6
obsolete: reports the number of local changeset obsoleted when unbundling
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33246
diff
changeset
|
1936 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1937 |
33541
b47fef6d2365
transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents:
33511
diff
changeset
|
1938 _reportobsoletedsource = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1939 b'debugobsolete', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1940 b'pull', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1941 b'push', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1942 b'serve', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1943 b'unbundle', |
33541
b47fef6d2365
transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents:
33511
diff
changeset
|
1944 ] |
b47fef6d2365
transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents:
33511
diff
changeset
|
1945 |
34661
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1946 _reportnewcssource = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1947 b'pull', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1948 b'unbundle', |
34661
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1949 ] |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
1950 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1951 |
45073
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1952 def prefetchfiles(repo, revmatches): |
37762
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1953 """Invokes the registered file prefetch functions, allowing extensions to |
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1954 ensure the corresponding files are available locally, before the command |
45073
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1955 uses them. |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1956 |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1957 Args: |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1958 revmatches: a list of (revision, match) tuples to indicate the files to |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1959 fetch at each revision. If any of the match elements is None, it matches |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1960 all files. |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1961 """ |
37762
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1962 |
45073
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1963 def _matcher(m): |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1964 if m: |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1965 assert isinstance(m, matchmod.basematcher) |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1966 # The command itself will complain about files that don't exist, so |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1967 # don't duplicate the message. |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1968 return matchmod.badmatch(m, lambda fn, msg: None) |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1969 else: |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1970 return matchall(repo) |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1971 |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1972 revbadmatches = [(rev, _matcher(match)) for (rev, match) in revmatches] |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1973 |
a56ba57c837d
scmutil: allowing different files to be prefetched per revision
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
44943
diff
changeset
|
1974 fileprefetchhooks(repo, revbadmatches) |
37762
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1975 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1976 |
37762
7269b87f817c
scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
37709
diff
changeset
|
1977 # a list of (repo, revs, match) prefetch functions |
36175
f52a9336ac5f
cmdutil: convert the prefetchfiles() hook to a callback mechanism (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
35953
diff
changeset
|
1978 fileprefetchhooks = util.hooks() |
f52a9336ac5f
cmdutil: convert the prefetchfiles() hook to a callback mechanism (API)
Matt Harbison <matt_harbison@yahoo.com>
parents:
35953
diff
changeset
|
1979 |
35709
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
1980 # A marker that tells the evolve extension to suppress its own reporting |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
1981 _reportstroubledchangesets = True |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
1982 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1983 |
44554
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
1984 def registersummarycallback(repo, otr, txnname=b'', as_validator=False): |
33252
53b3a1968aa6
obsolete: reports the number of local changeset obsoleted when unbundling
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33246
diff
changeset
|
1985 """register a callback to issue a summary after the transaction is closed |
44554
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
1986 |
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
1987 If as_validator is true, then the callbacks are registered as transaction |
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
1988 validators instead |
33252
53b3a1968aa6
obsolete: reports the number of local changeset obsoleted when unbundling
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
33246
diff
changeset
|
1989 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
1990 |
34619
18309380fb88
scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34543
diff
changeset
|
1991 def txmatch(sources): |
18309380fb88
scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34543
diff
changeset
|
1992 return any(txnname.startswith(source) for source in sources) |
18309380fb88
scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34543
diff
changeset
|
1993 |
34620
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1994 categories = [] |
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1995 |
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1996 def reportsummary(func): |
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
1997 """decorator for report callbacks.""" |
34987
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
34972
diff
changeset
|
1998 # The repoview life cycle is shorter than the one of the actual |
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
34972
diff
changeset
|
1999 # underlying repository. So the filtered object can die before the |
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
34972
diff
changeset
|
2000 # weakref is used leading to troubles. We keep a reference to the |
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
34972
diff
changeset
|
2001 # unfiltered object and restore the filtering when retrieving the |
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
34972
diff
changeset
|
2002 # repository through the weakref. |
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
34972
diff
changeset
|
2003 filtername = repo.filtername |
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
34972
diff
changeset
|
2004 reporef = weakref.ref(repo.unfiltered()) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2005 |
34620
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
2006 def wrapped(tr): |
34619
18309380fb88
scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34543
diff
changeset
|
2007 repo = reporef() |
34987
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
34972
diff
changeset
|
2008 if filtername: |
43760
5b90a050082b
scmutil: add assertions to help pytype
Matt Harbison <matt_harbison@yahoo.com>
parents:
43698
diff
changeset
|
2009 assert repo is not None # help pytype |
34987
96dcc78468e3
tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
34972
diff
changeset
|
2010 repo = repo.filtered(filtername) |
34620
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
2011 func(repo, tr) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2012 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2013 newcat = b'%02i-txnreport' % len(categories) |
44554
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
2014 if as_validator: |
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
2015 otr.addvalidator(newcat, wrapped) |
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
2016 else: |
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
2017 otr.addpostclose(newcat, wrapped) |
34620
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
2018 categories.append(newcat) |
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
2019 return wrapped |
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
2020 |
42903
d7304434390f
changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42900
diff
changeset
|
2021 @reportsummary |
d7304434390f
changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42900
diff
changeset
|
2022 def reportchangegroup(repo, tr): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2023 cgchangesets = tr.changes.get(b'changegroup-count-changesets', 0) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2024 cgrevisions = tr.changes.get(b'changegroup-count-revisions', 0) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2025 cgfiles = tr.changes.get(b'changegroup-count-files', 0) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2026 cgheads = tr.changes.get(b'changegroup-count-heads', 0) |
42903
d7304434390f
changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42900
diff
changeset
|
2027 if cgchangesets or cgrevisions or cgfiles: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2028 htext = b"" |
42903
d7304434390f
changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42900
diff
changeset
|
2029 if cgheads: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2030 htext = _(b" (%+d heads)") % cgheads |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2031 msg = _(b"added %d changesets with %d changes to %d files%s\n") |
44554
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
2032 if as_validator: |
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
2033 msg = _(b"adding %d changesets with %d changes to %d files%s\n") |
43760
5b90a050082b
scmutil: add assertions to help pytype
Matt Harbison <matt_harbison@yahoo.com>
parents:
43698
diff
changeset
|
2034 assert repo is not None # help pytype |
42903
d7304434390f
changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42900
diff
changeset
|
2035 repo.ui.status(msg % (cgchangesets, cgrevisions, cgfiles, htext)) |
d7304434390f
changegroup: move message about added changes to transaction summary
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42900
diff
changeset
|
2036 |
34620
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
2037 if txmatch(_reportobsoletedsource): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2038 |
34620
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
2039 @reportsummary |
b799f11644d8
scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34619
diff
changeset
|
2040 def reportobsoleted(repo, tr): |
34619
18309380fb88
scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34543
diff
changeset
|
2041 obsoleted = obsutil.getobsoleted(repo, tr) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2042 newmarkers = len(tr.changes.get(b'obsmarkers', ())) |
42900
38392d5bde8e
transaction: issue "new obsmarkers" message at the end of the transaction
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42731
diff
changeset
|
2043 if newmarkers: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2044 repo.ui.status(_(b'%i new obsolescence markers\n') % newmarkers) |
34619
18309380fb88
scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34543
diff
changeset
|
2045 if obsoleted: |
44554
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
2046 msg = _(b'obsoleted %i changesets\n') |
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
2047 if as_validator: |
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
2048 msg = _(b'obsoleting %i changesets\n') |
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
2049 repo.ui.status(msg % len(obsoleted)) |
34661
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
2050 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2051 if obsolete.isenabled( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2052 repo, obsolete.createmarkersopt |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2053 ) and repo.ui.configbool( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2054 b'experimental', b'evolution.report-instabilities' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2055 ): |
35709
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
2056 instabilitytypes = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2057 (b'orphan', b'orphan'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2058 (b'phase-divergent', b'phasedivergent'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2059 (b'content-divergent', b'contentdivergent'), |
35709
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
2060 ] |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
2061 |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
2062 def getinstabilitycounts(repo): |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
2063 filtered = repo.changelog.filteredrevs |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
2064 counts = {} |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
2065 for instability, revset in instabilitytypes: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2066 counts[instability] = len( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2067 set(obsolete.getrevs(repo, revset)) - filtered |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2068 ) |
35709
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
2069 return counts |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
2070 |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
2071 oldinstabilitycounts = getinstabilitycounts(repo) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2072 |
35709
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
2073 @reportsummary |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
2074 def reportnewinstabilities(repo, tr): |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
2075 newinstabilitycounts = getinstabilitycounts(repo) |
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
2076 for instability, revset in instabilitytypes: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2077 delta = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2078 newinstabilitycounts[instability] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2079 - oldinstabilitycounts[instability] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2080 ) |
38460
1cac2e8c7624
scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38437
diff
changeset
|
2081 msg = getinstabilitymessage(delta, instability) |
1cac2e8c7624
scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38437
diff
changeset
|
2082 if msg: |
1cac2e8c7624
scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38437
diff
changeset
|
2083 repo.ui.warn(msg) |
35709
1a09dad8b85a
evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents:
35503
diff
changeset
|
2084 |
34661
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
2085 if txmatch(_reportnewcssource): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2086 |
34661
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
2087 @reportsummary |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
2088 def reportnewcs(repo, tr): |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
2089 """Report the range of new revisions pulled/unbundled.""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2090 origrepolen = tr.changes.get(b'origrepolen', len(repo)) |
39903
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2091 unfi = repo.unfiltered() |
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2092 if origrepolen >= len(unfi): |
34661
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
2093 return |
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
2094 |
39902
a477679f6323
pullreport: skip filtered revs instead of obsolete ones
Boris Feld <boris.feld@octobus.net>
parents:
39899
diff
changeset
|
2095 # Compute the bounds of new visible revisions' range. |
a477679f6323
pullreport: skip filtered revs instead of obsolete ones
Boris Feld <boris.feld@octobus.net>
parents:
39899
diff
changeset
|
2096 revs = smartset.spanset(repo, start=origrepolen) |
39903
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2097 if revs: |
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2098 minrev, maxrev = repo[revs.min()], repo[revs.max()] |
34661
eb586ed5d8ce
transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
34645
diff
changeset
|
2099 |
39903
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2100 if minrev == maxrev: |
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2101 revrange = minrev |
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2102 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2103 revrange = b'%s:%s' % (minrev, maxrev) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2104 draft = len(repo.revs(b'%ld and draft()', revs)) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2105 secret = len(repo.revs(b'%ld and secret()', revs)) |
39903
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2106 if not (draft or secret): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2107 msg = _(b'new changesets %s\n') % revrange |
39903
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2108 elif draft and secret: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2109 msg = _(b'new changesets %s (%d drafts, %d secrets)\n') |
39903
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2110 msg %= (revrange, draft, secret) |
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2111 elif draft: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2112 msg = _(b'new changesets %s (%d drafts)\n') |
39903
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2113 msg %= (revrange, draft) |
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2114 elif secret: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2115 msg = _(b'new changesets %s (%d secrets)\n') |
39903
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2116 msg %= (revrange, secret) |
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2117 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2118 errormsg = b'entered unreachable condition' |
39903
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2119 raise error.ProgrammingError(errormsg) |
b5e12039e6e0
pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents:
39902
diff
changeset
|
2120 repo.ui.status(msg) |
35188
9700cb9df140
convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents:
34987
diff
changeset
|
2121 |
39904
f9232b0310ef
pullreport: issue a message about "extinct" pulled changesets
Boris Feld <boris.feld@octobus.net>
parents:
39903
diff
changeset
|
2122 # search new changesets directly pulled as obsolete |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2123 duplicates = tr.changes.get(b'revduplicates', ()) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2124 obsadded = unfi.revs( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2125 b'(%d: + %ld) and obsolete()', origrepolen, duplicates |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2126 ) |
39904
f9232b0310ef
pullreport: issue a message about "extinct" pulled changesets
Boris Feld <boris.feld@octobus.net>
parents:
39903
diff
changeset
|
2127 cl = repo.changelog |
f9232b0310ef
pullreport: issue a message about "extinct" pulled changesets
Boris Feld <boris.feld@octobus.net>
parents:
39903
diff
changeset
|
2128 extinctadded = [r for r in obsadded if r not in cl] |
f9232b0310ef
pullreport: issue a message about "extinct" pulled changesets
Boris Feld <boris.feld@octobus.net>
parents:
39903
diff
changeset
|
2129 if extinctadded: |
f9232b0310ef
pullreport: issue a message about "extinct" pulled changesets
Boris Feld <boris.feld@octobus.net>
parents:
39903
diff
changeset
|
2130 # They are not just obsolete, but obsolete and invisible |
f9232b0310ef
pullreport: issue a message about "extinct" pulled changesets
Boris Feld <boris.feld@octobus.net>
parents:
39903
diff
changeset
|
2131 # we call them "extinct" internally but the terms have not been |
f9232b0310ef
pullreport: issue a message about "extinct" pulled changesets
Boris Feld <boris.feld@octobus.net>
parents:
39903
diff
changeset
|
2132 # exposed to users. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2133 msg = b'(%d other changesets obsolete on arrival)\n' |
39904
f9232b0310ef
pullreport: issue a message about "extinct" pulled changesets
Boris Feld <boris.feld@octobus.net>
parents:
39903
diff
changeset
|
2134 repo.ui.status(msg % len(extinctadded)) |
f9232b0310ef
pullreport: issue a message about "extinct" pulled changesets
Boris Feld <boris.feld@octobus.net>
parents:
39903
diff
changeset
|
2135 |
38204
eb9835014d20
transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
38164
diff
changeset
|
2136 @reportsummary |
eb9835014d20
transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
38164
diff
changeset
|
2137 def reportphasechanges(repo, tr): |
eb9835014d20
transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
38164
diff
changeset
|
2138 """Report statistics of phase changes for changesets pre-existing |
eb9835014d20
transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
38164
diff
changeset
|
2139 pull/unbundle. |
eb9835014d20
transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
38164
diff
changeset
|
2140 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2141 origrepolen = tr.changes.get(b'origrepolen', len(repo)) |
44558
fdc802f29b2c
transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents:
44554
diff
changeset
|
2142 published = [] |
fdc802f29b2c
transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents:
44554
diff
changeset
|
2143 for revs, (old, new) in tr.changes.get(b'phases', []): |
fdc802f29b2c
transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents:
44554
diff
changeset
|
2144 if new != phases.public: |
fdc802f29b2c
transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents:
44554
diff
changeset
|
2145 continue |
fdc802f29b2c
transactions: convert changes['phases'] to list of ranges
Joerg Sonnenberger <joerg@bec.de>
parents:
44554
diff
changeset
|
2146 published.extend(rev for rev in revs if rev < origrepolen) |
38204
eb9835014d20
transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
38164
diff
changeset
|
2147 if not published: |
eb9835014d20
transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
38164
diff
changeset
|
2148 return |
44554
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
2149 msg = _(b'%d local changesets published\n') |
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
2150 if as_validator: |
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
2151 msg = _(b'%d local changesets will be published\n') |
13da36d77a3f
scmutil: add option to register summary callbacks as transaction validators
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44470
diff
changeset
|
2152 repo.ui.status(msg % len(published)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2153 |
38204
eb9835014d20
transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
38164
diff
changeset
|
2154 |
38460
1cac2e8c7624
scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38437
diff
changeset
|
2155 def getinstabilitymessage(delta, instability): |
1cac2e8c7624
scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38437
diff
changeset
|
2156 """function to return the message to show warning about new instabilities |
1cac2e8c7624
scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38437
diff
changeset
|
2157 |
1cac2e8c7624
scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38437
diff
changeset
|
2158 exists as a separate function so that extension can wrap to show more |
1cac2e8c7624
scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38437
diff
changeset
|
2159 information like how to fix instabilities""" |
1cac2e8c7624
scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38437
diff
changeset
|
2160 if delta > 0: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2161 return _(b'%i new %s changesets\n') % (delta, instability) |
38460
1cac2e8c7624
scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38437
diff
changeset
|
2162 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2163 |
35195
bc775b8cc020
scmutil: extra utility to display a reasonable amount of nodes
Boris Feld <boris.feld@octobus.net>
parents:
35188
diff
changeset
|
2164 def nodesummaries(repo, nodes, maxnumnodes=4): |
bc775b8cc020
scmutil: extra utility to display a reasonable amount of nodes
Boris Feld <boris.feld@octobus.net>
parents:
35188
diff
changeset
|
2165 if len(nodes) <= maxnumnodes or repo.ui.verbose: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2166 return b' '.join(short(h) for h in nodes) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2167 first = b' '.join(short(h) for h in nodes[:maxnumnodes]) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2168 return _(b"%s and %d others") % (first, len(nodes) - maxnumnodes) |
35195
bc775b8cc020
scmutil: extra utility to display a reasonable amount of nodes
Boris Feld <boris.feld@octobus.net>
parents:
35188
diff
changeset
|
2169 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2170 |
46097
4d5e2fd53707
singlehead: introduce option to restrict to public changes
Joerg Sonnenberger <joerg@bec.de>
parents:
46046
diff
changeset
|
2171 def enforcesinglehead(repo, tr, desc, accountclosed, filtername): |
35196
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35195
diff
changeset
|
2172 """check that no named branch has multiple heads""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2173 if desc in (b'strip', b'repair'): |
35196
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35195
diff
changeset
|
2174 # skip the logic during strip |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35195
diff
changeset
|
2175 return |
46097
4d5e2fd53707
singlehead: introduce option to restrict to public changes
Joerg Sonnenberger <joerg@bec.de>
parents:
46046
diff
changeset
|
2176 visible = repo.filtered(filtername) |
35196
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35195
diff
changeset
|
2177 # possible improvement: we could restrict the check to affected branch |
42971
76608f9f27f6
singlehead: introduce special handling of closed heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42930
diff
changeset
|
2178 bm = visible.branchmap() |
76608f9f27f6
singlehead: introduce special handling of closed heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42930
diff
changeset
|
2179 for name in bm: |
76608f9f27f6
singlehead: introduce special handling of closed heads
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42930
diff
changeset
|
2180 heads = bm.branchheads(name, closed=accountclosed) |
35196
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35195
diff
changeset
|
2181 if len(heads) > 1: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2182 msg = _(b'rejecting multiple heads on branch "%s"') |
35196
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35195
diff
changeset
|
2183 msg %= name |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2184 hint = _(b'%d heads: %s') |
35196
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35195
diff
changeset
|
2185 hint %= (len(heads), nodesummaries(repo, heads)) |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35195
diff
changeset
|
2186 raise error.Abort(msg, hint=hint) |
66ecde8a704d
server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents:
35195
diff
changeset
|
2187 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2188 |
35188
9700cb9df140
convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents:
34987
diff
changeset
|
2189 def wrapconvertsink(sink): |
9700cb9df140
convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents:
34987
diff
changeset
|
2190 """Allow extensions to wrap the sink returned by convcmd.convertsink() |
9700cb9df140
convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents:
34987
diff
changeset
|
2191 before it is used, whether or not the convert extension was formally loaded. |
9700cb9df140
convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents:
34987
diff
changeset
|
2192 """ |
9700cb9df140
convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents:
34987
diff
changeset
|
2193 return sink |
35500
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2194 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2195 |
35500
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2196 def unhidehashlikerevs(repo, specs, hiddentype): |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2197 """parse the user specs and unhide changesets whose hash or revision number |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2198 is passed. |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2199 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2200 hiddentype can be: 1) 'warn': warn while unhiding changesets |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2201 2) 'nowarn': don't warn while unhiding changesets |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2202 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2203 returns a repo object with the required changesets unhidden |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2204 """ |
48499
c51408b92b88
directaccess: fix uses of commands.status() that don't go through flag parsing
Kyle Lippincott <spectral@google.com>
parents:
48416
diff
changeset
|
2205 if not specs: |
c51408b92b88
directaccess: fix uses of commands.status() that don't go through flag parsing
Kyle Lippincott <spectral@google.com>
parents:
48416
diff
changeset
|
2206 return repo |
c51408b92b88
directaccess: fix uses of commands.status() that don't go through flag parsing
Kyle Lippincott <spectral@google.com>
parents:
48416
diff
changeset
|
2207 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2208 if not repo.filtername or not repo.ui.configbool( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2209 b'experimental', b'directaccess' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2210 ): |
35500
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2211 return repo |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2212 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2213 if repo.filtername not in (b'visible', b'visible-hidden'): |
35500
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2214 return repo |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2215 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2216 symbols = set() |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2217 for spec in specs: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2218 try: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2219 tree = revsetlang.parse(spec) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2220 except error.ParseError: # will be reported by scmutil.revrange() |
35500
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2221 continue |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2222 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2223 symbols.update(revsetlang.gethashlikesymbols(tree)) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2224 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2225 if not symbols: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2226 return repo |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2227 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2228 revs = _getrevsfromsymbols(repo, symbols) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2229 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2230 if not revs: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2231 return repo |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2232 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2233 if hiddentype == b'warn': |
35500
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2234 unfi = repo.unfiltered() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2235 revstr = b", ".join([pycompat.bytestr(unfi[l]) for l in revs]) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2236 repo.ui.warn( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2237 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2238 b"warning: accessing hidden changesets for write " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2239 b"operation: %s\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2240 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2241 % revstr |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2242 ) |
35500
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2243 |
35503
b55a142f00c5
scmutil: use a tuple of possible values instead of using startswith()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35500
diff
changeset
|
2244 # we have to use new filtername to separate branch/tags cache until we can |
b55a142f00c5
scmutil: use a tuple of possible values instead of using startswith()
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35500
diff
changeset
|
2245 # disbale these cache when revisions are dynamically pinned. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2246 return repo.filtered(b'visible-hidden', revs) |
35500
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2247 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2248 |
35500
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2249 def _getrevsfromsymbols(repo, symbols): |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2250 """parse the list of symbols and returns a set of revision numbers of hidden |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2251 changesets present in symbols""" |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2252 revs = set() |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2253 unfi = repo.unfiltered() |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2254 unficl = unfi.changelog |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2255 cl = repo.changelog |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2256 tiprev = len(unficl) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2257 allowrevnums = repo.ui.configbool(b'experimental', b'directaccess.revnums') |
35500
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2258 for s in symbols: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2259 try: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2260 n = int(s) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2261 if n <= tiprev: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2262 if not allowrevnums: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2263 continue |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2264 else: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2265 if n not in cl: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2266 revs.add(n) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2267 continue |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2268 except ValueError: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2269 pass |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2270 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2271 try: |
37912
69de3c3de036
directaccess: use resolvehexnodeidprefix() instead of _partialmatch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
37909
diff
changeset
|
2272 s = resolvehexnodeidprefix(unfi, s) |
37097
7f025c9b7865
directaccess: do not abort by 'ff...' hash
Yuya Nishihara <yuya@tcha.org>
parents:
37087
diff
changeset
|
2273 except (error.LookupError, error.WdirUnsupported): |
35500
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2274 s = None |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2275 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2276 if s is not None: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2277 rev = unficl.rev(s) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2278 if rev not in cl: |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2279 revs.add(rev) |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2280 |
8bb90cc4668e
scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35419
diff
changeset
|
2281 return revs |
38164
46c2b19a1263
scmutil: move repair.stripbmrevset as scmutil.bookmarkrevs (API)
David Demelier <markand@malikania.fr>
parents:
38023
diff
changeset
|
2282 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2283 |
38164
46c2b19a1263
scmutil: move repair.stripbmrevset as scmutil.bookmarkrevs (API)
David Demelier <markand@malikania.fr>
parents:
38023
diff
changeset
|
2284 def bookmarkrevs(repo, mark): |
46043
b9ebe0bfed4e
scmutil: document that bookmarkrevs() ignores non-head bookmark branch
Yuya Nishihara <yuya@tcha.org>
parents:
45957
diff
changeset
|
2285 """Select revisions reachable by a given bookmark |
b9ebe0bfed4e
scmutil: document that bookmarkrevs() ignores non-head bookmark branch
Yuya Nishihara <yuya@tcha.org>
parents:
45957
diff
changeset
|
2286 |
b9ebe0bfed4e
scmutil: document that bookmarkrevs() ignores non-head bookmark branch
Yuya Nishihara <yuya@tcha.org>
parents:
45957
diff
changeset
|
2287 If the bookmarked revision isn't a head, an empty set will be returned. |
38164
46c2b19a1263
scmutil: move repair.stripbmrevset as scmutil.bookmarkrevs (API)
David Demelier <markand@malikania.fr>
parents:
38023
diff
changeset
|
2288 """ |
46044
9ee791f3278f
scmutil: extract function that builds revset expr to select bookmark branch
Yuya Nishihara <yuya@tcha.org>
parents:
46043
diff
changeset
|
2289 return repo.revs(format_bookmark_revspec(mark)) |
9ee791f3278f
scmutil: extract function that builds revset expr to select bookmark branch
Yuya Nishihara <yuya@tcha.org>
parents:
46043
diff
changeset
|
2290 |
9ee791f3278f
scmutil: extract function that builds revset expr to select bookmark branch
Yuya Nishihara <yuya@tcha.org>
parents:
46043
diff
changeset
|
2291 |
9ee791f3278f
scmutil: extract function that builds revset expr to select bookmark branch
Yuya Nishihara <yuya@tcha.org>
parents:
46043
diff
changeset
|
2292 def format_bookmark_revspec(mark): |
9ee791f3278f
scmutil: extract function that builds revset expr to select bookmark branch
Yuya Nishihara <yuya@tcha.org>
parents:
46043
diff
changeset
|
2293 """Build a revset expression to select revisions reachable by a given |
9ee791f3278f
scmutil: extract function that builds revset expr to select bookmark branch
Yuya Nishihara <yuya@tcha.org>
parents:
46043
diff
changeset
|
2294 bookmark""" |
46046
1bf2b44c4007
log: do not accept string-matcher pattern as -u/-b/-B parameter
Yuya Nishihara <yuya@tcha.org>
parents:
46044
diff
changeset
|
2295 mark = b'literal:' + mark |
46044
9ee791f3278f
scmutil: extract function that builds revset expr to select bookmark branch
Yuya Nishihara <yuya@tcha.org>
parents:
46043
diff
changeset
|
2296 return revsetlang.formatspec( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2297 b"ancestors(bookmark(%s)) - " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2298 b"ancestors(head() and not bookmark(%s)) - " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
2299 b"ancestors(bookmark() and not bookmark(%s))", |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2300 mark, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2301 mark, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2302 mark, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42971
diff
changeset
|
2303 ) |