Show More
@@ -1,537 +1,548 b'' | |||||
1 | # changelog.py - changelog class for mercurial |
|
1 | # changelog.py - changelog class for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | import collections |
|
10 | import collections | |
11 |
|
11 | |||
12 | from .i18n import _ |
|
12 | from .i18n import _ | |
13 | from .node import ( |
|
13 | from .node import ( | |
14 | bin, |
|
14 | bin, | |
15 | hex, |
|
15 | hex, | |
16 | nullid, |
|
16 | nullid, | |
17 | ) |
|
17 | ) | |
18 |
|
18 | |||
19 | from . import ( |
|
19 | from . import ( | |
20 | encoding, |
|
20 | encoding, | |
21 | error, |
|
21 | error, | |
22 | revlog, |
|
22 | revlog, | |
23 | util, |
|
23 | util, | |
24 | ) |
|
24 | ) | |
25 |
|
25 | |||
26 | _defaultextra = {'branch': 'default'} |
|
26 | _defaultextra = {'branch': 'default'} | |
27 |
|
27 | |||
28 | def _string_escape(text): |
|
28 | def _string_escape(text): | |
29 | """ |
|
29 | """ | |
30 | >>> d = {'nl': chr(10), 'bs': chr(92), 'cr': chr(13), 'nul': chr(0)} |
|
30 | >>> d = {'nl': chr(10), 'bs': chr(92), 'cr': chr(13), 'nul': chr(0)} | |
31 | >>> s = "ab%(nl)scd%(bs)s%(bs)sn%(nul)sab%(cr)scd%(bs)s%(nl)s" % d |
|
31 | >>> s = "ab%(nl)scd%(bs)s%(bs)sn%(nul)sab%(cr)scd%(bs)s%(nl)s" % d | |
32 | >>> s |
|
32 | >>> s | |
33 | 'ab\\ncd\\\\\\\\n\\x00ab\\rcd\\\\\\n' |
|
33 | 'ab\\ncd\\\\\\\\n\\x00ab\\rcd\\\\\\n' | |
34 | >>> res = _string_escape(s) |
|
34 | >>> res = _string_escape(s) | |
35 | >>> s == util.unescapestr(res) |
|
35 | >>> s == util.unescapestr(res) | |
36 | True |
|
36 | True | |
37 | """ |
|
37 | """ | |
38 | # subset of the string_escape codec |
|
38 | # subset of the string_escape codec | |
39 | text = text.replace('\\', '\\\\').replace('\n', '\\n').replace('\r', '\\r') |
|
39 | text = text.replace('\\', '\\\\').replace('\n', '\\n').replace('\r', '\\r') | |
40 | return text.replace('\0', '\\0') |
|
40 | return text.replace('\0', '\\0') | |
41 |
|
41 | |||
42 | def decodeextra(text): |
|
42 | def decodeextra(text): | |
43 | """ |
|
43 | """ | |
44 | >>> sorted(decodeextra(encodeextra({'foo': 'bar', 'baz': chr(0) + '2'}) |
|
44 | >>> sorted(decodeextra(encodeextra({'foo': 'bar', 'baz': chr(0) + '2'}) | |
45 | ... ).iteritems()) |
|
45 | ... ).iteritems()) | |
46 | [('baz', '\\x002'), ('branch', 'default'), ('foo', 'bar')] |
|
46 | [('baz', '\\x002'), ('branch', 'default'), ('foo', 'bar')] | |
47 | >>> sorted(decodeextra(encodeextra({'foo': 'bar', |
|
47 | >>> sorted(decodeextra(encodeextra({'foo': 'bar', | |
48 | ... 'baz': chr(92) + chr(0) + '2'}) |
|
48 | ... 'baz': chr(92) + chr(0) + '2'}) | |
49 | ... ).iteritems()) |
|
49 | ... ).iteritems()) | |
50 | [('baz', '\\\\\\x002'), ('branch', 'default'), ('foo', 'bar')] |
|
50 | [('baz', '\\\\\\x002'), ('branch', 'default'), ('foo', 'bar')] | |
51 | """ |
|
51 | """ | |
52 | extra = _defaultextra.copy() |
|
52 | extra = _defaultextra.copy() | |
53 | for l in text.split('\0'): |
|
53 | for l in text.split('\0'): | |
54 | if l: |
|
54 | if l: | |
55 | if '\\0' in l: |
|
55 | if '\\0' in l: | |
56 | # fix up \0 without getting into trouble with \\0 |
|
56 | # fix up \0 without getting into trouble with \\0 | |
57 | l = l.replace('\\\\', '\\\\\n') |
|
57 | l = l.replace('\\\\', '\\\\\n') | |
58 | l = l.replace('\\0', '\0') |
|
58 | l = l.replace('\\0', '\0') | |
59 | l = l.replace('\n', '') |
|
59 | l = l.replace('\n', '') | |
60 | k, v = util.unescapestr(l).split(':', 1) |
|
60 | k, v = util.unescapestr(l).split(':', 1) | |
61 | extra[k] = v |
|
61 | extra[k] = v | |
62 | return extra |
|
62 | return extra | |
63 |
|
63 | |||
64 | def encodeextra(d): |
|
64 | def encodeextra(d): | |
65 | # keys must be sorted to produce a deterministic changelog entry |
|
65 | # keys must be sorted to produce a deterministic changelog entry | |
66 | items = [_string_escape('%s:%s' % (k, d[k])) for k in sorted(d)] |
|
66 | items = [_string_escape('%s:%s' % (k, d[k])) for k in sorted(d)] | |
67 | return "\0".join(items) |
|
67 | return "\0".join(items) | |
68 |
|
68 | |||
69 | def stripdesc(desc): |
|
69 | def stripdesc(desc): | |
70 | """strip trailing whitespace and leading and trailing empty lines""" |
|
70 | """strip trailing whitespace and leading and trailing empty lines""" | |
71 | return '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n') |
|
71 | return '\n'.join([l.rstrip() for l in desc.splitlines()]).strip('\n') | |
72 |
|
72 | |||
73 | class appender(object): |
|
73 | class appender(object): | |
74 | '''the changelog index must be updated last on disk, so we use this class |
|
74 | '''the changelog index must be updated last on disk, so we use this class | |
75 | to delay writes to it''' |
|
75 | to delay writes to it''' | |
76 | def __init__(self, vfs, name, mode, buf): |
|
76 | def __init__(self, vfs, name, mode, buf): | |
77 | self.data = buf |
|
77 | self.data = buf | |
78 | fp = vfs(name, mode) |
|
78 | fp = vfs(name, mode) | |
79 | self.fp = fp |
|
79 | self.fp = fp | |
80 | self.offset = fp.tell() |
|
80 | self.offset = fp.tell() | |
81 | self.size = vfs.fstat(fp).st_size |
|
81 | self.size = vfs.fstat(fp).st_size | |
82 | self._end = self.size |
|
82 | self._end = self.size | |
83 |
|
83 | |||
84 | def end(self): |
|
84 | def end(self): | |
85 | return self._end |
|
85 | return self._end | |
86 | def tell(self): |
|
86 | def tell(self): | |
87 | return self.offset |
|
87 | return self.offset | |
88 | def flush(self): |
|
88 | def flush(self): | |
89 | pass |
|
89 | pass | |
90 | def close(self): |
|
90 | def close(self): | |
91 | self.fp.close() |
|
91 | self.fp.close() | |
92 |
|
92 | |||
93 | def seek(self, offset, whence=0): |
|
93 | def seek(self, offset, whence=0): | |
94 | '''virtual file offset spans real file and data''' |
|
94 | '''virtual file offset spans real file and data''' | |
95 | if whence == 0: |
|
95 | if whence == 0: | |
96 | self.offset = offset |
|
96 | self.offset = offset | |
97 | elif whence == 1: |
|
97 | elif whence == 1: | |
98 | self.offset += offset |
|
98 | self.offset += offset | |
99 | elif whence == 2: |
|
99 | elif whence == 2: | |
100 | self.offset = self.end() + offset |
|
100 | self.offset = self.end() + offset | |
101 | if self.offset < self.size: |
|
101 | if self.offset < self.size: | |
102 | self.fp.seek(self.offset) |
|
102 | self.fp.seek(self.offset) | |
103 |
|
103 | |||
104 | def read(self, count=-1): |
|
104 | def read(self, count=-1): | |
105 | '''only trick here is reads that span real file and data''' |
|
105 | '''only trick here is reads that span real file and data''' | |
106 | ret = "" |
|
106 | ret = "" | |
107 | if self.offset < self.size: |
|
107 | if self.offset < self.size: | |
108 | s = self.fp.read(count) |
|
108 | s = self.fp.read(count) | |
109 | ret = s |
|
109 | ret = s | |
110 | self.offset += len(s) |
|
110 | self.offset += len(s) | |
111 | if count > 0: |
|
111 | if count > 0: | |
112 | count -= len(s) |
|
112 | count -= len(s) | |
113 | if count != 0: |
|
113 | if count != 0: | |
114 | doff = self.offset - self.size |
|
114 | doff = self.offset - self.size | |
115 | self.data.insert(0, "".join(self.data)) |
|
115 | self.data.insert(0, "".join(self.data)) | |
116 | del self.data[1:] |
|
116 | del self.data[1:] | |
117 | s = self.data[0][doff:doff + count] |
|
117 | s = self.data[0][doff:doff + count] | |
118 | self.offset += len(s) |
|
118 | self.offset += len(s) | |
119 | ret += s |
|
119 | ret += s | |
120 | return ret |
|
120 | return ret | |
121 |
|
121 | |||
122 | def write(self, s): |
|
122 | def write(self, s): | |
123 | self.data.append(bytes(s)) |
|
123 | self.data.append(bytes(s)) | |
124 | self.offset += len(s) |
|
124 | self.offset += len(s) | |
125 | self._end += len(s) |
|
125 | self._end += len(s) | |
126 |
|
126 | |||
127 | def _divertopener(opener, target): |
|
127 | def _divertopener(opener, target): | |
128 | """build an opener that writes in 'target.a' instead of 'target'""" |
|
128 | """build an opener that writes in 'target.a' instead of 'target'""" | |
129 | def _divert(name, mode='r', checkambig=False): |
|
129 | def _divert(name, mode='r', checkambig=False): | |
130 | if name != target: |
|
130 | if name != target: | |
131 | return opener(name, mode) |
|
131 | return opener(name, mode) | |
132 | return opener(name + ".a", mode) |
|
132 | return opener(name + ".a", mode) | |
133 | return _divert |
|
133 | return _divert | |
134 |
|
134 | |||
135 | def _delayopener(opener, target, buf): |
|
135 | def _delayopener(opener, target, buf): | |
136 | """build an opener that stores chunks in 'buf' instead of 'target'""" |
|
136 | """build an opener that stores chunks in 'buf' instead of 'target'""" | |
137 | def _delay(name, mode='r', checkambig=False): |
|
137 | def _delay(name, mode='r', checkambig=False): | |
138 | if name != target: |
|
138 | if name != target: | |
139 | return opener(name, mode) |
|
139 | return opener(name, mode) | |
140 | return appender(opener, name, mode, buf) |
|
140 | return appender(opener, name, mode, buf) | |
141 | return _delay |
|
141 | return _delay | |
142 |
|
142 | |||
143 | _changelogrevision = collections.namedtuple(u'changelogrevision', |
|
143 | _changelogrevision = collections.namedtuple(u'changelogrevision', | |
144 | (u'manifest', u'user', u'date', |
|
144 | (u'manifest', u'user', u'date', | |
145 | u'files', u'description', |
|
145 | u'files', u'description', | |
146 | u'extra')) |
|
146 | u'extra')) | |
147 |
|
147 | |||
148 | class changelogrevision(object): |
|
148 | class changelogrevision(object): | |
149 | """Holds results of a parsed changelog revision. |
|
149 | """Holds results of a parsed changelog revision. | |
150 |
|
150 | |||
151 | Changelog revisions consist of multiple pieces of data, including |
|
151 | Changelog revisions consist of multiple pieces of data, including | |
152 | the manifest node, user, and date. This object exposes a view into |
|
152 | the manifest node, user, and date. This object exposes a view into | |
153 | the parsed object. |
|
153 | the parsed object. | |
154 | """ |
|
154 | """ | |
155 |
|
155 | |||
156 | __slots__ = ( |
|
156 | __slots__ = ( | |
157 | u'_offsets', |
|
157 | u'_offsets', | |
158 | u'_text', |
|
158 | u'_text', | |
159 | ) |
|
159 | ) | |
160 |
|
160 | |||
161 | def __new__(cls, text): |
|
161 | def __new__(cls, text): | |
162 | if not text: |
|
162 | if not text: | |
163 | return _changelogrevision( |
|
163 | return _changelogrevision( | |
164 | manifest=nullid, |
|
164 | manifest=nullid, | |
165 | user='', |
|
165 | user='', | |
166 | date=(0, 0), |
|
166 | date=(0, 0), | |
167 | files=[], |
|
167 | files=[], | |
168 | description='', |
|
168 | description='', | |
169 | extra=_defaultextra, |
|
169 | extra=_defaultextra, | |
170 | ) |
|
170 | ) | |
171 |
|
171 | |||
172 | self = super(changelogrevision, cls).__new__(cls) |
|
172 | self = super(changelogrevision, cls).__new__(cls) | |
173 | # We could return here and implement the following as an __init__. |
|
173 | # We could return here and implement the following as an __init__. | |
174 | # But doing it here is equivalent and saves an extra function call. |
|
174 | # But doing it here is equivalent and saves an extra function call. | |
175 |
|
175 | |||
176 | # format used: |
|
176 | # format used: | |
177 | # nodeid\n : manifest node in ascii |
|
177 | # nodeid\n : manifest node in ascii | |
178 | # user\n : user, no \n or \r allowed |
|
178 | # user\n : user, no \n or \r allowed | |
179 | # time tz extra\n : date (time is int or float, timezone is int) |
|
179 | # time tz extra\n : date (time is int or float, timezone is int) | |
180 | # : extra is metadata, encoded and separated by '\0' |
|
180 | # : extra is metadata, encoded and separated by '\0' | |
181 | # : older versions ignore it |
|
181 | # : older versions ignore it | |
182 | # files\n\n : files modified by the cset, no \n or \r allowed |
|
182 | # files\n\n : files modified by the cset, no \n or \r allowed | |
183 | # (.*) : comment (free text, ideally utf-8) |
|
183 | # (.*) : comment (free text, ideally utf-8) | |
184 | # |
|
184 | # | |
185 | # changelog v0 doesn't use extra |
|
185 | # changelog v0 doesn't use extra | |
186 |
|
186 | |||
187 | nl1 = text.index('\n') |
|
187 | nl1 = text.index('\n') | |
188 | nl2 = text.index('\n', nl1 + 1) |
|
188 | nl2 = text.index('\n', nl1 + 1) | |
189 | nl3 = text.index('\n', nl2 + 1) |
|
189 | nl3 = text.index('\n', nl2 + 1) | |
190 |
|
190 | |||
191 | # The list of files may be empty. Which means nl3 is the first of the |
|
191 | # The list of files may be empty. Which means nl3 is the first of the | |
192 | # double newline that precedes the description. |
|
192 | # double newline that precedes the description. | |
193 | if text[nl3 + 1:nl3 + 2] == '\n': |
|
193 | if text[nl3 + 1:nl3 + 2] == '\n': | |
194 | doublenl = nl3 |
|
194 | doublenl = nl3 | |
195 | else: |
|
195 | else: | |
196 | doublenl = text.index('\n\n', nl3 + 1) |
|
196 | doublenl = text.index('\n\n', nl3 + 1) | |
197 |
|
197 | |||
198 | self._offsets = (nl1, nl2, nl3, doublenl) |
|
198 | self._offsets = (nl1, nl2, nl3, doublenl) | |
199 | self._text = text |
|
199 | self._text = text | |
200 |
|
200 | |||
201 | return self |
|
201 | return self | |
202 |
|
202 | |||
203 | @property |
|
203 | @property | |
204 | def manifest(self): |
|
204 | def manifest(self): | |
205 | return bin(self._text[0:self._offsets[0]]) |
|
205 | return bin(self._text[0:self._offsets[0]]) | |
206 |
|
206 | |||
207 | @property |
|
207 | @property | |
208 | def user(self): |
|
208 | def user(self): | |
209 | off = self._offsets |
|
209 | off = self._offsets | |
210 | return encoding.tolocal(self._text[off[0] + 1:off[1]]) |
|
210 | return encoding.tolocal(self._text[off[0] + 1:off[1]]) | |
211 |
|
211 | |||
212 | @property |
|
212 | @property | |
213 | def _rawdate(self): |
|
213 | def _rawdate(self): | |
214 | off = self._offsets |
|
214 | off = self._offsets | |
215 | dateextra = self._text[off[1] + 1:off[2]] |
|
215 | dateextra = self._text[off[1] + 1:off[2]] | |
216 | return dateextra.split(' ', 2)[0:2] |
|
216 | return dateextra.split(' ', 2)[0:2] | |
217 |
|
217 | |||
218 | @property |
|
218 | @property | |
219 | def _rawextra(self): |
|
219 | def _rawextra(self): | |
220 | off = self._offsets |
|
220 | off = self._offsets | |
221 | dateextra = self._text[off[1] + 1:off[2]] |
|
221 | dateextra = self._text[off[1] + 1:off[2]] | |
222 | fields = dateextra.split(' ', 2) |
|
222 | fields = dateextra.split(' ', 2) | |
223 | if len(fields) != 3: |
|
223 | if len(fields) != 3: | |
224 | return None |
|
224 | return None | |
225 |
|
225 | |||
226 | return fields[2] |
|
226 | return fields[2] | |
227 |
|
227 | |||
228 | @property |
|
228 | @property | |
229 | def date(self): |
|
229 | def date(self): | |
230 | raw = self._rawdate |
|
230 | raw = self._rawdate | |
231 | time = float(raw[0]) |
|
231 | time = float(raw[0]) | |
232 | # Various tools did silly things with the timezone. |
|
232 | # Various tools did silly things with the timezone. | |
233 | try: |
|
233 | try: | |
234 | timezone = int(raw[1]) |
|
234 | timezone = int(raw[1]) | |
235 | except ValueError: |
|
235 | except ValueError: | |
236 | timezone = 0 |
|
236 | timezone = 0 | |
237 |
|
237 | |||
238 | return time, timezone |
|
238 | return time, timezone | |
239 |
|
239 | |||
240 | @property |
|
240 | @property | |
241 | def extra(self): |
|
241 | def extra(self): | |
242 | raw = self._rawextra |
|
242 | raw = self._rawextra | |
243 | if raw is None: |
|
243 | if raw is None: | |
244 | return _defaultextra |
|
244 | return _defaultextra | |
245 |
|
245 | |||
246 | return decodeextra(raw) |
|
246 | return decodeextra(raw) | |
247 |
|
247 | |||
248 | @property |
|
248 | @property | |
249 | def files(self): |
|
249 | def files(self): | |
250 | off = self._offsets |
|
250 | off = self._offsets | |
251 | if off[2] == off[3]: |
|
251 | if off[2] == off[3]: | |
252 | return [] |
|
252 | return [] | |
253 |
|
253 | |||
254 | return self._text[off[2] + 1:off[3]].split('\n') |
|
254 | return self._text[off[2] + 1:off[3]].split('\n') | |
255 |
|
255 | |||
256 | @property |
|
256 | @property | |
257 | def description(self): |
|
257 | def description(self): | |
258 | return encoding.tolocal(self._text[self._offsets[3] + 2:]) |
|
258 | return encoding.tolocal(self._text[self._offsets[3] + 2:]) | |
259 |
|
259 | |||
260 | class changelog(revlog.revlog): |
|
260 | class changelog(revlog.revlog): | |
261 | def __init__(self, opener): |
|
261 | def __init__(self, opener): | |
262 | revlog.revlog.__init__(self, opener, "00changelog.i", |
|
262 | revlog.revlog.__init__(self, opener, "00changelog.i", | |
263 | checkambig=True) |
|
263 | checkambig=True) | |
264 | if self._initempty: |
|
264 | if self._initempty: | |
265 | # changelogs don't benefit from generaldelta |
|
265 | # changelogs don't benefit from generaldelta | |
266 | self.version &= ~revlog.REVLOGGENERALDELTA |
|
266 | self.version &= ~revlog.REVLOGGENERALDELTA | |
267 | self._generaldelta = False |
|
267 | self._generaldelta = False | |
268 |
|
268 | |||
269 | # Delta chains for changelogs tend to be very small because entries |
|
269 | # Delta chains for changelogs tend to be very small because entries | |
270 | # tend to be small and don't delta well with each. So disable delta |
|
270 | # tend to be small and don't delta well with each. So disable delta | |
271 | # chains. |
|
271 | # chains. | |
272 | self.storedeltachains = False |
|
272 | self.storedeltachains = False | |
273 |
|
273 | |||
274 | self._realopener = opener |
|
274 | self._realopener = opener | |
275 | self._delayed = False |
|
275 | self._delayed = False | |
276 | self._delaybuf = None |
|
276 | self._delaybuf = None | |
277 | self._divert = False |
|
277 | self._divert = False | |
278 | self.filteredrevs = frozenset() |
|
278 | self.filteredrevs = frozenset() | |
279 |
|
279 | |||
280 | def tip(self): |
|
280 | def tip(self): | |
281 | """filtered version of revlog.tip""" |
|
281 | """filtered version of revlog.tip""" | |
282 | for i in xrange(len(self) -1, -2, -1): |
|
282 | for i in xrange(len(self) -1, -2, -1): | |
283 | if i not in self.filteredrevs: |
|
283 | if i not in self.filteredrevs: | |
284 | return self.node(i) |
|
284 | return self.node(i) | |
285 |
|
285 | |||
286 | def __contains__(self, rev): |
|
286 | def __contains__(self, rev): | |
287 | """filtered version of revlog.__contains__""" |
|
287 | """filtered version of revlog.__contains__""" | |
288 | return (0 <= rev < len(self) |
|
288 | return (0 <= rev < len(self) | |
289 | and rev not in self.filteredrevs) |
|
289 | and rev not in self.filteredrevs) | |
290 |
|
290 | |||
291 | def __iter__(self): |
|
291 | def __iter__(self): | |
292 | """filtered version of revlog.__iter__""" |
|
292 | """filtered version of revlog.__iter__""" | |
293 | if len(self.filteredrevs) == 0: |
|
293 | if len(self.filteredrevs) == 0: | |
294 | return revlog.revlog.__iter__(self) |
|
294 | return revlog.revlog.__iter__(self) | |
295 |
|
295 | |||
296 | def filterediter(): |
|
296 | def filterediter(): | |
297 | for i in xrange(len(self)): |
|
297 | for i in xrange(len(self)): | |
298 | if i not in self.filteredrevs: |
|
298 | if i not in self.filteredrevs: | |
299 | yield i |
|
299 | yield i | |
300 |
|
300 | |||
301 | return filterediter() |
|
301 | return filterediter() | |
302 |
|
302 | |||
303 | def revs(self, start=0, stop=None): |
|
303 | def revs(self, start=0, stop=None): | |
304 | """filtered version of revlog.revs""" |
|
304 | """filtered version of revlog.revs""" | |
305 | for i in super(changelog, self).revs(start, stop): |
|
305 | for i in super(changelog, self).revs(start, stop): | |
306 | if i not in self.filteredrevs: |
|
306 | if i not in self.filteredrevs: | |
307 | yield i |
|
307 | yield i | |
308 |
|
308 | |||
309 | @util.propertycache |
|
309 | @util.propertycache | |
310 | def nodemap(self): |
|
310 | def nodemap(self): | |
311 | # XXX need filtering too |
|
311 | # XXX need filtering too | |
312 | self.rev(self.node(0)) |
|
312 | self.rev(self.node(0)) | |
313 | return self._nodecache |
|
313 | return self._nodecache | |
314 |
|
314 | |||
315 | def reachableroots(self, minroot, heads, roots, includepath=False): |
|
315 | def reachableroots(self, minroot, heads, roots, includepath=False): | |
316 | return self.index.reachableroots2(minroot, heads, roots, includepath) |
|
316 | return self.index.reachableroots2(minroot, heads, roots, includepath) | |
317 |
|
317 | |||
318 | def headrevs(self): |
|
318 | def headrevs(self): | |
319 | if self.filteredrevs: |
|
319 | if self.filteredrevs: | |
320 | try: |
|
320 | try: | |
321 | return self.index.headrevsfiltered(self.filteredrevs) |
|
321 | return self.index.headrevsfiltered(self.filteredrevs) | |
322 | # AttributeError covers non-c-extension environments and |
|
322 | # AttributeError covers non-c-extension environments and | |
323 | # old c extensions without filter handling. |
|
323 | # old c extensions without filter handling. | |
324 | except AttributeError: |
|
324 | except AttributeError: | |
325 | return self._headrevs() |
|
325 | return self._headrevs() | |
326 |
|
326 | |||
327 | return super(changelog, self).headrevs() |
|
327 | return super(changelog, self).headrevs() | |
328 |
|
328 | |||
329 | def strip(self, *args, **kwargs): |
|
329 | def strip(self, *args, **kwargs): | |
330 | # XXX make something better than assert |
|
330 | # XXX make something better than assert | |
331 | # We can't expect proper strip behavior if we are filtered. |
|
331 | # We can't expect proper strip behavior if we are filtered. | |
332 | assert not self.filteredrevs |
|
332 | assert not self.filteredrevs | |
333 | super(changelog, self).strip(*args, **kwargs) |
|
333 | super(changelog, self).strip(*args, **kwargs) | |
334 |
|
334 | |||
335 | def rev(self, node): |
|
335 | def rev(self, node): | |
336 | """filtered version of revlog.rev""" |
|
336 | """filtered version of revlog.rev""" | |
337 | r = super(changelog, self).rev(node) |
|
337 | r = super(changelog, self).rev(node) | |
338 | if r in self.filteredrevs: |
|
338 | if r in self.filteredrevs: | |
339 | raise error.FilteredLookupError(hex(node), self.indexfile, |
|
339 | raise error.FilteredLookupError(hex(node), self.indexfile, | |
340 | _('filtered node')) |
|
340 | _('filtered node')) | |
341 | return r |
|
341 | return r | |
342 |
|
342 | |||
343 | def node(self, rev): |
|
343 | def node(self, rev): | |
344 | """filtered version of revlog.node""" |
|
344 | """filtered version of revlog.node""" | |
345 | if rev in self.filteredrevs: |
|
345 | if rev in self.filteredrevs: | |
346 | raise error.FilteredIndexError(rev) |
|
346 | raise error.FilteredIndexError(rev) | |
347 | return super(changelog, self).node(rev) |
|
347 | return super(changelog, self).node(rev) | |
348 |
|
348 | |||
349 | def linkrev(self, rev): |
|
349 | def linkrev(self, rev): | |
350 | """filtered version of revlog.linkrev""" |
|
350 | """filtered version of revlog.linkrev""" | |
351 | if rev in self.filteredrevs: |
|
351 | if rev in self.filteredrevs: | |
352 | raise error.FilteredIndexError(rev) |
|
352 | raise error.FilteredIndexError(rev) | |
353 | return super(changelog, self).linkrev(rev) |
|
353 | return super(changelog, self).linkrev(rev) | |
354 |
|
354 | |||
355 | def parentrevs(self, rev): |
|
355 | def parentrevs(self, rev): | |
356 | """filtered version of revlog.parentrevs""" |
|
356 | """filtered version of revlog.parentrevs""" | |
357 | if rev in self.filteredrevs: |
|
357 | if rev in self.filteredrevs: | |
358 | raise error.FilteredIndexError(rev) |
|
358 | raise error.FilteredIndexError(rev) | |
359 | return super(changelog, self).parentrevs(rev) |
|
359 | return super(changelog, self).parentrevs(rev) | |
360 |
|
360 | |||
361 | def flags(self, rev): |
|
361 | def flags(self, rev): | |
362 | """filtered version of revlog.flags""" |
|
362 | """filtered version of revlog.flags""" | |
363 | if rev in self.filteredrevs: |
|
363 | if rev in self.filteredrevs: | |
364 | raise error.FilteredIndexError(rev) |
|
364 | raise error.FilteredIndexError(rev) | |
365 | return super(changelog, self).flags(rev) |
|
365 | return super(changelog, self).flags(rev) | |
366 |
|
366 | |||
367 | def delayupdate(self, tr): |
|
367 | def delayupdate(self, tr): | |
368 | "delay visibility of index updates to other readers" |
|
368 | "delay visibility of index updates to other readers" | |
369 |
|
369 | |||
370 | if not self._delayed: |
|
370 | if not self._delayed: | |
371 | if len(self) == 0: |
|
371 | if len(self) == 0: | |
372 | self._divert = True |
|
372 | self._divert = True | |
373 | if self._realopener.exists(self.indexfile + '.a'): |
|
373 | if self._realopener.exists(self.indexfile + '.a'): | |
374 | self._realopener.unlink(self.indexfile + '.a') |
|
374 | self._realopener.unlink(self.indexfile + '.a') | |
375 | self.opener = _divertopener(self._realopener, self.indexfile) |
|
375 | self.opener = _divertopener(self._realopener, self.indexfile) | |
376 | else: |
|
376 | else: | |
377 | self._delaybuf = [] |
|
377 | self._delaybuf = [] | |
378 | self.opener = _delayopener(self._realopener, self.indexfile, |
|
378 | self.opener = _delayopener(self._realopener, self.indexfile, | |
379 | self._delaybuf) |
|
379 | self._delaybuf) | |
380 | self._delayed = True |
|
380 | self._delayed = True | |
381 | tr.addpending('cl-%i' % id(self), self._writepending) |
|
381 | tr.addpending('cl-%i' % id(self), self._writepending) | |
382 | tr.addfinalize('cl-%i' % id(self), self._finalize) |
|
382 | tr.addfinalize('cl-%i' % id(self), self._finalize) | |
383 |
|
383 | |||
384 | def _finalize(self, tr): |
|
384 | def _finalize(self, tr): | |
385 | "finalize index updates" |
|
385 | "finalize index updates" | |
386 | self._delayed = False |
|
386 | self._delayed = False | |
387 | self.opener = self._realopener |
|
387 | self.opener = self._realopener | |
388 | # move redirected index data back into place |
|
388 | # move redirected index data back into place | |
389 | if self._divert: |
|
389 | if self._divert: | |
390 | assert not self._delaybuf |
|
390 | assert not self._delaybuf | |
391 | tmpname = self.indexfile + ".a" |
|
391 | tmpname = self.indexfile + ".a" | |
392 | nfile = self.opener.open(tmpname) |
|
392 | nfile = self.opener.open(tmpname) | |
393 | nfile.close() |
|
393 | nfile.close() | |
394 | self.opener.rename(tmpname, self.indexfile, checkambig=True) |
|
394 | self.opener.rename(tmpname, self.indexfile, checkambig=True) | |
395 | elif self._delaybuf: |
|
395 | elif self._delaybuf: | |
396 | fp = self.opener(self.indexfile, 'a', checkambig=True) |
|
396 | fp = self.opener(self.indexfile, 'a', checkambig=True) | |
397 | fp.write("".join(self._delaybuf)) |
|
397 | fp.write("".join(self._delaybuf)) | |
398 | fp.close() |
|
398 | fp.close() | |
399 | self._delaybuf = None |
|
399 | self._delaybuf = None | |
400 | self._divert = False |
|
400 | self._divert = False | |
401 | # split when we're done |
|
401 | # split when we're done | |
402 | self.checkinlinesize(tr) |
|
402 | self.checkinlinesize(tr) | |
403 |
|
403 | |||
404 | def readpending(self, file): |
|
404 | def readpending(self, file): | |
405 | """read index data from a "pending" file |
|
405 | """read index data from a "pending" file | |
406 |
|
406 | |||
407 | During a transaction, the actual changeset data is already stored in the |
|
407 | During a transaction, the actual changeset data is already stored in the | |
408 | main file, but not yet finalized in the on-disk index. Instead, a |
|
408 | main file, but not yet finalized in the on-disk index. Instead, a | |
409 | "pending" index is written by the transaction logic. If this function |
|
409 | "pending" index is written by the transaction logic. If this function | |
410 | is running, we are likely in a subprocess invoked in a hook. The |
|
410 | is running, we are likely in a subprocess invoked in a hook. The | |
411 | subprocess is informed that it is within a transaction and needs to |
|
411 | subprocess is informed that it is within a transaction and needs to | |
412 | access its content. |
|
412 | access its content. | |
413 |
|
413 | |||
414 | This function will read all the index data out of the pending file and |
|
414 | This function will read all the index data out of the pending file and | |
415 | overwrite the main index.""" |
|
415 | overwrite the main index.""" | |
416 |
|
416 | |||
417 | if not self.opener.exists(file): |
|
417 | if not self.opener.exists(file): | |
418 | return # no pending data for changelog |
|
418 | return # no pending data for changelog | |
419 | r = revlog.revlog(self.opener, file) |
|
419 | r = revlog.revlog(self.opener, file) | |
420 | self.index = r.index |
|
420 | self.index = r.index | |
421 | self.nodemap = r.nodemap |
|
421 | self.nodemap = r.nodemap | |
422 | self._nodecache = r._nodecache |
|
422 | self._nodecache = r._nodecache | |
423 | self._chunkcache = r._chunkcache |
|
423 | self._chunkcache = r._chunkcache | |
424 |
|
424 | |||
425 | def _writepending(self, tr): |
|
425 | def _writepending(self, tr): | |
426 | "create a file containing the unfinalized state for pretxnchangegroup" |
|
426 | "create a file containing the unfinalized state for pretxnchangegroup" | |
427 | if self._delaybuf: |
|
427 | if self._delaybuf: | |
428 | # make a temporary copy of the index |
|
428 | # make a temporary copy of the index | |
429 | fp1 = self._realopener(self.indexfile) |
|
429 | fp1 = self._realopener(self.indexfile) | |
430 | pendingfilename = self.indexfile + ".a" |
|
430 | pendingfilename = self.indexfile + ".a" | |
431 | # register as a temp file to ensure cleanup on failure |
|
431 | # register as a temp file to ensure cleanup on failure | |
432 | tr.registertmp(pendingfilename) |
|
432 | tr.registertmp(pendingfilename) | |
433 | # write existing data |
|
433 | # write existing data | |
434 | fp2 = self._realopener(pendingfilename, "w") |
|
434 | fp2 = self._realopener(pendingfilename, "w") | |
435 | fp2.write(fp1.read()) |
|
435 | fp2.write(fp1.read()) | |
436 | # add pending data |
|
436 | # add pending data | |
437 | fp2.write("".join(self._delaybuf)) |
|
437 | fp2.write("".join(self._delaybuf)) | |
438 | fp2.close() |
|
438 | fp2.close() | |
439 | # switch modes so finalize can simply rename |
|
439 | # switch modes so finalize can simply rename | |
440 | self._delaybuf = None |
|
440 | self._delaybuf = None | |
441 | self._divert = True |
|
441 | self._divert = True | |
442 | self.opener = _divertopener(self._realopener, self.indexfile) |
|
442 | self.opener = _divertopener(self._realopener, self.indexfile) | |
443 |
|
443 | |||
444 | if self._divert: |
|
444 | if self._divert: | |
445 | return True |
|
445 | return True | |
446 |
|
446 | |||
447 | return False |
|
447 | return False | |
448 |
|
448 | |||
449 | def checkinlinesize(self, tr, fp=None): |
|
449 | def checkinlinesize(self, tr, fp=None): | |
450 | if not self._delayed: |
|
450 | if not self._delayed: | |
451 | revlog.revlog.checkinlinesize(self, tr, fp) |
|
451 | revlog.revlog.checkinlinesize(self, tr, fp) | |
452 |
|
452 | |||
453 | def read(self, node): |
|
453 | def read(self, node): | |
454 | """Obtain data from a parsed changelog revision. |
|
454 | """Obtain data from a parsed changelog revision. | |
455 |
|
455 | |||
456 | Returns a 6-tuple of: |
|
456 | Returns a 6-tuple of: | |
457 |
|
457 | |||
458 | - manifest node in binary |
|
458 | - manifest node in binary | |
459 | - author/user as a localstr |
|
459 | - author/user as a localstr | |
460 | - date as a 2-tuple of (time, timezone) |
|
460 | - date as a 2-tuple of (time, timezone) | |
461 | - list of files |
|
461 | - list of files | |
462 | - commit message as a localstr |
|
462 | - commit message as a localstr | |
463 | - dict of extra metadata |
|
463 | - dict of extra metadata | |
464 |
|
464 | |||
465 | Unless you need to access all fields, consider calling |
|
465 | Unless you need to access all fields, consider calling | |
466 | ``changelogrevision`` instead, as it is faster for partial object |
|
466 | ``changelogrevision`` instead, as it is faster for partial object | |
467 | access. |
|
467 | access. | |
468 | """ |
|
468 | """ | |
469 | c = changelogrevision(self.revision(node)) |
|
469 | c = changelogrevision(self.revision(node)) | |
470 | return ( |
|
470 | return ( | |
471 | c.manifest, |
|
471 | c.manifest, | |
472 | c.user, |
|
472 | c.user, | |
473 | c.date, |
|
473 | c.date, | |
474 | c.files, |
|
474 | c.files, | |
475 | c.description, |
|
475 | c.description, | |
476 | c.extra |
|
476 | c.extra | |
477 | ) |
|
477 | ) | |
478 |
|
478 | |||
479 | def changelogrevision(self, nodeorrev): |
|
479 | def changelogrevision(self, nodeorrev): | |
480 | """Obtain a ``changelogrevision`` for a node or revision.""" |
|
480 | """Obtain a ``changelogrevision`` for a node or revision.""" | |
481 | return changelogrevision(self.revision(nodeorrev)) |
|
481 | return changelogrevision(self.revision(nodeorrev)) | |
482 |
|
482 | |||
483 | def readfiles(self, node): |
|
483 | def readfiles(self, node): | |
484 | """ |
|
484 | """ | |
485 | short version of read that only returns the files modified by the cset |
|
485 | short version of read that only returns the files modified by the cset | |
486 | """ |
|
486 | """ | |
487 | text = self.revision(node) |
|
487 | text = self.revision(node) | |
488 | if not text: |
|
488 | if not text: | |
489 | return [] |
|
489 | return [] | |
490 | last = text.index("\n\n") |
|
490 | last = text.index("\n\n") | |
491 | l = text[:last].split('\n') |
|
491 | l = text[:last].split('\n') | |
492 | return l[3:] |
|
492 | return l[3:] | |
493 |
|
493 | |||
494 | def add(self, manifest, files, desc, transaction, p1, p2, |
|
494 | def add(self, manifest, files, desc, transaction, p1, p2, | |
495 | user, date=None, extra=None): |
|
495 | user, date=None, extra=None): | |
496 | # Convert to UTF-8 encoded bytestrings as the very first |
|
496 | # Convert to UTF-8 encoded bytestrings as the very first | |
497 | # thing: calling any method on a localstr object will turn it |
|
497 | # thing: calling any method on a localstr object will turn it | |
498 | # into a str object and the cached UTF-8 string is thus lost. |
|
498 | # into a str object and the cached UTF-8 string is thus lost. | |
499 | user, desc = encoding.fromlocal(user), encoding.fromlocal(desc) |
|
499 | user, desc = encoding.fromlocal(user), encoding.fromlocal(desc) | |
500 |
|
500 | |||
501 | user = user.strip() |
|
501 | user = user.strip() | |
502 | # An empty username or a username with a "\n" will make the |
|
502 | # An empty username or a username with a "\n" will make the | |
503 | # revision text contain two "\n\n" sequences -> corrupt |
|
503 | # revision text contain two "\n\n" sequences -> corrupt | |
504 | # repository since read cannot unpack the revision. |
|
504 | # repository since read cannot unpack the revision. | |
505 | if not user: |
|
505 | if not user: | |
506 | raise error.RevlogError(_("empty username")) |
|
506 | raise error.RevlogError(_("empty username")) | |
507 | if "\n" in user: |
|
507 | if "\n" in user: | |
508 | raise error.RevlogError(_("username %s contains a newline") |
|
508 | raise error.RevlogError(_("username %s contains a newline") | |
509 | % repr(user)) |
|
509 | % repr(user)) | |
510 |
|
510 | |||
511 | desc = stripdesc(desc) |
|
511 | desc = stripdesc(desc) | |
512 |
|
512 | |||
513 | if date: |
|
513 | if date: | |
514 | parseddate = "%d %d" % util.parsedate(date) |
|
514 | parseddate = "%d %d" % util.parsedate(date) | |
515 | else: |
|
515 | else: | |
516 | parseddate = "%d %d" % util.makedate() |
|
516 | parseddate = "%d %d" % util.makedate() | |
517 | if extra: |
|
517 | if extra: | |
518 | branch = extra.get("branch") |
|
518 | branch = extra.get("branch") | |
519 | if branch in ("default", ""): |
|
519 | if branch in ("default", ""): | |
520 | del extra["branch"] |
|
520 | del extra["branch"] | |
521 | elif branch in (".", "null", "tip"): |
|
521 | elif branch in (".", "null", "tip"): | |
522 | raise error.RevlogError(_('the name \'%s\' is reserved') |
|
522 | raise error.RevlogError(_('the name \'%s\' is reserved') | |
523 | % branch) |
|
523 | % branch) | |
524 | if extra: |
|
524 | if extra: | |
525 | extra = encodeextra(extra) |
|
525 | extra = encodeextra(extra) | |
526 | parseddate = "%s %s" % (parseddate, extra) |
|
526 | parseddate = "%s %s" % (parseddate, extra) | |
527 | l = [hex(manifest), user, parseddate] + sorted(files) + ["", desc] |
|
527 | l = [hex(manifest), user, parseddate] + sorted(files) + ["", desc] | |
528 | text = "\n".join(l) |
|
528 | text = "\n".join(l) | |
529 | return self.addrevision(text, transaction, len(self), p1, p2) |
|
529 | return self.addrevision(text, transaction, len(self), p1, p2) | |
530 |
|
530 | |||
531 | def branchinfo(self, rev): |
|
531 | def branchinfo(self, rev): | |
532 | """return the branch name and open/close state of a revision |
|
532 | """return the branch name and open/close state of a revision | |
533 |
|
533 | |||
534 | This function exists because creating a changectx object |
|
534 | This function exists because creating a changectx object | |
535 | just to access this is costly.""" |
|
535 | just to access this is costly.""" | |
536 | extra = self.read(rev)[5] |
|
536 | extra = self.read(rev)[5] | |
537 | return encoding.tolocal(extra.get("branch")), 'close' in extra |
|
537 | return encoding.tolocal(extra.get("branch")), 'close' in extra | |
|
538 | ||||
|
539 | def _addrevision(self, node, rawtext, transaction, *args, **kwargs): | |||
|
540 | # overlay over the standard revlog._addrevision to track the new | |||
|
541 | # revision on the transaction. | |||
|
542 | rev = len(self) | |||
|
543 | node = super(changelog, self)._addrevision(node, rawtext, transaction, | |||
|
544 | *args, **kwargs) | |||
|
545 | revs = transaction.changes.get('revs') | |||
|
546 | if revs is not None: | |||
|
547 | revs.add(rev) | |||
|
548 | return node |
@@ -1,2030 +1,2031 b'' | |||||
1 | # localrepo.py - read/write repository class for mercurial |
|
1 | # localrepo.py - read/write repository class for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms of the |
|
5 | # This software may be used and distributed according to the terms of the | |
6 | # GNU General Public License version 2 or any later version. |
|
6 | # GNU General Public License version 2 or any later version. | |
7 |
|
7 | |||
8 | from __future__ import absolute_import |
|
8 | from __future__ import absolute_import | |
9 |
|
9 | |||
10 | import errno |
|
10 | import errno | |
11 | import hashlib |
|
11 | import hashlib | |
12 | import inspect |
|
12 | import inspect | |
13 | import os |
|
13 | import os | |
14 | import random |
|
14 | import random | |
15 | import time |
|
15 | import time | |
16 | import weakref |
|
16 | import weakref | |
17 |
|
17 | |||
18 | from .i18n import _ |
|
18 | from .i18n import _ | |
19 | from .node import ( |
|
19 | from .node import ( | |
20 | hex, |
|
20 | hex, | |
21 | nullid, |
|
21 | nullid, | |
22 | short, |
|
22 | short, | |
23 | wdirrev, |
|
23 | wdirrev, | |
24 | ) |
|
24 | ) | |
25 | from . import ( |
|
25 | from . import ( | |
26 | bookmarks, |
|
26 | bookmarks, | |
27 | branchmap, |
|
27 | branchmap, | |
28 | bundle2, |
|
28 | bundle2, | |
29 | changegroup, |
|
29 | changegroup, | |
30 | changelog, |
|
30 | changelog, | |
31 | color, |
|
31 | color, | |
32 | context, |
|
32 | context, | |
33 | dirstate, |
|
33 | dirstate, | |
34 | dirstateguard, |
|
34 | dirstateguard, | |
35 | encoding, |
|
35 | encoding, | |
36 | error, |
|
36 | error, | |
37 | exchange, |
|
37 | exchange, | |
38 | extensions, |
|
38 | extensions, | |
39 | filelog, |
|
39 | filelog, | |
40 | hook, |
|
40 | hook, | |
41 | lock as lockmod, |
|
41 | lock as lockmod, | |
42 | manifest, |
|
42 | manifest, | |
43 | match as matchmod, |
|
43 | match as matchmod, | |
44 | merge as mergemod, |
|
44 | merge as mergemod, | |
45 | mergeutil, |
|
45 | mergeutil, | |
46 | namespaces, |
|
46 | namespaces, | |
47 | obsolete, |
|
47 | obsolete, | |
48 | pathutil, |
|
48 | pathutil, | |
49 | peer, |
|
49 | peer, | |
50 | phases, |
|
50 | phases, | |
51 | pushkey, |
|
51 | pushkey, | |
52 | pycompat, |
|
52 | pycompat, | |
53 | repoview, |
|
53 | repoview, | |
54 | revset, |
|
54 | revset, | |
55 | revsetlang, |
|
55 | revsetlang, | |
56 | scmutil, |
|
56 | scmutil, | |
57 | store, |
|
57 | store, | |
58 | subrepo, |
|
58 | subrepo, | |
59 | tags as tagsmod, |
|
59 | tags as tagsmod, | |
60 | transaction, |
|
60 | transaction, | |
61 | txnutil, |
|
61 | txnutil, | |
62 | util, |
|
62 | util, | |
63 | vfs as vfsmod, |
|
63 | vfs as vfsmod, | |
64 | ) |
|
64 | ) | |
65 |
|
65 | |||
66 | release = lockmod.release |
|
66 | release = lockmod.release | |
67 | urlerr = util.urlerr |
|
67 | urlerr = util.urlerr | |
68 | urlreq = util.urlreq |
|
68 | urlreq = util.urlreq | |
69 |
|
69 | |||
70 | class repofilecache(scmutil.filecache): |
|
70 | class repofilecache(scmutil.filecache): | |
71 | """All filecache usage on repo are done for logic that should be unfiltered |
|
71 | """All filecache usage on repo are done for logic that should be unfiltered | |
72 | """ |
|
72 | """ | |
73 |
|
73 | |||
74 | def join(self, obj, fname): |
|
74 | def join(self, obj, fname): | |
75 | return obj.vfs.join(fname) |
|
75 | return obj.vfs.join(fname) | |
76 | def __get__(self, repo, type=None): |
|
76 | def __get__(self, repo, type=None): | |
77 | if repo is None: |
|
77 | if repo is None: | |
78 | return self |
|
78 | return self | |
79 | return super(repofilecache, self).__get__(repo.unfiltered(), type) |
|
79 | return super(repofilecache, self).__get__(repo.unfiltered(), type) | |
80 | def __set__(self, repo, value): |
|
80 | def __set__(self, repo, value): | |
81 | return super(repofilecache, self).__set__(repo.unfiltered(), value) |
|
81 | return super(repofilecache, self).__set__(repo.unfiltered(), value) | |
82 | def __delete__(self, repo): |
|
82 | def __delete__(self, repo): | |
83 | return super(repofilecache, self).__delete__(repo.unfiltered()) |
|
83 | return super(repofilecache, self).__delete__(repo.unfiltered()) | |
84 |
|
84 | |||
85 | class storecache(repofilecache): |
|
85 | class storecache(repofilecache): | |
86 | """filecache for files in the store""" |
|
86 | """filecache for files in the store""" | |
87 | def join(self, obj, fname): |
|
87 | def join(self, obj, fname): | |
88 | return obj.sjoin(fname) |
|
88 | return obj.sjoin(fname) | |
89 |
|
89 | |||
90 | class unfilteredpropertycache(util.propertycache): |
|
90 | class unfilteredpropertycache(util.propertycache): | |
91 | """propertycache that apply to unfiltered repo only""" |
|
91 | """propertycache that apply to unfiltered repo only""" | |
92 |
|
92 | |||
93 | def __get__(self, repo, type=None): |
|
93 | def __get__(self, repo, type=None): | |
94 | unfi = repo.unfiltered() |
|
94 | unfi = repo.unfiltered() | |
95 | if unfi is repo: |
|
95 | if unfi is repo: | |
96 | return super(unfilteredpropertycache, self).__get__(unfi) |
|
96 | return super(unfilteredpropertycache, self).__get__(unfi) | |
97 | return getattr(unfi, self.name) |
|
97 | return getattr(unfi, self.name) | |
98 |
|
98 | |||
99 | class filteredpropertycache(util.propertycache): |
|
99 | class filteredpropertycache(util.propertycache): | |
100 | """propertycache that must take filtering in account""" |
|
100 | """propertycache that must take filtering in account""" | |
101 |
|
101 | |||
102 | def cachevalue(self, obj, value): |
|
102 | def cachevalue(self, obj, value): | |
103 | object.__setattr__(obj, self.name, value) |
|
103 | object.__setattr__(obj, self.name, value) | |
104 |
|
104 | |||
105 |
|
105 | |||
106 | def hasunfilteredcache(repo, name): |
|
106 | def hasunfilteredcache(repo, name): | |
107 | """check if a repo has an unfilteredpropertycache value for <name>""" |
|
107 | """check if a repo has an unfilteredpropertycache value for <name>""" | |
108 | return name in vars(repo.unfiltered()) |
|
108 | return name in vars(repo.unfiltered()) | |
109 |
|
109 | |||
110 | def unfilteredmethod(orig): |
|
110 | def unfilteredmethod(orig): | |
111 | """decorate method that always need to be run on unfiltered version""" |
|
111 | """decorate method that always need to be run on unfiltered version""" | |
112 | def wrapper(repo, *args, **kwargs): |
|
112 | def wrapper(repo, *args, **kwargs): | |
113 | return orig(repo.unfiltered(), *args, **kwargs) |
|
113 | return orig(repo.unfiltered(), *args, **kwargs) | |
114 | return wrapper |
|
114 | return wrapper | |
115 |
|
115 | |||
116 | moderncaps = set(('lookup', 'branchmap', 'pushkey', 'known', 'getbundle', |
|
116 | moderncaps = set(('lookup', 'branchmap', 'pushkey', 'known', 'getbundle', | |
117 | 'unbundle')) |
|
117 | 'unbundle')) | |
118 | legacycaps = moderncaps.union(set(['changegroupsubset'])) |
|
118 | legacycaps = moderncaps.union(set(['changegroupsubset'])) | |
119 |
|
119 | |||
120 | class localpeer(peer.peerrepository): |
|
120 | class localpeer(peer.peerrepository): | |
121 | '''peer for a local repo; reflects only the most recent API''' |
|
121 | '''peer for a local repo; reflects only the most recent API''' | |
122 |
|
122 | |||
123 | def __init__(self, repo, caps=None): |
|
123 | def __init__(self, repo, caps=None): | |
124 | if caps is None: |
|
124 | if caps is None: | |
125 | caps = moderncaps.copy() |
|
125 | caps = moderncaps.copy() | |
126 | peer.peerrepository.__init__(self) |
|
126 | peer.peerrepository.__init__(self) | |
127 | self._repo = repo.filtered('served') |
|
127 | self._repo = repo.filtered('served') | |
128 | self.ui = repo.ui |
|
128 | self.ui = repo.ui | |
129 | self._caps = repo._restrictcapabilities(caps) |
|
129 | self._caps = repo._restrictcapabilities(caps) | |
130 | self.requirements = repo.requirements |
|
130 | self.requirements = repo.requirements | |
131 | self.supportedformats = repo.supportedformats |
|
131 | self.supportedformats = repo.supportedformats | |
132 |
|
132 | |||
133 | def close(self): |
|
133 | def close(self): | |
134 | self._repo.close() |
|
134 | self._repo.close() | |
135 |
|
135 | |||
136 | def _capabilities(self): |
|
136 | def _capabilities(self): | |
137 | return self._caps |
|
137 | return self._caps | |
138 |
|
138 | |||
139 | def local(self): |
|
139 | def local(self): | |
140 | return self._repo |
|
140 | return self._repo | |
141 |
|
141 | |||
142 | def canpush(self): |
|
142 | def canpush(self): | |
143 | return True |
|
143 | return True | |
144 |
|
144 | |||
145 | def url(self): |
|
145 | def url(self): | |
146 | return self._repo.url() |
|
146 | return self._repo.url() | |
147 |
|
147 | |||
148 | def lookup(self, key): |
|
148 | def lookup(self, key): | |
149 | return self._repo.lookup(key) |
|
149 | return self._repo.lookup(key) | |
150 |
|
150 | |||
151 | def branchmap(self): |
|
151 | def branchmap(self): | |
152 | return self._repo.branchmap() |
|
152 | return self._repo.branchmap() | |
153 |
|
153 | |||
154 | def heads(self): |
|
154 | def heads(self): | |
155 | return self._repo.heads() |
|
155 | return self._repo.heads() | |
156 |
|
156 | |||
157 | def known(self, nodes): |
|
157 | def known(self, nodes): | |
158 | return self._repo.known(nodes) |
|
158 | return self._repo.known(nodes) | |
159 |
|
159 | |||
160 | def getbundle(self, source, heads=None, common=None, bundlecaps=None, |
|
160 | def getbundle(self, source, heads=None, common=None, bundlecaps=None, | |
161 | **kwargs): |
|
161 | **kwargs): | |
162 | chunks = exchange.getbundlechunks(self._repo, source, heads=heads, |
|
162 | chunks = exchange.getbundlechunks(self._repo, source, heads=heads, | |
163 | common=common, bundlecaps=bundlecaps, |
|
163 | common=common, bundlecaps=bundlecaps, | |
164 | **kwargs) |
|
164 | **kwargs) | |
165 | cb = util.chunkbuffer(chunks) |
|
165 | cb = util.chunkbuffer(chunks) | |
166 |
|
166 | |||
167 | if exchange.bundle2requested(bundlecaps): |
|
167 | if exchange.bundle2requested(bundlecaps): | |
168 | # When requesting a bundle2, getbundle returns a stream to make the |
|
168 | # When requesting a bundle2, getbundle returns a stream to make the | |
169 | # wire level function happier. We need to build a proper object |
|
169 | # wire level function happier. We need to build a proper object | |
170 | # from it in local peer. |
|
170 | # from it in local peer. | |
171 | return bundle2.getunbundler(self.ui, cb) |
|
171 | return bundle2.getunbundler(self.ui, cb) | |
172 | else: |
|
172 | else: | |
173 | return changegroup.getunbundler('01', cb, None) |
|
173 | return changegroup.getunbundler('01', cb, None) | |
174 |
|
174 | |||
175 | # TODO We might want to move the next two calls into legacypeer and add |
|
175 | # TODO We might want to move the next two calls into legacypeer and add | |
176 | # unbundle instead. |
|
176 | # unbundle instead. | |
177 |
|
177 | |||
178 | def unbundle(self, cg, heads, url): |
|
178 | def unbundle(self, cg, heads, url): | |
179 | """apply a bundle on a repo |
|
179 | """apply a bundle on a repo | |
180 |
|
180 | |||
181 | This function handles the repo locking itself.""" |
|
181 | This function handles the repo locking itself.""" | |
182 | try: |
|
182 | try: | |
183 | try: |
|
183 | try: | |
184 | cg = exchange.readbundle(self.ui, cg, None) |
|
184 | cg = exchange.readbundle(self.ui, cg, None) | |
185 | ret = exchange.unbundle(self._repo, cg, heads, 'push', url) |
|
185 | ret = exchange.unbundle(self._repo, cg, heads, 'push', url) | |
186 | if util.safehasattr(ret, 'getchunks'): |
|
186 | if util.safehasattr(ret, 'getchunks'): | |
187 | # This is a bundle20 object, turn it into an unbundler. |
|
187 | # This is a bundle20 object, turn it into an unbundler. | |
188 | # This little dance should be dropped eventually when the |
|
188 | # This little dance should be dropped eventually when the | |
189 | # API is finally improved. |
|
189 | # API is finally improved. | |
190 | stream = util.chunkbuffer(ret.getchunks()) |
|
190 | stream = util.chunkbuffer(ret.getchunks()) | |
191 | ret = bundle2.getunbundler(self.ui, stream) |
|
191 | ret = bundle2.getunbundler(self.ui, stream) | |
192 | return ret |
|
192 | return ret | |
193 | except Exception as exc: |
|
193 | except Exception as exc: | |
194 | # If the exception contains output salvaged from a bundle2 |
|
194 | # If the exception contains output salvaged from a bundle2 | |
195 | # reply, we need to make sure it is printed before continuing |
|
195 | # reply, we need to make sure it is printed before continuing | |
196 | # to fail. So we build a bundle2 with such output and consume |
|
196 | # to fail. So we build a bundle2 with such output and consume | |
197 | # it directly. |
|
197 | # it directly. | |
198 | # |
|
198 | # | |
199 | # This is not very elegant but allows a "simple" solution for |
|
199 | # This is not very elegant but allows a "simple" solution for | |
200 | # issue4594 |
|
200 | # issue4594 | |
201 | output = getattr(exc, '_bundle2salvagedoutput', ()) |
|
201 | output = getattr(exc, '_bundle2salvagedoutput', ()) | |
202 | if output: |
|
202 | if output: | |
203 | bundler = bundle2.bundle20(self._repo.ui) |
|
203 | bundler = bundle2.bundle20(self._repo.ui) | |
204 | for out in output: |
|
204 | for out in output: | |
205 | bundler.addpart(out) |
|
205 | bundler.addpart(out) | |
206 | stream = util.chunkbuffer(bundler.getchunks()) |
|
206 | stream = util.chunkbuffer(bundler.getchunks()) | |
207 | b = bundle2.getunbundler(self.ui, stream) |
|
207 | b = bundle2.getunbundler(self.ui, stream) | |
208 | bundle2.processbundle(self._repo, b) |
|
208 | bundle2.processbundle(self._repo, b) | |
209 | raise |
|
209 | raise | |
210 | except error.PushRaced as exc: |
|
210 | except error.PushRaced as exc: | |
211 | raise error.ResponseError(_('push failed:'), str(exc)) |
|
211 | raise error.ResponseError(_('push failed:'), str(exc)) | |
212 |
|
212 | |||
213 | def lock(self): |
|
213 | def lock(self): | |
214 | return self._repo.lock() |
|
214 | return self._repo.lock() | |
215 |
|
215 | |||
216 | def addchangegroup(self, cg, source, url): |
|
216 | def addchangegroup(self, cg, source, url): | |
217 | return cg.apply(self._repo, source, url) |
|
217 | return cg.apply(self._repo, source, url) | |
218 |
|
218 | |||
219 | def pushkey(self, namespace, key, old, new): |
|
219 | def pushkey(self, namespace, key, old, new): | |
220 | return self._repo.pushkey(namespace, key, old, new) |
|
220 | return self._repo.pushkey(namespace, key, old, new) | |
221 |
|
221 | |||
222 | def listkeys(self, namespace): |
|
222 | def listkeys(self, namespace): | |
223 | return self._repo.listkeys(namespace) |
|
223 | return self._repo.listkeys(namespace) | |
224 |
|
224 | |||
225 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
225 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
226 | '''used to test argument passing over the wire''' |
|
226 | '''used to test argument passing over the wire''' | |
227 | return "%s %s %s %s %s" % (one, two, three, four, five) |
|
227 | return "%s %s %s %s %s" % (one, two, three, four, five) | |
228 |
|
228 | |||
229 | class locallegacypeer(localpeer): |
|
229 | class locallegacypeer(localpeer): | |
230 | '''peer extension which implements legacy methods too; used for tests with |
|
230 | '''peer extension which implements legacy methods too; used for tests with | |
231 | restricted capabilities''' |
|
231 | restricted capabilities''' | |
232 |
|
232 | |||
233 | def __init__(self, repo): |
|
233 | def __init__(self, repo): | |
234 | localpeer.__init__(self, repo, caps=legacycaps) |
|
234 | localpeer.__init__(self, repo, caps=legacycaps) | |
235 |
|
235 | |||
236 | def branches(self, nodes): |
|
236 | def branches(self, nodes): | |
237 | return self._repo.branches(nodes) |
|
237 | return self._repo.branches(nodes) | |
238 |
|
238 | |||
239 | def between(self, pairs): |
|
239 | def between(self, pairs): | |
240 | return self._repo.between(pairs) |
|
240 | return self._repo.between(pairs) | |
241 |
|
241 | |||
242 | def changegroup(self, basenodes, source): |
|
242 | def changegroup(self, basenodes, source): | |
243 | return changegroup.changegroup(self._repo, basenodes, source) |
|
243 | return changegroup.changegroup(self._repo, basenodes, source) | |
244 |
|
244 | |||
245 | def changegroupsubset(self, bases, heads, source): |
|
245 | def changegroupsubset(self, bases, heads, source): | |
246 | return changegroup.changegroupsubset(self._repo, bases, heads, source) |
|
246 | return changegroup.changegroupsubset(self._repo, bases, heads, source) | |
247 |
|
247 | |||
248 | class localrepository(object): |
|
248 | class localrepository(object): | |
249 |
|
249 | |||
250 | supportedformats = set(('revlogv1', 'generaldelta', 'treemanifest', |
|
250 | supportedformats = set(('revlogv1', 'generaldelta', 'treemanifest', | |
251 | 'manifestv2')) |
|
251 | 'manifestv2')) | |
252 | _basesupported = supportedformats | set(('store', 'fncache', 'shared', |
|
252 | _basesupported = supportedformats | set(('store', 'fncache', 'shared', | |
253 | 'relshared', 'dotencode')) |
|
253 | 'relshared', 'dotencode')) | |
254 | openerreqs = set(('revlogv1', 'generaldelta', 'treemanifest', 'manifestv2')) |
|
254 | openerreqs = set(('revlogv1', 'generaldelta', 'treemanifest', 'manifestv2')) | |
255 | filtername = None |
|
255 | filtername = None | |
256 |
|
256 | |||
257 | # a list of (ui, featureset) functions. |
|
257 | # a list of (ui, featureset) functions. | |
258 | # only functions defined in module of enabled extensions are invoked |
|
258 | # only functions defined in module of enabled extensions are invoked | |
259 | featuresetupfuncs = set() |
|
259 | featuresetupfuncs = set() | |
260 |
|
260 | |||
261 | def __init__(self, baseui, path, create=False): |
|
261 | def __init__(self, baseui, path, create=False): | |
262 | self.requirements = set() |
|
262 | self.requirements = set() | |
263 | # wvfs: rooted at the repository root, used to access the working copy |
|
263 | # wvfs: rooted at the repository root, used to access the working copy | |
264 | self.wvfs = vfsmod.vfs(path, expandpath=True, realpath=True) |
|
264 | self.wvfs = vfsmod.vfs(path, expandpath=True, realpath=True) | |
265 | # vfs: rooted at .hg, used to access repo files outside of .hg/store |
|
265 | # vfs: rooted at .hg, used to access repo files outside of .hg/store | |
266 | self.vfs = None |
|
266 | self.vfs = None | |
267 | # svfs: usually rooted at .hg/store, used to access repository history |
|
267 | # svfs: usually rooted at .hg/store, used to access repository history | |
268 | # If this is a shared repository, this vfs may point to another |
|
268 | # If this is a shared repository, this vfs may point to another | |
269 | # repository's .hg/store directory. |
|
269 | # repository's .hg/store directory. | |
270 | self.svfs = None |
|
270 | self.svfs = None | |
271 | self.root = self.wvfs.base |
|
271 | self.root = self.wvfs.base | |
272 | self.path = self.wvfs.join(".hg") |
|
272 | self.path = self.wvfs.join(".hg") | |
273 | self.origroot = path |
|
273 | self.origroot = path | |
274 | self.auditor = pathutil.pathauditor(self.root, self._checknested) |
|
274 | self.auditor = pathutil.pathauditor(self.root, self._checknested) | |
275 | self.nofsauditor = pathutil.pathauditor(self.root, self._checknested, |
|
275 | self.nofsauditor = pathutil.pathauditor(self.root, self._checknested, | |
276 | realfs=False) |
|
276 | realfs=False) | |
277 | self.vfs = vfsmod.vfs(self.path) |
|
277 | self.vfs = vfsmod.vfs(self.path) | |
278 | self.baseui = baseui |
|
278 | self.baseui = baseui | |
279 | self.ui = baseui.copy() |
|
279 | self.ui = baseui.copy() | |
280 | self.ui.copy = baseui.copy # prevent copying repo configuration |
|
280 | self.ui.copy = baseui.copy # prevent copying repo configuration | |
281 | # A list of callback to shape the phase if no data were found. |
|
281 | # A list of callback to shape the phase if no data were found. | |
282 | # Callback are in the form: func(repo, roots) --> processed root. |
|
282 | # Callback are in the form: func(repo, roots) --> processed root. | |
283 | # This list it to be filled by extension during repo setup |
|
283 | # This list it to be filled by extension during repo setup | |
284 | self._phasedefaults = [] |
|
284 | self._phasedefaults = [] | |
285 | try: |
|
285 | try: | |
286 | self.ui.readconfig(self.vfs.join("hgrc"), self.root) |
|
286 | self.ui.readconfig(self.vfs.join("hgrc"), self.root) | |
287 | self._loadextensions() |
|
287 | self._loadextensions() | |
288 | except IOError: |
|
288 | except IOError: | |
289 | pass |
|
289 | pass | |
290 |
|
290 | |||
291 | if self.featuresetupfuncs: |
|
291 | if self.featuresetupfuncs: | |
292 | self.supported = set(self._basesupported) # use private copy |
|
292 | self.supported = set(self._basesupported) # use private copy | |
293 | extmods = set(m.__name__ for n, m |
|
293 | extmods = set(m.__name__ for n, m | |
294 | in extensions.extensions(self.ui)) |
|
294 | in extensions.extensions(self.ui)) | |
295 | for setupfunc in self.featuresetupfuncs: |
|
295 | for setupfunc in self.featuresetupfuncs: | |
296 | if setupfunc.__module__ in extmods: |
|
296 | if setupfunc.__module__ in extmods: | |
297 | setupfunc(self.ui, self.supported) |
|
297 | setupfunc(self.ui, self.supported) | |
298 | else: |
|
298 | else: | |
299 | self.supported = self._basesupported |
|
299 | self.supported = self._basesupported | |
300 | color.setup(self.ui) |
|
300 | color.setup(self.ui) | |
301 |
|
301 | |||
302 | # Add compression engines. |
|
302 | # Add compression engines. | |
303 | for name in util.compengines: |
|
303 | for name in util.compengines: | |
304 | engine = util.compengines[name] |
|
304 | engine = util.compengines[name] | |
305 | if engine.revlogheader(): |
|
305 | if engine.revlogheader(): | |
306 | self.supported.add('exp-compression-%s' % name) |
|
306 | self.supported.add('exp-compression-%s' % name) | |
307 |
|
307 | |||
308 | if not self.vfs.isdir(): |
|
308 | if not self.vfs.isdir(): | |
309 | if create: |
|
309 | if create: | |
310 | self.requirements = newreporequirements(self) |
|
310 | self.requirements = newreporequirements(self) | |
311 |
|
311 | |||
312 | if not self.wvfs.exists(): |
|
312 | if not self.wvfs.exists(): | |
313 | self.wvfs.makedirs() |
|
313 | self.wvfs.makedirs() | |
314 | self.vfs.makedir(notindexed=True) |
|
314 | self.vfs.makedir(notindexed=True) | |
315 |
|
315 | |||
316 | if 'store' in self.requirements: |
|
316 | if 'store' in self.requirements: | |
317 | self.vfs.mkdir("store") |
|
317 | self.vfs.mkdir("store") | |
318 |
|
318 | |||
319 | # create an invalid changelog |
|
319 | # create an invalid changelog | |
320 | self.vfs.append( |
|
320 | self.vfs.append( | |
321 | "00changelog.i", |
|
321 | "00changelog.i", | |
322 | '\0\0\0\2' # represents revlogv2 |
|
322 | '\0\0\0\2' # represents revlogv2 | |
323 | ' dummy changelog to prevent using the old repo layout' |
|
323 | ' dummy changelog to prevent using the old repo layout' | |
324 | ) |
|
324 | ) | |
325 | else: |
|
325 | else: | |
326 | raise error.RepoError(_("repository %s not found") % path) |
|
326 | raise error.RepoError(_("repository %s not found") % path) | |
327 | elif create: |
|
327 | elif create: | |
328 | raise error.RepoError(_("repository %s already exists") % path) |
|
328 | raise error.RepoError(_("repository %s already exists") % path) | |
329 | else: |
|
329 | else: | |
330 | try: |
|
330 | try: | |
331 | self.requirements = scmutil.readrequires( |
|
331 | self.requirements = scmutil.readrequires( | |
332 | self.vfs, self.supported) |
|
332 | self.vfs, self.supported) | |
333 | except IOError as inst: |
|
333 | except IOError as inst: | |
334 | if inst.errno != errno.ENOENT: |
|
334 | if inst.errno != errno.ENOENT: | |
335 | raise |
|
335 | raise | |
336 |
|
336 | |||
337 | self.sharedpath = self.path |
|
337 | self.sharedpath = self.path | |
338 | try: |
|
338 | try: | |
339 | sharedpath = self.vfs.read("sharedpath").rstrip('\n') |
|
339 | sharedpath = self.vfs.read("sharedpath").rstrip('\n') | |
340 | if 'relshared' in self.requirements: |
|
340 | if 'relshared' in self.requirements: | |
341 | sharedpath = self.vfs.join(sharedpath) |
|
341 | sharedpath = self.vfs.join(sharedpath) | |
342 | vfs = vfsmod.vfs(sharedpath, realpath=True) |
|
342 | vfs = vfsmod.vfs(sharedpath, realpath=True) | |
343 | s = vfs.base |
|
343 | s = vfs.base | |
344 | if not vfs.exists(): |
|
344 | if not vfs.exists(): | |
345 | raise error.RepoError( |
|
345 | raise error.RepoError( | |
346 | _('.hg/sharedpath points to nonexistent directory %s') % s) |
|
346 | _('.hg/sharedpath points to nonexistent directory %s') % s) | |
347 | self.sharedpath = s |
|
347 | self.sharedpath = s | |
348 | except IOError as inst: |
|
348 | except IOError as inst: | |
349 | if inst.errno != errno.ENOENT: |
|
349 | if inst.errno != errno.ENOENT: | |
350 | raise |
|
350 | raise | |
351 |
|
351 | |||
352 | self.store = store.store( |
|
352 | self.store = store.store( | |
353 | self.requirements, self.sharedpath, vfsmod.vfs) |
|
353 | self.requirements, self.sharedpath, vfsmod.vfs) | |
354 | self.spath = self.store.path |
|
354 | self.spath = self.store.path | |
355 | self.svfs = self.store.vfs |
|
355 | self.svfs = self.store.vfs | |
356 | self.sjoin = self.store.join |
|
356 | self.sjoin = self.store.join | |
357 | self.vfs.createmode = self.store.createmode |
|
357 | self.vfs.createmode = self.store.createmode | |
358 | self._applyopenerreqs() |
|
358 | self._applyopenerreqs() | |
359 | if create: |
|
359 | if create: | |
360 | self._writerequirements() |
|
360 | self._writerequirements() | |
361 |
|
361 | |||
362 | self._dirstatevalidatewarned = False |
|
362 | self._dirstatevalidatewarned = False | |
363 |
|
363 | |||
364 | self._branchcaches = {} |
|
364 | self._branchcaches = {} | |
365 | self._revbranchcache = None |
|
365 | self._revbranchcache = None | |
366 | self.filterpats = {} |
|
366 | self.filterpats = {} | |
367 | self._datafilters = {} |
|
367 | self._datafilters = {} | |
368 | self._transref = self._lockref = self._wlockref = None |
|
368 | self._transref = self._lockref = self._wlockref = None | |
369 |
|
369 | |||
370 | # A cache for various files under .hg/ that tracks file changes, |
|
370 | # A cache for various files under .hg/ that tracks file changes, | |
371 | # (used by the filecache decorator) |
|
371 | # (used by the filecache decorator) | |
372 | # |
|
372 | # | |
373 | # Maps a property name to its util.filecacheentry |
|
373 | # Maps a property name to its util.filecacheentry | |
374 | self._filecache = {} |
|
374 | self._filecache = {} | |
375 |
|
375 | |||
376 | # hold sets of revision to be filtered |
|
376 | # hold sets of revision to be filtered | |
377 | # should be cleared when something might have changed the filter value: |
|
377 | # should be cleared when something might have changed the filter value: | |
378 | # - new changesets, |
|
378 | # - new changesets, | |
379 | # - phase change, |
|
379 | # - phase change, | |
380 | # - new obsolescence marker, |
|
380 | # - new obsolescence marker, | |
381 | # - working directory parent change, |
|
381 | # - working directory parent change, | |
382 | # - bookmark changes |
|
382 | # - bookmark changes | |
383 | self.filteredrevcache = {} |
|
383 | self.filteredrevcache = {} | |
384 |
|
384 | |||
385 | # generic mapping between names and nodes |
|
385 | # generic mapping between names and nodes | |
386 | self.names = namespaces.namespaces() |
|
386 | self.names = namespaces.namespaces() | |
387 |
|
387 | |||
388 | def close(self): |
|
388 | def close(self): | |
389 | self._writecaches() |
|
389 | self._writecaches() | |
390 |
|
390 | |||
391 | def _loadextensions(self): |
|
391 | def _loadextensions(self): | |
392 | extensions.loadall(self.ui) |
|
392 | extensions.loadall(self.ui) | |
393 |
|
393 | |||
394 | def _writecaches(self): |
|
394 | def _writecaches(self): | |
395 | if self._revbranchcache: |
|
395 | if self._revbranchcache: | |
396 | self._revbranchcache.write() |
|
396 | self._revbranchcache.write() | |
397 |
|
397 | |||
398 | def _restrictcapabilities(self, caps): |
|
398 | def _restrictcapabilities(self, caps): | |
399 | if self.ui.configbool('experimental', 'bundle2-advertise', True): |
|
399 | if self.ui.configbool('experimental', 'bundle2-advertise', True): | |
400 | caps = set(caps) |
|
400 | caps = set(caps) | |
401 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(self)) |
|
401 | capsblob = bundle2.encodecaps(bundle2.getrepocaps(self)) | |
402 | caps.add('bundle2=' + urlreq.quote(capsblob)) |
|
402 | caps.add('bundle2=' + urlreq.quote(capsblob)) | |
403 | return caps |
|
403 | return caps | |
404 |
|
404 | |||
405 | def _applyopenerreqs(self): |
|
405 | def _applyopenerreqs(self): | |
406 | self.svfs.options = dict((r, 1) for r in self.requirements |
|
406 | self.svfs.options = dict((r, 1) for r in self.requirements | |
407 | if r in self.openerreqs) |
|
407 | if r in self.openerreqs) | |
408 | # experimental config: format.chunkcachesize |
|
408 | # experimental config: format.chunkcachesize | |
409 | chunkcachesize = self.ui.configint('format', 'chunkcachesize') |
|
409 | chunkcachesize = self.ui.configint('format', 'chunkcachesize') | |
410 | if chunkcachesize is not None: |
|
410 | if chunkcachesize is not None: | |
411 | self.svfs.options['chunkcachesize'] = chunkcachesize |
|
411 | self.svfs.options['chunkcachesize'] = chunkcachesize | |
412 | # experimental config: format.maxchainlen |
|
412 | # experimental config: format.maxchainlen | |
413 | maxchainlen = self.ui.configint('format', 'maxchainlen') |
|
413 | maxchainlen = self.ui.configint('format', 'maxchainlen') | |
414 | if maxchainlen is not None: |
|
414 | if maxchainlen is not None: | |
415 | self.svfs.options['maxchainlen'] = maxchainlen |
|
415 | self.svfs.options['maxchainlen'] = maxchainlen | |
416 | # experimental config: format.manifestcachesize |
|
416 | # experimental config: format.manifestcachesize | |
417 | manifestcachesize = self.ui.configint('format', 'manifestcachesize') |
|
417 | manifestcachesize = self.ui.configint('format', 'manifestcachesize') | |
418 | if manifestcachesize is not None: |
|
418 | if manifestcachesize is not None: | |
419 | self.svfs.options['manifestcachesize'] = manifestcachesize |
|
419 | self.svfs.options['manifestcachesize'] = manifestcachesize | |
420 | # experimental config: format.aggressivemergedeltas |
|
420 | # experimental config: format.aggressivemergedeltas | |
421 | aggressivemergedeltas = self.ui.configbool('format', |
|
421 | aggressivemergedeltas = self.ui.configbool('format', | |
422 | 'aggressivemergedeltas', False) |
|
422 | 'aggressivemergedeltas', False) | |
423 | self.svfs.options['aggressivemergedeltas'] = aggressivemergedeltas |
|
423 | self.svfs.options['aggressivemergedeltas'] = aggressivemergedeltas | |
424 | self.svfs.options['lazydeltabase'] = not scmutil.gddeltaconfig(self.ui) |
|
424 | self.svfs.options['lazydeltabase'] = not scmutil.gddeltaconfig(self.ui) | |
425 |
|
425 | |||
426 | for r in self.requirements: |
|
426 | for r in self.requirements: | |
427 | if r.startswith('exp-compression-'): |
|
427 | if r.startswith('exp-compression-'): | |
428 | self.svfs.options['compengine'] = r[len('exp-compression-'):] |
|
428 | self.svfs.options['compengine'] = r[len('exp-compression-'):] | |
429 |
|
429 | |||
430 | def _writerequirements(self): |
|
430 | def _writerequirements(self): | |
431 | scmutil.writerequires(self.vfs, self.requirements) |
|
431 | scmutil.writerequires(self.vfs, self.requirements) | |
432 |
|
432 | |||
433 | def _checknested(self, path): |
|
433 | def _checknested(self, path): | |
434 | """Determine if path is a legal nested repository.""" |
|
434 | """Determine if path is a legal nested repository.""" | |
435 | if not path.startswith(self.root): |
|
435 | if not path.startswith(self.root): | |
436 | return False |
|
436 | return False | |
437 | subpath = path[len(self.root) + 1:] |
|
437 | subpath = path[len(self.root) + 1:] | |
438 | normsubpath = util.pconvert(subpath) |
|
438 | normsubpath = util.pconvert(subpath) | |
439 |
|
439 | |||
440 | # XXX: Checking against the current working copy is wrong in |
|
440 | # XXX: Checking against the current working copy is wrong in | |
441 | # the sense that it can reject things like |
|
441 | # the sense that it can reject things like | |
442 | # |
|
442 | # | |
443 | # $ hg cat -r 10 sub/x.txt |
|
443 | # $ hg cat -r 10 sub/x.txt | |
444 | # |
|
444 | # | |
445 | # if sub/ is no longer a subrepository in the working copy |
|
445 | # if sub/ is no longer a subrepository in the working copy | |
446 | # parent revision. |
|
446 | # parent revision. | |
447 | # |
|
447 | # | |
448 | # However, it can of course also allow things that would have |
|
448 | # However, it can of course also allow things that would have | |
449 | # been rejected before, such as the above cat command if sub/ |
|
449 | # been rejected before, such as the above cat command if sub/ | |
450 | # is a subrepository now, but was a normal directory before. |
|
450 | # is a subrepository now, but was a normal directory before. | |
451 | # The old path auditor would have rejected by mistake since it |
|
451 | # The old path auditor would have rejected by mistake since it | |
452 | # panics when it sees sub/.hg/. |
|
452 | # panics when it sees sub/.hg/. | |
453 | # |
|
453 | # | |
454 | # All in all, checking against the working copy seems sensible |
|
454 | # All in all, checking against the working copy seems sensible | |
455 | # since we want to prevent access to nested repositories on |
|
455 | # since we want to prevent access to nested repositories on | |
456 | # the filesystem *now*. |
|
456 | # the filesystem *now*. | |
457 | ctx = self[None] |
|
457 | ctx = self[None] | |
458 | parts = util.splitpath(subpath) |
|
458 | parts = util.splitpath(subpath) | |
459 | while parts: |
|
459 | while parts: | |
460 | prefix = '/'.join(parts) |
|
460 | prefix = '/'.join(parts) | |
461 | if prefix in ctx.substate: |
|
461 | if prefix in ctx.substate: | |
462 | if prefix == normsubpath: |
|
462 | if prefix == normsubpath: | |
463 | return True |
|
463 | return True | |
464 | else: |
|
464 | else: | |
465 | sub = ctx.sub(prefix) |
|
465 | sub = ctx.sub(prefix) | |
466 | return sub.checknested(subpath[len(prefix) + 1:]) |
|
466 | return sub.checknested(subpath[len(prefix) + 1:]) | |
467 | else: |
|
467 | else: | |
468 | parts.pop() |
|
468 | parts.pop() | |
469 | return False |
|
469 | return False | |
470 |
|
470 | |||
471 | def peer(self): |
|
471 | def peer(self): | |
472 | return localpeer(self) # not cached to avoid reference cycle |
|
472 | return localpeer(self) # not cached to avoid reference cycle | |
473 |
|
473 | |||
474 | def unfiltered(self): |
|
474 | def unfiltered(self): | |
475 | """Return unfiltered version of the repository |
|
475 | """Return unfiltered version of the repository | |
476 |
|
476 | |||
477 | Intended to be overwritten by filtered repo.""" |
|
477 | Intended to be overwritten by filtered repo.""" | |
478 | return self |
|
478 | return self | |
479 |
|
479 | |||
480 | def filtered(self, name): |
|
480 | def filtered(self, name): | |
481 | """Return a filtered version of a repository""" |
|
481 | """Return a filtered version of a repository""" | |
482 | # build a new class with the mixin and the current class |
|
482 | # build a new class with the mixin and the current class | |
483 | # (possibly subclass of the repo) |
|
483 | # (possibly subclass of the repo) | |
484 | class filteredrepo(repoview.repoview, self.unfiltered().__class__): |
|
484 | class filteredrepo(repoview.repoview, self.unfiltered().__class__): | |
485 | pass |
|
485 | pass | |
486 | return filteredrepo(self, name) |
|
486 | return filteredrepo(self, name) | |
487 |
|
487 | |||
488 | @repofilecache('bookmarks', 'bookmarks.current') |
|
488 | @repofilecache('bookmarks', 'bookmarks.current') | |
489 | def _bookmarks(self): |
|
489 | def _bookmarks(self): | |
490 | return bookmarks.bmstore(self) |
|
490 | return bookmarks.bmstore(self) | |
491 |
|
491 | |||
492 | @property |
|
492 | @property | |
493 | def _activebookmark(self): |
|
493 | def _activebookmark(self): | |
494 | return self._bookmarks.active |
|
494 | return self._bookmarks.active | |
495 |
|
495 | |||
496 | def bookmarkheads(self, bookmark): |
|
496 | def bookmarkheads(self, bookmark): | |
497 | name = bookmark.split('@', 1)[0] |
|
497 | name = bookmark.split('@', 1)[0] | |
498 | heads = [] |
|
498 | heads = [] | |
499 | for mark, n in self._bookmarks.iteritems(): |
|
499 | for mark, n in self._bookmarks.iteritems(): | |
500 | if mark.split('@', 1)[0] == name: |
|
500 | if mark.split('@', 1)[0] == name: | |
501 | heads.append(n) |
|
501 | heads.append(n) | |
502 | return heads |
|
502 | return heads | |
503 |
|
503 | |||
504 | # _phaserevs and _phasesets depend on changelog. what we need is to |
|
504 | # _phaserevs and _phasesets depend on changelog. what we need is to | |
505 | # call _phasecache.invalidate() if '00changelog.i' was changed, but it |
|
505 | # call _phasecache.invalidate() if '00changelog.i' was changed, but it | |
506 | # can't be easily expressed in filecache mechanism. |
|
506 | # can't be easily expressed in filecache mechanism. | |
507 | @storecache('phaseroots', '00changelog.i') |
|
507 | @storecache('phaseroots', '00changelog.i') | |
508 | def _phasecache(self): |
|
508 | def _phasecache(self): | |
509 | return phases.phasecache(self, self._phasedefaults) |
|
509 | return phases.phasecache(self, self._phasedefaults) | |
510 |
|
510 | |||
511 | @storecache('obsstore') |
|
511 | @storecache('obsstore') | |
512 | def obsstore(self): |
|
512 | def obsstore(self): | |
513 | # read default format for new obsstore. |
|
513 | # read default format for new obsstore. | |
514 | # developer config: format.obsstore-version |
|
514 | # developer config: format.obsstore-version | |
515 | defaultformat = self.ui.configint('format', 'obsstore-version', None) |
|
515 | defaultformat = self.ui.configint('format', 'obsstore-version', None) | |
516 | # rely on obsstore class default when possible. |
|
516 | # rely on obsstore class default when possible. | |
517 | kwargs = {} |
|
517 | kwargs = {} | |
518 | if defaultformat is not None: |
|
518 | if defaultformat is not None: | |
519 | kwargs['defaultformat'] = defaultformat |
|
519 | kwargs['defaultformat'] = defaultformat | |
520 | readonly = not obsolete.isenabled(self, obsolete.createmarkersopt) |
|
520 | readonly = not obsolete.isenabled(self, obsolete.createmarkersopt) | |
521 | store = obsolete.obsstore(self.svfs, readonly=readonly, |
|
521 | store = obsolete.obsstore(self.svfs, readonly=readonly, | |
522 | **kwargs) |
|
522 | **kwargs) | |
523 | if store and readonly: |
|
523 | if store and readonly: | |
524 | self.ui.warn( |
|
524 | self.ui.warn( | |
525 | _('obsolete feature not enabled but %i markers found!\n') |
|
525 | _('obsolete feature not enabled but %i markers found!\n') | |
526 | % len(list(store))) |
|
526 | % len(list(store))) | |
527 | return store |
|
527 | return store | |
528 |
|
528 | |||
529 | @storecache('00changelog.i') |
|
529 | @storecache('00changelog.i') | |
530 | def changelog(self): |
|
530 | def changelog(self): | |
531 | c = changelog.changelog(self.svfs) |
|
531 | c = changelog.changelog(self.svfs) | |
532 | if txnutil.mayhavepending(self.root): |
|
532 | if txnutil.mayhavepending(self.root): | |
533 | c.readpending('00changelog.i.a') |
|
533 | c.readpending('00changelog.i.a') | |
534 | return c |
|
534 | return c | |
535 |
|
535 | |||
536 | def _constructmanifest(self): |
|
536 | def _constructmanifest(self): | |
537 | # This is a temporary function while we migrate from manifest to |
|
537 | # This is a temporary function while we migrate from manifest to | |
538 | # manifestlog. It allows bundlerepo and unionrepo to intercept the |
|
538 | # manifestlog. It allows bundlerepo and unionrepo to intercept the | |
539 | # manifest creation. |
|
539 | # manifest creation. | |
540 | return manifest.manifestrevlog(self.svfs) |
|
540 | return manifest.manifestrevlog(self.svfs) | |
541 |
|
541 | |||
542 | @storecache('00manifest.i') |
|
542 | @storecache('00manifest.i') | |
543 | def manifestlog(self): |
|
543 | def manifestlog(self): | |
544 | return manifest.manifestlog(self.svfs, self) |
|
544 | return manifest.manifestlog(self.svfs, self) | |
545 |
|
545 | |||
546 | @repofilecache('dirstate') |
|
546 | @repofilecache('dirstate') | |
547 | def dirstate(self): |
|
547 | def dirstate(self): | |
548 | return dirstate.dirstate(self.vfs, self.ui, self.root, |
|
548 | return dirstate.dirstate(self.vfs, self.ui, self.root, | |
549 | self._dirstatevalidate) |
|
549 | self._dirstatevalidate) | |
550 |
|
550 | |||
551 | def _dirstatevalidate(self, node): |
|
551 | def _dirstatevalidate(self, node): | |
552 | try: |
|
552 | try: | |
553 | self.changelog.rev(node) |
|
553 | self.changelog.rev(node) | |
554 | return node |
|
554 | return node | |
555 | except error.LookupError: |
|
555 | except error.LookupError: | |
556 | if not self._dirstatevalidatewarned: |
|
556 | if not self._dirstatevalidatewarned: | |
557 | self._dirstatevalidatewarned = True |
|
557 | self._dirstatevalidatewarned = True | |
558 | self.ui.warn(_("warning: ignoring unknown" |
|
558 | self.ui.warn(_("warning: ignoring unknown" | |
559 | " working parent %s!\n") % short(node)) |
|
559 | " working parent %s!\n") % short(node)) | |
560 | return nullid |
|
560 | return nullid | |
561 |
|
561 | |||
562 | def __getitem__(self, changeid): |
|
562 | def __getitem__(self, changeid): | |
563 | if changeid is None or changeid == wdirrev: |
|
563 | if changeid is None or changeid == wdirrev: | |
564 | return context.workingctx(self) |
|
564 | return context.workingctx(self) | |
565 | if isinstance(changeid, slice): |
|
565 | if isinstance(changeid, slice): | |
566 | return [context.changectx(self, i) |
|
566 | return [context.changectx(self, i) | |
567 | for i in xrange(*changeid.indices(len(self))) |
|
567 | for i in xrange(*changeid.indices(len(self))) | |
568 | if i not in self.changelog.filteredrevs] |
|
568 | if i not in self.changelog.filteredrevs] | |
569 | return context.changectx(self, changeid) |
|
569 | return context.changectx(self, changeid) | |
570 |
|
570 | |||
571 | def __contains__(self, changeid): |
|
571 | def __contains__(self, changeid): | |
572 | try: |
|
572 | try: | |
573 | self[changeid] |
|
573 | self[changeid] | |
574 | return True |
|
574 | return True | |
575 | except error.RepoLookupError: |
|
575 | except error.RepoLookupError: | |
576 | return False |
|
576 | return False | |
577 |
|
577 | |||
578 | def __nonzero__(self): |
|
578 | def __nonzero__(self): | |
579 | return True |
|
579 | return True | |
580 |
|
580 | |||
581 | __bool__ = __nonzero__ |
|
581 | __bool__ = __nonzero__ | |
582 |
|
582 | |||
583 | def __len__(self): |
|
583 | def __len__(self): | |
584 | return len(self.changelog) |
|
584 | return len(self.changelog) | |
585 |
|
585 | |||
586 | def __iter__(self): |
|
586 | def __iter__(self): | |
587 | return iter(self.changelog) |
|
587 | return iter(self.changelog) | |
588 |
|
588 | |||
589 | def revs(self, expr, *args): |
|
589 | def revs(self, expr, *args): | |
590 | '''Find revisions matching a revset. |
|
590 | '''Find revisions matching a revset. | |
591 |
|
591 | |||
592 | The revset is specified as a string ``expr`` that may contain |
|
592 | The revset is specified as a string ``expr`` that may contain | |
593 | %-formatting to escape certain types. See ``revsetlang.formatspec``. |
|
593 | %-formatting to escape certain types. See ``revsetlang.formatspec``. | |
594 |
|
594 | |||
595 | Revset aliases from the configuration are not expanded. To expand |
|
595 | Revset aliases from the configuration are not expanded. To expand | |
596 | user aliases, consider calling ``scmutil.revrange()`` or |
|
596 | user aliases, consider calling ``scmutil.revrange()`` or | |
597 | ``repo.anyrevs([expr], user=True)``. |
|
597 | ``repo.anyrevs([expr], user=True)``. | |
598 |
|
598 | |||
599 | Returns a revset.abstractsmartset, which is a list-like interface |
|
599 | Returns a revset.abstractsmartset, which is a list-like interface | |
600 | that contains integer revisions. |
|
600 | that contains integer revisions. | |
601 | ''' |
|
601 | ''' | |
602 | expr = revsetlang.formatspec(expr, *args) |
|
602 | expr = revsetlang.formatspec(expr, *args) | |
603 | m = revset.match(None, expr) |
|
603 | m = revset.match(None, expr) | |
604 | return m(self) |
|
604 | return m(self) | |
605 |
|
605 | |||
606 | def set(self, expr, *args): |
|
606 | def set(self, expr, *args): | |
607 | '''Find revisions matching a revset and emit changectx instances. |
|
607 | '''Find revisions matching a revset and emit changectx instances. | |
608 |
|
608 | |||
609 | This is a convenience wrapper around ``revs()`` that iterates the |
|
609 | This is a convenience wrapper around ``revs()`` that iterates the | |
610 | result and is a generator of changectx instances. |
|
610 | result and is a generator of changectx instances. | |
611 |
|
611 | |||
612 | Revset aliases from the configuration are not expanded. To expand |
|
612 | Revset aliases from the configuration are not expanded. To expand | |
613 | user aliases, consider calling ``scmutil.revrange()``. |
|
613 | user aliases, consider calling ``scmutil.revrange()``. | |
614 | ''' |
|
614 | ''' | |
615 | for r in self.revs(expr, *args): |
|
615 | for r in self.revs(expr, *args): | |
616 | yield self[r] |
|
616 | yield self[r] | |
617 |
|
617 | |||
618 | def anyrevs(self, specs, user=False): |
|
618 | def anyrevs(self, specs, user=False): | |
619 | '''Find revisions matching one of the given revsets. |
|
619 | '''Find revisions matching one of the given revsets. | |
620 |
|
620 | |||
621 | Revset aliases from the configuration are not expanded by default. To |
|
621 | Revset aliases from the configuration are not expanded by default. To | |
622 | expand user aliases, specify ``user=True``. |
|
622 | expand user aliases, specify ``user=True``. | |
623 | ''' |
|
623 | ''' | |
624 | if user: |
|
624 | if user: | |
625 | m = revset.matchany(self.ui, specs, repo=self) |
|
625 | m = revset.matchany(self.ui, specs, repo=self) | |
626 | else: |
|
626 | else: | |
627 | m = revset.matchany(None, specs) |
|
627 | m = revset.matchany(None, specs) | |
628 | return m(self) |
|
628 | return m(self) | |
629 |
|
629 | |||
630 | def url(self): |
|
630 | def url(self): | |
631 | return 'file:' + self.root |
|
631 | return 'file:' + self.root | |
632 |
|
632 | |||
633 | def hook(self, name, throw=False, **args): |
|
633 | def hook(self, name, throw=False, **args): | |
634 | """Call a hook, passing this repo instance. |
|
634 | """Call a hook, passing this repo instance. | |
635 |
|
635 | |||
636 | This a convenience method to aid invoking hooks. Extensions likely |
|
636 | This a convenience method to aid invoking hooks. Extensions likely | |
637 | won't call this unless they have registered a custom hook or are |
|
637 | won't call this unless they have registered a custom hook or are | |
638 | replacing code that is expected to call a hook. |
|
638 | replacing code that is expected to call a hook. | |
639 | """ |
|
639 | """ | |
640 | return hook.hook(self.ui, self, name, throw, **args) |
|
640 | return hook.hook(self.ui, self, name, throw, **args) | |
641 |
|
641 | |||
642 | @filteredpropertycache |
|
642 | @filteredpropertycache | |
643 | def _tagscache(self): |
|
643 | def _tagscache(self): | |
644 | '''Returns a tagscache object that contains various tags related |
|
644 | '''Returns a tagscache object that contains various tags related | |
645 | caches.''' |
|
645 | caches.''' | |
646 |
|
646 | |||
647 | # This simplifies its cache management by having one decorated |
|
647 | # This simplifies its cache management by having one decorated | |
648 | # function (this one) and the rest simply fetch things from it. |
|
648 | # function (this one) and the rest simply fetch things from it. | |
649 | class tagscache(object): |
|
649 | class tagscache(object): | |
650 | def __init__(self): |
|
650 | def __init__(self): | |
651 | # These two define the set of tags for this repository. tags |
|
651 | # These two define the set of tags for this repository. tags | |
652 | # maps tag name to node; tagtypes maps tag name to 'global' or |
|
652 | # maps tag name to node; tagtypes maps tag name to 'global' or | |
653 | # 'local'. (Global tags are defined by .hgtags across all |
|
653 | # 'local'. (Global tags are defined by .hgtags across all | |
654 | # heads, and local tags are defined in .hg/localtags.) |
|
654 | # heads, and local tags are defined in .hg/localtags.) | |
655 | # They constitute the in-memory cache of tags. |
|
655 | # They constitute the in-memory cache of tags. | |
656 | self.tags = self.tagtypes = None |
|
656 | self.tags = self.tagtypes = None | |
657 |
|
657 | |||
658 | self.nodetagscache = self.tagslist = None |
|
658 | self.nodetagscache = self.tagslist = None | |
659 |
|
659 | |||
660 | cache = tagscache() |
|
660 | cache = tagscache() | |
661 | cache.tags, cache.tagtypes = self._findtags() |
|
661 | cache.tags, cache.tagtypes = self._findtags() | |
662 |
|
662 | |||
663 | return cache |
|
663 | return cache | |
664 |
|
664 | |||
665 | def tags(self): |
|
665 | def tags(self): | |
666 | '''return a mapping of tag to node''' |
|
666 | '''return a mapping of tag to node''' | |
667 | t = {} |
|
667 | t = {} | |
668 | if self.changelog.filteredrevs: |
|
668 | if self.changelog.filteredrevs: | |
669 | tags, tt = self._findtags() |
|
669 | tags, tt = self._findtags() | |
670 | else: |
|
670 | else: | |
671 | tags = self._tagscache.tags |
|
671 | tags = self._tagscache.tags | |
672 | for k, v in tags.iteritems(): |
|
672 | for k, v in tags.iteritems(): | |
673 | try: |
|
673 | try: | |
674 | # ignore tags to unknown nodes |
|
674 | # ignore tags to unknown nodes | |
675 | self.changelog.rev(v) |
|
675 | self.changelog.rev(v) | |
676 | t[k] = v |
|
676 | t[k] = v | |
677 | except (error.LookupError, ValueError): |
|
677 | except (error.LookupError, ValueError): | |
678 | pass |
|
678 | pass | |
679 | return t |
|
679 | return t | |
680 |
|
680 | |||
681 | def _findtags(self): |
|
681 | def _findtags(self): | |
682 | '''Do the hard work of finding tags. Return a pair of dicts |
|
682 | '''Do the hard work of finding tags. Return a pair of dicts | |
683 | (tags, tagtypes) where tags maps tag name to node, and tagtypes |
|
683 | (tags, tagtypes) where tags maps tag name to node, and tagtypes | |
684 | maps tag name to a string like \'global\' or \'local\'. |
|
684 | maps tag name to a string like \'global\' or \'local\'. | |
685 | Subclasses or extensions are free to add their own tags, but |
|
685 | Subclasses or extensions are free to add their own tags, but | |
686 | should be aware that the returned dicts will be retained for the |
|
686 | should be aware that the returned dicts will be retained for the | |
687 | duration of the localrepo object.''' |
|
687 | duration of the localrepo object.''' | |
688 |
|
688 | |||
689 | # XXX what tagtype should subclasses/extensions use? Currently |
|
689 | # XXX what tagtype should subclasses/extensions use? Currently | |
690 | # mq and bookmarks add tags, but do not set the tagtype at all. |
|
690 | # mq and bookmarks add tags, but do not set the tagtype at all. | |
691 | # Should each extension invent its own tag type? Should there |
|
691 | # Should each extension invent its own tag type? Should there | |
692 | # be one tagtype for all such "virtual" tags? Or is the status |
|
692 | # be one tagtype for all such "virtual" tags? Or is the status | |
693 | # quo fine? |
|
693 | # quo fine? | |
694 |
|
694 | |||
695 |
|
695 | |||
696 | # map tag name to (node, hist) |
|
696 | # map tag name to (node, hist) | |
697 | alltags = tagsmod.findglobaltags(self.ui, self) |
|
697 | alltags = tagsmod.findglobaltags(self.ui, self) | |
698 | # map tag name to tag type |
|
698 | # map tag name to tag type | |
699 | tagtypes = dict((tag, 'global') for tag in alltags) |
|
699 | tagtypes = dict((tag, 'global') for tag in alltags) | |
700 |
|
700 | |||
701 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) |
|
701 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) | |
702 |
|
702 | |||
703 | # Build the return dicts. Have to re-encode tag names because |
|
703 | # Build the return dicts. Have to re-encode tag names because | |
704 | # the tags module always uses UTF-8 (in order not to lose info |
|
704 | # the tags module always uses UTF-8 (in order not to lose info | |
705 | # writing to the cache), but the rest of Mercurial wants them in |
|
705 | # writing to the cache), but the rest of Mercurial wants them in | |
706 | # local encoding. |
|
706 | # local encoding. | |
707 | tags = {} |
|
707 | tags = {} | |
708 | for (name, (node, hist)) in alltags.iteritems(): |
|
708 | for (name, (node, hist)) in alltags.iteritems(): | |
709 | if node != nullid: |
|
709 | if node != nullid: | |
710 | tags[encoding.tolocal(name)] = node |
|
710 | tags[encoding.tolocal(name)] = node | |
711 | tags['tip'] = self.changelog.tip() |
|
711 | tags['tip'] = self.changelog.tip() | |
712 | tagtypes = dict([(encoding.tolocal(name), value) |
|
712 | tagtypes = dict([(encoding.tolocal(name), value) | |
713 | for (name, value) in tagtypes.iteritems()]) |
|
713 | for (name, value) in tagtypes.iteritems()]) | |
714 | return (tags, tagtypes) |
|
714 | return (tags, tagtypes) | |
715 |
|
715 | |||
716 | def tagtype(self, tagname): |
|
716 | def tagtype(self, tagname): | |
717 | ''' |
|
717 | ''' | |
718 | return the type of the given tag. result can be: |
|
718 | return the type of the given tag. result can be: | |
719 |
|
719 | |||
720 | 'local' : a local tag |
|
720 | 'local' : a local tag | |
721 | 'global' : a global tag |
|
721 | 'global' : a global tag | |
722 | None : tag does not exist |
|
722 | None : tag does not exist | |
723 | ''' |
|
723 | ''' | |
724 |
|
724 | |||
725 | return self._tagscache.tagtypes.get(tagname) |
|
725 | return self._tagscache.tagtypes.get(tagname) | |
726 |
|
726 | |||
727 | def tagslist(self): |
|
727 | def tagslist(self): | |
728 | '''return a list of tags ordered by revision''' |
|
728 | '''return a list of tags ordered by revision''' | |
729 | if not self._tagscache.tagslist: |
|
729 | if not self._tagscache.tagslist: | |
730 | l = [] |
|
730 | l = [] | |
731 | for t, n in self.tags().iteritems(): |
|
731 | for t, n in self.tags().iteritems(): | |
732 | l.append((self.changelog.rev(n), t, n)) |
|
732 | l.append((self.changelog.rev(n), t, n)) | |
733 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] |
|
733 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] | |
734 |
|
734 | |||
735 | return self._tagscache.tagslist |
|
735 | return self._tagscache.tagslist | |
736 |
|
736 | |||
737 | def nodetags(self, node): |
|
737 | def nodetags(self, node): | |
738 | '''return the tags associated with a node''' |
|
738 | '''return the tags associated with a node''' | |
739 | if not self._tagscache.nodetagscache: |
|
739 | if not self._tagscache.nodetagscache: | |
740 | nodetagscache = {} |
|
740 | nodetagscache = {} | |
741 | for t, n in self._tagscache.tags.iteritems(): |
|
741 | for t, n in self._tagscache.tags.iteritems(): | |
742 | nodetagscache.setdefault(n, []).append(t) |
|
742 | nodetagscache.setdefault(n, []).append(t) | |
743 | for tags in nodetagscache.itervalues(): |
|
743 | for tags in nodetagscache.itervalues(): | |
744 | tags.sort() |
|
744 | tags.sort() | |
745 | self._tagscache.nodetagscache = nodetagscache |
|
745 | self._tagscache.nodetagscache = nodetagscache | |
746 | return self._tagscache.nodetagscache.get(node, []) |
|
746 | return self._tagscache.nodetagscache.get(node, []) | |
747 |
|
747 | |||
748 | def nodebookmarks(self, node): |
|
748 | def nodebookmarks(self, node): | |
749 | """return the list of bookmarks pointing to the specified node""" |
|
749 | """return the list of bookmarks pointing to the specified node""" | |
750 | marks = [] |
|
750 | marks = [] | |
751 | for bookmark, n in self._bookmarks.iteritems(): |
|
751 | for bookmark, n in self._bookmarks.iteritems(): | |
752 | if n == node: |
|
752 | if n == node: | |
753 | marks.append(bookmark) |
|
753 | marks.append(bookmark) | |
754 | return sorted(marks) |
|
754 | return sorted(marks) | |
755 |
|
755 | |||
756 | def branchmap(self): |
|
756 | def branchmap(self): | |
757 | '''returns a dictionary {branch: [branchheads]} with branchheads |
|
757 | '''returns a dictionary {branch: [branchheads]} with branchheads | |
758 | ordered by increasing revision number''' |
|
758 | ordered by increasing revision number''' | |
759 | branchmap.updatecache(self) |
|
759 | branchmap.updatecache(self) | |
760 | return self._branchcaches[self.filtername] |
|
760 | return self._branchcaches[self.filtername] | |
761 |
|
761 | |||
762 | @unfilteredmethod |
|
762 | @unfilteredmethod | |
763 | def revbranchcache(self): |
|
763 | def revbranchcache(self): | |
764 | if not self._revbranchcache: |
|
764 | if not self._revbranchcache: | |
765 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) |
|
765 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) | |
766 | return self._revbranchcache |
|
766 | return self._revbranchcache | |
767 |
|
767 | |||
768 | def branchtip(self, branch, ignoremissing=False): |
|
768 | def branchtip(self, branch, ignoremissing=False): | |
769 | '''return the tip node for a given branch |
|
769 | '''return the tip node for a given branch | |
770 |
|
770 | |||
771 | If ignoremissing is True, then this method will not raise an error. |
|
771 | If ignoremissing is True, then this method will not raise an error. | |
772 | This is helpful for callers that only expect None for a missing branch |
|
772 | This is helpful for callers that only expect None for a missing branch | |
773 | (e.g. namespace). |
|
773 | (e.g. namespace). | |
774 |
|
774 | |||
775 | ''' |
|
775 | ''' | |
776 | try: |
|
776 | try: | |
777 | return self.branchmap().branchtip(branch) |
|
777 | return self.branchmap().branchtip(branch) | |
778 | except KeyError: |
|
778 | except KeyError: | |
779 | if not ignoremissing: |
|
779 | if not ignoremissing: | |
780 | raise error.RepoLookupError(_("unknown branch '%s'") % branch) |
|
780 | raise error.RepoLookupError(_("unknown branch '%s'") % branch) | |
781 | else: |
|
781 | else: | |
782 | pass |
|
782 | pass | |
783 |
|
783 | |||
784 | def lookup(self, key): |
|
784 | def lookup(self, key): | |
785 | return self[key].node() |
|
785 | return self[key].node() | |
786 |
|
786 | |||
787 | def lookupbranch(self, key, remote=None): |
|
787 | def lookupbranch(self, key, remote=None): | |
788 | repo = remote or self |
|
788 | repo = remote or self | |
789 | if key in repo.branchmap(): |
|
789 | if key in repo.branchmap(): | |
790 | return key |
|
790 | return key | |
791 |
|
791 | |||
792 | repo = (remote and remote.local()) and remote or self |
|
792 | repo = (remote and remote.local()) and remote or self | |
793 | return repo[key].branch() |
|
793 | return repo[key].branch() | |
794 |
|
794 | |||
795 | def known(self, nodes): |
|
795 | def known(self, nodes): | |
796 | cl = self.changelog |
|
796 | cl = self.changelog | |
797 | nm = cl.nodemap |
|
797 | nm = cl.nodemap | |
798 | filtered = cl.filteredrevs |
|
798 | filtered = cl.filteredrevs | |
799 | result = [] |
|
799 | result = [] | |
800 | for n in nodes: |
|
800 | for n in nodes: | |
801 | r = nm.get(n) |
|
801 | r = nm.get(n) | |
802 | resp = not (r is None or r in filtered) |
|
802 | resp = not (r is None or r in filtered) | |
803 | result.append(resp) |
|
803 | result.append(resp) | |
804 | return result |
|
804 | return result | |
805 |
|
805 | |||
806 | def local(self): |
|
806 | def local(self): | |
807 | return self |
|
807 | return self | |
808 |
|
808 | |||
809 | def publishing(self): |
|
809 | def publishing(self): | |
810 | # it's safe (and desirable) to trust the publish flag unconditionally |
|
810 | # it's safe (and desirable) to trust the publish flag unconditionally | |
811 | # so that we don't finalize changes shared between users via ssh or nfs |
|
811 | # so that we don't finalize changes shared between users via ssh or nfs | |
812 | return self.ui.configbool('phases', 'publish', True, untrusted=True) |
|
812 | return self.ui.configbool('phases', 'publish', True, untrusted=True) | |
813 |
|
813 | |||
814 | def cancopy(self): |
|
814 | def cancopy(self): | |
815 | # so statichttprepo's override of local() works |
|
815 | # so statichttprepo's override of local() works | |
816 | if not self.local(): |
|
816 | if not self.local(): | |
817 | return False |
|
817 | return False | |
818 | if not self.publishing(): |
|
818 | if not self.publishing(): | |
819 | return True |
|
819 | return True | |
820 | # if publishing we can't copy if there is filtered content |
|
820 | # if publishing we can't copy if there is filtered content | |
821 | return not self.filtered('visible').changelog.filteredrevs |
|
821 | return not self.filtered('visible').changelog.filteredrevs | |
822 |
|
822 | |||
823 | def shared(self): |
|
823 | def shared(self): | |
824 | '''the type of shared repository (None if not shared)''' |
|
824 | '''the type of shared repository (None if not shared)''' | |
825 | if self.sharedpath != self.path: |
|
825 | if self.sharedpath != self.path: | |
826 | return 'store' |
|
826 | return 'store' | |
827 | return None |
|
827 | return None | |
828 |
|
828 | |||
829 | def wjoin(self, f, *insidef): |
|
829 | def wjoin(self, f, *insidef): | |
830 | return self.vfs.reljoin(self.root, f, *insidef) |
|
830 | return self.vfs.reljoin(self.root, f, *insidef) | |
831 |
|
831 | |||
832 | def file(self, f): |
|
832 | def file(self, f): | |
833 | if f[0] == '/': |
|
833 | if f[0] == '/': | |
834 | f = f[1:] |
|
834 | f = f[1:] | |
835 | return filelog.filelog(self.svfs, f) |
|
835 | return filelog.filelog(self.svfs, f) | |
836 |
|
836 | |||
837 | def changectx(self, changeid): |
|
837 | def changectx(self, changeid): | |
838 | return self[changeid] |
|
838 | return self[changeid] | |
839 |
|
839 | |||
840 | def setparents(self, p1, p2=nullid): |
|
840 | def setparents(self, p1, p2=nullid): | |
841 | self.dirstate.beginparentchange() |
|
841 | self.dirstate.beginparentchange() | |
842 | copies = self.dirstate.setparents(p1, p2) |
|
842 | copies = self.dirstate.setparents(p1, p2) | |
843 | pctx = self[p1] |
|
843 | pctx = self[p1] | |
844 | if copies: |
|
844 | if copies: | |
845 | # Adjust copy records, the dirstate cannot do it, it |
|
845 | # Adjust copy records, the dirstate cannot do it, it | |
846 | # requires access to parents manifests. Preserve them |
|
846 | # requires access to parents manifests. Preserve them | |
847 | # only for entries added to first parent. |
|
847 | # only for entries added to first parent. | |
848 | for f in copies: |
|
848 | for f in copies: | |
849 | if f not in pctx and copies[f] in pctx: |
|
849 | if f not in pctx and copies[f] in pctx: | |
850 | self.dirstate.copy(copies[f], f) |
|
850 | self.dirstate.copy(copies[f], f) | |
851 | if p2 == nullid: |
|
851 | if p2 == nullid: | |
852 | for f, s in sorted(self.dirstate.copies().items()): |
|
852 | for f, s in sorted(self.dirstate.copies().items()): | |
853 | if f not in pctx and s not in pctx: |
|
853 | if f not in pctx and s not in pctx: | |
854 | self.dirstate.copy(None, f) |
|
854 | self.dirstate.copy(None, f) | |
855 | self.dirstate.endparentchange() |
|
855 | self.dirstate.endparentchange() | |
856 |
|
856 | |||
857 | def filectx(self, path, changeid=None, fileid=None): |
|
857 | def filectx(self, path, changeid=None, fileid=None): | |
858 | """changeid can be a changeset revision, node, or tag. |
|
858 | """changeid can be a changeset revision, node, or tag. | |
859 | fileid can be a file revision or node.""" |
|
859 | fileid can be a file revision or node.""" | |
860 | return context.filectx(self, path, changeid, fileid) |
|
860 | return context.filectx(self, path, changeid, fileid) | |
861 |
|
861 | |||
862 | def getcwd(self): |
|
862 | def getcwd(self): | |
863 | return self.dirstate.getcwd() |
|
863 | return self.dirstate.getcwd() | |
864 |
|
864 | |||
865 | def pathto(self, f, cwd=None): |
|
865 | def pathto(self, f, cwd=None): | |
866 | return self.dirstate.pathto(f, cwd) |
|
866 | return self.dirstate.pathto(f, cwd) | |
867 |
|
867 | |||
868 | def _loadfilter(self, filter): |
|
868 | def _loadfilter(self, filter): | |
869 | if filter not in self.filterpats: |
|
869 | if filter not in self.filterpats: | |
870 | l = [] |
|
870 | l = [] | |
871 | for pat, cmd in self.ui.configitems(filter): |
|
871 | for pat, cmd in self.ui.configitems(filter): | |
872 | if cmd == '!': |
|
872 | if cmd == '!': | |
873 | continue |
|
873 | continue | |
874 | mf = matchmod.match(self.root, '', [pat]) |
|
874 | mf = matchmod.match(self.root, '', [pat]) | |
875 | fn = None |
|
875 | fn = None | |
876 | params = cmd |
|
876 | params = cmd | |
877 | for name, filterfn in self._datafilters.iteritems(): |
|
877 | for name, filterfn in self._datafilters.iteritems(): | |
878 | if cmd.startswith(name): |
|
878 | if cmd.startswith(name): | |
879 | fn = filterfn |
|
879 | fn = filterfn | |
880 | params = cmd[len(name):].lstrip() |
|
880 | params = cmd[len(name):].lstrip() | |
881 | break |
|
881 | break | |
882 | if not fn: |
|
882 | if not fn: | |
883 | fn = lambda s, c, **kwargs: util.filter(s, c) |
|
883 | fn = lambda s, c, **kwargs: util.filter(s, c) | |
884 | # Wrap old filters not supporting keyword arguments |
|
884 | # Wrap old filters not supporting keyword arguments | |
885 | if not inspect.getargspec(fn)[2]: |
|
885 | if not inspect.getargspec(fn)[2]: | |
886 | oldfn = fn |
|
886 | oldfn = fn | |
887 | fn = lambda s, c, **kwargs: oldfn(s, c) |
|
887 | fn = lambda s, c, **kwargs: oldfn(s, c) | |
888 | l.append((mf, fn, params)) |
|
888 | l.append((mf, fn, params)) | |
889 | self.filterpats[filter] = l |
|
889 | self.filterpats[filter] = l | |
890 | return self.filterpats[filter] |
|
890 | return self.filterpats[filter] | |
891 |
|
891 | |||
892 | def _filter(self, filterpats, filename, data): |
|
892 | def _filter(self, filterpats, filename, data): | |
893 | for mf, fn, cmd in filterpats: |
|
893 | for mf, fn, cmd in filterpats: | |
894 | if mf(filename): |
|
894 | if mf(filename): | |
895 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) |
|
895 | self.ui.debug("filtering %s through %s\n" % (filename, cmd)) | |
896 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) |
|
896 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) | |
897 | break |
|
897 | break | |
898 |
|
898 | |||
899 | return data |
|
899 | return data | |
900 |
|
900 | |||
901 | @unfilteredpropertycache |
|
901 | @unfilteredpropertycache | |
902 | def _encodefilterpats(self): |
|
902 | def _encodefilterpats(self): | |
903 | return self._loadfilter('encode') |
|
903 | return self._loadfilter('encode') | |
904 |
|
904 | |||
905 | @unfilteredpropertycache |
|
905 | @unfilteredpropertycache | |
906 | def _decodefilterpats(self): |
|
906 | def _decodefilterpats(self): | |
907 | return self._loadfilter('decode') |
|
907 | return self._loadfilter('decode') | |
908 |
|
908 | |||
909 | def adddatafilter(self, name, filter): |
|
909 | def adddatafilter(self, name, filter): | |
910 | self._datafilters[name] = filter |
|
910 | self._datafilters[name] = filter | |
911 |
|
911 | |||
912 | def wread(self, filename): |
|
912 | def wread(self, filename): | |
913 | if self.wvfs.islink(filename): |
|
913 | if self.wvfs.islink(filename): | |
914 | data = self.wvfs.readlink(filename) |
|
914 | data = self.wvfs.readlink(filename) | |
915 | else: |
|
915 | else: | |
916 | data = self.wvfs.read(filename) |
|
916 | data = self.wvfs.read(filename) | |
917 | return self._filter(self._encodefilterpats, filename, data) |
|
917 | return self._filter(self._encodefilterpats, filename, data) | |
918 |
|
918 | |||
919 | def wwrite(self, filename, data, flags, backgroundclose=False): |
|
919 | def wwrite(self, filename, data, flags, backgroundclose=False): | |
920 | """write ``data`` into ``filename`` in the working directory |
|
920 | """write ``data`` into ``filename`` in the working directory | |
921 |
|
921 | |||
922 | This returns length of written (maybe decoded) data. |
|
922 | This returns length of written (maybe decoded) data. | |
923 | """ |
|
923 | """ | |
924 | data = self._filter(self._decodefilterpats, filename, data) |
|
924 | data = self._filter(self._decodefilterpats, filename, data) | |
925 | if 'l' in flags: |
|
925 | if 'l' in flags: | |
926 | self.wvfs.symlink(data, filename) |
|
926 | self.wvfs.symlink(data, filename) | |
927 | else: |
|
927 | else: | |
928 | self.wvfs.write(filename, data, backgroundclose=backgroundclose) |
|
928 | self.wvfs.write(filename, data, backgroundclose=backgroundclose) | |
929 | if 'x' in flags: |
|
929 | if 'x' in flags: | |
930 | self.wvfs.setflags(filename, False, True) |
|
930 | self.wvfs.setflags(filename, False, True) | |
931 | return len(data) |
|
931 | return len(data) | |
932 |
|
932 | |||
933 | def wwritedata(self, filename, data): |
|
933 | def wwritedata(self, filename, data): | |
934 | return self._filter(self._decodefilterpats, filename, data) |
|
934 | return self._filter(self._decodefilterpats, filename, data) | |
935 |
|
935 | |||
936 | def currenttransaction(self): |
|
936 | def currenttransaction(self): | |
937 | """return the current transaction or None if non exists""" |
|
937 | """return the current transaction or None if non exists""" | |
938 | if self._transref: |
|
938 | if self._transref: | |
939 | tr = self._transref() |
|
939 | tr = self._transref() | |
940 | else: |
|
940 | else: | |
941 | tr = None |
|
941 | tr = None | |
942 |
|
942 | |||
943 | if tr and tr.running(): |
|
943 | if tr and tr.running(): | |
944 | return tr |
|
944 | return tr | |
945 | return None |
|
945 | return None | |
946 |
|
946 | |||
947 | def transaction(self, desc, report=None): |
|
947 | def transaction(self, desc, report=None): | |
948 | if (self.ui.configbool('devel', 'all-warnings') |
|
948 | if (self.ui.configbool('devel', 'all-warnings') | |
949 | or self.ui.configbool('devel', 'check-locks')): |
|
949 | or self.ui.configbool('devel', 'check-locks')): | |
950 | if self._currentlock(self._lockref) is None: |
|
950 | if self._currentlock(self._lockref) is None: | |
951 | raise error.ProgrammingError('transaction requires locking') |
|
951 | raise error.ProgrammingError('transaction requires locking') | |
952 | tr = self.currenttransaction() |
|
952 | tr = self.currenttransaction() | |
953 | if tr is not None: |
|
953 | if tr is not None: | |
954 | return tr.nest() |
|
954 | return tr.nest() | |
955 |
|
955 | |||
956 | # abort here if the journal already exists |
|
956 | # abort here if the journal already exists | |
957 | if self.svfs.exists("journal"): |
|
957 | if self.svfs.exists("journal"): | |
958 | raise error.RepoError( |
|
958 | raise error.RepoError( | |
959 | _("abandoned transaction found"), |
|
959 | _("abandoned transaction found"), | |
960 | hint=_("run 'hg recover' to clean up transaction")) |
|
960 | hint=_("run 'hg recover' to clean up transaction")) | |
961 |
|
961 | |||
962 | idbase = "%.40f#%f" % (random.random(), time.time()) |
|
962 | idbase = "%.40f#%f" % (random.random(), time.time()) | |
963 | ha = hex(hashlib.sha1(idbase).digest()) |
|
963 | ha = hex(hashlib.sha1(idbase).digest()) | |
964 | txnid = 'TXN:' + ha |
|
964 | txnid = 'TXN:' + ha | |
965 | self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid) |
|
965 | self.hook('pretxnopen', throw=True, txnname=desc, txnid=txnid) | |
966 |
|
966 | |||
967 | self._writejournal(desc) |
|
967 | self._writejournal(desc) | |
968 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] |
|
968 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] | |
969 | if report: |
|
969 | if report: | |
970 | rp = report |
|
970 | rp = report | |
971 | else: |
|
971 | else: | |
972 | rp = self.ui.warn |
|
972 | rp = self.ui.warn | |
973 | vfsmap = {'plain': self.vfs} # root of .hg/ |
|
973 | vfsmap = {'plain': self.vfs} # root of .hg/ | |
974 | # we must avoid cyclic reference between repo and transaction. |
|
974 | # we must avoid cyclic reference between repo and transaction. | |
975 | reporef = weakref.ref(self) |
|
975 | reporef = weakref.ref(self) | |
976 | # Code to track tag movement |
|
976 | # Code to track tag movement | |
977 | # |
|
977 | # | |
978 | # Since tags are all handled as file content, it is actually quite hard |
|
978 | # Since tags are all handled as file content, it is actually quite hard | |
979 | # to track these movement from a code perspective. So we fallback to a |
|
979 | # to track these movement from a code perspective. So we fallback to a | |
980 | # tracking at the repository level. One could envision to track changes |
|
980 | # tracking at the repository level. One could envision to track changes | |
981 | # to the '.hgtags' file through changegroup apply but that fails to |
|
981 | # to the '.hgtags' file through changegroup apply but that fails to | |
982 | # cope with case where transaction expose new heads without changegroup |
|
982 | # cope with case where transaction expose new heads without changegroup | |
983 | # being involved (eg: phase movement). |
|
983 | # being involved (eg: phase movement). | |
984 | # |
|
984 | # | |
985 | # For now, We gate the feature behind a flag since this likely comes |
|
985 | # For now, We gate the feature behind a flag since this likely comes | |
986 | # with performance impacts. The current code run more often than needed |
|
986 | # with performance impacts. The current code run more often than needed | |
987 | # and do not use caches as much as it could. The current focus is on |
|
987 | # and do not use caches as much as it could. The current focus is on | |
988 | # the behavior of the feature so we disable it by default. The flag |
|
988 | # the behavior of the feature so we disable it by default. The flag | |
989 | # will be removed when we are happy with the performance impact. |
|
989 | # will be removed when we are happy with the performance impact. | |
990 | # |
|
990 | # | |
991 | # Once this feature is no longer experimental move the following |
|
991 | # Once this feature is no longer experimental move the following | |
992 | # documentation to the appropriate help section: |
|
992 | # documentation to the appropriate help section: | |
993 | # |
|
993 | # | |
994 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched |
|
994 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched | |
995 | # tags (new or changed or deleted tags). In addition the details of |
|
995 | # tags (new or changed or deleted tags). In addition the details of | |
996 | # these changes are made available in a file at: |
|
996 | # these changes are made available in a file at: | |
997 | # ``REPOROOT/.hg/changes/tags.changes``. |
|
997 | # ``REPOROOT/.hg/changes/tags.changes``. | |
998 | # Make sure you check for HG_TAG_MOVED before reading that file as it |
|
998 | # Make sure you check for HG_TAG_MOVED before reading that file as it | |
999 | # might exist from a previous transaction even if no tag were touched |
|
999 | # might exist from a previous transaction even if no tag were touched | |
1000 | # in this one. Changes are recorded in a line base format:: |
|
1000 | # in this one. Changes are recorded in a line base format:: | |
1001 | # |
|
1001 | # | |
1002 | # <action> <hex-node> <tag-name>\n |
|
1002 | # <action> <hex-node> <tag-name>\n | |
1003 | # |
|
1003 | # | |
1004 | # Actions are defined as follow: |
|
1004 | # Actions are defined as follow: | |
1005 | # "-R": tag is removed, |
|
1005 | # "-R": tag is removed, | |
1006 | # "+A": tag is added, |
|
1006 | # "+A": tag is added, | |
1007 | # "-M": tag is moved (old value), |
|
1007 | # "-M": tag is moved (old value), | |
1008 | # "+M": tag is moved (new value), |
|
1008 | # "+M": tag is moved (new value), | |
1009 | tracktags = lambda x: None |
|
1009 | tracktags = lambda x: None | |
1010 | # experimental config: experimental.hook-track-tags |
|
1010 | # experimental config: experimental.hook-track-tags | |
1011 | shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags', |
|
1011 | shouldtracktags = self.ui.configbool('experimental', 'hook-track-tags', | |
1012 | False) |
|
1012 | False) | |
1013 | if desc != 'strip' and shouldtracktags: |
|
1013 | if desc != 'strip' and shouldtracktags: | |
1014 | oldheads = self.changelog.headrevs() |
|
1014 | oldheads = self.changelog.headrevs() | |
1015 | def tracktags(tr2): |
|
1015 | def tracktags(tr2): | |
1016 | repo = reporef() |
|
1016 | repo = reporef() | |
1017 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) |
|
1017 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) | |
1018 | newheads = repo.changelog.headrevs() |
|
1018 | newheads = repo.changelog.headrevs() | |
1019 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) |
|
1019 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) | |
1020 | # notes: we compare lists here. |
|
1020 | # notes: we compare lists here. | |
1021 | # As we do it only once buiding set would not be cheaper |
|
1021 | # As we do it only once buiding set would not be cheaper | |
1022 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) |
|
1022 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) | |
1023 | if changes: |
|
1023 | if changes: | |
1024 | tr2.hookargs['tag_moved'] = '1' |
|
1024 | tr2.hookargs['tag_moved'] = '1' | |
1025 | with repo.vfs('changes/tags.changes', 'w', |
|
1025 | with repo.vfs('changes/tags.changes', 'w', | |
1026 | atomictemp=True) as changesfile: |
|
1026 | atomictemp=True) as changesfile: | |
1027 | # note: we do not register the file to the transaction |
|
1027 | # note: we do not register the file to the transaction | |
1028 | # because we needs it to still exist on the transaction |
|
1028 | # because we needs it to still exist on the transaction | |
1029 | # is close (for txnclose hooks) |
|
1029 | # is close (for txnclose hooks) | |
1030 | tagsmod.writediff(changesfile, changes) |
|
1030 | tagsmod.writediff(changesfile, changes) | |
1031 | def validate(tr2): |
|
1031 | def validate(tr2): | |
1032 | """will run pre-closing hooks""" |
|
1032 | """will run pre-closing hooks""" | |
1033 | # XXX the transaction API is a bit lacking here so we take a hacky |
|
1033 | # XXX the transaction API is a bit lacking here so we take a hacky | |
1034 | # path for now |
|
1034 | # path for now | |
1035 | # |
|
1035 | # | |
1036 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' |
|
1036 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' | |
1037 | # dict is copied before these run. In addition we needs the data |
|
1037 | # dict is copied before these run. In addition we needs the data | |
1038 | # available to in memory hooks too. |
|
1038 | # available to in memory hooks too. | |
1039 | # |
|
1039 | # | |
1040 | # Moreover, we also need to make sure this runs before txnclose |
|
1040 | # Moreover, we also need to make sure this runs before txnclose | |
1041 | # hooks and there is no "pending" mechanism that would execute |
|
1041 | # hooks and there is no "pending" mechanism that would execute | |
1042 | # logic only if hooks are about to run. |
|
1042 | # logic only if hooks are about to run. | |
1043 | # |
|
1043 | # | |
1044 | # Fixing this limitation of the transaction is also needed to track |
|
1044 | # Fixing this limitation of the transaction is also needed to track | |
1045 | # other families of changes (bookmarks, phases, obsolescence). |
|
1045 | # other families of changes (bookmarks, phases, obsolescence). | |
1046 | # |
|
1046 | # | |
1047 | # This will have to be fixed before we remove the experimental |
|
1047 | # This will have to be fixed before we remove the experimental | |
1048 | # gating. |
|
1048 | # gating. | |
1049 | tracktags(tr2) |
|
1049 | tracktags(tr2) | |
1050 | reporef().hook('pretxnclose', throw=True, |
|
1050 | reporef().hook('pretxnclose', throw=True, | |
1051 | txnname=desc, **pycompat.strkwargs(tr.hookargs)) |
|
1051 | txnname=desc, **pycompat.strkwargs(tr.hookargs)) | |
1052 | def releasefn(tr, success): |
|
1052 | def releasefn(tr, success): | |
1053 | repo = reporef() |
|
1053 | repo = reporef() | |
1054 | if success: |
|
1054 | if success: | |
1055 | # this should be explicitly invoked here, because |
|
1055 | # this should be explicitly invoked here, because | |
1056 | # in-memory changes aren't written out at closing |
|
1056 | # in-memory changes aren't written out at closing | |
1057 | # transaction, if tr.addfilegenerator (via |
|
1057 | # transaction, if tr.addfilegenerator (via | |
1058 | # dirstate.write or so) isn't invoked while |
|
1058 | # dirstate.write or so) isn't invoked while | |
1059 | # transaction running |
|
1059 | # transaction running | |
1060 | repo.dirstate.write(None) |
|
1060 | repo.dirstate.write(None) | |
1061 | else: |
|
1061 | else: | |
1062 | # discard all changes (including ones already written |
|
1062 | # discard all changes (including ones already written | |
1063 | # out) in this transaction |
|
1063 | # out) in this transaction | |
1064 | repo.dirstate.restorebackup(None, prefix='journal.') |
|
1064 | repo.dirstate.restorebackup(None, prefix='journal.') | |
1065 |
|
1065 | |||
1066 | repo.invalidate(clearfilecache=True) |
|
1066 | repo.invalidate(clearfilecache=True) | |
1067 |
|
1067 | |||
1068 | tr = transaction.transaction(rp, self.svfs, vfsmap, |
|
1068 | tr = transaction.transaction(rp, self.svfs, vfsmap, | |
1069 | "journal", |
|
1069 | "journal", | |
1070 | "undo", |
|
1070 | "undo", | |
1071 | aftertrans(renames), |
|
1071 | aftertrans(renames), | |
1072 | self.store.createmode, |
|
1072 | self.store.createmode, | |
1073 | validator=validate, |
|
1073 | validator=validate, | |
1074 | releasefn=releasefn) |
|
1074 | releasefn=releasefn) | |
|
1075 | tr.changes['revs'] = set() | |||
1075 |
|
1076 | |||
1076 | tr.hookargs['txnid'] = txnid |
|
1077 | tr.hookargs['txnid'] = txnid | |
1077 | # note: writing the fncache only during finalize mean that the file is |
|
1078 | # note: writing the fncache only during finalize mean that the file is | |
1078 | # outdated when running hooks. As fncache is used for streaming clone, |
|
1079 | # outdated when running hooks. As fncache is used for streaming clone, | |
1079 | # this is not expected to break anything that happen during the hooks. |
|
1080 | # this is not expected to break anything that happen during the hooks. | |
1080 | tr.addfinalize('flush-fncache', self.store.write) |
|
1081 | tr.addfinalize('flush-fncache', self.store.write) | |
1081 | def txnclosehook(tr2): |
|
1082 | def txnclosehook(tr2): | |
1082 | """To be run if transaction is successful, will schedule a hook run |
|
1083 | """To be run if transaction is successful, will schedule a hook run | |
1083 | """ |
|
1084 | """ | |
1084 | # Don't reference tr2 in hook() so we don't hold a reference. |
|
1085 | # Don't reference tr2 in hook() so we don't hold a reference. | |
1085 | # This reduces memory consumption when there are multiple |
|
1086 | # This reduces memory consumption when there are multiple | |
1086 | # transactions per lock. This can likely go away if issue5045 |
|
1087 | # transactions per lock. This can likely go away if issue5045 | |
1087 | # fixes the function accumulation. |
|
1088 | # fixes the function accumulation. | |
1088 | hookargs = tr2.hookargs |
|
1089 | hookargs = tr2.hookargs | |
1089 |
|
1090 | |||
1090 | def hook(): |
|
1091 | def hook(): | |
1091 | reporef().hook('txnclose', throw=False, txnname=desc, |
|
1092 | reporef().hook('txnclose', throw=False, txnname=desc, | |
1092 | **pycompat.strkwargs(hookargs)) |
|
1093 | **pycompat.strkwargs(hookargs)) | |
1093 | reporef()._afterlock(hook) |
|
1094 | reporef()._afterlock(hook) | |
1094 | tr.addfinalize('txnclose-hook', txnclosehook) |
|
1095 | tr.addfinalize('txnclose-hook', txnclosehook) | |
1095 | def txnaborthook(tr2): |
|
1096 | def txnaborthook(tr2): | |
1096 | """To be run if transaction is aborted |
|
1097 | """To be run if transaction is aborted | |
1097 | """ |
|
1098 | """ | |
1098 | reporef().hook('txnabort', throw=False, txnname=desc, |
|
1099 | reporef().hook('txnabort', throw=False, txnname=desc, | |
1099 | **tr2.hookargs) |
|
1100 | **tr2.hookargs) | |
1100 | tr.addabort('txnabort-hook', txnaborthook) |
|
1101 | tr.addabort('txnabort-hook', txnaborthook) | |
1101 | # avoid eager cache invalidation. in-memory data should be identical |
|
1102 | # avoid eager cache invalidation. in-memory data should be identical | |
1102 | # to stored data if transaction has no error. |
|
1103 | # to stored data if transaction has no error. | |
1103 | tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats) |
|
1104 | tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats) | |
1104 | self._transref = weakref.ref(tr) |
|
1105 | self._transref = weakref.ref(tr) | |
1105 | return tr |
|
1106 | return tr | |
1106 |
|
1107 | |||
1107 | def _journalfiles(self): |
|
1108 | def _journalfiles(self): | |
1108 | return ((self.svfs, 'journal'), |
|
1109 | return ((self.svfs, 'journal'), | |
1109 | (self.vfs, 'journal.dirstate'), |
|
1110 | (self.vfs, 'journal.dirstate'), | |
1110 | (self.vfs, 'journal.branch'), |
|
1111 | (self.vfs, 'journal.branch'), | |
1111 | (self.vfs, 'journal.desc'), |
|
1112 | (self.vfs, 'journal.desc'), | |
1112 | (self.vfs, 'journal.bookmarks'), |
|
1113 | (self.vfs, 'journal.bookmarks'), | |
1113 | (self.svfs, 'journal.phaseroots')) |
|
1114 | (self.svfs, 'journal.phaseroots')) | |
1114 |
|
1115 | |||
1115 | def undofiles(self): |
|
1116 | def undofiles(self): | |
1116 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] |
|
1117 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] | |
1117 |
|
1118 | |||
1118 | def _writejournal(self, desc): |
|
1119 | def _writejournal(self, desc): | |
1119 | self.dirstate.savebackup(None, prefix='journal.') |
|
1120 | self.dirstate.savebackup(None, prefix='journal.') | |
1120 | self.vfs.write("journal.branch", |
|
1121 | self.vfs.write("journal.branch", | |
1121 | encoding.fromlocal(self.dirstate.branch())) |
|
1122 | encoding.fromlocal(self.dirstate.branch())) | |
1122 | self.vfs.write("journal.desc", |
|
1123 | self.vfs.write("journal.desc", | |
1123 | "%d\n%s\n" % (len(self), desc)) |
|
1124 | "%d\n%s\n" % (len(self), desc)) | |
1124 | self.vfs.write("journal.bookmarks", |
|
1125 | self.vfs.write("journal.bookmarks", | |
1125 | self.vfs.tryread("bookmarks")) |
|
1126 | self.vfs.tryread("bookmarks")) | |
1126 | self.svfs.write("journal.phaseroots", |
|
1127 | self.svfs.write("journal.phaseroots", | |
1127 | self.svfs.tryread("phaseroots")) |
|
1128 | self.svfs.tryread("phaseroots")) | |
1128 |
|
1129 | |||
1129 | def recover(self): |
|
1130 | def recover(self): | |
1130 | with self.lock(): |
|
1131 | with self.lock(): | |
1131 | if self.svfs.exists("journal"): |
|
1132 | if self.svfs.exists("journal"): | |
1132 | self.ui.status(_("rolling back interrupted transaction\n")) |
|
1133 | self.ui.status(_("rolling back interrupted transaction\n")) | |
1133 | vfsmap = {'': self.svfs, |
|
1134 | vfsmap = {'': self.svfs, | |
1134 | 'plain': self.vfs,} |
|
1135 | 'plain': self.vfs,} | |
1135 | transaction.rollback(self.svfs, vfsmap, "journal", |
|
1136 | transaction.rollback(self.svfs, vfsmap, "journal", | |
1136 | self.ui.warn) |
|
1137 | self.ui.warn) | |
1137 | self.invalidate() |
|
1138 | self.invalidate() | |
1138 | return True |
|
1139 | return True | |
1139 | else: |
|
1140 | else: | |
1140 | self.ui.warn(_("no interrupted transaction available\n")) |
|
1141 | self.ui.warn(_("no interrupted transaction available\n")) | |
1141 | return False |
|
1142 | return False | |
1142 |
|
1143 | |||
1143 | def rollback(self, dryrun=False, force=False): |
|
1144 | def rollback(self, dryrun=False, force=False): | |
1144 | wlock = lock = dsguard = None |
|
1145 | wlock = lock = dsguard = None | |
1145 | try: |
|
1146 | try: | |
1146 | wlock = self.wlock() |
|
1147 | wlock = self.wlock() | |
1147 | lock = self.lock() |
|
1148 | lock = self.lock() | |
1148 | if self.svfs.exists("undo"): |
|
1149 | if self.svfs.exists("undo"): | |
1149 | dsguard = dirstateguard.dirstateguard(self, 'rollback') |
|
1150 | dsguard = dirstateguard.dirstateguard(self, 'rollback') | |
1150 |
|
1151 | |||
1151 | return self._rollback(dryrun, force, dsguard) |
|
1152 | return self._rollback(dryrun, force, dsguard) | |
1152 | else: |
|
1153 | else: | |
1153 | self.ui.warn(_("no rollback information available\n")) |
|
1154 | self.ui.warn(_("no rollback information available\n")) | |
1154 | return 1 |
|
1155 | return 1 | |
1155 | finally: |
|
1156 | finally: | |
1156 | release(dsguard, lock, wlock) |
|
1157 | release(dsguard, lock, wlock) | |
1157 |
|
1158 | |||
1158 | @unfilteredmethod # Until we get smarter cache management |
|
1159 | @unfilteredmethod # Until we get smarter cache management | |
1159 | def _rollback(self, dryrun, force, dsguard): |
|
1160 | def _rollback(self, dryrun, force, dsguard): | |
1160 | ui = self.ui |
|
1161 | ui = self.ui | |
1161 | try: |
|
1162 | try: | |
1162 | args = self.vfs.read('undo.desc').splitlines() |
|
1163 | args = self.vfs.read('undo.desc').splitlines() | |
1163 | (oldlen, desc, detail) = (int(args[0]), args[1], None) |
|
1164 | (oldlen, desc, detail) = (int(args[0]), args[1], None) | |
1164 | if len(args) >= 3: |
|
1165 | if len(args) >= 3: | |
1165 | detail = args[2] |
|
1166 | detail = args[2] | |
1166 | oldtip = oldlen - 1 |
|
1167 | oldtip = oldlen - 1 | |
1167 |
|
1168 | |||
1168 | if detail and ui.verbose: |
|
1169 | if detail and ui.verbose: | |
1169 | msg = (_('repository tip rolled back to revision %s' |
|
1170 | msg = (_('repository tip rolled back to revision %s' | |
1170 | ' (undo %s: %s)\n') |
|
1171 | ' (undo %s: %s)\n') | |
1171 | % (oldtip, desc, detail)) |
|
1172 | % (oldtip, desc, detail)) | |
1172 | else: |
|
1173 | else: | |
1173 | msg = (_('repository tip rolled back to revision %s' |
|
1174 | msg = (_('repository tip rolled back to revision %s' | |
1174 | ' (undo %s)\n') |
|
1175 | ' (undo %s)\n') | |
1175 | % (oldtip, desc)) |
|
1176 | % (oldtip, desc)) | |
1176 | except IOError: |
|
1177 | except IOError: | |
1177 | msg = _('rolling back unknown transaction\n') |
|
1178 | msg = _('rolling back unknown transaction\n') | |
1178 | desc = None |
|
1179 | desc = None | |
1179 |
|
1180 | |||
1180 | if not force and self['.'] != self['tip'] and desc == 'commit': |
|
1181 | if not force and self['.'] != self['tip'] and desc == 'commit': | |
1181 | raise error.Abort( |
|
1182 | raise error.Abort( | |
1182 | _('rollback of last commit while not checked out ' |
|
1183 | _('rollback of last commit while not checked out ' | |
1183 | 'may lose data'), hint=_('use -f to force')) |
|
1184 | 'may lose data'), hint=_('use -f to force')) | |
1184 |
|
1185 | |||
1185 | ui.status(msg) |
|
1186 | ui.status(msg) | |
1186 | if dryrun: |
|
1187 | if dryrun: | |
1187 | return 0 |
|
1188 | return 0 | |
1188 |
|
1189 | |||
1189 | parents = self.dirstate.parents() |
|
1190 | parents = self.dirstate.parents() | |
1190 | self.destroying() |
|
1191 | self.destroying() | |
1191 | vfsmap = {'plain': self.vfs, '': self.svfs} |
|
1192 | vfsmap = {'plain': self.vfs, '': self.svfs} | |
1192 | transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn) |
|
1193 | transaction.rollback(self.svfs, vfsmap, 'undo', ui.warn) | |
1193 | if self.vfs.exists('undo.bookmarks'): |
|
1194 | if self.vfs.exists('undo.bookmarks'): | |
1194 | self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True) |
|
1195 | self.vfs.rename('undo.bookmarks', 'bookmarks', checkambig=True) | |
1195 | if self.svfs.exists('undo.phaseroots'): |
|
1196 | if self.svfs.exists('undo.phaseroots'): | |
1196 | self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True) |
|
1197 | self.svfs.rename('undo.phaseroots', 'phaseroots', checkambig=True) | |
1197 | self.invalidate() |
|
1198 | self.invalidate() | |
1198 |
|
1199 | |||
1199 | parentgone = (parents[0] not in self.changelog.nodemap or |
|
1200 | parentgone = (parents[0] not in self.changelog.nodemap or | |
1200 | parents[1] not in self.changelog.nodemap) |
|
1201 | parents[1] not in self.changelog.nodemap) | |
1201 | if parentgone: |
|
1202 | if parentgone: | |
1202 | # prevent dirstateguard from overwriting already restored one |
|
1203 | # prevent dirstateguard from overwriting already restored one | |
1203 | dsguard.close() |
|
1204 | dsguard.close() | |
1204 |
|
1205 | |||
1205 | self.dirstate.restorebackup(None, prefix='undo.') |
|
1206 | self.dirstate.restorebackup(None, prefix='undo.') | |
1206 | try: |
|
1207 | try: | |
1207 | branch = self.vfs.read('undo.branch') |
|
1208 | branch = self.vfs.read('undo.branch') | |
1208 | self.dirstate.setbranch(encoding.tolocal(branch)) |
|
1209 | self.dirstate.setbranch(encoding.tolocal(branch)) | |
1209 | except IOError: |
|
1210 | except IOError: | |
1210 | ui.warn(_('named branch could not be reset: ' |
|
1211 | ui.warn(_('named branch could not be reset: ' | |
1211 | 'current branch is still \'%s\'\n') |
|
1212 | 'current branch is still \'%s\'\n') | |
1212 | % self.dirstate.branch()) |
|
1213 | % self.dirstate.branch()) | |
1213 |
|
1214 | |||
1214 | parents = tuple([p.rev() for p in self[None].parents()]) |
|
1215 | parents = tuple([p.rev() for p in self[None].parents()]) | |
1215 | if len(parents) > 1: |
|
1216 | if len(parents) > 1: | |
1216 | ui.status(_('working directory now based on ' |
|
1217 | ui.status(_('working directory now based on ' | |
1217 | 'revisions %d and %d\n') % parents) |
|
1218 | 'revisions %d and %d\n') % parents) | |
1218 | else: |
|
1219 | else: | |
1219 | ui.status(_('working directory now based on ' |
|
1220 | ui.status(_('working directory now based on ' | |
1220 | 'revision %d\n') % parents) |
|
1221 | 'revision %d\n') % parents) | |
1221 | mergemod.mergestate.clean(self, self['.'].node()) |
|
1222 | mergemod.mergestate.clean(self, self['.'].node()) | |
1222 |
|
1223 | |||
1223 | # TODO: if we know which new heads may result from this rollback, pass |
|
1224 | # TODO: if we know which new heads may result from this rollback, pass | |
1224 | # them to destroy(), which will prevent the branchhead cache from being |
|
1225 | # them to destroy(), which will prevent the branchhead cache from being | |
1225 | # invalidated. |
|
1226 | # invalidated. | |
1226 | self.destroyed() |
|
1227 | self.destroyed() | |
1227 | return 0 |
|
1228 | return 0 | |
1228 |
|
1229 | |||
1229 | def invalidatecaches(self): |
|
1230 | def invalidatecaches(self): | |
1230 |
|
1231 | |||
1231 | if '_tagscache' in vars(self): |
|
1232 | if '_tagscache' in vars(self): | |
1232 | # can't use delattr on proxy |
|
1233 | # can't use delattr on proxy | |
1233 | del self.__dict__['_tagscache'] |
|
1234 | del self.__dict__['_tagscache'] | |
1234 |
|
1235 | |||
1235 | self.unfiltered()._branchcaches.clear() |
|
1236 | self.unfiltered()._branchcaches.clear() | |
1236 | self.invalidatevolatilesets() |
|
1237 | self.invalidatevolatilesets() | |
1237 |
|
1238 | |||
1238 | def invalidatevolatilesets(self): |
|
1239 | def invalidatevolatilesets(self): | |
1239 | self.filteredrevcache.clear() |
|
1240 | self.filteredrevcache.clear() | |
1240 | obsolete.clearobscaches(self) |
|
1241 | obsolete.clearobscaches(self) | |
1241 |
|
1242 | |||
1242 | def invalidatedirstate(self): |
|
1243 | def invalidatedirstate(self): | |
1243 | '''Invalidates the dirstate, causing the next call to dirstate |
|
1244 | '''Invalidates the dirstate, causing the next call to dirstate | |
1244 | to check if it was modified since the last time it was read, |
|
1245 | to check if it was modified since the last time it was read, | |
1245 | rereading it if it has. |
|
1246 | rereading it if it has. | |
1246 |
|
1247 | |||
1247 | This is different to dirstate.invalidate() that it doesn't always |
|
1248 | This is different to dirstate.invalidate() that it doesn't always | |
1248 | rereads the dirstate. Use dirstate.invalidate() if you want to |
|
1249 | rereads the dirstate. Use dirstate.invalidate() if you want to | |
1249 | explicitly read the dirstate again (i.e. restoring it to a previous |
|
1250 | explicitly read the dirstate again (i.e. restoring it to a previous | |
1250 | known good state).''' |
|
1251 | known good state).''' | |
1251 | if hasunfilteredcache(self, 'dirstate'): |
|
1252 | if hasunfilteredcache(self, 'dirstate'): | |
1252 | for k in self.dirstate._filecache: |
|
1253 | for k in self.dirstate._filecache: | |
1253 | try: |
|
1254 | try: | |
1254 | delattr(self.dirstate, k) |
|
1255 | delattr(self.dirstate, k) | |
1255 | except AttributeError: |
|
1256 | except AttributeError: | |
1256 | pass |
|
1257 | pass | |
1257 | delattr(self.unfiltered(), 'dirstate') |
|
1258 | delattr(self.unfiltered(), 'dirstate') | |
1258 |
|
1259 | |||
1259 | def invalidate(self, clearfilecache=False): |
|
1260 | def invalidate(self, clearfilecache=False): | |
1260 | '''Invalidates both store and non-store parts other than dirstate |
|
1261 | '''Invalidates both store and non-store parts other than dirstate | |
1261 |
|
1262 | |||
1262 | If a transaction is running, invalidation of store is omitted, |
|
1263 | If a transaction is running, invalidation of store is omitted, | |
1263 | because discarding in-memory changes might cause inconsistency |
|
1264 | because discarding in-memory changes might cause inconsistency | |
1264 | (e.g. incomplete fncache causes unintentional failure, but |
|
1265 | (e.g. incomplete fncache causes unintentional failure, but | |
1265 | redundant one doesn't). |
|
1266 | redundant one doesn't). | |
1266 | ''' |
|
1267 | ''' | |
1267 | unfiltered = self.unfiltered() # all file caches are stored unfiltered |
|
1268 | unfiltered = self.unfiltered() # all file caches are stored unfiltered | |
1268 | for k in list(self._filecache.keys()): |
|
1269 | for k in list(self._filecache.keys()): | |
1269 | # dirstate is invalidated separately in invalidatedirstate() |
|
1270 | # dirstate is invalidated separately in invalidatedirstate() | |
1270 | if k == 'dirstate': |
|
1271 | if k == 'dirstate': | |
1271 | continue |
|
1272 | continue | |
1272 |
|
1273 | |||
1273 | if clearfilecache: |
|
1274 | if clearfilecache: | |
1274 | del self._filecache[k] |
|
1275 | del self._filecache[k] | |
1275 | try: |
|
1276 | try: | |
1276 | delattr(unfiltered, k) |
|
1277 | delattr(unfiltered, k) | |
1277 | except AttributeError: |
|
1278 | except AttributeError: | |
1278 | pass |
|
1279 | pass | |
1279 | self.invalidatecaches() |
|
1280 | self.invalidatecaches() | |
1280 | if not self.currenttransaction(): |
|
1281 | if not self.currenttransaction(): | |
1281 | # TODO: Changing contents of store outside transaction |
|
1282 | # TODO: Changing contents of store outside transaction | |
1282 | # causes inconsistency. We should make in-memory store |
|
1283 | # causes inconsistency. We should make in-memory store | |
1283 | # changes detectable, and abort if changed. |
|
1284 | # changes detectable, and abort if changed. | |
1284 | self.store.invalidatecaches() |
|
1285 | self.store.invalidatecaches() | |
1285 |
|
1286 | |||
1286 | def invalidateall(self): |
|
1287 | def invalidateall(self): | |
1287 | '''Fully invalidates both store and non-store parts, causing the |
|
1288 | '''Fully invalidates both store and non-store parts, causing the | |
1288 | subsequent operation to reread any outside changes.''' |
|
1289 | subsequent operation to reread any outside changes.''' | |
1289 | # extension should hook this to invalidate its caches |
|
1290 | # extension should hook this to invalidate its caches | |
1290 | self.invalidate() |
|
1291 | self.invalidate() | |
1291 | self.invalidatedirstate() |
|
1292 | self.invalidatedirstate() | |
1292 |
|
1293 | |||
1293 | @unfilteredmethod |
|
1294 | @unfilteredmethod | |
1294 | def _refreshfilecachestats(self, tr): |
|
1295 | def _refreshfilecachestats(self, tr): | |
1295 | """Reload stats of cached files so that they are flagged as valid""" |
|
1296 | """Reload stats of cached files so that they are flagged as valid""" | |
1296 | for k, ce in self._filecache.items(): |
|
1297 | for k, ce in self._filecache.items(): | |
1297 | if k == 'dirstate' or k not in self.__dict__: |
|
1298 | if k == 'dirstate' or k not in self.__dict__: | |
1298 | continue |
|
1299 | continue | |
1299 | ce.refresh() |
|
1300 | ce.refresh() | |
1300 |
|
1301 | |||
1301 | def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc, |
|
1302 | def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc, | |
1302 | inheritchecker=None, parentenvvar=None): |
|
1303 | inheritchecker=None, parentenvvar=None): | |
1303 | parentlock = None |
|
1304 | parentlock = None | |
1304 | # the contents of parentenvvar are used by the underlying lock to |
|
1305 | # the contents of parentenvvar are used by the underlying lock to | |
1305 | # determine whether it can be inherited |
|
1306 | # determine whether it can be inherited | |
1306 | if parentenvvar is not None: |
|
1307 | if parentenvvar is not None: | |
1307 | parentlock = encoding.environ.get(parentenvvar) |
|
1308 | parentlock = encoding.environ.get(parentenvvar) | |
1308 | try: |
|
1309 | try: | |
1309 | l = lockmod.lock(vfs, lockname, 0, releasefn=releasefn, |
|
1310 | l = lockmod.lock(vfs, lockname, 0, releasefn=releasefn, | |
1310 | acquirefn=acquirefn, desc=desc, |
|
1311 | acquirefn=acquirefn, desc=desc, | |
1311 | inheritchecker=inheritchecker, |
|
1312 | inheritchecker=inheritchecker, | |
1312 | parentlock=parentlock) |
|
1313 | parentlock=parentlock) | |
1313 | except error.LockHeld as inst: |
|
1314 | except error.LockHeld as inst: | |
1314 | if not wait: |
|
1315 | if not wait: | |
1315 | raise |
|
1316 | raise | |
1316 | # show more details for new-style locks |
|
1317 | # show more details for new-style locks | |
1317 | if ':' in inst.locker: |
|
1318 | if ':' in inst.locker: | |
1318 | host, pid = inst.locker.split(":", 1) |
|
1319 | host, pid = inst.locker.split(":", 1) | |
1319 | self.ui.warn( |
|
1320 | self.ui.warn( | |
1320 | _("waiting for lock on %s held by process %r " |
|
1321 | _("waiting for lock on %s held by process %r " | |
1321 | "on host %r\n") % (desc, pid, host)) |
|
1322 | "on host %r\n") % (desc, pid, host)) | |
1322 | else: |
|
1323 | else: | |
1323 | self.ui.warn(_("waiting for lock on %s held by %r\n") % |
|
1324 | self.ui.warn(_("waiting for lock on %s held by %r\n") % | |
1324 | (desc, inst.locker)) |
|
1325 | (desc, inst.locker)) | |
1325 | # default to 600 seconds timeout |
|
1326 | # default to 600 seconds timeout | |
1326 | l = lockmod.lock(vfs, lockname, |
|
1327 | l = lockmod.lock(vfs, lockname, | |
1327 | int(self.ui.config("ui", "timeout", "600")), |
|
1328 | int(self.ui.config("ui", "timeout", "600")), | |
1328 | releasefn=releasefn, acquirefn=acquirefn, |
|
1329 | releasefn=releasefn, acquirefn=acquirefn, | |
1329 | desc=desc) |
|
1330 | desc=desc) | |
1330 | self.ui.warn(_("got lock after %s seconds\n") % l.delay) |
|
1331 | self.ui.warn(_("got lock after %s seconds\n") % l.delay) | |
1331 | return l |
|
1332 | return l | |
1332 |
|
1333 | |||
1333 | def _afterlock(self, callback): |
|
1334 | def _afterlock(self, callback): | |
1334 | """add a callback to be run when the repository is fully unlocked |
|
1335 | """add a callback to be run when the repository is fully unlocked | |
1335 |
|
1336 | |||
1336 | The callback will be executed when the outermost lock is released |
|
1337 | The callback will be executed when the outermost lock is released | |
1337 | (with wlock being higher level than 'lock').""" |
|
1338 | (with wlock being higher level than 'lock').""" | |
1338 | for ref in (self._wlockref, self._lockref): |
|
1339 | for ref in (self._wlockref, self._lockref): | |
1339 | l = ref and ref() |
|
1340 | l = ref and ref() | |
1340 | if l and l.held: |
|
1341 | if l and l.held: | |
1341 | l.postrelease.append(callback) |
|
1342 | l.postrelease.append(callback) | |
1342 | break |
|
1343 | break | |
1343 | else: # no lock have been found. |
|
1344 | else: # no lock have been found. | |
1344 | callback() |
|
1345 | callback() | |
1345 |
|
1346 | |||
1346 | def lock(self, wait=True): |
|
1347 | def lock(self, wait=True): | |
1347 | '''Lock the repository store (.hg/store) and return a weak reference |
|
1348 | '''Lock the repository store (.hg/store) and return a weak reference | |
1348 | to the lock. Use this before modifying the store (e.g. committing or |
|
1349 | to the lock. Use this before modifying the store (e.g. committing or | |
1349 | stripping). If you are opening a transaction, get a lock as well.) |
|
1350 | stripping). If you are opening a transaction, get a lock as well.) | |
1350 |
|
1351 | |||
1351 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
1352 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
1352 | 'wlock' first to avoid a dead-lock hazard.''' |
|
1353 | 'wlock' first to avoid a dead-lock hazard.''' | |
1353 | l = self._currentlock(self._lockref) |
|
1354 | l = self._currentlock(self._lockref) | |
1354 | if l is not None: |
|
1355 | if l is not None: | |
1355 | l.lock() |
|
1356 | l.lock() | |
1356 | return l |
|
1357 | return l | |
1357 |
|
1358 | |||
1358 | l = self._lock(self.svfs, "lock", wait, None, |
|
1359 | l = self._lock(self.svfs, "lock", wait, None, | |
1359 | self.invalidate, _('repository %s') % self.origroot) |
|
1360 | self.invalidate, _('repository %s') % self.origroot) | |
1360 | self._lockref = weakref.ref(l) |
|
1361 | self._lockref = weakref.ref(l) | |
1361 | return l |
|
1362 | return l | |
1362 |
|
1363 | |||
1363 | def _wlockchecktransaction(self): |
|
1364 | def _wlockchecktransaction(self): | |
1364 | if self.currenttransaction() is not None: |
|
1365 | if self.currenttransaction() is not None: | |
1365 | raise error.LockInheritanceContractViolation( |
|
1366 | raise error.LockInheritanceContractViolation( | |
1366 | 'wlock cannot be inherited in the middle of a transaction') |
|
1367 | 'wlock cannot be inherited in the middle of a transaction') | |
1367 |
|
1368 | |||
1368 | def wlock(self, wait=True): |
|
1369 | def wlock(self, wait=True): | |
1369 | '''Lock the non-store parts of the repository (everything under |
|
1370 | '''Lock the non-store parts of the repository (everything under | |
1370 | .hg except .hg/store) and return a weak reference to the lock. |
|
1371 | .hg except .hg/store) and return a weak reference to the lock. | |
1371 |
|
1372 | |||
1372 | Use this before modifying files in .hg. |
|
1373 | Use this before modifying files in .hg. | |
1373 |
|
1374 | |||
1374 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
1375 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
1375 | 'wlock' first to avoid a dead-lock hazard.''' |
|
1376 | 'wlock' first to avoid a dead-lock hazard.''' | |
1376 | l = self._wlockref and self._wlockref() |
|
1377 | l = self._wlockref and self._wlockref() | |
1377 | if l is not None and l.held: |
|
1378 | if l is not None and l.held: | |
1378 | l.lock() |
|
1379 | l.lock() | |
1379 | return l |
|
1380 | return l | |
1380 |
|
1381 | |||
1381 | # We do not need to check for non-waiting lock acquisition. Such |
|
1382 | # We do not need to check for non-waiting lock acquisition. Such | |
1382 | # acquisition would not cause dead-lock as they would just fail. |
|
1383 | # acquisition would not cause dead-lock as they would just fail. | |
1383 | if wait and (self.ui.configbool('devel', 'all-warnings') |
|
1384 | if wait and (self.ui.configbool('devel', 'all-warnings') | |
1384 | or self.ui.configbool('devel', 'check-locks')): |
|
1385 | or self.ui.configbool('devel', 'check-locks')): | |
1385 | if self._currentlock(self._lockref) is not None: |
|
1386 | if self._currentlock(self._lockref) is not None: | |
1386 | self.ui.develwarn('"wlock" acquired after "lock"') |
|
1387 | self.ui.develwarn('"wlock" acquired after "lock"') | |
1387 |
|
1388 | |||
1388 | def unlock(): |
|
1389 | def unlock(): | |
1389 | if self.dirstate.pendingparentchange(): |
|
1390 | if self.dirstate.pendingparentchange(): | |
1390 | self.dirstate.invalidate() |
|
1391 | self.dirstate.invalidate() | |
1391 | else: |
|
1392 | else: | |
1392 | self.dirstate.write(None) |
|
1393 | self.dirstate.write(None) | |
1393 |
|
1394 | |||
1394 | self._filecache['dirstate'].refresh() |
|
1395 | self._filecache['dirstate'].refresh() | |
1395 |
|
1396 | |||
1396 | l = self._lock(self.vfs, "wlock", wait, unlock, |
|
1397 | l = self._lock(self.vfs, "wlock", wait, unlock, | |
1397 | self.invalidatedirstate, _('working directory of %s') % |
|
1398 | self.invalidatedirstate, _('working directory of %s') % | |
1398 | self.origroot, |
|
1399 | self.origroot, | |
1399 | inheritchecker=self._wlockchecktransaction, |
|
1400 | inheritchecker=self._wlockchecktransaction, | |
1400 | parentenvvar='HG_WLOCK_LOCKER') |
|
1401 | parentenvvar='HG_WLOCK_LOCKER') | |
1401 | self._wlockref = weakref.ref(l) |
|
1402 | self._wlockref = weakref.ref(l) | |
1402 | return l |
|
1403 | return l | |
1403 |
|
1404 | |||
1404 | def _currentlock(self, lockref): |
|
1405 | def _currentlock(self, lockref): | |
1405 | """Returns the lock if it's held, or None if it's not.""" |
|
1406 | """Returns the lock if it's held, or None if it's not.""" | |
1406 | if lockref is None: |
|
1407 | if lockref is None: | |
1407 | return None |
|
1408 | return None | |
1408 | l = lockref() |
|
1409 | l = lockref() | |
1409 | if l is None or not l.held: |
|
1410 | if l is None or not l.held: | |
1410 | return None |
|
1411 | return None | |
1411 | return l |
|
1412 | return l | |
1412 |
|
1413 | |||
1413 | def currentwlock(self): |
|
1414 | def currentwlock(self): | |
1414 | """Returns the wlock if it's held, or None if it's not.""" |
|
1415 | """Returns the wlock if it's held, or None if it's not.""" | |
1415 | return self._currentlock(self._wlockref) |
|
1416 | return self._currentlock(self._wlockref) | |
1416 |
|
1417 | |||
1417 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): |
|
1418 | def _filecommit(self, fctx, manifest1, manifest2, linkrev, tr, changelist): | |
1418 | """ |
|
1419 | """ | |
1419 | commit an individual file as part of a larger transaction |
|
1420 | commit an individual file as part of a larger transaction | |
1420 | """ |
|
1421 | """ | |
1421 |
|
1422 | |||
1422 | fname = fctx.path() |
|
1423 | fname = fctx.path() | |
1423 | fparent1 = manifest1.get(fname, nullid) |
|
1424 | fparent1 = manifest1.get(fname, nullid) | |
1424 | fparent2 = manifest2.get(fname, nullid) |
|
1425 | fparent2 = manifest2.get(fname, nullid) | |
1425 | if isinstance(fctx, context.filectx): |
|
1426 | if isinstance(fctx, context.filectx): | |
1426 | node = fctx.filenode() |
|
1427 | node = fctx.filenode() | |
1427 | if node in [fparent1, fparent2]: |
|
1428 | if node in [fparent1, fparent2]: | |
1428 | self.ui.debug('reusing %s filelog entry\n' % fname) |
|
1429 | self.ui.debug('reusing %s filelog entry\n' % fname) | |
1429 | if manifest1.flags(fname) != fctx.flags(): |
|
1430 | if manifest1.flags(fname) != fctx.flags(): | |
1430 | changelist.append(fname) |
|
1431 | changelist.append(fname) | |
1431 | return node |
|
1432 | return node | |
1432 |
|
1433 | |||
1433 | flog = self.file(fname) |
|
1434 | flog = self.file(fname) | |
1434 | meta = {} |
|
1435 | meta = {} | |
1435 | copy = fctx.renamed() |
|
1436 | copy = fctx.renamed() | |
1436 | if copy and copy[0] != fname: |
|
1437 | if copy and copy[0] != fname: | |
1437 | # Mark the new revision of this file as a copy of another |
|
1438 | # Mark the new revision of this file as a copy of another | |
1438 | # file. This copy data will effectively act as a parent |
|
1439 | # file. This copy data will effectively act as a parent | |
1439 | # of this new revision. If this is a merge, the first |
|
1440 | # of this new revision. If this is a merge, the first | |
1440 | # parent will be the nullid (meaning "look up the copy data") |
|
1441 | # parent will be the nullid (meaning "look up the copy data") | |
1441 | # and the second one will be the other parent. For example: |
|
1442 | # and the second one will be the other parent. For example: | |
1442 | # |
|
1443 | # | |
1443 | # 0 --- 1 --- 3 rev1 changes file foo |
|
1444 | # 0 --- 1 --- 3 rev1 changes file foo | |
1444 | # \ / rev2 renames foo to bar and changes it |
|
1445 | # \ / rev2 renames foo to bar and changes it | |
1445 | # \- 2 -/ rev3 should have bar with all changes and |
|
1446 | # \- 2 -/ rev3 should have bar with all changes and | |
1446 | # should record that bar descends from |
|
1447 | # should record that bar descends from | |
1447 | # bar in rev2 and foo in rev1 |
|
1448 | # bar in rev2 and foo in rev1 | |
1448 | # |
|
1449 | # | |
1449 | # this allows this merge to succeed: |
|
1450 | # this allows this merge to succeed: | |
1450 | # |
|
1451 | # | |
1451 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 |
|
1452 | # 0 --- 1 --- 3 rev4 reverts the content change from rev2 | |
1452 | # \ / merging rev3 and rev4 should use bar@rev2 |
|
1453 | # \ / merging rev3 and rev4 should use bar@rev2 | |
1453 | # \- 2 --- 4 as the merge base |
|
1454 | # \- 2 --- 4 as the merge base | |
1454 | # |
|
1455 | # | |
1455 |
|
1456 | |||
1456 | cfname = copy[0] |
|
1457 | cfname = copy[0] | |
1457 | crev = manifest1.get(cfname) |
|
1458 | crev = manifest1.get(cfname) | |
1458 | newfparent = fparent2 |
|
1459 | newfparent = fparent2 | |
1459 |
|
1460 | |||
1460 | if manifest2: # branch merge |
|
1461 | if manifest2: # branch merge | |
1461 | if fparent2 == nullid or crev is None: # copied on remote side |
|
1462 | if fparent2 == nullid or crev is None: # copied on remote side | |
1462 | if cfname in manifest2: |
|
1463 | if cfname in manifest2: | |
1463 | crev = manifest2[cfname] |
|
1464 | crev = manifest2[cfname] | |
1464 | newfparent = fparent1 |
|
1465 | newfparent = fparent1 | |
1465 |
|
1466 | |||
1466 | # Here, we used to search backwards through history to try to find |
|
1467 | # Here, we used to search backwards through history to try to find | |
1467 | # where the file copy came from if the source of a copy was not in |
|
1468 | # where the file copy came from if the source of a copy was not in | |
1468 | # the parent directory. However, this doesn't actually make sense to |
|
1469 | # the parent directory. However, this doesn't actually make sense to | |
1469 | # do (what does a copy from something not in your working copy even |
|
1470 | # do (what does a copy from something not in your working copy even | |
1470 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn |
|
1471 | # mean?) and it causes bugs (eg, issue4476). Instead, we will warn | |
1471 | # the user that copy information was dropped, so if they didn't |
|
1472 | # the user that copy information was dropped, so if they didn't | |
1472 | # expect this outcome it can be fixed, but this is the correct |
|
1473 | # expect this outcome it can be fixed, but this is the correct | |
1473 | # behavior in this circumstance. |
|
1474 | # behavior in this circumstance. | |
1474 |
|
1475 | |||
1475 | if crev: |
|
1476 | if crev: | |
1476 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) |
|
1477 | self.ui.debug(" %s: copy %s:%s\n" % (fname, cfname, hex(crev))) | |
1477 | meta["copy"] = cfname |
|
1478 | meta["copy"] = cfname | |
1478 | meta["copyrev"] = hex(crev) |
|
1479 | meta["copyrev"] = hex(crev) | |
1479 | fparent1, fparent2 = nullid, newfparent |
|
1480 | fparent1, fparent2 = nullid, newfparent | |
1480 | else: |
|
1481 | else: | |
1481 | self.ui.warn(_("warning: can't find ancestor for '%s' " |
|
1482 | self.ui.warn(_("warning: can't find ancestor for '%s' " | |
1482 | "copied from '%s'!\n") % (fname, cfname)) |
|
1483 | "copied from '%s'!\n") % (fname, cfname)) | |
1483 |
|
1484 | |||
1484 | elif fparent1 == nullid: |
|
1485 | elif fparent1 == nullid: | |
1485 | fparent1, fparent2 = fparent2, nullid |
|
1486 | fparent1, fparent2 = fparent2, nullid | |
1486 | elif fparent2 != nullid: |
|
1487 | elif fparent2 != nullid: | |
1487 | # is one parent an ancestor of the other? |
|
1488 | # is one parent an ancestor of the other? | |
1488 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) |
|
1489 | fparentancestors = flog.commonancestorsheads(fparent1, fparent2) | |
1489 | if fparent1 in fparentancestors: |
|
1490 | if fparent1 in fparentancestors: | |
1490 | fparent1, fparent2 = fparent2, nullid |
|
1491 | fparent1, fparent2 = fparent2, nullid | |
1491 | elif fparent2 in fparentancestors: |
|
1492 | elif fparent2 in fparentancestors: | |
1492 | fparent2 = nullid |
|
1493 | fparent2 = nullid | |
1493 |
|
1494 | |||
1494 | # is the file changed? |
|
1495 | # is the file changed? | |
1495 | text = fctx.data() |
|
1496 | text = fctx.data() | |
1496 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: |
|
1497 | if fparent2 != nullid or flog.cmp(fparent1, text) or meta: | |
1497 | changelist.append(fname) |
|
1498 | changelist.append(fname) | |
1498 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) |
|
1499 | return flog.add(text, meta, tr, linkrev, fparent1, fparent2) | |
1499 | # are just the flags changed during merge? |
|
1500 | # are just the flags changed during merge? | |
1500 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): |
|
1501 | elif fname in manifest1 and manifest1.flags(fname) != fctx.flags(): | |
1501 | changelist.append(fname) |
|
1502 | changelist.append(fname) | |
1502 |
|
1503 | |||
1503 | return fparent1 |
|
1504 | return fparent1 | |
1504 |
|
1505 | |||
1505 | def checkcommitpatterns(self, wctx, vdirs, match, status, fail): |
|
1506 | def checkcommitpatterns(self, wctx, vdirs, match, status, fail): | |
1506 | """check for commit arguments that aren't committable""" |
|
1507 | """check for commit arguments that aren't committable""" | |
1507 | if match.isexact() or match.prefix(): |
|
1508 | if match.isexact() or match.prefix(): | |
1508 | matched = set(status.modified + status.added + status.removed) |
|
1509 | matched = set(status.modified + status.added + status.removed) | |
1509 |
|
1510 | |||
1510 | for f in match.files(): |
|
1511 | for f in match.files(): | |
1511 | f = self.dirstate.normalize(f) |
|
1512 | f = self.dirstate.normalize(f) | |
1512 | if f == '.' or f in matched or f in wctx.substate: |
|
1513 | if f == '.' or f in matched or f in wctx.substate: | |
1513 | continue |
|
1514 | continue | |
1514 | if f in status.deleted: |
|
1515 | if f in status.deleted: | |
1515 | fail(f, _('file not found!')) |
|
1516 | fail(f, _('file not found!')) | |
1516 | if f in vdirs: # visited directory |
|
1517 | if f in vdirs: # visited directory | |
1517 | d = f + '/' |
|
1518 | d = f + '/' | |
1518 | for mf in matched: |
|
1519 | for mf in matched: | |
1519 | if mf.startswith(d): |
|
1520 | if mf.startswith(d): | |
1520 | break |
|
1521 | break | |
1521 | else: |
|
1522 | else: | |
1522 | fail(f, _("no match under directory!")) |
|
1523 | fail(f, _("no match under directory!")) | |
1523 | elif f not in self.dirstate: |
|
1524 | elif f not in self.dirstate: | |
1524 | fail(f, _("file not tracked!")) |
|
1525 | fail(f, _("file not tracked!")) | |
1525 |
|
1526 | |||
1526 | @unfilteredmethod |
|
1527 | @unfilteredmethod | |
1527 | def commit(self, text="", user=None, date=None, match=None, force=False, |
|
1528 | def commit(self, text="", user=None, date=None, match=None, force=False, | |
1528 | editor=False, extra=None): |
|
1529 | editor=False, extra=None): | |
1529 | """Add a new revision to current repository. |
|
1530 | """Add a new revision to current repository. | |
1530 |
|
1531 | |||
1531 | Revision information is gathered from the working directory, |
|
1532 | Revision information is gathered from the working directory, | |
1532 | match can be used to filter the committed files. If editor is |
|
1533 | match can be used to filter the committed files. If editor is | |
1533 | supplied, it is called to get a commit message. |
|
1534 | supplied, it is called to get a commit message. | |
1534 | """ |
|
1535 | """ | |
1535 | if extra is None: |
|
1536 | if extra is None: | |
1536 | extra = {} |
|
1537 | extra = {} | |
1537 |
|
1538 | |||
1538 | def fail(f, msg): |
|
1539 | def fail(f, msg): | |
1539 | raise error.Abort('%s: %s' % (f, msg)) |
|
1540 | raise error.Abort('%s: %s' % (f, msg)) | |
1540 |
|
1541 | |||
1541 | if not match: |
|
1542 | if not match: | |
1542 | match = matchmod.always(self.root, '') |
|
1543 | match = matchmod.always(self.root, '') | |
1543 |
|
1544 | |||
1544 | if not force: |
|
1545 | if not force: | |
1545 | vdirs = [] |
|
1546 | vdirs = [] | |
1546 | match.explicitdir = vdirs.append |
|
1547 | match.explicitdir = vdirs.append | |
1547 | match.bad = fail |
|
1548 | match.bad = fail | |
1548 |
|
1549 | |||
1549 | wlock = lock = tr = None |
|
1550 | wlock = lock = tr = None | |
1550 | try: |
|
1551 | try: | |
1551 | wlock = self.wlock() |
|
1552 | wlock = self.wlock() | |
1552 | lock = self.lock() # for recent changelog (see issue4368) |
|
1553 | lock = self.lock() # for recent changelog (see issue4368) | |
1553 |
|
1554 | |||
1554 | wctx = self[None] |
|
1555 | wctx = self[None] | |
1555 | merge = len(wctx.parents()) > 1 |
|
1556 | merge = len(wctx.parents()) > 1 | |
1556 |
|
1557 | |||
1557 | if not force and merge and match.ispartial(): |
|
1558 | if not force and merge and match.ispartial(): | |
1558 | raise error.Abort(_('cannot partially commit a merge ' |
|
1559 | raise error.Abort(_('cannot partially commit a merge ' | |
1559 | '(do not specify files or patterns)')) |
|
1560 | '(do not specify files or patterns)')) | |
1560 |
|
1561 | |||
1561 | status = self.status(match=match, clean=force) |
|
1562 | status = self.status(match=match, clean=force) | |
1562 | if force: |
|
1563 | if force: | |
1563 | status.modified.extend(status.clean) # mq may commit clean files |
|
1564 | status.modified.extend(status.clean) # mq may commit clean files | |
1564 |
|
1565 | |||
1565 | # check subrepos |
|
1566 | # check subrepos | |
1566 | subs = [] |
|
1567 | subs = [] | |
1567 | commitsubs = set() |
|
1568 | commitsubs = set() | |
1568 | newstate = wctx.substate.copy() |
|
1569 | newstate = wctx.substate.copy() | |
1569 | # only manage subrepos and .hgsubstate if .hgsub is present |
|
1570 | # only manage subrepos and .hgsubstate if .hgsub is present | |
1570 | if '.hgsub' in wctx: |
|
1571 | if '.hgsub' in wctx: | |
1571 | # we'll decide whether to track this ourselves, thanks |
|
1572 | # we'll decide whether to track this ourselves, thanks | |
1572 | for c in status.modified, status.added, status.removed: |
|
1573 | for c in status.modified, status.added, status.removed: | |
1573 | if '.hgsubstate' in c: |
|
1574 | if '.hgsubstate' in c: | |
1574 | c.remove('.hgsubstate') |
|
1575 | c.remove('.hgsubstate') | |
1575 |
|
1576 | |||
1576 | # compare current state to last committed state |
|
1577 | # compare current state to last committed state | |
1577 | # build new substate based on last committed state |
|
1578 | # build new substate based on last committed state | |
1578 | oldstate = wctx.p1().substate |
|
1579 | oldstate = wctx.p1().substate | |
1579 | for s in sorted(newstate.keys()): |
|
1580 | for s in sorted(newstate.keys()): | |
1580 | if not match(s): |
|
1581 | if not match(s): | |
1581 | # ignore working copy, use old state if present |
|
1582 | # ignore working copy, use old state if present | |
1582 | if s in oldstate: |
|
1583 | if s in oldstate: | |
1583 | newstate[s] = oldstate[s] |
|
1584 | newstate[s] = oldstate[s] | |
1584 | continue |
|
1585 | continue | |
1585 | if not force: |
|
1586 | if not force: | |
1586 | raise error.Abort( |
|
1587 | raise error.Abort( | |
1587 | _("commit with new subrepo %s excluded") % s) |
|
1588 | _("commit with new subrepo %s excluded") % s) | |
1588 | dirtyreason = wctx.sub(s).dirtyreason(True) |
|
1589 | dirtyreason = wctx.sub(s).dirtyreason(True) | |
1589 | if dirtyreason: |
|
1590 | if dirtyreason: | |
1590 | if not self.ui.configbool('ui', 'commitsubrepos'): |
|
1591 | if not self.ui.configbool('ui', 'commitsubrepos'): | |
1591 | raise error.Abort(dirtyreason, |
|
1592 | raise error.Abort(dirtyreason, | |
1592 | hint=_("use --subrepos for recursive commit")) |
|
1593 | hint=_("use --subrepos for recursive commit")) | |
1593 | subs.append(s) |
|
1594 | subs.append(s) | |
1594 | commitsubs.add(s) |
|
1595 | commitsubs.add(s) | |
1595 | else: |
|
1596 | else: | |
1596 | bs = wctx.sub(s).basestate() |
|
1597 | bs = wctx.sub(s).basestate() | |
1597 | newstate[s] = (newstate[s][0], bs, newstate[s][2]) |
|
1598 | newstate[s] = (newstate[s][0], bs, newstate[s][2]) | |
1598 | if oldstate.get(s, (None, None, None))[1] != bs: |
|
1599 | if oldstate.get(s, (None, None, None))[1] != bs: | |
1599 | subs.append(s) |
|
1600 | subs.append(s) | |
1600 |
|
1601 | |||
1601 | # check for removed subrepos |
|
1602 | # check for removed subrepos | |
1602 | for p in wctx.parents(): |
|
1603 | for p in wctx.parents(): | |
1603 | r = [s for s in p.substate if s not in newstate] |
|
1604 | r = [s for s in p.substate if s not in newstate] | |
1604 | subs += [s for s in r if match(s)] |
|
1605 | subs += [s for s in r if match(s)] | |
1605 | if subs: |
|
1606 | if subs: | |
1606 | if (not match('.hgsub') and |
|
1607 | if (not match('.hgsub') and | |
1607 | '.hgsub' in (wctx.modified() + wctx.added())): |
|
1608 | '.hgsub' in (wctx.modified() + wctx.added())): | |
1608 | raise error.Abort( |
|
1609 | raise error.Abort( | |
1609 | _("can't commit subrepos without .hgsub")) |
|
1610 | _("can't commit subrepos without .hgsub")) | |
1610 | status.modified.insert(0, '.hgsubstate') |
|
1611 | status.modified.insert(0, '.hgsubstate') | |
1611 |
|
1612 | |||
1612 | elif '.hgsub' in status.removed: |
|
1613 | elif '.hgsub' in status.removed: | |
1613 | # clean up .hgsubstate when .hgsub is removed |
|
1614 | # clean up .hgsubstate when .hgsub is removed | |
1614 | if ('.hgsubstate' in wctx and |
|
1615 | if ('.hgsubstate' in wctx and | |
1615 | '.hgsubstate' not in (status.modified + status.added + |
|
1616 | '.hgsubstate' not in (status.modified + status.added + | |
1616 | status.removed)): |
|
1617 | status.removed)): | |
1617 | status.removed.insert(0, '.hgsubstate') |
|
1618 | status.removed.insert(0, '.hgsubstate') | |
1618 |
|
1619 | |||
1619 | # make sure all explicit patterns are matched |
|
1620 | # make sure all explicit patterns are matched | |
1620 | if not force: |
|
1621 | if not force: | |
1621 | self.checkcommitpatterns(wctx, vdirs, match, status, fail) |
|
1622 | self.checkcommitpatterns(wctx, vdirs, match, status, fail) | |
1622 |
|
1623 | |||
1623 | cctx = context.workingcommitctx(self, status, |
|
1624 | cctx = context.workingcommitctx(self, status, | |
1624 | text, user, date, extra) |
|
1625 | text, user, date, extra) | |
1625 |
|
1626 | |||
1626 | # internal config: ui.allowemptycommit |
|
1627 | # internal config: ui.allowemptycommit | |
1627 | allowemptycommit = (wctx.branch() != wctx.p1().branch() |
|
1628 | allowemptycommit = (wctx.branch() != wctx.p1().branch() | |
1628 | or extra.get('close') or merge or cctx.files() |
|
1629 | or extra.get('close') or merge or cctx.files() | |
1629 | or self.ui.configbool('ui', 'allowemptycommit')) |
|
1630 | or self.ui.configbool('ui', 'allowemptycommit')) | |
1630 | if not allowemptycommit: |
|
1631 | if not allowemptycommit: | |
1631 | return None |
|
1632 | return None | |
1632 |
|
1633 | |||
1633 | if merge and cctx.deleted(): |
|
1634 | if merge and cctx.deleted(): | |
1634 | raise error.Abort(_("cannot commit merge with missing files")) |
|
1635 | raise error.Abort(_("cannot commit merge with missing files")) | |
1635 |
|
1636 | |||
1636 | ms = mergemod.mergestate.read(self) |
|
1637 | ms = mergemod.mergestate.read(self) | |
1637 | mergeutil.checkunresolved(ms) |
|
1638 | mergeutil.checkunresolved(ms) | |
1638 |
|
1639 | |||
1639 | if editor: |
|
1640 | if editor: | |
1640 | cctx._text = editor(self, cctx, subs) |
|
1641 | cctx._text = editor(self, cctx, subs) | |
1641 | edited = (text != cctx._text) |
|
1642 | edited = (text != cctx._text) | |
1642 |
|
1643 | |||
1643 | # Save commit message in case this transaction gets rolled back |
|
1644 | # Save commit message in case this transaction gets rolled back | |
1644 | # (e.g. by a pretxncommit hook). Leave the content alone on |
|
1645 | # (e.g. by a pretxncommit hook). Leave the content alone on | |
1645 | # the assumption that the user will use the same editor again. |
|
1646 | # the assumption that the user will use the same editor again. | |
1646 | msgfn = self.savecommitmessage(cctx._text) |
|
1647 | msgfn = self.savecommitmessage(cctx._text) | |
1647 |
|
1648 | |||
1648 | # commit subs and write new state |
|
1649 | # commit subs and write new state | |
1649 | if subs: |
|
1650 | if subs: | |
1650 | for s in sorted(commitsubs): |
|
1651 | for s in sorted(commitsubs): | |
1651 | sub = wctx.sub(s) |
|
1652 | sub = wctx.sub(s) | |
1652 | self.ui.status(_('committing subrepository %s\n') % |
|
1653 | self.ui.status(_('committing subrepository %s\n') % | |
1653 | subrepo.subrelpath(sub)) |
|
1654 | subrepo.subrelpath(sub)) | |
1654 | sr = sub.commit(cctx._text, user, date) |
|
1655 | sr = sub.commit(cctx._text, user, date) | |
1655 | newstate[s] = (newstate[s][0], sr) |
|
1656 | newstate[s] = (newstate[s][0], sr) | |
1656 | subrepo.writestate(self, newstate) |
|
1657 | subrepo.writestate(self, newstate) | |
1657 |
|
1658 | |||
1658 | p1, p2 = self.dirstate.parents() |
|
1659 | p1, p2 = self.dirstate.parents() | |
1659 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') |
|
1660 | hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '') | |
1660 | try: |
|
1661 | try: | |
1661 | self.hook("precommit", throw=True, parent1=hookp1, |
|
1662 | self.hook("precommit", throw=True, parent1=hookp1, | |
1662 | parent2=hookp2) |
|
1663 | parent2=hookp2) | |
1663 | tr = self.transaction('commit') |
|
1664 | tr = self.transaction('commit') | |
1664 | ret = self.commitctx(cctx, True) |
|
1665 | ret = self.commitctx(cctx, True) | |
1665 | except: # re-raises |
|
1666 | except: # re-raises | |
1666 | if edited: |
|
1667 | if edited: | |
1667 | self.ui.write( |
|
1668 | self.ui.write( | |
1668 | _('note: commit message saved in %s\n') % msgfn) |
|
1669 | _('note: commit message saved in %s\n') % msgfn) | |
1669 | raise |
|
1670 | raise | |
1670 | # update bookmarks, dirstate and mergestate |
|
1671 | # update bookmarks, dirstate and mergestate | |
1671 | bookmarks.update(self, [p1, p2], ret) |
|
1672 | bookmarks.update(self, [p1, p2], ret) | |
1672 | cctx.markcommitted(ret) |
|
1673 | cctx.markcommitted(ret) | |
1673 | ms.reset() |
|
1674 | ms.reset() | |
1674 | tr.close() |
|
1675 | tr.close() | |
1675 |
|
1676 | |||
1676 | finally: |
|
1677 | finally: | |
1677 | lockmod.release(tr, lock, wlock) |
|
1678 | lockmod.release(tr, lock, wlock) | |
1678 |
|
1679 | |||
1679 | def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2): |
|
1680 | def commithook(node=hex(ret), parent1=hookp1, parent2=hookp2): | |
1680 | # hack for command that use a temporary commit (eg: histedit) |
|
1681 | # hack for command that use a temporary commit (eg: histedit) | |
1681 | # temporary commit got stripped before hook release |
|
1682 | # temporary commit got stripped before hook release | |
1682 | if self.changelog.hasnode(ret): |
|
1683 | if self.changelog.hasnode(ret): | |
1683 | self.hook("commit", node=node, parent1=parent1, |
|
1684 | self.hook("commit", node=node, parent1=parent1, | |
1684 | parent2=parent2) |
|
1685 | parent2=parent2) | |
1685 | self._afterlock(commithook) |
|
1686 | self._afterlock(commithook) | |
1686 | return ret |
|
1687 | return ret | |
1687 |
|
1688 | |||
1688 | @unfilteredmethod |
|
1689 | @unfilteredmethod | |
1689 | def commitctx(self, ctx, error=False): |
|
1690 | def commitctx(self, ctx, error=False): | |
1690 | """Add a new revision to current repository. |
|
1691 | """Add a new revision to current repository. | |
1691 | Revision information is passed via the context argument. |
|
1692 | Revision information is passed via the context argument. | |
1692 | """ |
|
1693 | """ | |
1693 |
|
1694 | |||
1694 | tr = None |
|
1695 | tr = None | |
1695 | p1, p2 = ctx.p1(), ctx.p2() |
|
1696 | p1, p2 = ctx.p1(), ctx.p2() | |
1696 | user = ctx.user() |
|
1697 | user = ctx.user() | |
1697 |
|
1698 | |||
1698 | lock = self.lock() |
|
1699 | lock = self.lock() | |
1699 | try: |
|
1700 | try: | |
1700 | tr = self.transaction("commit") |
|
1701 | tr = self.transaction("commit") | |
1701 | trp = weakref.proxy(tr) |
|
1702 | trp = weakref.proxy(tr) | |
1702 |
|
1703 | |||
1703 | if ctx.manifestnode(): |
|
1704 | if ctx.manifestnode(): | |
1704 | # reuse an existing manifest revision |
|
1705 | # reuse an existing manifest revision | |
1705 | mn = ctx.manifestnode() |
|
1706 | mn = ctx.manifestnode() | |
1706 | files = ctx.files() |
|
1707 | files = ctx.files() | |
1707 | elif ctx.files(): |
|
1708 | elif ctx.files(): | |
1708 | m1ctx = p1.manifestctx() |
|
1709 | m1ctx = p1.manifestctx() | |
1709 | m2ctx = p2.manifestctx() |
|
1710 | m2ctx = p2.manifestctx() | |
1710 | mctx = m1ctx.copy() |
|
1711 | mctx = m1ctx.copy() | |
1711 |
|
1712 | |||
1712 | m = mctx.read() |
|
1713 | m = mctx.read() | |
1713 | m1 = m1ctx.read() |
|
1714 | m1 = m1ctx.read() | |
1714 | m2 = m2ctx.read() |
|
1715 | m2 = m2ctx.read() | |
1715 |
|
1716 | |||
1716 | # check in files |
|
1717 | # check in files | |
1717 | added = [] |
|
1718 | added = [] | |
1718 | changed = [] |
|
1719 | changed = [] | |
1719 | removed = list(ctx.removed()) |
|
1720 | removed = list(ctx.removed()) | |
1720 | linkrev = len(self) |
|
1721 | linkrev = len(self) | |
1721 | self.ui.note(_("committing files:\n")) |
|
1722 | self.ui.note(_("committing files:\n")) | |
1722 | for f in sorted(ctx.modified() + ctx.added()): |
|
1723 | for f in sorted(ctx.modified() + ctx.added()): | |
1723 | self.ui.note(f + "\n") |
|
1724 | self.ui.note(f + "\n") | |
1724 | try: |
|
1725 | try: | |
1725 | fctx = ctx[f] |
|
1726 | fctx = ctx[f] | |
1726 | if fctx is None: |
|
1727 | if fctx is None: | |
1727 | removed.append(f) |
|
1728 | removed.append(f) | |
1728 | else: |
|
1729 | else: | |
1729 | added.append(f) |
|
1730 | added.append(f) | |
1730 | m[f] = self._filecommit(fctx, m1, m2, linkrev, |
|
1731 | m[f] = self._filecommit(fctx, m1, m2, linkrev, | |
1731 | trp, changed) |
|
1732 | trp, changed) | |
1732 | m.setflag(f, fctx.flags()) |
|
1733 | m.setflag(f, fctx.flags()) | |
1733 | except OSError as inst: |
|
1734 | except OSError as inst: | |
1734 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
1735 | self.ui.warn(_("trouble committing %s!\n") % f) | |
1735 | raise |
|
1736 | raise | |
1736 | except IOError as inst: |
|
1737 | except IOError as inst: | |
1737 | errcode = getattr(inst, 'errno', errno.ENOENT) |
|
1738 | errcode = getattr(inst, 'errno', errno.ENOENT) | |
1738 | if error or errcode and errcode != errno.ENOENT: |
|
1739 | if error or errcode and errcode != errno.ENOENT: | |
1739 | self.ui.warn(_("trouble committing %s!\n") % f) |
|
1740 | self.ui.warn(_("trouble committing %s!\n") % f) | |
1740 | raise |
|
1741 | raise | |
1741 |
|
1742 | |||
1742 | # update manifest |
|
1743 | # update manifest | |
1743 | self.ui.note(_("committing manifest\n")) |
|
1744 | self.ui.note(_("committing manifest\n")) | |
1744 | removed = [f for f in sorted(removed) if f in m1 or f in m2] |
|
1745 | removed = [f for f in sorted(removed) if f in m1 or f in m2] | |
1745 | drop = [f for f in removed if f in m] |
|
1746 | drop = [f for f in removed if f in m] | |
1746 | for f in drop: |
|
1747 | for f in drop: | |
1747 | del m[f] |
|
1748 | del m[f] | |
1748 | mn = mctx.write(trp, linkrev, |
|
1749 | mn = mctx.write(trp, linkrev, | |
1749 | p1.manifestnode(), p2.manifestnode(), |
|
1750 | p1.manifestnode(), p2.manifestnode(), | |
1750 | added, drop) |
|
1751 | added, drop) | |
1751 | files = changed + removed |
|
1752 | files = changed + removed | |
1752 | else: |
|
1753 | else: | |
1753 | mn = p1.manifestnode() |
|
1754 | mn = p1.manifestnode() | |
1754 | files = [] |
|
1755 | files = [] | |
1755 |
|
1756 | |||
1756 | # update changelog |
|
1757 | # update changelog | |
1757 | self.ui.note(_("committing changelog\n")) |
|
1758 | self.ui.note(_("committing changelog\n")) | |
1758 | self.changelog.delayupdate(tr) |
|
1759 | self.changelog.delayupdate(tr) | |
1759 | n = self.changelog.add(mn, files, ctx.description(), |
|
1760 | n = self.changelog.add(mn, files, ctx.description(), | |
1760 | trp, p1.node(), p2.node(), |
|
1761 | trp, p1.node(), p2.node(), | |
1761 | user, ctx.date(), ctx.extra().copy()) |
|
1762 | user, ctx.date(), ctx.extra().copy()) | |
1762 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' |
|
1763 | xp1, xp2 = p1.hex(), p2 and p2.hex() or '' | |
1763 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, |
|
1764 | self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1, | |
1764 | parent2=xp2) |
|
1765 | parent2=xp2) | |
1765 | # set the new commit is proper phase |
|
1766 | # set the new commit is proper phase | |
1766 | targetphase = subrepo.newcommitphase(self.ui, ctx) |
|
1767 | targetphase = subrepo.newcommitphase(self.ui, ctx) | |
1767 | if targetphase: |
|
1768 | if targetphase: | |
1768 | # retract boundary do not alter parent changeset. |
|
1769 | # retract boundary do not alter parent changeset. | |
1769 | # if a parent have higher the resulting phase will |
|
1770 | # if a parent have higher the resulting phase will | |
1770 | # be compliant anyway |
|
1771 | # be compliant anyway | |
1771 | # |
|
1772 | # | |
1772 | # if minimal phase was 0 we don't need to retract anything |
|
1773 | # if minimal phase was 0 we don't need to retract anything | |
1773 | phases.retractboundary(self, tr, targetphase, [n]) |
|
1774 | phases.retractboundary(self, tr, targetphase, [n]) | |
1774 | tr.close() |
|
1775 | tr.close() | |
1775 | branchmap.updatecache(self.filtered('served')) |
|
1776 | branchmap.updatecache(self.filtered('served')) | |
1776 | return n |
|
1777 | return n | |
1777 | finally: |
|
1778 | finally: | |
1778 | if tr: |
|
1779 | if tr: | |
1779 | tr.release() |
|
1780 | tr.release() | |
1780 | lock.release() |
|
1781 | lock.release() | |
1781 |
|
1782 | |||
1782 | @unfilteredmethod |
|
1783 | @unfilteredmethod | |
1783 | def destroying(self): |
|
1784 | def destroying(self): | |
1784 | '''Inform the repository that nodes are about to be destroyed. |
|
1785 | '''Inform the repository that nodes are about to be destroyed. | |
1785 | Intended for use by strip and rollback, so there's a common |
|
1786 | Intended for use by strip and rollback, so there's a common | |
1786 | place for anything that has to be done before destroying history. |
|
1787 | place for anything that has to be done before destroying history. | |
1787 |
|
1788 | |||
1788 | This is mostly useful for saving state that is in memory and waiting |
|
1789 | This is mostly useful for saving state that is in memory and waiting | |
1789 | to be flushed when the current lock is released. Because a call to |
|
1790 | to be flushed when the current lock is released. Because a call to | |
1790 | destroyed is imminent, the repo will be invalidated causing those |
|
1791 | destroyed is imminent, the repo will be invalidated causing those | |
1791 | changes to stay in memory (waiting for the next unlock), or vanish |
|
1792 | changes to stay in memory (waiting for the next unlock), or vanish | |
1792 | completely. |
|
1793 | completely. | |
1793 | ''' |
|
1794 | ''' | |
1794 | # When using the same lock to commit and strip, the phasecache is left |
|
1795 | # When using the same lock to commit and strip, the phasecache is left | |
1795 | # dirty after committing. Then when we strip, the repo is invalidated, |
|
1796 | # dirty after committing. Then when we strip, the repo is invalidated, | |
1796 | # causing those changes to disappear. |
|
1797 | # causing those changes to disappear. | |
1797 | if '_phasecache' in vars(self): |
|
1798 | if '_phasecache' in vars(self): | |
1798 | self._phasecache.write() |
|
1799 | self._phasecache.write() | |
1799 |
|
1800 | |||
1800 | @unfilteredmethod |
|
1801 | @unfilteredmethod | |
1801 | def destroyed(self): |
|
1802 | def destroyed(self): | |
1802 | '''Inform the repository that nodes have been destroyed. |
|
1803 | '''Inform the repository that nodes have been destroyed. | |
1803 | Intended for use by strip and rollback, so there's a common |
|
1804 | Intended for use by strip and rollback, so there's a common | |
1804 | place for anything that has to be done after destroying history. |
|
1805 | place for anything that has to be done after destroying history. | |
1805 | ''' |
|
1806 | ''' | |
1806 | # When one tries to: |
|
1807 | # When one tries to: | |
1807 | # 1) destroy nodes thus calling this method (e.g. strip) |
|
1808 | # 1) destroy nodes thus calling this method (e.g. strip) | |
1808 | # 2) use phasecache somewhere (e.g. commit) |
|
1809 | # 2) use phasecache somewhere (e.g. commit) | |
1809 | # |
|
1810 | # | |
1810 | # then 2) will fail because the phasecache contains nodes that were |
|
1811 | # then 2) will fail because the phasecache contains nodes that were | |
1811 | # removed. We can either remove phasecache from the filecache, |
|
1812 | # removed. We can either remove phasecache from the filecache, | |
1812 | # causing it to reload next time it is accessed, or simply filter |
|
1813 | # causing it to reload next time it is accessed, or simply filter | |
1813 | # the removed nodes now and write the updated cache. |
|
1814 | # the removed nodes now and write the updated cache. | |
1814 | self._phasecache.filterunknown(self) |
|
1815 | self._phasecache.filterunknown(self) | |
1815 | self._phasecache.write() |
|
1816 | self._phasecache.write() | |
1816 |
|
1817 | |||
1817 | # update the 'served' branch cache to help read only server process |
|
1818 | # update the 'served' branch cache to help read only server process | |
1818 | # Thanks to branchcache collaboration this is done from the nearest |
|
1819 | # Thanks to branchcache collaboration this is done from the nearest | |
1819 | # filtered subset and it is expected to be fast. |
|
1820 | # filtered subset and it is expected to be fast. | |
1820 | branchmap.updatecache(self.filtered('served')) |
|
1821 | branchmap.updatecache(self.filtered('served')) | |
1821 |
|
1822 | |||
1822 | # Ensure the persistent tag cache is updated. Doing it now |
|
1823 | # Ensure the persistent tag cache is updated. Doing it now | |
1823 | # means that the tag cache only has to worry about destroyed |
|
1824 | # means that the tag cache only has to worry about destroyed | |
1824 | # heads immediately after a strip/rollback. That in turn |
|
1825 | # heads immediately after a strip/rollback. That in turn | |
1825 | # guarantees that "cachetip == currenttip" (comparing both rev |
|
1826 | # guarantees that "cachetip == currenttip" (comparing both rev | |
1826 | # and node) always means no nodes have been added or destroyed. |
|
1827 | # and node) always means no nodes have been added or destroyed. | |
1827 |
|
1828 | |||
1828 | # XXX this is suboptimal when qrefresh'ing: we strip the current |
|
1829 | # XXX this is suboptimal when qrefresh'ing: we strip the current | |
1829 | # head, refresh the tag cache, then immediately add a new head. |
|
1830 | # head, refresh the tag cache, then immediately add a new head. | |
1830 | # But I think doing it this way is necessary for the "instant |
|
1831 | # But I think doing it this way is necessary for the "instant | |
1831 | # tag cache retrieval" case to work. |
|
1832 | # tag cache retrieval" case to work. | |
1832 | self.invalidate() |
|
1833 | self.invalidate() | |
1833 |
|
1834 | |||
1834 | def walk(self, match, node=None): |
|
1835 | def walk(self, match, node=None): | |
1835 | ''' |
|
1836 | ''' | |
1836 | walk recursively through the directory tree or a given |
|
1837 | walk recursively through the directory tree or a given | |
1837 | changeset, finding all files matched by the match |
|
1838 | changeset, finding all files matched by the match | |
1838 | function |
|
1839 | function | |
1839 | ''' |
|
1840 | ''' | |
1840 | return self[node].walk(match) |
|
1841 | return self[node].walk(match) | |
1841 |
|
1842 | |||
1842 | def status(self, node1='.', node2=None, match=None, |
|
1843 | def status(self, node1='.', node2=None, match=None, | |
1843 | ignored=False, clean=False, unknown=False, |
|
1844 | ignored=False, clean=False, unknown=False, | |
1844 | listsubrepos=False): |
|
1845 | listsubrepos=False): | |
1845 | '''a convenience method that calls node1.status(node2)''' |
|
1846 | '''a convenience method that calls node1.status(node2)''' | |
1846 | return self[node1].status(node2, match, ignored, clean, unknown, |
|
1847 | return self[node1].status(node2, match, ignored, clean, unknown, | |
1847 | listsubrepos) |
|
1848 | listsubrepos) | |
1848 |
|
1849 | |||
1849 | def heads(self, start=None): |
|
1850 | def heads(self, start=None): | |
1850 | if start is None: |
|
1851 | if start is None: | |
1851 | cl = self.changelog |
|
1852 | cl = self.changelog | |
1852 | headrevs = reversed(cl.headrevs()) |
|
1853 | headrevs = reversed(cl.headrevs()) | |
1853 | return [cl.node(rev) for rev in headrevs] |
|
1854 | return [cl.node(rev) for rev in headrevs] | |
1854 |
|
1855 | |||
1855 | heads = self.changelog.heads(start) |
|
1856 | heads = self.changelog.heads(start) | |
1856 | # sort the output in rev descending order |
|
1857 | # sort the output in rev descending order | |
1857 | return sorted(heads, key=self.changelog.rev, reverse=True) |
|
1858 | return sorted(heads, key=self.changelog.rev, reverse=True) | |
1858 |
|
1859 | |||
1859 | def branchheads(self, branch=None, start=None, closed=False): |
|
1860 | def branchheads(self, branch=None, start=None, closed=False): | |
1860 | '''return a (possibly filtered) list of heads for the given branch |
|
1861 | '''return a (possibly filtered) list of heads for the given branch | |
1861 |
|
1862 | |||
1862 | Heads are returned in topological order, from newest to oldest. |
|
1863 | Heads are returned in topological order, from newest to oldest. | |
1863 | If branch is None, use the dirstate branch. |
|
1864 | If branch is None, use the dirstate branch. | |
1864 | If start is not None, return only heads reachable from start. |
|
1865 | If start is not None, return only heads reachable from start. | |
1865 | If closed is True, return heads that are marked as closed as well. |
|
1866 | If closed is True, return heads that are marked as closed as well. | |
1866 | ''' |
|
1867 | ''' | |
1867 | if branch is None: |
|
1868 | if branch is None: | |
1868 | branch = self[None].branch() |
|
1869 | branch = self[None].branch() | |
1869 | branches = self.branchmap() |
|
1870 | branches = self.branchmap() | |
1870 | if branch not in branches: |
|
1871 | if branch not in branches: | |
1871 | return [] |
|
1872 | return [] | |
1872 | # the cache returns heads ordered lowest to highest |
|
1873 | # the cache returns heads ordered lowest to highest | |
1873 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) |
|
1874 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) | |
1874 | if start is not None: |
|
1875 | if start is not None: | |
1875 | # filter out the heads that cannot be reached from startrev |
|
1876 | # filter out the heads that cannot be reached from startrev | |
1876 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) |
|
1877 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) | |
1877 | bheads = [h for h in bheads if h in fbheads] |
|
1878 | bheads = [h for h in bheads if h in fbheads] | |
1878 | return bheads |
|
1879 | return bheads | |
1879 |
|
1880 | |||
1880 | def branches(self, nodes): |
|
1881 | def branches(self, nodes): | |
1881 | if not nodes: |
|
1882 | if not nodes: | |
1882 | nodes = [self.changelog.tip()] |
|
1883 | nodes = [self.changelog.tip()] | |
1883 | b = [] |
|
1884 | b = [] | |
1884 | for n in nodes: |
|
1885 | for n in nodes: | |
1885 | t = n |
|
1886 | t = n | |
1886 | while True: |
|
1887 | while True: | |
1887 | p = self.changelog.parents(n) |
|
1888 | p = self.changelog.parents(n) | |
1888 | if p[1] != nullid or p[0] == nullid: |
|
1889 | if p[1] != nullid or p[0] == nullid: | |
1889 | b.append((t, n, p[0], p[1])) |
|
1890 | b.append((t, n, p[0], p[1])) | |
1890 | break |
|
1891 | break | |
1891 | n = p[0] |
|
1892 | n = p[0] | |
1892 | return b |
|
1893 | return b | |
1893 |
|
1894 | |||
1894 | def between(self, pairs): |
|
1895 | def between(self, pairs): | |
1895 | r = [] |
|
1896 | r = [] | |
1896 |
|
1897 | |||
1897 | for top, bottom in pairs: |
|
1898 | for top, bottom in pairs: | |
1898 | n, l, i = top, [], 0 |
|
1899 | n, l, i = top, [], 0 | |
1899 | f = 1 |
|
1900 | f = 1 | |
1900 |
|
1901 | |||
1901 | while n != bottom and n != nullid: |
|
1902 | while n != bottom and n != nullid: | |
1902 | p = self.changelog.parents(n)[0] |
|
1903 | p = self.changelog.parents(n)[0] | |
1903 | if i == f: |
|
1904 | if i == f: | |
1904 | l.append(n) |
|
1905 | l.append(n) | |
1905 | f = f * 2 |
|
1906 | f = f * 2 | |
1906 | n = p |
|
1907 | n = p | |
1907 | i += 1 |
|
1908 | i += 1 | |
1908 |
|
1909 | |||
1909 | r.append(l) |
|
1910 | r.append(l) | |
1910 |
|
1911 | |||
1911 | return r |
|
1912 | return r | |
1912 |
|
1913 | |||
1913 | def checkpush(self, pushop): |
|
1914 | def checkpush(self, pushop): | |
1914 | """Extensions can override this function if additional checks have |
|
1915 | """Extensions can override this function if additional checks have | |
1915 | to be performed before pushing, or call it if they override push |
|
1916 | to be performed before pushing, or call it if they override push | |
1916 | command. |
|
1917 | command. | |
1917 | """ |
|
1918 | """ | |
1918 | pass |
|
1919 | pass | |
1919 |
|
1920 | |||
1920 | @unfilteredpropertycache |
|
1921 | @unfilteredpropertycache | |
1921 | def prepushoutgoinghooks(self): |
|
1922 | def prepushoutgoinghooks(self): | |
1922 | """Return util.hooks consists of a pushop with repo, remote, outgoing |
|
1923 | """Return util.hooks consists of a pushop with repo, remote, outgoing | |
1923 | methods, which are called before pushing changesets. |
|
1924 | methods, which are called before pushing changesets. | |
1924 | """ |
|
1925 | """ | |
1925 | return util.hooks() |
|
1926 | return util.hooks() | |
1926 |
|
1927 | |||
1927 | def pushkey(self, namespace, key, old, new): |
|
1928 | def pushkey(self, namespace, key, old, new): | |
1928 | try: |
|
1929 | try: | |
1929 | tr = self.currenttransaction() |
|
1930 | tr = self.currenttransaction() | |
1930 | hookargs = {} |
|
1931 | hookargs = {} | |
1931 | if tr is not None: |
|
1932 | if tr is not None: | |
1932 | hookargs.update(tr.hookargs) |
|
1933 | hookargs.update(tr.hookargs) | |
1933 | hookargs['namespace'] = namespace |
|
1934 | hookargs['namespace'] = namespace | |
1934 | hookargs['key'] = key |
|
1935 | hookargs['key'] = key | |
1935 | hookargs['old'] = old |
|
1936 | hookargs['old'] = old | |
1936 | hookargs['new'] = new |
|
1937 | hookargs['new'] = new | |
1937 | self.hook('prepushkey', throw=True, **hookargs) |
|
1938 | self.hook('prepushkey', throw=True, **hookargs) | |
1938 | except error.HookAbort as exc: |
|
1939 | except error.HookAbort as exc: | |
1939 | self.ui.write_err(_("pushkey-abort: %s\n") % exc) |
|
1940 | self.ui.write_err(_("pushkey-abort: %s\n") % exc) | |
1940 | if exc.hint: |
|
1941 | if exc.hint: | |
1941 | self.ui.write_err(_("(%s)\n") % exc.hint) |
|
1942 | self.ui.write_err(_("(%s)\n") % exc.hint) | |
1942 | return False |
|
1943 | return False | |
1943 | self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key)) |
|
1944 | self.ui.debug('pushing key for "%s:%s"\n' % (namespace, key)) | |
1944 | ret = pushkey.push(self, namespace, key, old, new) |
|
1945 | ret = pushkey.push(self, namespace, key, old, new) | |
1945 | def runhook(): |
|
1946 | def runhook(): | |
1946 | self.hook('pushkey', namespace=namespace, key=key, old=old, new=new, |
|
1947 | self.hook('pushkey', namespace=namespace, key=key, old=old, new=new, | |
1947 | ret=ret) |
|
1948 | ret=ret) | |
1948 | self._afterlock(runhook) |
|
1949 | self._afterlock(runhook) | |
1949 | return ret |
|
1950 | return ret | |
1950 |
|
1951 | |||
1951 | def listkeys(self, namespace): |
|
1952 | def listkeys(self, namespace): | |
1952 | self.hook('prelistkeys', throw=True, namespace=namespace) |
|
1953 | self.hook('prelistkeys', throw=True, namespace=namespace) | |
1953 | self.ui.debug('listing keys for "%s"\n' % namespace) |
|
1954 | self.ui.debug('listing keys for "%s"\n' % namespace) | |
1954 | values = pushkey.list(self, namespace) |
|
1955 | values = pushkey.list(self, namespace) | |
1955 | self.hook('listkeys', namespace=namespace, values=values) |
|
1956 | self.hook('listkeys', namespace=namespace, values=values) | |
1956 | return values |
|
1957 | return values | |
1957 |
|
1958 | |||
1958 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
1959 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
1959 | '''used to test argument passing over the wire''' |
|
1960 | '''used to test argument passing over the wire''' | |
1960 | return "%s %s %s %s %s" % (one, two, three, four, five) |
|
1961 | return "%s %s %s %s %s" % (one, two, three, four, five) | |
1961 |
|
1962 | |||
1962 | def savecommitmessage(self, text): |
|
1963 | def savecommitmessage(self, text): | |
1963 | fp = self.vfs('last-message.txt', 'wb') |
|
1964 | fp = self.vfs('last-message.txt', 'wb') | |
1964 | try: |
|
1965 | try: | |
1965 | fp.write(text) |
|
1966 | fp.write(text) | |
1966 | finally: |
|
1967 | finally: | |
1967 | fp.close() |
|
1968 | fp.close() | |
1968 | return self.pathto(fp.name[len(self.root) + 1:]) |
|
1969 | return self.pathto(fp.name[len(self.root) + 1:]) | |
1969 |
|
1970 | |||
1970 | # used to avoid circular references so destructors work |
|
1971 | # used to avoid circular references so destructors work | |
1971 | def aftertrans(files): |
|
1972 | def aftertrans(files): | |
1972 | renamefiles = [tuple(t) for t in files] |
|
1973 | renamefiles = [tuple(t) for t in files] | |
1973 | def a(): |
|
1974 | def a(): | |
1974 | for vfs, src, dest in renamefiles: |
|
1975 | for vfs, src, dest in renamefiles: | |
1975 | # if src and dest refer to a same file, vfs.rename is a no-op, |
|
1976 | # if src and dest refer to a same file, vfs.rename is a no-op, | |
1976 | # leaving both src and dest on disk. delete dest to make sure |
|
1977 | # leaving both src and dest on disk. delete dest to make sure | |
1977 | # the rename couldn't be such a no-op. |
|
1978 | # the rename couldn't be such a no-op. | |
1978 | vfs.tryunlink(dest) |
|
1979 | vfs.tryunlink(dest) | |
1979 | try: |
|
1980 | try: | |
1980 | vfs.rename(src, dest) |
|
1981 | vfs.rename(src, dest) | |
1981 | except OSError: # journal file does not yet exist |
|
1982 | except OSError: # journal file does not yet exist | |
1982 | pass |
|
1983 | pass | |
1983 | return a |
|
1984 | return a | |
1984 |
|
1985 | |||
1985 | def undoname(fn): |
|
1986 | def undoname(fn): | |
1986 | base, name = os.path.split(fn) |
|
1987 | base, name = os.path.split(fn) | |
1987 | assert name.startswith('journal') |
|
1988 | assert name.startswith('journal') | |
1988 | return os.path.join(base, name.replace('journal', 'undo', 1)) |
|
1989 | return os.path.join(base, name.replace('journal', 'undo', 1)) | |
1989 |
|
1990 | |||
1990 | def instance(ui, path, create): |
|
1991 | def instance(ui, path, create): | |
1991 | return localrepository(ui, util.urllocalpath(path), create) |
|
1992 | return localrepository(ui, util.urllocalpath(path), create) | |
1992 |
|
1993 | |||
1993 | def islocal(path): |
|
1994 | def islocal(path): | |
1994 | return True |
|
1995 | return True | |
1995 |
|
1996 | |||
1996 | def newreporequirements(repo): |
|
1997 | def newreporequirements(repo): | |
1997 | """Determine the set of requirements for a new local repository. |
|
1998 | """Determine the set of requirements for a new local repository. | |
1998 |
|
1999 | |||
1999 | Extensions can wrap this function to specify custom requirements for |
|
2000 | Extensions can wrap this function to specify custom requirements for | |
2000 | new repositories. |
|
2001 | new repositories. | |
2001 | """ |
|
2002 | """ | |
2002 | ui = repo.ui |
|
2003 | ui = repo.ui | |
2003 | requirements = set(['revlogv1']) |
|
2004 | requirements = set(['revlogv1']) | |
2004 | if ui.configbool('format', 'usestore', True): |
|
2005 | if ui.configbool('format', 'usestore', True): | |
2005 | requirements.add('store') |
|
2006 | requirements.add('store') | |
2006 | if ui.configbool('format', 'usefncache', True): |
|
2007 | if ui.configbool('format', 'usefncache', True): | |
2007 | requirements.add('fncache') |
|
2008 | requirements.add('fncache') | |
2008 | if ui.configbool('format', 'dotencode', True): |
|
2009 | if ui.configbool('format', 'dotencode', True): | |
2009 | requirements.add('dotencode') |
|
2010 | requirements.add('dotencode') | |
2010 |
|
2011 | |||
2011 | compengine = ui.config('experimental', 'format.compression', 'zlib') |
|
2012 | compengine = ui.config('experimental', 'format.compression', 'zlib') | |
2012 | if compengine not in util.compengines: |
|
2013 | if compengine not in util.compengines: | |
2013 | raise error.Abort(_('compression engine %s defined by ' |
|
2014 | raise error.Abort(_('compression engine %s defined by ' | |
2014 | 'experimental.format.compression not available') % |
|
2015 | 'experimental.format.compression not available') % | |
2015 | compengine, |
|
2016 | compengine, | |
2016 | hint=_('run "hg debuginstall" to list available ' |
|
2017 | hint=_('run "hg debuginstall" to list available ' | |
2017 | 'compression engines')) |
|
2018 | 'compression engines')) | |
2018 |
|
2019 | |||
2019 | # zlib is the historical default and doesn't need an explicit requirement. |
|
2020 | # zlib is the historical default and doesn't need an explicit requirement. | |
2020 | if compengine != 'zlib': |
|
2021 | if compengine != 'zlib': | |
2021 | requirements.add('exp-compression-%s' % compengine) |
|
2022 | requirements.add('exp-compression-%s' % compengine) | |
2022 |
|
2023 | |||
2023 | if scmutil.gdinitconfig(ui): |
|
2024 | if scmutil.gdinitconfig(ui): | |
2024 | requirements.add('generaldelta') |
|
2025 | requirements.add('generaldelta') | |
2025 | if ui.configbool('experimental', 'treemanifest', False): |
|
2026 | if ui.configbool('experimental', 'treemanifest', False): | |
2026 | requirements.add('treemanifest') |
|
2027 | requirements.add('treemanifest') | |
2027 | if ui.configbool('experimental', 'manifestv2', False): |
|
2028 | if ui.configbool('experimental', 'manifestv2', False): | |
2028 | requirements.add('manifestv2') |
|
2029 | requirements.add('manifestv2') | |
2029 |
|
2030 | |||
2030 | return requirements |
|
2031 | return requirements |
General Comments 0
You need to be logged in to leave comments.
Login now