annotate mercurial/scmutil.py @ 42155:5079242abef9

revpair: simplify revpair by always relying on smartset.first/last I thinkt the code was written the way it was because it comes from 97b2f26dfc43 (revpair: smartset compatibility, 2014-03-20) and the first/last methods came only later, in 228b0aafb1ce (smartset: add first and last methods, 2014-10-06). Differential Revision: https://phab.mercurial-scm.org/D5687
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 24 Jan 2019 12:38:19 -0800
parents 17941fc53ae9
children a728ef2f9b15
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 #
8b252e826c68 add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff changeset
3 # Copyright Matt Mackall <mpm@selenic.com>
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
28129
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
8 from __future__ import absolute_import
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
9
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
10 import errno
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
11 import glob
30091
0d83ad967bf8 cleanup: replace uses of util.(md5|sha1|sha256|sha512) with hashlib.\1
Augie Fackler <raf@durin42.com>
parents: 30086
diff changeset
12 import hashlib
28129
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
13 import os
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
14 import re
35244
c67db5dc131d extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents: 35243
diff changeset
15 import subprocess
34035
53b3a1968aa6 obsolete: reports the number of local changeset obsoleted when unbundling
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 34029
diff changeset
16 import weakref
28129
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
17
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
18 from .i18n import _
33441
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 33439
diff changeset
19 from .node import (
38314
d2b484eed1ec scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38313
diff changeset
20 bin,
33871
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
21 hex,
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
22 nullid,
40680
d739f423bf06 repo: look up nullrev context by revnum, not symbolic name
Martin von Zweigbergk <martinvonz@google.com>
parents: 40677
diff changeset
23 nullrev,
35110
4647e0a8d3d7 scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents: 34929
diff changeset
24 short,
33441
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 33439
diff changeset
25 wdirid,
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 33439
diff changeset
26 wdirrev,
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 33439
diff changeset
27 )
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 33439
diff changeset
28
28129
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
29 from . import (
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
30 encoding,
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
31 error,
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
32 match as matchmod,
33871
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
33 obsolete,
34035
53b3a1968aa6 obsolete: reports the number of local changeset obsoleted when unbundling
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 34029
diff changeset
34 obsutil,
28129
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
35 pathutil,
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
36 phases,
40012
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
37 policy,
31084
af7c60988f6e py3: make scmutil.rcpath() return bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30888
diff changeset
38 pycompat,
31803
0b8356705de6 revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 31418
diff changeset
39 revsetlang,
28129
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
40 similar,
40683
a477679f6323 pullreport: skip filtered revs instead of obsolete ones
Boris Feld <boris.feld@octobus.net>
parents: 40680
diff changeset
41 smartset,
35239
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
42 url,
28129
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
43 util,
35326
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
44 vfs,
28129
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
45 )
18690
4c6f7f0dadab scmutil: split platform-specific bits into their own modules
Kevin Bullock <kbullock@ringworld.org>
parents: 18678
diff changeset
46
37870
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37622
diff changeset
47 from .utils import (
37906
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37880
diff changeset
48 procutil,
37870
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37622
diff changeset
49 stringutil,
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37622
diff changeset
50 )
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37622
diff changeset
51
35428
75979c8d4572 codemod: use pycompat.iswindows
Jun Wu <quark@fb.com>
parents: 35403
diff changeset
52 if pycompat.iswindows:
28129
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
53 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
54 else:
28129
dde3da2246f1 scmutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 27733
diff changeset
55 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
56
40012
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
57 parsers = policy.importmod(r'parsers')
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
58
31093
365812902904 scmutil: extend termwidth() to return terminal height, renamed to termsize()
Yuya Nishihara <yuya@tcha.org>
parents: 31088
diff changeset
59 termsize = scmplatform.termsize
13962
8b252e826c68 add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff changeset
60
22913
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
61 class status(tuple):
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
62 '''Named tuple with a list of files per status. The 'deleted', 'unknown'
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
63 and 'ignored' properties are only relevant to the working copy.
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
64 '''
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
65
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
66 __slots__ = ()
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
67
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
68 def __new__(cls, modified, added, removed, deleted, unknown, ignored,
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
69 clean):
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
70 return tuple.__new__(cls, (modified, added, removed, deleted, unknown,
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
71 ignored, clean))
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
72
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
73 @property
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
74 def modified(self):
22915
4d680deb0d9e status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22913
diff changeset
75 '''files that have been modified'''
22913
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
76 return self[0]
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
77
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
78 @property
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
79 def added(self):
22915
4d680deb0d9e status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22913
diff changeset
80 '''files that have been added'''
22913
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
81 return self[1]
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
82
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
83 @property
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
84 def removed(self):
22915
4d680deb0d9e status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22913
diff changeset
85 '''files that have been removed'''
22913
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
86 return self[2]
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
87
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
88 @property
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
89 def deleted(self):
22915
4d680deb0d9e status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22913
diff changeset
90 '''files that are in the dirstate, but have been deleted from the
4d680deb0d9e status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22913
diff changeset
91 working copy (aka "missing")
4d680deb0d9e status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22913
diff changeset
92 '''
22913
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
93 return self[3]
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
94
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
95 @property
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
96 def unknown(self):
22915
4d680deb0d9e status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22913
diff changeset
97 '''files not in the dirstate that are not ignored'''
22913
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
98 return self[4]
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
99
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
100 @property
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
101 def ignored(self):
22915
4d680deb0d9e status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22913
diff changeset
102 '''files not in the dirstate that are ignored (by _dirignore())'''
22913
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
103 return self[5]
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
104
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
105 @property
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
106 def clean(self):
22915
4d680deb0d9e status: update and move documentation of status types to status class
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22913
diff changeset
107 '''files that have not been modified'''
22913
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
108 return self[6]
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
109
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
110 def __repr__(self, *args, **kwargs):
38707
a8a7ccec1783 scmutil: fix __repr__ of status tuple
Augie Fackler <augie@google.com>
parents: 38655
diff changeset
111 return ((r'<status modified=%s, added=%s, removed=%s, deleted=%s, '
a8a7ccec1783 scmutil: fix __repr__ of status tuple
Augie Fackler <augie@google.com>
parents: 38655
diff changeset
112 r'unknown=%s, ignored=%s, clean=%s>') %
38728
32bc3815efae stringutil: flip the default of pprint() to bprefix=False
Yuya Nishihara <yuya@tcha.org>
parents: 38707
diff changeset
113 tuple(pycompat.sysstr(stringutil.pprint(v)) for v in self))
22913
cb4449921a1d status: create class for status lists
Martin von Zweigbergk <martinvonz@gmail.com>
parents: 22816
diff changeset
114
20392
d4f804caa0ed itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents: 20364
diff changeset
115 def itersubrepos(ctx1, ctx2):
d4f804caa0ed itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents: 20364
diff changeset
116 """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
117 # 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
118 # 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
119 # 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
120 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
121 subpaths.update(dict.fromkeys(ctx1.substate, ctx1))
25952
c0995cd8ff6f scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25907
diff changeset
122
c0995cd8ff6f scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25907
diff changeset
123 missing = set()
c0995cd8ff6f scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25907
diff changeset
124
c0995cd8ff6f scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25907
diff changeset
125 for subpath in ctx2.substate:
c0995cd8ff6f scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25907
diff changeset
126 if subpath not in ctx1.substate:
c0995cd8ff6f scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25907
diff changeset
127 del subpaths[subpath]
c0995cd8ff6f scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25907
diff changeset
128 missing.add(subpath)
c0995cd8ff6f scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25907
diff changeset
129
20392
d4f804caa0ed itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents: 20364
diff changeset
130 for subpath, ctx in sorted(subpaths.iteritems()):
d4f804caa0ed itersubrepos: move to scmutil to break a direct import cycle
Augie Fackler <raf@durin42.com>
parents: 20364
diff changeset
131 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
132
25952
c0995cd8ff6f scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25907
diff changeset
133 # 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: 25907
diff changeset
134 # 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: 25907
diff changeset
135 # '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: 25907
diff changeset
136 # against itself.
c0995cd8ff6f scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25907
diff changeset
137 for subpath in missing:
c0995cd8ff6f scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25907
diff changeset
138 yield subpath, ctx2.nullsub(subpath, ctx1)
c0995cd8ff6f scmutil: consistently return subrepos relative to ctx1 from itersubrepos()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25907
diff changeset
139
17248
6ffb35b2284c discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents: 17201
diff changeset
140 def nochangesfound(ui, repo, excluded=None):
6ffb35b2284c discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents: 17201
diff changeset
141 '''Report no changes for push/pull, excluded is None or a list of
6ffb35b2284c discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents: 17201
diff changeset
142 nodes excluded from the push/pull.
6ffb35b2284c discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents: 17201
diff changeset
143 '''
6ffb35b2284c discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents: 17201
diff changeset
144 secretlist = []
6ffb35b2284c discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents: 17201
diff changeset
145 if excluded:
6ffb35b2284c discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents: 17201
diff changeset
146 for n in excluded:
6ffb35b2284c discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents: 17201
diff changeset
147 ctx = repo[n]
6ffb35b2284c discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents: 17201
diff changeset
148 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
149 secretlist.append(n)
6ffb35b2284c discovery: add extinct changesets to outgoing.excluded
Patrick Mezard <patrick@mezard.eu>
parents: 17201
diff changeset
150
15993
0b05e0bfdc1c scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents: 15797
diff changeset
151 if secretlist:
0b05e0bfdc1c scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents: 15797
diff changeset
152 ui.status(_("no changes found (ignored %d secret changesets)\n")
0b05e0bfdc1c scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents: 15797
diff changeset
153 % len(secretlist))
0b05e0bfdc1c scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents: 15797
diff changeset
154 else:
0b05e0bfdc1c scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents: 15797
diff changeset
155 ui.status(_("no changes found\n"))
0b05e0bfdc1c scmutil: unify some 'no changes found' messages
Matt Mackall <mpm@selenic.com>
parents: 15797
diff changeset
156
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
157 def callcatch(ui, func):
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
158 """call func() with global exception handling
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
159
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
160 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: 31196
diff changeset
161 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: 31196
diff changeset
162 """
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
163 try:
32820
38963a53ab0d dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents: 32730
diff changeset
164 try:
38963a53ab0d dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents: 32730
diff changeset
165 return func()
38963a53ab0d dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents: 32730
diff changeset
166 except: # re-raises
38963a53ab0d dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents: 32730
diff changeset
167 ui.traceback()
38963a53ab0d dispatch: print traceback in scmutil.callcatch() if --traceback specified
Yuya Nishihara <yuya@tcha.org>
parents: 32730
diff changeset
168 raise
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
169 # Global exception handling, alphabetically
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
170 # Mercurial-specific first, followed by built-in and library exceptions
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
171 except error.LockHeld as inst:
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
172 if inst.errno == errno.ETIMEDOUT:
40953
c554dc0cc16e scmutil: wrap locker information in bytestr before repr()ing it
Augie Fackler <augie@google.com>
parents: 40873
diff changeset
173 reason = _('timed out waiting for lock held by %r') % (
c554dc0cc16e scmutil: wrap locker information in bytestr before repr()ing it
Augie Fackler <augie@google.com>
parents: 40873
diff changeset
174 pycompat.bytestr(inst.locker))
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
175 else:
32867
0d892d820a51 lock: avoid unintentional lock acquisition at failure of readlock
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32820
diff changeset
176 reason = _('lock held by %r') % inst.locker
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
177 ui.error(_("abort: %s: %s\n") % (
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
178 inst.desc or stringutil.forcebytestr(inst.filename), reason))
32867
0d892d820a51 lock: avoid unintentional lock acquisition at failure of readlock
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32820
diff changeset
179 if not inst.locker:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
180 ui.error(_("(lock might be very busy)\n"))
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
181 except error.LockUnavailable as inst:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
182 ui.error(_("abort: could not lock %s: %s\n") %
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
183 (inst.desc or stringutil.forcebytestr(inst.filename),
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
184 encoding.strtolocal(inst.strerror)))
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
185 except error.OutOfBandError as inst:
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
186 if inst.args:
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
187 msg = _("abort: remote error:\n")
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
188 else:
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
189 msg = _("abort: remote error\n")
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
190 ui.error(msg)
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
191 if inst.args:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
192 ui.error(''.join(inst.args))
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
193 if inst.hint:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
194 ui.error('(%s)\n' % inst.hint)
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
195 except error.RepoError as inst:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
196 ui.error(_("abort: %s!\n") % inst)
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
197 if inst.hint:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
198 ui.error(_("(%s)\n") % inst.hint)
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
199 except error.ResponseError as inst:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
200 ui.error(_("abort: %s") % inst.args[0])
37447
b76248e51605 scmutil: avoid using basestring and add explicit handling of unicodes
Augie Fackler <augie@google.com>
parents: 37444
diff changeset
201 msg = inst.args[1]
b76248e51605 scmutil: avoid using basestring and add explicit handling of unicodes
Augie Fackler <augie@google.com>
parents: 37444
diff changeset
202 if isinstance(msg, type(u'')):
b76248e51605 scmutil: avoid using basestring and add explicit handling of unicodes
Augie Fackler <augie@google.com>
parents: 37444
diff changeset
203 msg = pycompat.sysbytes(msg)
37481
c442c4a92ae8 scmutil: fix oversight in b76248e51605c6 where I forgot to use msg
Augie Fackler <augie@google.com>
parents: 37447
diff changeset
204 if not isinstance(msg, bytes):
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
205 ui.error(" %r\n" % (msg,))
37481
c442c4a92ae8 scmutil: fix oversight in b76248e51605c6 where I forgot to use msg
Augie Fackler <augie@google.com>
parents: 37447
diff changeset
206 elif not msg:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
207 ui.error(_(" empty string\n"))
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
208 else:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
209 ui.error("\n%r\n" % pycompat.bytestr(stringutil.ellipsis(msg)))
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
210 except error.CensoredNodeError as inst:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
211 ui.error(_("abort: file censored %s!\n") % inst)
40563
b63dee7bd0d9 global: replace most uses of RevlogError with StorageError (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40480
diff changeset
212 except error.StorageError as inst:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
213 ui.error(_("abort: %s!\n") % inst)
41444
4ec8bee15930 scmutil: display the optional hint when handling StorageError in catchall()
Matt Harbison <matt_harbison@yahoo.com>
parents: 41421
diff changeset
214 if inst.hint:
4ec8bee15930 scmutil: display the optional hint when handling StorageError in catchall()
Matt Harbison <matt_harbison@yahoo.com>
parents: 41421
diff changeset
215 ui.error(_("(%s)\n") % inst.hint)
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
216 except error.InterventionRequired as inst:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
217 ui.error("%s\n" % inst)
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
218 if inst.hint:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
219 ui.error(_("(%s)\n") % inst.hint)
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
220 return 1
33442
7b17f9de6d3e revlog: map rev(wdirid) to WdirUnsupported exception
Yuya Nishihara <yuya@tcha.org>
parents: 33441
diff changeset
221 except error.WdirUnsupported:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
222 ui.error(_("abort: working directory revision cannot be specified\n"))
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
223 except error.Abort as inst:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
224 ui.error(_("abort: %s\n") % inst)
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
225 if inst.hint:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
226 ui.error(_("(%s)\n") % inst.hint)
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
227 except ImportError as inst:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
228 ui.error(_("abort: %s!\n") % stringutil.forcebytestr(inst))
37870
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37622
diff changeset
229 m = stringutil.forcebytestr(inst).split()[-1]
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
230 if m in "mpatch bdiff".split():
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
231 ui.error(_("(did you forget to compile extensions?)\n"))
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
232 elif m in "zlib".split():
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
233 ui.error(_("(is your Python install correct?)\n"))
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
234 except IOError as inst:
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
235 if util.safehasattr(inst, "code"):
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
236 ui.error(_("abort: %s\n") % stringutil.forcebytestr(inst))
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
237 elif util.safehasattr(inst, "reason"):
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
238 try: # usually it is in the form (errno, strerror)
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
239 reason = inst.reason.args[1]
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
240 except (AttributeError, IndexError):
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
241 # it might be anything, for example a string
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
242 reason = inst.reason
39098
79dd61a4554f py3: replace `unicode` with pycompat.unicode
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39036
diff changeset
243 if isinstance(reason, pycompat.unicode):
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
244 # SSLError of Python 2.7.9 contains a unicode
32931
994b0b1c77d6 py3: use encoding.unitolocal instead of .encode(encoding.encoding)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32894
diff changeset
245 reason = encoding.unitolocal(reason)
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
246 ui.error(_("abort: error: %s\n") % reason)
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
247 elif (util.safehasattr(inst, "args")
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
248 and inst.args and inst.args[0] == errno.EPIPE):
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
249 pass
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
250 elif getattr(inst, "strerror", None):
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
251 if getattr(inst, "filename", None):
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
252 ui.error(_("abort: %s: %s\n") % (
37427
77f98867538f py3: fix some unicode madness in global exception catcher
Yuya Nishihara <yuya@tcha.org>
parents: 37355
diff changeset
253 encoding.strtolocal(inst.strerror),
37870
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37622
diff changeset
254 stringutil.forcebytestr(inst.filename)))
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
255 else:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
256 ui.error(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
257 else:
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
258 raise
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
259 except OSError as inst:
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
260 if getattr(inst, "filename", None) is not None:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
261 ui.error(_("abort: %s: '%s'\n") % (
37427
77f98867538f py3: fix some unicode madness in global exception catcher
Yuya Nishihara <yuya@tcha.org>
parents: 37355
diff changeset
262 encoding.strtolocal(inst.strerror),
37870
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37622
diff changeset
263 stringutil.forcebytestr(inst.filename)))
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
264 else:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
265 ui.error(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
266 except MemoryError:
39554
afc4ad706f9c dispatch: making all hg abortions be output with a specific label
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents: 39545
diff changeset
267 ui.error(_("abort: out of memory\n"))
31299
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
268 except SystemExit as inst:
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
269 # 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: 31196
diff changeset
270 # Just in case catch this and and pass exit code to caller.
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
271 return inst.code
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
272
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
273 return -1
4338f87dbf6f dispatch: move part of callcatch to scmutil
Jun Wu <quark@fb.com>
parents: 31196
diff changeset
274
17821
361ab1e2086f scmutil: add bad character checking to checknewlabel
Kevin Bullock <kbullock@ringworld.org>
parents: 17817
diff changeset
275 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
276 # 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
277 # It makes strings difficult to translate.
17817
b17be267b59c scmutil: add function to validate new branch, tag, and bookmark names
Kevin Bullock <kbullock@ringworld.org>
parents: 17768
diff changeset
278 if lbl in ['tip', '.', 'null']:
27227
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27124
diff changeset
279 raise error.Abort(_("the name '%s' is reserved") % lbl)
17821
361ab1e2086f scmutil: add bad character checking to checknewlabel
Kevin Bullock <kbullock@ringworld.org>
parents: 17817
diff changeset
280 for c in (':', '\0', '\n', '\r'):
361ab1e2086f scmutil: add bad character checking to checknewlabel
Kevin Bullock <kbullock@ringworld.org>
parents: 17817
diff changeset
281 if c in lbl:
37355
bb5f5c1c3c1b scmutil: fix a repr in an error message on Python 3
Augie Fackler <augie@google.com>
parents: 37208
diff changeset
282 raise error.Abort(
bb5f5c1c3c1b scmutil: fix a repr in an error message on Python 3
Augie Fackler <augie@google.com>
parents: 37208
diff changeset
283 _("%r cannot be used in a name") % pycompat.bytestr(c))
18566
341868ef0cf6 bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents: 18560
diff changeset
284 try:
341868ef0cf6 bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents: 18560
diff changeset
285 int(lbl)
27227
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27124
diff changeset
286 raise error.Abort(_("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
287 except ValueError:
341868ef0cf6 bookmark: don't allow integers as bookmark/branch/tag names
Durham Goode <durham@fb.com>
parents: 18560
diff changeset
288 pass
36931
4f3e989536c3 label: enforce the lack of leading or trailing white space
Boris Feld <boris.feld@octobus.net>
parents: 36923
diff changeset
289 if lbl.strip() != lbl:
4f3e989536c3 label: enforce the lack of leading or trailing white space
Boris Feld <boris.feld@octobus.net>
parents: 36923
diff changeset
290 raise error.Abort(_("leading or trailing whitespace in name %r") % lbl)
17817
b17be267b59c scmutil: add function to validate new branch, tag, and bookmark names
Kevin Bullock <kbullock@ringworld.org>
parents: 17768
diff changeset
291
13974
23f2736abce3 move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13973
diff changeset
292 def checkfilename(f):
23f2736abce3 move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13973
diff changeset
293 '''Check that the filename f is an acceptable filename for a tracked file'''
23f2736abce3 move checkfilename from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13973
diff changeset
294 if '\r' in f or '\n' in f:
39117
cf59de802883 py3: remove b'' from error message of disallowed filename
Yuya Nishihara <yuya@tcha.org>
parents: 39098
diff changeset
295 raise error.Abort(_("'\\n' and '\\r' disallowed in filenames: %r")
cf59de802883 py3: remove b'' from error message of disallowed filename
Yuya Nishihara <yuya@tcha.org>
parents: 39098
diff changeset
296 % pycompat.bytestr(f))
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)
14146
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:
37906
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37880
diff changeset
305 msg = "%s: %s" % (msg, procutil.shellquote(f))
14146
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14097
diff changeset
306 if abort:
27227
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27124
diff changeset
307 raise error.Abort(msg)
14146
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14097
diff changeset
308 ui.warn(_("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
14067
e88a4958a6b7 scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents: 13986
diff changeset
310 def checkportabilityalert(ui):
e88a4958a6b7 scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents: 13986
diff changeset
311 '''check if the user's config requests nothing, a warning, or abort for
e88a4958a6b7 scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents: 13986
diff changeset
312 non-portable filenames'''
34282
0407a51b9d8c codemod: register core configitems using a script
Jun Wu <quark@fb.com>
parents: 34135
diff changeset
313 val = ui.config('ui', 'portablefilenames')
14067
e88a4958a6b7 scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents: 13986
diff changeset
314 lval = val.lower()
37870
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37622
diff changeset
315 bval = stringutil.parsebool(val)
35428
75979c8d4572 codemod: use pycompat.iswindows
Jun Wu <quark@fb.com>
parents: 35403
diff changeset
316 abort = pycompat.iswindows or lval == 'abort'
14067
e88a4958a6b7 scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents: 13986
diff changeset
317 warn = bval or lval == 'warn'
e88a4958a6b7 scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents: 13986
diff changeset
318 if bval is None and not (warn or abort or lval == 'ignore'):
13962
8b252e826c68 add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff changeset
319 raise error.ConfigError(
8b252e826c68 add: introduce a warning message for non-portable filenames (issue2756) (BC)
Adrian Buehlmann <adrian@cadifra.com>
parents:
diff changeset
320 _("ui.portablefilenames value is invalid ('%s')") % val)
14067
e88a4958a6b7 scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents: 13986
diff changeset
321 return abort, warn
e88a4958a6b7 scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents: 13986
diff changeset
322
14146
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14097
diff changeset
323 class casecollisionauditor(object):
17201
afd75476939e scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents: 17161
diff changeset
324 def __init__(self, ui, abort, dirstate):
14146
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14097
diff changeset
325 self._ui = ui
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14097
diff changeset
326 self._abort = abort
17201
afd75476939e scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents: 17161
diff changeset
327 allfiles = '\0'.join(dirstate._map)
afd75476939e scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents: 17161
diff changeset
328 self._loweredfiles = set(encoding.lower(allfiles).split('\0'))
afd75476939e scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents: 17161
diff changeset
329 self._dirstate = dirstate
afd75476939e scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents: 17161
diff changeset
330 # 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
331 # 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
332 # same filename twice.
afd75476939e scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents: 17161
diff changeset
333 self._newfiles = set()
14067
e88a4958a6b7 scmutil: refactor ui.portablefilenames processing
Kevin Gessner <kevin@kevingessner.com>
parents: 13986
diff changeset
334
14146
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14097
diff changeset
335 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
336 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
337 return
14981
28e98a8b173d i18n: use UTF-8 string to lower filename for case collision check
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 14864
diff changeset
338 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
339 if fl in self._loweredfiles and f not in self._dirstate:
14146
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14097
diff changeset
340 msg = _('possible case-folding collision for %s') % f
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14097
diff changeset
341 if self._abort:
27227
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27124
diff changeset
342 raise error.Abort(msg)
14146
c18204fd35b0 scmutil: introduce casecollisionauditor
Adrian Buehlmann <adrian@cadifra.com>
parents: 14097
diff changeset
343 self._ui.warn(_("warning: %s\n") % msg)
17201
afd75476939e scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents: 17161
diff changeset
344 self._loweredfiles.add(fl)
afd75476939e scmutil: 25% speedup in casecollisionauditor
Joshua Redstone <joshua.redstone@fb.com>
parents: 17161
diff changeset
345 self._newfiles.add(f)
13970
d13913355390 move opener from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13962
diff changeset
346
24902
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
347 def filteredhash(repo, maxrev):
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
348 """build hash of filtered revisions in the current repoview.
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
349
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
350 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: 24832
diff changeset
351 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: 24832
diff changeset
352 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: 24832
diff changeset
353 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: 24832
diff changeset
354 tipnode changing.
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
355
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
356 This function hashes all the revs filtered from the view and returns
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
357 that SHA-1 digest.
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
358 """
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
359 cl = repo.changelog
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
360 if not cl.filteredrevs:
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
361 return None
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
362 key = None
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
363 revs = sorted(r for r in cl.filteredrevs if r <= maxrev)
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
364 if revs:
30091
0d83ad967bf8 cleanup: replace uses of util.(md5|sha1|sha256|sha512) with hashlib.\1
Augie Fackler <raf@durin42.com>
parents: 30086
diff changeset
365 s = hashlib.sha1()
24902
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
366 for rev in revs:
32128
719e64bf9ec2 scmutil: fix key generation to portably bytestringify integer
Augie Fackler <augie@google.com>
parents: 32064
diff changeset
367 s.update('%d;' % rev)
24902
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
368 key = s.digest()
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
369 return key
467a33142425 repoview: move function for computing filtered hash
Gregory Szorc <gregory.szorc@gmail.com>
parents: 24832
diff changeset
370
13975
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
371 def walkrepos(path, followsym=False, seen_dirs=None, recurse=False):
17104
5a9acb0b2086 help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents: 17041
diff changeset
372 '''yield every hg repository under path, always recursively.
5a9acb0b2086 help: improve hgweb help
Mads Kiilerich <mads@kiilerich.com>
parents: 17041
diff changeset
373 The recurse flag will only control recursion into repo working dirs'''
13975
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
374 def errhandler(err):
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
375 if err.filename == path:
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
376 raise err
14962
5523529bd1af walkrepos: use getattr instead of hasattr for samestat
Augie Fackler <durin42@gmail.com>
parents: 14928
diff changeset
377 samestat = getattr(os.path, 'samestat', None)
5523529bd1af walkrepos: use getattr instead of hasattr for samestat
Augie Fackler <durin42@gmail.com>
parents: 14928
diff changeset
378 if followsym and samestat is not None:
14227
94985b5a8278 scmutil: rename local function _add_dir_if_not_there
Adrian Buehlmann <adrian@cadifra.com>
parents: 14226
diff changeset
379 def adddir(dirlst, dirname):
13975
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
380 dirstat = os.stat(dirname)
37124
ddd9474d2e08 walkrepos: don't reimplement any()
Martin von Zweigbergk <martinvonz@google.com>
parents: 37099
diff changeset
381 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
382 if not match:
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
383 dirlst.append(dirstat)
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
384 return not match
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
385 else:
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
386 followsym = False
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
387
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
388 if (seen_dirs is None) and followsym:
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
389 seen_dirs = []
14227
94985b5a8278 scmutil: rename local function _add_dir_if_not_there
Adrian Buehlmann <adrian@cadifra.com>
parents: 14226
diff changeset
390 adddir(seen_dirs, path)
13975
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
391 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
392 dirs.sort()
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
393 if '.hg' in dirs:
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
394 yield root # found a repository
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
395 qroot = os.path.join(root, '.hg', 'patches')
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
396 if os.path.isdir(os.path.join(qroot, '.hg')):
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
397 yield qroot # we have a patch queue repo here
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
398 if recurse:
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
399 # avoid recursing inside the .hg directory
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
400 dirs.remove('.hg')
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
401 else:
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
402 dirs[:] = [] # don't descend further
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
403 elif followsym:
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
404 newdirs = []
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
405 for d in dirs:
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
406 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
407 if adddir(seen_dirs, fname):
13975
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
408 if os.path.islink(fname):
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
409 for hgname in walkrepos(fname, True, seen_dirs):
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
410 yield hgname
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
411 else:
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
412 newdirs.append(d)
938fbeacac84 move walkrepos from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13974
diff changeset
413 dirs[:] = newdirs
13984
af60153b5e3b move rcpath from util to scmutil
Adrian Buehlmann <adrian@cadifra.com>
parents: 13975
diff changeset
414
33441
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 33439
diff changeset
415 def binnode(ctx):
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 33439
diff changeset
416 """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: 33439
diff changeset
417 node = ctx.node()
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 33439
diff changeset
418 if node is None:
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 33439
diff changeset
419 return wdirid
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 33439
diff changeset
420 return node
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 33439
diff changeset
421
33439
4bec8cce6a09 scmutil: pass ctx object to intrev()
Yuya Nishihara <yuya@tcha.org>
parents: 33053
diff changeset
422 def intrev(ctx):
4bec8cce6a09 scmutil: pass ctx object to intrev()
Yuya Nishihara <yuya@tcha.org>
parents: 33053
diff changeset
423 """Return integer for a given basectx that can be used in comparison or
24715
56fff44cce98 scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents: 24577
diff changeset
424 arithmetic operation"""
33439
4bec8cce6a09 scmutil: pass ctx object to intrev()
Yuya Nishihara <yuya@tcha.org>
parents: 33053
diff changeset
425 rev = ctx.rev()
24715
56fff44cce98 scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents: 24577
diff changeset
426 if rev is None:
26298
3dabc9b7494a changeset_printer: use node.wdirrev to calculate meaningful parentrevs
Yuya Nishihara <yuya@tcha.org>
parents: 26214
diff changeset
427 return wdirrev
24715
56fff44cce98 scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents: 24577
diff changeset
428 return rev
56fff44cce98 scmutil: add function to help handling workingctx in arithmetic operation
Yuya Nishihara <yuya@tcha.org>
parents: 24577
diff changeset
429
35110
4647e0a8d3d7 scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents: 34929
diff changeset
430 def formatchangeid(ctx):
4647e0a8d3d7 scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents: 34929
diff changeset
431 """Format changectx as '{rev}:{node|formatnode}', which is the default
36674
c8e2d6ed1f9e cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36534
diff changeset
432 template provided by logcmdutil.changesettemplater"""
35110
4647e0a8d3d7 scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents: 34929
diff changeset
433 repo = ctx.repo()
4647e0a8d3d7 scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents: 34929
diff changeset
434 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: 34929
diff changeset
435
4647e0a8d3d7 scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents: 34929
diff changeset
436 def formatrevnode(ui, rev, node):
4647e0a8d3d7 scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents: 34929
diff changeset
437 """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: 34929
diff changeset
438 if ui.debugflag:
4647e0a8d3d7 scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents: 34929
diff changeset
439 hexfunc = hex
4647e0a8d3d7 scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents: 34929
diff changeset
440 else:
4647e0a8d3d7 scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents: 34929
diff changeset
441 hexfunc = short
4647e0a8d3d7 scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents: 34929
diff changeset
442 return '%d:%s' % (rev, hexfunc(node))
4647e0a8d3d7 scmutil: extract helper functions that returns human-readable change id
Yuya Nishihara <yuya@tcha.org>
parents: 34929
diff changeset
443
38464
5f8f013e7d52 scmutil: rename resolvepartialhexnodeid() to resolvehexnodeidprefix()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38463
diff changeset
444 def resolvehexnodeidprefix(repo, prefix):
39641
7848f284b211 revisions: allow "x123" to refer to nodeid prefix "123"
Martin von Zweigbergk <martinvonz@google.com>
parents: 39640
diff changeset
445 if (prefix.startswith('x') and
7848f284b211 revisions: allow "x123" to refer to nodeid prefix "123"
Martin von Zweigbergk <martinvonz@google.com>
parents: 39640
diff changeset
446 repo.ui.configbool('experimental', 'revisions.prefixhexnode')):
7848f284b211 revisions: allow "x123" to refer to nodeid prefix "123"
Martin von Zweigbergk <martinvonz@google.com>
parents: 39640
diff changeset
447 prefix = prefix[1:]
39628
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
448 try:
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
449 # 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: 39627
diff changeset
450 # This matches the shortesthexnodeidprefix() function below.
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
451 node = repo.unfiltered().changelog._partialmatch(prefix)
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
452 except error.AmbiguousPrefixLookupError:
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
453 revset = repo.ui.config('experimental', 'revisions.disambiguatewithin')
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
454 if revset:
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
455 # Clear config to avoid infinite recursion
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
456 configoverrides = {('experimental',
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
457 'revisions.disambiguatewithin'): None}
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
458 with repo.ui.configoverride(configoverrides):
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
459 revs = repo.anyrevs([revset], user=True)
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
460 matches = []
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
461 for rev in revs:
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
462 node = repo.changelog.node(rev)
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
463 if hex(node).startswith(prefix):
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
464 matches.append(node)
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
465 if len(matches) == 1:
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
466 return matches[0]
503f936489dd lookup: add option to disambiguate prefix within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39627
diff changeset
467 raise
38290
901e749ca0e1 context: extract partial nodeid lookup method to scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 38249
diff changeset
468 if node is None:
901e749ca0e1 context: extract partial nodeid lookup method to scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 38249
diff changeset
469 return
901e749ca0e1 context: extract partial nodeid lookup method to scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 38249
diff changeset
470 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: 38249
diff changeset
471 return node
901e749ca0e1 context: extract partial nodeid lookup method to scmutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 38249
diff changeset
472
39640
531b86cc8fb3 shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents: 39639
diff changeset
473 def mayberevnum(repo, prefix):
531b86cc8fb3 shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents: 39639
diff changeset
474 """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: 39639
diff changeset
475 try:
531b86cc8fb3 shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents: 39639
diff changeset
476 i = int(prefix)
531b86cc8fb3 shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents: 39639
diff changeset
477 # 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: 39639
diff changeset
478 # confused as a rev; or, obviously, if the int is larger
41127
d916ed3ca951 revisions: when using prefixhexnode, ensure we prefix "0"
Kyle Lippincott <spectral@google.com>
parents: 40953
diff changeset
479 # 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: 40953
diff changeset
480 # prefix == '0', since that *is* a valid revnum.
d916ed3ca951 revisions: when using prefixhexnode, ensure we prefix "0"
Kyle Lippincott <spectral@google.com>
parents: 40953
diff changeset
481 if (prefix != b'0' and prefix[0:1] == b'0') or i >= len(repo):
39640
531b86cc8fb3 shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents: 39639
diff changeset
482 return False
531b86cc8fb3 shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents: 39639
diff changeset
483 return True
531b86cc8fb3 shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents: 39639
diff changeset
484 except ValueError:
531b86cc8fb3 shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents: 39639
diff changeset
485 return False
531b86cc8fb3 shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents: 39639
diff changeset
486
39639
3588e41f796d shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39629
diff changeset
487 def shortesthexnodeidprefix(repo, node, minlength=1, cache=None):
3588e41f796d shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39629
diff changeset
488 """Find the shortest unambiguous prefix that matches hexnode.
3588e41f796d shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39629
diff changeset
489
3588e41f796d shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39629
diff changeset
490 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: 39629
diff changeset
491 caching between calls to this method.
3588e41f796d shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39629
diff changeset
492 """
38494
8e8541610d85 scmutil: make shortesthexnodeidprefix() use unfiltered repo
Martin von Zweigbergk <martinvonz@google.com>
parents: 38466
diff changeset
493 # _partialmatch() of filtered changelog could take O(len(repo)) time,
8e8541610d85 scmutil: make shortesthexnodeidprefix() use unfiltered repo
Martin von Zweigbergk <martinvonz@google.com>
parents: 38466
diff changeset
494 # 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: 38466
diff changeset
495 # unfiltered space, which means some hashes may be slightly longer.
38757
3ac950cd5978 shortest: move revnum-disambiguation out of revlog
Martin von Zweigbergk <martinvonz@google.com>
parents: 38746
diff changeset
496
41189
bf249bb60087 shortest: never emit 0-length prefix even if unique
Martin von Zweigbergk <martinvonz@google.com>
parents: 41153
diff changeset
497 minlength=max(minlength, 1)
bf249bb60087 shortest: never emit 0-length prefix even if unique
Martin von Zweigbergk <martinvonz@google.com>
parents: 41153
diff changeset
498
38757
3ac950cd5978 shortest: move revnum-disambiguation out of revlog
Martin von Zweigbergk <martinvonz@google.com>
parents: 38746
diff changeset
499 def disambiguate(prefix):
3ac950cd5978 shortest: move revnum-disambiguation out of revlog
Martin von Zweigbergk <martinvonz@google.com>
parents: 38746
diff changeset
500 """Disambiguate against revnums."""
39642
a01200b25da6 shortest: use 'x' prefix to disambiguate from revnum if configured
Martin von Zweigbergk <martinvonz@google.com>
parents: 39641
diff changeset
501 if repo.ui.configbool('experimental', 'revisions.prefixhexnode'):
a01200b25da6 shortest: use 'x' prefix to disambiguate from revnum if configured
Martin von Zweigbergk <martinvonz@google.com>
parents: 39641
diff changeset
502 if mayberevnum(repo, prefix):
a01200b25da6 shortest: use 'x' prefix to disambiguate from revnum if configured
Martin von Zweigbergk <martinvonz@google.com>
parents: 39641
diff changeset
503 return 'x' + prefix
a01200b25da6 shortest: use 'x' prefix to disambiguate from revnum if configured
Martin von Zweigbergk <martinvonz@google.com>
parents: 39641
diff changeset
504 else:
a01200b25da6 shortest: use 'x' prefix to disambiguate from revnum if configured
Martin von Zweigbergk <martinvonz@google.com>
parents: 39641
diff changeset
505 return prefix
a01200b25da6 shortest: use 'x' prefix to disambiguate from revnum if configured
Martin von Zweigbergk <martinvonz@google.com>
parents: 39641
diff changeset
506
38757
3ac950cd5978 shortest: move revnum-disambiguation out of revlog
Martin von Zweigbergk <martinvonz@google.com>
parents: 38746
diff changeset
507 hexnode = hex(node)
38765
5ac72e07692a shortest: avoid magic number "41"
Martin von Zweigbergk <martinvonz@google.com>
parents: 38757
diff changeset
508 for length in range(len(prefix), len(hexnode) + 1):
38757
3ac950cd5978 shortest: move revnum-disambiguation out of revlog
Martin von Zweigbergk <martinvonz@google.com>
parents: 38746
diff changeset
509 prefix = hexnode[:length]
39640
531b86cc8fb3 shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents: 39639
diff changeset
510 if not mayberevnum(repo, prefix):
38757
3ac950cd5978 shortest: move revnum-disambiguation out of revlog
Martin von Zweigbergk <martinvonz@google.com>
parents: 38746
diff changeset
511 return prefix
3ac950cd5978 shortest: move revnum-disambiguation out of revlog
Martin von Zweigbergk <martinvonz@google.com>
parents: 38746
diff changeset
512
39640
531b86cc8fb3 shortest: make isrev() a top-level function
Martin von Zweigbergk <martinvonz@google.com>
parents: 39639
diff changeset
513 cl = repo.unfiltered().changelog
39629
6f7c9527030b scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39628
diff changeset
514 revset = repo.ui.config('experimental', 'revisions.disambiguatewithin')
6f7c9527030b scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39628
diff changeset
515 if revset:
39639
3588e41f796d shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39629
diff changeset
516 revs = None
3588e41f796d shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39629
diff changeset
517 if cache is not None:
3588e41f796d shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39629
diff changeset
518 revs = cache.get('disambiguationrevset')
3588e41f796d shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39629
diff changeset
519 if revs is None:
3588e41f796d shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39629
diff changeset
520 revs = repo.anyrevs([revset], user=True)
3588e41f796d shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39629
diff changeset
521 if cache is not None:
3588e41f796d shortest: cache disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39629
diff changeset
522 cache['disambiguationrevset'] = revs
39629
6f7c9527030b scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39628
diff changeset
523 if cl.rev(node) in revs:
6f7c9527030b scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39628
diff changeset
524 hexnode = hex(node)
40012
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
525 nodetree = None
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
526 if cache is not None:
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
527 nodetree = cache.get('disambiguationnodetree')
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
528 if not nodetree:
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
529 try:
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
530 nodetree = parsers.nodetree(cl.index, len(revs))
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
531 except AttributeError:
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
532 # no native nodetree
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
533 pass
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
534 else:
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
535 for r in revs:
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
536 nodetree.insert(r)
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
537 if cache is not None:
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
538 cache['disambiguationnodetree'] = nodetree
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
539 if nodetree is not None:
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
540 length = max(nodetree.shortest(node), minlength)
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
541 prefix = hexnode[:length]
7a759ad2d06d shortest: use nodetree for finding shortest node within revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39874
diff changeset
542 return disambiguate(prefix)
39629
6f7c9527030b scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39628
diff changeset
543 for length in range(minlength, len(hexnode) + 1):
6f7c9527030b scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39628
diff changeset
544 matches = []
6f7c9527030b scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39628
diff changeset
545 prefix = hexnode[:length]
6f7c9527030b scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39628
diff changeset
546 for rev in revs:
6f7c9527030b scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39628
diff changeset
547 otherhexnode = repo[rev].hex()
6f7c9527030b scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39628
diff changeset
548 if prefix == otherhexnode[:length]:
6f7c9527030b scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39628
diff changeset
549 matches.append(otherhexnode)
6f7c9527030b scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39628
diff changeset
550 if len(matches) == 1:
6f7c9527030b scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39628
diff changeset
551 return disambiguate(prefix)
6f7c9527030b scmutil: make shortest() respect disambiguation revset
Martin von Zweigbergk <martinvonz@google.com>
parents: 39628
diff changeset
552
38651
da083d9fafab shortest: don't keep checking for longer prefix if node doesn't exist (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38553
diff changeset
553 try:
38757
3ac950cd5978 shortest: move revnum-disambiguation out of revlog
Martin von Zweigbergk <martinvonz@google.com>
parents: 38746
diff changeset
554 return disambiguate(cl.shortest(node, minlength))
38651
da083d9fafab shortest: don't keep checking for longer prefix if node doesn't exist (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38553
diff changeset
555 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: 38553
diff changeset
556 raise error.RepoLookupError()
38466
e743b8524d60 scmutil: introduce shortesthexnodeidprefix()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38465
diff changeset
557
38136
e32dfff71529 revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents: 38092
diff changeset
558 def isrevsymbol(repo, symbol):
38463
41ac707322ba scmutil: document that isrevsymbol() raises on ambiguous node prefix
Martin von Zweigbergk <martinvonz@google.com>
parents: 38317
diff changeset
559 """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: 38317
diff changeset
560
39627
df0873ab5c14 revlog: use specialized exception for ambiguous prefix lookup
Martin von Zweigbergk <martinvonz@google.com>
parents: 39585
diff changeset
561 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: 39585
diff changeset
562 symbol is an ambiguous nodeid prefix.
38463
41ac707322ba scmutil: document that isrevsymbol() raises on ambiguous node prefix
Martin von Zweigbergk <martinvonz@google.com>
parents: 38317
diff changeset
563 """
38136
e32dfff71529 revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents: 38092
diff changeset
564 try:
e32dfff71529 revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents: 38092
diff changeset
565 revsymbol(repo, symbol)
e32dfff71529 revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents: 38092
diff changeset
566 return True
e32dfff71529 revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents: 38092
diff changeset
567 except error.RepoLookupError:
e32dfff71529 revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents: 38092
diff changeset
568 return False
e32dfff71529 revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents: 38092
diff changeset
569
38057
0194dac77c93 scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents: 38055
diff changeset
570 def revsymbol(repo, symbol):
0194dac77c93 scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents: 38055
diff changeset
571 """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: 38055
diff changeset
572
0194dac77c93 scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents: 38055
diff changeset
573 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: 38055
diff changeset
574 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: 38055
diff changeset
575 not "max(public())".
0194dac77c93 scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents: 38055
diff changeset
576 """
0194dac77c93 scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents: 38055
diff changeset
577 if not isinstance(symbol, bytes):
0194dac77c93 scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents: 38055
diff changeset
578 msg = ("symbol (%s of type %s) was not a string, did you mean "
0194dac77c93 scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents: 38055
diff changeset
579 "repo[symbol]?" % (symbol, type(symbol)))
0194dac77c93 scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents: 38055
diff changeset
580 raise error.ProgrammingError(msg)
38171
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
581 try:
38313
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
582 if symbol in ('.', 'tip', 'null'):
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
583 return repo[symbol]
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
584
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
585 try:
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
586 r = int(symbol)
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
587 if '%d' % r != symbol:
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
588 raise ValueError
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
589 l = len(repo.changelog)
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
590 if r < 0:
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
591 r += l
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
592 if r < 0 or r >= l and r != wdirrev:
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
593 raise ValueError
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
594 return repo[r]
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
595 except error.FilteredIndexError:
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
596 raise
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
597 except (ValueError, OverflowError, IndexError):
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
598 pass
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
599
38314
d2b484eed1ec scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38313
diff changeset
600 if len(symbol) == 40:
d2b484eed1ec scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38313
diff changeset
601 try:
d2b484eed1ec scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38313
diff changeset
602 node = bin(symbol)
d2b484eed1ec scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38313
diff changeset
603 rev = repo.changelog.rev(node)
d2b484eed1ec scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38313
diff changeset
604 return repo[rev]
d2b484eed1ec scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38313
diff changeset
605 except error.FilteredLookupError:
d2b484eed1ec scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38313
diff changeset
606 raise
d2b484eed1ec scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38313
diff changeset
607 except (TypeError, LookupError):
d2b484eed1ec scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38313
diff changeset
608 pass
d2b484eed1ec scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38313
diff changeset
609
38315
45667439439e context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38314
diff changeset
610 # look up bookmarks through the name interface
45667439439e context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38314
diff changeset
611 try:
45667439439e context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38314
diff changeset
612 node = repo.names.singlenode(repo, symbol)
45667439439e context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38314
diff changeset
613 rev = repo.changelog.rev(node)
45667439439e context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38314
diff changeset
614 return repo[rev]
45667439439e context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38314
diff changeset
615 except KeyError:
45667439439e context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38314
diff changeset
616 pass
45667439439e context: handle namespaces in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38314
diff changeset
617
38465
ab828755e1ea scmutil: use resolvehexnodeidprefix() from revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38464
diff changeset
618 node = resolvehexnodeidprefix(repo, symbol)
38316
35b34202dd3b context: handle partial nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38315
diff changeset
619 if node is not None:
35b34202dd3b context: handle partial nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38315
diff changeset
620 rev = repo.changelog.rev(node)
35b34202dd3b context: handle partial nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38315
diff changeset
621 return repo[rev]
35b34202dd3b context: handle partial nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38315
diff changeset
622
38317
6639ac97ec3b revsymbol: stop delegating to repo.__getitem__ for unhandled symbols (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38316
diff changeset
623 raise error.RepoLookupError(_("unknown revision '%s'") % symbol)
38313
1c09481acdcc context: handle stringified ints in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38290
diff changeset
624
38314
d2b484eed1ec scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38313
diff changeset
625 except error.WdirUnsupported:
d2b484eed1ec scmutil: handle full hex nodeids in revsymbol()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38313
diff changeset
626 return repo[None]
38171
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
627 except (error.FilteredIndexError, error.FilteredLookupError,
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
628 error.FilteredRepoLookupError):
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
629 raise _filterederror(repo, symbol)
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
630
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
631 def _filterederror(repo, changeid):
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
632 """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: 38146
diff changeset
633
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
634 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: 38146
diff changeset
635 experiment with various message variants."""
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
636 if repo.filtername.startswith('visible'):
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
637
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
638 # Check if the changeset is obsolete
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
639 unfilteredrepo = repo.unfiltered()
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
640 ctx = revsymbol(unfilteredrepo, changeid)
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
641
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
642 # 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: 38146
diff changeset
643 # that made this changeset not visible
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
644 if ctx.obsolete():
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
645 msg = obsutil._getfilteredreason(repo, changeid, ctx)
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
646 else:
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
647 msg = _("hidden revision '%s'") % changeid
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
648
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
649 hint = _('use --hidden to access hidden revisions')
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
650
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
651 return error.FilteredRepoLookupError(msg, hint=hint)
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
652 msg = _("filtered revision '%s' (not in '%s' subset)")
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
653 msg %= (changeid, repo.filtername)
ecd3f6909184 context: move handling of filtering error to revsymbol() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38146
diff changeset
654 return error.FilteredRepoLookupError(msg)
38057
0194dac77c93 scmutil: add method for looking up a context given a revision symbol
Martin von Zweigbergk <martinvonz@google.com>
parents: 38055
diff changeset
655
34788
5e83a8fe6bc4 rebase: initial support for multiple destinations
Jun Wu <quark@fb.com>
parents: 34581
diff changeset
656 def revsingle(repo, revspec, default='.', localalias=None):
19509
8963a706e075 revsingle: fix silly API issue (issue2992)
Matt Mackall <mpm@selenic.com>
parents: 19154
diff changeset
657 if not revspec and revspec != 0:
14319
b33f3e35efb0 scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14263
diff changeset
658 return repo[default]
b33f3e35efb0 scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14263
diff changeset
659
34788
5e83a8fe6bc4 rebase: initial support for multiple destinations
Jun Wu <quark@fb.com>
parents: 34581
diff changeset
660 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
661 if not l:
27227
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27124
diff changeset
662 raise error.Abort(_('empty revision set'))
22815
4f81470e83bf revsingle: use `last` instead of direct indexing
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 22814
diff changeset
663 return repo[l.last()]
14319
b33f3e35efb0 scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14263
diff changeset
664
26604
cc3a30ff9490 revpair: restrict odd-range handling to top-level x:y expression (issue4774)
Yuya Nishihara <yuya@tcha.org>
parents: 26512
diff changeset
665 def _pairspec(revspec):
31803
0b8356705de6 revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 31418
diff changeset
666 tree = revsetlang.parse(revspec)
26604
cc3a30ff9490 revpair: restrict odd-range handling to top-level x:y expression (issue4774)
Yuya Nishihara <yuya@tcha.org>
parents: 26512
diff changeset
667 return tree and tree[0] in ('range', 'rangepre', 'rangepost', 'rangeall')
cc3a30ff9490 revpair: restrict odd-range handling to top-level x:y expression (issue4774)
Yuya Nishihara <yuya@tcha.org>
parents: 26512
diff changeset
668
14319
b33f3e35efb0 scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14263
diff changeset
669 def revpair(repo, revs):
b33f3e35efb0 scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14263
diff changeset
670 if not revs:
38038
e9ee540af434 scmutil: make revpair() return context objects (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38037
diff changeset
671 return repo['.'], repo[None]
14319
b33f3e35efb0 scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14263
diff changeset
672
b33f3e35efb0 scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14263
diff changeset
673 l = revrange(repo, revs)
b33f3e35efb0 scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14263
diff changeset
674
42155
5079242abef9 revpair: simplify revpair by always relying on smartset.first/last
Martin von Zweigbergk <martinvonz@google.com>
parents: 42074
diff changeset
675 first = l.first()
5079242abef9 revpair: simplify revpair by always relying on smartset.first/last
Martin von Zweigbergk <martinvonz@google.com>
parents: 42074
diff changeset
676 second = l.last()
20862
97b2f26dfc43 revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20820
diff changeset
677
97b2f26dfc43 revpair: smartset compatibility
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 20820
diff changeset
678 if first is None:
27227
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27124
diff changeset
679 raise error.Abort(_('empty revision range'))
27476
88c4e97b9669 scmutil: abort if an empty revision is given to revpair()
Matt Harbison <matt_harbison@yahoo.com>
parents: 27227
diff changeset
680 if (first == second and len(revs) >= 2
88c4e97b9669 scmutil: abort if an empty revision is given to revpair()
Matt Harbison <matt_harbison@yahoo.com>
parents: 27227
diff changeset
681 and not all(revrange(repo, [r]) for r in revs)):
88c4e97b9669 scmutil: abort if an empty revision is given to revpair()
Matt Harbison <matt_harbison@yahoo.com>
parents: 27227
diff changeset
682 raise error.Abort(_('empty revision on one side of range'))
14319
b33f3e35efb0 scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14263
diff changeset
683
26604
cc3a30ff9490 revpair: restrict odd-range handling to top-level x:y expression (issue4774)
Yuya Nishihara <yuya@tcha.org>
parents: 26512
diff changeset
684 # 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: 26512
diff changeset
685 if first == second and len(revs) == 1 and not _pairspec(revs[0]):
38038
e9ee540af434 scmutil: make revpair() return context objects (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38037
diff changeset
686 return repo[first], repo[None]
14319
b33f3e35efb0 scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14263
diff changeset
687
38038
e9ee540af434 scmutil: make revpair() return context objects (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 38037
diff changeset
688 return repo[first], repo[second]
14319
b33f3e35efb0 scmutil: move revsingle/pair/range from cmdutil
Matt Mackall <mpm@selenic.com>
parents: 14263
diff changeset
689
34788
5e83a8fe6bc4 rebase: initial support for multiple destinations
Jun Wu <quark@fb.com>
parents: 34581
diff changeset
690 def revrange(repo, specs, localalias=None):
30178
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
691 """Execute 1 to many revsets and return the union.
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
692
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
693 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: 30150
diff changeset
694 config options, such as revset aliases.
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
695
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
696 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: 30150
diff changeset
697 expression. If ``specs`` is empty, an empty result is returned.
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
698
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
699 ``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: 30150
diff changeset
700 revision numbers.
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
701
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
702 It is assumed the revsets are already formatted. If you have arguments
31803
0b8356705de6 revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 31418
diff changeset
703 that need to be expanded in the revset, call ``revsetlang.formatspec()``
30178
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
704 and pass the result as an element of ``specs``.
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
705
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
706 Specifying a single revset is allowed.
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
707
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
708 Returns a ``revset.abstractsmartset`` which is a list-like interface over
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
709 integer revisions.
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
710 """
26512
4ee4f7415095 revrange: evaluate all revset specs at once
Yuya Nishihara <yuya@tcha.org>
parents: 26488
diff changeset
711 allspecs = []
30178
526b027b0130 scmutil: improve documentation of revset APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30150
diff changeset
712 for spec in specs:
26488
fbaa2de13cf6 revrange: drop old-style parser in favor of revset (API)
Yuya Nishihara <yuya@tcha.org>
parents: 26331
diff changeset
713 if isinstance(spec, int):
42004
24a1f67bb75a revset: enforce "%d" to be interpreted as literal revision number (API) (BC)
Boris Feld <boris.feld@octobus.net>
parents: 41996
diff changeset
714 spec = revsetlang.formatspec('%d', spec)
26512
4ee4f7415095 revrange: evaluate all revset specs at once
Yuya Nishihara <yuya@tcha.org>
parents: 26488
diff changeset
715 allspecs.append(spec)
34788
5e83a8fe6bc4 rebase: initial support for multiple destinations
Jun Wu <quark@fb.com>
parents: 34581
diff changeset
716 return repo.anyrevs(allspecs, user=True, localalias=localalias)
14320
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
717
27059
3ad41638b4b4 changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents: 27047
diff changeset
718 def meaningfulparents(repo, ctx):
3ad41638b4b4 changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents: 27047
diff changeset
719 """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: 27047
diff changeset
720
3ad41638b4b4 changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents: 27047
diff changeset
721 For merges (two non-nullrev revisions) both parents are meaningful.
3ad41638b4b4 changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents: 27047
diff changeset
722 Otherwise the first parent revision is considered meaningful if it
3ad41638b4b4 changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents: 27047
diff changeset
723 is not the preceding revision.
3ad41638b4b4 changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents: 27047
diff changeset
724 """
3ad41638b4b4 changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents: 27047
diff changeset
725 parents = ctx.parents()
3ad41638b4b4 changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents: 27047
diff changeset
726 if len(parents) > 1:
3ad41638b4b4 changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents: 27047
diff changeset
727 return parents
3ad41638b4b4 changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents: 27047
diff changeset
728 if repo.ui.debugflag:
40680
d739f423bf06 repo: look up nullrev context by revnum, not symbolic name
Martin von Zweigbergk <martinvonz@google.com>
parents: 40677
diff changeset
729 return [parents[0], repo[nullrev]]
33439
4bec8cce6a09 scmutil: pass ctx object to intrev()
Yuya Nishihara <yuya@tcha.org>
parents: 33053
diff changeset
730 if parents[0].rev() >= intrev(ctx) - 1:
27059
3ad41638b4b4 changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents: 27047
diff changeset
731 return []
3ad41638b4b4 changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents: 27047
diff changeset
732 return parents
3ad41638b4b4 changeset_printer: move _meaningful_parentrevs() to scmutil
Yuya Nishihara <yuya@tcha.org>
parents: 27047
diff changeset
733
14320
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
734 def expandpats(pats):
21111
9d28fd795215 match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents: 20980
diff changeset
735 '''Expand bare globs when running on windows.
9d28fd795215 match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents: 20980
diff changeset
736 On posix we assume it already has already been done by sh.'''
14320
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
737 if not util.expandglobs:
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
738 return list(pats)
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
739 ret = []
21111
9d28fd795215 match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents: 20980
diff changeset
740 for kindpat in pats:
9d28fd795215 match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents: 20980
diff changeset
741 kind, pat = matchmod._patsplit(kindpat, None)
14320
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
742 if kind is None:
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
743 try:
21111
9d28fd795215 match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents: 20980
diff changeset
744 globbed = glob.glob(pat)
14320
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
745 except re.error:
21111
9d28fd795215 match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents: 20980
diff changeset
746 globbed = [pat]
14320
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
747 if globbed:
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
748 ret.extend(globbed)
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
749 continue
21111
9d28fd795215 match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents: 20980
diff changeset
750 ret.append(kindpat)
14320
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
751 return ret
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
752
26944
58218b0e6005 match: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26943
diff changeset
753 def matchandpats(ctx, pats=(), opts=None, globbed=False, default='relpath',
26003
f64dbe06f3d0 scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents: 26002
diff changeset
754 badfn=None):
21111
9d28fd795215 match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents: 20980
diff changeset
755 '''Return a matcher and the patterns that were used.
26003
f64dbe06f3d0 scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents: 26002
diff changeset
756 The matcher will warn about bad matches, unless an alternate badfn callback
f64dbe06f3d0 scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents: 26002
diff changeset
757 is provided.'''
14320
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
758 if pats == ("",):
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
759 pats = []
26944
58218b0e6005 match: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26943
diff changeset
760 if opts is None:
58218b0e6005 match: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26943
diff changeset
761 opts = {}
14320
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
762 if not globbed and default == 'relpath':
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
763 pats = expandpats(pats or [])
14670
19197fa4c41c scmutil: match now accepts a context or a repo
Matt Mackall <mpm@selenic.com>
parents: 14669
diff changeset
764
26003
f64dbe06f3d0 scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents: 26002
diff changeset
765 def bad(f, msg):
24458
ca1365078c86 scmutil: replace 'ctx._repo' with 'ctx.repo()'
Matt Harbison <matt_harbison@yahoo.com>
parents: 24230
diff changeset
766 ctx.repo().ui.warn("%s: %s\n" % (m.rel(f), msg))
26002
007a1d53f7c3 scmutil: use the optional badfn argument when building a matcher
Matt Harbison <matt_harbison@yahoo.com>
parents: 25968
diff changeset
767
26003
f64dbe06f3d0 scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents: 26002
diff changeset
768 if badfn is None:
f64dbe06f3d0 scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents: 26002
diff changeset
769 badfn = bad
f64dbe06f3d0 scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents: 26002
diff changeset
770
26002
007a1d53f7c3 scmutil: use the optional badfn argument when building a matcher
Matt Harbison <matt_harbison@yahoo.com>
parents: 25968
diff changeset
771 m = ctx.match(pats, opts.get('include'), opts.get('exclude'),
007a1d53f7c3 scmutil: use the optional badfn argument when building a matcher
Matt Harbison <matt_harbison@yahoo.com>
parents: 25968
diff changeset
772 default, listsubrepos=opts.get('subrepos'), badfn=badfn)
007a1d53f7c3 scmutil: use the optional badfn argument when building a matcher
Matt Harbison <matt_harbison@yahoo.com>
parents: 25968
diff changeset
773
24577
d44d53bc9a1e matcher: make e.g. 'relpath:.' lead to fast paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 24458
diff changeset
774 if m.always():
d44d53bc9a1e matcher: make e.g. 'relpath:.' lead to fast paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 24458
diff changeset
775 pats = []
16171
336e61875335 graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents: 16167
diff changeset
776 return m, pats
336e61875335 graphlog: restore FILE glob expansion on Windows
Patrick Mezard <patrick@mezard.eu>
parents: 16167
diff changeset
777
26946
188c1e9506f5 match: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26945
diff changeset
778 def match(ctx, pats=(), opts=None, globbed=False, default='relpath',
188c1e9506f5 match: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26945
diff changeset
779 badfn=None):
21111
9d28fd795215 match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents: 20980
diff changeset
780 '''Return a matcher that will warn about bad matches.'''
26003
f64dbe06f3d0 scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents: 26002
diff changeset
781 return matchandpats(ctx, pats, opts, globbed, default, badfn=badfn)[0]
14320
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
782
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
783 def matchall(repo):
21111
9d28fd795215 match: improve documentation - docstrings and more descriptive variable naming
Mads Kiilerich <madski@unity3d.com>
parents: 20980
diff changeset
784 '''Return a matcher that will efficiently match everything.'''
14320
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
785 return matchmod.always(repo.root, repo.getcwd())
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
786
26003
f64dbe06f3d0 scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents: 26002
diff changeset
787 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
788 '''Return a matcher that will efficiently match exactly these files.'''
26003
f64dbe06f3d0 scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents: 26002
diff changeset
789 return matchmod.exact(repo.root, repo.getcwd(), files, badfn=badfn)
14320
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
790
35637
39b094e4ae2c revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35576
diff changeset
791 def parsefollowlinespattern(repo, rev, pat, msg):
39b094e4ae2c revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35576
diff changeset
792 """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: 35576
diff changeset
793 logic.
39b094e4ae2c revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35576
diff changeset
794 """
39b094e4ae2c revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35576
diff changeset
795 if not matchmod.patkind(pat):
39b094e4ae2c revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35576
diff changeset
796 return pathutil.canonpath(repo.root, repo.getcwd(), pat)
39b094e4ae2c revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35576
diff changeset
797 else:
39b094e4ae2c revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35576
diff changeset
798 ctx = repo[rev]
39b094e4ae2c revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35576
diff changeset
799 m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=ctx)
39b094e4ae2c revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35576
diff changeset
800 files = [f for f in ctx if m(f)]
39b094e4ae2c revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35576
diff changeset
801 if len(files) != 1:
39b094e4ae2c revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35576
diff changeset
802 raise error.ParseError(msg)
39b094e4ae2c revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35576
diff changeset
803 return files[0]
39b094e4ae2c revset: extract a parsefollowlinespattern helper function
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35576
diff changeset
804
41538
65591a513b9c revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents: 41444
diff changeset
805 def getorigvfs(ui, repo):
65591a513b9c revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents: 41444
diff changeset
806 """return a vfs suitable to save 'orig' file
65591a513b9c revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents: 41444
diff changeset
807
65591a513b9c revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents: 41444
diff changeset
808 return None if no special directory is configured"""
65591a513b9c revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents: 41444
diff changeset
809 origbackuppath = ui.config('ui', 'origbackuppath')
65591a513b9c revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents: 41444
diff changeset
810 if not origbackuppath:
65591a513b9c revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents: 41444
diff changeset
811 return None
65591a513b9c revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents: 41444
diff changeset
812 return vfs.vfs(repo.wvfs.join(origbackuppath))
65591a513b9c revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents: 41444
diff changeset
813
28306
07fc2f2134ba origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents: 28265
diff changeset
814 def origpath(ui, repo, filepath):
07fc2f2134ba origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents: 28265
diff changeset
815 '''customize where .orig files are created
07fc2f2134ba origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents: 28265
diff changeset
816
07fc2f2134ba origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents: 28265
diff changeset
817 Fetch user defined path from config file: [ui] origbackuppath = <path>
34929
9e4f82bc2b0b scmutil: don't append .orig to backups in origbackuppath (BC)
Mark Thomas <mbthomas@fb.com>
parents: 34805
diff changeset
818 Fall back to default (filepath with .orig suffix) if not specified
28306
07fc2f2134ba origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents: 28265
diff changeset
819 '''
41538
65591a513b9c revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents: 41444
diff changeset
820 origvfs = getorigvfs(ui, repo)
65591a513b9c revert: extract origvfs logic in a sub-function
Boris Feld <boris.feld@octobus.net>
parents: 41444
diff changeset
821 if origvfs is None:
28306
07fc2f2134ba origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents: 28265
diff changeset
822 return filepath + ".orig"
07fc2f2134ba origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents: 28265
diff changeset
823
35326
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
824 # Convert filepath from an absolute path into a path inside the repo.
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
825 filepathfromroot = util.normpath(os.path.relpath(filepath,
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
826 start=repo.root))
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
827
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
828 origbackupdir = origvfs.dirname(filepathfromroot)
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
829 if not origvfs.isdir(origbackupdir) or origvfs.islink(origbackupdir):
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
830 ui.note(_('creating directory: %s\n') % origvfs.join(origbackupdir))
28306
07fc2f2134ba origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents: 28265
diff changeset
831
35326
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
832 # Remove any files that conflict with the backup file's path
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
833 for f in reversed(list(util.finddirs(filepathfromroot))):
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
834 if origvfs.isfileorlink(f):
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
835 ui.note(_('removing conflicting file: %s\n')
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
836 % origvfs.join(f))
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
837 origvfs.unlink(f)
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
838 break
28306
07fc2f2134ba origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents: 28265
diff changeset
839
35326
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
840 origvfs.makedirs(origbackupdir)
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
841
35792
99ab7bc944d2 scmutil: don't try to delete origbackup symlinks to directories (issue5731)
Mark Thomas <mbthomas@fb.com>
parents: 35637
diff changeset
842 if origvfs.isdir(filepathfromroot) and not origvfs.islink(filepathfromroot):
35326
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
843 ui.note(_('removing conflicting directory: %s\n')
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
844 % origvfs.join(filepathfromroot))
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
845 origvfs.rmtree(filepathfromroot, forcibly=True)
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
846
6fad8059a970 scmutil: handle conflicting files and dirs in origbackuppath
Mark Thomas <mbthomas@fb.com>
parents: 35325
diff changeset
847 return origvfs.join(filepathfromroot)
28306
07fc2f2134ba origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents: 28265
diff changeset
848
34114
4bae3c117b57 scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents: 34113
diff changeset
849 class _containsnode(object):
4bae3c117b57 scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents: 34113
diff changeset
850 """proxy __contains__(node) to container.__contains__ which accepts revs"""
4bae3c117b57 scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents: 34113
diff changeset
851
4bae3c117b57 scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents: 34113
diff changeset
852 def __init__(self, repo, revcontainer):
4bae3c117b57 scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents: 34113
diff changeset
853 self._torev = repo.changelog.rev
4bae3c117b57 scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents: 34113
diff changeset
854 self._revcontains = revcontainer.__contains__
4bae3c117b57 scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents: 34113
diff changeset
855
4bae3c117b57 scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents: 34113
diff changeset
856 def __contains__(self, node):
4bae3c117b57 scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents: 34113
diff changeset
857 return self._revcontains(self._torev(node))
4bae3c117b57 scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents: 34113
diff changeset
858
39209
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
859 def cleanupnodes(repo, replacements, operation, moves=None, metadata=None,
39585
2002c193f2bc rebase: support "history-editing-backup" config option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 39569
diff changeset
860 fixphase=False, targetphase=None, backup=True):
33871
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
861 """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: 33442
diff changeset
862
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
863 That includes writing obsmarkers or stripping nodes, and moving bookmarks.
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
864 (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: 33442
diff changeset
865
35137
2f427b57bf90 rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents: 35136
diff changeset
866 By default, bookmark moves are calculated automatically from 'replacements',
2f427b57bf90 rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents: 35136
diff changeset
867 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: 35136
diff changeset
868 additional bookmark moves that should not have associated obsmarkers.
2f427b57bf90 rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents: 35136
diff changeset
869
35136
2dbd6d259cd2 cleanupnodes: rename "mapping" to "replacements"
Martin von Zweigbergk <martinvonz@google.com>
parents: 35135
diff changeset
870 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: 35135
diff changeset
871 have replacements. operation is a string, like "rebase".
35576
3df59451cdec scmutil: add capability to cleanupnodes to take obsmarker metadata
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35520
diff changeset
872
3df59451cdec scmutil: add capability to cleanupnodes to take obsmarker metadata
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35520
diff changeset
873 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: 35520
diff changeset
874 obsolescence is enabled.
33871
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
875 """
39209
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
876 assert fixphase or targetphase is None
35137
2f427b57bf90 rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents: 35136
diff changeset
877 if not replacements and not moves:
2f427b57bf90 rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents: 35136
diff changeset
878 return
2f427b57bf90 rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents: 35136
diff changeset
879
2f427b57bf90 rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents: 35136
diff changeset
880 # translate mapping's other forms
35136
2dbd6d259cd2 cleanupnodes: rename "mapping" to "replacements"
Martin von Zweigbergk <martinvonz@google.com>
parents: 35135
diff changeset
881 if not util.safehasattr(replacements, 'items'):
40677
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
882 replacements = {(n,): () for n in replacements}
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
883 else:
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
884 # upgrading non tuple "source" to tuple ones for BC
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
885 repls = {}
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
886 for key, value in replacements.items():
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
887 if not isinstance(key, tuple):
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
888 key = (key,)
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
889 repls[key] = value
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
890 replacements = repls
33871
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
891
41641
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
892 # 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: 41538
diff changeset
893 unfi = repo.unfiltered()
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
894
35135
033a5befbaf7 cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents: 34432
diff changeset
895 # Calculate bookmark movements
35137
2f427b57bf90 rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents: 35136
diff changeset
896 if moves is None:
2f427b57bf90 rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents: 35136
diff changeset
897 moves = {}
41641
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
898 for oldnodes, newnodes in replacements.items():
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
899 for oldnode in oldnodes:
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
900 if oldnode in moves:
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
901 continue
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
902 if len(newnodes) > 1:
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
903 # usually a split, take the one with biggest rev number
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
904 newnode = next(unfi.set('max(%ln)', newnodes)).node()
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
905 elif len(newnodes) == 0:
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
906 # move bookmark backwards
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
907 allreplaced = []
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
908 for rep in replacements:
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
909 allreplaced.extend(rep)
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
910 roots = list(unfi.set('max((::%n) - %ln)', oldnode,
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
911 allreplaced))
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
912 if roots:
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
913 newnode = roots[0].node()
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
914 else:
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
915 newnode = nullid
40677
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
916 else:
41641
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
917 newnode = newnodes[0]
b7823bd59b07 cleanupnodes: trust caller when "moves" is not None
Martin von Zweigbergk <martinvonz@google.com>
parents: 41538
diff changeset
918 moves[oldnode] = newnode
35135
033a5befbaf7 cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents: 34432
diff changeset
919
39209
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
920 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: 39205
diff changeset
921 toretract = {}
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
922 toadvance = {}
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
923 if fixphase:
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
924 precursors = {}
40677
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
925 for oldnodes, newnodes in replacements.items():
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
926 for oldnode in oldnodes:
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
927 for newnode in newnodes:
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
928 precursors.setdefault(newnode, []).append(oldnode)
39209
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
929
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
930 allnewnodes.sort(key=lambda n: unfi[n].rev())
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
931 newphases = {}
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
932 def phase(ctx):
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
933 return newphases.get(ctx.node(), ctx.phase())
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
934 for newnode in allnewnodes:
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
935 ctx = unfi[newnode]
39218
05b7dd11918e cleanupnodes: preserve phase of parents of new nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 39209
diff changeset
936 parentphase = max(phase(p) for p in ctx.parents())
39209
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
937 if targetphase is None:
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
938 oldphase = max(unfi[oldnode].phase()
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
939 for oldnode in precursors[newnode])
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
940 newphase = max(oldphase, parentphase)
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
941 else:
39218
05b7dd11918e cleanupnodes: preserve phase of parents of new nodes
Martin von Zweigbergk <martinvonz@google.com>
parents: 39209
diff changeset
942 newphase = max(targetphase, parentphase)
39209
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
943 newphases[newnode] = newphase
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
944 if newphase > ctx.phase():
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
945 toretract.setdefault(newphase, []).append(newnode)
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
946 elif newphase < ctx.phase():
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
947 toadvance.setdefault(newphase, []).append(newnode)
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
948
33871
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
949 with repo.transaction('cleanup') as tr:
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
950 # Move bookmarks
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
951 bmarks = repo._bookmarks
34294
9689239d7c2b bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents: 34288
diff changeset
952 bmarkchanges = []
35135
033a5befbaf7 cleanupnodes: separate out bookmark destination calculation from actual update
Martin von Zweigbergk <martinvonz@google.com>
parents: 34432
diff changeset
953 for oldnode, newnode in moves.items():
33871
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
954 oldbmarks = repo.nodebookmarks(oldnode)
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
955 if not oldbmarks:
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
956 continue
34114
4bae3c117b57 scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents: 34113
diff changeset
957 from . import bookmarks # avoid import cycle
33871
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
958 repo.ui.debug('moving bookmarks %r from %s to %s\n' %
39361
152f4822d210 pycompat: move rapply() from util
Yuya Nishihara <yuya@tcha.org>
parents: 39289
diff changeset
959 (pycompat.rapply(pycompat.maybebytestr, oldbmarks),
37622
a00c38b33047 py3: drop b'' from debug message "moving bookmarks"
Yuya Nishihara <yuya@tcha.org>
parents: 37481
diff changeset
960 hex(oldnode), hex(newnode)))
34114
4bae3c117b57 scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents: 34113
diff changeset
961 # Delete divergent bookmarks being parents of related newnodes
4bae3c117b57 scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents: 34113
diff changeset
962 deleterevs = repo.revs('parents(roots(%ln & (::%n))) - parents(%n)',
4bae3c117b57 scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents: 34113
diff changeset
963 allnewnodes, newnode, oldnode)
4bae3c117b57 scmutil: make cleanupnodes delete divergent bookmarks
Jun Wu <quark@fb.com>
parents: 34113
diff changeset
964 deletenodes = _containsnode(repo, deleterevs)
33871
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
965 for name in oldbmarks:
34294
9689239d7c2b bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents: 34288
diff changeset
966 bmarkchanges.append((name, newnode))
9689239d7c2b bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents: 34288
diff changeset
967 for b in bookmarks.divergent2delete(repo, deletenodes, name):
9689239d7c2b bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents: 34288
diff changeset
968 bmarkchanges.append((b, None))
9689239d7c2b bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents: 34288
diff changeset
969
9689239d7c2b bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents: 34288
diff changeset
970 if bmarkchanges:
9689239d7c2b bookmark: use 'divergent2delete' in 'scmutil.cleanupnode'
Boris Feld <boris.feld@octobus.net>
parents: 34288
diff changeset
971 bmarks.applychanges(repo, tr, bmarkchanges)
33871
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
972
39209
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
973 for phase, nodes in toretract.items():
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
974 phases.retractboundary(repo, tr, phase, nodes)
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
975 for phase, nodes in toadvance.items():
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
976 phases.advanceboundary(repo, tr, phase, nodes)
32fba6fe893d scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents: 39205
diff changeset
977
33871
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
978 # Obsolete or strip nodes
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
979 if obsolete.isenabled(repo, obsolete.createmarkersopt):
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
980 # 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: 33442
diff changeset
981 # without a successor, skip that obssolete request since it's
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
982 # 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: 33442
diff changeset
983 # 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: 33442
diff changeset
984 # some obsstore logic.
40827
ca9d0c93acea cleanupnodes: update comment to drop mention of filtering
Boris Feld <boris.feld@octobus.net>
parents: 40709
diff changeset
985 # NOTE: the sorting might belong to createmarkers.
34113
ba43e5ee9c6d scmutil: make cleanupnodes handle filtered node
Jun Wu <quark@fb.com>
parents: 34035
diff changeset
986 torev = unfi.changelog.rev
40677
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
987 sortfunc = lambda ns: torev(ns[0][0])
40676
1c3f1491965f scmutil: expand long "one-liner"
Boris Feld <boris.feld@octobus.net>
parents: 40622
diff changeset
988 rels = []
40677
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
989 for ns, s in sorted(replacements.items(), key=sortfunc):
40709
61f39a892168 cleanupnodes: pass multiple predecessors to `createmarkers` directly
Boris Feld <boris.feld@octobus.net>
parents: 40702
diff changeset
990 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: 40702
diff changeset
991 rels.append(rel)
35137
2f427b57bf90 rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents: 35136
diff changeset
992 if rels:
35576
3df59451cdec scmutil: add capability to cleanupnodes to take obsmarker metadata
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35520
diff changeset
993 obsolete.createmarkers(repo, rels, operation=operation,
3df59451cdec scmutil: add capability to cleanupnodes to take obsmarker metadata
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35520
diff changeset
994 metadata=metadata)
33871
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
995 else:
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
996 from . import repair # avoid import cycle
40677
b99903534e06 scmutil: accept multiple predecessors in 'replacements' (API)
Boris Feld <boris.feld@octobus.net>
parents: 40676
diff changeset
997 tostrip = list(n for ns in replacements for n in ns)
35137
2f427b57bf90 rebase: move bookmarks with --keep (issue5682)
Jun Wu <quark@fb.com>
parents: 35136
diff changeset
998 if tostrip:
39585
2002c193f2bc rebase: support "history-editing-backup" config option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 39569
diff changeset
999 repair.delayedstrip(repo.ui, repo, tostrip, operation,
2002c193f2bc rebase: support "history-editing-backup" config option
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 39569
diff changeset
1000 backup=backup)
33871
65cadeea6c22 scmutil: add a cleanupnodes method for developers
Jun Wu <quark@fb.com>
parents: 33442
diff changeset
1001
38055
14cd5290c4e6 addremove: remove dry_run, similarity from scmutil.addremove (API)
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38045
diff changeset
1002 def addremove(repo, matcher, prefix, opts=None):
26947
d9537ce64f3a addremove: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26946
diff changeset
1003 if opts is None:
d9537ce64f3a addremove: remove a mutable default argument
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26946
diff changeset
1004 opts = {}
23541
891aaa7c0c70 scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns
Matt Harbison <matt_harbison@yahoo.com>
parents: 23489
diff changeset
1005 m = matcher
38055
14cd5290c4e6 addremove: remove dry_run, similarity from scmutil.addremove (API)
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38045
diff changeset
1006 dry_run = opts.get('dry_run')
38092
6942c73f0733 addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents: 38057
diff changeset
1007 try:
6942c73f0733 addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents: 38057
diff changeset
1008 similarity = float(opts.get('similarity') or 0)
6942c73f0733 addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents: 38057
diff changeset
1009 except ValueError:
6942c73f0733 addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents: 38057
diff changeset
1010 raise error.Abort(_('similarity must be a number'))
6942c73f0733 addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents: 38057
diff changeset
1011 if similarity < 0 or similarity > 100:
6942c73f0733 addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents: 38057
diff changeset
1012 raise error.Abort(_('similarity must be between 0 and 100'))
6942c73f0733 addremove: pass command-level similarity value down to scmutil.addremove()
Yuya Nishihara <yuya@tcha.org>
parents: 38057
diff changeset
1013 similarity /= 100.0
23541
891aaa7c0c70 scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns
Matt Harbison <matt_harbison@yahoo.com>
parents: 23489
diff changeset
1014
23545
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23542
diff changeset
1015 ret = 0
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23542
diff changeset
1016 join = lambda f: os.path.join(prefix, f)
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23542
diff changeset
1017
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23542
diff changeset
1018 wctx = repo[None]
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23542
diff changeset
1019 for subpath in sorted(wctx.substate):
30572
35560189677c subrepo: cleanup of subrepo filematcher logic
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 30532
diff changeset
1020 submatch = matchmod.subdirmatcher(subpath, m)
35560189677c subrepo: cleanup of subrepo filematcher logic
Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
parents: 30532
diff changeset
1021 if opts.get('subrepos') or m.exact(subpath) or any(submatch.files()):
23545
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23542
diff changeset
1022 sub = wctx.sub(subpath)
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23542
diff changeset
1023 try:
38055
14cd5290c4e6 addremove: remove dry_run, similarity from scmutil.addremove (API)
Sushil khanchi <sushilkhanchi97@gmail.com>
parents: 38045
diff changeset
1024 if sub.addremove(submatch, prefix, opts):
23545
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23542
diff changeset
1025 ret = 1
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23542
diff changeset
1026 except error.LookupError:
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23542
diff changeset
1027 repo.ui.status(_("skipping missing subrepository: %s\n")
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23542
diff changeset
1028 % join(subpath))
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23542
diff changeset
1029
16167
94a8396c9305 addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents: 16115
diff changeset
1030 rejected = []
23542
83bbedc16b3f addremove: warn when addremove fails to operate on a named path
Matt Harbison <matt_harbison@yahoo.com>
parents: 23541
diff changeset
1031 def badfn(f, msg):
83bbedc16b3f addremove: warn when addremove fails to operate on a named path
Matt Harbison <matt_harbison@yahoo.com>
parents: 23541
diff changeset
1032 if f in m.files():
25968
5984dd42e140 addremove: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25952
diff changeset
1033 m.bad(f, msg)
23542
83bbedc16b3f addremove: warn when addremove fails to operate on a named path
Matt Harbison <matt_harbison@yahoo.com>
parents: 23541
diff changeset
1034 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
1035
25968
5984dd42e140 addremove: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25952
diff changeset
1036 badmatch = matchmod.badmatch(m, badfn)
5984dd42e140 addremove: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25952
diff changeset
1037 added, unknown, deleted, removed, forgotten = _interestingfiles(repo,
5984dd42e140 addremove: replace match.bad() monkey patching with match.badmatch()
Matt Harbison <matt_harbison@yahoo.com>
parents: 25952
diff changeset
1038 badmatch)
18862
1b70e5941ad7 scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents: 18861
diff changeset
1039
23259
9f4778027bc2 addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 23142
diff changeset
1040 unknownset = set(unknown + forgotten)
18862
1b70e5941ad7 scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents: 18861
diff changeset
1041 toprint = unknownset.copy()
1b70e5941ad7 scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents: 18861
diff changeset
1042 toprint.update(deleted)
1b70e5941ad7 scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents: 18861
diff changeset
1043 for abs in sorted(toprint):
1b70e5941ad7 scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents: 18861
diff changeset
1044 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: 18861
diff changeset
1045 if abs in unknownset:
23698
164915e8ef7b narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 23594
diff changeset
1046 status = _('adding %s\n') % m.uipath(abs)
41153
824b687ff6af addremove: add "ui." prefix to message color keys
Yuya Nishihara <yuya@tcha.org>
parents: 41127
diff changeset
1047 label = 'ui.addremove.added'
18862
1b70e5941ad7 scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents: 18861
diff changeset
1048 else:
23698
164915e8ef7b narrowmatcher: propagate the rel() method
Matt Harbison <matt_harbison@yahoo.com>
parents: 23594
diff changeset
1049 status = _('removing %s\n') % m.uipath(abs)
41153
824b687ff6af addremove: add "ui." prefix to message color keys
Yuya Nishihara <yuya@tcha.org>
parents: 41127
diff changeset
1050 label = 'ui.addremove.removed'
39874
ad88726d6982 addremove: add labels for messages about added and removed files
Boris Feld <boris.feld@octobus.net>
parents: 39642
diff changeset
1051 repo.ui.status(status, label=label)
18862
1b70e5941ad7 scmutil.addremove: pull ui.status printing out of the loop
Siddharth Agarwal <sid0@fb.com>
parents: 18861
diff changeset
1052
19152
7a1292523db3 scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents: 19151
diff changeset
1053 renames = _findrenames(repo, m, added + unknown, removed + deleted,
7a1292523db3 scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents: 19151
diff changeset
1054 similarity)
14320
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1055
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1056 if not dry_run:
23259
9f4778027bc2 addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 23142
diff changeset
1057 _markchanges(repo, unknown + forgotten, deleted, renames)
14320
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1058
16167
94a8396c9305 addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents: 16115
diff changeset
1059 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
1060 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
1061 return 1
23545
f1b06a8aad42 commit: propagate --addremove to subrepos if -S is specified (issue3759)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23542
diff changeset
1062 return ret
16167
94a8396c9305 addremove: return 1 if we failed to handle any explicit files
Matt Mackall <mpm@selenic.com>
parents: 16115
diff changeset
1063
19154
0c7cf411b390 scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents: 19153
diff changeset
1064 def marktouched(repo, files, similarity=0.0):
0c7cf411b390 scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents: 19153
diff changeset
1065 '''Assert that files have somehow been operated upon. files are relative to
0c7cf411b390 scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents: 19153
diff changeset
1066 the repo root.'''
26003
f64dbe06f3d0 scmutil: add an optional parameter to matcher factories for a bad() override
Matt Harbison <matt_harbison@yahoo.com>
parents: 26002
diff changeset
1067 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
1068 rejected = []
0c7cf411b390 scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents: 19153
diff changeset
1069
23259
9f4778027bc2 addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 23142
diff changeset
1070 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
1071
0c7cf411b390 scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents: 19153
diff changeset
1072 if repo.ui.verbose:
23259
9f4778027bc2 addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 23142
diff changeset
1073 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
1074 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
1075 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
1076 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
1077 if abs in unknownset:
0c7cf411b390 scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents: 19153
diff changeset
1078 status = _('adding %s\n') % abs
0c7cf411b390 scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents: 19153
diff changeset
1079 else:
0c7cf411b390 scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents: 19153
diff changeset
1080 status = _('removing %s\n') % abs
0c7cf411b390 scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents: 19153
diff changeset
1081 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
1082
0c7cf411b390 scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents: 19153
diff changeset
1083 renames = _findrenames(repo, m, added + unknown, removed + deleted,
0c7cf411b390 scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents: 19153
diff changeset
1084 similarity)
0c7cf411b390 scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents: 19153
diff changeset
1085
23259
9f4778027bc2 addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 23142
diff changeset
1086 _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
1087
0c7cf411b390 scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents: 19153
diff changeset
1088 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
1089 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
1090 return 1
0c7cf411b390 scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents: 19153
diff changeset
1091 return 0
0c7cf411b390 scmutil: add a function to mark that files have been operated on
Siddharth Agarwal <sid0@fb.com>
parents: 19153
diff changeset
1092
19150
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1093 def _interestingfiles(repo, matcher):
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1094 '''Walk dirstate with matcher, looking for files that addremove would care
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1095 about.
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1096
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1097 This is different from dirstate.status because it doesn't care about
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1098 whether files are modified or clean.'''
23259
9f4778027bc2 addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 23142
diff changeset
1099 added, unknown, deleted, removed, forgotten = [], [], [], [], []
34432
377e8ddaebef pathauditor: disable cache of audited paths by default (issue5628)
Yuya Nishihara <yuya@tcha.org>
parents: 34325
diff changeset
1100 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
1101
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1102 ctx = repo[None]
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1103 dirstate = repo.dirstate
40873
1d09ba0d2ed3 narrow: move remaining narrow-limited dirstate walks to core
Martin von Zweigbergk <martinvonz@google.com>
parents: 40827
diff changeset
1104 matcher = repo.narrowmatch(matcher, includeexact=True)
35126
255c761a52db dirstate: use keyword arguments to clarify walk()'s callers
Martin von Zweigbergk <martinvonz@google.com>
parents: 35110
diff changeset
1105 walkresults = dirstate.walk(matcher, subrepos=sorted(ctx.substate),
255c761a52db dirstate: use keyword arguments to clarify walk()'s callers
Martin von Zweigbergk <martinvonz@google.com>
parents: 35110
diff changeset
1106 unknown=True, ignored=False, full=False)
19150
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1107 for abs, st in walkresults.iteritems():
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1108 dstate = dirstate[abs]
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1109 if dstate == '?' and audit_path.check(abs):
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1110 unknown.append(abs)
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1111 elif dstate != 'r' and not st:
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1112 deleted.append(abs)
23259
9f4778027bc2 addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 23142
diff changeset
1113 elif dstate == 'r' and st:
9f4778027bc2 addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 23142
diff changeset
1114 forgotten.append(abs)
19150
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1115 # for finding renames
23259
9f4778027bc2 addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 23142
diff changeset
1116 elif dstate == 'r' and not st:
19150
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1117 removed.append(abs)
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1118 elif dstate == 'a':
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1119 added.append(abs)
7a4eab2456de scmutil.addremove: factor out dirstate walk into another function
Siddharth Agarwal <sid0@fb.com>
parents: 19070
diff changeset
1120
23259
9f4778027bc2 addremove: add back forgotten files (BC)
Martin von Zweigbergk <martinvonz@google.com>
parents: 23142
diff changeset
1121 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
1122
19152
7a1292523db3 scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents: 19151
diff changeset
1123 def _findrenames(repo, matcher, added, removed, similarity):
7a1292523db3 scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents: 19151
diff changeset
1124 '''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
1125 renames = {}
7a1292523db3 scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents: 19151
diff changeset
1126 if similarity > 0:
7a1292523db3 scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents: 19151
diff changeset
1127 for old, new, score in similar.findrenames(repo, added, removed,
7a1292523db3 scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents: 19151
diff changeset
1128 similarity):
7a1292523db3 scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents: 19151
diff changeset
1129 if (repo.ui.verbose or not matcher.exact(old)
7a1292523db3 scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents: 19151
diff changeset
1130 or not matcher.exact(new)):
7a1292523db3 scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents: 19151
diff changeset
1131 repo.ui.status(_('recording removal of %s as rename to %s '
7a1292523db3 scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents: 19151
diff changeset
1132 '(%d%% similar)\n') %
7a1292523db3 scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents: 19151
diff changeset
1133 (matcher.rel(old), matcher.rel(new),
7a1292523db3 scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents: 19151
diff changeset
1134 score * 100))
7a1292523db3 scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents: 19151
diff changeset
1135 renames[new] = old
7a1292523db3 scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents: 19151
diff changeset
1136 return renames
7a1292523db3 scmutil.addremove: factor out code to find renames
Siddharth Agarwal <sid0@fb.com>
parents: 19151
diff changeset
1137
19153
9a4e219bda89 scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents: 19152
diff changeset
1138 def _markchanges(repo, unknown, deleted, renames):
9a4e219bda89 scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents: 19152
diff changeset
1139 '''Marks the files in unknown as added, the files in deleted as removed,
9a4e219bda89 scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents: 19152
diff changeset
1140 and the files in renames as copied.'''
9a4e219bda89 scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents: 19152
diff changeset
1141 wctx = repo[None]
28506
4133a306606c with: use context manager in _markchanges
Bryan O'Sullivan <bryano@fb.com>
parents: 28361
diff changeset
1142 with repo.wlock():
19153
9a4e219bda89 scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents: 19152
diff changeset
1143 wctx.forget(deleted)
9a4e219bda89 scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents: 19152
diff changeset
1144 wctx.add(unknown)
9a4e219bda89 scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents: 19152
diff changeset
1145 for new, old in renames.iteritems():
9a4e219bda89 scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents: 19152
diff changeset
1146 wctx.copy(old, new)
9a4e219bda89 scmutil.addremove: factor out code to mark added/removed/renames
Siddharth Agarwal <sid0@fb.com>
parents: 19152
diff changeset
1147
14320
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1148 def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None):
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1149 """Update the dirstate to reflect the intent of copying src to dst. For
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1150 different reasons it might not end with dst being marked as copied from src.
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1151 """
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1152 origsrc = repo.dirstate.copied(src) or src
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1153 if dst == origsrc: # copying back a copy?
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1154 if repo.dirstate[dst] not in 'mn' and not dryrun:
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1155 repo.dirstate.normallookup(dst)
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1156 else:
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1157 if repo.dirstate[origsrc] == 'a' and origsrc == src:
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1158 if not ui.quiet:
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1159 ui.warn(_("%s has not been committed yet, so no copy "
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1160 "data will be stored for %s.\n")
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1161 % (repo.pathto(origsrc, cwd), repo.pathto(dst, cwd)))
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1162 if repo.dirstate[dst] in '?r' and not dryrun:
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1163 wctx.add([dst])
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1164 elif not dryrun:
3438417a6657 scmutil: fold in wdutil
Matt Mackall <mpm@selenic.com>
parents: 14319
diff changeset
1165 wctx.copy(origsrc, dst)
14482
58b36e9ea783 introduce new function scmutil.readrequires
Adrian Buehlmann <adrian@cadifra.com>
parents: 14435
diff changeset
1166
25269
5abd0a76bc8f requires: move requires file writing func from localrepo to scmutil
Drew Gottlieb <drgott@google.com>
parents: 24934
diff changeset
1167 def writerequires(opener, requirements):
41421
acd17caa699a requires: use atomictemp=True when writing .hg/requires
Martin von Zweigbergk <martinvonz@google.com>
parents: 41210
diff changeset
1168 with opener('requires', 'w', atomictemp=True) as fp:
28361
22e362da27cf scmutil: use context managers for file handles
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28306
diff changeset
1169 for r in sorted(requirements):
22e362da27cf scmutil: use context managers for file handles
Gregory Szorc <gregory.szorc@gmail.com>
parents: 28306
diff changeset
1170 fp.write("%s\n" % r)
25269
5abd0a76bc8f requires: move requires file writing func from localrepo to scmutil
Drew Gottlieb <drgott@google.com>
parents: 24934
diff changeset
1171
20043
88bd8df008f2 scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents: 20042
diff changeset
1172 class filecachesubentry(object):
20042
9a72d3886888 scmutil.filecacheentry: make stat argument to constructor mandatory
Siddharth Agarwal <sid0@fb.com>
parents: 20033
diff changeset
1173 def __init__(self, path, stat):
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1174 self.path = path
18315
216230643ae2 filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents: 18213
diff changeset
1175 self.cachestat = None
216230643ae2 filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents: 18213
diff changeset
1176 self._cacheable = None
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1177
18315
216230643ae2 filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents: 18213
diff changeset
1178 if stat:
20043
88bd8df008f2 scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents: 20042
diff changeset
1179 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
1180
216230643ae2 filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents: 18213
diff changeset
1181 if self.cachestat:
216230643ae2 filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents: 18213
diff changeset
1182 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
1183 else:
216230643ae2 filecache: allow filecacheentry to be created without stating in __init__
Idan Kamara <idankk86@gmail.com>
parents: 18213
diff changeset
1184 # 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
1185 self._cacheable = None
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1186
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1187 def refresh(self):
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1188 if self.cacheable():
20043
88bd8df008f2 scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents: 20042
diff changeset
1189 self.cachestat = filecachesubentry.stat(self.path)
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1190
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1191 def cacheable(self):
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1192 if self._cacheable is not None:
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1193 return self._cacheable
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1194
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1195 # we don't know yet, assume it is for now
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1196 return True
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1197
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1198 def changed(self):
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1199 # no point in going further if we can't cache it
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1200 if not self.cacheable():
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1201 return True
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1202
20043
88bd8df008f2 scmutil: rename filecacheentry to filecachesubentry
Siddharth Agarwal <sid0@fb.com>
parents: 20042
diff changeset
1203 newstat = filecachesubentry.stat(self.path)
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1204
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1205 # we may not know if it's cacheable yet, check again now
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1206 if newstat and self._cacheable is None:
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1207 self._cacheable = newstat.cacheable()
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1208
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1209 # check again
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1210 if not self._cacheable:
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1211 return True
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1212
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1213 if self.cachestat != newstat:
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1214 self.cachestat = newstat
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1215 return True
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1216 else:
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1217 return False
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1218
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1219 @staticmethod
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1220 def stat(path):
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1221 try:
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1222 return util.cachestat(path)
26214
328739ea70c3 global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26212
diff changeset
1223 except OSError as e:
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1224 if e.errno != errno.ENOENT:
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1225 raise
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1226
20044
d38de18d187a scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents: 20043
diff changeset
1227 class filecacheentry(object):
d38de18d187a scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents: 20043
diff changeset
1228 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
1229 self._entries = []
d38de18d187a scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents: 20043
diff changeset
1230 for path in paths:
d38de18d187a scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents: 20043
diff changeset
1231 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
1232
d38de18d187a scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents: 20043
diff changeset
1233 def changed(self):
d38de18d187a scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents: 20043
diff changeset
1234 '''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
1235 for entry in self._entries:
d38de18d187a scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents: 20043
diff changeset
1236 if entry.changed():
d38de18d187a scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents: 20043
diff changeset
1237 return True
d38de18d187a scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents: 20043
diff changeset
1238 return False
d38de18d187a scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents: 20043
diff changeset
1239
d38de18d187a scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents: 20043
diff changeset
1240 def refresh(self):
d38de18d187a scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents: 20043
diff changeset
1241 for entry in self._entries:
d38de18d187a scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents: 20043
diff changeset
1242 entry.refresh()
d38de18d187a scmutil: introduce a filecacheentry that can watch multiple paths
Siddharth Agarwal <sid0@fb.com>
parents: 20043
diff changeset
1243
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1244 class filecache(object):
39462
3b072388ca78 scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39445
diff changeset
1245 """A property like decorator that tracks files under .hg/ for updates.
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1246
39462
3b072388ca78 scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39445
diff changeset
1247 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: 39445
diff changeset
1248 results cached. The decorated function is called. The results are stashed
3b072388ca78 scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39445
diff changeset
1249 away in a ``_filecache`` dict on the object whose method is decorated.
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1250
41210
7caf632e30c3 filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 41209
diff changeset
1251 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: 41209
diff changeset
1252 instance dictionary.
39462
3b072388ca78 scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39445
diff changeset
1253
41210
7caf632e30c3 filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 41209
diff changeset
1254 On external property set/delete operations, the caller must update the
7caf632e30c3 filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 41209
diff changeset
1255 corresponding _filecache entry appropriately. Use __class__.<attr>.set()
7caf632e30c3 filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 41209
diff changeset
1256 instead of directly setting <attr>.
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1257
41210
7caf632e30c3 filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 41209
diff changeset
1258 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: 41209
diff changeset
1259 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
1260
39462
3b072388ca78 scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39445
diff changeset
1261 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: 39445
diff changeset
1262 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: 39445
diff changeset
1263 entries in ``_filecache`` will be used during property operations,
3b072388ca78 scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39445
diff changeset
1264 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: 39445
diff changeset
1265 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: 39445
diff changeset
1266 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: 39445
diff changeset
1267 remove the ``filecacheentry``.
3b072388ca78 scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39445
diff changeset
1268 """
3b072388ca78 scmutil: rewrite docstring for filecache
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39445
diff changeset
1269
20045
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20044
diff changeset
1270 def __init__(self, *paths):
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20044
diff changeset
1271 self.paths = paths
16200
fa8488565afd filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents: 16115
diff changeset
1272
fa8488565afd filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents: 16115
diff changeset
1273 def join(self, obj, fname):
20045
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20044
diff changeset
1274 """Used to compute the runtime path of a cached file.
16200
fa8488565afd filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents: 16115
diff changeset
1275
fa8488565afd filecache: refactor path join logic to a function
Idan Kamara <idankk86@gmail.com>
parents: 16115
diff changeset
1276 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
1277 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
1278 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
1279 """
32064
1937671105bc filecache: make 'join' abstract
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31996
diff changeset
1280 raise NotImplementedError
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1281
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1282 def __call__(self, func):
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1283 self.func = func
38655
73a74f29eb87 scmutil: clean up bytes/string cache decorator mess on Python 3 again
Augie Fackler <augie@google.com>
parents: 38654
diff changeset
1284 self.sname = func.__name__
73a74f29eb87 scmutil: clean up bytes/string cache decorator mess on Python 3 again
Augie Fackler <augie@google.com>
parents: 38654
diff changeset
1285 self.name = pycompat.sysbytes(self.sname)
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1286 return self
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1287
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1288 def __get__(self, obj, type=None):
30134
36fbd72c2f39 scmutil: allow access to filecache descriptor on class
Martijn Pieters <mjpieters@fb.com>
parents: 30117
diff changeset
1289 # if accessed on the class, return the descriptor itself.
36fbd72c2f39 scmutil: allow access to filecache descriptor on class
Martijn Pieters <mjpieters@fb.com>
parents: 30117
diff changeset
1290 if obj is None:
36fbd72c2f39 scmutil: allow access to filecache descriptor on class
Martijn Pieters <mjpieters@fb.com>
parents: 30117
diff changeset
1291 return self
41210
7caf632e30c3 filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 41209
diff changeset
1292
7caf632e30c3 filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 41209
diff changeset
1293 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
1294
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1295 entry = obj._filecache.get(self.name)
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1296
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1297 if entry:
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1298 if entry.changed():
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1299 entry.obj = self.func(obj)
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1300 else:
20045
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20044
diff changeset
1301 paths = [self.join(obj, path) for path in self.paths]
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1302
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1303 # We stat -before- creating the object so our cache doesn't lie if
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1304 # 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
1305 entry = filecacheentry(paths, True)
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1306 entry.obj = self.func(obj)
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1307
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1308 obj._filecache[self.name] = entry
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1309
38655
73a74f29eb87 scmutil: clean up bytes/string cache decorator mess on Python 3 again
Augie Fackler <augie@google.com>
parents: 38654
diff changeset
1310 obj.__dict__[self.sname] = entry.obj
14928
dca59d5be12d scmutil: introduce filecache
Idan Kamara <idankk86@gmail.com>
parents: 14864
diff changeset
1311 return entry.obj
16115
236bb604dc39 scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents: 16068
diff changeset
1312
41210
7caf632e30c3 filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 41209
diff changeset
1313 # 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: 41209
diff changeset
1314 # function call.
7caf632e30c3 filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 41209
diff changeset
1315
7caf632e30c3 filecache: unimplement __set__() and __delete__() (API)
Yuya Nishihara <yuya@tcha.org>
parents: 41209
diff changeset
1316 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
1317 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
1318 # 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
1319 # implies X in _filecache
20045
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20044
diff changeset
1320 paths = [self.join(obj, path) for path in self.paths]
b3684fd2ff1a scmutil.filecache: support watching over multiple files
Siddharth Agarwal <sid0@fb.com>
parents: 20044
diff changeset
1321 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
1322 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
1323 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
1324 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
1325
f36375576ed5 filecache: create an entry in _filecache when __set__ is called for a missing one
Idan Kamara <idankk86@gmail.com>
parents: 18315
diff changeset
1326 ce.obj = value # update cached copy
38655
73a74f29eb87 scmutil: clean up bytes/string cache decorator mess on Python 3 again
Augie Fackler <augie@google.com>
parents: 38654
diff changeset
1327 obj.__dict__[self.sname] = value # update copy returned by obj.x
16115
236bb604dc39 scmutil: update cached copy when filecached attribute is assigned (issue3263)
Idan Kamara <idankk86@gmail.com>
parents: 16068
diff changeset
1328
35239
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1329 def extdatasource(repo, source):
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1330 """Gather a map of rev -> value dict from the specified source
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1331
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1332 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: 35150
diff changeset
1333 for parsing the output from a shell command.
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1334
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1335 The data is parsed as a series of newline-separated records where
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1336 each record is a revision specifier optionally followed by a space
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1337 and a freeform string value. If the revision is known locally, it
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1338 is converted to a rev, otherwise the record is skipped.
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1339
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1340 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: 35150
diff changeset
1341 the local encoding. This allows uniformity between local and
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1342 remote data sources.
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1343 """
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1344
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1345 spec = repo.ui.config("extdata", source)
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1346 if not spec:
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1347 raise error.Abort(_("unknown extdata source '%s'") % source)
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1348
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1349 data = {}
35244
c67db5dc131d extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents: 35243
diff changeset
1350 src = proc = None
35239
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1351 try:
35244
c67db5dc131d extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents: 35243
diff changeset
1352 if spec.startswith("shell:"):
c67db5dc131d extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents: 35243
diff changeset
1353 # 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: 35243
diff changeset
1354 cmd = spec[6:]
40622
f1d6021453c2 py3: remove a couple of superfluous calls to pycompat.rapply()
Matt Harbison <matt_harbison@yahoo.com>
parents: 40612
diff changeset
1355 proc = subprocess.Popen(procutil.tonativestr(cmd),
40612
c31ce080eb75 py3: convert arguments, cwd and env to native strings when spawning subprocess
Matt Harbison <matt_harbison@yahoo.com>
parents: 40563
diff changeset
1356 shell=True, bufsize=-1,
37906
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37880
diff changeset
1357 close_fds=procutil.closefds,
40612
c31ce080eb75 py3: convert arguments, cwd and env to native strings when spawning subprocess
Matt Harbison <matt_harbison@yahoo.com>
parents: 40563
diff changeset
1358 stdout=subprocess.PIPE,
c31ce080eb75 py3: convert arguments, cwd and env to native strings when spawning subprocess
Matt Harbison <matt_harbison@yahoo.com>
parents: 40563
diff changeset
1359 cwd=procutil.tonativestr(repo.root))
35244
c67db5dc131d extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents: 35243
diff changeset
1360 src = proc.stdout
c67db5dc131d extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents: 35243
diff changeset
1361 else:
c67db5dc131d extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents: 35243
diff changeset
1362 # treat as a URL or file
c67db5dc131d extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents: 35243
diff changeset
1363 src = url.open(repo.ui, spec)
35243
910adadf08e8 extdata: just use iterator to read lines one by one
Yuya Nishihara <yuya@tcha.org>
parents: 35242
diff changeset
1364 for l in src:
35239
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1365 if " " in l:
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1366 k, v = l.strip().split(" ", 1)
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1367 else:
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1368 k, v = l.strip(), ""
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1369
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1370 k = encoding.tolocal(k)
35242
d5c5cc767b7e extdata: ignore ambiguous identifier as well
Yuya Nishihara <yuya@tcha.org>
parents: 35239
diff changeset
1371 try:
38146
d0d55980ffa7 extdatasource: use revsymbol() for converting to node
Martin von Zweigbergk <martinvonz@google.com>
parents: 38136
diff changeset
1372 data[revsingle(repo, k).rev()] = encoding.tolocal(v)
35242
d5c5cc767b7e extdata: ignore ambiguous identifier as well
Yuya Nishihara <yuya@tcha.org>
parents: 35239
diff changeset
1373 except (error.LookupError, error.RepoLookupError):
d5c5cc767b7e extdata: ignore ambiguous identifier as well
Yuya Nishihara <yuya@tcha.org>
parents: 35239
diff changeset
1374 pass # we ignore data for nodes that don't exist locally
35239
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1375 finally:
35244
c67db5dc131d extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents: 35243
diff changeset
1376 if proc:
c67db5dc131d extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents: 35243
diff changeset
1377 proc.communicate()
c67db5dc131d extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents: 35243
diff changeset
1378 if src:
c67db5dc131d extdata: use subprocess so we don't have to chdir() manually
Yuya Nishihara <yuya@tcha.org>
parents: 35243
diff changeset
1379 src.close()
36195
b1959391a088 extdata: abort if external command exits with non-zero status (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36091
diff changeset
1380 if proc and proc.returncode != 0:
b1959391a088 extdata: abort if external command exits with non-zero status (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 36091
diff changeset
1381 raise error.Abort(_("extdata command '%s' failed: %s")
38249
bbd240f81ac5 procutil: make explainexit() simply return a message (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38171
diff changeset
1382 % (cmd, procutil.explainexit(proc.returncode)))
35239
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1383
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1384 return data
7757cc48b766 extdata: add extdatasource reader
Matt Mackall <mpm@selenic.com>
parents: 35150
diff changeset
1385
27123
f0d730efb02f scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents: 27059
diff changeset
1386 def _locksub(repo, lock, envvar, cmd, environ=None, *args, **kwargs):
f0d730efb02f scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents: 27059
diff changeset
1387 if lock is None:
f0d730efb02f scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents: 27059
diff changeset
1388 raise error.LockInheritanceContractViolation(
f0d730efb02f scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents: 27059
diff changeset
1389 'lock can only be inherited while held')
f0d730efb02f scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents: 27059
diff changeset
1390 if environ is None:
f0d730efb02f scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents: 27059
diff changeset
1391 environ = {}
f0d730efb02f scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents: 27059
diff changeset
1392 with lock.inherit() as locker:
f0d730efb02f scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents: 27059
diff changeset
1393 environ[envvar] = locker
f0d730efb02f scmutil: add a way for a subprocess to be run with an inheritable lock
Siddharth Agarwal <sid0@fb.com>
parents: 27059
diff changeset
1394 return repo.ui.system(cmd, environ=environ, *args, **kwargs)
27124
366d489295ca scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents: 27123
diff changeset
1395
366d489295ca scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents: 27123
diff changeset
1396 def wlocksub(repo, cmd, *args, **kwargs):
366d489295ca scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents: 27123
diff changeset
1397 """run cmd as a subprocess that allows inheriting repo's wlock
366d489295ca scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents: 27123
diff changeset
1398
366d489295ca scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents: 27123
diff changeset
1399 This can only be called while the wlock is held. This takes all the
366d489295ca scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents: 27123
diff changeset
1400 arguments that ui.system does, and returns the exit code of the
366d489295ca scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents: 27123
diff changeset
1401 subprocess."""
366d489295ca scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents: 27123
diff changeset
1402 return _locksub(repo, repo.currentwlock(), 'HG_WLOCK_LOCKER', cmd, *args,
366d489295ca scmutil: add a way for a repo's wlock to be inherited by a subprocess
Siddharth Agarwal <sid0@fb.com>
parents: 27123
diff changeset
1403 **kwargs)
27546
e40af07e518e scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27476
diff changeset
1404
39131
bec1212eceaa progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 39117
diff changeset
1405 class progress(object):
41996
929999d963b8 progress: specify updatebar() function by constructor argument
Yuya Nishihara <yuya@tcha.org>
parents: 41995
diff changeset
1406 def __init__(self, ui, updatebar, topic, unit="", total=None):
39131
bec1212eceaa progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 39117
diff changeset
1407 self.ui = ui
bec1212eceaa progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 39117
diff changeset
1408 self.pos = 0
bec1212eceaa progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 39117
diff changeset
1409 self.topic = topic
bec1212eceaa progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 39117
diff changeset
1410 self.unit = unit
bec1212eceaa progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 39117
diff changeset
1411 self.total = total
41929
7b80406b8271 progress: move cached debug flag from progress.progbar to scmutil.progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 41928
diff changeset
1412 self.debug = ui.configbool('progress', 'debug')
41931
963462786f6e progress: check what type of progress bar to use only once per topic
Martin von Zweigbergk <martinvonz@google.com>
parents: 41930
diff changeset
1413 self._updatebar = updatebar
39131
bec1212eceaa progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 39117
diff changeset
1414
39160
800f5a2c869e progress: make the progress helper a context manager
Martin von Zweigbergk <martinvonz@google.com>
parents: 39159
diff changeset
1415 def __enter__(self):
39289
077301ac69dc scmutil: fix __enter__ in progress context manager
Danny Hooper <hooper@google.com>
parents: 39242
diff changeset
1416 return self
39160
800f5a2c869e progress: make the progress helper a context manager
Martin von Zweigbergk <martinvonz@google.com>
parents: 39159
diff changeset
1417
800f5a2c869e progress: make the progress helper a context manager
Martin von Zweigbergk <martinvonz@google.com>
parents: 39159
diff changeset
1418 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: 39159
diff changeset
1419 self.complete()
800f5a2c869e progress: make the progress helper a context manager
Martin von Zweigbergk <martinvonz@google.com>
parents: 39159
diff changeset
1420
39131
bec1212eceaa progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 39117
diff changeset
1421 def update(self, pos, item="", total=None):
39205
6dea017eb6ba progress: enforce use of complete() on the helper class
Martin von Zweigbergk <martinvonz@google.com>
parents: 39160
diff changeset
1422 assert pos is not None
39131
bec1212eceaa progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 39117
diff changeset
1423 if total:
bec1212eceaa progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 39117
diff changeset
1424 self.total = total
bec1212eceaa progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 39117
diff changeset
1425 self.pos = pos
41995
b223fc1c6b4c progress: change _updatebar() to take parameters as arguments
Yuya Nishihara <yuya@tcha.org>
parents: 41931
diff changeset
1426 self._updatebar(self.topic, self.pos, item, self.unit, self.total)
41930
3025fd3c2e71 progress: split up _print() method in bar-updating and debug-printing
Martin von Zweigbergk <martinvonz@google.com>
parents: 41929
diff changeset
1427 if self.debug:
3025fd3c2e71 progress: split up _print() method in bar-updating and debug-printing
Martin von Zweigbergk <martinvonz@google.com>
parents: 41929
diff changeset
1428 self._printdebug(item)
39131
bec1212eceaa progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 39117
diff changeset
1429
bec1212eceaa progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 39117
diff changeset
1430 def increment(self, step=1, item="", total=None):
bec1212eceaa progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 39117
diff changeset
1431 self.update(self.pos + step, item, total)
bec1212eceaa progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 39117
diff changeset
1432
39159
ef692614e601 progress: hide update(None) in a new complete() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 39131
diff changeset
1433 def complete(self):
41928
8cf92ca92bfe progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41670
diff changeset
1434 self.pos = None
8cf92ca92bfe progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41670
diff changeset
1435 self.unit = ""
8cf92ca92bfe progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41670
diff changeset
1436 self.total = None
41995
b223fc1c6b4c progress: change _updatebar() to take parameters as arguments
Yuya Nishihara <yuya@tcha.org>
parents: 41931
diff changeset
1437 self._updatebar(self.topic, self.pos, "", self.unit, self.total)
39159
ef692614e601 progress: hide update(None) in a new complete() method
Martin von Zweigbergk <martinvonz@google.com>
parents: 39131
diff changeset
1438
41930
3025fd3c2e71 progress: split up _print() method in bar-updating and debug-printing
Martin von Zweigbergk <martinvonz@google.com>
parents: 41929
diff changeset
1439 def _printdebug(self, item):
41928
8cf92ca92bfe progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41670
diff changeset
1440 if self.unit:
8cf92ca92bfe progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41670
diff changeset
1441 unit = ' ' + self.unit
8cf92ca92bfe progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41670
diff changeset
1442 if item:
8cf92ca92bfe progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41670
diff changeset
1443 item = ' ' + item
8cf92ca92bfe progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41670
diff changeset
1444
8cf92ca92bfe progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41670
diff changeset
1445 if self.total:
8cf92ca92bfe progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41670
diff changeset
1446 pct = 100.0 * self.pos / self.total
8cf92ca92bfe progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41670
diff changeset
1447 self.ui.debug('%s:%s %d/%d%s (%4.2f%%)\n'
8cf92ca92bfe progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41670
diff changeset
1448 % (self.topic, item, self.pos, self.total, unit, pct))
8cf92ca92bfe progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41670
diff changeset
1449 else:
8cf92ca92bfe progress: write ui.progress() in terms of ui.makeprogress()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41670
diff changeset
1450 self.ui.debug('%s:%s %d%s\n' % (self.topic, item, self.pos, unit))
39131
bec1212eceaa progress: create helper class for incrementing progress
Martin von Zweigbergk <martinvonz@google.com>
parents: 39117
diff changeset
1451
27546
e40af07e518e scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27476
diff changeset
1452 def gdinitconfig(ui):
e40af07e518e scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27476
diff changeset
1453 """helper function to know if a repo should be created as general delta
27547
dfab6edb98e3 format: introduce 'format.usegeneraldelta`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27546
diff changeset
1454 """
dfab6edb98e3 format: introduce 'format.usegeneraldelta`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27546
diff changeset
1455 # experimental config: format.generaldelta
34021
784f2bd96d43 configitems: register the 'format.generaldelta' config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33871
diff changeset
1456 return (ui.configbool('format', 'generaldelta')
41670
a714eee1ac28 sparse-revlog: disable sparse-revlog if config disable general-delta
Boris Feld <boris.feld@octobus.net>
parents: 41641
diff changeset
1457 or ui.configbool('format', 'usegeneraldelta'))
27546
e40af07e518e scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27476
diff changeset
1458
27547
dfab6edb98e3 format: introduce 'format.usegeneraldelta`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27546
diff changeset
1459 def gddeltaconfig(ui):
dfab6edb98e3 format: introduce 'format.usegeneraldelta`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27546
diff changeset
1460 """helper function to know if incoming delta should be optimised
dfab6edb98e3 format: introduce 'format.usegeneraldelta`
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27546
diff changeset
1461 """
27546
e40af07e518e scmutil: extract general delta config handling in a function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27476
diff changeset
1462 # experimental config: format.generaldelta
34021
784f2bd96d43 configitems: register the 'format.generaldelta' config
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33871
diff changeset
1463 return ui.configbool('format', 'generaldelta')
32332
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1464
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1465 class simplekeyvaluefile(object):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1466 """A simple file with key=value lines
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1467
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1468 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: 32198
diff changeset
1469 contain '\n' characters"""
33053
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1470 firstlinekey = '__firstline'
32332
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1471
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1472 def __init__(self, vfs, path, keys=None):
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1473 self.vfs = vfs
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1474 self.path = path
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1475
33053
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1476 def read(self, firstlinenonkeyval=False):
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1477 """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: 33052
diff changeset
1478
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1479 '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: 33052
diff changeset
1480 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: 33052
diff changeset
1481 __firstline key."""
32332
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1482 lines = self.vfs.readlines(self.path)
33053
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1483 d = {}
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1484 if firstlinenonkeyval:
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1485 if not lines:
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1486 e = _("empty simplekeyvalue file")
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1487 raise error.CorruptedState(e)
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1488 # 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: 33052
diff changeset
1489 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: 33052
diff changeset
1490 del lines[0]
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1491
32332
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1492 try:
33052
ed2c44741190 scmutil: add simplekeyvaluefile reading test
Kostia Balytskyi <ikostia@fb.com>
parents: 32955
diff changeset
1493 # the 'if line.strip()' part prevents us from failing on empty
ed2c44741190 scmutil: add simplekeyvaluefile reading test
Kostia Balytskyi <ikostia@fb.com>
parents: 32955
diff changeset
1494 # lines which only contain '\n' therefore are not skipped
ed2c44741190 scmutil: add simplekeyvaluefile reading test
Kostia Balytskyi <ikostia@fb.com>
parents: 32955
diff changeset
1495 # by 'if line'
33053
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1496 updatedict = dict(line[:-1].split('=', 1) for line in lines
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1497 if line.strip())
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1498 if self.firstlinekey in updatedict:
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1499 e = _("%r can't be used as a key")
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1500 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: 33052
diff changeset
1501 d.update(updatedict)
32332
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1502 except ValueError as e:
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1503 raise error.CorruptedState(str(e))
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1504 return d
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1505
33053
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1506 def write(self, data, firstline=None):
32332
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1507 """Write key=>value mapping to a file
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1508 data is a dict. Keys must be alphanumerical and start with a letter.
33053
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1509 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: 33052
diff changeset
1510
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1511 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: 33052
diff changeset
1512 everything else, as it is, not in a key=value form"""
32332
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1513 lines = []
33053
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1514 if firstline is not None:
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1515 lines.append('%s\n' % firstline)
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1516
32332
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1517 for k, v in data.items():
33053
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1518 if k == self.firstlinekey:
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1519 e = "key name '%s' is reserved" % self.firstlinekey
218ca8526ec0 scmutil: make simplekeyvaluefile able to have a non-key-value first line
Kostia Balytskyi <ikostia@fb.com>
parents: 33052
diff changeset
1520 raise error.ProgrammingError(e)
36699
558e01a23f40 py3: slice on bytes to prevent getting the ascii values
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36674
diff changeset
1521 if not k[0:1].isalpha():
32332
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1522 e = "keys must start with a letter in a key-value file"
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1523 raise error.ProgrammingError(e)
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1524 if not k.isalnum():
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1525 e = "invalid key name in a simple key-value file"
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1526 raise error.ProgrammingError(e)
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1527 if '\n' in v:
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1528 e = "invalid value in a simple key-value file"
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1529 raise error.ProgrammingError(e)
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1530 lines.append("%s=%s\n" % (k, v))
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1531 with self.vfs(self.path, mode='wb', atomictemp=True) as fp:
56acc4250900 scmutil: add a simple key-value file helper
Kostia Balytskyi <ikostia@fb.com>
parents: 32198
diff changeset
1532 fp.write(''.join(lines))
34035
53b3a1968aa6 obsolete: reports the number of local changeset obsoleted when unbundling
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 34029
diff changeset
1533
34324
b47fef6d2365 transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents: 34294
diff changeset
1534 _reportobsoletedsource = [
34325
b11e8c67fb0f debugobsolete: also report the number of obsoleted changesets
Boris Feld <boris.feld@octobus.net>
parents: 34324
diff changeset
1535 'debugobsolete',
34324
b47fef6d2365 transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents: 34294
diff changeset
1536 'pull',
b47fef6d2365 transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents: 34294
diff changeset
1537 'push',
b47fef6d2365 transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents: 34294
diff changeset
1538 'serve',
b47fef6d2365 transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents: 34294
diff changeset
1539 'unbundle',
b47fef6d2365 transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents: 34294
diff changeset
1540 ]
b47fef6d2365 transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents: 34294
diff changeset
1541
35444
eb586ed5d8ce transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35428
diff changeset
1542 _reportnewcssource = [
eb586ed5d8ce transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35428
diff changeset
1543 'pull',
eb586ed5d8ce transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35428
diff changeset
1544 'unbundle',
eb586ed5d8ce transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35428
diff changeset
1545 ]
eb586ed5d8ce transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35428
diff changeset
1546
38548
7269b87f817c scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 38495
diff changeset
1547 def prefetchfiles(repo, revs, match):
7269b87f817c scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 38495
diff changeset
1548 """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: 38495
diff changeset
1549 ensure the corresponding files are available locally, before the command
7269b87f817c scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 38495
diff changeset
1550 uses them."""
7269b87f817c scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 38495
diff changeset
1551 if match:
7269b87f817c scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 38495
diff changeset
1552 # The command itself will complain about files that don't exist, so
7269b87f817c scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 38495
diff changeset
1553 # don't duplicate the message.
7269b87f817c scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 38495
diff changeset
1554 match = matchmod.badmatch(match, lambda fn, msg: None)
7269b87f817c scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 38495
diff changeset
1555 else:
7269b87f817c scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 38495
diff changeset
1556 match = matchall(repo)
7269b87f817c scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 38495
diff changeset
1557
7269b87f817c scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 38495
diff changeset
1558 fileprefetchhooks(repo, revs, match)
7269b87f817c scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 38495
diff changeset
1559
7269b87f817c scmutil: teach the file prefetch hook to handle multiple commits
Matt Harbison <matt_harbison@yahoo.com>
parents: 38495
diff changeset
1560 # a list of (repo, revs, match) prefetch functions
36923
f52a9336ac5f cmdutil: convert the prefetchfiles() hook to a callback mechanism (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 36699
diff changeset
1561 fileprefetchhooks = util.hooks()
f52a9336ac5f cmdutil: convert the prefetchfiles() hook to a callback mechanism (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 36699
diff changeset
1562
36495
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1563 # 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: 36282
diff changeset
1564 _reportstroubledchangesets = True
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1565
34324
b47fef6d2365 transaction-summary: display the summary for all transactions
Boris Feld <boris.feld@octobus.net>
parents: 34294
diff changeset
1566 def registersummarycallback(repo, otr, txnname=''):
34035
53b3a1968aa6 obsolete: reports the number of local changeset obsoleted when unbundling
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 34029
diff changeset
1567 """register a callback to issue a summary after the transaction is closed
53b3a1968aa6 obsolete: reports the number of local changeset obsoleted when unbundling
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 34029
diff changeset
1568 """
35402
18309380fb88 scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35326
diff changeset
1569 def txmatch(sources):
18309380fb88 scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35326
diff changeset
1570 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: 35326
diff changeset
1571
35403
b799f11644d8 scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35402
diff changeset
1572 categories = []
b799f11644d8 scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35402
diff changeset
1573
b799f11644d8 scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35402
diff changeset
1574 def reportsummary(func):
b799f11644d8 scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35402
diff changeset
1575 """decorator for report callbacks."""
35818
96dcc78468e3 tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents: 35792
diff changeset
1576 # 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: 35792
diff changeset
1577 # 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: 35792
diff changeset
1578 # 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: 35792
diff changeset
1579 # 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: 35792
diff changeset
1580 # repository through the weakref.
96dcc78468e3 tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents: 35792
diff changeset
1581 filtername = repo.filtername
96dcc78468e3 tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents: 35792
diff changeset
1582 reporef = weakref.ref(repo.unfiltered())
35403
b799f11644d8 scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35402
diff changeset
1583 def wrapped(tr):
35402
18309380fb88 scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35326
diff changeset
1584 repo = reporef()
35818
96dcc78468e3 tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents: 35792
diff changeset
1585 if filtername:
96dcc78468e3 tr-summary: keep a weakref to the unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents: 35792
diff changeset
1586 repo = repo.filtered(filtername)
35403
b799f11644d8 scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35402
diff changeset
1587 func(repo, tr)
36534
963a611b2f39 scmutil: 0-pad transaction report callback category
Martin von Zweigbergk <martinvonz@google.com>
parents: 36496
diff changeset
1588 newcat = '%02i-txnreport' % len(categories)
35403
b799f11644d8 scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35402
diff changeset
1589 otr.addpostclose(newcat, wrapped)
b799f11644d8 scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35402
diff changeset
1590 categories.append(newcat)
b799f11644d8 scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35402
diff changeset
1591 return wrapped
b799f11644d8 scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35402
diff changeset
1592
b799f11644d8 scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35402
diff changeset
1593 if txmatch(_reportobsoletedsource):
b799f11644d8 scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35402
diff changeset
1594 @reportsummary
b799f11644d8 scmutil: factor out building of transaction summary callback
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35402
diff changeset
1595 def reportobsoleted(repo, tr):
35402
18309380fb88 scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35326
diff changeset
1596 obsoleted = obsutil.getobsoleted(repo, tr)
18309380fb88 scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35326
diff changeset
1597 if obsoleted:
18309380fb88 scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35326
diff changeset
1598 repo.ui.status(_('obsoleted %i changesets\n')
18309380fb88 scmutil: factor out transaction name lookup in registersummarycallback()
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35326
diff changeset
1599 % len(obsoleted))
35444
eb586ed5d8ce transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35428
diff changeset
1600
36496
5cd60b0587a8 evolution: make reporting of new unstable changesets optional
Martin von Zweigbergk <martinvonz@google.com>
parents: 36495
diff changeset
1601 if (obsolete.isenabled(repo, obsolete.createmarkersopt) and
5cd60b0587a8 evolution: make reporting of new unstable changesets optional
Martin von Zweigbergk <martinvonz@google.com>
parents: 36495
diff changeset
1602 repo.ui.configbool('experimental', 'evolution.report-instabilities')):
36495
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1603 instabilitytypes = [
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1604 ('orphan', 'orphan'),
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1605 ('phase-divergent', 'phasedivergent'),
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1606 ('content-divergent', 'contentdivergent'),
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1607 ]
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1608
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1609 def getinstabilitycounts(repo):
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1610 filtered = repo.changelog.filteredrevs
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1611 counts = {}
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1612 for instability, revset in instabilitytypes:
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1613 counts[instability] = len(set(obsolete.getrevs(repo, revset)) -
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1614 filtered)
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1615 return counts
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1616
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1617 oldinstabilitycounts = getinstabilitycounts(repo)
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1618 @reportsummary
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1619 def reportnewinstabilities(repo, tr):
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1620 newinstabilitycounts = getinstabilitycounts(repo)
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1621 for instability, revset in instabilitytypes:
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1622 delta = (newinstabilitycounts[instability] -
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1623 oldinstabilitycounts[instability])
39242
1cac2e8c7624 scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39218
diff changeset
1624 msg = getinstabilitymessage(delta, instability)
1cac2e8c7624 scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39218
diff changeset
1625 if msg:
1cac2e8c7624 scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39218
diff changeset
1626 repo.ui.warn(msg)
36495
1a09dad8b85a evolution: report new unstable changesets
Martin von Zweigbergk <martinvonz@google.com>
parents: 36282
diff changeset
1627
35444
eb586ed5d8ce transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35428
diff changeset
1628 if txmatch(_reportnewcssource):
eb586ed5d8ce transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35428
diff changeset
1629 @reportsummary
eb586ed5d8ce transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35428
diff changeset
1630 def reportnewcs(repo, tr):
eb586ed5d8ce transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35428
diff changeset
1631 """Report the range of new revisions pulled/unbundled."""
40087
5763216ba311 transaction: remember original len(repo) instead of tracking added revs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 40051
diff changeset
1632 origrepolen = tr.changes.get('origrepolen', len(repo))
40684
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1633 unfi = repo.unfiltered()
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1634 if origrepolen >= len(unfi):
35444
eb586ed5d8ce transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35428
diff changeset
1635 return
eb586ed5d8ce transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35428
diff changeset
1636
40683
a477679f6323 pullreport: skip filtered revs instead of obsolete ones
Boris Feld <boris.feld@octobus.net>
parents: 40680
diff changeset
1637 # Compute the bounds of new visible revisions' range.
a477679f6323 pullreport: skip filtered revs instead of obsolete ones
Boris Feld <boris.feld@octobus.net>
parents: 40680
diff changeset
1638 revs = smartset.spanset(repo, start=origrepolen)
40684
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1639 if revs:
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1640 minrev, maxrev = repo[revs.min()], repo[revs.max()]
35444
eb586ed5d8ce transaction-summary: show the range of new revisions upon pull/unbundle (BC)
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 35428
diff changeset
1641
40684
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1642 if minrev == maxrev:
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1643 revrange = minrev
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1644 else:
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1645 revrange = '%s:%s' % (minrev, maxrev)
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1646 draft = len(repo.revs('%ld and draft()', revs))
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1647 secret = len(repo.revs('%ld and secret()', revs))
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1648 if not (draft or secret):
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1649 msg = _('new changesets %s\n') % revrange
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1650 elif draft and secret:
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1651 msg = _('new changesets %s (%d drafts, %d secrets)\n')
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1652 msg %= (revrange, draft, secret)
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1653 elif draft:
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1654 msg = _('new changesets %s (%d drafts)\n')
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1655 msg %= (revrange, draft)
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1656 elif secret:
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1657 msg = _('new changesets %s (%d secrets)\n')
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1658 msg %= (revrange, secret)
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1659 else:
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1660 errormsg = 'entered unreachable condition'
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1661 raise error.ProgrammingError(errormsg)
b5e12039e6e0 pullreport: skip or rework some early return
Boris Feld <boris.feld@octobus.net>
parents: 40683
diff changeset
1662 repo.ui.status(msg)
35960
9700cb9df140 convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents: 35818
diff changeset
1663
40685
f9232b0310ef pullreport: issue a message about "extinct" pulled changesets
Boris Feld <boris.feld@octobus.net>
parents: 40684
diff changeset
1664 # search new changesets directly pulled as obsolete
40686
a89dd6d01df0 pullreport: rev duplicated and extinct into account
Boris Feld <boris.feld@octobus.net>
parents: 40685
diff changeset
1665 duplicates = tr.changes.get('revduplicates', ())
a89dd6d01df0 pullreport: rev duplicated and extinct into account
Boris Feld <boris.feld@octobus.net>
parents: 40685
diff changeset
1666 obsadded = unfi.revs('(%d: + %ld) and obsolete()',
a89dd6d01df0 pullreport: rev duplicated and extinct into account
Boris Feld <boris.feld@octobus.net>
parents: 40685
diff changeset
1667 origrepolen, duplicates)
40685
f9232b0310ef pullreport: issue a message about "extinct" pulled changesets
Boris Feld <boris.feld@octobus.net>
parents: 40684
diff changeset
1668 cl = repo.changelog
f9232b0310ef pullreport: issue a message about "extinct" pulled changesets
Boris Feld <boris.feld@octobus.net>
parents: 40684
diff changeset
1669 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: 40684
diff changeset
1670 if extinctadded:
f9232b0310ef pullreport: issue a message about "extinct" pulled changesets
Boris Feld <boris.feld@octobus.net>
parents: 40684
diff changeset
1671 # 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: 40684
diff changeset
1672 # 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: 40684
diff changeset
1673 # exposed to users.
f9232b0310ef pullreport: issue a message about "extinct" pulled changesets
Boris Feld <boris.feld@octobus.net>
parents: 40684
diff changeset
1674 msg = '(%d other changesets obsolete on arrival)\n'
f9232b0310ef pullreport: issue a message about "extinct" pulled changesets
Boris Feld <boris.feld@octobus.net>
parents: 40684
diff changeset
1675 repo.ui.status(msg % len(extinctadded))
f9232b0310ef pullreport: issue a message about "extinct" pulled changesets
Boris Feld <boris.feld@octobus.net>
parents: 40684
diff changeset
1676
38957
eb9835014d20 transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 38917
diff changeset
1677 @reportsummary
eb9835014d20 transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 38917
diff changeset
1678 def reportphasechanges(repo, tr):
eb9835014d20 transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 38917
diff changeset
1679 """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: 38917
diff changeset
1680 pull/unbundle.
eb9835014d20 transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 38917
diff changeset
1681 """
40087
5763216ba311 transaction: remember original len(repo) instead of tracking added revs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 40051
diff changeset
1682 origrepolen = tr.changes.get('origrepolen', len(repo))
38957
eb9835014d20 transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 38917
diff changeset
1683 phasetracking = tr.changes.get('phases', {})
eb9835014d20 transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 38917
diff changeset
1684 if not phasetracking:
eb9835014d20 transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 38917
diff changeset
1685 return
eb9835014d20 transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 38917
diff changeset
1686 published = [
eb9835014d20 transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 38917
diff changeset
1687 rev for rev, (old, new) in phasetracking.iteritems()
40087
5763216ba311 transaction: remember original len(repo) instead of tracking added revs (API)
Yuya Nishihara <yuya@tcha.org>
parents: 40051
diff changeset
1688 if new == phases.public and rev < origrepolen
38957
eb9835014d20 transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 38917
diff changeset
1689 ]
eb9835014d20 transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 38917
diff changeset
1690 if not published:
eb9835014d20 transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 38917
diff changeset
1691 return
39036
d0abd7949ea3 phases: use "published" in the phase movement message
Boris Feld <boris.feld@octobus.net>
parents: 39035
diff changeset
1692 repo.ui.status(_('%d local changesets published\n')
38957
eb9835014d20 transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 38917
diff changeset
1693 % len(published))
eb9835014d20 transaction-summary: show phase changes statistics in pull/unbundle
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 38917
diff changeset
1694
39242
1cac2e8c7624 scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39218
diff changeset
1695 def getinstabilitymessage(delta, instability):
1cac2e8c7624 scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39218
diff changeset
1696 """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: 39218
diff changeset
1697
1cac2e8c7624 scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39218
diff changeset
1698 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: 39218
diff changeset
1699 information like how to fix instabilities"""
1cac2e8c7624 scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39218
diff changeset
1700 if delta > 0:
1cac2e8c7624 scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39218
diff changeset
1701 return _('%i new %s changesets\n') % (delta, instability)
1cac2e8c7624 scmutil: move construction of instability count message to separate fn
Pulkit Goyal <7895pulkit@gmail.com>
parents: 39218
diff changeset
1702
35967
bc775b8cc020 scmutil: extra utility to display a reasonable amount of nodes
Boris Feld <boris.feld@octobus.net>
parents: 35960
diff changeset
1703 def nodesummaries(repo, nodes, maxnumnodes=4):
bc775b8cc020 scmutil: extra utility to display a reasonable amount of nodes
Boris Feld <boris.feld@octobus.net>
parents: 35960
diff changeset
1704 if len(nodes) <= maxnumnodes or repo.ui.verbose:
bc775b8cc020 scmutil: extra utility to display a reasonable amount of nodes
Boris Feld <boris.feld@octobus.net>
parents: 35960
diff changeset
1705 return ' '.join(short(h) for h in nodes)
bc775b8cc020 scmutil: extra utility to display a reasonable amount of nodes
Boris Feld <boris.feld@octobus.net>
parents: 35960
diff changeset
1706 first = ' '.join(short(h) for h in nodes[:maxnumnodes])
35989
278f1feee73a scmutil: improve format pattern used in nodesummaries
Boris Feld <boris.feld@octobus.net>
parents: 35968
diff changeset
1707 return _("%s and %d others") % (first, len(nodes) - maxnumnodes)
35967
bc775b8cc020 scmutil: extra utility to display a reasonable amount of nodes
Boris Feld <boris.feld@octobus.net>
parents: 35960
diff changeset
1708
35968
66ecde8a704d server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents: 35967
diff changeset
1709 def enforcesinglehead(repo, tr, desc):
66ecde8a704d server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents: 35967
diff changeset
1710 """check that no named branch has multiple heads"""
66ecde8a704d server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents: 35967
diff changeset
1711 if desc in ('strip', 'repair'):
66ecde8a704d server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents: 35967
diff changeset
1712 # skip the logic during strip
66ecde8a704d server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents: 35967
diff changeset
1713 return
66ecde8a704d server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents: 35967
diff changeset
1714 visible = repo.filtered('visible')
66ecde8a704d server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents: 35967
diff changeset
1715 # possible improvement: we could restrict the check to affected branch
66ecde8a704d server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents: 35967
diff changeset
1716 for name, heads in visible.branchmap().iteritems():
66ecde8a704d server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents: 35967
diff changeset
1717 if len(heads) > 1:
66ecde8a704d server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents: 35967
diff changeset
1718 msg = _('rejecting multiple heads on branch "%s"')
66ecde8a704d server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents: 35967
diff changeset
1719 msg %= name
66ecde8a704d server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents: 35967
diff changeset
1720 hint = _('%d heads: %s')
66ecde8a704d server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents: 35967
diff changeset
1721 hint %= (len(heads), nodesummaries(repo, heads))
66ecde8a704d server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents: 35967
diff changeset
1722 raise error.Abort(msg, hint=hint)
66ecde8a704d server: introduce a 'experimental.single-head-per-branch' option
Boris Feld <boris.feld@octobus.net>
parents: 35967
diff changeset
1723
35960
9700cb9df140 convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents: 35818
diff changeset
1724 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: 35818
diff changeset
1725 """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: 35818
diff changeset
1726 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: 35818
diff changeset
1727 """
9700cb9df140 convert: allow the sink object to be wrapped when the extension isn't loaded
Matt Harbison <matt_harbison@yahoo.com>
parents: 35818
diff changeset
1728 return sink
36279
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1729
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1730 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: 36195
diff changeset
1731 """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: 36195
diff changeset
1732 is passed.
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1733
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1734 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: 36195
diff changeset
1735 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: 36195
diff changeset
1736
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1737 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: 36195
diff changeset
1738 """
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1739 if not repo.filtername or not repo.ui.configbool('experimental',
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1740 'directaccess'):
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1741 return repo
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1742
36282
b55a142f00c5 scmutil: use a tuple of possible values instead of using startswith()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36279
diff changeset
1743 if repo.filtername not in ('visible', 'visible-hidden'):
36279
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1744 return repo
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1745
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1746 symbols = set()
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1747 for spec in specs:
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1748 try:
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1749 tree = revsetlang.parse(spec)
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1750 except error.ParseError: # will be reported by scmutil.revrange()
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1751 continue
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1752
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1753 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: 36195
diff changeset
1754
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1755 if not symbols:
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1756 return repo
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1757
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1758 revs = _getrevsfromsymbols(repo, symbols)
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1759
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1760 if not revs:
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1761 return repo
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1762
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1763 if hiddentype == 'warn':
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1764 unfi = repo.unfiltered()
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1765 revstr = ", ".join([pycompat.bytestr(unfi[l]) for l in revs])
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1766 repo.ui.warn(_("warning: accessing hidden changesets for write "
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1767 "operation: %s\n") % revstr)
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1768
36282
b55a142f00c5 scmutil: use a tuple of possible values instead of using startswith()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36279
diff changeset
1769 # 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: 36279
diff changeset
1770 # disbale these cache when revisions are dynamically pinned.
36279
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1771 return repo.filtered('visible-hidden', revs)
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1772
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1773 def _getrevsfromsymbols(repo, symbols):
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1774 """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: 36195
diff changeset
1775 changesets present in symbols"""
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1776 revs = set()
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1777 unfi = repo.unfiltered()
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1778 unficl = unfi.changelog
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1779 cl = repo.changelog
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1780 tiprev = len(unficl)
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1781 allowrevnums = repo.ui.configbool('experimental', 'directaccess.revnums')
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1782 for s in symbols:
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1783 try:
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1784 n = int(s)
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1785 if n <= tiprev:
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1786 if not allowrevnums:
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1787 continue
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1788 else:
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1789 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: 36195
diff changeset
1790 revs.add(n)
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1791 continue
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1792 except ValueError:
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1793 pass
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1794
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1795 try:
38654
69de3c3de036 directaccess: use resolvehexnodeidprefix() instead of _partialmatch()
Martin von Zweigbergk <martinvonz@google.com>
parents: 38651
diff changeset
1796 s = resolvehexnodeidprefix(unfi, s)
37880
7f025c9b7865 directaccess: do not abort by 'ff...' hash
Yuya Nishihara <yuya@tcha.org>
parents: 37870
diff changeset
1797 except (error.LookupError, error.WdirUnsupported):
36279
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1798 s = None
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1799
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1800 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: 36195
diff changeset
1801 rev = unficl.rev(s)
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1802 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: 36195
diff changeset
1803 revs.add(rev)
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1804
8bb90cc4668e scmutil: add utility fn to return repo object with user passed revs unhidden
Pulkit Goyal <7895pulkit@gmail.com>
parents: 36195
diff changeset
1805 return revs
38917
46c2b19a1263 scmutil: move repair.stripbmrevset as scmutil.bookmarkrevs (API)
David Demelier <markand@malikania.fr>
parents: 38765
diff changeset
1806
46c2b19a1263 scmutil: move repair.stripbmrevset as scmutil.bookmarkrevs (API)
David Demelier <markand@malikania.fr>
parents: 38765
diff changeset
1807 def bookmarkrevs(repo, mark):
46c2b19a1263 scmutil: move repair.stripbmrevset as scmutil.bookmarkrevs (API)
David Demelier <markand@malikania.fr>
parents: 38765
diff changeset
1808 """
46c2b19a1263 scmutil: move repair.stripbmrevset as scmutil.bookmarkrevs (API)
David Demelier <markand@malikania.fr>
parents: 38765
diff changeset
1809 Select revisions reachable by a given bookmark
46c2b19a1263 scmutil: move repair.stripbmrevset as scmutil.bookmarkrevs (API)
David Demelier <markand@malikania.fr>
parents: 38765
diff changeset
1810 """
46c2b19a1263 scmutil: move repair.stripbmrevset as scmutil.bookmarkrevs (API)
David Demelier <markand@malikania.fr>
parents: 38765
diff changeset
1811 return repo.revs("ancestors(bookmark(%s)) - "
46c2b19a1263 scmutil: move repair.stripbmrevset as scmutil.bookmarkrevs (API)
David Demelier <markand@malikania.fr>
parents: 38765
diff changeset
1812 "ancestors(head() and not bookmark(%s)) - "
46c2b19a1263 scmutil: move repair.stripbmrevset as scmutil.bookmarkrevs (API)
David Demelier <markand@malikania.fr>
parents: 38765
diff changeset
1813 "ancestors(bookmark() and not bookmark(%s))",
46c2b19a1263 scmutil: move repair.stripbmrevset as scmutil.bookmarkrevs (API)
David Demelier <markand@malikania.fr>
parents: 38765
diff changeset
1814 mark, mark, mark)