Show More
@@ -1,1939 +1,1944 b'' | |||||
1 | # changegroup.py - Mercurial changegroup manipulation functions |
|
1 | # changegroup.py - Mercurial changegroup manipulation functions | |
2 | # |
|
2 | # | |
3 | # Copyright 2006 Olivia Mackall <olivia@selenic.com> |
|
3 | # Copyright 2006 Olivia Mackall <olivia@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 | import os |
|
11 | import os | |
12 | import struct |
|
12 | import struct | |
13 | import weakref |
|
13 | import weakref | |
14 |
|
14 | |||
15 | from .i18n import _ |
|
15 | from .i18n import _ | |
16 | from .node import ( |
|
16 | from .node import ( | |
17 | hex, |
|
17 | hex, | |
18 | nullrev, |
|
18 | nullrev, | |
19 | short, |
|
19 | short, | |
20 | ) |
|
20 | ) | |
21 | from .pycompat import open |
|
21 | from .pycompat import open | |
22 |
|
22 | |||
23 | from . import ( |
|
23 | from . import ( | |
24 | error, |
|
24 | error, | |
25 | match as matchmod, |
|
25 | match as matchmod, | |
26 | mdiff, |
|
26 | mdiff, | |
27 | phases, |
|
27 | phases, | |
28 | pycompat, |
|
28 | pycompat, | |
29 | requirements, |
|
29 | requirements, | |
30 | scmutil, |
|
30 | scmutil, | |
31 | util, |
|
31 | util, | |
32 | ) |
|
32 | ) | |
33 |
|
33 | |||
34 | from .interfaces import repository |
|
34 | from .interfaces import repository | |
35 | from .revlogutils import sidedata as sidedatamod |
|
35 | from .revlogutils import sidedata as sidedatamod | |
36 | from .revlogutils import constants as revlog_constants |
|
36 | from .revlogutils import constants as revlog_constants | |
37 |
|
37 | |||
38 | _CHANGEGROUPV1_DELTA_HEADER = struct.Struct(b"20s20s20s20s") |
|
38 | _CHANGEGROUPV1_DELTA_HEADER = struct.Struct(b"20s20s20s20s") | |
39 | _CHANGEGROUPV2_DELTA_HEADER = struct.Struct(b"20s20s20s20s20s") |
|
39 | _CHANGEGROUPV2_DELTA_HEADER = struct.Struct(b"20s20s20s20s20s") | |
40 | _CHANGEGROUPV3_DELTA_HEADER = struct.Struct(b">20s20s20s20s20sH") |
|
40 | _CHANGEGROUPV3_DELTA_HEADER = struct.Struct(b">20s20s20s20s20sH") | |
41 |
|
41 | |||
42 | LFS_REQUIREMENT = b'lfs' |
|
42 | LFS_REQUIREMENT = b'lfs' | |
43 |
|
43 | |||
44 | readexactly = util.readexactly |
|
44 | readexactly = util.readexactly | |
45 |
|
45 | |||
46 |
|
46 | |||
47 | def getchunk(stream): |
|
47 | def getchunk(stream): | |
48 | """return the next chunk from stream as a string""" |
|
48 | """return the next chunk from stream as a string""" | |
49 | d = readexactly(stream, 4) |
|
49 | d = readexactly(stream, 4) | |
50 | l = struct.unpack(b">l", d)[0] |
|
50 | l = struct.unpack(b">l", d)[0] | |
51 | if l <= 4: |
|
51 | if l <= 4: | |
52 | if l: |
|
52 | if l: | |
53 | raise error.Abort(_(b"invalid chunk length %d") % l) |
|
53 | raise error.Abort(_(b"invalid chunk length %d") % l) | |
54 | return b"" |
|
54 | return b"" | |
55 | return readexactly(stream, l - 4) |
|
55 | return readexactly(stream, l - 4) | |
56 |
|
56 | |||
57 |
|
57 | |||
58 | def chunkheader(length): |
|
58 | def chunkheader(length): | |
59 | """return a changegroup chunk header (string)""" |
|
59 | """return a changegroup chunk header (string)""" | |
60 | return struct.pack(b">l", length + 4) |
|
60 | return struct.pack(b">l", length + 4) | |
61 |
|
61 | |||
62 |
|
62 | |||
63 | def closechunk(): |
|
63 | def closechunk(): | |
64 | """return a changegroup chunk header (string) for a zero-length chunk""" |
|
64 | """return a changegroup chunk header (string) for a zero-length chunk""" | |
65 | return struct.pack(b">l", 0) |
|
65 | return struct.pack(b">l", 0) | |
66 |
|
66 | |||
67 |
|
67 | |||
68 | def _fileheader(path): |
|
68 | def _fileheader(path): | |
69 | """Obtain a changegroup chunk header for a named path.""" |
|
69 | """Obtain a changegroup chunk header for a named path.""" | |
70 | return chunkheader(len(path)) + path |
|
70 | return chunkheader(len(path)) + path | |
71 |
|
71 | |||
72 |
|
72 | |||
73 | def writechunks(ui, chunks, filename, vfs=None): |
|
73 | def writechunks(ui, chunks, filename, vfs=None): | |
74 | """Write chunks to a file and return its filename. |
|
74 | """Write chunks to a file and return its filename. | |
75 |
|
75 | |||
76 | The stream is assumed to be a bundle file. |
|
76 | The stream is assumed to be a bundle file. | |
77 | Existing files will not be overwritten. |
|
77 | Existing files will not be overwritten. | |
78 | If no filename is specified, a temporary file is created. |
|
78 | If no filename is specified, a temporary file is created. | |
79 | """ |
|
79 | """ | |
80 | fh = None |
|
80 | fh = None | |
81 | cleanup = None |
|
81 | cleanup = None | |
82 | try: |
|
82 | try: | |
83 | if filename: |
|
83 | if filename: | |
84 | if vfs: |
|
84 | if vfs: | |
85 | fh = vfs.open(filename, b"wb") |
|
85 | fh = vfs.open(filename, b"wb") | |
86 | else: |
|
86 | else: | |
87 | # Increase default buffer size because default is usually |
|
87 | # Increase default buffer size because default is usually | |
88 | # small (4k is common on Linux). |
|
88 | # small (4k is common on Linux). | |
89 | fh = open(filename, b"wb", 131072) |
|
89 | fh = open(filename, b"wb", 131072) | |
90 | else: |
|
90 | else: | |
91 | fd, filename = pycompat.mkstemp(prefix=b"hg-bundle-", suffix=b".hg") |
|
91 | fd, filename = pycompat.mkstemp(prefix=b"hg-bundle-", suffix=b".hg") | |
92 | fh = os.fdopen(fd, "wb") |
|
92 | fh = os.fdopen(fd, "wb") | |
93 | cleanup = filename |
|
93 | cleanup = filename | |
94 | for c in chunks: |
|
94 | for c in chunks: | |
95 | fh.write(c) |
|
95 | fh.write(c) | |
96 | cleanup = None |
|
96 | cleanup = None | |
97 | return filename |
|
97 | return filename | |
98 | finally: |
|
98 | finally: | |
99 | if fh is not None: |
|
99 | if fh is not None: | |
100 | fh.close() |
|
100 | fh.close() | |
101 | if cleanup is not None: |
|
101 | if cleanup is not None: | |
102 | if filename and vfs: |
|
102 | if filename and vfs: | |
103 | vfs.unlink(cleanup) |
|
103 | vfs.unlink(cleanup) | |
104 | else: |
|
104 | else: | |
105 | os.unlink(cleanup) |
|
105 | os.unlink(cleanup) | |
106 |
|
106 | |||
107 |
|
107 | |||
108 | class cg1unpacker(object): |
|
108 | class cg1unpacker(object): | |
109 | """Unpacker for cg1 changegroup streams. |
|
109 | """Unpacker for cg1 changegroup streams. | |
110 |
|
110 | |||
111 | A changegroup unpacker handles the framing of the revision data in |
|
111 | A changegroup unpacker handles the framing of the revision data in | |
112 | the wire format. Most consumers will want to use the apply() |
|
112 | the wire format. Most consumers will want to use the apply() | |
113 | method to add the changes from the changegroup to a repository. |
|
113 | method to add the changes from the changegroup to a repository. | |
114 |
|
114 | |||
115 | If you're forwarding a changegroup unmodified to another consumer, |
|
115 | If you're forwarding a changegroup unmodified to another consumer, | |
116 | use getchunks(), which returns an iterator of changegroup |
|
116 | use getchunks(), which returns an iterator of changegroup | |
117 | chunks. This is mostly useful for cases where you need to know the |
|
117 | chunks. This is mostly useful for cases where you need to know the | |
118 | data stream has ended by observing the end of the changegroup. |
|
118 | data stream has ended by observing the end of the changegroup. | |
119 |
|
119 | |||
120 | deltachunk() is useful only if you're applying delta data. Most |
|
120 | deltachunk() is useful only if you're applying delta data. Most | |
121 | consumers should prefer apply() instead. |
|
121 | consumers should prefer apply() instead. | |
122 |
|
122 | |||
123 | A few other public methods exist. Those are used only for |
|
123 | A few other public methods exist. Those are used only for | |
124 | bundlerepo and some debug commands - their use is discouraged. |
|
124 | bundlerepo and some debug commands - their use is discouraged. | |
125 | """ |
|
125 | """ | |
126 |
|
126 | |||
127 | deltaheader = _CHANGEGROUPV1_DELTA_HEADER |
|
127 | deltaheader = _CHANGEGROUPV1_DELTA_HEADER | |
128 | deltaheadersize = deltaheader.size |
|
128 | deltaheadersize = deltaheader.size | |
129 | version = b'01' |
|
129 | version = b'01' | |
130 | _grouplistcount = 1 # One list of files after the manifests |
|
130 | _grouplistcount = 1 # One list of files after the manifests | |
131 |
|
131 | |||
132 | def __init__(self, fh, alg, extras=None): |
|
132 | def __init__(self, fh, alg, extras=None): | |
133 | if alg is None: |
|
133 | if alg is None: | |
134 | alg = b'UN' |
|
134 | alg = b'UN' | |
135 | if alg not in util.compengines.supportedbundletypes: |
|
135 | if alg not in util.compengines.supportedbundletypes: | |
136 | raise error.Abort(_(b'unknown stream compression type: %s') % alg) |
|
136 | raise error.Abort(_(b'unknown stream compression type: %s') % alg) | |
137 | if alg == b'BZ': |
|
137 | if alg == b'BZ': | |
138 | alg = b'_truncatedBZ' |
|
138 | alg = b'_truncatedBZ' | |
139 |
|
139 | |||
140 | compengine = util.compengines.forbundletype(alg) |
|
140 | compengine = util.compengines.forbundletype(alg) | |
141 | self._stream = compengine.decompressorreader(fh) |
|
141 | self._stream = compengine.decompressorreader(fh) | |
142 | self._type = alg |
|
142 | self._type = alg | |
143 | self.extras = extras or {} |
|
143 | self.extras = extras or {} | |
144 | self.callback = None |
|
144 | self.callback = None | |
145 |
|
145 | |||
146 | # These methods (compressed, read, seek, tell) all appear to only |
|
146 | # These methods (compressed, read, seek, tell) all appear to only | |
147 | # be used by bundlerepo, but it's a little hard to tell. |
|
147 | # be used by bundlerepo, but it's a little hard to tell. | |
148 | def compressed(self): |
|
148 | def compressed(self): | |
149 | return self._type is not None and self._type != b'UN' |
|
149 | return self._type is not None and self._type != b'UN' | |
150 |
|
150 | |||
151 | def read(self, l): |
|
151 | def read(self, l): | |
152 | return self._stream.read(l) |
|
152 | return self._stream.read(l) | |
153 |
|
153 | |||
154 | def seek(self, pos): |
|
154 | def seek(self, pos): | |
155 | return self._stream.seek(pos) |
|
155 | return self._stream.seek(pos) | |
156 |
|
156 | |||
157 | def tell(self): |
|
157 | def tell(self): | |
158 | return self._stream.tell() |
|
158 | return self._stream.tell() | |
159 |
|
159 | |||
160 | def close(self): |
|
160 | def close(self): | |
161 | return self._stream.close() |
|
161 | return self._stream.close() | |
162 |
|
162 | |||
163 | def _chunklength(self): |
|
163 | def _chunklength(self): | |
164 | d = readexactly(self._stream, 4) |
|
164 | d = readexactly(self._stream, 4) | |
165 | l = struct.unpack(b">l", d)[0] |
|
165 | l = struct.unpack(b">l", d)[0] | |
166 | if l <= 4: |
|
166 | if l <= 4: | |
167 | if l: |
|
167 | if l: | |
168 | raise error.Abort(_(b"invalid chunk length %d") % l) |
|
168 | raise error.Abort(_(b"invalid chunk length %d") % l) | |
169 | return 0 |
|
169 | return 0 | |
170 | if self.callback: |
|
170 | if self.callback: | |
171 | self.callback() |
|
171 | self.callback() | |
172 | return l - 4 |
|
172 | return l - 4 | |
173 |
|
173 | |||
174 | def changelogheader(self): |
|
174 | def changelogheader(self): | |
175 | """v10 does not have a changelog header chunk""" |
|
175 | """v10 does not have a changelog header chunk""" | |
176 | return {} |
|
176 | return {} | |
177 |
|
177 | |||
178 | def manifestheader(self): |
|
178 | def manifestheader(self): | |
179 | """v10 does not have a manifest header chunk""" |
|
179 | """v10 does not have a manifest header chunk""" | |
180 | return {} |
|
180 | return {} | |
181 |
|
181 | |||
182 | def filelogheader(self): |
|
182 | def filelogheader(self): | |
183 | """return the header of the filelogs chunk, v10 only has the filename""" |
|
183 | """return the header of the filelogs chunk, v10 only has the filename""" | |
184 | l = self._chunklength() |
|
184 | l = self._chunklength() | |
185 | if not l: |
|
185 | if not l: | |
186 | return {} |
|
186 | return {} | |
187 | fname = readexactly(self._stream, l) |
|
187 | fname = readexactly(self._stream, l) | |
188 | return {b'filename': fname} |
|
188 | return {b'filename': fname} | |
189 |
|
189 | |||
190 | def _deltaheader(self, headertuple, prevnode): |
|
190 | def _deltaheader(self, headertuple, prevnode): | |
191 | node, p1, p2, cs = headertuple |
|
191 | node, p1, p2, cs = headertuple | |
192 | if prevnode is None: |
|
192 | if prevnode is None: | |
193 | deltabase = p1 |
|
193 | deltabase = p1 | |
194 | else: |
|
194 | else: | |
195 | deltabase = prevnode |
|
195 | deltabase = prevnode | |
196 | flags = 0 |
|
196 | flags = 0 | |
197 | return node, p1, p2, deltabase, cs, flags |
|
197 | return node, p1, p2, deltabase, cs, flags | |
198 |
|
198 | |||
199 | def deltachunk(self, prevnode): |
|
199 | def deltachunk(self, prevnode): | |
200 | l = self._chunklength() |
|
200 | l = self._chunklength() | |
201 | if not l: |
|
201 | if not l: | |
202 | return {} |
|
202 | return {} | |
203 | headerdata = readexactly(self._stream, self.deltaheadersize) |
|
203 | headerdata = readexactly(self._stream, self.deltaheadersize) | |
204 | header = self.deltaheader.unpack(headerdata) |
|
204 | header = self.deltaheader.unpack(headerdata) | |
205 | delta = readexactly(self._stream, l - self.deltaheadersize) |
|
205 | delta = readexactly(self._stream, l - self.deltaheadersize) | |
206 | node, p1, p2, deltabase, cs, flags = self._deltaheader(header, prevnode) |
|
206 | node, p1, p2, deltabase, cs, flags = self._deltaheader(header, prevnode) | |
207 | # cg4 forward-compat |
|
207 | # cg4 forward-compat | |
208 | sidedata = {} |
|
208 | sidedata = {} | |
209 | return (node, p1, p2, cs, deltabase, delta, flags, sidedata) |
|
209 | return (node, p1, p2, cs, deltabase, delta, flags, sidedata) | |
210 |
|
210 | |||
211 | def getchunks(self): |
|
211 | def getchunks(self): | |
212 | """returns all the chunks contains in the bundle |
|
212 | """returns all the chunks contains in the bundle | |
213 |
|
213 | |||
214 | Used when you need to forward the binary stream to a file or another |
|
214 | Used when you need to forward the binary stream to a file or another | |
215 | network API. To do so, it parse the changegroup data, otherwise it will |
|
215 | network API. To do so, it parse the changegroup data, otherwise it will | |
216 | block in case of sshrepo because it don't know the end of the stream. |
|
216 | block in case of sshrepo because it don't know the end of the stream. | |
217 | """ |
|
217 | """ | |
218 | # For changegroup 1 and 2, we expect 3 parts: changelog, manifestlog, |
|
218 | # For changegroup 1 and 2, we expect 3 parts: changelog, manifestlog, | |
219 | # and a list of filelogs. For changegroup 3, we expect 4 parts: |
|
219 | # and a list of filelogs. For changegroup 3, we expect 4 parts: | |
220 | # changelog, manifestlog, a list of tree manifestlogs, and a list of |
|
220 | # changelog, manifestlog, a list of tree manifestlogs, and a list of | |
221 | # filelogs. |
|
221 | # filelogs. | |
222 | # |
|
222 | # | |
223 | # Changelog and manifestlog parts are terminated with empty chunks. The |
|
223 | # Changelog and manifestlog parts are terminated with empty chunks. The | |
224 | # tree and file parts are a list of entry sections. Each entry section |
|
224 | # tree and file parts are a list of entry sections. Each entry section | |
225 | # is a series of chunks terminating in an empty chunk. The list of these |
|
225 | # is a series of chunks terminating in an empty chunk. The list of these | |
226 | # entry sections is terminated in yet another empty chunk, so we know |
|
226 | # entry sections is terminated in yet another empty chunk, so we know | |
227 | # we've reached the end of the tree/file list when we reach an empty |
|
227 | # we've reached the end of the tree/file list when we reach an empty | |
228 | # chunk that was proceeded by no non-empty chunks. |
|
228 | # chunk that was proceeded by no non-empty chunks. | |
229 |
|
229 | |||
230 | parts = 0 |
|
230 | parts = 0 | |
231 | while parts < 2 + self._grouplistcount: |
|
231 | while parts < 2 + self._grouplistcount: | |
232 | noentries = True |
|
232 | noentries = True | |
233 | while True: |
|
233 | while True: | |
234 | chunk = getchunk(self) |
|
234 | chunk = getchunk(self) | |
235 | if not chunk: |
|
235 | if not chunk: | |
236 | # The first two empty chunks represent the end of the |
|
236 | # The first two empty chunks represent the end of the | |
237 | # changelog and the manifestlog portions. The remaining |
|
237 | # changelog and the manifestlog portions. The remaining | |
238 | # empty chunks represent either A) the end of individual |
|
238 | # empty chunks represent either A) the end of individual | |
239 | # tree or file entries in the file list, or B) the end of |
|
239 | # tree or file entries in the file list, or B) the end of | |
240 | # the entire list. It's the end of the entire list if there |
|
240 | # the entire list. It's the end of the entire list if there | |
241 | # were no entries (i.e. noentries is True). |
|
241 | # were no entries (i.e. noentries is True). | |
242 | if parts < 2: |
|
242 | if parts < 2: | |
243 | parts += 1 |
|
243 | parts += 1 | |
244 | elif noentries: |
|
244 | elif noentries: | |
245 | parts += 1 |
|
245 | parts += 1 | |
246 | break |
|
246 | break | |
247 | noentries = False |
|
247 | noentries = False | |
248 | yield chunkheader(len(chunk)) |
|
248 | yield chunkheader(len(chunk)) | |
249 | pos = 0 |
|
249 | pos = 0 | |
250 | while pos < len(chunk): |
|
250 | while pos < len(chunk): | |
251 | next = pos + 2 ** 20 |
|
251 | next = pos + 2 ** 20 | |
252 | yield chunk[pos:next] |
|
252 | yield chunk[pos:next] | |
253 | pos = next |
|
253 | pos = next | |
254 | yield closechunk() |
|
254 | yield closechunk() | |
255 |
|
255 | |||
256 | def _unpackmanifests(self, repo, revmap, trp, prog, addrevisioncb=None): |
|
256 | def _unpackmanifests(self, repo, revmap, trp, prog, addrevisioncb=None): | |
257 | self.callback = prog.increment |
|
257 | self.callback = prog.increment | |
258 | # no need to check for empty manifest group here: |
|
258 | # no need to check for empty manifest group here: | |
259 | # if the result of the merge of 1 and 2 is the same in 3 and 4, |
|
259 | # if the result of the merge of 1 and 2 is the same in 3 and 4, | |
260 | # no new manifest will be created and the manifest group will |
|
260 | # no new manifest will be created and the manifest group will | |
261 | # be empty during the pull |
|
261 | # be empty during the pull | |
262 | self.manifestheader() |
|
262 | self.manifestheader() | |
263 | deltas = self.deltaiter() |
|
263 | deltas = self.deltaiter() | |
264 | storage = repo.manifestlog.getstorage(b'') |
|
264 | storage = repo.manifestlog.getstorage(b'') | |
265 | storage.addgroup(deltas, revmap, trp, addrevisioncb=addrevisioncb) |
|
265 | storage.addgroup(deltas, revmap, trp, addrevisioncb=addrevisioncb) | |
266 | prog.complete() |
|
266 | prog.complete() | |
267 | self.callback = None |
|
267 | self.callback = None | |
268 |
|
268 | |||
269 | def apply( |
|
269 | def apply( | |
270 | self, |
|
270 | self, | |
271 | repo, |
|
271 | repo, | |
272 | tr, |
|
272 | tr, | |
273 | srctype, |
|
273 | srctype, | |
274 | url, |
|
274 | url, | |
275 | targetphase=phases.draft, |
|
275 | targetphase=phases.draft, | |
276 | expectedtotal=None, |
|
276 | expectedtotal=None, | |
277 | sidedata_categories=None, |
|
277 | sidedata_categories=None, | |
278 | ): |
|
278 | ): | |
279 | """Add the changegroup returned by source.read() to this repo. |
|
279 | """Add the changegroup returned by source.read() to this repo. | |
280 | srctype is a string like 'push', 'pull', or 'unbundle'. url is |
|
280 | srctype is a string like 'push', 'pull', or 'unbundle'. url is | |
281 | the URL of the repo where this changegroup is coming from. |
|
281 | the URL of the repo where this changegroup is coming from. | |
282 |
|
282 | |||
283 | Return an integer summarizing the change to this repo: |
|
283 | Return an integer summarizing the change to this repo: | |
284 | - nothing changed or no source: 0 |
|
284 | - nothing changed or no source: 0 | |
285 | - more heads than before: 1+added heads (2..n) |
|
285 | - more heads than before: 1+added heads (2..n) | |
286 | - fewer heads than before: -1-removed heads (-2..-n) |
|
286 | - fewer heads than before: -1-removed heads (-2..-n) | |
287 | - number of heads stays the same: 1 |
|
287 | - number of heads stays the same: 1 | |
288 |
|
288 | |||
289 | `sidedata_categories` is an optional set of the remote's sidedata wanted |
|
289 | `sidedata_categories` is an optional set of the remote's sidedata wanted | |
290 | categories. |
|
290 | categories. | |
291 | """ |
|
291 | """ | |
292 | repo = repo.unfiltered() |
|
292 | repo = repo.unfiltered() | |
293 |
|
293 | |||
294 | # Only useful if we're adding sidedata categories. If both peers have |
|
294 | # Only useful if we're adding sidedata categories. If both peers have | |
295 | # the same categories, then we simply don't do anything. |
|
295 | # the same categories, then we simply don't do anything. | |
296 | if self.version == b'04' and srctype == b'pull': |
|
296 | adding_sidedata = ( | |
|
297 | requirements.REVLOGV2_REQUIREMENT in repo.requirements | |||
|
298 | and self.version == b'04' | |||
|
299 | and srctype == b'pull' | |||
|
300 | ) | |||
|
301 | if adding_sidedata: | |||
297 | sidedata_helpers = get_sidedata_helpers( |
|
302 | sidedata_helpers = get_sidedata_helpers( | |
298 | repo, |
|
303 | repo, | |
299 | sidedata_categories or set(), |
|
304 | sidedata_categories or set(), | |
300 | pull=True, |
|
305 | pull=True, | |
301 | ) |
|
306 | ) | |
302 | else: |
|
307 | else: | |
303 | sidedata_helpers = None |
|
308 | sidedata_helpers = None | |
304 |
|
309 | |||
305 | def csmap(x): |
|
310 | def csmap(x): | |
306 | repo.ui.debug(b"add changeset %s\n" % short(x)) |
|
311 | repo.ui.debug(b"add changeset %s\n" % short(x)) | |
307 | return len(cl) |
|
312 | return len(cl) | |
308 |
|
313 | |||
309 | def revmap(x): |
|
314 | def revmap(x): | |
310 | return cl.rev(x) |
|
315 | return cl.rev(x) | |
311 |
|
316 | |||
312 | try: |
|
317 | try: | |
313 | # The transaction may already carry source information. In this |
|
318 | # The transaction may already carry source information. In this | |
314 | # case we use the top level data. We overwrite the argument |
|
319 | # case we use the top level data. We overwrite the argument | |
315 | # because we need to use the top level value (if they exist) |
|
320 | # because we need to use the top level value (if they exist) | |
316 | # in this function. |
|
321 | # in this function. | |
317 | srctype = tr.hookargs.setdefault(b'source', srctype) |
|
322 | srctype = tr.hookargs.setdefault(b'source', srctype) | |
318 | tr.hookargs.setdefault(b'url', url) |
|
323 | tr.hookargs.setdefault(b'url', url) | |
319 | repo.hook( |
|
324 | repo.hook( | |
320 | b'prechangegroup', throw=True, **pycompat.strkwargs(tr.hookargs) |
|
325 | b'prechangegroup', throw=True, **pycompat.strkwargs(tr.hookargs) | |
321 | ) |
|
326 | ) | |
322 |
|
327 | |||
323 | # write changelog data to temp files so concurrent readers |
|
328 | # write changelog data to temp files so concurrent readers | |
324 | # will not see an inconsistent view |
|
329 | # will not see an inconsistent view | |
325 | cl = repo.changelog |
|
330 | cl = repo.changelog | |
326 | cl.delayupdate(tr) |
|
331 | cl.delayupdate(tr) | |
327 | oldheads = set(cl.heads()) |
|
332 | oldheads = set(cl.heads()) | |
328 |
|
333 | |||
329 | trp = weakref.proxy(tr) |
|
334 | trp = weakref.proxy(tr) | |
330 | # pull off the changeset group |
|
335 | # pull off the changeset group | |
331 | repo.ui.status(_(b"adding changesets\n")) |
|
336 | repo.ui.status(_(b"adding changesets\n")) | |
332 | clstart = len(cl) |
|
337 | clstart = len(cl) | |
333 | progress = repo.ui.makeprogress( |
|
338 | progress = repo.ui.makeprogress( | |
334 | _(b'changesets'), unit=_(b'chunks'), total=expectedtotal |
|
339 | _(b'changesets'), unit=_(b'chunks'), total=expectedtotal | |
335 | ) |
|
340 | ) | |
336 | self.callback = progress.increment |
|
341 | self.callback = progress.increment | |
337 |
|
342 | |||
338 | efilesset = set() |
|
343 | efilesset = set() | |
339 | duprevs = [] |
|
344 | duprevs = [] | |
340 |
|
345 | |||
341 | def ondupchangelog(cl, rev): |
|
346 | def ondupchangelog(cl, rev): | |
342 | if rev < clstart: |
|
347 | if rev < clstart: | |
343 | duprevs.append(rev) |
|
348 | duprevs.append(rev) | |
344 |
|
349 | |||
345 | def onchangelog(cl, rev): |
|
350 | def onchangelog(cl, rev): | |
346 | ctx = cl.changelogrevision(rev) |
|
351 | ctx = cl.changelogrevision(rev) | |
347 | efilesset.update(ctx.files) |
|
352 | efilesset.update(ctx.files) | |
348 | repo.register_changeset(rev, ctx) |
|
353 | repo.register_changeset(rev, ctx) | |
349 |
|
354 | |||
350 | self.changelogheader() |
|
355 | self.changelogheader() | |
351 | deltas = self.deltaiter() |
|
356 | deltas = self.deltaiter() | |
352 | if not cl.addgroup( |
|
357 | if not cl.addgroup( | |
353 | deltas, |
|
358 | deltas, | |
354 | csmap, |
|
359 | csmap, | |
355 | trp, |
|
360 | trp, | |
356 | alwayscache=True, |
|
361 | alwayscache=True, | |
357 | addrevisioncb=onchangelog, |
|
362 | addrevisioncb=onchangelog, | |
358 | duplicaterevisioncb=ondupchangelog, |
|
363 | duplicaterevisioncb=ondupchangelog, | |
359 | ): |
|
364 | ): | |
360 | repo.ui.develwarn( |
|
365 | repo.ui.develwarn( | |
361 | b'applied empty changelog from changegroup', |
|
366 | b'applied empty changelog from changegroup', | |
362 | config=b'warn-empty-changegroup', |
|
367 | config=b'warn-empty-changegroup', | |
363 | ) |
|
368 | ) | |
364 | efiles = len(efilesset) |
|
369 | efiles = len(efilesset) | |
365 | clend = len(cl) |
|
370 | clend = len(cl) | |
366 | changesets = clend - clstart |
|
371 | changesets = clend - clstart | |
367 | progress.complete() |
|
372 | progress.complete() | |
368 | del deltas |
|
373 | del deltas | |
369 | # TODO Python 2.7 removal |
|
374 | # TODO Python 2.7 removal | |
370 | # del efilesset |
|
375 | # del efilesset | |
371 | efilesset = None |
|
376 | efilesset = None | |
372 | self.callback = None |
|
377 | self.callback = None | |
373 |
|
378 | |||
374 | # Keep track of the (non-changelog) revlogs we've updated and their |
|
379 | # Keep track of the (non-changelog) revlogs we've updated and their | |
375 | # range of new revisions for sidedata rewrite. |
|
380 | # range of new revisions for sidedata rewrite. | |
376 | # TODO do something more efficient than keeping the reference to |
|
381 | # TODO do something more efficient than keeping the reference to | |
377 | # the revlogs, especially memory-wise. |
|
382 | # the revlogs, especially memory-wise. | |
378 | touched_manifests = {} |
|
383 | touched_manifests = {} | |
379 | touched_filelogs = {} |
|
384 | touched_filelogs = {} | |
380 |
|
385 | |||
381 | # pull off the manifest group |
|
386 | # pull off the manifest group | |
382 | repo.ui.status(_(b"adding manifests\n")) |
|
387 | repo.ui.status(_(b"adding manifests\n")) | |
383 | # We know that we'll never have more manifests than we had |
|
388 | # We know that we'll never have more manifests than we had | |
384 | # changesets. |
|
389 | # changesets. | |
385 | progress = repo.ui.makeprogress( |
|
390 | progress = repo.ui.makeprogress( | |
386 | _(b'manifests'), unit=_(b'chunks'), total=changesets |
|
391 | _(b'manifests'), unit=_(b'chunks'), total=changesets | |
387 | ) |
|
392 | ) | |
388 | on_manifest_rev = None |
|
393 | on_manifest_rev = None | |
389 | if sidedata_helpers: |
|
394 | if sidedata_helpers: | |
390 | if revlog_constants.KIND_MANIFESTLOG in sidedata_helpers[1]: |
|
395 | if revlog_constants.KIND_MANIFESTLOG in sidedata_helpers[1]: | |
391 |
|
396 | |||
392 | def on_manifest_rev(manifest, rev): |
|
397 | def on_manifest_rev(manifest, rev): | |
393 | range = touched_manifests.get(manifest) |
|
398 | range = touched_manifests.get(manifest) | |
394 | if not range: |
|
399 | if not range: | |
395 | touched_manifests[manifest] = (rev, rev) |
|
400 | touched_manifests[manifest] = (rev, rev) | |
396 | else: |
|
401 | else: | |
397 | assert rev == range[1] + 1 |
|
402 | assert rev == range[1] + 1 | |
398 | touched_manifests[manifest] = (range[0], rev) |
|
403 | touched_manifests[manifest] = (range[0], rev) | |
399 |
|
404 | |||
400 | self._unpackmanifests( |
|
405 | self._unpackmanifests( | |
401 | repo, |
|
406 | repo, | |
402 | revmap, |
|
407 | revmap, | |
403 | trp, |
|
408 | trp, | |
404 | progress, |
|
409 | progress, | |
405 | addrevisioncb=on_manifest_rev, |
|
410 | addrevisioncb=on_manifest_rev, | |
406 | ) |
|
411 | ) | |
407 |
|
412 | |||
408 | needfiles = {} |
|
413 | needfiles = {} | |
409 | if repo.ui.configbool(b'server', b'validate'): |
|
414 | if repo.ui.configbool(b'server', b'validate'): | |
410 | cl = repo.changelog |
|
415 | cl = repo.changelog | |
411 | ml = repo.manifestlog |
|
416 | ml = repo.manifestlog | |
412 | # validate incoming csets have their manifests |
|
417 | # validate incoming csets have their manifests | |
413 | for cset in pycompat.xrange(clstart, clend): |
|
418 | for cset in pycompat.xrange(clstart, clend): | |
414 | mfnode = cl.changelogrevision(cset).manifest |
|
419 | mfnode = cl.changelogrevision(cset).manifest | |
415 | mfest = ml[mfnode].readdelta() |
|
420 | mfest = ml[mfnode].readdelta() | |
416 | # store file nodes we must see |
|
421 | # store file nodes we must see | |
417 | for f, n in pycompat.iteritems(mfest): |
|
422 | for f, n in pycompat.iteritems(mfest): | |
418 | needfiles.setdefault(f, set()).add(n) |
|
423 | needfiles.setdefault(f, set()).add(n) | |
419 |
|
424 | |||
420 | on_filelog_rev = None |
|
425 | on_filelog_rev = None | |
421 | if sidedata_helpers: |
|
426 | if sidedata_helpers: | |
422 | if revlog_constants.KIND_FILELOG in sidedata_helpers[1]: |
|
427 | if revlog_constants.KIND_FILELOG in sidedata_helpers[1]: | |
423 |
|
428 | |||
424 | def on_filelog_rev(filelog, rev): |
|
429 | def on_filelog_rev(filelog, rev): | |
425 | range = touched_filelogs.get(filelog) |
|
430 | range = touched_filelogs.get(filelog) | |
426 | if not range: |
|
431 | if not range: | |
427 | touched_filelogs[filelog] = (rev, rev) |
|
432 | touched_filelogs[filelog] = (rev, rev) | |
428 | else: |
|
433 | else: | |
429 | assert rev == range[1] + 1 |
|
434 | assert rev == range[1] + 1 | |
430 | touched_filelogs[filelog] = (range[0], rev) |
|
435 | touched_filelogs[filelog] = (range[0], rev) | |
431 |
|
436 | |||
432 | # process the files |
|
437 | # process the files | |
433 | repo.ui.status(_(b"adding file changes\n")) |
|
438 | repo.ui.status(_(b"adding file changes\n")) | |
434 | newrevs, newfiles = _addchangegroupfiles( |
|
439 | newrevs, newfiles = _addchangegroupfiles( | |
435 | repo, |
|
440 | repo, | |
436 | self, |
|
441 | self, | |
437 | revmap, |
|
442 | revmap, | |
438 | trp, |
|
443 | trp, | |
439 | efiles, |
|
444 | efiles, | |
440 | needfiles, |
|
445 | needfiles, | |
441 | addrevisioncb=on_filelog_rev, |
|
446 | addrevisioncb=on_filelog_rev, | |
442 | ) |
|
447 | ) | |
443 |
|
448 | |||
444 | if sidedata_helpers: |
|
449 | if sidedata_helpers: | |
445 | if revlog_constants.KIND_CHANGELOG in sidedata_helpers[1]: |
|
450 | if revlog_constants.KIND_CHANGELOG in sidedata_helpers[1]: | |
446 | cl.rewrite_sidedata(sidedata_helpers, clstart, clend - 1) |
|
451 | cl.rewrite_sidedata(sidedata_helpers, clstart, clend - 1) | |
447 | for mf, (startrev, endrev) in touched_manifests.items(): |
|
452 | for mf, (startrev, endrev) in touched_manifests.items(): | |
448 | mf.rewrite_sidedata(sidedata_helpers, startrev, endrev) |
|
453 | mf.rewrite_sidedata(sidedata_helpers, startrev, endrev) | |
449 | for fl, (startrev, endrev) in touched_filelogs.items(): |
|
454 | for fl, (startrev, endrev) in touched_filelogs.items(): | |
450 | fl.rewrite_sidedata(sidedata_helpers, startrev, endrev) |
|
455 | fl.rewrite_sidedata(sidedata_helpers, startrev, endrev) | |
451 |
|
456 | |||
452 | # making sure the value exists |
|
457 | # making sure the value exists | |
453 | tr.changes.setdefault(b'changegroup-count-changesets', 0) |
|
458 | tr.changes.setdefault(b'changegroup-count-changesets', 0) | |
454 | tr.changes.setdefault(b'changegroup-count-revisions', 0) |
|
459 | tr.changes.setdefault(b'changegroup-count-revisions', 0) | |
455 | tr.changes.setdefault(b'changegroup-count-files', 0) |
|
460 | tr.changes.setdefault(b'changegroup-count-files', 0) | |
456 | tr.changes.setdefault(b'changegroup-count-heads', 0) |
|
461 | tr.changes.setdefault(b'changegroup-count-heads', 0) | |
457 |
|
462 | |||
458 | # some code use bundle operation for internal purpose. They usually |
|
463 | # some code use bundle operation for internal purpose. They usually | |
459 | # set `ui.quiet` to do this outside of user sight. Size the report |
|
464 | # set `ui.quiet` to do this outside of user sight. Size the report | |
460 | # of such operation now happens at the end of the transaction, that |
|
465 | # of such operation now happens at the end of the transaction, that | |
461 | # ui.quiet has not direct effect on the output. |
|
466 | # ui.quiet has not direct effect on the output. | |
462 | # |
|
467 | # | |
463 | # To preserve this intend use an inelegant hack, we fail to report |
|
468 | # To preserve this intend use an inelegant hack, we fail to report | |
464 | # the change if `quiet` is set. We should probably move to |
|
469 | # the change if `quiet` is set. We should probably move to | |
465 | # something better, but this is a good first step to allow the "end |
|
470 | # something better, but this is a good first step to allow the "end | |
466 | # of transaction report" to pass tests. |
|
471 | # of transaction report" to pass tests. | |
467 | if not repo.ui.quiet: |
|
472 | if not repo.ui.quiet: | |
468 | tr.changes[b'changegroup-count-changesets'] += changesets |
|
473 | tr.changes[b'changegroup-count-changesets'] += changesets | |
469 | tr.changes[b'changegroup-count-revisions'] += newrevs |
|
474 | tr.changes[b'changegroup-count-revisions'] += newrevs | |
470 | tr.changes[b'changegroup-count-files'] += newfiles |
|
475 | tr.changes[b'changegroup-count-files'] += newfiles | |
471 |
|
476 | |||
472 | deltaheads = 0 |
|
477 | deltaheads = 0 | |
473 | if oldheads: |
|
478 | if oldheads: | |
474 | heads = cl.heads() |
|
479 | heads = cl.heads() | |
475 | deltaheads += len(heads) - len(oldheads) |
|
480 | deltaheads += len(heads) - len(oldheads) | |
476 | for h in heads: |
|
481 | for h in heads: | |
477 | if h not in oldheads and repo[h].closesbranch(): |
|
482 | if h not in oldheads and repo[h].closesbranch(): | |
478 | deltaheads -= 1 |
|
483 | deltaheads -= 1 | |
479 |
|
484 | |||
480 | # see previous comment about checking ui.quiet |
|
485 | # see previous comment about checking ui.quiet | |
481 | if not repo.ui.quiet: |
|
486 | if not repo.ui.quiet: | |
482 | tr.changes[b'changegroup-count-heads'] += deltaheads |
|
487 | tr.changes[b'changegroup-count-heads'] += deltaheads | |
483 | repo.invalidatevolatilesets() |
|
488 | repo.invalidatevolatilesets() | |
484 |
|
489 | |||
485 | if changesets > 0: |
|
490 | if changesets > 0: | |
486 | if b'node' not in tr.hookargs: |
|
491 | if b'node' not in tr.hookargs: | |
487 | tr.hookargs[b'node'] = hex(cl.node(clstart)) |
|
492 | tr.hookargs[b'node'] = hex(cl.node(clstart)) | |
488 | tr.hookargs[b'node_last'] = hex(cl.node(clend - 1)) |
|
493 | tr.hookargs[b'node_last'] = hex(cl.node(clend - 1)) | |
489 | hookargs = dict(tr.hookargs) |
|
494 | hookargs = dict(tr.hookargs) | |
490 | else: |
|
495 | else: | |
491 | hookargs = dict(tr.hookargs) |
|
496 | hookargs = dict(tr.hookargs) | |
492 | hookargs[b'node'] = hex(cl.node(clstart)) |
|
497 | hookargs[b'node'] = hex(cl.node(clstart)) | |
493 | hookargs[b'node_last'] = hex(cl.node(clend - 1)) |
|
498 | hookargs[b'node_last'] = hex(cl.node(clend - 1)) | |
494 | repo.hook( |
|
499 | repo.hook( | |
495 | b'pretxnchangegroup', |
|
500 | b'pretxnchangegroup', | |
496 | throw=True, |
|
501 | throw=True, | |
497 | **pycompat.strkwargs(hookargs) |
|
502 | **pycompat.strkwargs(hookargs) | |
498 | ) |
|
503 | ) | |
499 |
|
504 | |||
500 | added = pycompat.xrange(clstart, clend) |
|
505 | added = pycompat.xrange(clstart, clend) | |
501 | phaseall = None |
|
506 | phaseall = None | |
502 | if srctype in (b'push', b'serve'): |
|
507 | if srctype in (b'push', b'serve'): | |
503 | # Old servers can not push the boundary themselves. |
|
508 | # Old servers can not push the boundary themselves. | |
504 | # New servers won't push the boundary if changeset already |
|
509 | # New servers won't push the boundary if changeset already | |
505 | # exists locally as secret |
|
510 | # exists locally as secret | |
506 | # |
|
511 | # | |
507 | # We should not use added here but the list of all change in |
|
512 | # We should not use added here but the list of all change in | |
508 | # the bundle |
|
513 | # the bundle | |
509 | if repo.publishing(): |
|
514 | if repo.publishing(): | |
510 | targetphase = phaseall = phases.public |
|
515 | targetphase = phaseall = phases.public | |
511 | else: |
|
516 | else: | |
512 | # closer target phase computation |
|
517 | # closer target phase computation | |
513 |
|
518 | |||
514 | # Those changesets have been pushed from the |
|
519 | # Those changesets have been pushed from the | |
515 | # outside, their phases are going to be pushed |
|
520 | # outside, their phases are going to be pushed | |
516 | # alongside. Therefor `targetphase` is |
|
521 | # alongside. Therefor `targetphase` is | |
517 | # ignored. |
|
522 | # ignored. | |
518 | targetphase = phaseall = phases.draft |
|
523 | targetphase = phaseall = phases.draft | |
519 | if added: |
|
524 | if added: | |
520 | phases.registernew(repo, tr, targetphase, added) |
|
525 | phases.registernew(repo, tr, targetphase, added) | |
521 | if phaseall is not None: |
|
526 | if phaseall is not None: | |
522 | if duprevs: |
|
527 | if duprevs: | |
523 | duprevs.extend(added) |
|
528 | duprevs.extend(added) | |
524 | else: |
|
529 | else: | |
525 | duprevs = added |
|
530 | duprevs = added | |
526 | phases.advanceboundary(repo, tr, phaseall, [], revs=duprevs) |
|
531 | phases.advanceboundary(repo, tr, phaseall, [], revs=duprevs) | |
527 | duprevs = [] |
|
532 | duprevs = [] | |
528 |
|
533 | |||
529 | if changesets > 0: |
|
534 | if changesets > 0: | |
530 |
|
535 | |||
531 | def runhooks(unused_success): |
|
536 | def runhooks(unused_success): | |
532 | # These hooks run when the lock releases, not when the |
|
537 | # These hooks run when the lock releases, not when the | |
533 | # transaction closes. So it's possible for the changelog |
|
538 | # transaction closes. So it's possible for the changelog | |
534 | # to have changed since we last saw it. |
|
539 | # to have changed since we last saw it. | |
535 | if clstart >= len(repo): |
|
540 | if clstart >= len(repo): | |
536 | return |
|
541 | return | |
537 |
|
542 | |||
538 | repo.hook(b"changegroup", **pycompat.strkwargs(hookargs)) |
|
543 | repo.hook(b"changegroup", **pycompat.strkwargs(hookargs)) | |
539 |
|
544 | |||
540 | for rev in added: |
|
545 | for rev in added: | |
541 | args = hookargs.copy() |
|
546 | args = hookargs.copy() | |
542 | args[b'node'] = hex(cl.node(rev)) |
|
547 | args[b'node'] = hex(cl.node(rev)) | |
543 | del args[b'node_last'] |
|
548 | del args[b'node_last'] | |
544 | repo.hook(b"incoming", **pycompat.strkwargs(args)) |
|
549 | repo.hook(b"incoming", **pycompat.strkwargs(args)) | |
545 |
|
550 | |||
546 | newheads = [h for h in repo.heads() if h not in oldheads] |
|
551 | newheads = [h for h in repo.heads() if h not in oldheads] | |
547 | repo.ui.log( |
|
552 | repo.ui.log( | |
548 | b"incoming", |
|
553 | b"incoming", | |
549 | b"%d incoming changes - new heads: %s\n", |
|
554 | b"%d incoming changes - new heads: %s\n", | |
550 | len(added), |
|
555 | len(added), | |
551 | b', '.join([hex(c[:6]) for c in newheads]), |
|
556 | b', '.join([hex(c[:6]) for c in newheads]), | |
552 | ) |
|
557 | ) | |
553 |
|
558 | |||
554 | tr.addpostclose( |
|
559 | tr.addpostclose( | |
555 | b'changegroup-runhooks-%020i' % clstart, |
|
560 | b'changegroup-runhooks-%020i' % clstart, | |
556 | lambda tr: repo._afterlock(runhooks), |
|
561 | lambda tr: repo._afterlock(runhooks), | |
557 | ) |
|
562 | ) | |
558 | finally: |
|
563 | finally: | |
559 | repo.ui.flush() |
|
564 | repo.ui.flush() | |
560 | # never return 0 here: |
|
565 | # never return 0 here: | |
561 | if deltaheads < 0: |
|
566 | if deltaheads < 0: | |
562 | ret = deltaheads - 1 |
|
567 | ret = deltaheads - 1 | |
563 | else: |
|
568 | else: | |
564 | ret = deltaheads + 1 |
|
569 | ret = deltaheads + 1 | |
565 | return ret |
|
570 | return ret | |
566 |
|
571 | |||
567 | def deltaiter(self): |
|
572 | def deltaiter(self): | |
568 | """ |
|
573 | """ | |
569 | returns an iterator of the deltas in this changegroup |
|
574 | returns an iterator of the deltas in this changegroup | |
570 |
|
575 | |||
571 | Useful for passing to the underlying storage system to be stored. |
|
576 | Useful for passing to the underlying storage system to be stored. | |
572 | """ |
|
577 | """ | |
573 | chain = None |
|
578 | chain = None | |
574 | for chunkdata in iter(lambda: self.deltachunk(chain), {}): |
|
579 | for chunkdata in iter(lambda: self.deltachunk(chain), {}): | |
575 | # Chunkdata: (node, p1, p2, cs, deltabase, delta, flags, sidedata) |
|
580 | # Chunkdata: (node, p1, p2, cs, deltabase, delta, flags, sidedata) | |
576 | yield chunkdata |
|
581 | yield chunkdata | |
577 | chain = chunkdata[0] |
|
582 | chain = chunkdata[0] | |
578 |
|
583 | |||
579 |
|
584 | |||
580 | class cg2unpacker(cg1unpacker): |
|
585 | class cg2unpacker(cg1unpacker): | |
581 | """Unpacker for cg2 streams. |
|
586 | """Unpacker for cg2 streams. | |
582 |
|
587 | |||
583 | cg2 streams add support for generaldelta, so the delta header |
|
588 | cg2 streams add support for generaldelta, so the delta header | |
584 | format is slightly different. All other features about the data |
|
589 | format is slightly different. All other features about the data | |
585 | remain the same. |
|
590 | remain the same. | |
586 | """ |
|
591 | """ | |
587 |
|
592 | |||
588 | deltaheader = _CHANGEGROUPV2_DELTA_HEADER |
|
593 | deltaheader = _CHANGEGROUPV2_DELTA_HEADER | |
589 | deltaheadersize = deltaheader.size |
|
594 | deltaheadersize = deltaheader.size | |
590 | version = b'02' |
|
595 | version = b'02' | |
591 |
|
596 | |||
592 | def _deltaheader(self, headertuple, prevnode): |
|
597 | def _deltaheader(self, headertuple, prevnode): | |
593 | node, p1, p2, deltabase, cs = headertuple |
|
598 | node, p1, p2, deltabase, cs = headertuple | |
594 | flags = 0 |
|
599 | flags = 0 | |
595 | return node, p1, p2, deltabase, cs, flags |
|
600 | return node, p1, p2, deltabase, cs, flags | |
596 |
|
601 | |||
597 |
|
602 | |||
598 | class cg3unpacker(cg2unpacker): |
|
603 | class cg3unpacker(cg2unpacker): | |
599 | """Unpacker for cg3 streams. |
|
604 | """Unpacker for cg3 streams. | |
600 |
|
605 | |||
601 | cg3 streams add support for exchanging treemanifests and revlog |
|
606 | cg3 streams add support for exchanging treemanifests and revlog | |
602 | flags. It adds the revlog flags to the delta header and an empty chunk |
|
607 | flags. It adds the revlog flags to the delta header and an empty chunk | |
603 | separating manifests and files. |
|
608 | separating manifests and files. | |
604 | """ |
|
609 | """ | |
605 |
|
610 | |||
606 | deltaheader = _CHANGEGROUPV3_DELTA_HEADER |
|
611 | deltaheader = _CHANGEGROUPV3_DELTA_HEADER | |
607 | deltaheadersize = deltaheader.size |
|
612 | deltaheadersize = deltaheader.size | |
608 | version = b'03' |
|
613 | version = b'03' | |
609 | _grouplistcount = 2 # One list of manifests and one list of files |
|
614 | _grouplistcount = 2 # One list of manifests and one list of files | |
610 |
|
615 | |||
611 | def _deltaheader(self, headertuple, prevnode): |
|
616 | def _deltaheader(self, headertuple, prevnode): | |
612 | node, p1, p2, deltabase, cs, flags = headertuple |
|
617 | node, p1, p2, deltabase, cs, flags = headertuple | |
613 | return node, p1, p2, deltabase, cs, flags |
|
618 | return node, p1, p2, deltabase, cs, flags | |
614 |
|
619 | |||
615 | def _unpackmanifests(self, repo, revmap, trp, prog, addrevisioncb=None): |
|
620 | def _unpackmanifests(self, repo, revmap, trp, prog, addrevisioncb=None): | |
616 | super(cg3unpacker, self)._unpackmanifests( |
|
621 | super(cg3unpacker, self)._unpackmanifests( | |
617 | repo, revmap, trp, prog, addrevisioncb=addrevisioncb |
|
622 | repo, revmap, trp, prog, addrevisioncb=addrevisioncb | |
618 | ) |
|
623 | ) | |
619 | for chunkdata in iter(self.filelogheader, {}): |
|
624 | for chunkdata in iter(self.filelogheader, {}): | |
620 | # If we get here, there are directory manifests in the changegroup |
|
625 | # If we get here, there are directory manifests in the changegroup | |
621 | d = chunkdata[b"filename"] |
|
626 | d = chunkdata[b"filename"] | |
622 | repo.ui.debug(b"adding %s revisions\n" % d) |
|
627 | repo.ui.debug(b"adding %s revisions\n" % d) | |
623 | deltas = self.deltaiter() |
|
628 | deltas = self.deltaiter() | |
624 | if not repo.manifestlog.getstorage(d).addgroup( |
|
629 | if not repo.manifestlog.getstorage(d).addgroup( | |
625 | deltas, revmap, trp, addrevisioncb=addrevisioncb |
|
630 | deltas, revmap, trp, addrevisioncb=addrevisioncb | |
626 | ): |
|
631 | ): | |
627 | raise error.Abort(_(b"received dir revlog group is empty")) |
|
632 | raise error.Abort(_(b"received dir revlog group is empty")) | |
628 |
|
633 | |||
629 |
|
634 | |||
630 | class cg4unpacker(cg3unpacker): |
|
635 | class cg4unpacker(cg3unpacker): | |
631 | """Unpacker for cg4 streams. |
|
636 | """Unpacker for cg4 streams. | |
632 |
|
637 | |||
633 | cg4 streams add support for exchanging sidedata. |
|
638 | cg4 streams add support for exchanging sidedata. | |
634 | """ |
|
639 | """ | |
635 |
|
640 | |||
636 | version = b'04' |
|
641 | version = b'04' | |
637 |
|
642 | |||
638 | def deltachunk(self, prevnode): |
|
643 | def deltachunk(self, prevnode): | |
639 | res = super(cg4unpacker, self).deltachunk(prevnode) |
|
644 | res = super(cg4unpacker, self).deltachunk(prevnode) | |
640 | if not res: |
|
645 | if not res: | |
641 | return res |
|
646 | return res | |
642 |
|
647 | |||
643 | (node, p1, p2, cs, deltabase, delta, flags, _sidedata) = res |
|
648 | (node, p1, p2, cs, deltabase, delta, flags, _sidedata) = res | |
644 |
|
649 | |||
645 | sidedata_raw = getchunk(self._stream) |
|
650 | sidedata_raw = getchunk(self._stream) | |
646 | sidedata = {} |
|
651 | sidedata = {} | |
647 | if len(sidedata_raw) > 0: |
|
652 | if len(sidedata_raw) > 0: | |
648 | sidedata = sidedatamod.deserialize_sidedata(sidedata_raw) |
|
653 | sidedata = sidedatamod.deserialize_sidedata(sidedata_raw) | |
649 |
|
654 | |||
650 | return node, p1, p2, cs, deltabase, delta, flags, sidedata |
|
655 | return node, p1, p2, cs, deltabase, delta, flags, sidedata | |
651 |
|
656 | |||
652 |
|
657 | |||
653 | class headerlessfixup(object): |
|
658 | class headerlessfixup(object): | |
654 | def __init__(self, fh, h): |
|
659 | def __init__(self, fh, h): | |
655 | self._h = h |
|
660 | self._h = h | |
656 | self._fh = fh |
|
661 | self._fh = fh | |
657 |
|
662 | |||
658 | def read(self, n): |
|
663 | def read(self, n): | |
659 | if self._h: |
|
664 | if self._h: | |
660 | d, self._h = self._h[:n], self._h[n:] |
|
665 | d, self._h = self._h[:n], self._h[n:] | |
661 | if len(d) < n: |
|
666 | if len(d) < n: | |
662 | d += readexactly(self._fh, n - len(d)) |
|
667 | d += readexactly(self._fh, n - len(d)) | |
663 | return d |
|
668 | return d | |
664 | return readexactly(self._fh, n) |
|
669 | return readexactly(self._fh, n) | |
665 |
|
670 | |||
666 |
|
671 | |||
667 | def _revisiondeltatochunks(repo, delta, headerfn): |
|
672 | def _revisiondeltatochunks(repo, delta, headerfn): | |
668 | """Serialize a revisiondelta to changegroup chunks.""" |
|
673 | """Serialize a revisiondelta to changegroup chunks.""" | |
669 |
|
674 | |||
670 | # The captured revision delta may be encoded as a delta against |
|
675 | # The captured revision delta may be encoded as a delta against | |
671 | # a base revision or as a full revision. The changegroup format |
|
676 | # a base revision or as a full revision. The changegroup format | |
672 | # requires that everything on the wire be deltas. So for full |
|
677 | # requires that everything on the wire be deltas. So for full | |
673 | # revisions, we need to invent a header that says to rewrite |
|
678 | # revisions, we need to invent a header that says to rewrite | |
674 | # data. |
|
679 | # data. | |
675 |
|
680 | |||
676 | if delta.delta is not None: |
|
681 | if delta.delta is not None: | |
677 | prefix, data = b'', delta.delta |
|
682 | prefix, data = b'', delta.delta | |
678 | elif delta.basenode == repo.nullid: |
|
683 | elif delta.basenode == repo.nullid: | |
679 | data = delta.revision |
|
684 | data = delta.revision | |
680 | prefix = mdiff.trivialdiffheader(len(data)) |
|
685 | prefix = mdiff.trivialdiffheader(len(data)) | |
681 | else: |
|
686 | else: | |
682 | data = delta.revision |
|
687 | data = delta.revision | |
683 | prefix = mdiff.replacediffheader(delta.baserevisionsize, len(data)) |
|
688 | prefix = mdiff.replacediffheader(delta.baserevisionsize, len(data)) | |
684 |
|
689 | |||
685 | meta = headerfn(delta) |
|
690 | meta = headerfn(delta) | |
686 |
|
691 | |||
687 | yield chunkheader(len(meta) + len(prefix) + len(data)) |
|
692 | yield chunkheader(len(meta) + len(prefix) + len(data)) | |
688 | yield meta |
|
693 | yield meta | |
689 | if prefix: |
|
694 | if prefix: | |
690 | yield prefix |
|
695 | yield prefix | |
691 | yield data |
|
696 | yield data | |
692 |
|
697 | |||
693 | sidedata = delta.sidedata |
|
698 | sidedata = delta.sidedata | |
694 | if sidedata is not None: |
|
699 | if sidedata is not None: | |
695 | # Need a separate chunk for sidedata to be able to differentiate |
|
700 | # Need a separate chunk for sidedata to be able to differentiate | |
696 | # "raw delta" length and sidedata length |
|
701 | # "raw delta" length and sidedata length | |
697 | yield chunkheader(len(sidedata)) |
|
702 | yield chunkheader(len(sidedata)) | |
698 | yield sidedata |
|
703 | yield sidedata | |
699 |
|
704 | |||
700 |
|
705 | |||
701 | def _sortnodesellipsis(store, nodes, cl, lookup): |
|
706 | def _sortnodesellipsis(store, nodes, cl, lookup): | |
702 | """Sort nodes for changegroup generation.""" |
|
707 | """Sort nodes for changegroup generation.""" | |
703 | # Ellipses serving mode. |
|
708 | # Ellipses serving mode. | |
704 | # |
|
709 | # | |
705 | # In a perfect world, we'd generate better ellipsis-ified graphs |
|
710 | # In a perfect world, we'd generate better ellipsis-ified graphs | |
706 | # for non-changelog revlogs. In practice, we haven't started doing |
|
711 | # for non-changelog revlogs. In practice, we haven't started doing | |
707 | # that yet, so the resulting DAGs for the manifestlog and filelogs |
|
712 | # that yet, so the resulting DAGs for the manifestlog and filelogs | |
708 | # are actually full of bogus parentage on all the ellipsis |
|
713 | # are actually full of bogus parentage on all the ellipsis | |
709 | # nodes. This has the side effect that, while the contents are |
|
714 | # nodes. This has the side effect that, while the contents are | |
710 | # correct, the individual DAGs might be completely out of whack in |
|
715 | # correct, the individual DAGs might be completely out of whack in | |
711 | # a case like 882681bc3166 and its ancestors (back about 10 |
|
716 | # a case like 882681bc3166 and its ancestors (back about 10 | |
712 | # revisions or so) in the main hg repo. |
|
717 | # revisions or so) in the main hg repo. | |
713 | # |
|
718 | # | |
714 | # The one invariant we *know* holds is that the new (potentially |
|
719 | # The one invariant we *know* holds is that the new (potentially | |
715 | # bogus) DAG shape will be valid if we order the nodes in the |
|
720 | # bogus) DAG shape will be valid if we order the nodes in the | |
716 | # order that they're introduced in dramatis personae by the |
|
721 | # order that they're introduced in dramatis personae by the | |
717 | # changelog, so what we do is we sort the non-changelog histories |
|
722 | # changelog, so what we do is we sort the non-changelog histories | |
718 | # by the order in which they are used by the changelog. |
|
723 | # by the order in which they are used by the changelog. | |
719 | key = lambda n: cl.rev(lookup(n)) |
|
724 | key = lambda n: cl.rev(lookup(n)) | |
720 | return sorted(nodes, key=key) |
|
725 | return sorted(nodes, key=key) | |
721 |
|
726 | |||
722 |
|
727 | |||
723 | def _resolvenarrowrevisioninfo( |
|
728 | def _resolvenarrowrevisioninfo( | |
724 | cl, |
|
729 | cl, | |
725 | store, |
|
730 | store, | |
726 | ischangelog, |
|
731 | ischangelog, | |
727 | rev, |
|
732 | rev, | |
728 | linkrev, |
|
733 | linkrev, | |
729 | linknode, |
|
734 | linknode, | |
730 | clrevtolocalrev, |
|
735 | clrevtolocalrev, | |
731 | fullclnodes, |
|
736 | fullclnodes, | |
732 | precomputedellipsis, |
|
737 | precomputedellipsis, | |
733 | ): |
|
738 | ): | |
734 | linkparents = precomputedellipsis[linkrev] |
|
739 | linkparents = precomputedellipsis[linkrev] | |
735 |
|
740 | |||
736 | def local(clrev): |
|
741 | def local(clrev): | |
737 | """Turn a changelog revnum into a local revnum. |
|
742 | """Turn a changelog revnum into a local revnum. | |
738 |
|
743 | |||
739 | The ellipsis dag is stored as revnums on the changelog, |
|
744 | The ellipsis dag is stored as revnums on the changelog, | |
740 | but when we're producing ellipsis entries for |
|
745 | but when we're producing ellipsis entries for | |
741 | non-changelog revlogs, we need to turn those numbers into |
|
746 | non-changelog revlogs, we need to turn those numbers into | |
742 | something local. This does that for us, and during the |
|
747 | something local. This does that for us, and during the | |
743 | changelog sending phase will also expand the stored |
|
748 | changelog sending phase will also expand the stored | |
744 | mappings as needed. |
|
749 | mappings as needed. | |
745 | """ |
|
750 | """ | |
746 | if clrev == nullrev: |
|
751 | if clrev == nullrev: | |
747 | return nullrev |
|
752 | return nullrev | |
748 |
|
753 | |||
749 | if ischangelog: |
|
754 | if ischangelog: | |
750 | return clrev |
|
755 | return clrev | |
751 |
|
756 | |||
752 | # Walk the ellipsis-ized changelog breadth-first looking for a |
|
757 | # Walk the ellipsis-ized changelog breadth-first looking for a | |
753 | # change that has been linked from the current revlog. |
|
758 | # change that has been linked from the current revlog. | |
754 | # |
|
759 | # | |
755 | # For a flat manifest revlog only a single step should be necessary |
|
760 | # For a flat manifest revlog only a single step should be necessary | |
756 | # as all relevant changelog entries are relevant to the flat |
|
761 | # as all relevant changelog entries are relevant to the flat | |
757 | # manifest. |
|
762 | # manifest. | |
758 | # |
|
763 | # | |
759 | # For a filelog or tree manifest dirlog however not every changelog |
|
764 | # For a filelog or tree manifest dirlog however not every changelog | |
760 | # entry will have been relevant, so we need to skip some changelog |
|
765 | # entry will have been relevant, so we need to skip some changelog | |
761 | # nodes even after ellipsis-izing. |
|
766 | # nodes even after ellipsis-izing. | |
762 | walk = [clrev] |
|
767 | walk = [clrev] | |
763 | while walk: |
|
768 | while walk: | |
764 | p = walk[0] |
|
769 | p = walk[0] | |
765 | walk = walk[1:] |
|
770 | walk = walk[1:] | |
766 | if p in clrevtolocalrev: |
|
771 | if p in clrevtolocalrev: | |
767 | return clrevtolocalrev[p] |
|
772 | return clrevtolocalrev[p] | |
768 | elif p in fullclnodes: |
|
773 | elif p in fullclnodes: | |
769 | walk.extend([pp for pp in cl.parentrevs(p) if pp != nullrev]) |
|
774 | walk.extend([pp for pp in cl.parentrevs(p) if pp != nullrev]) | |
770 | elif p in precomputedellipsis: |
|
775 | elif p in precomputedellipsis: | |
771 | walk.extend( |
|
776 | walk.extend( | |
772 | [pp for pp in precomputedellipsis[p] if pp != nullrev] |
|
777 | [pp for pp in precomputedellipsis[p] if pp != nullrev] | |
773 | ) |
|
778 | ) | |
774 | else: |
|
779 | else: | |
775 | # In this case, we've got an ellipsis with parents |
|
780 | # In this case, we've got an ellipsis with parents | |
776 | # outside the current bundle (likely an |
|
781 | # outside the current bundle (likely an | |
777 | # incremental pull). We "know" that we can use the |
|
782 | # incremental pull). We "know" that we can use the | |
778 | # value of this same revlog at whatever revision |
|
783 | # value of this same revlog at whatever revision | |
779 | # is pointed to by linknode. "Know" is in scare |
|
784 | # is pointed to by linknode. "Know" is in scare | |
780 | # quotes because I haven't done enough examination |
|
785 | # quotes because I haven't done enough examination | |
781 | # of edge cases to convince myself this is really |
|
786 | # of edge cases to convince myself this is really | |
782 | # a fact - it works for all the (admittedly |
|
787 | # a fact - it works for all the (admittedly | |
783 | # thorough) cases in our testsuite, but I would be |
|
788 | # thorough) cases in our testsuite, but I would be | |
784 | # somewhat unsurprised to find a case in the wild |
|
789 | # somewhat unsurprised to find a case in the wild | |
785 | # where this breaks down a bit. That said, I don't |
|
790 | # where this breaks down a bit. That said, I don't | |
786 | # know if it would hurt anything. |
|
791 | # know if it would hurt anything. | |
787 | for i in pycompat.xrange(rev, 0, -1): |
|
792 | for i in pycompat.xrange(rev, 0, -1): | |
788 | if store.linkrev(i) == clrev: |
|
793 | if store.linkrev(i) == clrev: | |
789 | return i |
|
794 | return i | |
790 | # We failed to resolve a parent for this node, so |
|
795 | # We failed to resolve a parent for this node, so | |
791 | # we crash the changegroup construction. |
|
796 | # we crash the changegroup construction. | |
792 | raise error.Abort( |
|
797 | raise error.Abort( | |
793 | b"unable to resolve parent while packing '%s' %r" |
|
798 | b"unable to resolve parent while packing '%s' %r" | |
794 | b' for changeset %r' % (store.indexfile, rev, clrev) |
|
799 | b' for changeset %r' % (store.indexfile, rev, clrev) | |
795 | ) |
|
800 | ) | |
796 |
|
801 | |||
797 | return nullrev |
|
802 | return nullrev | |
798 |
|
803 | |||
799 | if not linkparents or (store.parentrevs(rev) == (nullrev, nullrev)): |
|
804 | if not linkparents or (store.parentrevs(rev) == (nullrev, nullrev)): | |
800 | p1, p2 = nullrev, nullrev |
|
805 | p1, p2 = nullrev, nullrev | |
801 | elif len(linkparents) == 1: |
|
806 | elif len(linkparents) == 1: | |
802 | (p1,) = sorted(local(p) for p in linkparents) |
|
807 | (p1,) = sorted(local(p) for p in linkparents) | |
803 | p2 = nullrev |
|
808 | p2 = nullrev | |
804 | else: |
|
809 | else: | |
805 | p1, p2 = sorted(local(p) for p in linkparents) |
|
810 | p1, p2 = sorted(local(p) for p in linkparents) | |
806 |
|
811 | |||
807 | p1node, p2node = store.node(p1), store.node(p2) |
|
812 | p1node, p2node = store.node(p1), store.node(p2) | |
808 |
|
813 | |||
809 | return p1node, p2node, linknode |
|
814 | return p1node, p2node, linknode | |
810 |
|
815 | |||
811 |
|
816 | |||
812 | def deltagroup( |
|
817 | def deltagroup( | |
813 | repo, |
|
818 | repo, | |
814 | store, |
|
819 | store, | |
815 | nodes, |
|
820 | nodes, | |
816 | ischangelog, |
|
821 | ischangelog, | |
817 | lookup, |
|
822 | lookup, | |
818 | forcedeltaparentprev, |
|
823 | forcedeltaparentprev, | |
819 | topic=None, |
|
824 | topic=None, | |
820 | ellipses=False, |
|
825 | ellipses=False, | |
821 | clrevtolocalrev=None, |
|
826 | clrevtolocalrev=None, | |
822 | fullclnodes=None, |
|
827 | fullclnodes=None, | |
823 | precomputedellipsis=None, |
|
828 | precomputedellipsis=None, | |
824 | sidedata_helpers=None, |
|
829 | sidedata_helpers=None, | |
825 | ): |
|
830 | ): | |
826 | """Calculate deltas for a set of revisions. |
|
831 | """Calculate deltas for a set of revisions. | |
827 |
|
832 | |||
828 | Is a generator of ``revisiondelta`` instances. |
|
833 | Is a generator of ``revisiondelta`` instances. | |
829 |
|
834 | |||
830 | If topic is not None, progress detail will be generated using this |
|
835 | If topic is not None, progress detail will be generated using this | |
831 | topic name (e.g. changesets, manifests, etc). |
|
836 | topic name (e.g. changesets, manifests, etc). | |
832 |
|
837 | |||
833 | See `storageutil.emitrevisions` for the doc on `sidedata_helpers`. |
|
838 | See `storageutil.emitrevisions` for the doc on `sidedata_helpers`. | |
834 | """ |
|
839 | """ | |
835 | if not nodes: |
|
840 | if not nodes: | |
836 | return |
|
841 | return | |
837 |
|
842 | |||
838 | cl = repo.changelog |
|
843 | cl = repo.changelog | |
839 |
|
844 | |||
840 | if ischangelog: |
|
845 | if ischangelog: | |
841 | # `hg log` shows changesets in storage order. To preserve order |
|
846 | # `hg log` shows changesets in storage order. To preserve order | |
842 | # across clones, send out changesets in storage order. |
|
847 | # across clones, send out changesets in storage order. | |
843 | nodesorder = b'storage' |
|
848 | nodesorder = b'storage' | |
844 | elif ellipses: |
|
849 | elif ellipses: | |
845 | nodes = _sortnodesellipsis(store, nodes, cl, lookup) |
|
850 | nodes = _sortnodesellipsis(store, nodes, cl, lookup) | |
846 | nodesorder = b'nodes' |
|
851 | nodesorder = b'nodes' | |
847 | else: |
|
852 | else: | |
848 | nodesorder = None |
|
853 | nodesorder = None | |
849 |
|
854 | |||
850 | # Perform ellipses filtering and revision massaging. We do this before |
|
855 | # Perform ellipses filtering and revision massaging. We do this before | |
851 | # emitrevisions() because a) filtering out revisions creates less work |
|
856 | # emitrevisions() because a) filtering out revisions creates less work | |
852 | # for emitrevisions() b) dropping revisions would break emitrevisions()'s |
|
857 | # for emitrevisions() b) dropping revisions would break emitrevisions()'s | |
853 | # assumptions about delta choices and we would possibly send a delta |
|
858 | # assumptions about delta choices and we would possibly send a delta | |
854 | # referencing a missing base revision. |
|
859 | # referencing a missing base revision. | |
855 | # |
|
860 | # | |
856 | # Also, calling lookup() has side-effects with regards to populating |
|
861 | # Also, calling lookup() has side-effects with regards to populating | |
857 | # data structures. If we don't call lookup() for each node or if we call |
|
862 | # data structures. If we don't call lookup() for each node or if we call | |
858 | # lookup() after the first pass through each node, things can break - |
|
863 | # lookup() after the first pass through each node, things can break - | |
859 | # possibly intermittently depending on the python hash seed! For that |
|
864 | # possibly intermittently depending on the python hash seed! For that | |
860 | # reason, we store a mapping of all linknodes during the initial node |
|
865 | # reason, we store a mapping of all linknodes during the initial node | |
861 | # pass rather than use lookup() on the output side. |
|
866 | # pass rather than use lookup() on the output side. | |
862 | if ellipses: |
|
867 | if ellipses: | |
863 | filtered = [] |
|
868 | filtered = [] | |
864 | adjustedparents = {} |
|
869 | adjustedparents = {} | |
865 | linknodes = {} |
|
870 | linknodes = {} | |
866 |
|
871 | |||
867 | for node in nodes: |
|
872 | for node in nodes: | |
868 | rev = store.rev(node) |
|
873 | rev = store.rev(node) | |
869 | linknode = lookup(node) |
|
874 | linknode = lookup(node) | |
870 | linkrev = cl.rev(linknode) |
|
875 | linkrev = cl.rev(linknode) | |
871 | clrevtolocalrev[linkrev] = rev |
|
876 | clrevtolocalrev[linkrev] = rev | |
872 |
|
877 | |||
873 | # If linknode is in fullclnodes, it means the corresponding |
|
878 | # If linknode is in fullclnodes, it means the corresponding | |
874 | # changeset was a full changeset and is being sent unaltered. |
|
879 | # changeset was a full changeset and is being sent unaltered. | |
875 | if linknode in fullclnodes: |
|
880 | if linknode in fullclnodes: | |
876 | linknodes[node] = linknode |
|
881 | linknodes[node] = linknode | |
877 |
|
882 | |||
878 | # If the corresponding changeset wasn't in the set computed |
|
883 | # If the corresponding changeset wasn't in the set computed | |
879 | # as relevant to us, it should be dropped outright. |
|
884 | # as relevant to us, it should be dropped outright. | |
880 | elif linkrev not in precomputedellipsis: |
|
885 | elif linkrev not in precomputedellipsis: | |
881 | continue |
|
886 | continue | |
882 |
|
887 | |||
883 | else: |
|
888 | else: | |
884 | # We could probably do this later and avoid the dict |
|
889 | # We could probably do this later and avoid the dict | |
885 | # holding state. But it likely doesn't matter. |
|
890 | # holding state. But it likely doesn't matter. | |
886 | p1node, p2node, linknode = _resolvenarrowrevisioninfo( |
|
891 | p1node, p2node, linknode = _resolvenarrowrevisioninfo( | |
887 | cl, |
|
892 | cl, | |
888 | store, |
|
893 | store, | |
889 | ischangelog, |
|
894 | ischangelog, | |
890 | rev, |
|
895 | rev, | |
891 | linkrev, |
|
896 | linkrev, | |
892 | linknode, |
|
897 | linknode, | |
893 | clrevtolocalrev, |
|
898 | clrevtolocalrev, | |
894 | fullclnodes, |
|
899 | fullclnodes, | |
895 | precomputedellipsis, |
|
900 | precomputedellipsis, | |
896 | ) |
|
901 | ) | |
897 |
|
902 | |||
898 | adjustedparents[node] = (p1node, p2node) |
|
903 | adjustedparents[node] = (p1node, p2node) | |
899 | linknodes[node] = linknode |
|
904 | linknodes[node] = linknode | |
900 |
|
905 | |||
901 | filtered.append(node) |
|
906 | filtered.append(node) | |
902 |
|
907 | |||
903 | nodes = filtered |
|
908 | nodes = filtered | |
904 |
|
909 | |||
905 | # We expect the first pass to be fast, so we only engage the progress |
|
910 | # We expect the first pass to be fast, so we only engage the progress | |
906 | # meter for constructing the revision deltas. |
|
911 | # meter for constructing the revision deltas. | |
907 | progress = None |
|
912 | progress = None | |
908 | if topic is not None: |
|
913 | if topic is not None: | |
909 | progress = repo.ui.makeprogress( |
|
914 | progress = repo.ui.makeprogress( | |
910 | topic, unit=_(b'chunks'), total=len(nodes) |
|
915 | topic, unit=_(b'chunks'), total=len(nodes) | |
911 | ) |
|
916 | ) | |
912 |
|
917 | |||
913 | configtarget = repo.ui.config(b'devel', b'bundle.delta') |
|
918 | configtarget = repo.ui.config(b'devel', b'bundle.delta') | |
914 | if configtarget not in (b'', b'p1', b'full'): |
|
919 | if configtarget not in (b'', b'p1', b'full'): | |
915 | msg = _(b"""config "devel.bundle.delta" as unknown value: %s""") |
|
920 | msg = _(b"""config "devel.bundle.delta" as unknown value: %s""") | |
916 | repo.ui.warn(msg % configtarget) |
|
921 | repo.ui.warn(msg % configtarget) | |
917 |
|
922 | |||
918 | deltamode = repository.CG_DELTAMODE_STD |
|
923 | deltamode = repository.CG_DELTAMODE_STD | |
919 | if forcedeltaparentprev: |
|
924 | if forcedeltaparentprev: | |
920 | deltamode = repository.CG_DELTAMODE_PREV |
|
925 | deltamode = repository.CG_DELTAMODE_PREV | |
921 | elif configtarget == b'p1': |
|
926 | elif configtarget == b'p1': | |
922 | deltamode = repository.CG_DELTAMODE_P1 |
|
927 | deltamode = repository.CG_DELTAMODE_P1 | |
923 | elif configtarget == b'full': |
|
928 | elif configtarget == b'full': | |
924 | deltamode = repository.CG_DELTAMODE_FULL |
|
929 | deltamode = repository.CG_DELTAMODE_FULL | |
925 |
|
930 | |||
926 | revisions = store.emitrevisions( |
|
931 | revisions = store.emitrevisions( | |
927 | nodes, |
|
932 | nodes, | |
928 | nodesorder=nodesorder, |
|
933 | nodesorder=nodesorder, | |
929 | revisiondata=True, |
|
934 | revisiondata=True, | |
930 | assumehaveparentrevisions=not ellipses, |
|
935 | assumehaveparentrevisions=not ellipses, | |
931 | deltamode=deltamode, |
|
936 | deltamode=deltamode, | |
932 | sidedata_helpers=sidedata_helpers, |
|
937 | sidedata_helpers=sidedata_helpers, | |
933 | ) |
|
938 | ) | |
934 |
|
939 | |||
935 | for i, revision in enumerate(revisions): |
|
940 | for i, revision in enumerate(revisions): | |
936 | if progress: |
|
941 | if progress: | |
937 | progress.update(i + 1) |
|
942 | progress.update(i + 1) | |
938 |
|
943 | |||
939 | if ellipses: |
|
944 | if ellipses: | |
940 | linknode = linknodes[revision.node] |
|
945 | linknode = linknodes[revision.node] | |
941 |
|
946 | |||
942 | if revision.node in adjustedparents: |
|
947 | if revision.node in adjustedparents: | |
943 | p1node, p2node = adjustedparents[revision.node] |
|
948 | p1node, p2node = adjustedparents[revision.node] | |
944 | revision.p1node = p1node |
|
949 | revision.p1node = p1node | |
945 | revision.p2node = p2node |
|
950 | revision.p2node = p2node | |
946 | revision.flags |= repository.REVISION_FLAG_ELLIPSIS |
|
951 | revision.flags |= repository.REVISION_FLAG_ELLIPSIS | |
947 |
|
952 | |||
948 | else: |
|
953 | else: | |
949 | linknode = lookup(revision.node) |
|
954 | linknode = lookup(revision.node) | |
950 |
|
955 | |||
951 | revision.linknode = linknode |
|
956 | revision.linknode = linknode | |
952 | yield revision |
|
957 | yield revision | |
953 |
|
958 | |||
954 | if progress: |
|
959 | if progress: | |
955 | progress.complete() |
|
960 | progress.complete() | |
956 |
|
961 | |||
957 |
|
962 | |||
958 | class cgpacker(object): |
|
963 | class cgpacker(object): | |
959 | def __init__( |
|
964 | def __init__( | |
960 | self, |
|
965 | self, | |
961 | repo, |
|
966 | repo, | |
962 | oldmatcher, |
|
967 | oldmatcher, | |
963 | matcher, |
|
968 | matcher, | |
964 | version, |
|
969 | version, | |
965 | builddeltaheader, |
|
970 | builddeltaheader, | |
966 | manifestsend, |
|
971 | manifestsend, | |
967 | forcedeltaparentprev=False, |
|
972 | forcedeltaparentprev=False, | |
968 | bundlecaps=None, |
|
973 | bundlecaps=None, | |
969 | ellipses=False, |
|
974 | ellipses=False, | |
970 | shallow=False, |
|
975 | shallow=False, | |
971 | ellipsisroots=None, |
|
976 | ellipsisroots=None, | |
972 | fullnodes=None, |
|
977 | fullnodes=None, | |
973 | remote_sidedata=None, |
|
978 | remote_sidedata=None, | |
974 | ): |
|
979 | ): | |
975 | """Given a source repo, construct a bundler. |
|
980 | """Given a source repo, construct a bundler. | |
976 |
|
981 | |||
977 | oldmatcher is a matcher that matches on files the client already has. |
|
982 | oldmatcher is a matcher that matches on files the client already has. | |
978 | These will not be included in the changegroup. |
|
983 | These will not be included in the changegroup. | |
979 |
|
984 | |||
980 | matcher is a matcher that matches on files to include in the |
|
985 | matcher is a matcher that matches on files to include in the | |
981 | changegroup. Used to facilitate sparse changegroups. |
|
986 | changegroup. Used to facilitate sparse changegroups. | |
982 |
|
987 | |||
983 | forcedeltaparentprev indicates whether delta parents must be against |
|
988 | forcedeltaparentprev indicates whether delta parents must be against | |
984 | the previous revision in a delta group. This should only be used for |
|
989 | the previous revision in a delta group. This should only be used for | |
985 | compatibility with changegroup version 1. |
|
990 | compatibility with changegroup version 1. | |
986 |
|
991 | |||
987 | builddeltaheader is a callable that constructs the header for a group |
|
992 | builddeltaheader is a callable that constructs the header for a group | |
988 | delta. |
|
993 | delta. | |
989 |
|
994 | |||
990 | manifestsend is a chunk to send after manifests have been fully emitted. |
|
995 | manifestsend is a chunk to send after manifests have been fully emitted. | |
991 |
|
996 | |||
992 | ellipses indicates whether ellipsis serving mode is enabled. |
|
997 | ellipses indicates whether ellipsis serving mode is enabled. | |
993 |
|
998 | |||
994 | bundlecaps is optional and can be used to specify the set of |
|
999 | bundlecaps is optional and can be used to specify the set of | |
995 | capabilities which can be used to build the bundle. While bundlecaps is |
|
1000 | capabilities which can be used to build the bundle. While bundlecaps is | |
996 | unused in core Mercurial, extensions rely on this feature to communicate |
|
1001 | unused in core Mercurial, extensions rely on this feature to communicate | |
997 | capabilities to customize the changegroup packer. |
|
1002 | capabilities to customize the changegroup packer. | |
998 |
|
1003 | |||
999 | shallow indicates whether shallow data might be sent. The packer may |
|
1004 | shallow indicates whether shallow data might be sent. The packer may | |
1000 | need to pack file contents not introduced by the changes being packed. |
|
1005 | need to pack file contents not introduced by the changes being packed. | |
1001 |
|
1006 | |||
1002 | fullnodes is the set of changelog nodes which should not be ellipsis |
|
1007 | fullnodes is the set of changelog nodes which should not be ellipsis | |
1003 | nodes. We store this rather than the set of nodes that should be |
|
1008 | nodes. We store this rather than the set of nodes that should be | |
1004 | ellipsis because for very large histories we expect this to be |
|
1009 | ellipsis because for very large histories we expect this to be | |
1005 | significantly smaller. |
|
1010 | significantly smaller. | |
1006 |
|
1011 | |||
1007 | remote_sidedata is the set of sidedata categories wanted by the remote. |
|
1012 | remote_sidedata is the set of sidedata categories wanted by the remote. | |
1008 | """ |
|
1013 | """ | |
1009 | assert oldmatcher |
|
1014 | assert oldmatcher | |
1010 | assert matcher |
|
1015 | assert matcher | |
1011 | self._oldmatcher = oldmatcher |
|
1016 | self._oldmatcher = oldmatcher | |
1012 | self._matcher = matcher |
|
1017 | self._matcher = matcher | |
1013 |
|
1018 | |||
1014 | self.version = version |
|
1019 | self.version = version | |
1015 | self._forcedeltaparentprev = forcedeltaparentprev |
|
1020 | self._forcedeltaparentprev = forcedeltaparentprev | |
1016 | self._builddeltaheader = builddeltaheader |
|
1021 | self._builddeltaheader = builddeltaheader | |
1017 | self._manifestsend = manifestsend |
|
1022 | self._manifestsend = manifestsend | |
1018 | self._ellipses = ellipses |
|
1023 | self._ellipses = ellipses | |
1019 |
|
1024 | |||
1020 | # Set of capabilities we can use to build the bundle. |
|
1025 | # Set of capabilities we can use to build the bundle. | |
1021 | if bundlecaps is None: |
|
1026 | if bundlecaps is None: | |
1022 | bundlecaps = set() |
|
1027 | bundlecaps = set() | |
1023 | self._bundlecaps = bundlecaps |
|
1028 | self._bundlecaps = bundlecaps | |
1024 | if remote_sidedata is None: |
|
1029 | if remote_sidedata is None: | |
1025 | remote_sidedata = set() |
|
1030 | remote_sidedata = set() | |
1026 | self._remote_sidedata = remote_sidedata |
|
1031 | self._remote_sidedata = remote_sidedata | |
1027 | self._isshallow = shallow |
|
1032 | self._isshallow = shallow | |
1028 | self._fullclnodes = fullnodes |
|
1033 | self._fullclnodes = fullnodes | |
1029 |
|
1034 | |||
1030 | # Maps ellipsis revs to their roots at the changelog level. |
|
1035 | # Maps ellipsis revs to their roots at the changelog level. | |
1031 | self._precomputedellipsis = ellipsisroots |
|
1036 | self._precomputedellipsis = ellipsisroots | |
1032 |
|
1037 | |||
1033 | self._repo = repo |
|
1038 | self._repo = repo | |
1034 |
|
1039 | |||
1035 | if self._repo.ui.verbose and not self._repo.ui.debugflag: |
|
1040 | if self._repo.ui.verbose and not self._repo.ui.debugflag: | |
1036 | self._verbosenote = self._repo.ui.note |
|
1041 | self._verbosenote = self._repo.ui.note | |
1037 | else: |
|
1042 | else: | |
1038 | self._verbosenote = lambda s: None |
|
1043 | self._verbosenote = lambda s: None | |
1039 |
|
1044 | |||
1040 | def generate( |
|
1045 | def generate( | |
1041 | self, commonrevs, clnodes, fastpathlinkrev, source, changelog=True |
|
1046 | self, commonrevs, clnodes, fastpathlinkrev, source, changelog=True | |
1042 | ): |
|
1047 | ): | |
1043 | """Yield a sequence of changegroup byte chunks. |
|
1048 | """Yield a sequence of changegroup byte chunks. | |
1044 | If changelog is False, changelog data won't be added to changegroup |
|
1049 | If changelog is False, changelog data won't be added to changegroup | |
1045 | """ |
|
1050 | """ | |
1046 |
|
1051 | |||
1047 | repo = self._repo |
|
1052 | repo = self._repo | |
1048 | cl = repo.changelog |
|
1053 | cl = repo.changelog | |
1049 |
|
1054 | |||
1050 | self._verbosenote(_(b'uncompressed size of bundle content:\n')) |
|
1055 | self._verbosenote(_(b'uncompressed size of bundle content:\n')) | |
1051 | size = 0 |
|
1056 | size = 0 | |
1052 |
|
1057 | |||
1053 | sidedata_helpers = None |
|
1058 | sidedata_helpers = None | |
1054 | if self.version == b'04': |
|
1059 | if self.version == b'04': | |
1055 | remote_sidedata = self._remote_sidedata |
|
1060 | remote_sidedata = self._remote_sidedata | |
1056 | if source == b'strip': |
|
1061 | if source == b'strip': | |
1057 | # We're our own remote when stripping, get the no-op helpers |
|
1062 | # We're our own remote when stripping, get the no-op helpers | |
1058 | # TODO a better approach would be for the strip bundle to |
|
1063 | # TODO a better approach would be for the strip bundle to | |
1059 | # correctly advertise its sidedata categories directly. |
|
1064 | # correctly advertise its sidedata categories directly. | |
1060 | remote_sidedata = repo._wanted_sidedata |
|
1065 | remote_sidedata = repo._wanted_sidedata | |
1061 | sidedata_helpers = get_sidedata_helpers(repo, remote_sidedata) |
|
1066 | sidedata_helpers = get_sidedata_helpers(repo, remote_sidedata) | |
1062 |
|
1067 | |||
1063 | clstate, deltas = self._generatechangelog( |
|
1068 | clstate, deltas = self._generatechangelog( | |
1064 | cl, |
|
1069 | cl, | |
1065 | clnodes, |
|
1070 | clnodes, | |
1066 | generate=changelog, |
|
1071 | generate=changelog, | |
1067 | sidedata_helpers=sidedata_helpers, |
|
1072 | sidedata_helpers=sidedata_helpers, | |
1068 | ) |
|
1073 | ) | |
1069 | for delta in deltas: |
|
1074 | for delta in deltas: | |
1070 | for chunk in _revisiondeltatochunks( |
|
1075 | for chunk in _revisiondeltatochunks( | |
1071 | self._repo, delta, self._builddeltaheader |
|
1076 | self._repo, delta, self._builddeltaheader | |
1072 | ): |
|
1077 | ): | |
1073 | size += len(chunk) |
|
1078 | size += len(chunk) | |
1074 | yield chunk |
|
1079 | yield chunk | |
1075 |
|
1080 | |||
1076 | close = closechunk() |
|
1081 | close = closechunk() | |
1077 | size += len(close) |
|
1082 | size += len(close) | |
1078 | yield closechunk() |
|
1083 | yield closechunk() | |
1079 |
|
1084 | |||
1080 | self._verbosenote(_(b'%8.i (changelog)\n') % size) |
|
1085 | self._verbosenote(_(b'%8.i (changelog)\n') % size) | |
1081 |
|
1086 | |||
1082 | clrevorder = clstate[b'clrevorder'] |
|
1087 | clrevorder = clstate[b'clrevorder'] | |
1083 | manifests = clstate[b'manifests'] |
|
1088 | manifests = clstate[b'manifests'] | |
1084 | changedfiles = clstate[b'changedfiles'] |
|
1089 | changedfiles = clstate[b'changedfiles'] | |
1085 |
|
1090 | |||
1086 | # We need to make sure that the linkrev in the changegroup refers to |
|
1091 | # We need to make sure that the linkrev in the changegroup refers to | |
1087 | # the first changeset that introduced the manifest or file revision. |
|
1092 | # the first changeset that introduced the manifest or file revision. | |
1088 | # The fastpath is usually safer than the slowpath, because the filelogs |
|
1093 | # The fastpath is usually safer than the slowpath, because the filelogs | |
1089 | # are walked in revlog order. |
|
1094 | # are walked in revlog order. | |
1090 | # |
|
1095 | # | |
1091 | # When taking the slowpath when the manifest revlog uses generaldelta, |
|
1096 | # When taking the slowpath when the manifest revlog uses generaldelta, | |
1092 | # the manifest may be walked in the "wrong" order. Without 'clrevorder', |
|
1097 | # the manifest may be walked in the "wrong" order. Without 'clrevorder', | |
1093 | # we would get an incorrect linkrev (see fix in cc0ff93d0c0c). |
|
1098 | # we would get an incorrect linkrev (see fix in cc0ff93d0c0c). | |
1094 | # |
|
1099 | # | |
1095 | # When taking the fastpath, we are only vulnerable to reordering |
|
1100 | # When taking the fastpath, we are only vulnerable to reordering | |
1096 | # of the changelog itself. The changelog never uses generaldelta and is |
|
1101 | # of the changelog itself. The changelog never uses generaldelta and is | |
1097 | # never reordered. To handle this case, we simply take the slowpath, |
|
1102 | # never reordered. To handle this case, we simply take the slowpath, | |
1098 | # which already has the 'clrevorder' logic. This was also fixed in |
|
1103 | # which already has the 'clrevorder' logic. This was also fixed in | |
1099 | # cc0ff93d0c0c. |
|
1104 | # cc0ff93d0c0c. | |
1100 |
|
1105 | |||
1101 | # Treemanifests don't work correctly with fastpathlinkrev |
|
1106 | # Treemanifests don't work correctly with fastpathlinkrev | |
1102 | # either, because we don't discover which directory nodes to |
|
1107 | # either, because we don't discover which directory nodes to | |
1103 | # send along with files. This could probably be fixed. |
|
1108 | # send along with files. This could probably be fixed. | |
1104 | fastpathlinkrev = fastpathlinkrev and not scmutil.istreemanifest(repo) |
|
1109 | fastpathlinkrev = fastpathlinkrev and not scmutil.istreemanifest(repo) | |
1105 |
|
1110 | |||
1106 | fnodes = {} # needed file nodes |
|
1111 | fnodes = {} # needed file nodes | |
1107 |
|
1112 | |||
1108 | size = 0 |
|
1113 | size = 0 | |
1109 | it = self.generatemanifests( |
|
1114 | it = self.generatemanifests( | |
1110 | commonrevs, |
|
1115 | commonrevs, | |
1111 | clrevorder, |
|
1116 | clrevorder, | |
1112 | fastpathlinkrev, |
|
1117 | fastpathlinkrev, | |
1113 | manifests, |
|
1118 | manifests, | |
1114 | fnodes, |
|
1119 | fnodes, | |
1115 | source, |
|
1120 | source, | |
1116 | clstate[b'clrevtomanifestrev'], |
|
1121 | clstate[b'clrevtomanifestrev'], | |
1117 | sidedata_helpers=sidedata_helpers, |
|
1122 | sidedata_helpers=sidedata_helpers, | |
1118 | ) |
|
1123 | ) | |
1119 |
|
1124 | |||
1120 | for tree, deltas in it: |
|
1125 | for tree, deltas in it: | |
1121 | if tree: |
|
1126 | if tree: | |
1122 | assert self.version in (b'03', b'04') |
|
1127 | assert self.version in (b'03', b'04') | |
1123 | chunk = _fileheader(tree) |
|
1128 | chunk = _fileheader(tree) | |
1124 | size += len(chunk) |
|
1129 | size += len(chunk) | |
1125 | yield chunk |
|
1130 | yield chunk | |
1126 |
|
1131 | |||
1127 | for delta in deltas: |
|
1132 | for delta in deltas: | |
1128 | chunks = _revisiondeltatochunks( |
|
1133 | chunks = _revisiondeltatochunks( | |
1129 | self._repo, delta, self._builddeltaheader |
|
1134 | self._repo, delta, self._builddeltaheader | |
1130 | ) |
|
1135 | ) | |
1131 | for chunk in chunks: |
|
1136 | for chunk in chunks: | |
1132 | size += len(chunk) |
|
1137 | size += len(chunk) | |
1133 | yield chunk |
|
1138 | yield chunk | |
1134 |
|
1139 | |||
1135 | close = closechunk() |
|
1140 | close = closechunk() | |
1136 | size += len(close) |
|
1141 | size += len(close) | |
1137 | yield close |
|
1142 | yield close | |
1138 |
|
1143 | |||
1139 | self._verbosenote(_(b'%8.i (manifests)\n') % size) |
|
1144 | self._verbosenote(_(b'%8.i (manifests)\n') % size) | |
1140 | yield self._manifestsend |
|
1145 | yield self._manifestsend | |
1141 |
|
1146 | |||
1142 | mfdicts = None |
|
1147 | mfdicts = None | |
1143 | if self._ellipses and self._isshallow: |
|
1148 | if self._ellipses and self._isshallow: | |
1144 | mfdicts = [ |
|
1149 | mfdicts = [ | |
1145 | (repo.manifestlog[n].read(), lr) |
|
1150 | (repo.manifestlog[n].read(), lr) | |
1146 | for (n, lr) in pycompat.iteritems(manifests) |
|
1151 | for (n, lr) in pycompat.iteritems(manifests) | |
1147 | ] |
|
1152 | ] | |
1148 |
|
1153 | |||
1149 | manifests.clear() |
|
1154 | manifests.clear() | |
1150 | clrevs = {cl.rev(x) for x in clnodes} |
|
1155 | clrevs = {cl.rev(x) for x in clnodes} | |
1151 |
|
1156 | |||
1152 | it = self.generatefiles( |
|
1157 | it = self.generatefiles( | |
1153 | changedfiles, |
|
1158 | changedfiles, | |
1154 | commonrevs, |
|
1159 | commonrevs, | |
1155 | source, |
|
1160 | source, | |
1156 | mfdicts, |
|
1161 | mfdicts, | |
1157 | fastpathlinkrev, |
|
1162 | fastpathlinkrev, | |
1158 | fnodes, |
|
1163 | fnodes, | |
1159 | clrevs, |
|
1164 | clrevs, | |
1160 | sidedata_helpers=sidedata_helpers, |
|
1165 | sidedata_helpers=sidedata_helpers, | |
1161 | ) |
|
1166 | ) | |
1162 |
|
1167 | |||
1163 | for path, deltas in it: |
|
1168 | for path, deltas in it: | |
1164 | h = _fileheader(path) |
|
1169 | h = _fileheader(path) | |
1165 | size = len(h) |
|
1170 | size = len(h) | |
1166 | yield h |
|
1171 | yield h | |
1167 |
|
1172 | |||
1168 | for delta in deltas: |
|
1173 | for delta in deltas: | |
1169 | chunks = _revisiondeltatochunks( |
|
1174 | chunks = _revisiondeltatochunks( | |
1170 | self._repo, delta, self._builddeltaheader |
|
1175 | self._repo, delta, self._builddeltaheader | |
1171 | ) |
|
1176 | ) | |
1172 | for chunk in chunks: |
|
1177 | for chunk in chunks: | |
1173 | size += len(chunk) |
|
1178 | size += len(chunk) | |
1174 | yield chunk |
|
1179 | yield chunk | |
1175 |
|
1180 | |||
1176 | close = closechunk() |
|
1181 | close = closechunk() | |
1177 | size += len(close) |
|
1182 | size += len(close) | |
1178 | yield close |
|
1183 | yield close | |
1179 |
|
1184 | |||
1180 | self._verbosenote(_(b'%8.i %s\n') % (size, path)) |
|
1185 | self._verbosenote(_(b'%8.i %s\n') % (size, path)) | |
1181 |
|
1186 | |||
1182 | yield closechunk() |
|
1187 | yield closechunk() | |
1183 |
|
1188 | |||
1184 | if clnodes: |
|
1189 | if clnodes: | |
1185 | repo.hook(b'outgoing', node=hex(clnodes[0]), source=source) |
|
1190 | repo.hook(b'outgoing', node=hex(clnodes[0]), source=source) | |
1186 |
|
1191 | |||
1187 | def _generatechangelog( |
|
1192 | def _generatechangelog( | |
1188 | self, cl, nodes, generate=True, sidedata_helpers=None |
|
1193 | self, cl, nodes, generate=True, sidedata_helpers=None | |
1189 | ): |
|
1194 | ): | |
1190 | """Generate data for changelog chunks. |
|
1195 | """Generate data for changelog chunks. | |
1191 |
|
1196 | |||
1192 | Returns a 2-tuple of a dict containing state and an iterable of |
|
1197 | Returns a 2-tuple of a dict containing state and an iterable of | |
1193 | byte chunks. The state will not be fully populated until the |
|
1198 | byte chunks. The state will not be fully populated until the | |
1194 | chunk stream has been fully consumed. |
|
1199 | chunk stream has been fully consumed. | |
1195 |
|
1200 | |||
1196 | if generate is False, the state will be fully populated and no chunk |
|
1201 | if generate is False, the state will be fully populated and no chunk | |
1197 | stream will be yielded |
|
1202 | stream will be yielded | |
1198 |
|
1203 | |||
1199 | See `storageutil.emitrevisions` for the doc on `sidedata_helpers`. |
|
1204 | See `storageutil.emitrevisions` for the doc on `sidedata_helpers`. | |
1200 | """ |
|
1205 | """ | |
1201 | clrevorder = {} |
|
1206 | clrevorder = {} | |
1202 | manifests = {} |
|
1207 | manifests = {} | |
1203 | mfl = self._repo.manifestlog |
|
1208 | mfl = self._repo.manifestlog | |
1204 | changedfiles = set() |
|
1209 | changedfiles = set() | |
1205 | clrevtomanifestrev = {} |
|
1210 | clrevtomanifestrev = {} | |
1206 |
|
1211 | |||
1207 | state = { |
|
1212 | state = { | |
1208 | b'clrevorder': clrevorder, |
|
1213 | b'clrevorder': clrevorder, | |
1209 | b'manifests': manifests, |
|
1214 | b'manifests': manifests, | |
1210 | b'changedfiles': changedfiles, |
|
1215 | b'changedfiles': changedfiles, | |
1211 | b'clrevtomanifestrev': clrevtomanifestrev, |
|
1216 | b'clrevtomanifestrev': clrevtomanifestrev, | |
1212 | } |
|
1217 | } | |
1213 |
|
1218 | |||
1214 | if not (generate or self._ellipses): |
|
1219 | if not (generate or self._ellipses): | |
1215 | # sort the nodes in storage order |
|
1220 | # sort the nodes in storage order | |
1216 | nodes = sorted(nodes, key=cl.rev) |
|
1221 | nodes = sorted(nodes, key=cl.rev) | |
1217 | for node in nodes: |
|
1222 | for node in nodes: | |
1218 | c = cl.changelogrevision(node) |
|
1223 | c = cl.changelogrevision(node) | |
1219 | clrevorder[node] = len(clrevorder) |
|
1224 | clrevorder[node] = len(clrevorder) | |
1220 | # record the first changeset introducing this manifest version |
|
1225 | # record the first changeset introducing this manifest version | |
1221 | manifests.setdefault(c.manifest, node) |
|
1226 | manifests.setdefault(c.manifest, node) | |
1222 | # Record a complete list of potentially-changed files in |
|
1227 | # Record a complete list of potentially-changed files in | |
1223 | # this manifest. |
|
1228 | # this manifest. | |
1224 | changedfiles.update(c.files) |
|
1229 | changedfiles.update(c.files) | |
1225 |
|
1230 | |||
1226 | return state, () |
|
1231 | return state, () | |
1227 |
|
1232 | |||
1228 | # Callback for the changelog, used to collect changed files and |
|
1233 | # Callback for the changelog, used to collect changed files and | |
1229 | # manifest nodes. |
|
1234 | # manifest nodes. | |
1230 | # Returns the linkrev node (identity in the changelog case). |
|
1235 | # Returns the linkrev node (identity in the changelog case). | |
1231 | def lookupcl(x): |
|
1236 | def lookupcl(x): | |
1232 | c = cl.changelogrevision(x) |
|
1237 | c = cl.changelogrevision(x) | |
1233 | clrevorder[x] = len(clrevorder) |
|
1238 | clrevorder[x] = len(clrevorder) | |
1234 |
|
1239 | |||
1235 | if self._ellipses: |
|
1240 | if self._ellipses: | |
1236 | # Only update manifests if x is going to be sent. Otherwise we |
|
1241 | # Only update manifests if x is going to be sent. Otherwise we | |
1237 | # end up with bogus linkrevs specified for manifests and |
|
1242 | # end up with bogus linkrevs specified for manifests and | |
1238 | # we skip some manifest nodes that we should otherwise |
|
1243 | # we skip some manifest nodes that we should otherwise | |
1239 | # have sent. |
|
1244 | # have sent. | |
1240 | if ( |
|
1245 | if ( | |
1241 | x in self._fullclnodes |
|
1246 | x in self._fullclnodes | |
1242 | or cl.rev(x) in self._precomputedellipsis |
|
1247 | or cl.rev(x) in self._precomputedellipsis | |
1243 | ): |
|
1248 | ): | |
1244 |
|
1249 | |||
1245 | manifestnode = c.manifest |
|
1250 | manifestnode = c.manifest | |
1246 | # Record the first changeset introducing this manifest |
|
1251 | # Record the first changeset introducing this manifest | |
1247 | # version. |
|
1252 | # version. | |
1248 | manifests.setdefault(manifestnode, x) |
|
1253 | manifests.setdefault(manifestnode, x) | |
1249 | # Set this narrow-specific dict so we have the lowest |
|
1254 | # Set this narrow-specific dict so we have the lowest | |
1250 | # manifest revnum to look up for this cl revnum. (Part of |
|
1255 | # manifest revnum to look up for this cl revnum. (Part of | |
1251 | # mapping changelog ellipsis parents to manifest ellipsis |
|
1256 | # mapping changelog ellipsis parents to manifest ellipsis | |
1252 | # parents) |
|
1257 | # parents) | |
1253 | clrevtomanifestrev.setdefault( |
|
1258 | clrevtomanifestrev.setdefault( | |
1254 | cl.rev(x), mfl.rev(manifestnode) |
|
1259 | cl.rev(x), mfl.rev(manifestnode) | |
1255 | ) |
|
1260 | ) | |
1256 | # We can't trust the changed files list in the changeset if the |
|
1261 | # We can't trust the changed files list in the changeset if the | |
1257 | # client requested a shallow clone. |
|
1262 | # client requested a shallow clone. | |
1258 | if self._isshallow: |
|
1263 | if self._isshallow: | |
1259 | changedfiles.update(mfl[c.manifest].read().keys()) |
|
1264 | changedfiles.update(mfl[c.manifest].read().keys()) | |
1260 | else: |
|
1265 | else: | |
1261 | changedfiles.update(c.files) |
|
1266 | changedfiles.update(c.files) | |
1262 | else: |
|
1267 | else: | |
1263 | # record the first changeset introducing this manifest version |
|
1268 | # record the first changeset introducing this manifest version | |
1264 | manifests.setdefault(c.manifest, x) |
|
1269 | manifests.setdefault(c.manifest, x) | |
1265 | # Record a complete list of potentially-changed files in |
|
1270 | # Record a complete list of potentially-changed files in | |
1266 | # this manifest. |
|
1271 | # this manifest. | |
1267 | changedfiles.update(c.files) |
|
1272 | changedfiles.update(c.files) | |
1268 |
|
1273 | |||
1269 | return x |
|
1274 | return x | |
1270 |
|
1275 | |||
1271 | gen = deltagroup( |
|
1276 | gen = deltagroup( | |
1272 | self._repo, |
|
1277 | self._repo, | |
1273 | cl, |
|
1278 | cl, | |
1274 | nodes, |
|
1279 | nodes, | |
1275 | True, |
|
1280 | True, | |
1276 | lookupcl, |
|
1281 | lookupcl, | |
1277 | self._forcedeltaparentprev, |
|
1282 | self._forcedeltaparentprev, | |
1278 | ellipses=self._ellipses, |
|
1283 | ellipses=self._ellipses, | |
1279 | topic=_(b'changesets'), |
|
1284 | topic=_(b'changesets'), | |
1280 | clrevtolocalrev={}, |
|
1285 | clrevtolocalrev={}, | |
1281 | fullclnodes=self._fullclnodes, |
|
1286 | fullclnodes=self._fullclnodes, | |
1282 | precomputedellipsis=self._precomputedellipsis, |
|
1287 | precomputedellipsis=self._precomputedellipsis, | |
1283 | sidedata_helpers=sidedata_helpers, |
|
1288 | sidedata_helpers=sidedata_helpers, | |
1284 | ) |
|
1289 | ) | |
1285 |
|
1290 | |||
1286 | return state, gen |
|
1291 | return state, gen | |
1287 |
|
1292 | |||
1288 | def generatemanifests( |
|
1293 | def generatemanifests( | |
1289 | self, |
|
1294 | self, | |
1290 | commonrevs, |
|
1295 | commonrevs, | |
1291 | clrevorder, |
|
1296 | clrevorder, | |
1292 | fastpathlinkrev, |
|
1297 | fastpathlinkrev, | |
1293 | manifests, |
|
1298 | manifests, | |
1294 | fnodes, |
|
1299 | fnodes, | |
1295 | source, |
|
1300 | source, | |
1296 | clrevtolocalrev, |
|
1301 | clrevtolocalrev, | |
1297 | sidedata_helpers=None, |
|
1302 | sidedata_helpers=None, | |
1298 | ): |
|
1303 | ): | |
1299 | """Returns an iterator of changegroup chunks containing manifests. |
|
1304 | """Returns an iterator of changegroup chunks containing manifests. | |
1300 |
|
1305 | |||
1301 | `source` is unused here, but is used by extensions like remotefilelog to |
|
1306 | `source` is unused here, but is used by extensions like remotefilelog to | |
1302 | change what is sent based in pulls vs pushes, etc. |
|
1307 | change what is sent based in pulls vs pushes, etc. | |
1303 |
|
1308 | |||
1304 | See `storageutil.emitrevisions` for the doc on `sidedata_helpers`. |
|
1309 | See `storageutil.emitrevisions` for the doc on `sidedata_helpers`. | |
1305 | """ |
|
1310 | """ | |
1306 | repo = self._repo |
|
1311 | repo = self._repo | |
1307 | mfl = repo.manifestlog |
|
1312 | mfl = repo.manifestlog | |
1308 | tmfnodes = {b'': manifests} |
|
1313 | tmfnodes = {b'': manifests} | |
1309 |
|
1314 | |||
1310 | # Callback for the manifest, used to collect linkrevs for filelog |
|
1315 | # Callback for the manifest, used to collect linkrevs for filelog | |
1311 | # revisions. |
|
1316 | # revisions. | |
1312 | # Returns the linkrev node (collected in lookupcl). |
|
1317 | # Returns the linkrev node (collected in lookupcl). | |
1313 | def makelookupmflinknode(tree, nodes): |
|
1318 | def makelookupmflinknode(tree, nodes): | |
1314 | if fastpathlinkrev: |
|
1319 | if fastpathlinkrev: | |
1315 | assert not tree |
|
1320 | assert not tree | |
1316 |
|
1321 | |||
1317 | # pytype: disable=unsupported-operands |
|
1322 | # pytype: disable=unsupported-operands | |
1318 | return manifests.__getitem__ |
|
1323 | return manifests.__getitem__ | |
1319 | # pytype: enable=unsupported-operands |
|
1324 | # pytype: enable=unsupported-operands | |
1320 |
|
1325 | |||
1321 | def lookupmflinknode(x): |
|
1326 | def lookupmflinknode(x): | |
1322 | """Callback for looking up the linknode for manifests. |
|
1327 | """Callback for looking up the linknode for manifests. | |
1323 |
|
1328 | |||
1324 | Returns the linkrev node for the specified manifest. |
|
1329 | Returns the linkrev node for the specified manifest. | |
1325 |
|
1330 | |||
1326 | SIDE EFFECT: |
|
1331 | SIDE EFFECT: | |
1327 |
|
1332 | |||
1328 | 1) fclnodes gets populated with the list of relevant |
|
1333 | 1) fclnodes gets populated with the list of relevant | |
1329 | file nodes if we're not using fastpathlinkrev |
|
1334 | file nodes if we're not using fastpathlinkrev | |
1330 | 2) When treemanifests are in use, collects treemanifest nodes |
|
1335 | 2) When treemanifests are in use, collects treemanifest nodes | |
1331 | to send |
|
1336 | to send | |
1332 |
|
1337 | |||
1333 | Note that this means manifests must be completely sent to |
|
1338 | Note that this means manifests must be completely sent to | |
1334 | the client before you can trust the list of files and |
|
1339 | the client before you can trust the list of files and | |
1335 | treemanifests to send. |
|
1340 | treemanifests to send. | |
1336 | """ |
|
1341 | """ | |
1337 | clnode = nodes[x] |
|
1342 | clnode = nodes[x] | |
1338 | mdata = mfl.get(tree, x).readfast(shallow=True) |
|
1343 | mdata = mfl.get(tree, x).readfast(shallow=True) | |
1339 | for p, n, fl in mdata.iterentries(): |
|
1344 | for p, n, fl in mdata.iterentries(): | |
1340 | if fl == b't': # subdirectory manifest |
|
1345 | if fl == b't': # subdirectory manifest | |
1341 | subtree = tree + p + b'/' |
|
1346 | subtree = tree + p + b'/' | |
1342 | tmfclnodes = tmfnodes.setdefault(subtree, {}) |
|
1347 | tmfclnodes = tmfnodes.setdefault(subtree, {}) | |
1343 | tmfclnode = tmfclnodes.setdefault(n, clnode) |
|
1348 | tmfclnode = tmfclnodes.setdefault(n, clnode) | |
1344 | if clrevorder[clnode] < clrevorder[tmfclnode]: |
|
1349 | if clrevorder[clnode] < clrevorder[tmfclnode]: | |
1345 | tmfclnodes[n] = clnode |
|
1350 | tmfclnodes[n] = clnode | |
1346 | else: |
|
1351 | else: | |
1347 | f = tree + p |
|
1352 | f = tree + p | |
1348 | fclnodes = fnodes.setdefault(f, {}) |
|
1353 | fclnodes = fnodes.setdefault(f, {}) | |
1349 | fclnode = fclnodes.setdefault(n, clnode) |
|
1354 | fclnode = fclnodes.setdefault(n, clnode) | |
1350 | if clrevorder[clnode] < clrevorder[fclnode]: |
|
1355 | if clrevorder[clnode] < clrevorder[fclnode]: | |
1351 | fclnodes[n] = clnode |
|
1356 | fclnodes[n] = clnode | |
1352 | return clnode |
|
1357 | return clnode | |
1353 |
|
1358 | |||
1354 | return lookupmflinknode |
|
1359 | return lookupmflinknode | |
1355 |
|
1360 | |||
1356 | while tmfnodes: |
|
1361 | while tmfnodes: | |
1357 | tree, nodes = tmfnodes.popitem() |
|
1362 | tree, nodes = tmfnodes.popitem() | |
1358 |
|
1363 | |||
1359 | should_visit = self._matcher.visitdir(tree[:-1]) |
|
1364 | should_visit = self._matcher.visitdir(tree[:-1]) | |
1360 | if tree and not should_visit: |
|
1365 | if tree and not should_visit: | |
1361 | continue |
|
1366 | continue | |
1362 |
|
1367 | |||
1363 | store = mfl.getstorage(tree) |
|
1368 | store = mfl.getstorage(tree) | |
1364 |
|
1369 | |||
1365 | if not should_visit: |
|
1370 | if not should_visit: | |
1366 | # No nodes to send because this directory is out of |
|
1371 | # No nodes to send because this directory is out of | |
1367 | # the client's view of the repository (probably |
|
1372 | # the client's view of the repository (probably | |
1368 | # because of narrow clones). Do this even for the root |
|
1373 | # because of narrow clones). Do this even for the root | |
1369 | # directory (tree=='') |
|
1374 | # directory (tree=='') | |
1370 | prunednodes = [] |
|
1375 | prunednodes = [] | |
1371 | else: |
|
1376 | else: | |
1372 | # Avoid sending any manifest nodes we can prove the |
|
1377 | # Avoid sending any manifest nodes we can prove the | |
1373 | # client already has by checking linkrevs. See the |
|
1378 | # client already has by checking linkrevs. See the | |
1374 | # related comment in generatefiles(). |
|
1379 | # related comment in generatefiles(). | |
1375 | prunednodes = self._prunemanifests(store, nodes, commonrevs) |
|
1380 | prunednodes = self._prunemanifests(store, nodes, commonrevs) | |
1376 |
|
1381 | |||
1377 | if tree and not prunednodes: |
|
1382 | if tree and not prunednodes: | |
1378 | continue |
|
1383 | continue | |
1379 |
|
1384 | |||
1380 | lookupfn = makelookupmflinknode(tree, nodes) |
|
1385 | lookupfn = makelookupmflinknode(tree, nodes) | |
1381 |
|
1386 | |||
1382 | deltas = deltagroup( |
|
1387 | deltas = deltagroup( | |
1383 | self._repo, |
|
1388 | self._repo, | |
1384 | store, |
|
1389 | store, | |
1385 | prunednodes, |
|
1390 | prunednodes, | |
1386 | False, |
|
1391 | False, | |
1387 | lookupfn, |
|
1392 | lookupfn, | |
1388 | self._forcedeltaparentprev, |
|
1393 | self._forcedeltaparentprev, | |
1389 | ellipses=self._ellipses, |
|
1394 | ellipses=self._ellipses, | |
1390 | topic=_(b'manifests'), |
|
1395 | topic=_(b'manifests'), | |
1391 | clrevtolocalrev=clrevtolocalrev, |
|
1396 | clrevtolocalrev=clrevtolocalrev, | |
1392 | fullclnodes=self._fullclnodes, |
|
1397 | fullclnodes=self._fullclnodes, | |
1393 | precomputedellipsis=self._precomputedellipsis, |
|
1398 | precomputedellipsis=self._precomputedellipsis, | |
1394 | sidedata_helpers=sidedata_helpers, |
|
1399 | sidedata_helpers=sidedata_helpers, | |
1395 | ) |
|
1400 | ) | |
1396 |
|
1401 | |||
1397 | if not self._oldmatcher.visitdir(store.tree[:-1]): |
|
1402 | if not self._oldmatcher.visitdir(store.tree[:-1]): | |
1398 | yield tree, deltas |
|
1403 | yield tree, deltas | |
1399 | else: |
|
1404 | else: | |
1400 | # 'deltas' is a generator and we need to consume it even if |
|
1405 | # 'deltas' is a generator and we need to consume it even if | |
1401 | # we are not going to send it because a side-effect is that |
|
1406 | # we are not going to send it because a side-effect is that | |
1402 | # it updates tmdnodes (via lookupfn) |
|
1407 | # it updates tmdnodes (via lookupfn) | |
1403 | for d in deltas: |
|
1408 | for d in deltas: | |
1404 | pass |
|
1409 | pass | |
1405 | if not tree: |
|
1410 | if not tree: | |
1406 | yield tree, [] |
|
1411 | yield tree, [] | |
1407 |
|
1412 | |||
1408 | def _prunemanifests(self, store, nodes, commonrevs): |
|
1413 | def _prunemanifests(self, store, nodes, commonrevs): | |
1409 | if not self._ellipses: |
|
1414 | if not self._ellipses: | |
1410 | # In non-ellipses case and large repositories, it is better to |
|
1415 | # In non-ellipses case and large repositories, it is better to | |
1411 | # prevent calling of store.rev and store.linkrev on a lot of |
|
1416 | # prevent calling of store.rev and store.linkrev on a lot of | |
1412 | # nodes as compared to sending some extra data |
|
1417 | # nodes as compared to sending some extra data | |
1413 | return nodes.copy() |
|
1418 | return nodes.copy() | |
1414 | # This is split out as a separate method to allow filtering |
|
1419 | # This is split out as a separate method to allow filtering | |
1415 | # commonrevs in extension code. |
|
1420 | # commonrevs in extension code. | |
1416 | # |
|
1421 | # | |
1417 | # TODO(augie): this shouldn't be required, instead we should |
|
1422 | # TODO(augie): this shouldn't be required, instead we should | |
1418 | # make filtering of revisions to send delegated to the store |
|
1423 | # make filtering of revisions to send delegated to the store | |
1419 | # layer. |
|
1424 | # layer. | |
1420 | frev, flr = store.rev, store.linkrev |
|
1425 | frev, flr = store.rev, store.linkrev | |
1421 | return [n for n in nodes if flr(frev(n)) not in commonrevs] |
|
1426 | return [n for n in nodes if flr(frev(n)) not in commonrevs] | |
1422 |
|
1427 | |||
1423 | # The 'source' parameter is useful for extensions |
|
1428 | # The 'source' parameter is useful for extensions | |
1424 | def generatefiles( |
|
1429 | def generatefiles( | |
1425 | self, |
|
1430 | self, | |
1426 | changedfiles, |
|
1431 | changedfiles, | |
1427 | commonrevs, |
|
1432 | commonrevs, | |
1428 | source, |
|
1433 | source, | |
1429 | mfdicts, |
|
1434 | mfdicts, | |
1430 | fastpathlinkrev, |
|
1435 | fastpathlinkrev, | |
1431 | fnodes, |
|
1436 | fnodes, | |
1432 | clrevs, |
|
1437 | clrevs, | |
1433 | sidedata_helpers=None, |
|
1438 | sidedata_helpers=None, | |
1434 | ): |
|
1439 | ): | |
1435 | changedfiles = [ |
|
1440 | changedfiles = [ | |
1436 | f |
|
1441 | f | |
1437 | for f in changedfiles |
|
1442 | for f in changedfiles | |
1438 | if self._matcher(f) and not self._oldmatcher(f) |
|
1443 | if self._matcher(f) and not self._oldmatcher(f) | |
1439 | ] |
|
1444 | ] | |
1440 |
|
1445 | |||
1441 | if not fastpathlinkrev: |
|
1446 | if not fastpathlinkrev: | |
1442 |
|
1447 | |||
1443 | def normallinknodes(unused, fname): |
|
1448 | def normallinknodes(unused, fname): | |
1444 | return fnodes.get(fname, {}) |
|
1449 | return fnodes.get(fname, {}) | |
1445 |
|
1450 | |||
1446 | else: |
|
1451 | else: | |
1447 | cln = self._repo.changelog.node |
|
1452 | cln = self._repo.changelog.node | |
1448 |
|
1453 | |||
1449 | def normallinknodes(store, fname): |
|
1454 | def normallinknodes(store, fname): | |
1450 | flinkrev = store.linkrev |
|
1455 | flinkrev = store.linkrev | |
1451 | fnode = store.node |
|
1456 | fnode = store.node | |
1452 | revs = ((r, flinkrev(r)) for r in store) |
|
1457 | revs = ((r, flinkrev(r)) for r in store) | |
1453 | return {fnode(r): cln(lr) for r, lr in revs if lr in clrevs} |
|
1458 | return {fnode(r): cln(lr) for r, lr in revs if lr in clrevs} | |
1454 |
|
1459 | |||
1455 | clrevtolocalrev = {} |
|
1460 | clrevtolocalrev = {} | |
1456 |
|
1461 | |||
1457 | if self._isshallow: |
|
1462 | if self._isshallow: | |
1458 | # In a shallow clone, the linknodes callback needs to also include |
|
1463 | # In a shallow clone, the linknodes callback needs to also include | |
1459 | # those file nodes that are in the manifests we sent but weren't |
|
1464 | # those file nodes that are in the manifests we sent but weren't | |
1460 | # introduced by those manifests. |
|
1465 | # introduced by those manifests. | |
1461 | commonctxs = [self._repo[c] for c in commonrevs] |
|
1466 | commonctxs = [self._repo[c] for c in commonrevs] | |
1462 | clrev = self._repo.changelog.rev |
|
1467 | clrev = self._repo.changelog.rev | |
1463 |
|
1468 | |||
1464 | def linknodes(flog, fname): |
|
1469 | def linknodes(flog, fname): | |
1465 | for c in commonctxs: |
|
1470 | for c in commonctxs: | |
1466 | try: |
|
1471 | try: | |
1467 | fnode = c.filenode(fname) |
|
1472 | fnode = c.filenode(fname) | |
1468 | clrevtolocalrev[c.rev()] = flog.rev(fnode) |
|
1473 | clrevtolocalrev[c.rev()] = flog.rev(fnode) | |
1469 | except error.ManifestLookupError: |
|
1474 | except error.ManifestLookupError: | |
1470 | pass |
|
1475 | pass | |
1471 | links = normallinknodes(flog, fname) |
|
1476 | links = normallinknodes(flog, fname) | |
1472 | if len(links) != len(mfdicts): |
|
1477 | if len(links) != len(mfdicts): | |
1473 | for mf, lr in mfdicts: |
|
1478 | for mf, lr in mfdicts: | |
1474 | fnode = mf.get(fname, None) |
|
1479 | fnode = mf.get(fname, None) | |
1475 | if fnode in links: |
|
1480 | if fnode in links: | |
1476 | links[fnode] = min(links[fnode], lr, key=clrev) |
|
1481 | links[fnode] = min(links[fnode], lr, key=clrev) | |
1477 | elif fnode: |
|
1482 | elif fnode: | |
1478 | links[fnode] = lr |
|
1483 | links[fnode] = lr | |
1479 | return links |
|
1484 | return links | |
1480 |
|
1485 | |||
1481 | else: |
|
1486 | else: | |
1482 | linknodes = normallinknodes |
|
1487 | linknodes = normallinknodes | |
1483 |
|
1488 | |||
1484 | repo = self._repo |
|
1489 | repo = self._repo | |
1485 | progress = repo.ui.makeprogress( |
|
1490 | progress = repo.ui.makeprogress( | |
1486 | _(b'files'), unit=_(b'files'), total=len(changedfiles) |
|
1491 | _(b'files'), unit=_(b'files'), total=len(changedfiles) | |
1487 | ) |
|
1492 | ) | |
1488 | for i, fname in enumerate(sorted(changedfiles)): |
|
1493 | for i, fname in enumerate(sorted(changedfiles)): | |
1489 | filerevlog = repo.file(fname) |
|
1494 | filerevlog = repo.file(fname) | |
1490 | if not filerevlog: |
|
1495 | if not filerevlog: | |
1491 | raise error.Abort( |
|
1496 | raise error.Abort( | |
1492 | _(b"empty or missing file data for %s") % fname |
|
1497 | _(b"empty or missing file data for %s") % fname | |
1493 | ) |
|
1498 | ) | |
1494 |
|
1499 | |||
1495 | clrevtolocalrev.clear() |
|
1500 | clrevtolocalrev.clear() | |
1496 |
|
1501 | |||
1497 | linkrevnodes = linknodes(filerevlog, fname) |
|
1502 | linkrevnodes = linknodes(filerevlog, fname) | |
1498 | # Lookup for filenodes, we collected the linkrev nodes above in the |
|
1503 | # Lookup for filenodes, we collected the linkrev nodes above in the | |
1499 | # fastpath case and with lookupmf in the slowpath case. |
|
1504 | # fastpath case and with lookupmf in the slowpath case. | |
1500 | def lookupfilelog(x): |
|
1505 | def lookupfilelog(x): | |
1501 | return linkrevnodes[x] |
|
1506 | return linkrevnodes[x] | |
1502 |
|
1507 | |||
1503 | frev, flr = filerevlog.rev, filerevlog.linkrev |
|
1508 | frev, flr = filerevlog.rev, filerevlog.linkrev | |
1504 | # Skip sending any filenode we know the client already |
|
1509 | # Skip sending any filenode we know the client already | |
1505 | # has. This avoids over-sending files relatively |
|
1510 | # has. This avoids over-sending files relatively | |
1506 | # inexpensively, so it's not a problem if we under-filter |
|
1511 | # inexpensively, so it's not a problem if we under-filter | |
1507 | # here. |
|
1512 | # here. | |
1508 | filenodes = [ |
|
1513 | filenodes = [ | |
1509 | n for n in linkrevnodes if flr(frev(n)) not in commonrevs |
|
1514 | n for n in linkrevnodes if flr(frev(n)) not in commonrevs | |
1510 | ] |
|
1515 | ] | |
1511 |
|
1516 | |||
1512 | if not filenodes: |
|
1517 | if not filenodes: | |
1513 | continue |
|
1518 | continue | |
1514 |
|
1519 | |||
1515 | progress.update(i + 1, item=fname) |
|
1520 | progress.update(i + 1, item=fname) | |
1516 |
|
1521 | |||
1517 | deltas = deltagroup( |
|
1522 | deltas = deltagroup( | |
1518 | self._repo, |
|
1523 | self._repo, | |
1519 | filerevlog, |
|
1524 | filerevlog, | |
1520 | filenodes, |
|
1525 | filenodes, | |
1521 | False, |
|
1526 | False, | |
1522 | lookupfilelog, |
|
1527 | lookupfilelog, | |
1523 | self._forcedeltaparentprev, |
|
1528 | self._forcedeltaparentprev, | |
1524 | ellipses=self._ellipses, |
|
1529 | ellipses=self._ellipses, | |
1525 | clrevtolocalrev=clrevtolocalrev, |
|
1530 | clrevtolocalrev=clrevtolocalrev, | |
1526 | fullclnodes=self._fullclnodes, |
|
1531 | fullclnodes=self._fullclnodes, | |
1527 | precomputedellipsis=self._precomputedellipsis, |
|
1532 | precomputedellipsis=self._precomputedellipsis, | |
1528 | sidedata_helpers=sidedata_helpers, |
|
1533 | sidedata_helpers=sidedata_helpers, | |
1529 | ) |
|
1534 | ) | |
1530 |
|
1535 | |||
1531 | yield fname, deltas |
|
1536 | yield fname, deltas | |
1532 |
|
1537 | |||
1533 | progress.complete() |
|
1538 | progress.complete() | |
1534 |
|
1539 | |||
1535 |
|
1540 | |||
1536 | def _makecg1packer( |
|
1541 | def _makecg1packer( | |
1537 | repo, |
|
1542 | repo, | |
1538 | oldmatcher, |
|
1543 | oldmatcher, | |
1539 | matcher, |
|
1544 | matcher, | |
1540 | bundlecaps, |
|
1545 | bundlecaps, | |
1541 | ellipses=False, |
|
1546 | ellipses=False, | |
1542 | shallow=False, |
|
1547 | shallow=False, | |
1543 | ellipsisroots=None, |
|
1548 | ellipsisroots=None, | |
1544 | fullnodes=None, |
|
1549 | fullnodes=None, | |
1545 | remote_sidedata=None, |
|
1550 | remote_sidedata=None, | |
1546 | ): |
|
1551 | ): | |
1547 | builddeltaheader = lambda d: _CHANGEGROUPV1_DELTA_HEADER.pack( |
|
1552 | builddeltaheader = lambda d: _CHANGEGROUPV1_DELTA_HEADER.pack( | |
1548 | d.node, d.p1node, d.p2node, d.linknode |
|
1553 | d.node, d.p1node, d.p2node, d.linknode | |
1549 | ) |
|
1554 | ) | |
1550 |
|
1555 | |||
1551 | return cgpacker( |
|
1556 | return cgpacker( | |
1552 | repo, |
|
1557 | repo, | |
1553 | oldmatcher, |
|
1558 | oldmatcher, | |
1554 | matcher, |
|
1559 | matcher, | |
1555 | b'01', |
|
1560 | b'01', | |
1556 | builddeltaheader=builddeltaheader, |
|
1561 | builddeltaheader=builddeltaheader, | |
1557 | manifestsend=b'', |
|
1562 | manifestsend=b'', | |
1558 | forcedeltaparentprev=True, |
|
1563 | forcedeltaparentprev=True, | |
1559 | bundlecaps=bundlecaps, |
|
1564 | bundlecaps=bundlecaps, | |
1560 | ellipses=ellipses, |
|
1565 | ellipses=ellipses, | |
1561 | shallow=shallow, |
|
1566 | shallow=shallow, | |
1562 | ellipsisroots=ellipsisroots, |
|
1567 | ellipsisroots=ellipsisroots, | |
1563 | fullnodes=fullnodes, |
|
1568 | fullnodes=fullnodes, | |
1564 | ) |
|
1569 | ) | |
1565 |
|
1570 | |||
1566 |
|
1571 | |||
1567 | def _makecg2packer( |
|
1572 | def _makecg2packer( | |
1568 | repo, |
|
1573 | repo, | |
1569 | oldmatcher, |
|
1574 | oldmatcher, | |
1570 | matcher, |
|
1575 | matcher, | |
1571 | bundlecaps, |
|
1576 | bundlecaps, | |
1572 | ellipses=False, |
|
1577 | ellipses=False, | |
1573 | shallow=False, |
|
1578 | shallow=False, | |
1574 | ellipsisroots=None, |
|
1579 | ellipsisroots=None, | |
1575 | fullnodes=None, |
|
1580 | fullnodes=None, | |
1576 | remote_sidedata=None, |
|
1581 | remote_sidedata=None, | |
1577 | ): |
|
1582 | ): | |
1578 | builddeltaheader = lambda d: _CHANGEGROUPV2_DELTA_HEADER.pack( |
|
1583 | builddeltaheader = lambda d: _CHANGEGROUPV2_DELTA_HEADER.pack( | |
1579 | d.node, d.p1node, d.p2node, d.basenode, d.linknode |
|
1584 | d.node, d.p1node, d.p2node, d.basenode, d.linknode | |
1580 | ) |
|
1585 | ) | |
1581 |
|
1586 | |||
1582 | return cgpacker( |
|
1587 | return cgpacker( | |
1583 | repo, |
|
1588 | repo, | |
1584 | oldmatcher, |
|
1589 | oldmatcher, | |
1585 | matcher, |
|
1590 | matcher, | |
1586 | b'02', |
|
1591 | b'02', | |
1587 | builddeltaheader=builddeltaheader, |
|
1592 | builddeltaheader=builddeltaheader, | |
1588 | manifestsend=b'', |
|
1593 | manifestsend=b'', | |
1589 | bundlecaps=bundlecaps, |
|
1594 | bundlecaps=bundlecaps, | |
1590 | ellipses=ellipses, |
|
1595 | ellipses=ellipses, | |
1591 | shallow=shallow, |
|
1596 | shallow=shallow, | |
1592 | ellipsisroots=ellipsisroots, |
|
1597 | ellipsisroots=ellipsisroots, | |
1593 | fullnodes=fullnodes, |
|
1598 | fullnodes=fullnodes, | |
1594 | ) |
|
1599 | ) | |
1595 |
|
1600 | |||
1596 |
|
1601 | |||
1597 | def _makecg3packer( |
|
1602 | def _makecg3packer( | |
1598 | repo, |
|
1603 | repo, | |
1599 | oldmatcher, |
|
1604 | oldmatcher, | |
1600 | matcher, |
|
1605 | matcher, | |
1601 | bundlecaps, |
|
1606 | bundlecaps, | |
1602 | ellipses=False, |
|
1607 | ellipses=False, | |
1603 | shallow=False, |
|
1608 | shallow=False, | |
1604 | ellipsisroots=None, |
|
1609 | ellipsisroots=None, | |
1605 | fullnodes=None, |
|
1610 | fullnodes=None, | |
1606 | remote_sidedata=None, |
|
1611 | remote_sidedata=None, | |
1607 | ): |
|
1612 | ): | |
1608 | builddeltaheader = lambda d: _CHANGEGROUPV3_DELTA_HEADER.pack( |
|
1613 | builddeltaheader = lambda d: _CHANGEGROUPV3_DELTA_HEADER.pack( | |
1609 | d.node, d.p1node, d.p2node, d.basenode, d.linknode, d.flags |
|
1614 | d.node, d.p1node, d.p2node, d.basenode, d.linknode, d.flags | |
1610 | ) |
|
1615 | ) | |
1611 |
|
1616 | |||
1612 | return cgpacker( |
|
1617 | return cgpacker( | |
1613 | repo, |
|
1618 | repo, | |
1614 | oldmatcher, |
|
1619 | oldmatcher, | |
1615 | matcher, |
|
1620 | matcher, | |
1616 | b'03', |
|
1621 | b'03', | |
1617 | builddeltaheader=builddeltaheader, |
|
1622 | builddeltaheader=builddeltaheader, | |
1618 | manifestsend=closechunk(), |
|
1623 | manifestsend=closechunk(), | |
1619 | bundlecaps=bundlecaps, |
|
1624 | bundlecaps=bundlecaps, | |
1620 | ellipses=ellipses, |
|
1625 | ellipses=ellipses, | |
1621 | shallow=shallow, |
|
1626 | shallow=shallow, | |
1622 | ellipsisroots=ellipsisroots, |
|
1627 | ellipsisroots=ellipsisroots, | |
1623 | fullnodes=fullnodes, |
|
1628 | fullnodes=fullnodes, | |
1624 | ) |
|
1629 | ) | |
1625 |
|
1630 | |||
1626 |
|
1631 | |||
1627 | def _makecg4packer( |
|
1632 | def _makecg4packer( | |
1628 | repo, |
|
1633 | repo, | |
1629 | oldmatcher, |
|
1634 | oldmatcher, | |
1630 | matcher, |
|
1635 | matcher, | |
1631 | bundlecaps, |
|
1636 | bundlecaps, | |
1632 | ellipses=False, |
|
1637 | ellipses=False, | |
1633 | shallow=False, |
|
1638 | shallow=False, | |
1634 | ellipsisroots=None, |
|
1639 | ellipsisroots=None, | |
1635 | fullnodes=None, |
|
1640 | fullnodes=None, | |
1636 | remote_sidedata=None, |
|
1641 | remote_sidedata=None, | |
1637 | ): |
|
1642 | ): | |
1638 | # Same header func as cg3. Sidedata is in a separate chunk from the delta to |
|
1643 | # Same header func as cg3. Sidedata is in a separate chunk from the delta to | |
1639 | # differenciate "raw delta" and sidedata. |
|
1644 | # differenciate "raw delta" and sidedata. | |
1640 | builddeltaheader = lambda d: _CHANGEGROUPV3_DELTA_HEADER.pack( |
|
1645 | builddeltaheader = lambda d: _CHANGEGROUPV3_DELTA_HEADER.pack( | |
1641 | d.node, d.p1node, d.p2node, d.basenode, d.linknode, d.flags |
|
1646 | d.node, d.p1node, d.p2node, d.basenode, d.linknode, d.flags | |
1642 | ) |
|
1647 | ) | |
1643 |
|
1648 | |||
1644 | return cgpacker( |
|
1649 | return cgpacker( | |
1645 | repo, |
|
1650 | repo, | |
1646 | oldmatcher, |
|
1651 | oldmatcher, | |
1647 | matcher, |
|
1652 | matcher, | |
1648 | b'04', |
|
1653 | b'04', | |
1649 | builddeltaheader=builddeltaheader, |
|
1654 | builddeltaheader=builddeltaheader, | |
1650 | manifestsend=closechunk(), |
|
1655 | manifestsend=closechunk(), | |
1651 | bundlecaps=bundlecaps, |
|
1656 | bundlecaps=bundlecaps, | |
1652 | ellipses=ellipses, |
|
1657 | ellipses=ellipses, | |
1653 | shallow=shallow, |
|
1658 | shallow=shallow, | |
1654 | ellipsisroots=ellipsisroots, |
|
1659 | ellipsisroots=ellipsisroots, | |
1655 | fullnodes=fullnodes, |
|
1660 | fullnodes=fullnodes, | |
1656 | remote_sidedata=remote_sidedata, |
|
1661 | remote_sidedata=remote_sidedata, | |
1657 | ) |
|
1662 | ) | |
1658 |
|
1663 | |||
1659 |
|
1664 | |||
1660 | _packermap = { |
|
1665 | _packermap = { | |
1661 | b'01': (_makecg1packer, cg1unpacker), |
|
1666 | b'01': (_makecg1packer, cg1unpacker), | |
1662 | # cg2 adds support for exchanging generaldelta |
|
1667 | # cg2 adds support for exchanging generaldelta | |
1663 | b'02': (_makecg2packer, cg2unpacker), |
|
1668 | b'02': (_makecg2packer, cg2unpacker), | |
1664 | # cg3 adds support for exchanging revlog flags and treemanifests |
|
1669 | # cg3 adds support for exchanging revlog flags and treemanifests | |
1665 | b'03': (_makecg3packer, cg3unpacker), |
|
1670 | b'03': (_makecg3packer, cg3unpacker), | |
1666 | # ch4 adds support for exchanging sidedata |
|
1671 | # ch4 adds support for exchanging sidedata | |
1667 | b'04': (_makecg4packer, cg4unpacker), |
|
1672 | b'04': (_makecg4packer, cg4unpacker), | |
1668 | } |
|
1673 | } | |
1669 |
|
1674 | |||
1670 |
|
1675 | |||
1671 | def allsupportedversions(repo): |
|
1676 | def allsupportedversions(repo): | |
1672 | versions = set(_packermap.keys()) |
|
1677 | versions = set(_packermap.keys()) | |
1673 | needv03 = False |
|
1678 | needv03 = False | |
1674 | if ( |
|
1679 | if ( | |
1675 | repo.ui.configbool(b'experimental', b'changegroup3') |
|
1680 | repo.ui.configbool(b'experimental', b'changegroup3') | |
1676 | or repo.ui.configbool(b'experimental', b'treemanifest') |
|
1681 | or repo.ui.configbool(b'experimental', b'treemanifest') | |
1677 | or scmutil.istreemanifest(repo) |
|
1682 | or scmutil.istreemanifest(repo) | |
1678 | ): |
|
1683 | ): | |
1679 | # we keep version 03 because we need to to exchange treemanifest data |
|
1684 | # we keep version 03 because we need to to exchange treemanifest data | |
1680 | # |
|
1685 | # | |
1681 | # we also keep vresion 01 and 02, because it is possible for repo to |
|
1686 | # we also keep vresion 01 and 02, because it is possible for repo to | |
1682 | # contains both normal and tree manifest at the same time. so using |
|
1687 | # contains both normal and tree manifest at the same time. so using | |
1683 | # older version to pull data is viable |
|
1688 | # older version to pull data is viable | |
1684 | # |
|
1689 | # | |
1685 | # (or even to push subset of history) |
|
1690 | # (or even to push subset of history) | |
1686 | needv03 = True |
|
1691 | needv03 = True | |
1687 | has_revlogv2 = requirements.REVLOGV2_REQUIREMENT in repo.requirements |
|
1692 | has_revlogv2 = requirements.REVLOGV2_REQUIREMENT in repo.requirements | |
1688 | if not has_revlogv2: |
|
1693 | if not has_revlogv2: | |
1689 | versions.discard(b'04') |
|
1694 | versions.discard(b'04') | |
1690 | if not needv03: |
|
1695 | if not needv03: | |
1691 | versions.discard(b'03') |
|
1696 | versions.discard(b'03') | |
1692 | return versions |
|
1697 | return versions | |
1693 |
|
1698 | |||
1694 |
|
1699 | |||
1695 | # Changegroup versions that can be applied to the repo |
|
1700 | # Changegroup versions that can be applied to the repo | |
1696 | def supportedincomingversions(repo): |
|
1701 | def supportedincomingversions(repo): | |
1697 | return allsupportedversions(repo) |
|
1702 | return allsupportedversions(repo) | |
1698 |
|
1703 | |||
1699 |
|
1704 | |||
1700 | # Changegroup versions that can be created from the repo |
|
1705 | # Changegroup versions that can be created from the repo | |
1701 | def supportedoutgoingversions(repo): |
|
1706 | def supportedoutgoingversions(repo): | |
1702 | versions = allsupportedversions(repo) |
|
1707 | versions = allsupportedversions(repo) | |
1703 | if scmutil.istreemanifest(repo): |
|
1708 | if scmutil.istreemanifest(repo): | |
1704 | # Versions 01 and 02 support only flat manifests and it's just too |
|
1709 | # Versions 01 and 02 support only flat manifests and it's just too | |
1705 | # expensive to convert between the flat manifest and tree manifest on |
|
1710 | # expensive to convert between the flat manifest and tree manifest on | |
1706 | # the fly. Since tree manifests are hashed differently, all of history |
|
1711 | # the fly. Since tree manifests are hashed differently, all of history | |
1707 | # would have to be converted. Instead, we simply don't even pretend to |
|
1712 | # would have to be converted. Instead, we simply don't even pretend to | |
1708 | # support versions 01 and 02. |
|
1713 | # support versions 01 and 02. | |
1709 | versions.discard(b'01') |
|
1714 | versions.discard(b'01') | |
1710 | versions.discard(b'02') |
|
1715 | versions.discard(b'02') | |
1711 | if requirements.NARROW_REQUIREMENT in repo.requirements: |
|
1716 | if requirements.NARROW_REQUIREMENT in repo.requirements: | |
1712 | # Versions 01 and 02 don't support revlog flags, and we need to |
|
1717 | # Versions 01 and 02 don't support revlog flags, and we need to | |
1713 | # support that for stripping and unbundling to work. |
|
1718 | # support that for stripping and unbundling to work. | |
1714 | versions.discard(b'01') |
|
1719 | versions.discard(b'01') | |
1715 | versions.discard(b'02') |
|
1720 | versions.discard(b'02') | |
1716 | if LFS_REQUIREMENT in repo.requirements: |
|
1721 | if LFS_REQUIREMENT in repo.requirements: | |
1717 | # Versions 01 and 02 don't support revlog flags, and we need to |
|
1722 | # Versions 01 and 02 don't support revlog flags, and we need to | |
1718 | # mark LFS entries with REVIDX_EXTSTORED. |
|
1723 | # mark LFS entries with REVIDX_EXTSTORED. | |
1719 | versions.discard(b'01') |
|
1724 | versions.discard(b'01') | |
1720 | versions.discard(b'02') |
|
1725 | versions.discard(b'02') | |
1721 |
|
1726 | |||
1722 | return versions |
|
1727 | return versions | |
1723 |
|
1728 | |||
1724 |
|
1729 | |||
1725 | def localversion(repo): |
|
1730 | def localversion(repo): | |
1726 | # Finds the best version to use for bundles that are meant to be used |
|
1731 | # Finds the best version to use for bundles that are meant to be used | |
1727 | # locally, such as those from strip and shelve, and temporary bundles. |
|
1732 | # locally, such as those from strip and shelve, and temporary bundles. | |
1728 | return max(supportedoutgoingversions(repo)) |
|
1733 | return max(supportedoutgoingversions(repo)) | |
1729 |
|
1734 | |||
1730 |
|
1735 | |||
1731 | def safeversion(repo): |
|
1736 | def safeversion(repo): | |
1732 | # Finds the smallest version that it's safe to assume clients of the repo |
|
1737 | # Finds the smallest version that it's safe to assume clients of the repo | |
1733 | # will support. For example, all hg versions that support generaldelta also |
|
1738 | # will support. For example, all hg versions that support generaldelta also | |
1734 | # support changegroup 02. |
|
1739 | # support changegroup 02. | |
1735 | versions = supportedoutgoingversions(repo) |
|
1740 | versions = supportedoutgoingversions(repo) | |
1736 | if requirements.GENERALDELTA_REQUIREMENT in repo.requirements: |
|
1741 | if requirements.GENERALDELTA_REQUIREMENT in repo.requirements: | |
1737 | versions.discard(b'01') |
|
1742 | versions.discard(b'01') | |
1738 | assert versions |
|
1743 | assert versions | |
1739 | return min(versions) |
|
1744 | return min(versions) | |
1740 |
|
1745 | |||
1741 |
|
1746 | |||
1742 | def getbundler( |
|
1747 | def getbundler( | |
1743 | version, |
|
1748 | version, | |
1744 | repo, |
|
1749 | repo, | |
1745 | bundlecaps=None, |
|
1750 | bundlecaps=None, | |
1746 | oldmatcher=None, |
|
1751 | oldmatcher=None, | |
1747 | matcher=None, |
|
1752 | matcher=None, | |
1748 | ellipses=False, |
|
1753 | ellipses=False, | |
1749 | shallow=False, |
|
1754 | shallow=False, | |
1750 | ellipsisroots=None, |
|
1755 | ellipsisroots=None, | |
1751 | fullnodes=None, |
|
1756 | fullnodes=None, | |
1752 | remote_sidedata=None, |
|
1757 | remote_sidedata=None, | |
1753 | ): |
|
1758 | ): | |
1754 | assert version in supportedoutgoingversions(repo) |
|
1759 | assert version in supportedoutgoingversions(repo) | |
1755 |
|
1760 | |||
1756 | if matcher is None: |
|
1761 | if matcher is None: | |
1757 | matcher = matchmod.always() |
|
1762 | matcher = matchmod.always() | |
1758 | if oldmatcher is None: |
|
1763 | if oldmatcher is None: | |
1759 | oldmatcher = matchmod.never() |
|
1764 | oldmatcher = matchmod.never() | |
1760 |
|
1765 | |||
1761 | if version == b'01' and not matcher.always(): |
|
1766 | if version == b'01' and not matcher.always(): | |
1762 | raise error.ProgrammingError( |
|
1767 | raise error.ProgrammingError( | |
1763 | b'version 01 changegroups do not support sparse file matchers' |
|
1768 | b'version 01 changegroups do not support sparse file matchers' | |
1764 | ) |
|
1769 | ) | |
1765 |
|
1770 | |||
1766 | if ellipses and version in (b'01', b'02'): |
|
1771 | if ellipses and version in (b'01', b'02'): | |
1767 | raise error.Abort( |
|
1772 | raise error.Abort( | |
1768 | _( |
|
1773 | _( | |
1769 | b'ellipsis nodes require at least cg3 on client and server, ' |
|
1774 | b'ellipsis nodes require at least cg3 on client and server, ' | |
1770 | b'but negotiated version %s' |
|
1775 | b'but negotiated version %s' | |
1771 | ) |
|
1776 | ) | |
1772 | % version |
|
1777 | % version | |
1773 | ) |
|
1778 | ) | |
1774 |
|
1779 | |||
1775 | # Requested files could include files not in the local store. So |
|
1780 | # Requested files could include files not in the local store. So | |
1776 | # filter those out. |
|
1781 | # filter those out. | |
1777 | matcher = repo.narrowmatch(matcher) |
|
1782 | matcher = repo.narrowmatch(matcher) | |
1778 |
|
1783 | |||
1779 | fn = _packermap[version][0] |
|
1784 | fn = _packermap[version][0] | |
1780 | return fn( |
|
1785 | return fn( | |
1781 | repo, |
|
1786 | repo, | |
1782 | oldmatcher, |
|
1787 | oldmatcher, | |
1783 | matcher, |
|
1788 | matcher, | |
1784 | bundlecaps, |
|
1789 | bundlecaps, | |
1785 | ellipses=ellipses, |
|
1790 | ellipses=ellipses, | |
1786 | shallow=shallow, |
|
1791 | shallow=shallow, | |
1787 | ellipsisroots=ellipsisroots, |
|
1792 | ellipsisroots=ellipsisroots, | |
1788 | fullnodes=fullnodes, |
|
1793 | fullnodes=fullnodes, | |
1789 | remote_sidedata=remote_sidedata, |
|
1794 | remote_sidedata=remote_sidedata, | |
1790 | ) |
|
1795 | ) | |
1791 |
|
1796 | |||
1792 |
|
1797 | |||
1793 | def getunbundler(version, fh, alg, extras=None): |
|
1798 | def getunbundler(version, fh, alg, extras=None): | |
1794 | return _packermap[version][1](fh, alg, extras=extras) |
|
1799 | return _packermap[version][1](fh, alg, extras=extras) | |
1795 |
|
1800 | |||
1796 |
|
1801 | |||
1797 | def _changegroupinfo(repo, nodes, source): |
|
1802 | def _changegroupinfo(repo, nodes, source): | |
1798 | if repo.ui.verbose or source == b'bundle': |
|
1803 | if repo.ui.verbose or source == b'bundle': | |
1799 | repo.ui.status(_(b"%d changesets found\n") % len(nodes)) |
|
1804 | repo.ui.status(_(b"%d changesets found\n") % len(nodes)) | |
1800 | if repo.ui.debugflag: |
|
1805 | if repo.ui.debugflag: | |
1801 | repo.ui.debug(b"list of changesets:\n") |
|
1806 | repo.ui.debug(b"list of changesets:\n") | |
1802 | for node in nodes: |
|
1807 | for node in nodes: | |
1803 | repo.ui.debug(b"%s\n" % hex(node)) |
|
1808 | repo.ui.debug(b"%s\n" % hex(node)) | |
1804 |
|
1809 | |||
1805 |
|
1810 | |||
1806 | def makechangegroup( |
|
1811 | def makechangegroup( | |
1807 | repo, outgoing, version, source, fastpath=False, bundlecaps=None |
|
1812 | repo, outgoing, version, source, fastpath=False, bundlecaps=None | |
1808 | ): |
|
1813 | ): | |
1809 | cgstream = makestream( |
|
1814 | cgstream = makestream( | |
1810 | repo, |
|
1815 | repo, | |
1811 | outgoing, |
|
1816 | outgoing, | |
1812 | version, |
|
1817 | version, | |
1813 | source, |
|
1818 | source, | |
1814 | fastpath=fastpath, |
|
1819 | fastpath=fastpath, | |
1815 | bundlecaps=bundlecaps, |
|
1820 | bundlecaps=bundlecaps, | |
1816 | ) |
|
1821 | ) | |
1817 | return getunbundler( |
|
1822 | return getunbundler( | |
1818 | version, |
|
1823 | version, | |
1819 | util.chunkbuffer(cgstream), |
|
1824 | util.chunkbuffer(cgstream), | |
1820 | None, |
|
1825 | None, | |
1821 | {b'clcount': len(outgoing.missing)}, |
|
1826 | {b'clcount': len(outgoing.missing)}, | |
1822 | ) |
|
1827 | ) | |
1823 |
|
1828 | |||
1824 |
|
1829 | |||
1825 | def makestream( |
|
1830 | def makestream( | |
1826 | repo, |
|
1831 | repo, | |
1827 | outgoing, |
|
1832 | outgoing, | |
1828 | version, |
|
1833 | version, | |
1829 | source, |
|
1834 | source, | |
1830 | fastpath=False, |
|
1835 | fastpath=False, | |
1831 | bundlecaps=None, |
|
1836 | bundlecaps=None, | |
1832 | matcher=None, |
|
1837 | matcher=None, | |
1833 | remote_sidedata=None, |
|
1838 | remote_sidedata=None, | |
1834 | ): |
|
1839 | ): | |
1835 | bundler = getbundler( |
|
1840 | bundler = getbundler( | |
1836 | version, |
|
1841 | version, | |
1837 | repo, |
|
1842 | repo, | |
1838 | bundlecaps=bundlecaps, |
|
1843 | bundlecaps=bundlecaps, | |
1839 | matcher=matcher, |
|
1844 | matcher=matcher, | |
1840 | remote_sidedata=remote_sidedata, |
|
1845 | remote_sidedata=remote_sidedata, | |
1841 | ) |
|
1846 | ) | |
1842 |
|
1847 | |||
1843 | repo = repo.unfiltered() |
|
1848 | repo = repo.unfiltered() | |
1844 | commonrevs = outgoing.common |
|
1849 | commonrevs = outgoing.common | |
1845 | csets = outgoing.missing |
|
1850 | csets = outgoing.missing | |
1846 | heads = outgoing.ancestorsof |
|
1851 | heads = outgoing.ancestorsof | |
1847 | # We go through the fast path if we get told to, or if all (unfiltered |
|
1852 | # We go through the fast path if we get told to, or if all (unfiltered | |
1848 | # heads have been requested (since we then know there all linkrevs will |
|
1853 | # heads have been requested (since we then know there all linkrevs will | |
1849 | # be pulled by the client). |
|
1854 | # be pulled by the client). | |
1850 | heads.sort() |
|
1855 | heads.sort() | |
1851 | fastpathlinkrev = fastpath or ( |
|
1856 | fastpathlinkrev = fastpath or ( | |
1852 | repo.filtername is None and heads == sorted(repo.heads()) |
|
1857 | repo.filtername is None and heads == sorted(repo.heads()) | |
1853 | ) |
|
1858 | ) | |
1854 |
|
1859 | |||
1855 | repo.hook(b'preoutgoing', throw=True, source=source) |
|
1860 | repo.hook(b'preoutgoing', throw=True, source=source) | |
1856 | _changegroupinfo(repo, csets, source) |
|
1861 | _changegroupinfo(repo, csets, source) | |
1857 | return bundler.generate(commonrevs, csets, fastpathlinkrev, source) |
|
1862 | return bundler.generate(commonrevs, csets, fastpathlinkrev, source) | |
1858 |
|
1863 | |||
1859 |
|
1864 | |||
1860 | def _addchangegroupfiles( |
|
1865 | def _addchangegroupfiles( | |
1861 | repo, |
|
1866 | repo, | |
1862 | source, |
|
1867 | source, | |
1863 | revmap, |
|
1868 | revmap, | |
1864 | trp, |
|
1869 | trp, | |
1865 | expectedfiles, |
|
1870 | expectedfiles, | |
1866 | needfiles, |
|
1871 | needfiles, | |
1867 | addrevisioncb=None, |
|
1872 | addrevisioncb=None, | |
1868 | ): |
|
1873 | ): | |
1869 | revisions = 0 |
|
1874 | revisions = 0 | |
1870 | files = 0 |
|
1875 | files = 0 | |
1871 | progress = repo.ui.makeprogress( |
|
1876 | progress = repo.ui.makeprogress( | |
1872 | _(b'files'), unit=_(b'files'), total=expectedfiles |
|
1877 | _(b'files'), unit=_(b'files'), total=expectedfiles | |
1873 | ) |
|
1878 | ) | |
1874 | for chunkdata in iter(source.filelogheader, {}): |
|
1879 | for chunkdata in iter(source.filelogheader, {}): | |
1875 | files += 1 |
|
1880 | files += 1 | |
1876 | f = chunkdata[b"filename"] |
|
1881 | f = chunkdata[b"filename"] | |
1877 | repo.ui.debug(b"adding %s revisions\n" % f) |
|
1882 | repo.ui.debug(b"adding %s revisions\n" % f) | |
1878 | progress.increment() |
|
1883 | progress.increment() | |
1879 | fl = repo.file(f) |
|
1884 | fl = repo.file(f) | |
1880 | o = len(fl) |
|
1885 | o = len(fl) | |
1881 | try: |
|
1886 | try: | |
1882 | deltas = source.deltaiter() |
|
1887 | deltas = source.deltaiter() | |
1883 | added = fl.addgroup( |
|
1888 | added = fl.addgroup( | |
1884 | deltas, |
|
1889 | deltas, | |
1885 | revmap, |
|
1890 | revmap, | |
1886 | trp, |
|
1891 | trp, | |
1887 | addrevisioncb=addrevisioncb, |
|
1892 | addrevisioncb=addrevisioncb, | |
1888 | ) |
|
1893 | ) | |
1889 | if not added: |
|
1894 | if not added: | |
1890 | raise error.Abort(_(b"received file revlog group is empty")) |
|
1895 | raise error.Abort(_(b"received file revlog group is empty")) | |
1891 | except error.CensoredBaseError as e: |
|
1896 | except error.CensoredBaseError as e: | |
1892 | raise error.Abort(_(b"received delta base is censored: %s") % e) |
|
1897 | raise error.Abort(_(b"received delta base is censored: %s") % e) | |
1893 | revisions += len(fl) - o |
|
1898 | revisions += len(fl) - o | |
1894 | if f in needfiles: |
|
1899 | if f in needfiles: | |
1895 | needs = needfiles[f] |
|
1900 | needs = needfiles[f] | |
1896 | for new in pycompat.xrange(o, len(fl)): |
|
1901 | for new in pycompat.xrange(o, len(fl)): | |
1897 | n = fl.node(new) |
|
1902 | n = fl.node(new) | |
1898 | if n in needs: |
|
1903 | if n in needs: | |
1899 | needs.remove(n) |
|
1904 | needs.remove(n) | |
1900 | else: |
|
1905 | else: | |
1901 | raise error.Abort(_(b"received spurious file revlog entry")) |
|
1906 | raise error.Abort(_(b"received spurious file revlog entry")) | |
1902 | if not needs: |
|
1907 | if not needs: | |
1903 | del needfiles[f] |
|
1908 | del needfiles[f] | |
1904 | progress.complete() |
|
1909 | progress.complete() | |
1905 |
|
1910 | |||
1906 | for f, needs in pycompat.iteritems(needfiles): |
|
1911 | for f, needs in pycompat.iteritems(needfiles): | |
1907 | fl = repo.file(f) |
|
1912 | fl = repo.file(f) | |
1908 | for n in needs: |
|
1913 | for n in needs: | |
1909 | try: |
|
1914 | try: | |
1910 | fl.rev(n) |
|
1915 | fl.rev(n) | |
1911 | except error.LookupError: |
|
1916 | except error.LookupError: | |
1912 | raise error.Abort( |
|
1917 | raise error.Abort( | |
1913 | _(b'missing file data for %s:%s - run hg verify') |
|
1918 | _(b'missing file data for %s:%s - run hg verify') | |
1914 | % (f, hex(n)) |
|
1919 | % (f, hex(n)) | |
1915 | ) |
|
1920 | ) | |
1916 |
|
1921 | |||
1917 | return revisions, files |
|
1922 | return revisions, files | |
1918 |
|
1923 | |||
1919 |
|
1924 | |||
1920 | def get_sidedata_helpers(repo, remote_sd_categories, pull=False): |
|
1925 | def get_sidedata_helpers(repo, remote_sd_categories, pull=False): | |
1921 | # Computers for computing sidedata on-the-fly |
|
1926 | # Computers for computing sidedata on-the-fly | |
1922 | sd_computers = collections.defaultdict(list) |
|
1927 | sd_computers = collections.defaultdict(list) | |
1923 | # Computers for categories to remove from sidedata |
|
1928 | # Computers for categories to remove from sidedata | |
1924 | sd_removers = collections.defaultdict(list) |
|
1929 | sd_removers = collections.defaultdict(list) | |
1925 |
|
1930 | |||
1926 | to_generate = remote_sd_categories - repo._wanted_sidedata |
|
1931 | to_generate = remote_sd_categories - repo._wanted_sidedata | |
1927 | to_remove = repo._wanted_sidedata - remote_sd_categories |
|
1932 | to_remove = repo._wanted_sidedata - remote_sd_categories | |
1928 | if pull: |
|
1933 | if pull: | |
1929 | to_generate, to_remove = to_remove, to_generate |
|
1934 | to_generate, to_remove = to_remove, to_generate | |
1930 |
|
1935 | |||
1931 | for revlog_kind, computers in repo._sidedata_computers.items(): |
|
1936 | for revlog_kind, computers in repo._sidedata_computers.items(): | |
1932 | for category, computer in computers.items(): |
|
1937 | for category, computer in computers.items(): | |
1933 | if category in to_generate: |
|
1938 | if category in to_generate: | |
1934 | sd_computers[revlog_kind].append(computer) |
|
1939 | sd_computers[revlog_kind].append(computer) | |
1935 | if category in to_remove: |
|
1940 | if category in to_remove: | |
1936 | sd_removers[revlog_kind].append(computer) |
|
1941 | sd_removers[revlog_kind].append(computer) | |
1937 |
|
1942 | |||
1938 | sidedata_helpers = (repo, sd_computers, sd_removers) |
|
1943 | sidedata_helpers = (repo, sd_computers, sd_removers) | |
1939 | return sidedata_helpers |
|
1944 | return sidedata_helpers |
@@ -1,3760 +1,3763 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 Olivia Mackall <olivia@selenic.com> |
|
3 | # Copyright 2005-2007 Olivia Mackall <olivia@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 functools |
|
11 | import functools | |
12 | import os |
|
12 | import os | |
13 | import random |
|
13 | import random | |
14 | import sys |
|
14 | import sys | |
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 | bin, |
|
20 | bin, | |
21 | hex, |
|
21 | hex, | |
22 | nullrev, |
|
22 | nullrev, | |
23 | sha1nodeconstants, |
|
23 | sha1nodeconstants, | |
24 | short, |
|
24 | short, | |
25 | ) |
|
25 | ) | |
26 | from .pycompat import ( |
|
26 | from .pycompat import ( | |
27 | delattr, |
|
27 | delattr, | |
28 | getattr, |
|
28 | getattr, | |
29 | ) |
|
29 | ) | |
30 | from . import ( |
|
30 | from . import ( | |
31 | bookmarks, |
|
31 | bookmarks, | |
32 | branchmap, |
|
32 | branchmap, | |
33 | bundle2, |
|
33 | bundle2, | |
34 | bundlecaches, |
|
34 | bundlecaches, | |
35 | changegroup, |
|
35 | changegroup, | |
36 | color, |
|
36 | color, | |
37 | commit, |
|
37 | commit, | |
38 | context, |
|
38 | context, | |
39 | dirstate, |
|
39 | dirstate, | |
40 | dirstateguard, |
|
40 | dirstateguard, | |
41 | discovery, |
|
41 | discovery, | |
42 | encoding, |
|
42 | encoding, | |
43 | error, |
|
43 | error, | |
44 | exchange, |
|
44 | exchange, | |
45 | extensions, |
|
45 | extensions, | |
46 | filelog, |
|
46 | filelog, | |
47 | hook, |
|
47 | hook, | |
48 | lock as lockmod, |
|
48 | lock as lockmod, | |
49 | match as matchmod, |
|
49 | match as matchmod, | |
50 | mergestate as mergestatemod, |
|
50 | mergestate as mergestatemod, | |
51 | mergeutil, |
|
51 | mergeutil, | |
52 | metadata as metadatamod, |
|
52 | metadata as metadatamod, | |
53 | namespaces, |
|
53 | namespaces, | |
54 | narrowspec, |
|
54 | narrowspec, | |
55 | obsolete, |
|
55 | obsolete, | |
56 | pathutil, |
|
56 | pathutil, | |
57 | phases, |
|
57 | phases, | |
58 | pushkey, |
|
58 | pushkey, | |
59 | pycompat, |
|
59 | pycompat, | |
60 | rcutil, |
|
60 | rcutil, | |
61 | repoview, |
|
61 | repoview, | |
62 | requirements as requirementsmod, |
|
62 | requirements as requirementsmod, | |
63 | revlog, |
|
63 | revlog, | |
64 | revset, |
|
64 | revset, | |
65 | revsetlang, |
|
65 | revsetlang, | |
66 | scmutil, |
|
66 | scmutil, | |
67 | sparse, |
|
67 | sparse, | |
68 | store as storemod, |
|
68 | store as storemod, | |
69 | subrepoutil, |
|
69 | subrepoutil, | |
70 | tags as tagsmod, |
|
70 | tags as tagsmod, | |
71 | transaction, |
|
71 | transaction, | |
72 | txnutil, |
|
72 | txnutil, | |
73 | util, |
|
73 | util, | |
74 | vfs as vfsmod, |
|
74 | vfs as vfsmod, | |
75 | wireprototypes, |
|
75 | wireprototypes, | |
76 | ) |
|
76 | ) | |
77 |
|
77 | |||
78 | from .interfaces import ( |
|
78 | from .interfaces import ( | |
79 | repository, |
|
79 | repository, | |
80 | util as interfaceutil, |
|
80 | util as interfaceutil, | |
81 | ) |
|
81 | ) | |
82 |
|
82 | |||
83 | from .utils import ( |
|
83 | from .utils import ( | |
84 | hashutil, |
|
84 | hashutil, | |
85 | procutil, |
|
85 | procutil, | |
86 | stringutil, |
|
86 | stringutil, | |
87 | urlutil, |
|
87 | urlutil, | |
88 | ) |
|
88 | ) | |
89 |
|
89 | |||
90 | from .revlogutils import ( |
|
90 | from .revlogutils import ( | |
91 | concurrency_checker as revlogchecker, |
|
91 | concurrency_checker as revlogchecker, | |
92 | constants as revlogconst, |
|
92 | constants as revlogconst, | |
93 | ) |
|
93 | ) | |
94 |
|
94 | |||
95 | release = lockmod.release |
|
95 | release = lockmod.release | |
96 | urlerr = util.urlerr |
|
96 | urlerr = util.urlerr | |
97 | urlreq = util.urlreq |
|
97 | urlreq = util.urlreq | |
98 |
|
98 | |||
99 | # set of (path, vfs-location) tuples. vfs-location is: |
|
99 | # set of (path, vfs-location) tuples. vfs-location is: | |
100 | # - 'plain for vfs relative paths |
|
100 | # - 'plain for vfs relative paths | |
101 | # - '' for svfs relative paths |
|
101 | # - '' for svfs relative paths | |
102 | _cachedfiles = set() |
|
102 | _cachedfiles = set() | |
103 |
|
103 | |||
104 |
|
104 | |||
105 | class _basefilecache(scmutil.filecache): |
|
105 | class _basefilecache(scmutil.filecache): | |
106 | """All filecache usage on repo are done for logic that should be unfiltered""" |
|
106 | """All filecache usage on repo are done for logic that should be unfiltered""" | |
107 |
|
107 | |||
108 | def __get__(self, repo, type=None): |
|
108 | def __get__(self, repo, type=None): | |
109 | if repo is None: |
|
109 | if repo is None: | |
110 | return self |
|
110 | return self | |
111 | # proxy to unfiltered __dict__ since filtered repo has no entry |
|
111 | # proxy to unfiltered __dict__ since filtered repo has no entry | |
112 | unfi = repo.unfiltered() |
|
112 | unfi = repo.unfiltered() | |
113 | try: |
|
113 | try: | |
114 | return unfi.__dict__[self.sname] |
|
114 | return unfi.__dict__[self.sname] | |
115 | except KeyError: |
|
115 | except KeyError: | |
116 | pass |
|
116 | pass | |
117 | return super(_basefilecache, self).__get__(unfi, type) |
|
117 | return super(_basefilecache, self).__get__(unfi, type) | |
118 |
|
118 | |||
119 | def set(self, repo, value): |
|
119 | def set(self, repo, value): | |
120 | return super(_basefilecache, self).set(repo.unfiltered(), value) |
|
120 | return super(_basefilecache, self).set(repo.unfiltered(), value) | |
121 |
|
121 | |||
122 |
|
122 | |||
123 | class repofilecache(_basefilecache): |
|
123 | class repofilecache(_basefilecache): | |
124 | """filecache for files in .hg but outside of .hg/store""" |
|
124 | """filecache for files in .hg but outside of .hg/store""" | |
125 |
|
125 | |||
126 | def __init__(self, *paths): |
|
126 | def __init__(self, *paths): | |
127 | super(repofilecache, self).__init__(*paths) |
|
127 | super(repofilecache, self).__init__(*paths) | |
128 | for path in paths: |
|
128 | for path in paths: | |
129 | _cachedfiles.add((path, b'plain')) |
|
129 | _cachedfiles.add((path, b'plain')) | |
130 |
|
130 | |||
131 | def join(self, obj, fname): |
|
131 | def join(self, obj, fname): | |
132 | return obj.vfs.join(fname) |
|
132 | return obj.vfs.join(fname) | |
133 |
|
133 | |||
134 |
|
134 | |||
135 | class storecache(_basefilecache): |
|
135 | class storecache(_basefilecache): | |
136 | """filecache for files in the store""" |
|
136 | """filecache for files in the store""" | |
137 |
|
137 | |||
138 | def __init__(self, *paths): |
|
138 | def __init__(self, *paths): | |
139 | super(storecache, self).__init__(*paths) |
|
139 | super(storecache, self).__init__(*paths) | |
140 | for path in paths: |
|
140 | for path in paths: | |
141 | _cachedfiles.add((path, b'')) |
|
141 | _cachedfiles.add((path, b'')) | |
142 |
|
142 | |||
143 | def join(self, obj, fname): |
|
143 | def join(self, obj, fname): | |
144 | return obj.sjoin(fname) |
|
144 | return obj.sjoin(fname) | |
145 |
|
145 | |||
146 |
|
146 | |||
147 | class mixedrepostorecache(_basefilecache): |
|
147 | class mixedrepostorecache(_basefilecache): | |
148 | """filecache for a mix files in .hg/store and outside""" |
|
148 | """filecache for a mix files in .hg/store and outside""" | |
149 |
|
149 | |||
150 | def __init__(self, *pathsandlocations): |
|
150 | def __init__(self, *pathsandlocations): | |
151 | # scmutil.filecache only uses the path for passing back into our |
|
151 | # scmutil.filecache only uses the path for passing back into our | |
152 | # join(), so we can safely pass a list of paths and locations |
|
152 | # join(), so we can safely pass a list of paths and locations | |
153 | super(mixedrepostorecache, self).__init__(*pathsandlocations) |
|
153 | super(mixedrepostorecache, self).__init__(*pathsandlocations) | |
154 | _cachedfiles.update(pathsandlocations) |
|
154 | _cachedfiles.update(pathsandlocations) | |
155 |
|
155 | |||
156 | def join(self, obj, fnameandlocation): |
|
156 | def join(self, obj, fnameandlocation): | |
157 | fname, location = fnameandlocation |
|
157 | fname, location = fnameandlocation | |
158 | if location == b'plain': |
|
158 | if location == b'plain': | |
159 | return obj.vfs.join(fname) |
|
159 | return obj.vfs.join(fname) | |
160 | else: |
|
160 | else: | |
161 | if location != b'': |
|
161 | if location != b'': | |
162 | raise error.ProgrammingError( |
|
162 | raise error.ProgrammingError( | |
163 | b'unexpected location: %s' % location |
|
163 | b'unexpected location: %s' % location | |
164 | ) |
|
164 | ) | |
165 | return obj.sjoin(fname) |
|
165 | return obj.sjoin(fname) | |
166 |
|
166 | |||
167 |
|
167 | |||
168 | def isfilecached(repo, name): |
|
168 | def isfilecached(repo, name): | |
169 | """check if a repo has already cached "name" filecache-ed property |
|
169 | """check if a repo has already cached "name" filecache-ed property | |
170 |
|
170 | |||
171 | This returns (cachedobj-or-None, iscached) tuple. |
|
171 | This returns (cachedobj-or-None, iscached) tuple. | |
172 | """ |
|
172 | """ | |
173 | cacheentry = repo.unfiltered()._filecache.get(name, None) |
|
173 | cacheentry = repo.unfiltered()._filecache.get(name, None) | |
174 | if not cacheentry: |
|
174 | if not cacheentry: | |
175 | return None, False |
|
175 | return None, False | |
176 | return cacheentry.obj, True |
|
176 | return cacheentry.obj, True | |
177 |
|
177 | |||
178 |
|
178 | |||
179 | class unfilteredpropertycache(util.propertycache): |
|
179 | class unfilteredpropertycache(util.propertycache): | |
180 | """propertycache that apply to unfiltered repo only""" |
|
180 | """propertycache that apply to unfiltered repo only""" | |
181 |
|
181 | |||
182 | def __get__(self, repo, type=None): |
|
182 | def __get__(self, repo, type=None): | |
183 | unfi = repo.unfiltered() |
|
183 | unfi = repo.unfiltered() | |
184 | if unfi is repo: |
|
184 | if unfi is repo: | |
185 | return super(unfilteredpropertycache, self).__get__(unfi) |
|
185 | return super(unfilteredpropertycache, self).__get__(unfi) | |
186 | return getattr(unfi, self.name) |
|
186 | return getattr(unfi, self.name) | |
187 |
|
187 | |||
188 |
|
188 | |||
189 | class filteredpropertycache(util.propertycache): |
|
189 | class filteredpropertycache(util.propertycache): | |
190 | """propertycache that must take filtering in account""" |
|
190 | """propertycache that must take filtering in account""" | |
191 |
|
191 | |||
192 | def cachevalue(self, obj, value): |
|
192 | def cachevalue(self, obj, value): | |
193 | object.__setattr__(obj, self.name, value) |
|
193 | object.__setattr__(obj, self.name, value) | |
194 |
|
194 | |||
195 |
|
195 | |||
196 | def hasunfilteredcache(repo, name): |
|
196 | def hasunfilteredcache(repo, name): | |
197 | """check if a repo has an unfilteredpropertycache value for <name>""" |
|
197 | """check if a repo has an unfilteredpropertycache value for <name>""" | |
198 | return name in vars(repo.unfiltered()) |
|
198 | return name in vars(repo.unfiltered()) | |
199 |
|
199 | |||
200 |
|
200 | |||
201 | def unfilteredmethod(orig): |
|
201 | def unfilteredmethod(orig): | |
202 | """decorate method that always need to be run on unfiltered version""" |
|
202 | """decorate method that always need to be run on unfiltered version""" | |
203 |
|
203 | |||
204 | @functools.wraps(orig) |
|
204 | @functools.wraps(orig) | |
205 | def wrapper(repo, *args, **kwargs): |
|
205 | def wrapper(repo, *args, **kwargs): | |
206 | return orig(repo.unfiltered(), *args, **kwargs) |
|
206 | return orig(repo.unfiltered(), *args, **kwargs) | |
207 |
|
207 | |||
208 | return wrapper |
|
208 | return wrapper | |
209 |
|
209 | |||
210 |
|
210 | |||
211 | moderncaps = { |
|
211 | moderncaps = { | |
212 | b'lookup', |
|
212 | b'lookup', | |
213 | b'branchmap', |
|
213 | b'branchmap', | |
214 | b'pushkey', |
|
214 | b'pushkey', | |
215 | b'known', |
|
215 | b'known', | |
216 | b'getbundle', |
|
216 | b'getbundle', | |
217 | b'unbundle', |
|
217 | b'unbundle', | |
218 | } |
|
218 | } | |
219 | legacycaps = moderncaps.union({b'changegroupsubset'}) |
|
219 | legacycaps = moderncaps.union({b'changegroupsubset'}) | |
220 |
|
220 | |||
221 |
|
221 | |||
222 | @interfaceutil.implementer(repository.ipeercommandexecutor) |
|
222 | @interfaceutil.implementer(repository.ipeercommandexecutor) | |
223 | class localcommandexecutor(object): |
|
223 | class localcommandexecutor(object): | |
224 | def __init__(self, peer): |
|
224 | def __init__(self, peer): | |
225 | self._peer = peer |
|
225 | self._peer = peer | |
226 | self._sent = False |
|
226 | self._sent = False | |
227 | self._closed = False |
|
227 | self._closed = False | |
228 |
|
228 | |||
229 | def __enter__(self): |
|
229 | def __enter__(self): | |
230 | return self |
|
230 | return self | |
231 |
|
231 | |||
232 | def __exit__(self, exctype, excvalue, exctb): |
|
232 | def __exit__(self, exctype, excvalue, exctb): | |
233 | self.close() |
|
233 | self.close() | |
234 |
|
234 | |||
235 | def callcommand(self, command, args): |
|
235 | def callcommand(self, command, args): | |
236 | if self._sent: |
|
236 | if self._sent: | |
237 | raise error.ProgrammingError( |
|
237 | raise error.ProgrammingError( | |
238 | b'callcommand() cannot be used after sendcommands()' |
|
238 | b'callcommand() cannot be used after sendcommands()' | |
239 | ) |
|
239 | ) | |
240 |
|
240 | |||
241 | if self._closed: |
|
241 | if self._closed: | |
242 | raise error.ProgrammingError( |
|
242 | raise error.ProgrammingError( | |
243 | b'callcommand() cannot be used after close()' |
|
243 | b'callcommand() cannot be used after close()' | |
244 | ) |
|
244 | ) | |
245 |
|
245 | |||
246 | # We don't need to support anything fancy. Just call the named |
|
246 | # We don't need to support anything fancy. Just call the named | |
247 | # method on the peer and return a resolved future. |
|
247 | # method on the peer and return a resolved future. | |
248 | fn = getattr(self._peer, pycompat.sysstr(command)) |
|
248 | fn = getattr(self._peer, pycompat.sysstr(command)) | |
249 |
|
249 | |||
250 | f = pycompat.futures.Future() |
|
250 | f = pycompat.futures.Future() | |
251 |
|
251 | |||
252 | try: |
|
252 | try: | |
253 | result = fn(**pycompat.strkwargs(args)) |
|
253 | result = fn(**pycompat.strkwargs(args)) | |
254 | except Exception: |
|
254 | except Exception: | |
255 | pycompat.future_set_exception_info(f, sys.exc_info()[1:]) |
|
255 | pycompat.future_set_exception_info(f, sys.exc_info()[1:]) | |
256 | else: |
|
256 | else: | |
257 | f.set_result(result) |
|
257 | f.set_result(result) | |
258 |
|
258 | |||
259 | return f |
|
259 | return f | |
260 |
|
260 | |||
261 | def sendcommands(self): |
|
261 | def sendcommands(self): | |
262 | self._sent = True |
|
262 | self._sent = True | |
263 |
|
263 | |||
264 | def close(self): |
|
264 | def close(self): | |
265 | self._closed = True |
|
265 | self._closed = True | |
266 |
|
266 | |||
267 |
|
267 | |||
268 | @interfaceutil.implementer(repository.ipeercommands) |
|
268 | @interfaceutil.implementer(repository.ipeercommands) | |
269 | class localpeer(repository.peer): |
|
269 | class localpeer(repository.peer): | |
270 | '''peer for a local repo; reflects only the most recent API''' |
|
270 | '''peer for a local repo; reflects only the most recent API''' | |
271 |
|
271 | |||
272 | def __init__(self, repo, caps=None): |
|
272 | def __init__(self, repo, caps=None): | |
273 | super(localpeer, self).__init__() |
|
273 | super(localpeer, self).__init__() | |
274 |
|
274 | |||
275 | if caps is None: |
|
275 | if caps is None: | |
276 | caps = moderncaps.copy() |
|
276 | caps = moderncaps.copy() | |
277 | self._repo = repo.filtered(b'served') |
|
277 | self._repo = repo.filtered(b'served') | |
278 | self.ui = repo.ui |
|
278 | self.ui = repo.ui | |
279 |
|
279 | |||
280 | if repo._wanted_sidedata: |
|
280 | if repo._wanted_sidedata: | |
281 | formatted = bundle2.format_remote_wanted_sidedata(repo) |
|
281 | formatted = bundle2.format_remote_wanted_sidedata(repo) | |
282 | caps.add(b'exp-wanted-sidedata=' + formatted) |
|
282 | caps.add(b'exp-wanted-sidedata=' + formatted) | |
283 |
|
283 | |||
284 | self._caps = repo._restrictcapabilities(caps) |
|
284 | self._caps = repo._restrictcapabilities(caps) | |
285 |
|
285 | |||
286 | # Begin of _basepeer interface. |
|
286 | # Begin of _basepeer interface. | |
287 |
|
287 | |||
288 | def url(self): |
|
288 | def url(self): | |
289 | return self._repo.url() |
|
289 | return self._repo.url() | |
290 |
|
290 | |||
291 | def local(self): |
|
291 | def local(self): | |
292 | return self._repo |
|
292 | return self._repo | |
293 |
|
293 | |||
294 | def peer(self): |
|
294 | def peer(self): | |
295 | return self |
|
295 | return self | |
296 |
|
296 | |||
297 | def canpush(self): |
|
297 | def canpush(self): | |
298 | return True |
|
298 | return True | |
299 |
|
299 | |||
300 | def close(self): |
|
300 | def close(self): | |
301 | self._repo.close() |
|
301 | self._repo.close() | |
302 |
|
302 | |||
303 | # End of _basepeer interface. |
|
303 | # End of _basepeer interface. | |
304 |
|
304 | |||
305 | # Begin of _basewirecommands interface. |
|
305 | # Begin of _basewirecommands interface. | |
306 |
|
306 | |||
307 | def branchmap(self): |
|
307 | def branchmap(self): | |
308 | return self._repo.branchmap() |
|
308 | return self._repo.branchmap() | |
309 |
|
309 | |||
310 | def capabilities(self): |
|
310 | def capabilities(self): | |
311 | return self._caps |
|
311 | return self._caps | |
312 |
|
312 | |||
313 | def clonebundles(self): |
|
313 | def clonebundles(self): | |
314 | return self._repo.tryread(bundlecaches.CB_MANIFEST_FILE) |
|
314 | return self._repo.tryread(bundlecaches.CB_MANIFEST_FILE) | |
315 |
|
315 | |||
316 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
316 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
317 | """Used to test argument passing over the wire""" |
|
317 | """Used to test argument passing over the wire""" | |
318 | return b"%s %s %s %s %s" % ( |
|
318 | return b"%s %s %s %s %s" % ( | |
319 | one, |
|
319 | one, | |
320 | two, |
|
320 | two, | |
321 | pycompat.bytestr(three), |
|
321 | pycompat.bytestr(three), | |
322 | pycompat.bytestr(four), |
|
322 | pycompat.bytestr(four), | |
323 | pycompat.bytestr(five), |
|
323 | pycompat.bytestr(five), | |
324 | ) |
|
324 | ) | |
325 |
|
325 | |||
326 | def getbundle( |
|
326 | def getbundle( | |
327 | self, |
|
327 | self, | |
328 | source, |
|
328 | source, | |
329 | heads=None, |
|
329 | heads=None, | |
330 | common=None, |
|
330 | common=None, | |
331 | bundlecaps=None, |
|
331 | bundlecaps=None, | |
332 | remote_sidedata=None, |
|
332 | remote_sidedata=None, | |
333 | **kwargs |
|
333 | **kwargs | |
334 | ): |
|
334 | ): | |
335 | chunks = exchange.getbundlechunks( |
|
335 | chunks = exchange.getbundlechunks( | |
336 | self._repo, |
|
336 | self._repo, | |
337 | source, |
|
337 | source, | |
338 | heads=heads, |
|
338 | heads=heads, | |
339 | common=common, |
|
339 | common=common, | |
340 | bundlecaps=bundlecaps, |
|
340 | bundlecaps=bundlecaps, | |
341 | remote_sidedata=remote_sidedata, |
|
341 | remote_sidedata=remote_sidedata, | |
342 | **kwargs |
|
342 | **kwargs | |
343 | )[1] |
|
343 | )[1] | |
344 | cb = util.chunkbuffer(chunks) |
|
344 | cb = util.chunkbuffer(chunks) | |
345 |
|
345 | |||
346 | if exchange.bundle2requested(bundlecaps): |
|
346 | if exchange.bundle2requested(bundlecaps): | |
347 | # When requesting a bundle2, getbundle returns a stream to make the |
|
347 | # When requesting a bundle2, getbundle returns a stream to make the | |
348 | # wire level function happier. We need to build a proper object |
|
348 | # wire level function happier. We need to build a proper object | |
349 | # from it in local peer. |
|
349 | # from it in local peer. | |
350 | return bundle2.getunbundler(self.ui, cb) |
|
350 | return bundle2.getunbundler(self.ui, cb) | |
351 | else: |
|
351 | else: | |
352 | return changegroup.getunbundler(b'01', cb, None) |
|
352 | return changegroup.getunbundler(b'01', cb, None) | |
353 |
|
353 | |||
354 | def heads(self): |
|
354 | def heads(self): | |
355 | return self._repo.heads() |
|
355 | return self._repo.heads() | |
356 |
|
356 | |||
357 | def known(self, nodes): |
|
357 | def known(self, nodes): | |
358 | return self._repo.known(nodes) |
|
358 | return self._repo.known(nodes) | |
359 |
|
359 | |||
360 | def listkeys(self, namespace): |
|
360 | def listkeys(self, namespace): | |
361 | return self._repo.listkeys(namespace) |
|
361 | return self._repo.listkeys(namespace) | |
362 |
|
362 | |||
363 | def lookup(self, key): |
|
363 | def lookup(self, key): | |
364 | return self._repo.lookup(key) |
|
364 | return self._repo.lookup(key) | |
365 |
|
365 | |||
366 | def pushkey(self, namespace, key, old, new): |
|
366 | def pushkey(self, namespace, key, old, new): | |
367 | return self._repo.pushkey(namespace, key, old, new) |
|
367 | return self._repo.pushkey(namespace, key, old, new) | |
368 |
|
368 | |||
369 | def stream_out(self): |
|
369 | def stream_out(self): | |
370 | raise error.Abort(_(b'cannot perform stream clone against local peer')) |
|
370 | raise error.Abort(_(b'cannot perform stream clone against local peer')) | |
371 |
|
371 | |||
372 | def unbundle(self, bundle, heads, url): |
|
372 | def unbundle(self, bundle, heads, url): | |
373 | """apply a bundle on a repo |
|
373 | """apply a bundle on a repo | |
374 |
|
374 | |||
375 | This function handles the repo locking itself.""" |
|
375 | This function handles the repo locking itself.""" | |
376 | try: |
|
376 | try: | |
377 | try: |
|
377 | try: | |
378 | bundle = exchange.readbundle(self.ui, bundle, None) |
|
378 | bundle = exchange.readbundle(self.ui, bundle, None) | |
379 | ret = exchange.unbundle(self._repo, bundle, heads, b'push', url) |
|
379 | ret = exchange.unbundle(self._repo, bundle, heads, b'push', url) | |
380 | if util.safehasattr(ret, b'getchunks'): |
|
380 | if util.safehasattr(ret, b'getchunks'): | |
381 | # This is a bundle20 object, turn it into an unbundler. |
|
381 | # This is a bundle20 object, turn it into an unbundler. | |
382 | # This little dance should be dropped eventually when the |
|
382 | # This little dance should be dropped eventually when the | |
383 | # API is finally improved. |
|
383 | # API is finally improved. | |
384 | stream = util.chunkbuffer(ret.getchunks()) |
|
384 | stream = util.chunkbuffer(ret.getchunks()) | |
385 | ret = bundle2.getunbundler(self.ui, stream) |
|
385 | ret = bundle2.getunbundler(self.ui, stream) | |
386 | return ret |
|
386 | return ret | |
387 | except Exception as exc: |
|
387 | except Exception as exc: | |
388 | # If the exception contains output salvaged from a bundle2 |
|
388 | # If the exception contains output salvaged from a bundle2 | |
389 | # reply, we need to make sure it is printed before continuing |
|
389 | # reply, we need to make sure it is printed before continuing | |
390 | # to fail. So we build a bundle2 with such output and consume |
|
390 | # to fail. So we build a bundle2 with such output and consume | |
391 | # it directly. |
|
391 | # it directly. | |
392 | # |
|
392 | # | |
393 | # This is not very elegant but allows a "simple" solution for |
|
393 | # This is not very elegant but allows a "simple" solution for | |
394 | # issue4594 |
|
394 | # issue4594 | |
395 | output = getattr(exc, '_bundle2salvagedoutput', ()) |
|
395 | output = getattr(exc, '_bundle2salvagedoutput', ()) | |
396 | if output: |
|
396 | if output: | |
397 | bundler = bundle2.bundle20(self._repo.ui) |
|
397 | bundler = bundle2.bundle20(self._repo.ui) | |
398 | for out in output: |
|
398 | for out in output: | |
399 | bundler.addpart(out) |
|
399 | bundler.addpart(out) | |
400 | stream = util.chunkbuffer(bundler.getchunks()) |
|
400 | stream = util.chunkbuffer(bundler.getchunks()) | |
401 | b = bundle2.getunbundler(self.ui, stream) |
|
401 | b = bundle2.getunbundler(self.ui, stream) | |
402 | bundle2.processbundle(self._repo, b) |
|
402 | bundle2.processbundle(self._repo, b) | |
403 | raise |
|
403 | raise | |
404 | except error.PushRaced as exc: |
|
404 | except error.PushRaced as exc: | |
405 | raise error.ResponseError( |
|
405 | raise error.ResponseError( | |
406 | _(b'push failed:'), stringutil.forcebytestr(exc) |
|
406 | _(b'push failed:'), stringutil.forcebytestr(exc) | |
407 | ) |
|
407 | ) | |
408 |
|
408 | |||
409 | # End of _basewirecommands interface. |
|
409 | # End of _basewirecommands interface. | |
410 |
|
410 | |||
411 | # Begin of peer interface. |
|
411 | # Begin of peer interface. | |
412 |
|
412 | |||
413 | def commandexecutor(self): |
|
413 | def commandexecutor(self): | |
414 | return localcommandexecutor(self) |
|
414 | return localcommandexecutor(self) | |
415 |
|
415 | |||
416 | # End of peer interface. |
|
416 | # End of peer interface. | |
417 |
|
417 | |||
418 |
|
418 | |||
419 | @interfaceutil.implementer(repository.ipeerlegacycommands) |
|
419 | @interfaceutil.implementer(repository.ipeerlegacycommands) | |
420 | class locallegacypeer(localpeer): |
|
420 | class locallegacypeer(localpeer): | |
421 | """peer extension which implements legacy methods too; used for tests with |
|
421 | """peer extension which implements legacy methods too; used for tests with | |
422 | restricted capabilities""" |
|
422 | restricted capabilities""" | |
423 |
|
423 | |||
424 | def __init__(self, repo): |
|
424 | def __init__(self, repo): | |
425 | super(locallegacypeer, self).__init__(repo, caps=legacycaps) |
|
425 | super(locallegacypeer, self).__init__(repo, caps=legacycaps) | |
426 |
|
426 | |||
427 | # Begin of baselegacywirecommands interface. |
|
427 | # Begin of baselegacywirecommands interface. | |
428 |
|
428 | |||
429 | def between(self, pairs): |
|
429 | def between(self, pairs): | |
430 | return self._repo.between(pairs) |
|
430 | return self._repo.between(pairs) | |
431 |
|
431 | |||
432 | def branches(self, nodes): |
|
432 | def branches(self, nodes): | |
433 | return self._repo.branches(nodes) |
|
433 | return self._repo.branches(nodes) | |
434 |
|
434 | |||
435 | def changegroup(self, nodes, source): |
|
435 | def changegroup(self, nodes, source): | |
436 | outgoing = discovery.outgoing( |
|
436 | outgoing = discovery.outgoing( | |
437 | self._repo, missingroots=nodes, ancestorsof=self._repo.heads() |
|
437 | self._repo, missingroots=nodes, ancestorsof=self._repo.heads() | |
438 | ) |
|
438 | ) | |
439 | return changegroup.makechangegroup(self._repo, outgoing, b'01', source) |
|
439 | return changegroup.makechangegroup(self._repo, outgoing, b'01', source) | |
440 |
|
440 | |||
441 | def changegroupsubset(self, bases, heads, source): |
|
441 | def changegroupsubset(self, bases, heads, source): | |
442 | outgoing = discovery.outgoing( |
|
442 | outgoing = discovery.outgoing( | |
443 | self._repo, missingroots=bases, ancestorsof=heads |
|
443 | self._repo, missingroots=bases, ancestorsof=heads | |
444 | ) |
|
444 | ) | |
445 | return changegroup.makechangegroup(self._repo, outgoing, b'01', source) |
|
445 | return changegroup.makechangegroup(self._repo, outgoing, b'01', source) | |
446 |
|
446 | |||
447 | # End of baselegacywirecommands interface. |
|
447 | # End of baselegacywirecommands interface. | |
448 |
|
448 | |||
449 |
|
449 | |||
450 | # Functions receiving (ui, features) that extensions can register to impact |
|
450 | # Functions receiving (ui, features) that extensions can register to impact | |
451 | # the ability to load repositories with custom requirements. Only |
|
451 | # the ability to load repositories with custom requirements. Only | |
452 | # functions defined in loaded extensions are called. |
|
452 | # functions defined in loaded extensions are called. | |
453 | # |
|
453 | # | |
454 | # The function receives a set of requirement strings that the repository |
|
454 | # The function receives a set of requirement strings that the repository | |
455 | # is capable of opening. Functions will typically add elements to the |
|
455 | # is capable of opening. Functions will typically add elements to the | |
456 | # set to reflect that the extension knows how to handle that requirements. |
|
456 | # set to reflect that the extension knows how to handle that requirements. | |
457 | featuresetupfuncs = set() |
|
457 | featuresetupfuncs = set() | |
458 |
|
458 | |||
459 |
|
459 | |||
460 | def _getsharedvfs(hgvfs, requirements): |
|
460 | def _getsharedvfs(hgvfs, requirements): | |
461 | """returns the vfs object pointing to root of shared source |
|
461 | """returns the vfs object pointing to root of shared source | |
462 | repo for a shared repository |
|
462 | repo for a shared repository | |
463 |
|
463 | |||
464 | hgvfs is vfs pointing at .hg/ of current repo (shared one) |
|
464 | hgvfs is vfs pointing at .hg/ of current repo (shared one) | |
465 | requirements is a set of requirements of current repo (shared one) |
|
465 | requirements is a set of requirements of current repo (shared one) | |
466 | """ |
|
466 | """ | |
467 | # The ``shared`` or ``relshared`` requirements indicate the |
|
467 | # The ``shared`` or ``relshared`` requirements indicate the | |
468 | # store lives in the path contained in the ``.hg/sharedpath`` file. |
|
468 | # store lives in the path contained in the ``.hg/sharedpath`` file. | |
469 | # This is an absolute path for ``shared`` and relative to |
|
469 | # This is an absolute path for ``shared`` and relative to | |
470 | # ``.hg/`` for ``relshared``. |
|
470 | # ``.hg/`` for ``relshared``. | |
471 | sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n') |
|
471 | sharedpath = hgvfs.read(b'sharedpath').rstrip(b'\n') | |
472 | if requirementsmod.RELATIVE_SHARED_REQUIREMENT in requirements: |
|
472 | if requirementsmod.RELATIVE_SHARED_REQUIREMENT in requirements: | |
473 | sharedpath = util.normpath(hgvfs.join(sharedpath)) |
|
473 | sharedpath = util.normpath(hgvfs.join(sharedpath)) | |
474 |
|
474 | |||
475 | sharedvfs = vfsmod.vfs(sharedpath, realpath=True) |
|
475 | sharedvfs = vfsmod.vfs(sharedpath, realpath=True) | |
476 |
|
476 | |||
477 | if not sharedvfs.exists(): |
|
477 | if not sharedvfs.exists(): | |
478 | raise error.RepoError( |
|
478 | raise error.RepoError( | |
479 | _(b'.hg/sharedpath points to nonexistent directory %s') |
|
479 | _(b'.hg/sharedpath points to nonexistent directory %s') | |
480 | % sharedvfs.base |
|
480 | % sharedvfs.base | |
481 | ) |
|
481 | ) | |
482 | return sharedvfs |
|
482 | return sharedvfs | |
483 |
|
483 | |||
484 |
|
484 | |||
485 | def _readrequires(vfs, allowmissing): |
|
485 | def _readrequires(vfs, allowmissing): | |
486 | """reads the require file present at root of this vfs |
|
486 | """reads the require file present at root of this vfs | |
487 | and return a set of requirements |
|
487 | and return a set of requirements | |
488 |
|
488 | |||
489 | If allowmissing is True, we suppress ENOENT if raised""" |
|
489 | If allowmissing is True, we suppress ENOENT if raised""" | |
490 | # requires file contains a newline-delimited list of |
|
490 | # requires file contains a newline-delimited list of | |
491 | # features/capabilities the opener (us) must have in order to use |
|
491 | # features/capabilities the opener (us) must have in order to use | |
492 | # the repository. This file was introduced in Mercurial 0.9.2, |
|
492 | # the repository. This file was introduced in Mercurial 0.9.2, | |
493 | # which means very old repositories may not have one. We assume |
|
493 | # which means very old repositories may not have one. We assume | |
494 | # a missing file translates to no requirements. |
|
494 | # a missing file translates to no requirements. | |
495 | try: |
|
495 | try: | |
496 | requirements = set(vfs.read(b'requires').splitlines()) |
|
496 | requirements = set(vfs.read(b'requires').splitlines()) | |
497 | except IOError as e: |
|
497 | except IOError as e: | |
498 | if not (allowmissing and e.errno == errno.ENOENT): |
|
498 | if not (allowmissing and e.errno == errno.ENOENT): | |
499 | raise |
|
499 | raise | |
500 | requirements = set() |
|
500 | requirements = set() | |
501 | return requirements |
|
501 | return requirements | |
502 |
|
502 | |||
503 |
|
503 | |||
504 | def makelocalrepository(baseui, path, intents=None): |
|
504 | def makelocalrepository(baseui, path, intents=None): | |
505 | """Create a local repository object. |
|
505 | """Create a local repository object. | |
506 |
|
506 | |||
507 | Given arguments needed to construct a local repository, this function |
|
507 | Given arguments needed to construct a local repository, this function | |
508 | performs various early repository loading functionality (such as |
|
508 | performs various early repository loading functionality (such as | |
509 | reading the ``.hg/requires`` and ``.hg/hgrc`` files), validates that |
|
509 | reading the ``.hg/requires`` and ``.hg/hgrc`` files), validates that | |
510 | the repository can be opened, derives a type suitable for representing |
|
510 | the repository can be opened, derives a type suitable for representing | |
511 | that repository, and returns an instance of it. |
|
511 | that repository, and returns an instance of it. | |
512 |
|
512 | |||
513 | The returned object conforms to the ``repository.completelocalrepository`` |
|
513 | The returned object conforms to the ``repository.completelocalrepository`` | |
514 | interface. |
|
514 | interface. | |
515 |
|
515 | |||
516 | The repository type is derived by calling a series of factory functions |
|
516 | The repository type is derived by calling a series of factory functions | |
517 | for each aspect/interface of the final repository. These are defined by |
|
517 | for each aspect/interface of the final repository. These are defined by | |
518 | ``REPO_INTERFACES``. |
|
518 | ``REPO_INTERFACES``. | |
519 |
|
519 | |||
520 | Each factory function is called to produce a type implementing a specific |
|
520 | Each factory function is called to produce a type implementing a specific | |
521 | interface. The cumulative list of returned types will be combined into a |
|
521 | interface. The cumulative list of returned types will be combined into a | |
522 | new type and that type will be instantiated to represent the local |
|
522 | new type and that type will be instantiated to represent the local | |
523 | repository. |
|
523 | repository. | |
524 |
|
524 | |||
525 | The factory functions each receive various state that may be consulted |
|
525 | The factory functions each receive various state that may be consulted | |
526 | as part of deriving a type. |
|
526 | as part of deriving a type. | |
527 |
|
527 | |||
528 | Extensions should wrap these factory functions to customize repository type |
|
528 | Extensions should wrap these factory functions to customize repository type | |
529 | creation. Note that an extension's wrapped function may be called even if |
|
529 | creation. Note that an extension's wrapped function may be called even if | |
530 | that extension is not loaded for the repo being constructed. Extensions |
|
530 | that extension is not loaded for the repo being constructed. Extensions | |
531 | should check if their ``__name__`` appears in the |
|
531 | should check if their ``__name__`` appears in the | |
532 | ``extensionmodulenames`` set passed to the factory function and no-op if |
|
532 | ``extensionmodulenames`` set passed to the factory function and no-op if | |
533 | not. |
|
533 | not. | |
534 | """ |
|
534 | """ | |
535 | ui = baseui.copy() |
|
535 | ui = baseui.copy() | |
536 | # Prevent copying repo configuration. |
|
536 | # Prevent copying repo configuration. | |
537 | ui.copy = baseui.copy |
|
537 | ui.copy = baseui.copy | |
538 |
|
538 | |||
539 | # Working directory VFS rooted at repository root. |
|
539 | # Working directory VFS rooted at repository root. | |
540 | wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) |
|
540 | wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) | |
541 |
|
541 | |||
542 | # Main VFS for .hg/ directory. |
|
542 | # Main VFS for .hg/ directory. | |
543 | hgpath = wdirvfs.join(b'.hg') |
|
543 | hgpath = wdirvfs.join(b'.hg') | |
544 | hgvfs = vfsmod.vfs(hgpath, cacheaudited=True) |
|
544 | hgvfs = vfsmod.vfs(hgpath, cacheaudited=True) | |
545 | # Whether this repository is shared one or not |
|
545 | # Whether this repository is shared one or not | |
546 | shared = False |
|
546 | shared = False | |
547 | # If this repository is shared, vfs pointing to shared repo |
|
547 | # If this repository is shared, vfs pointing to shared repo | |
548 | sharedvfs = None |
|
548 | sharedvfs = None | |
549 |
|
549 | |||
550 | # The .hg/ path should exist and should be a directory. All other |
|
550 | # The .hg/ path should exist and should be a directory. All other | |
551 | # cases are errors. |
|
551 | # cases are errors. | |
552 | if not hgvfs.isdir(): |
|
552 | if not hgvfs.isdir(): | |
553 | try: |
|
553 | try: | |
554 | hgvfs.stat() |
|
554 | hgvfs.stat() | |
555 | except OSError as e: |
|
555 | except OSError as e: | |
556 | if e.errno != errno.ENOENT: |
|
556 | if e.errno != errno.ENOENT: | |
557 | raise |
|
557 | raise | |
558 | except ValueError as e: |
|
558 | except ValueError as e: | |
559 | # Can be raised on Python 3.8 when path is invalid. |
|
559 | # Can be raised on Python 3.8 when path is invalid. | |
560 | raise error.Abort( |
|
560 | raise error.Abort( | |
561 | _(b'invalid path %s: %s') % (path, stringutil.forcebytestr(e)) |
|
561 | _(b'invalid path %s: %s') % (path, stringutil.forcebytestr(e)) | |
562 | ) |
|
562 | ) | |
563 |
|
563 | |||
564 | raise error.RepoError(_(b'repository %s not found') % path) |
|
564 | raise error.RepoError(_(b'repository %s not found') % path) | |
565 |
|
565 | |||
566 | requirements = _readrequires(hgvfs, True) |
|
566 | requirements = _readrequires(hgvfs, True) | |
567 | shared = ( |
|
567 | shared = ( | |
568 | requirementsmod.SHARED_REQUIREMENT in requirements |
|
568 | requirementsmod.SHARED_REQUIREMENT in requirements | |
569 | or requirementsmod.RELATIVE_SHARED_REQUIREMENT in requirements |
|
569 | or requirementsmod.RELATIVE_SHARED_REQUIREMENT in requirements | |
570 | ) |
|
570 | ) | |
571 | storevfs = None |
|
571 | storevfs = None | |
572 | if shared: |
|
572 | if shared: | |
573 | # This is a shared repo |
|
573 | # This is a shared repo | |
574 | sharedvfs = _getsharedvfs(hgvfs, requirements) |
|
574 | sharedvfs = _getsharedvfs(hgvfs, requirements) | |
575 | storevfs = vfsmod.vfs(sharedvfs.join(b'store')) |
|
575 | storevfs = vfsmod.vfs(sharedvfs.join(b'store')) | |
576 | else: |
|
576 | else: | |
577 | storevfs = vfsmod.vfs(hgvfs.join(b'store')) |
|
577 | storevfs = vfsmod.vfs(hgvfs.join(b'store')) | |
578 |
|
578 | |||
579 | # if .hg/requires contains the sharesafe requirement, it means |
|
579 | # if .hg/requires contains the sharesafe requirement, it means | |
580 | # there exists a `.hg/store/requires` too and we should read it |
|
580 | # there exists a `.hg/store/requires` too and we should read it | |
581 | # NOTE: presence of SHARESAFE_REQUIREMENT imply that store requirement |
|
581 | # NOTE: presence of SHARESAFE_REQUIREMENT imply that store requirement | |
582 | # is present. We never write SHARESAFE_REQUIREMENT for a repo if store |
|
582 | # is present. We never write SHARESAFE_REQUIREMENT for a repo if store | |
583 | # is not present, refer checkrequirementscompat() for that |
|
583 | # is not present, refer checkrequirementscompat() for that | |
584 | # |
|
584 | # | |
585 | # However, if SHARESAFE_REQUIREMENT is not present, it means that the |
|
585 | # However, if SHARESAFE_REQUIREMENT is not present, it means that the | |
586 | # repository was shared the old way. We check the share source .hg/requires |
|
586 | # repository was shared the old way. We check the share source .hg/requires | |
587 | # for SHARESAFE_REQUIREMENT to detect whether the current repository needs |
|
587 | # for SHARESAFE_REQUIREMENT to detect whether the current repository needs | |
588 | # to be reshared |
|
588 | # to be reshared | |
589 | hint = _(b"see `hg help config.format.use-share-safe` for more information") |
|
589 | hint = _(b"see `hg help config.format.use-share-safe` for more information") | |
590 | if requirementsmod.SHARESAFE_REQUIREMENT in requirements: |
|
590 | if requirementsmod.SHARESAFE_REQUIREMENT in requirements: | |
591 |
|
591 | |||
592 | if ( |
|
592 | if ( | |
593 | shared |
|
593 | shared | |
594 | and requirementsmod.SHARESAFE_REQUIREMENT |
|
594 | and requirementsmod.SHARESAFE_REQUIREMENT | |
595 | not in _readrequires(sharedvfs, True) |
|
595 | not in _readrequires(sharedvfs, True) | |
596 | ): |
|
596 | ): | |
597 | mismatch_warn = ui.configbool( |
|
597 | mismatch_warn = ui.configbool( | |
598 | b'share', b'safe-mismatch.source-not-safe.warn' |
|
598 | b'share', b'safe-mismatch.source-not-safe.warn' | |
599 | ) |
|
599 | ) | |
600 | mismatch_config = ui.config( |
|
600 | mismatch_config = ui.config( | |
601 | b'share', b'safe-mismatch.source-not-safe' |
|
601 | b'share', b'safe-mismatch.source-not-safe' | |
602 | ) |
|
602 | ) | |
603 | if mismatch_config in ( |
|
603 | if mismatch_config in ( | |
604 | b'downgrade-allow', |
|
604 | b'downgrade-allow', | |
605 | b'allow', |
|
605 | b'allow', | |
606 | b'downgrade-abort', |
|
606 | b'downgrade-abort', | |
607 | ): |
|
607 | ): | |
608 | # prevent cyclic import localrepo -> upgrade -> localrepo |
|
608 | # prevent cyclic import localrepo -> upgrade -> localrepo | |
609 | from . import upgrade |
|
609 | from . import upgrade | |
610 |
|
610 | |||
611 | upgrade.downgrade_share_to_non_safe( |
|
611 | upgrade.downgrade_share_to_non_safe( | |
612 | ui, |
|
612 | ui, | |
613 | hgvfs, |
|
613 | hgvfs, | |
614 | sharedvfs, |
|
614 | sharedvfs, | |
615 | requirements, |
|
615 | requirements, | |
616 | mismatch_config, |
|
616 | mismatch_config, | |
617 | mismatch_warn, |
|
617 | mismatch_warn, | |
618 | ) |
|
618 | ) | |
619 | elif mismatch_config == b'abort': |
|
619 | elif mismatch_config == b'abort': | |
620 | raise error.Abort( |
|
620 | raise error.Abort( | |
621 | _(b"share source does not support share-safe requirement"), |
|
621 | _(b"share source does not support share-safe requirement"), | |
622 | hint=hint, |
|
622 | hint=hint, | |
623 | ) |
|
623 | ) | |
624 | else: |
|
624 | else: | |
625 | raise error.Abort( |
|
625 | raise error.Abort( | |
626 | _( |
|
626 | _( | |
627 | b"share-safe mismatch with source.\nUnrecognized" |
|
627 | b"share-safe mismatch with source.\nUnrecognized" | |
628 | b" value '%s' of `share.safe-mismatch.source-not-safe`" |
|
628 | b" value '%s' of `share.safe-mismatch.source-not-safe`" | |
629 | b" set." |
|
629 | b" set." | |
630 | ) |
|
630 | ) | |
631 | % mismatch_config, |
|
631 | % mismatch_config, | |
632 | hint=hint, |
|
632 | hint=hint, | |
633 | ) |
|
633 | ) | |
634 | else: |
|
634 | else: | |
635 | requirements |= _readrequires(storevfs, False) |
|
635 | requirements |= _readrequires(storevfs, False) | |
636 | elif shared: |
|
636 | elif shared: | |
637 | sourcerequires = _readrequires(sharedvfs, False) |
|
637 | sourcerequires = _readrequires(sharedvfs, False) | |
638 | if requirementsmod.SHARESAFE_REQUIREMENT in sourcerequires: |
|
638 | if requirementsmod.SHARESAFE_REQUIREMENT in sourcerequires: | |
639 | mismatch_config = ui.config(b'share', b'safe-mismatch.source-safe') |
|
639 | mismatch_config = ui.config(b'share', b'safe-mismatch.source-safe') | |
640 | mismatch_warn = ui.configbool( |
|
640 | mismatch_warn = ui.configbool( | |
641 | b'share', b'safe-mismatch.source-safe.warn' |
|
641 | b'share', b'safe-mismatch.source-safe.warn' | |
642 | ) |
|
642 | ) | |
643 | if mismatch_config in ( |
|
643 | if mismatch_config in ( | |
644 | b'upgrade-allow', |
|
644 | b'upgrade-allow', | |
645 | b'allow', |
|
645 | b'allow', | |
646 | b'upgrade-abort', |
|
646 | b'upgrade-abort', | |
647 | ): |
|
647 | ): | |
648 | # prevent cyclic import localrepo -> upgrade -> localrepo |
|
648 | # prevent cyclic import localrepo -> upgrade -> localrepo | |
649 | from . import upgrade |
|
649 | from . import upgrade | |
650 |
|
650 | |||
651 | upgrade.upgrade_share_to_safe( |
|
651 | upgrade.upgrade_share_to_safe( | |
652 | ui, |
|
652 | ui, | |
653 | hgvfs, |
|
653 | hgvfs, | |
654 | storevfs, |
|
654 | storevfs, | |
655 | requirements, |
|
655 | requirements, | |
656 | mismatch_config, |
|
656 | mismatch_config, | |
657 | mismatch_warn, |
|
657 | mismatch_warn, | |
658 | ) |
|
658 | ) | |
659 | elif mismatch_config == b'abort': |
|
659 | elif mismatch_config == b'abort': | |
660 | raise error.Abort( |
|
660 | raise error.Abort( | |
661 | _( |
|
661 | _( | |
662 | b'version mismatch: source uses share-safe' |
|
662 | b'version mismatch: source uses share-safe' | |
663 | b' functionality while the current share does not' |
|
663 | b' functionality while the current share does not' | |
664 | ), |
|
664 | ), | |
665 | hint=hint, |
|
665 | hint=hint, | |
666 | ) |
|
666 | ) | |
667 | else: |
|
667 | else: | |
668 | raise error.Abort( |
|
668 | raise error.Abort( | |
669 | _( |
|
669 | _( | |
670 | b"share-safe mismatch with source.\nUnrecognized" |
|
670 | b"share-safe mismatch with source.\nUnrecognized" | |
671 | b" value '%s' of `share.safe-mismatch.source-safe` set." |
|
671 | b" value '%s' of `share.safe-mismatch.source-safe` set." | |
672 | ) |
|
672 | ) | |
673 | % mismatch_config, |
|
673 | % mismatch_config, | |
674 | hint=hint, |
|
674 | hint=hint, | |
675 | ) |
|
675 | ) | |
676 |
|
676 | |||
677 | # The .hg/hgrc file may load extensions or contain config options |
|
677 | # The .hg/hgrc file may load extensions or contain config options | |
678 | # that influence repository construction. Attempt to load it and |
|
678 | # that influence repository construction. Attempt to load it and | |
679 | # process any new extensions that it may have pulled in. |
|
679 | # process any new extensions that it may have pulled in. | |
680 | if loadhgrc(ui, wdirvfs, hgvfs, requirements, sharedvfs): |
|
680 | if loadhgrc(ui, wdirvfs, hgvfs, requirements, sharedvfs): | |
681 | afterhgrcload(ui, wdirvfs, hgvfs, requirements) |
|
681 | afterhgrcload(ui, wdirvfs, hgvfs, requirements) | |
682 | extensions.loadall(ui) |
|
682 | extensions.loadall(ui) | |
683 | extensions.populateui(ui) |
|
683 | extensions.populateui(ui) | |
684 |
|
684 | |||
685 | # Set of module names of extensions loaded for this repository. |
|
685 | # Set of module names of extensions loaded for this repository. | |
686 | extensionmodulenames = {m.__name__ for n, m in extensions.extensions(ui)} |
|
686 | extensionmodulenames = {m.__name__ for n, m in extensions.extensions(ui)} | |
687 |
|
687 | |||
688 | supportedrequirements = gathersupportedrequirements(ui) |
|
688 | supportedrequirements = gathersupportedrequirements(ui) | |
689 |
|
689 | |||
690 | # We first validate the requirements are known. |
|
690 | # We first validate the requirements are known. | |
691 | ensurerequirementsrecognized(requirements, supportedrequirements) |
|
691 | ensurerequirementsrecognized(requirements, supportedrequirements) | |
692 |
|
692 | |||
693 | # Then we validate that the known set is reasonable to use together. |
|
693 | # Then we validate that the known set is reasonable to use together. | |
694 | ensurerequirementscompatible(ui, requirements) |
|
694 | ensurerequirementscompatible(ui, requirements) | |
695 |
|
695 | |||
696 | # TODO there are unhandled edge cases related to opening repositories with |
|
696 | # TODO there are unhandled edge cases related to opening repositories with | |
697 | # shared storage. If storage is shared, we should also test for requirements |
|
697 | # shared storage. If storage is shared, we should also test for requirements | |
698 | # compatibility in the pointed-to repo. This entails loading the .hg/hgrc in |
|
698 | # compatibility in the pointed-to repo. This entails loading the .hg/hgrc in | |
699 | # that repo, as that repo may load extensions needed to open it. This is a |
|
699 | # that repo, as that repo may load extensions needed to open it. This is a | |
700 | # bit complicated because we don't want the other hgrc to overwrite settings |
|
700 | # bit complicated because we don't want the other hgrc to overwrite settings | |
701 | # in this hgrc. |
|
701 | # in this hgrc. | |
702 | # |
|
702 | # | |
703 | # This bug is somewhat mitigated by the fact that we copy the .hg/requires |
|
703 | # This bug is somewhat mitigated by the fact that we copy the .hg/requires | |
704 | # file when sharing repos. But if a requirement is added after the share is |
|
704 | # file when sharing repos. But if a requirement is added after the share is | |
705 | # performed, thereby introducing a new requirement for the opener, we may |
|
705 | # performed, thereby introducing a new requirement for the opener, we may | |
706 | # will not see that and could encounter a run-time error interacting with |
|
706 | # will not see that and could encounter a run-time error interacting with | |
707 | # that shared store since it has an unknown-to-us requirement. |
|
707 | # that shared store since it has an unknown-to-us requirement. | |
708 |
|
708 | |||
709 | # At this point, we know we should be capable of opening the repository. |
|
709 | # At this point, we know we should be capable of opening the repository. | |
710 | # Now get on with doing that. |
|
710 | # Now get on with doing that. | |
711 |
|
711 | |||
712 | features = set() |
|
712 | features = set() | |
713 |
|
713 | |||
714 | # The "store" part of the repository holds versioned data. How it is |
|
714 | # The "store" part of the repository holds versioned data. How it is | |
715 | # accessed is determined by various requirements. If `shared` or |
|
715 | # accessed is determined by various requirements. If `shared` or | |
716 | # `relshared` requirements are present, this indicates current repository |
|
716 | # `relshared` requirements are present, this indicates current repository | |
717 | # is a share and store exists in path mentioned in `.hg/sharedpath` |
|
717 | # is a share and store exists in path mentioned in `.hg/sharedpath` | |
718 | if shared: |
|
718 | if shared: | |
719 | storebasepath = sharedvfs.base |
|
719 | storebasepath = sharedvfs.base | |
720 | cachepath = sharedvfs.join(b'cache') |
|
720 | cachepath = sharedvfs.join(b'cache') | |
721 | features.add(repository.REPO_FEATURE_SHARED_STORAGE) |
|
721 | features.add(repository.REPO_FEATURE_SHARED_STORAGE) | |
722 | else: |
|
722 | else: | |
723 | storebasepath = hgvfs.base |
|
723 | storebasepath = hgvfs.base | |
724 | cachepath = hgvfs.join(b'cache') |
|
724 | cachepath = hgvfs.join(b'cache') | |
725 | wcachepath = hgvfs.join(b'wcache') |
|
725 | wcachepath = hgvfs.join(b'wcache') | |
726 |
|
726 | |||
727 | # The store has changed over time and the exact layout is dictated by |
|
727 | # The store has changed over time and the exact layout is dictated by | |
728 | # requirements. The store interface abstracts differences across all |
|
728 | # requirements. The store interface abstracts differences across all | |
729 | # of them. |
|
729 | # of them. | |
730 | store = makestore( |
|
730 | store = makestore( | |
731 | requirements, |
|
731 | requirements, | |
732 | storebasepath, |
|
732 | storebasepath, | |
733 | lambda base: vfsmod.vfs(base, cacheaudited=True), |
|
733 | lambda base: vfsmod.vfs(base, cacheaudited=True), | |
734 | ) |
|
734 | ) | |
735 | hgvfs.createmode = store.createmode |
|
735 | hgvfs.createmode = store.createmode | |
736 |
|
736 | |||
737 | storevfs = store.vfs |
|
737 | storevfs = store.vfs | |
738 | storevfs.options = resolvestorevfsoptions(ui, requirements, features) |
|
738 | storevfs.options = resolvestorevfsoptions(ui, requirements, features) | |
739 |
|
739 | |||
740 | # The cache vfs is used to manage cache files. |
|
740 | # The cache vfs is used to manage cache files. | |
741 | cachevfs = vfsmod.vfs(cachepath, cacheaudited=True) |
|
741 | cachevfs = vfsmod.vfs(cachepath, cacheaudited=True) | |
742 | cachevfs.createmode = store.createmode |
|
742 | cachevfs.createmode = store.createmode | |
743 | # The cache vfs is used to manage cache files related to the working copy |
|
743 | # The cache vfs is used to manage cache files related to the working copy | |
744 | wcachevfs = vfsmod.vfs(wcachepath, cacheaudited=True) |
|
744 | wcachevfs = vfsmod.vfs(wcachepath, cacheaudited=True) | |
745 | wcachevfs.createmode = store.createmode |
|
745 | wcachevfs.createmode = store.createmode | |
746 |
|
746 | |||
747 | # Now resolve the type for the repository object. We do this by repeatedly |
|
747 | # Now resolve the type for the repository object. We do this by repeatedly | |
748 | # calling a factory function to produces types for specific aspects of the |
|
748 | # calling a factory function to produces types for specific aspects of the | |
749 | # repo's operation. The aggregate returned types are used as base classes |
|
749 | # repo's operation. The aggregate returned types are used as base classes | |
750 | # for a dynamically-derived type, which will represent our new repository. |
|
750 | # for a dynamically-derived type, which will represent our new repository. | |
751 |
|
751 | |||
752 | bases = [] |
|
752 | bases = [] | |
753 | extrastate = {} |
|
753 | extrastate = {} | |
754 |
|
754 | |||
755 | for iface, fn in REPO_INTERFACES: |
|
755 | for iface, fn in REPO_INTERFACES: | |
756 | # We pass all potentially useful state to give extensions tons of |
|
756 | # We pass all potentially useful state to give extensions tons of | |
757 | # flexibility. |
|
757 | # flexibility. | |
758 | typ = fn()( |
|
758 | typ = fn()( | |
759 | ui=ui, |
|
759 | ui=ui, | |
760 | intents=intents, |
|
760 | intents=intents, | |
761 | requirements=requirements, |
|
761 | requirements=requirements, | |
762 | features=features, |
|
762 | features=features, | |
763 | wdirvfs=wdirvfs, |
|
763 | wdirvfs=wdirvfs, | |
764 | hgvfs=hgvfs, |
|
764 | hgvfs=hgvfs, | |
765 | store=store, |
|
765 | store=store, | |
766 | storevfs=storevfs, |
|
766 | storevfs=storevfs, | |
767 | storeoptions=storevfs.options, |
|
767 | storeoptions=storevfs.options, | |
768 | cachevfs=cachevfs, |
|
768 | cachevfs=cachevfs, | |
769 | wcachevfs=wcachevfs, |
|
769 | wcachevfs=wcachevfs, | |
770 | extensionmodulenames=extensionmodulenames, |
|
770 | extensionmodulenames=extensionmodulenames, | |
771 | extrastate=extrastate, |
|
771 | extrastate=extrastate, | |
772 | baseclasses=bases, |
|
772 | baseclasses=bases, | |
773 | ) |
|
773 | ) | |
774 |
|
774 | |||
775 | if not isinstance(typ, type): |
|
775 | if not isinstance(typ, type): | |
776 | raise error.ProgrammingError( |
|
776 | raise error.ProgrammingError( | |
777 | b'unable to construct type for %s' % iface |
|
777 | b'unable to construct type for %s' % iface | |
778 | ) |
|
778 | ) | |
779 |
|
779 | |||
780 | bases.append(typ) |
|
780 | bases.append(typ) | |
781 |
|
781 | |||
782 | # type() allows you to use characters in type names that wouldn't be |
|
782 | # type() allows you to use characters in type names that wouldn't be | |
783 | # recognized as Python symbols in source code. We abuse that to add |
|
783 | # recognized as Python symbols in source code. We abuse that to add | |
784 | # rich information about our constructed repo. |
|
784 | # rich information about our constructed repo. | |
785 | name = pycompat.sysstr( |
|
785 | name = pycompat.sysstr( | |
786 | b'derivedrepo:%s<%s>' % (wdirvfs.base, b','.join(sorted(requirements))) |
|
786 | b'derivedrepo:%s<%s>' % (wdirvfs.base, b','.join(sorted(requirements))) | |
787 | ) |
|
787 | ) | |
788 |
|
788 | |||
789 | cls = type(name, tuple(bases), {}) |
|
789 | cls = type(name, tuple(bases), {}) | |
790 |
|
790 | |||
791 | return cls( |
|
791 | return cls( | |
792 | baseui=baseui, |
|
792 | baseui=baseui, | |
793 | ui=ui, |
|
793 | ui=ui, | |
794 | origroot=path, |
|
794 | origroot=path, | |
795 | wdirvfs=wdirvfs, |
|
795 | wdirvfs=wdirvfs, | |
796 | hgvfs=hgvfs, |
|
796 | hgvfs=hgvfs, | |
797 | requirements=requirements, |
|
797 | requirements=requirements, | |
798 | supportedrequirements=supportedrequirements, |
|
798 | supportedrequirements=supportedrequirements, | |
799 | sharedpath=storebasepath, |
|
799 | sharedpath=storebasepath, | |
800 | store=store, |
|
800 | store=store, | |
801 | cachevfs=cachevfs, |
|
801 | cachevfs=cachevfs, | |
802 | wcachevfs=wcachevfs, |
|
802 | wcachevfs=wcachevfs, | |
803 | features=features, |
|
803 | features=features, | |
804 | intents=intents, |
|
804 | intents=intents, | |
805 | ) |
|
805 | ) | |
806 |
|
806 | |||
807 |
|
807 | |||
808 | def loadhgrc(ui, wdirvfs, hgvfs, requirements, sharedvfs=None): |
|
808 | def loadhgrc(ui, wdirvfs, hgvfs, requirements, sharedvfs=None): | |
809 | """Load hgrc files/content into a ui instance. |
|
809 | """Load hgrc files/content into a ui instance. | |
810 |
|
810 | |||
811 | This is called during repository opening to load any additional |
|
811 | This is called during repository opening to load any additional | |
812 | config files or settings relevant to the current repository. |
|
812 | config files or settings relevant to the current repository. | |
813 |
|
813 | |||
814 | Returns a bool indicating whether any additional configs were loaded. |
|
814 | Returns a bool indicating whether any additional configs were loaded. | |
815 |
|
815 | |||
816 | Extensions should monkeypatch this function to modify how per-repo |
|
816 | Extensions should monkeypatch this function to modify how per-repo | |
817 | configs are loaded. For example, an extension may wish to pull in |
|
817 | configs are loaded. For example, an extension may wish to pull in | |
818 | configs from alternate files or sources. |
|
818 | configs from alternate files or sources. | |
819 |
|
819 | |||
820 | sharedvfs is vfs object pointing to source repo if the current one is a |
|
820 | sharedvfs is vfs object pointing to source repo if the current one is a | |
821 | shared one |
|
821 | shared one | |
822 | """ |
|
822 | """ | |
823 | if not rcutil.use_repo_hgrc(): |
|
823 | if not rcutil.use_repo_hgrc(): | |
824 | return False |
|
824 | return False | |
825 |
|
825 | |||
826 | ret = False |
|
826 | ret = False | |
827 | # first load config from shared source if we has to |
|
827 | # first load config from shared source if we has to | |
828 | if requirementsmod.SHARESAFE_REQUIREMENT in requirements and sharedvfs: |
|
828 | if requirementsmod.SHARESAFE_REQUIREMENT in requirements and sharedvfs: | |
829 | try: |
|
829 | try: | |
830 | ui.readconfig(sharedvfs.join(b'hgrc'), root=sharedvfs.base) |
|
830 | ui.readconfig(sharedvfs.join(b'hgrc'), root=sharedvfs.base) | |
831 | ret = True |
|
831 | ret = True | |
832 | except IOError: |
|
832 | except IOError: | |
833 | pass |
|
833 | pass | |
834 |
|
834 | |||
835 | try: |
|
835 | try: | |
836 | ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) |
|
836 | ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) | |
837 | ret = True |
|
837 | ret = True | |
838 | except IOError: |
|
838 | except IOError: | |
839 | pass |
|
839 | pass | |
840 |
|
840 | |||
841 | try: |
|
841 | try: | |
842 | ui.readconfig(hgvfs.join(b'hgrc-not-shared'), root=wdirvfs.base) |
|
842 | ui.readconfig(hgvfs.join(b'hgrc-not-shared'), root=wdirvfs.base) | |
843 | ret = True |
|
843 | ret = True | |
844 | except IOError: |
|
844 | except IOError: | |
845 | pass |
|
845 | pass | |
846 |
|
846 | |||
847 | return ret |
|
847 | return ret | |
848 |
|
848 | |||
849 |
|
849 | |||
850 | def afterhgrcload(ui, wdirvfs, hgvfs, requirements): |
|
850 | def afterhgrcload(ui, wdirvfs, hgvfs, requirements): | |
851 | """Perform additional actions after .hg/hgrc is loaded. |
|
851 | """Perform additional actions after .hg/hgrc is loaded. | |
852 |
|
852 | |||
853 | This function is called during repository loading immediately after |
|
853 | This function is called during repository loading immediately after | |
854 | the .hg/hgrc file is loaded and before per-repo extensions are loaded. |
|
854 | the .hg/hgrc file is loaded and before per-repo extensions are loaded. | |
855 |
|
855 | |||
856 | The function can be used to validate configs, automatically add |
|
856 | The function can be used to validate configs, automatically add | |
857 | options (including extensions) based on requirements, etc. |
|
857 | options (including extensions) based on requirements, etc. | |
858 | """ |
|
858 | """ | |
859 |
|
859 | |||
860 | # Map of requirements to list of extensions to load automatically when |
|
860 | # Map of requirements to list of extensions to load automatically when | |
861 | # requirement is present. |
|
861 | # requirement is present. | |
862 | autoextensions = { |
|
862 | autoextensions = { | |
863 | b'git': [b'git'], |
|
863 | b'git': [b'git'], | |
864 | b'largefiles': [b'largefiles'], |
|
864 | b'largefiles': [b'largefiles'], | |
865 | b'lfs': [b'lfs'], |
|
865 | b'lfs': [b'lfs'], | |
866 | } |
|
866 | } | |
867 |
|
867 | |||
868 | for requirement, names in sorted(autoextensions.items()): |
|
868 | for requirement, names in sorted(autoextensions.items()): | |
869 | if requirement not in requirements: |
|
869 | if requirement not in requirements: | |
870 | continue |
|
870 | continue | |
871 |
|
871 | |||
872 | for name in names: |
|
872 | for name in names: | |
873 | if not ui.hasconfig(b'extensions', name): |
|
873 | if not ui.hasconfig(b'extensions', name): | |
874 | ui.setconfig(b'extensions', name, b'', source=b'autoload') |
|
874 | ui.setconfig(b'extensions', name, b'', source=b'autoload') | |
875 |
|
875 | |||
876 |
|
876 | |||
877 | def gathersupportedrequirements(ui): |
|
877 | def gathersupportedrequirements(ui): | |
878 | """Determine the complete set of recognized requirements.""" |
|
878 | """Determine the complete set of recognized requirements.""" | |
879 | # Start with all requirements supported by this file. |
|
879 | # Start with all requirements supported by this file. | |
880 | supported = set(localrepository._basesupported) |
|
880 | supported = set(localrepository._basesupported) | |
881 |
|
881 | |||
882 | # Execute ``featuresetupfuncs`` entries if they belong to an extension |
|
882 | # Execute ``featuresetupfuncs`` entries if they belong to an extension | |
883 | # relevant to this ui instance. |
|
883 | # relevant to this ui instance. | |
884 | modules = {m.__name__ for n, m in extensions.extensions(ui)} |
|
884 | modules = {m.__name__ for n, m in extensions.extensions(ui)} | |
885 |
|
885 | |||
886 | for fn in featuresetupfuncs: |
|
886 | for fn in featuresetupfuncs: | |
887 | if fn.__module__ in modules: |
|
887 | if fn.__module__ in modules: | |
888 | fn(ui, supported) |
|
888 | fn(ui, supported) | |
889 |
|
889 | |||
890 | # Add derived requirements from registered compression engines. |
|
890 | # Add derived requirements from registered compression engines. | |
891 | for name in util.compengines: |
|
891 | for name in util.compengines: | |
892 | engine = util.compengines[name] |
|
892 | engine = util.compengines[name] | |
893 | if engine.available() and engine.revlogheader(): |
|
893 | if engine.available() and engine.revlogheader(): | |
894 | supported.add(b'exp-compression-%s' % name) |
|
894 | supported.add(b'exp-compression-%s' % name) | |
895 | if engine.name() == b'zstd': |
|
895 | if engine.name() == b'zstd': | |
896 | supported.add(b'revlog-compression-zstd') |
|
896 | supported.add(b'revlog-compression-zstd') | |
897 |
|
897 | |||
898 | return supported |
|
898 | return supported | |
899 |
|
899 | |||
900 |
|
900 | |||
901 | def ensurerequirementsrecognized(requirements, supported): |
|
901 | def ensurerequirementsrecognized(requirements, supported): | |
902 | """Validate that a set of local requirements is recognized. |
|
902 | """Validate that a set of local requirements is recognized. | |
903 |
|
903 | |||
904 | Receives a set of requirements. Raises an ``error.RepoError`` if there |
|
904 | Receives a set of requirements. Raises an ``error.RepoError`` if there | |
905 | exists any requirement in that set that currently loaded code doesn't |
|
905 | exists any requirement in that set that currently loaded code doesn't | |
906 | recognize. |
|
906 | recognize. | |
907 |
|
907 | |||
908 | Returns a set of supported requirements. |
|
908 | Returns a set of supported requirements. | |
909 | """ |
|
909 | """ | |
910 | missing = set() |
|
910 | missing = set() | |
911 |
|
911 | |||
912 | for requirement in requirements: |
|
912 | for requirement in requirements: | |
913 | if requirement in supported: |
|
913 | if requirement in supported: | |
914 | continue |
|
914 | continue | |
915 |
|
915 | |||
916 | if not requirement or not requirement[0:1].isalnum(): |
|
916 | if not requirement or not requirement[0:1].isalnum(): | |
917 | raise error.RequirementError(_(b'.hg/requires file is corrupt')) |
|
917 | raise error.RequirementError(_(b'.hg/requires file is corrupt')) | |
918 |
|
918 | |||
919 | missing.add(requirement) |
|
919 | missing.add(requirement) | |
920 |
|
920 | |||
921 | if missing: |
|
921 | if missing: | |
922 | raise error.RequirementError( |
|
922 | raise error.RequirementError( | |
923 | _(b'repository requires features unknown to this Mercurial: %s') |
|
923 | _(b'repository requires features unknown to this Mercurial: %s') | |
924 | % b' '.join(sorted(missing)), |
|
924 | % b' '.join(sorted(missing)), | |
925 | hint=_( |
|
925 | hint=_( | |
926 | b'see https://mercurial-scm.org/wiki/MissingRequirement ' |
|
926 | b'see https://mercurial-scm.org/wiki/MissingRequirement ' | |
927 | b'for more information' |
|
927 | b'for more information' | |
928 | ), |
|
928 | ), | |
929 | ) |
|
929 | ) | |
930 |
|
930 | |||
931 |
|
931 | |||
932 | def ensurerequirementscompatible(ui, requirements): |
|
932 | def ensurerequirementscompatible(ui, requirements): | |
933 | """Validates that a set of recognized requirements is mutually compatible. |
|
933 | """Validates that a set of recognized requirements is mutually compatible. | |
934 |
|
934 | |||
935 | Some requirements may not be compatible with others or require |
|
935 | Some requirements may not be compatible with others or require | |
936 | config options that aren't enabled. This function is called during |
|
936 | config options that aren't enabled. This function is called during | |
937 | repository opening to ensure that the set of requirements needed |
|
937 | repository opening to ensure that the set of requirements needed | |
938 | to open a repository is sane and compatible with config options. |
|
938 | to open a repository is sane and compatible with config options. | |
939 |
|
939 | |||
940 | Extensions can monkeypatch this function to perform additional |
|
940 | Extensions can monkeypatch this function to perform additional | |
941 | checking. |
|
941 | checking. | |
942 |
|
942 | |||
943 | ``error.RepoError`` should be raised on failure. |
|
943 | ``error.RepoError`` should be raised on failure. | |
944 | """ |
|
944 | """ | |
945 | if ( |
|
945 | if ( | |
946 | requirementsmod.SPARSE_REQUIREMENT in requirements |
|
946 | requirementsmod.SPARSE_REQUIREMENT in requirements | |
947 | and not sparse.enabled |
|
947 | and not sparse.enabled | |
948 | ): |
|
948 | ): | |
949 | raise error.RepoError( |
|
949 | raise error.RepoError( | |
950 | _( |
|
950 | _( | |
951 | b'repository is using sparse feature but ' |
|
951 | b'repository is using sparse feature but ' | |
952 | b'sparse is not enabled; enable the ' |
|
952 | b'sparse is not enabled; enable the ' | |
953 | b'"sparse" extensions to access' |
|
953 | b'"sparse" extensions to access' | |
954 | ) |
|
954 | ) | |
955 | ) |
|
955 | ) | |
956 |
|
956 | |||
957 |
|
957 | |||
958 | def makestore(requirements, path, vfstype): |
|
958 | def makestore(requirements, path, vfstype): | |
959 | """Construct a storage object for a repository.""" |
|
959 | """Construct a storage object for a repository.""" | |
960 | if requirementsmod.STORE_REQUIREMENT in requirements: |
|
960 | if requirementsmod.STORE_REQUIREMENT in requirements: | |
961 | if requirementsmod.FNCACHE_REQUIREMENT in requirements: |
|
961 | if requirementsmod.FNCACHE_REQUIREMENT in requirements: | |
962 | dotencode = requirementsmod.DOTENCODE_REQUIREMENT in requirements |
|
962 | dotencode = requirementsmod.DOTENCODE_REQUIREMENT in requirements | |
963 | return storemod.fncachestore(path, vfstype, dotencode) |
|
963 | return storemod.fncachestore(path, vfstype, dotencode) | |
964 |
|
964 | |||
965 | return storemod.encodedstore(path, vfstype) |
|
965 | return storemod.encodedstore(path, vfstype) | |
966 |
|
966 | |||
967 | return storemod.basicstore(path, vfstype) |
|
967 | return storemod.basicstore(path, vfstype) | |
968 |
|
968 | |||
969 |
|
969 | |||
970 | def resolvestorevfsoptions(ui, requirements, features): |
|
970 | def resolvestorevfsoptions(ui, requirements, features): | |
971 | """Resolve the options to pass to the store vfs opener. |
|
971 | """Resolve the options to pass to the store vfs opener. | |
972 |
|
972 | |||
973 | The returned dict is used to influence behavior of the storage layer. |
|
973 | The returned dict is used to influence behavior of the storage layer. | |
974 | """ |
|
974 | """ | |
975 | options = {} |
|
975 | options = {} | |
976 |
|
976 | |||
977 | if requirementsmod.TREEMANIFEST_REQUIREMENT in requirements: |
|
977 | if requirementsmod.TREEMANIFEST_REQUIREMENT in requirements: | |
978 | options[b'treemanifest'] = True |
|
978 | options[b'treemanifest'] = True | |
979 |
|
979 | |||
980 | # experimental config: format.manifestcachesize |
|
980 | # experimental config: format.manifestcachesize | |
981 | manifestcachesize = ui.configint(b'format', b'manifestcachesize') |
|
981 | manifestcachesize = ui.configint(b'format', b'manifestcachesize') | |
982 | if manifestcachesize is not None: |
|
982 | if manifestcachesize is not None: | |
983 | options[b'manifestcachesize'] = manifestcachesize |
|
983 | options[b'manifestcachesize'] = manifestcachesize | |
984 |
|
984 | |||
985 | # In the absence of another requirement superseding a revlog-related |
|
985 | # In the absence of another requirement superseding a revlog-related | |
986 | # requirement, we have to assume the repo is using revlog version 0. |
|
986 | # requirement, we have to assume the repo is using revlog version 0. | |
987 | # This revlog format is super old and we don't bother trying to parse |
|
987 | # This revlog format is super old and we don't bother trying to parse | |
988 | # opener options for it because those options wouldn't do anything |
|
988 | # opener options for it because those options wouldn't do anything | |
989 | # meaningful on such old repos. |
|
989 | # meaningful on such old repos. | |
990 | if ( |
|
990 | if ( | |
991 | requirementsmod.REVLOGV1_REQUIREMENT in requirements |
|
991 | requirementsmod.REVLOGV1_REQUIREMENT in requirements | |
992 | or requirementsmod.REVLOGV2_REQUIREMENT in requirements |
|
992 | or requirementsmod.REVLOGV2_REQUIREMENT in requirements | |
993 | ): |
|
993 | ): | |
994 | options.update(resolverevlogstorevfsoptions(ui, requirements, features)) |
|
994 | options.update(resolverevlogstorevfsoptions(ui, requirements, features)) | |
995 | else: # explicitly mark repo as using revlogv0 |
|
995 | else: # explicitly mark repo as using revlogv0 | |
996 | options[b'revlogv0'] = True |
|
996 | options[b'revlogv0'] = True | |
997 |
|
997 | |||
998 | if requirementsmod.COPIESSDC_REQUIREMENT in requirements: |
|
998 | if requirementsmod.COPIESSDC_REQUIREMENT in requirements: | |
999 | options[b'copies-storage'] = b'changeset-sidedata' |
|
999 | options[b'copies-storage'] = b'changeset-sidedata' | |
1000 | else: |
|
1000 | else: | |
1001 | writecopiesto = ui.config(b'experimental', b'copies.write-to') |
|
1001 | writecopiesto = ui.config(b'experimental', b'copies.write-to') | |
1002 | copiesextramode = (b'changeset-only', b'compatibility') |
|
1002 | copiesextramode = (b'changeset-only', b'compatibility') | |
1003 | if writecopiesto in copiesextramode: |
|
1003 | if writecopiesto in copiesextramode: | |
1004 | options[b'copies-storage'] = b'extra' |
|
1004 | options[b'copies-storage'] = b'extra' | |
1005 |
|
1005 | |||
1006 | return options |
|
1006 | return options | |
1007 |
|
1007 | |||
1008 |
|
1008 | |||
1009 | def resolverevlogstorevfsoptions(ui, requirements, features): |
|
1009 | def resolverevlogstorevfsoptions(ui, requirements, features): | |
1010 | """Resolve opener options specific to revlogs.""" |
|
1010 | """Resolve opener options specific to revlogs.""" | |
1011 |
|
1011 | |||
1012 | options = {} |
|
1012 | options = {} | |
1013 | options[b'flagprocessors'] = {} |
|
1013 | options[b'flagprocessors'] = {} | |
1014 |
|
1014 | |||
1015 | if requirementsmod.REVLOGV1_REQUIREMENT in requirements: |
|
1015 | if requirementsmod.REVLOGV1_REQUIREMENT in requirements: | |
1016 | options[b'revlogv1'] = True |
|
1016 | options[b'revlogv1'] = True | |
1017 | if requirementsmod.REVLOGV2_REQUIREMENT in requirements: |
|
1017 | if requirementsmod.REVLOGV2_REQUIREMENT in requirements: | |
1018 | options[b'revlogv2'] = True |
|
1018 | options[b'revlogv2'] = True | |
1019 |
|
1019 | |||
1020 | if requirementsmod.GENERALDELTA_REQUIREMENT in requirements: |
|
1020 | if requirementsmod.GENERALDELTA_REQUIREMENT in requirements: | |
1021 | options[b'generaldelta'] = True |
|
1021 | options[b'generaldelta'] = True | |
1022 |
|
1022 | |||
1023 | # experimental config: format.chunkcachesize |
|
1023 | # experimental config: format.chunkcachesize | |
1024 | chunkcachesize = ui.configint(b'format', b'chunkcachesize') |
|
1024 | chunkcachesize = ui.configint(b'format', b'chunkcachesize') | |
1025 | if chunkcachesize is not None: |
|
1025 | if chunkcachesize is not None: | |
1026 | options[b'chunkcachesize'] = chunkcachesize |
|
1026 | options[b'chunkcachesize'] = chunkcachesize | |
1027 |
|
1027 | |||
1028 | deltabothparents = ui.configbool( |
|
1028 | deltabothparents = ui.configbool( | |
1029 | b'storage', b'revlog.optimize-delta-parent-choice' |
|
1029 | b'storage', b'revlog.optimize-delta-parent-choice' | |
1030 | ) |
|
1030 | ) | |
1031 | options[b'deltabothparents'] = deltabothparents |
|
1031 | options[b'deltabothparents'] = deltabothparents | |
1032 |
|
1032 | |||
1033 | lazydelta = ui.configbool(b'storage', b'revlog.reuse-external-delta') |
|
1033 | lazydelta = ui.configbool(b'storage', b'revlog.reuse-external-delta') | |
1034 | lazydeltabase = False |
|
1034 | lazydeltabase = False | |
1035 | if lazydelta: |
|
1035 | if lazydelta: | |
1036 | lazydeltabase = ui.configbool( |
|
1036 | lazydeltabase = ui.configbool( | |
1037 | b'storage', b'revlog.reuse-external-delta-parent' |
|
1037 | b'storage', b'revlog.reuse-external-delta-parent' | |
1038 | ) |
|
1038 | ) | |
1039 | if lazydeltabase is None: |
|
1039 | if lazydeltabase is None: | |
1040 | lazydeltabase = not scmutil.gddeltaconfig(ui) |
|
1040 | lazydeltabase = not scmutil.gddeltaconfig(ui) | |
1041 | options[b'lazydelta'] = lazydelta |
|
1041 | options[b'lazydelta'] = lazydelta | |
1042 | options[b'lazydeltabase'] = lazydeltabase |
|
1042 | options[b'lazydeltabase'] = lazydeltabase | |
1043 |
|
1043 | |||
1044 | chainspan = ui.configbytes(b'experimental', b'maxdeltachainspan') |
|
1044 | chainspan = ui.configbytes(b'experimental', b'maxdeltachainspan') | |
1045 | if 0 <= chainspan: |
|
1045 | if 0 <= chainspan: | |
1046 | options[b'maxdeltachainspan'] = chainspan |
|
1046 | options[b'maxdeltachainspan'] = chainspan | |
1047 |
|
1047 | |||
1048 | mmapindexthreshold = ui.configbytes(b'experimental', b'mmapindexthreshold') |
|
1048 | mmapindexthreshold = ui.configbytes(b'experimental', b'mmapindexthreshold') | |
1049 | if mmapindexthreshold is not None: |
|
1049 | if mmapindexthreshold is not None: | |
1050 | options[b'mmapindexthreshold'] = mmapindexthreshold |
|
1050 | options[b'mmapindexthreshold'] = mmapindexthreshold | |
1051 |
|
1051 | |||
1052 | withsparseread = ui.configbool(b'experimental', b'sparse-read') |
|
1052 | withsparseread = ui.configbool(b'experimental', b'sparse-read') | |
1053 | srdensitythres = float( |
|
1053 | srdensitythres = float( | |
1054 | ui.config(b'experimental', b'sparse-read.density-threshold') |
|
1054 | ui.config(b'experimental', b'sparse-read.density-threshold') | |
1055 | ) |
|
1055 | ) | |
1056 | srmingapsize = ui.configbytes(b'experimental', b'sparse-read.min-gap-size') |
|
1056 | srmingapsize = ui.configbytes(b'experimental', b'sparse-read.min-gap-size') | |
1057 | options[b'with-sparse-read'] = withsparseread |
|
1057 | options[b'with-sparse-read'] = withsparseread | |
1058 | options[b'sparse-read-density-threshold'] = srdensitythres |
|
1058 | options[b'sparse-read-density-threshold'] = srdensitythres | |
1059 | options[b'sparse-read-min-gap-size'] = srmingapsize |
|
1059 | options[b'sparse-read-min-gap-size'] = srmingapsize | |
1060 |
|
1060 | |||
1061 | sparserevlog = requirementsmod.SPARSEREVLOG_REQUIREMENT in requirements |
|
1061 | sparserevlog = requirementsmod.SPARSEREVLOG_REQUIREMENT in requirements | |
1062 | options[b'sparse-revlog'] = sparserevlog |
|
1062 | options[b'sparse-revlog'] = sparserevlog | |
1063 | if sparserevlog: |
|
1063 | if sparserevlog: | |
1064 | options[b'generaldelta'] = True |
|
1064 | options[b'generaldelta'] = True | |
1065 |
|
1065 | |||
1066 | sidedata = requirementsmod.SIDEDATA_REQUIREMENT in requirements |
|
1066 | sidedata = requirementsmod.SIDEDATA_REQUIREMENT in requirements | |
1067 | options[b'side-data'] = sidedata |
|
1067 | options[b'side-data'] = sidedata | |
1068 |
|
1068 | |||
1069 | maxchainlen = None |
|
1069 | maxchainlen = None | |
1070 | if sparserevlog: |
|
1070 | if sparserevlog: | |
1071 | maxchainlen = revlogconst.SPARSE_REVLOG_MAX_CHAIN_LENGTH |
|
1071 | maxchainlen = revlogconst.SPARSE_REVLOG_MAX_CHAIN_LENGTH | |
1072 | # experimental config: format.maxchainlen |
|
1072 | # experimental config: format.maxchainlen | |
1073 | maxchainlen = ui.configint(b'format', b'maxchainlen', maxchainlen) |
|
1073 | maxchainlen = ui.configint(b'format', b'maxchainlen', maxchainlen) | |
1074 | if maxchainlen is not None: |
|
1074 | if maxchainlen is not None: | |
1075 | options[b'maxchainlen'] = maxchainlen |
|
1075 | options[b'maxchainlen'] = maxchainlen | |
1076 |
|
1076 | |||
1077 | for r in requirements: |
|
1077 | for r in requirements: | |
1078 | # we allow multiple compression engine requirement to co-exist because |
|
1078 | # we allow multiple compression engine requirement to co-exist because | |
1079 | # strickly speaking, revlog seems to support mixed compression style. |
|
1079 | # strickly speaking, revlog seems to support mixed compression style. | |
1080 | # |
|
1080 | # | |
1081 | # The compression used for new entries will be "the last one" |
|
1081 | # The compression used for new entries will be "the last one" | |
1082 | prefix = r.startswith |
|
1082 | prefix = r.startswith | |
1083 | if prefix(b'revlog-compression-') or prefix(b'exp-compression-'): |
|
1083 | if prefix(b'revlog-compression-') or prefix(b'exp-compression-'): | |
1084 | options[b'compengine'] = r.split(b'-', 2)[2] |
|
1084 | options[b'compengine'] = r.split(b'-', 2)[2] | |
1085 |
|
1085 | |||
1086 | options[b'zlib.level'] = ui.configint(b'storage', b'revlog.zlib.level') |
|
1086 | options[b'zlib.level'] = ui.configint(b'storage', b'revlog.zlib.level') | |
1087 | if options[b'zlib.level'] is not None: |
|
1087 | if options[b'zlib.level'] is not None: | |
1088 | if not (0 <= options[b'zlib.level'] <= 9): |
|
1088 | if not (0 <= options[b'zlib.level'] <= 9): | |
1089 | msg = _(b'invalid value for `storage.revlog.zlib.level` config: %d') |
|
1089 | msg = _(b'invalid value for `storage.revlog.zlib.level` config: %d') | |
1090 | raise error.Abort(msg % options[b'zlib.level']) |
|
1090 | raise error.Abort(msg % options[b'zlib.level']) | |
1091 | options[b'zstd.level'] = ui.configint(b'storage', b'revlog.zstd.level') |
|
1091 | options[b'zstd.level'] = ui.configint(b'storage', b'revlog.zstd.level') | |
1092 | if options[b'zstd.level'] is not None: |
|
1092 | if options[b'zstd.level'] is not None: | |
1093 | if not (0 <= options[b'zstd.level'] <= 22): |
|
1093 | if not (0 <= options[b'zstd.level'] <= 22): | |
1094 | msg = _(b'invalid value for `storage.revlog.zstd.level` config: %d') |
|
1094 | msg = _(b'invalid value for `storage.revlog.zstd.level` config: %d') | |
1095 | raise error.Abort(msg % options[b'zstd.level']) |
|
1095 | raise error.Abort(msg % options[b'zstd.level']) | |
1096 |
|
1096 | |||
1097 | if requirementsmod.NARROW_REQUIREMENT in requirements: |
|
1097 | if requirementsmod.NARROW_REQUIREMENT in requirements: | |
1098 | options[b'enableellipsis'] = True |
|
1098 | options[b'enableellipsis'] = True | |
1099 |
|
1099 | |||
1100 | if ui.configbool(b'experimental', b'rust.index'): |
|
1100 | if ui.configbool(b'experimental', b'rust.index'): | |
1101 | options[b'rust.index'] = True |
|
1101 | options[b'rust.index'] = True | |
1102 | if requirementsmod.NODEMAP_REQUIREMENT in requirements: |
|
1102 | if requirementsmod.NODEMAP_REQUIREMENT in requirements: | |
1103 | slow_path = ui.config( |
|
1103 | slow_path = ui.config( | |
1104 | b'storage', b'revlog.persistent-nodemap.slow-path' |
|
1104 | b'storage', b'revlog.persistent-nodemap.slow-path' | |
1105 | ) |
|
1105 | ) | |
1106 | if slow_path not in (b'allow', b'warn', b'abort'): |
|
1106 | if slow_path not in (b'allow', b'warn', b'abort'): | |
1107 | default = ui.config_default( |
|
1107 | default = ui.config_default( | |
1108 | b'storage', b'revlog.persistent-nodemap.slow-path' |
|
1108 | b'storage', b'revlog.persistent-nodemap.slow-path' | |
1109 | ) |
|
1109 | ) | |
1110 | msg = _( |
|
1110 | msg = _( | |
1111 | b'unknown value for config ' |
|
1111 | b'unknown value for config ' | |
1112 | b'"storage.revlog.persistent-nodemap.slow-path": "%s"\n' |
|
1112 | b'"storage.revlog.persistent-nodemap.slow-path": "%s"\n' | |
1113 | ) |
|
1113 | ) | |
1114 | ui.warn(msg % slow_path) |
|
1114 | ui.warn(msg % slow_path) | |
1115 | if not ui.quiet: |
|
1115 | if not ui.quiet: | |
1116 | ui.warn(_(b'falling back to default value: %s\n') % default) |
|
1116 | ui.warn(_(b'falling back to default value: %s\n') % default) | |
1117 | slow_path = default |
|
1117 | slow_path = default | |
1118 |
|
1118 | |||
1119 | msg = _( |
|
1119 | msg = _( | |
1120 | b"accessing `persistent-nodemap` repository without associated " |
|
1120 | b"accessing `persistent-nodemap` repository without associated " | |
1121 | b"fast implementation." |
|
1121 | b"fast implementation." | |
1122 | ) |
|
1122 | ) | |
1123 | hint = _( |
|
1123 | hint = _( | |
1124 | b"check `hg help config.format.use-persistent-nodemap` " |
|
1124 | b"check `hg help config.format.use-persistent-nodemap` " | |
1125 | b"for details" |
|
1125 | b"for details" | |
1126 | ) |
|
1126 | ) | |
1127 | if not revlog.HAS_FAST_PERSISTENT_NODEMAP: |
|
1127 | if not revlog.HAS_FAST_PERSISTENT_NODEMAP: | |
1128 | if slow_path == b'warn': |
|
1128 | if slow_path == b'warn': | |
1129 | msg = b"warning: " + msg + b'\n' |
|
1129 | msg = b"warning: " + msg + b'\n' | |
1130 | ui.warn(msg) |
|
1130 | ui.warn(msg) | |
1131 | if not ui.quiet: |
|
1131 | if not ui.quiet: | |
1132 | hint = b'(' + hint + b')\n' |
|
1132 | hint = b'(' + hint + b')\n' | |
1133 | ui.warn(hint) |
|
1133 | ui.warn(hint) | |
1134 | if slow_path == b'abort': |
|
1134 | if slow_path == b'abort': | |
1135 | raise error.Abort(msg, hint=hint) |
|
1135 | raise error.Abort(msg, hint=hint) | |
1136 | options[b'persistent-nodemap'] = True |
|
1136 | options[b'persistent-nodemap'] = True | |
1137 | if ui.configbool(b'storage', b'revlog.persistent-nodemap.mmap'): |
|
1137 | if ui.configbool(b'storage', b'revlog.persistent-nodemap.mmap'): | |
1138 | options[b'persistent-nodemap.mmap'] = True |
|
1138 | options[b'persistent-nodemap.mmap'] = True | |
1139 | if ui.configbool(b'devel', b'persistent-nodemap'): |
|
1139 | if ui.configbool(b'devel', b'persistent-nodemap'): | |
1140 | options[b'devel-force-nodemap'] = True |
|
1140 | options[b'devel-force-nodemap'] = True | |
1141 |
|
1141 | |||
1142 | return options |
|
1142 | return options | |
1143 |
|
1143 | |||
1144 |
|
1144 | |||
1145 | def makemain(**kwargs): |
|
1145 | def makemain(**kwargs): | |
1146 | """Produce a type conforming to ``ilocalrepositorymain``.""" |
|
1146 | """Produce a type conforming to ``ilocalrepositorymain``.""" | |
1147 | return localrepository |
|
1147 | return localrepository | |
1148 |
|
1148 | |||
1149 |
|
1149 | |||
1150 | @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) |
|
1150 | @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) | |
1151 | class revlogfilestorage(object): |
|
1151 | class revlogfilestorage(object): | |
1152 | """File storage when using revlogs.""" |
|
1152 | """File storage when using revlogs.""" | |
1153 |
|
1153 | |||
1154 | def file(self, path): |
|
1154 | def file(self, path): | |
1155 | if path.startswith(b'/'): |
|
1155 | if path.startswith(b'/'): | |
1156 | path = path[1:] |
|
1156 | path = path[1:] | |
1157 |
|
1157 | |||
1158 | return filelog.filelog(self.svfs, path) |
|
1158 | return filelog.filelog(self.svfs, path) | |
1159 |
|
1159 | |||
1160 |
|
1160 | |||
1161 | @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) |
|
1161 | @interfaceutil.implementer(repository.ilocalrepositoryfilestorage) | |
1162 | class revlognarrowfilestorage(object): |
|
1162 | class revlognarrowfilestorage(object): | |
1163 | """File storage when using revlogs and narrow files.""" |
|
1163 | """File storage when using revlogs and narrow files.""" | |
1164 |
|
1164 | |||
1165 | def file(self, path): |
|
1165 | def file(self, path): | |
1166 | if path.startswith(b'/'): |
|
1166 | if path.startswith(b'/'): | |
1167 | path = path[1:] |
|
1167 | path = path[1:] | |
1168 |
|
1168 | |||
1169 | return filelog.narrowfilelog(self.svfs, path, self._storenarrowmatch) |
|
1169 | return filelog.narrowfilelog(self.svfs, path, self._storenarrowmatch) | |
1170 |
|
1170 | |||
1171 |
|
1171 | |||
1172 | def makefilestorage(requirements, features, **kwargs): |
|
1172 | def makefilestorage(requirements, features, **kwargs): | |
1173 | """Produce a type conforming to ``ilocalrepositoryfilestorage``.""" |
|
1173 | """Produce a type conforming to ``ilocalrepositoryfilestorage``.""" | |
1174 | features.add(repository.REPO_FEATURE_REVLOG_FILE_STORAGE) |
|
1174 | features.add(repository.REPO_FEATURE_REVLOG_FILE_STORAGE) | |
1175 | features.add(repository.REPO_FEATURE_STREAM_CLONE) |
|
1175 | features.add(repository.REPO_FEATURE_STREAM_CLONE) | |
1176 |
|
1176 | |||
1177 | if requirementsmod.NARROW_REQUIREMENT in requirements: |
|
1177 | if requirementsmod.NARROW_REQUIREMENT in requirements: | |
1178 | return revlognarrowfilestorage |
|
1178 | return revlognarrowfilestorage | |
1179 | else: |
|
1179 | else: | |
1180 | return revlogfilestorage |
|
1180 | return revlogfilestorage | |
1181 |
|
1181 | |||
1182 |
|
1182 | |||
1183 | # List of repository interfaces and factory functions for them. Each |
|
1183 | # List of repository interfaces and factory functions for them. Each | |
1184 | # will be called in order during ``makelocalrepository()`` to iteratively |
|
1184 | # will be called in order during ``makelocalrepository()`` to iteratively | |
1185 | # derive the final type for a local repository instance. We capture the |
|
1185 | # derive the final type for a local repository instance. We capture the | |
1186 | # function as a lambda so we don't hold a reference and the module-level |
|
1186 | # function as a lambda so we don't hold a reference and the module-level | |
1187 | # functions can be wrapped. |
|
1187 | # functions can be wrapped. | |
1188 | REPO_INTERFACES = [ |
|
1188 | REPO_INTERFACES = [ | |
1189 | (repository.ilocalrepositorymain, lambda: makemain), |
|
1189 | (repository.ilocalrepositorymain, lambda: makemain), | |
1190 | (repository.ilocalrepositoryfilestorage, lambda: makefilestorage), |
|
1190 | (repository.ilocalrepositoryfilestorage, lambda: makefilestorage), | |
1191 | ] |
|
1191 | ] | |
1192 |
|
1192 | |||
1193 |
|
1193 | |||
1194 | @interfaceutil.implementer(repository.ilocalrepositorymain) |
|
1194 | @interfaceutil.implementer(repository.ilocalrepositorymain) | |
1195 | class localrepository(object): |
|
1195 | class localrepository(object): | |
1196 | """Main class for representing local repositories. |
|
1196 | """Main class for representing local repositories. | |
1197 |
|
1197 | |||
1198 | All local repositories are instances of this class. |
|
1198 | All local repositories are instances of this class. | |
1199 |
|
1199 | |||
1200 | Constructed on its own, instances of this class are not usable as |
|
1200 | Constructed on its own, instances of this class are not usable as | |
1201 | repository objects. To obtain a usable repository object, call |
|
1201 | repository objects. To obtain a usable repository object, call | |
1202 | ``hg.repository()``, ``localrepo.instance()``, or |
|
1202 | ``hg.repository()``, ``localrepo.instance()``, or | |
1203 | ``localrepo.makelocalrepository()``. The latter is the lowest-level. |
|
1203 | ``localrepo.makelocalrepository()``. The latter is the lowest-level. | |
1204 | ``instance()`` adds support for creating new repositories. |
|
1204 | ``instance()`` adds support for creating new repositories. | |
1205 | ``hg.repository()`` adds more extension integration, including calling |
|
1205 | ``hg.repository()`` adds more extension integration, including calling | |
1206 | ``reposetup()``. Generally speaking, ``hg.repository()`` should be |
|
1206 | ``reposetup()``. Generally speaking, ``hg.repository()`` should be | |
1207 | used. |
|
1207 | used. | |
1208 | """ |
|
1208 | """ | |
1209 |
|
1209 | |||
1210 | # obsolete experimental requirements: |
|
1210 | # obsolete experimental requirements: | |
1211 | # - manifestv2: An experimental new manifest format that allowed |
|
1211 | # - manifestv2: An experimental new manifest format that allowed | |
1212 | # for stem compression of long paths. Experiment ended up not |
|
1212 | # for stem compression of long paths. Experiment ended up not | |
1213 | # being successful (repository sizes went up due to worse delta |
|
1213 | # being successful (repository sizes went up due to worse delta | |
1214 | # chains), and the code was deleted in 4.6. |
|
1214 | # chains), and the code was deleted in 4.6. | |
1215 | supportedformats = { |
|
1215 | supportedformats = { | |
1216 | requirementsmod.REVLOGV1_REQUIREMENT, |
|
1216 | requirementsmod.REVLOGV1_REQUIREMENT, | |
1217 | requirementsmod.GENERALDELTA_REQUIREMENT, |
|
1217 | requirementsmod.GENERALDELTA_REQUIREMENT, | |
1218 | requirementsmod.TREEMANIFEST_REQUIREMENT, |
|
1218 | requirementsmod.TREEMANIFEST_REQUIREMENT, | |
1219 | requirementsmod.COPIESSDC_REQUIREMENT, |
|
1219 | requirementsmod.COPIESSDC_REQUIREMENT, | |
1220 | requirementsmod.REVLOGV2_REQUIREMENT, |
|
1220 | requirementsmod.REVLOGV2_REQUIREMENT, | |
1221 | requirementsmod.SIDEDATA_REQUIREMENT, |
|
1221 | requirementsmod.SIDEDATA_REQUIREMENT, | |
1222 | requirementsmod.SPARSEREVLOG_REQUIREMENT, |
|
1222 | requirementsmod.SPARSEREVLOG_REQUIREMENT, | |
1223 | requirementsmod.NODEMAP_REQUIREMENT, |
|
1223 | requirementsmod.NODEMAP_REQUIREMENT, | |
1224 | bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT, |
|
1224 | bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT, | |
1225 | requirementsmod.SHARESAFE_REQUIREMENT, |
|
1225 | requirementsmod.SHARESAFE_REQUIREMENT, | |
1226 | } |
|
1226 | } | |
1227 | _basesupported = supportedformats | { |
|
1227 | _basesupported = supportedformats | { | |
1228 | requirementsmod.STORE_REQUIREMENT, |
|
1228 | requirementsmod.STORE_REQUIREMENT, | |
1229 | requirementsmod.FNCACHE_REQUIREMENT, |
|
1229 | requirementsmod.FNCACHE_REQUIREMENT, | |
1230 | requirementsmod.SHARED_REQUIREMENT, |
|
1230 | requirementsmod.SHARED_REQUIREMENT, | |
1231 | requirementsmod.RELATIVE_SHARED_REQUIREMENT, |
|
1231 | requirementsmod.RELATIVE_SHARED_REQUIREMENT, | |
1232 | requirementsmod.DOTENCODE_REQUIREMENT, |
|
1232 | requirementsmod.DOTENCODE_REQUIREMENT, | |
1233 | requirementsmod.SPARSE_REQUIREMENT, |
|
1233 | requirementsmod.SPARSE_REQUIREMENT, | |
1234 | requirementsmod.INTERNAL_PHASE_REQUIREMENT, |
|
1234 | requirementsmod.INTERNAL_PHASE_REQUIREMENT, | |
1235 | } |
|
1235 | } | |
1236 |
|
1236 | |||
1237 | # list of prefix for file which can be written without 'wlock' |
|
1237 | # list of prefix for file which can be written without 'wlock' | |
1238 | # Extensions should extend this list when needed |
|
1238 | # Extensions should extend this list when needed | |
1239 | _wlockfreeprefix = { |
|
1239 | _wlockfreeprefix = { | |
1240 | # We migh consider requiring 'wlock' for the next |
|
1240 | # We migh consider requiring 'wlock' for the next | |
1241 | # two, but pretty much all the existing code assume |
|
1241 | # two, but pretty much all the existing code assume | |
1242 | # wlock is not needed so we keep them excluded for |
|
1242 | # wlock is not needed so we keep them excluded for | |
1243 | # now. |
|
1243 | # now. | |
1244 | b'hgrc', |
|
1244 | b'hgrc', | |
1245 | b'requires', |
|
1245 | b'requires', | |
1246 | # XXX cache is a complicatged business someone |
|
1246 | # XXX cache is a complicatged business someone | |
1247 | # should investigate this in depth at some point |
|
1247 | # should investigate this in depth at some point | |
1248 | b'cache/', |
|
1248 | b'cache/', | |
1249 | # XXX shouldn't be dirstate covered by the wlock? |
|
1249 | # XXX shouldn't be dirstate covered by the wlock? | |
1250 | b'dirstate', |
|
1250 | b'dirstate', | |
1251 | # XXX bisect was still a bit too messy at the time |
|
1251 | # XXX bisect was still a bit too messy at the time | |
1252 | # this changeset was introduced. Someone should fix |
|
1252 | # this changeset was introduced. Someone should fix | |
1253 | # the remainig bit and drop this line |
|
1253 | # the remainig bit and drop this line | |
1254 | b'bisect.state', |
|
1254 | b'bisect.state', | |
1255 | } |
|
1255 | } | |
1256 |
|
1256 | |||
1257 | def __init__( |
|
1257 | def __init__( | |
1258 | self, |
|
1258 | self, | |
1259 | baseui, |
|
1259 | baseui, | |
1260 | ui, |
|
1260 | ui, | |
1261 | origroot, |
|
1261 | origroot, | |
1262 | wdirvfs, |
|
1262 | wdirvfs, | |
1263 | hgvfs, |
|
1263 | hgvfs, | |
1264 | requirements, |
|
1264 | requirements, | |
1265 | supportedrequirements, |
|
1265 | supportedrequirements, | |
1266 | sharedpath, |
|
1266 | sharedpath, | |
1267 | store, |
|
1267 | store, | |
1268 | cachevfs, |
|
1268 | cachevfs, | |
1269 | wcachevfs, |
|
1269 | wcachevfs, | |
1270 | features, |
|
1270 | features, | |
1271 | intents=None, |
|
1271 | intents=None, | |
1272 | ): |
|
1272 | ): | |
1273 | """Create a new local repository instance. |
|
1273 | """Create a new local repository instance. | |
1274 |
|
1274 | |||
1275 | Most callers should use ``hg.repository()``, ``localrepo.instance()``, |
|
1275 | Most callers should use ``hg.repository()``, ``localrepo.instance()``, | |
1276 | or ``localrepo.makelocalrepository()`` for obtaining a new repository |
|
1276 | or ``localrepo.makelocalrepository()`` for obtaining a new repository | |
1277 | object. |
|
1277 | object. | |
1278 |
|
1278 | |||
1279 | Arguments: |
|
1279 | Arguments: | |
1280 |
|
1280 | |||
1281 | baseui |
|
1281 | baseui | |
1282 | ``ui.ui`` instance that ``ui`` argument was based off of. |
|
1282 | ``ui.ui`` instance that ``ui`` argument was based off of. | |
1283 |
|
1283 | |||
1284 | ui |
|
1284 | ui | |
1285 | ``ui.ui`` instance for use by the repository. |
|
1285 | ``ui.ui`` instance for use by the repository. | |
1286 |
|
1286 | |||
1287 | origroot |
|
1287 | origroot | |
1288 | ``bytes`` path to working directory root of this repository. |
|
1288 | ``bytes`` path to working directory root of this repository. | |
1289 |
|
1289 | |||
1290 | wdirvfs |
|
1290 | wdirvfs | |
1291 | ``vfs.vfs`` rooted at the working directory. |
|
1291 | ``vfs.vfs`` rooted at the working directory. | |
1292 |
|
1292 | |||
1293 | hgvfs |
|
1293 | hgvfs | |
1294 | ``vfs.vfs`` rooted at .hg/ |
|
1294 | ``vfs.vfs`` rooted at .hg/ | |
1295 |
|
1295 | |||
1296 | requirements |
|
1296 | requirements | |
1297 | ``set`` of bytestrings representing repository opening requirements. |
|
1297 | ``set`` of bytestrings representing repository opening requirements. | |
1298 |
|
1298 | |||
1299 | supportedrequirements |
|
1299 | supportedrequirements | |
1300 | ``set`` of bytestrings representing repository requirements that we |
|
1300 | ``set`` of bytestrings representing repository requirements that we | |
1301 | know how to open. May be a supetset of ``requirements``. |
|
1301 | know how to open. May be a supetset of ``requirements``. | |
1302 |
|
1302 | |||
1303 | sharedpath |
|
1303 | sharedpath | |
1304 | ``bytes`` Defining path to storage base directory. Points to a |
|
1304 | ``bytes`` Defining path to storage base directory. Points to a | |
1305 | ``.hg/`` directory somewhere. |
|
1305 | ``.hg/`` directory somewhere. | |
1306 |
|
1306 | |||
1307 | store |
|
1307 | store | |
1308 | ``store.basicstore`` (or derived) instance providing access to |
|
1308 | ``store.basicstore`` (or derived) instance providing access to | |
1309 | versioned storage. |
|
1309 | versioned storage. | |
1310 |
|
1310 | |||
1311 | cachevfs |
|
1311 | cachevfs | |
1312 | ``vfs.vfs`` used for cache files. |
|
1312 | ``vfs.vfs`` used for cache files. | |
1313 |
|
1313 | |||
1314 | wcachevfs |
|
1314 | wcachevfs | |
1315 | ``vfs.vfs`` used for cache files related to the working copy. |
|
1315 | ``vfs.vfs`` used for cache files related to the working copy. | |
1316 |
|
1316 | |||
1317 | features |
|
1317 | features | |
1318 | ``set`` of bytestrings defining features/capabilities of this |
|
1318 | ``set`` of bytestrings defining features/capabilities of this | |
1319 | instance. |
|
1319 | instance. | |
1320 |
|
1320 | |||
1321 | intents |
|
1321 | intents | |
1322 | ``set`` of system strings indicating what this repo will be used |
|
1322 | ``set`` of system strings indicating what this repo will be used | |
1323 | for. |
|
1323 | for. | |
1324 | """ |
|
1324 | """ | |
1325 | self.baseui = baseui |
|
1325 | self.baseui = baseui | |
1326 | self.ui = ui |
|
1326 | self.ui = ui | |
1327 | self.origroot = origroot |
|
1327 | self.origroot = origroot | |
1328 | # vfs rooted at working directory. |
|
1328 | # vfs rooted at working directory. | |
1329 | self.wvfs = wdirvfs |
|
1329 | self.wvfs = wdirvfs | |
1330 | self.root = wdirvfs.base |
|
1330 | self.root = wdirvfs.base | |
1331 | # vfs rooted at .hg/. Used to access most non-store paths. |
|
1331 | # vfs rooted at .hg/. Used to access most non-store paths. | |
1332 | self.vfs = hgvfs |
|
1332 | self.vfs = hgvfs | |
1333 | self.path = hgvfs.base |
|
1333 | self.path = hgvfs.base | |
1334 | self.requirements = requirements |
|
1334 | self.requirements = requirements | |
1335 | self.nodeconstants = sha1nodeconstants |
|
1335 | self.nodeconstants = sha1nodeconstants | |
1336 | self.nullid = self.nodeconstants.nullid |
|
1336 | self.nullid = self.nodeconstants.nullid | |
1337 | self.supported = supportedrequirements |
|
1337 | self.supported = supportedrequirements | |
1338 | self.sharedpath = sharedpath |
|
1338 | self.sharedpath = sharedpath | |
1339 | self.store = store |
|
1339 | self.store = store | |
1340 | self.cachevfs = cachevfs |
|
1340 | self.cachevfs = cachevfs | |
1341 | self.wcachevfs = wcachevfs |
|
1341 | self.wcachevfs = wcachevfs | |
1342 | self.features = features |
|
1342 | self.features = features | |
1343 |
|
1343 | |||
1344 | self.filtername = None |
|
1344 | self.filtername = None | |
1345 |
|
1345 | |||
1346 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( |
|
1346 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( | |
1347 | b'devel', b'check-locks' |
|
1347 | b'devel', b'check-locks' | |
1348 | ): |
|
1348 | ): | |
1349 | self.vfs.audit = self._getvfsward(self.vfs.audit) |
|
1349 | self.vfs.audit = self._getvfsward(self.vfs.audit) | |
1350 | # A list of callback to shape the phase if no data were found. |
|
1350 | # A list of callback to shape the phase if no data were found. | |
1351 | # Callback are in the form: func(repo, roots) --> processed root. |
|
1351 | # Callback are in the form: func(repo, roots) --> processed root. | |
1352 | # This list it to be filled by extension during repo setup |
|
1352 | # This list it to be filled by extension during repo setup | |
1353 | self._phasedefaults = [] |
|
1353 | self._phasedefaults = [] | |
1354 |
|
1354 | |||
1355 | color.setup(self.ui) |
|
1355 | color.setup(self.ui) | |
1356 |
|
1356 | |||
1357 | self.spath = self.store.path |
|
1357 | self.spath = self.store.path | |
1358 | self.svfs = self.store.vfs |
|
1358 | self.svfs = self.store.vfs | |
1359 | self.sjoin = self.store.join |
|
1359 | self.sjoin = self.store.join | |
1360 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( |
|
1360 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( | |
1361 | b'devel', b'check-locks' |
|
1361 | b'devel', b'check-locks' | |
1362 | ): |
|
1362 | ): | |
1363 | if util.safehasattr(self.svfs, b'vfs'): # this is filtervfs |
|
1363 | if util.safehasattr(self.svfs, b'vfs'): # this is filtervfs | |
1364 | self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit) |
|
1364 | self.svfs.vfs.audit = self._getsvfsward(self.svfs.vfs.audit) | |
1365 | else: # standard vfs |
|
1365 | else: # standard vfs | |
1366 | self.svfs.audit = self._getsvfsward(self.svfs.audit) |
|
1366 | self.svfs.audit = self._getsvfsward(self.svfs.audit) | |
1367 |
|
1367 | |||
1368 | self._dirstatevalidatewarned = False |
|
1368 | self._dirstatevalidatewarned = False | |
1369 |
|
1369 | |||
1370 | self._branchcaches = branchmap.BranchMapCache() |
|
1370 | self._branchcaches = branchmap.BranchMapCache() | |
1371 | self._revbranchcache = None |
|
1371 | self._revbranchcache = None | |
1372 | self._filterpats = {} |
|
1372 | self._filterpats = {} | |
1373 | self._datafilters = {} |
|
1373 | self._datafilters = {} | |
1374 | self._transref = self._lockref = self._wlockref = None |
|
1374 | self._transref = self._lockref = self._wlockref = None | |
1375 |
|
1375 | |||
1376 | # A cache for various files under .hg/ that tracks file changes, |
|
1376 | # A cache for various files under .hg/ that tracks file changes, | |
1377 | # (used by the filecache decorator) |
|
1377 | # (used by the filecache decorator) | |
1378 | # |
|
1378 | # | |
1379 | # Maps a property name to its util.filecacheentry |
|
1379 | # Maps a property name to its util.filecacheentry | |
1380 | self._filecache = {} |
|
1380 | self._filecache = {} | |
1381 |
|
1381 | |||
1382 | # hold sets of revision to be filtered |
|
1382 | # hold sets of revision to be filtered | |
1383 | # should be cleared when something might have changed the filter value: |
|
1383 | # should be cleared when something might have changed the filter value: | |
1384 | # - new changesets, |
|
1384 | # - new changesets, | |
1385 | # - phase change, |
|
1385 | # - phase change, | |
1386 | # - new obsolescence marker, |
|
1386 | # - new obsolescence marker, | |
1387 | # - working directory parent change, |
|
1387 | # - working directory parent change, | |
1388 | # - bookmark changes |
|
1388 | # - bookmark changes | |
1389 | self.filteredrevcache = {} |
|
1389 | self.filteredrevcache = {} | |
1390 |
|
1390 | |||
1391 | # post-dirstate-status hooks |
|
1391 | # post-dirstate-status hooks | |
1392 | self._postdsstatus = [] |
|
1392 | self._postdsstatus = [] | |
1393 |
|
1393 | |||
1394 | # generic mapping between names and nodes |
|
1394 | # generic mapping between names and nodes | |
1395 | self.names = namespaces.namespaces() |
|
1395 | self.names = namespaces.namespaces() | |
1396 |
|
1396 | |||
1397 | # Key to signature value. |
|
1397 | # Key to signature value. | |
1398 | self._sparsesignaturecache = {} |
|
1398 | self._sparsesignaturecache = {} | |
1399 | # Signature to cached matcher instance. |
|
1399 | # Signature to cached matcher instance. | |
1400 | self._sparsematchercache = {} |
|
1400 | self._sparsematchercache = {} | |
1401 |
|
1401 | |||
1402 | self._extrafilterid = repoview.extrafilter(ui) |
|
1402 | self._extrafilterid = repoview.extrafilter(ui) | |
1403 |
|
1403 | |||
1404 | self.filecopiesmode = None |
|
1404 | self.filecopiesmode = None | |
1405 | if requirementsmod.COPIESSDC_REQUIREMENT in self.requirements: |
|
1405 | if requirementsmod.COPIESSDC_REQUIREMENT in self.requirements: | |
1406 | self.filecopiesmode = b'changeset-sidedata' |
|
1406 | self.filecopiesmode = b'changeset-sidedata' | |
1407 |
|
1407 | |||
1408 | self._wanted_sidedata = set() |
|
1408 | self._wanted_sidedata = set() | |
1409 | self._sidedata_computers = {} |
|
1409 | self._sidedata_computers = {} | |
1410 | metadatamod.set_sidedata_spec_for_repo(self) |
|
1410 | metadatamod.set_sidedata_spec_for_repo(self) | |
1411 |
|
1411 | |||
1412 | def _getvfsward(self, origfunc): |
|
1412 | def _getvfsward(self, origfunc): | |
1413 | """build a ward for self.vfs""" |
|
1413 | """build a ward for self.vfs""" | |
1414 | rref = weakref.ref(self) |
|
1414 | rref = weakref.ref(self) | |
1415 |
|
1415 | |||
1416 | def checkvfs(path, mode=None): |
|
1416 | def checkvfs(path, mode=None): | |
1417 | ret = origfunc(path, mode=mode) |
|
1417 | ret = origfunc(path, mode=mode) | |
1418 | repo = rref() |
|
1418 | repo = rref() | |
1419 | if ( |
|
1419 | if ( | |
1420 | repo is None |
|
1420 | repo is None | |
1421 | or not util.safehasattr(repo, b'_wlockref') |
|
1421 | or not util.safehasattr(repo, b'_wlockref') | |
1422 | or not util.safehasattr(repo, b'_lockref') |
|
1422 | or not util.safehasattr(repo, b'_lockref') | |
1423 | ): |
|
1423 | ): | |
1424 | return |
|
1424 | return | |
1425 | if mode in (None, b'r', b'rb'): |
|
1425 | if mode in (None, b'r', b'rb'): | |
1426 | return |
|
1426 | return | |
1427 | if path.startswith(repo.path): |
|
1427 | if path.startswith(repo.path): | |
1428 | # truncate name relative to the repository (.hg) |
|
1428 | # truncate name relative to the repository (.hg) | |
1429 | path = path[len(repo.path) + 1 :] |
|
1429 | path = path[len(repo.path) + 1 :] | |
1430 | if path.startswith(b'cache/'): |
|
1430 | if path.startswith(b'cache/'): | |
1431 | msg = b'accessing cache with vfs instead of cachevfs: "%s"' |
|
1431 | msg = b'accessing cache with vfs instead of cachevfs: "%s"' | |
1432 | repo.ui.develwarn(msg % path, stacklevel=3, config=b"cache-vfs") |
|
1432 | repo.ui.develwarn(msg % path, stacklevel=3, config=b"cache-vfs") | |
1433 | # path prefixes covered by 'lock' |
|
1433 | # path prefixes covered by 'lock' | |
1434 | vfs_path_prefixes = ( |
|
1434 | vfs_path_prefixes = ( | |
1435 | b'journal.', |
|
1435 | b'journal.', | |
1436 | b'undo.', |
|
1436 | b'undo.', | |
1437 | b'strip-backup/', |
|
1437 | b'strip-backup/', | |
1438 | b'cache/', |
|
1438 | b'cache/', | |
1439 | ) |
|
1439 | ) | |
1440 | if any(path.startswith(prefix) for prefix in vfs_path_prefixes): |
|
1440 | if any(path.startswith(prefix) for prefix in vfs_path_prefixes): | |
1441 | if repo._currentlock(repo._lockref) is None: |
|
1441 | if repo._currentlock(repo._lockref) is None: | |
1442 | repo.ui.develwarn( |
|
1442 | repo.ui.develwarn( | |
1443 | b'write with no lock: "%s"' % path, |
|
1443 | b'write with no lock: "%s"' % path, | |
1444 | stacklevel=3, |
|
1444 | stacklevel=3, | |
1445 | config=b'check-locks', |
|
1445 | config=b'check-locks', | |
1446 | ) |
|
1446 | ) | |
1447 | elif repo._currentlock(repo._wlockref) is None: |
|
1447 | elif repo._currentlock(repo._wlockref) is None: | |
1448 | # rest of vfs files are covered by 'wlock' |
|
1448 | # rest of vfs files are covered by 'wlock' | |
1449 | # |
|
1449 | # | |
1450 | # exclude special files |
|
1450 | # exclude special files | |
1451 | for prefix in self._wlockfreeprefix: |
|
1451 | for prefix in self._wlockfreeprefix: | |
1452 | if path.startswith(prefix): |
|
1452 | if path.startswith(prefix): | |
1453 | return |
|
1453 | return | |
1454 | repo.ui.develwarn( |
|
1454 | repo.ui.develwarn( | |
1455 | b'write with no wlock: "%s"' % path, |
|
1455 | b'write with no wlock: "%s"' % path, | |
1456 | stacklevel=3, |
|
1456 | stacklevel=3, | |
1457 | config=b'check-locks', |
|
1457 | config=b'check-locks', | |
1458 | ) |
|
1458 | ) | |
1459 | return ret |
|
1459 | return ret | |
1460 |
|
1460 | |||
1461 | return checkvfs |
|
1461 | return checkvfs | |
1462 |
|
1462 | |||
1463 | def _getsvfsward(self, origfunc): |
|
1463 | def _getsvfsward(self, origfunc): | |
1464 | """build a ward for self.svfs""" |
|
1464 | """build a ward for self.svfs""" | |
1465 | rref = weakref.ref(self) |
|
1465 | rref = weakref.ref(self) | |
1466 |
|
1466 | |||
1467 | def checksvfs(path, mode=None): |
|
1467 | def checksvfs(path, mode=None): | |
1468 | ret = origfunc(path, mode=mode) |
|
1468 | ret = origfunc(path, mode=mode) | |
1469 | repo = rref() |
|
1469 | repo = rref() | |
1470 | if repo is None or not util.safehasattr(repo, b'_lockref'): |
|
1470 | if repo is None or not util.safehasattr(repo, b'_lockref'): | |
1471 | return |
|
1471 | return | |
1472 | if mode in (None, b'r', b'rb'): |
|
1472 | if mode in (None, b'r', b'rb'): | |
1473 | return |
|
1473 | return | |
1474 | if path.startswith(repo.sharedpath): |
|
1474 | if path.startswith(repo.sharedpath): | |
1475 | # truncate name relative to the repository (.hg) |
|
1475 | # truncate name relative to the repository (.hg) | |
1476 | path = path[len(repo.sharedpath) + 1 :] |
|
1476 | path = path[len(repo.sharedpath) + 1 :] | |
1477 | if repo._currentlock(repo._lockref) is None: |
|
1477 | if repo._currentlock(repo._lockref) is None: | |
1478 | repo.ui.develwarn( |
|
1478 | repo.ui.develwarn( | |
1479 | b'write with no lock: "%s"' % path, stacklevel=4 |
|
1479 | b'write with no lock: "%s"' % path, stacklevel=4 | |
1480 | ) |
|
1480 | ) | |
1481 | return ret |
|
1481 | return ret | |
1482 |
|
1482 | |||
1483 | return checksvfs |
|
1483 | return checksvfs | |
1484 |
|
1484 | |||
1485 | def close(self): |
|
1485 | def close(self): | |
1486 | self._writecaches() |
|
1486 | self._writecaches() | |
1487 |
|
1487 | |||
1488 | def _writecaches(self): |
|
1488 | def _writecaches(self): | |
1489 | if self._revbranchcache: |
|
1489 | if self._revbranchcache: | |
1490 | self._revbranchcache.write() |
|
1490 | self._revbranchcache.write() | |
1491 |
|
1491 | |||
1492 | def _restrictcapabilities(self, caps): |
|
1492 | def _restrictcapabilities(self, caps): | |
1493 | if self.ui.configbool(b'experimental', b'bundle2-advertise'): |
|
1493 | if self.ui.configbool(b'experimental', b'bundle2-advertise'): | |
1494 | caps = set(caps) |
|
1494 | caps = set(caps) | |
1495 | capsblob = bundle2.encodecaps( |
|
1495 | capsblob = bundle2.encodecaps( | |
1496 | bundle2.getrepocaps(self, role=b'client') |
|
1496 | bundle2.getrepocaps(self, role=b'client') | |
1497 | ) |
|
1497 | ) | |
1498 | caps.add(b'bundle2=' + urlreq.quote(capsblob)) |
|
1498 | caps.add(b'bundle2=' + urlreq.quote(capsblob)) | |
1499 | if self.ui.configbool(b'experimental', b'narrow'): |
|
1499 | if self.ui.configbool(b'experimental', b'narrow'): | |
1500 | caps.add(wireprototypes.NARROWCAP) |
|
1500 | caps.add(wireprototypes.NARROWCAP) | |
1501 | return caps |
|
1501 | return caps | |
1502 |
|
1502 | |||
1503 | # Don't cache auditor/nofsauditor, or you'll end up with reference cycle: |
|
1503 | # Don't cache auditor/nofsauditor, or you'll end up with reference cycle: | |
1504 | # self -> auditor -> self._checknested -> self |
|
1504 | # self -> auditor -> self._checknested -> self | |
1505 |
|
1505 | |||
1506 | @property |
|
1506 | @property | |
1507 | def auditor(self): |
|
1507 | def auditor(self): | |
1508 | # This is only used by context.workingctx.match in order to |
|
1508 | # This is only used by context.workingctx.match in order to | |
1509 | # detect files in subrepos. |
|
1509 | # detect files in subrepos. | |
1510 | return pathutil.pathauditor(self.root, callback=self._checknested) |
|
1510 | return pathutil.pathauditor(self.root, callback=self._checknested) | |
1511 |
|
1511 | |||
1512 | @property |
|
1512 | @property | |
1513 | def nofsauditor(self): |
|
1513 | def nofsauditor(self): | |
1514 | # This is only used by context.basectx.match in order to detect |
|
1514 | # This is only used by context.basectx.match in order to detect | |
1515 | # files in subrepos. |
|
1515 | # files in subrepos. | |
1516 | return pathutil.pathauditor( |
|
1516 | return pathutil.pathauditor( | |
1517 | self.root, callback=self._checknested, realfs=False, cached=True |
|
1517 | self.root, callback=self._checknested, realfs=False, cached=True | |
1518 | ) |
|
1518 | ) | |
1519 |
|
1519 | |||
1520 | def _checknested(self, path): |
|
1520 | def _checknested(self, path): | |
1521 | """Determine if path is a legal nested repository.""" |
|
1521 | """Determine if path is a legal nested repository.""" | |
1522 | if not path.startswith(self.root): |
|
1522 | if not path.startswith(self.root): | |
1523 | return False |
|
1523 | return False | |
1524 | subpath = path[len(self.root) + 1 :] |
|
1524 | subpath = path[len(self.root) + 1 :] | |
1525 | normsubpath = util.pconvert(subpath) |
|
1525 | normsubpath = util.pconvert(subpath) | |
1526 |
|
1526 | |||
1527 | # XXX: Checking against the current working copy is wrong in |
|
1527 | # XXX: Checking against the current working copy is wrong in | |
1528 | # the sense that it can reject things like |
|
1528 | # the sense that it can reject things like | |
1529 | # |
|
1529 | # | |
1530 | # $ hg cat -r 10 sub/x.txt |
|
1530 | # $ hg cat -r 10 sub/x.txt | |
1531 | # |
|
1531 | # | |
1532 | # if sub/ is no longer a subrepository in the working copy |
|
1532 | # if sub/ is no longer a subrepository in the working copy | |
1533 | # parent revision. |
|
1533 | # parent revision. | |
1534 | # |
|
1534 | # | |
1535 | # However, it can of course also allow things that would have |
|
1535 | # However, it can of course also allow things that would have | |
1536 | # been rejected before, such as the above cat command if sub/ |
|
1536 | # been rejected before, such as the above cat command if sub/ | |
1537 | # is a subrepository now, but was a normal directory before. |
|
1537 | # is a subrepository now, but was a normal directory before. | |
1538 | # The old path auditor would have rejected by mistake since it |
|
1538 | # The old path auditor would have rejected by mistake since it | |
1539 | # panics when it sees sub/.hg/. |
|
1539 | # panics when it sees sub/.hg/. | |
1540 | # |
|
1540 | # | |
1541 | # All in all, checking against the working copy seems sensible |
|
1541 | # All in all, checking against the working copy seems sensible | |
1542 | # since we want to prevent access to nested repositories on |
|
1542 | # since we want to prevent access to nested repositories on | |
1543 | # the filesystem *now*. |
|
1543 | # the filesystem *now*. | |
1544 | ctx = self[None] |
|
1544 | ctx = self[None] | |
1545 | parts = util.splitpath(subpath) |
|
1545 | parts = util.splitpath(subpath) | |
1546 | while parts: |
|
1546 | while parts: | |
1547 | prefix = b'/'.join(parts) |
|
1547 | prefix = b'/'.join(parts) | |
1548 | if prefix in ctx.substate: |
|
1548 | if prefix in ctx.substate: | |
1549 | if prefix == normsubpath: |
|
1549 | if prefix == normsubpath: | |
1550 | return True |
|
1550 | return True | |
1551 | else: |
|
1551 | else: | |
1552 | sub = ctx.sub(prefix) |
|
1552 | sub = ctx.sub(prefix) | |
1553 | return sub.checknested(subpath[len(prefix) + 1 :]) |
|
1553 | return sub.checknested(subpath[len(prefix) + 1 :]) | |
1554 | else: |
|
1554 | else: | |
1555 | parts.pop() |
|
1555 | parts.pop() | |
1556 | return False |
|
1556 | return False | |
1557 |
|
1557 | |||
1558 | def peer(self): |
|
1558 | def peer(self): | |
1559 | return localpeer(self) # not cached to avoid reference cycle |
|
1559 | return localpeer(self) # not cached to avoid reference cycle | |
1560 |
|
1560 | |||
1561 | def unfiltered(self): |
|
1561 | def unfiltered(self): | |
1562 | """Return unfiltered version of the repository |
|
1562 | """Return unfiltered version of the repository | |
1563 |
|
1563 | |||
1564 | Intended to be overwritten by filtered repo.""" |
|
1564 | Intended to be overwritten by filtered repo.""" | |
1565 | return self |
|
1565 | return self | |
1566 |
|
1566 | |||
1567 | def filtered(self, name, visibilityexceptions=None): |
|
1567 | def filtered(self, name, visibilityexceptions=None): | |
1568 | """Return a filtered version of a repository |
|
1568 | """Return a filtered version of a repository | |
1569 |
|
1569 | |||
1570 | The `name` parameter is the identifier of the requested view. This |
|
1570 | The `name` parameter is the identifier of the requested view. This | |
1571 | will return a repoview object set "exactly" to the specified view. |
|
1571 | will return a repoview object set "exactly" to the specified view. | |
1572 |
|
1572 | |||
1573 | This function does not apply recursive filtering to a repository. For |
|
1573 | This function does not apply recursive filtering to a repository. For | |
1574 | example calling `repo.filtered("served")` will return a repoview using |
|
1574 | example calling `repo.filtered("served")` will return a repoview using | |
1575 | the "served" view, regardless of the initial view used by `repo`. |
|
1575 | the "served" view, regardless of the initial view used by `repo`. | |
1576 |
|
1576 | |||
1577 | In other word, there is always only one level of `repoview` "filtering". |
|
1577 | In other word, there is always only one level of `repoview` "filtering". | |
1578 | """ |
|
1578 | """ | |
1579 | if self._extrafilterid is not None and b'%' not in name: |
|
1579 | if self._extrafilterid is not None and b'%' not in name: | |
1580 | name = name + b'%' + self._extrafilterid |
|
1580 | name = name + b'%' + self._extrafilterid | |
1581 |
|
1581 | |||
1582 | cls = repoview.newtype(self.unfiltered().__class__) |
|
1582 | cls = repoview.newtype(self.unfiltered().__class__) | |
1583 | return cls(self, name, visibilityexceptions) |
|
1583 | return cls(self, name, visibilityexceptions) | |
1584 |
|
1584 | |||
1585 | @mixedrepostorecache( |
|
1585 | @mixedrepostorecache( | |
1586 | (b'bookmarks', b'plain'), |
|
1586 | (b'bookmarks', b'plain'), | |
1587 | (b'bookmarks.current', b'plain'), |
|
1587 | (b'bookmarks.current', b'plain'), | |
1588 | (b'bookmarks', b''), |
|
1588 | (b'bookmarks', b''), | |
1589 | (b'00changelog.i', b''), |
|
1589 | (b'00changelog.i', b''), | |
1590 | ) |
|
1590 | ) | |
1591 | def _bookmarks(self): |
|
1591 | def _bookmarks(self): | |
1592 | # Since the multiple files involved in the transaction cannot be |
|
1592 | # Since the multiple files involved in the transaction cannot be | |
1593 | # written atomically (with current repository format), there is a race |
|
1593 | # written atomically (with current repository format), there is a race | |
1594 | # condition here. |
|
1594 | # condition here. | |
1595 | # |
|
1595 | # | |
1596 | # 1) changelog content A is read |
|
1596 | # 1) changelog content A is read | |
1597 | # 2) outside transaction update changelog to content B |
|
1597 | # 2) outside transaction update changelog to content B | |
1598 | # 3) outside transaction update bookmark file referring to content B |
|
1598 | # 3) outside transaction update bookmark file referring to content B | |
1599 | # 4) bookmarks file content is read and filtered against changelog-A |
|
1599 | # 4) bookmarks file content is read and filtered against changelog-A | |
1600 | # |
|
1600 | # | |
1601 | # When this happens, bookmarks against nodes missing from A are dropped. |
|
1601 | # When this happens, bookmarks against nodes missing from A are dropped. | |
1602 | # |
|
1602 | # | |
1603 | # Having this happening during read is not great, but it become worse |
|
1603 | # Having this happening during read is not great, but it become worse | |
1604 | # when this happen during write because the bookmarks to the "unknown" |
|
1604 | # when this happen during write because the bookmarks to the "unknown" | |
1605 | # nodes will be dropped for good. However, writes happen within locks. |
|
1605 | # nodes will be dropped for good. However, writes happen within locks. | |
1606 | # This locking makes it possible to have a race free consistent read. |
|
1606 | # This locking makes it possible to have a race free consistent read. | |
1607 | # For this purpose data read from disc before locking are |
|
1607 | # For this purpose data read from disc before locking are | |
1608 | # "invalidated" right after the locks are taken. This invalidations are |
|
1608 | # "invalidated" right after the locks are taken. This invalidations are | |
1609 | # "light", the `filecache` mechanism keep the data in memory and will |
|
1609 | # "light", the `filecache` mechanism keep the data in memory and will | |
1610 | # reuse them if the underlying files did not changed. Not parsing the |
|
1610 | # reuse them if the underlying files did not changed. Not parsing the | |
1611 | # same data multiple times helps performances. |
|
1611 | # same data multiple times helps performances. | |
1612 | # |
|
1612 | # | |
1613 | # Unfortunately in the case describe above, the files tracked by the |
|
1613 | # Unfortunately in the case describe above, the files tracked by the | |
1614 | # bookmarks file cache might not have changed, but the in-memory |
|
1614 | # bookmarks file cache might not have changed, but the in-memory | |
1615 | # content is still "wrong" because we used an older changelog content |
|
1615 | # content is still "wrong" because we used an older changelog content | |
1616 | # to process the on-disk data. So after locking, the changelog would be |
|
1616 | # to process the on-disk data. So after locking, the changelog would be | |
1617 | # refreshed but `_bookmarks` would be preserved. |
|
1617 | # refreshed but `_bookmarks` would be preserved. | |
1618 | # Adding `00changelog.i` to the list of tracked file is not |
|
1618 | # Adding `00changelog.i` to the list of tracked file is not | |
1619 | # enough, because at the time we build the content for `_bookmarks` in |
|
1619 | # enough, because at the time we build the content for `_bookmarks` in | |
1620 | # (4), the changelog file has already diverged from the content used |
|
1620 | # (4), the changelog file has already diverged from the content used | |
1621 | # for loading `changelog` in (1) |
|
1621 | # for loading `changelog` in (1) | |
1622 | # |
|
1622 | # | |
1623 | # To prevent the issue, we force the changelog to be explicitly |
|
1623 | # To prevent the issue, we force the changelog to be explicitly | |
1624 | # reloaded while computing `_bookmarks`. The data race can still happen |
|
1624 | # reloaded while computing `_bookmarks`. The data race can still happen | |
1625 | # without the lock (with a narrower window), but it would no longer go |
|
1625 | # without the lock (with a narrower window), but it would no longer go | |
1626 | # undetected during the lock time refresh. |
|
1626 | # undetected during the lock time refresh. | |
1627 | # |
|
1627 | # | |
1628 | # The new schedule is as follow |
|
1628 | # The new schedule is as follow | |
1629 | # |
|
1629 | # | |
1630 | # 1) filecache logic detect that `_bookmarks` needs to be computed |
|
1630 | # 1) filecache logic detect that `_bookmarks` needs to be computed | |
1631 | # 2) cachestat for `bookmarks` and `changelog` are captured (for book) |
|
1631 | # 2) cachestat for `bookmarks` and `changelog` are captured (for book) | |
1632 | # 3) We force `changelog` filecache to be tested |
|
1632 | # 3) We force `changelog` filecache to be tested | |
1633 | # 4) cachestat for `changelog` are captured (for changelog) |
|
1633 | # 4) cachestat for `changelog` are captured (for changelog) | |
1634 | # 5) `_bookmarks` is computed and cached |
|
1634 | # 5) `_bookmarks` is computed and cached | |
1635 | # |
|
1635 | # | |
1636 | # The step in (3) ensure we have a changelog at least as recent as the |
|
1636 | # The step in (3) ensure we have a changelog at least as recent as the | |
1637 | # cache stat computed in (1). As a result at locking time: |
|
1637 | # cache stat computed in (1). As a result at locking time: | |
1638 | # * if the changelog did not changed since (1) -> we can reuse the data |
|
1638 | # * if the changelog did not changed since (1) -> we can reuse the data | |
1639 | # * otherwise -> the bookmarks get refreshed. |
|
1639 | # * otherwise -> the bookmarks get refreshed. | |
1640 | self._refreshchangelog() |
|
1640 | self._refreshchangelog() | |
1641 | return bookmarks.bmstore(self) |
|
1641 | return bookmarks.bmstore(self) | |
1642 |
|
1642 | |||
1643 | def _refreshchangelog(self): |
|
1643 | def _refreshchangelog(self): | |
1644 | """make sure the in memory changelog match the on-disk one""" |
|
1644 | """make sure the in memory changelog match the on-disk one""" | |
1645 | if 'changelog' in vars(self) and self.currenttransaction() is None: |
|
1645 | if 'changelog' in vars(self) and self.currenttransaction() is None: | |
1646 | del self.changelog |
|
1646 | del self.changelog | |
1647 |
|
1647 | |||
1648 | @property |
|
1648 | @property | |
1649 | def _activebookmark(self): |
|
1649 | def _activebookmark(self): | |
1650 | return self._bookmarks.active |
|
1650 | return self._bookmarks.active | |
1651 |
|
1651 | |||
1652 | # _phasesets depend on changelog. what we need is to call |
|
1652 | # _phasesets depend on changelog. what we need is to call | |
1653 | # _phasecache.invalidate() if '00changelog.i' was changed, but it |
|
1653 | # _phasecache.invalidate() if '00changelog.i' was changed, but it | |
1654 | # can't be easily expressed in filecache mechanism. |
|
1654 | # can't be easily expressed in filecache mechanism. | |
1655 | @storecache(b'phaseroots', b'00changelog.i') |
|
1655 | @storecache(b'phaseroots', b'00changelog.i') | |
1656 | def _phasecache(self): |
|
1656 | def _phasecache(self): | |
1657 | return phases.phasecache(self, self._phasedefaults) |
|
1657 | return phases.phasecache(self, self._phasedefaults) | |
1658 |
|
1658 | |||
1659 | @storecache(b'obsstore') |
|
1659 | @storecache(b'obsstore') | |
1660 | def obsstore(self): |
|
1660 | def obsstore(self): | |
1661 | return obsolete.makestore(self.ui, self) |
|
1661 | return obsolete.makestore(self.ui, self) | |
1662 |
|
1662 | |||
1663 | @storecache(b'00changelog.i') |
|
1663 | @storecache(b'00changelog.i') | |
1664 | def changelog(self): |
|
1664 | def changelog(self): | |
1665 | # load dirstate before changelog to avoid race see issue6303 |
|
1665 | # load dirstate before changelog to avoid race see issue6303 | |
1666 | self.dirstate.prefetch_parents() |
|
1666 | self.dirstate.prefetch_parents() | |
1667 | return self.store.changelog( |
|
1667 | return self.store.changelog( | |
1668 | txnutil.mayhavepending(self.root), |
|
1668 | txnutil.mayhavepending(self.root), | |
1669 | concurrencychecker=revlogchecker.get_checker(self.ui, b'changelog'), |
|
1669 | concurrencychecker=revlogchecker.get_checker(self.ui, b'changelog'), | |
1670 | ) |
|
1670 | ) | |
1671 |
|
1671 | |||
1672 | @storecache(b'00manifest.i') |
|
1672 | @storecache(b'00manifest.i') | |
1673 | def manifestlog(self): |
|
1673 | def manifestlog(self): | |
1674 | return self.store.manifestlog(self, self._storenarrowmatch) |
|
1674 | return self.store.manifestlog(self, self._storenarrowmatch) | |
1675 |
|
1675 | |||
1676 | @repofilecache(b'dirstate') |
|
1676 | @repofilecache(b'dirstate') | |
1677 | def dirstate(self): |
|
1677 | def dirstate(self): | |
1678 | return self._makedirstate() |
|
1678 | return self._makedirstate() | |
1679 |
|
1679 | |||
1680 | def _makedirstate(self): |
|
1680 | def _makedirstate(self): | |
1681 | """Extension point for wrapping the dirstate per-repo.""" |
|
1681 | """Extension point for wrapping the dirstate per-repo.""" | |
1682 | sparsematchfn = lambda: sparse.matcher(self) |
|
1682 | sparsematchfn = lambda: sparse.matcher(self) | |
1683 |
|
1683 | |||
1684 | return dirstate.dirstate( |
|
1684 | return dirstate.dirstate( | |
1685 | self.vfs, |
|
1685 | self.vfs, | |
1686 | self.ui, |
|
1686 | self.ui, | |
1687 | self.root, |
|
1687 | self.root, | |
1688 | self._dirstatevalidate, |
|
1688 | self._dirstatevalidate, | |
1689 | sparsematchfn, |
|
1689 | sparsematchfn, | |
1690 | self.nodeconstants, |
|
1690 | self.nodeconstants, | |
1691 | ) |
|
1691 | ) | |
1692 |
|
1692 | |||
1693 | def _dirstatevalidate(self, node): |
|
1693 | def _dirstatevalidate(self, node): | |
1694 | try: |
|
1694 | try: | |
1695 | self.changelog.rev(node) |
|
1695 | self.changelog.rev(node) | |
1696 | return node |
|
1696 | return node | |
1697 | except error.LookupError: |
|
1697 | except error.LookupError: | |
1698 | if not self._dirstatevalidatewarned: |
|
1698 | if not self._dirstatevalidatewarned: | |
1699 | self._dirstatevalidatewarned = True |
|
1699 | self._dirstatevalidatewarned = True | |
1700 | self.ui.warn( |
|
1700 | self.ui.warn( | |
1701 | _(b"warning: ignoring unknown working parent %s!\n") |
|
1701 | _(b"warning: ignoring unknown working parent %s!\n") | |
1702 | % short(node) |
|
1702 | % short(node) | |
1703 | ) |
|
1703 | ) | |
1704 | return self.nullid |
|
1704 | return self.nullid | |
1705 |
|
1705 | |||
1706 | @storecache(narrowspec.FILENAME) |
|
1706 | @storecache(narrowspec.FILENAME) | |
1707 | def narrowpats(self): |
|
1707 | def narrowpats(self): | |
1708 | """matcher patterns for this repository's narrowspec |
|
1708 | """matcher patterns for this repository's narrowspec | |
1709 |
|
1709 | |||
1710 | A tuple of (includes, excludes). |
|
1710 | A tuple of (includes, excludes). | |
1711 | """ |
|
1711 | """ | |
1712 | return narrowspec.load(self) |
|
1712 | return narrowspec.load(self) | |
1713 |
|
1713 | |||
1714 | @storecache(narrowspec.FILENAME) |
|
1714 | @storecache(narrowspec.FILENAME) | |
1715 | def _storenarrowmatch(self): |
|
1715 | def _storenarrowmatch(self): | |
1716 | if requirementsmod.NARROW_REQUIREMENT not in self.requirements: |
|
1716 | if requirementsmod.NARROW_REQUIREMENT not in self.requirements: | |
1717 | return matchmod.always() |
|
1717 | return matchmod.always() | |
1718 | include, exclude = self.narrowpats |
|
1718 | include, exclude = self.narrowpats | |
1719 | return narrowspec.match(self.root, include=include, exclude=exclude) |
|
1719 | return narrowspec.match(self.root, include=include, exclude=exclude) | |
1720 |
|
1720 | |||
1721 | @storecache(narrowspec.FILENAME) |
|
1721 | @storecache(narrowspec.FILENAME) | |
1722 | def _narrowmatch(self): |
|
1722 | def _narrowmatch(self): | |
1723 | if requirementsmod.NARROW_REQUIREMENT not in self.requirements: |
|
1723 | if requirementsmod.NARROW_REQUIREMENT not in self.requirements: | |
1724 | return matchmod.always() |
|
1724 | return matchmod.always() | |
1725 | narrowspec.checkworkingcopynarrowspec(self) |
|
1725 | narrowspec.checkworkingcopynarrowspec(self) | |
1726 | include, exclude = self.narrowpats |
|
1726 | include, exclude = self.narrowpats | |
1727 | return narrowspec.match(self.root, include=include, exclude=exclude) |
|
1727 | return narrowspec.match(self.root, include=include, exclude=exclude) | |
1728 |
|
1728 | |||
1729 | def narrowmatch(self, match=None, includeexact=False): |
|
1729 | def narrowmatch(self, match=None, includeexact=False): | |
1730 | """matcher corresponding the the repo's narrowspec |
|
1730 | """matcher corresponding the the repo's narrowspec | |
1731 |
|
1731 | |||
1732 | If `match` is given, then that will be intersected with the narrow |
|
1732 | If `match` is given, then that will be intersected with the narrow | |
1733 | matcher. |
|
1733 | matcher. | |
1734 |
|
1734 | |||
1735 | If `includeexact` is True, then any exact matches from `match` will |
|
1735 | If `includeexact` is True, then any exact matches from `match` will | |
1736 | be included even if they're outside the narrowspec. |
|
1736 | be included even if they're outside the narrowspec. | |
1737 | """ |
|
1737 | """ | |
1738 | if match: |
|
1738 | if match: | |
1739 | if includeexact and not self._narrowmatch.always(): |
|
1739 | if includeexact and not self._narrowmatch.always(): | |
1740 | # do not exclude explicitly-specified paths so that they can |
|
1740 | # do not exclude explicitly-specified paths so that they can | |
1741 | # be warned later on |
|
1741 | # be warned later on | |
1742 | em = matchmod.exact(match.files()) |
|
1742 | em = matchmod.exact(match.files()) | |
1743 | nm = matchmod.unionmatcher([self._narrowmatch, em]) |
|
1743 | nm = matchmod.unionmatcher([self._narrowmatch, em]) | |
1744 | return matchmod.intersectmatchers(match, nm) |
|
1744 | return matchmod.intersectmatchers(match, nm) | |
1745 | return matchmod.intersectmatchers(match, self._narrowmatch) |
|
1745 | return matchmod.intersectmatchers(match, self._narrowmatch) | |
1746 | return self._narrowmatch |
|
1746 | return self._narrowmatch | |
1747 |
|
1747 | |||
1748 | def setnarrowpats(self, newincludes, newexcludes): |
|
1748 | def setnarrowpats(self, newincludes, newexcludes): | |
1749 | narrowspec.save(self, newincludes, newexcludes) |
|
1749 | narrowspec.save(self, newincludes, newexcludes) | |
1750 | self.invalidate(clearfilecache=True) |
|
1750 | self.invalidate(clearfilecache=True) | |
1751 |
|
1751 | |||
1752 | @unfilteredpropertycache |
|
1752 | @unfilteredpropertycache | |
1753 | def _quick_access_changeid_null(self): |
|
1753 | def _quick_access_changeid_null(self): | |
1754 | return { |
|
1754 | return { | |
1755 | b'null': (nullrev, self.nodeconstants.nullid), |
|
1755 | b'null': (nullrev, self.nodeconstants.nullid), | |
1756 | nullrev: (nullrev, self.nodeconstants.nullid), |
|
1756 | nullrev: (nullrev, self.nodeconstants.nullid), | |
1757 | self.nullid: (nullrev, self.nullid), |
|
1757 | self.nullid: (nullrev, self.nullid), | |
1758 | } |
|
1758 | } | |
1759 |
|
1759 | |||
1760 | @unfilteredpropertycache |
|
1760 | @unfilteredpropertycache | |
1761 | def _quick_access_changeid_wc(self): |
|
1761 | def _quick_access_changeid_wc(self): | |
1762 | # also fast path access to the working copy parents |
|
1762 | # also fast path access to the working copy parents | |
1763 | # however, only do it for filter that ensure wc is visible. |
|
1763 | # however, only do it for filter that ensure wc is visible. | |
1764 | quick = self._quick_access_changeid_null.copy() |
|
1764 | quick = self._quick_access_changeid_null.copy() | |
1765 | cl = self.unfiltered().changelog |
|
1765 | cl = self.unfiltered().changelog | |
1766 | for node in self.dirstate.parents(): |
|
1766 | for node in self.dirstate.parents(): | |
1767 | if node == self.nullid: |
|
1767 | if node == self.nullid: | |
1768 | continue |
|
1768 | continue | |
1769 | rev = cl.index.get_rev(node) |
|
1769 | rev = cl.index.get_rev(node) | |
1770 | if rev is None: |
|
1770 | if rev is None: | |
1771 | # unknown working copy parent case: |
|
1771 | # unknown working copy parent case: | |
1772 | # |
|
1772 | # | |
1773 | # skip the fast path and let higher code deal with it |
|
1773 | # skip the fast path and let higher code deal with it | |
1774 | continue |
|
1774 | continue | |
1775 | pair = (rev, node) |
|
1775 | pair = (rev, node) | |
1776 | quick[rev] = pair |
|
1776 | quick[rev] = pair | |
1777 | quick[node] = pair |
|
1777 | quick[node] = pair | |
1778 | # also add the parents of the parents |
|
1778 | # also add the parents of the parents | |
1779 | for r in cl.parentrevs(rev): |
|
1779 | for r in cl.parentrevs(rev): | |
1780 | if r == nullrev: |
|
1780 | if r == nullrev: | |
1781 | continue |
|
1781 | continue | |
1782 | n = cl.node(r) |
|
1782 | n = cl.node(r) | |
1783 | pair = (r, n) |
|
1783 | pair = (r, n) | |
1784 | quick[r] = pair |
|
1784 | quick[r] = pair | |
1785 | quick[n] = pair |
|
1785 | quick[n] = pair | |
1786 | p1node = self.dirstate.p1() |
|
1786 | p1node = self.dirstate.p1() | |
1787 | if p1node != self.nullid: |
|
1787 | if p1node != self.nullid: | |
1788 | quick[b'.'] = quick[p1node] |
|
1788 | quick[b'.'] = quick[p1node] | |
1789 | return quick |
|
1789 | return quick | |
1790 |
|
1790 | |||
1791 | @unfilteredmethod |
|
1791 | @unfilteredmethod | |
1792 | def _quick_access_changeid_invalidate(self): |
|
1792 | def _quick_access_changeid_invalidate(self): | |
1793 | if '_quick_access_changeid_wc' in vars(self): |
|
1793 | if '_quick_access_changeid_wc' in vars(self): | |
1794 | del self.__dict__['_quick_access_changeid_wc'] |
|
1794 | del self.__dict__['_quick_access_changeid_wc'] | |
1795 |
|
1795 | |||
1796 | @property |
|
1796 | @property | |
1797 | def _quick_access_changeid(self): |
|
1797 | def _quick_access_changeid(self): | |
1798 | """an helper dictionnary for __getitem__ calls |
|
1798 | """an helper dictionnary for __getitem__ calls | |
1799 |
|
1799 | |||
1800 | This contains a list of symbol we can recognise right away without |
|
1800 | This contains a list of symbol we can recognise right away without | |
1801 | further processing. |
|
1801 | further processing. | |
1802 | """ |
|
1802 | """ | |
1803 | if self.filtername in repoview.filter_has_wc: |
|
1803 | if self.filtername in repoview.filter_has_wc: | |
1804 | return self._quick_access_changeid_wc |
|
1804 | return self._quick_access_changeid_wc | |
1805 | return self._quick_access_changeid_null |
|
1805 | return self._quick_access_changeid_null | |
1806 |
|
1806 | |||
1807 | def __getitem__(self, changeid): |
|
1807 | def __getitem__(self, changeid): | |
1808 | # dealing with special cases |
|
1808 | # dealing with special cases | |
1809 | if changeid is None: |
|
1809 | if changeid is None: | |
1810 | return context.workingctx(self) |
|
1810 | return context.workingctx(self) | |
1811 | if isinstance(changeid, context.basectx): |
|
1811 | if isinstance(changeid, context.basectx): | |
1812 | return changeid |
|
1812 | return changeid | |
1813 |
|
1813 | |||
1814 | # dealing with multiple revisions |
|
1814 | # dealing with multiple revisions | |
1815 | if isinstance(changeid, slice): |
|
1815 | if isinstance(changeid, slice): | |
1816 | # wdirrev isn't contiguous so the slice shouldn't include it |
|
1816 | # wdirrev isn't contiguous so the slice shouldn't include it | |
1817 | return [ |
|
1817 | return [ | |
1818 | self[i] |
|
1818 | self[i] | |
1819 | for i in pycompat.xrange(*changeid.indices(len(self))) |
|
1819 | for i in pycompat.xrange(*changeid.indices(len(self))) | |
1820 | if i not in self.changelog.filteredrevs |
|
1820 | if i not in self.changelog.filteredrevs | |
1821 | ] |
|
1821 | ] | |
1822 |
|
1822 | |||
1823 | # dealing with some special values |
|
1823 | # dealing with some special values | |
1824 | quick_access = self._quick_access_changeid.get(changeid) |
|
1824 | quick_access = self._quick_access_changeid.get(changeid) | |
1825 | if quick_access is not None: |
|
1825 | if quick_access is not None: | |
1826 | rev, node = quick_access |
|
1826 | rev, node = quick_access | |
1827 | return context.changectx(self, rev, node, maybe_filtered=False) |
|
1827 | return context.changectx(self, rev, node, maybe_filtered=False) | |
1828 | if changeid == b'tip': |
|
1828 | if changeid == b'tip': | |
1829 | node = self.changelog.tip() |
|
1829 | node = self.changelog.tip() | |
1830 | rev = self.changelog.rev(node) |
|
1830 | rev = self.changelog.rev(node) | |
1831 | return context.changectx(self, rev, node) |
|
1831 | return context.changectx(self, rev, node) | |
1832 |
|
1832 | |||
1833 | # dealing with arbitrary values |
|
1833 | # dealing with arbitrary values | |
1834 | try: |
|
1834 | try: | |
1835 | if isinstance(changeid, int): |
|
1835 | if isinstance(changeid, int): | |
1836 | node = self.changelog.node(changeid) |
|
1836 | node = self.changelog.node(changeid) | |
1837 | rev = changeid |
|
1837 | rev = changeid | |
1838 | elif changeid == b'.': |
|
1838 | elif changeid == b'.': | |
1839 | # this is a hack to delay/avoid loading obsmarkers |
|
1839 | # this is a hack to delay/avoid loading obsmarkers | |
1840 | # when we know that '.' won't be hidden |
|
1840 | # when we know that '.' won't be hidden | |
1841 | node = self.dirstate.p1() |
|
1841 | node = self.dirstate.p1() | |
1842 | rev = self.unfiltered().changelog.rev(node) |
|
1842 | rev = self.unfiltered().changelog.rev(node) | |
1843 | elif len(changeid) == self.nodeconstants.nodelen: |
|
1843 | elif len(changeid) == self.nodeconstants.nodelen: | |
1844 | try: |
|
1844 | try: | |
1845 | node = changeid |
|
1845 | node = changeid | |
1846 | rev = self.changelog.rev(changeid) |
|
1846 | rev = self.changelog.rev(changeid) | |
1847 | except error.FilteredLookupError: |
|
1847 | except error.FilteredLookupError: | |
1848 | changeid = hex(changeid) # for the error message |
|
1848 | changeid = hex(changeid) # for the error message | |
1849 | raise |
|
1849 | raise | |
1850 | except LookupError: |
|
1850 | except LookupError: | |
1851 | # check if it might have come from damaged dirstate |
|
1851 | # check if it might have come from damaged dirstate | |
1852 | # |
|
1852 | # | |
1853 | # XXX we could avoid the unfiltered if we had a recognizable |
|
1853 | # XXX we could avoid the unfiltered if we had a recognizable | |
1854 | # exception for filtered changeset access |
|
1854 | # exception for filtered changeset access | |
1855 | if ( |
|
1855 | if ( | |
1856 | self.local() |
|
1856 | self.local() | |
1857 | and changeid in self.unfiltered().dirstate.parents() |
|
1857 | and changeid in self.unfiltered().dirstate.parents() | |
1858 | ): |
|
1858 | ): | |
1859 | msg = _(b"working directory has unknown parent '%s'!") |
|
1859 | msg = _(b"working directory has unknown parent '%s'!") | |
1860 | raise error.Abort(msg % short(changeid)) |
|
1860 | raise error.Abort(msg % short(changeid)) | |
1861 | changeid = hex(changeid) # for the error message |
|
1861 | changeid = hex(changeid) # for the error message | |
1862 | raise |
|
1862 | raise | |
1863 |
|
1863 | |||
1864 | elif len(changeid) == 2 * self.nodeconstants.nodelen: |
|
1864 | elif len(changeid) == 2 * self.nodeconstants.nodelen: | |
1865 | node = bin(changeid) |
|
1865 | node = bin(changeid) | |
1866 | rev = self.changelog.rev(node) |
|
1866 | rev = self.changelog.rev(node) | |
1867 | else: |
|
1867 | else: | |
1868 | raise error.ProgrammingError( |
|
1868 | raise error.ProgrammingError( | |
1869 | b"unsupported changeid '%s' of type %s" |
|
1869 | b"unsupported changeid '%s' of type %s" | |
1870 | % (changeid, pycompat.bytestr(type(changeid))) |
|
1870 | % (changeid, pycompat.bytestr(type(changeid))) | |
1871 | ) |
|
1871 | ) | |
1872 |
|
1872 | |||
1873 | return context.changectx(self, rev, node) |
|
1873 | return context.changectx(self, rev, node) | |
1874 |
|
1874 | |||
1875 | except (error.FilteredIndexError, error.FilteredLookupError): |
|
1875 | except (error.FilteredIndexError, error.FilteredLookupError): | |
1876 | raise error.FilteredRepoLookupError( |
|
1876 | raise error.FilteredRepoLookupError( | |
1877 | _(b"filtered revision '%s'") % pycompat.bytestr(changeid) |
|
1877 | _(b"filtered revision '%s'") % pycompat.bytestr(changeid) | |
1878 | ) |
|
1878 | ) | |
1879 | except (IndexError, LookupError): |
|
1879 | except (IndexError, LookupError): | |
1880 | raise error.RepoLookupError( |
|
1880 | raise error.RepoLookupError( | |
1881 | _(b"unknown revision '%s'") % pycompat.bytestr(changeid) |
|
1881 | _(b"unknown revision '%s'") % pycompat.bytestr(changeid) | |
1882 | ) |
|
1882 | ) | |
1883 | except error.WdirUnsupported: |
|
1883 | except error.WdirUnsupported: | |
1884 | return context.workingctx(self) |
|
1884 | return context.workingctx(self) | |
1885 |
|
1885 | |||
1886 | def __contains__(self, changeid): |
|
1886 | def __contains__(self, changeid): | |
1887 | """True if the given changeid exists""" |
|
1887 | """True if the given changeid exists""" | |
1888 | try: |
|
1888 | try: | |
1889 | self[changeid] |
|
1889 | self[changeid] | |
1890 | return True |
|
1890 | return True | |
1891 | except error.RepoLookupError: |
|
1891 | except error.RepoLookupError: | |
1892 | return False |
|
1892 | return False | |
1893 |
|
1893 | |||
1894 | def __nonzero__(self): |
|
1894 | def __nonzero__(self): | |
1895 | return True |
|
1895 | return True | |
1896 |
|
1896 | |||
1897 | __bool__ = __nonzero__ |
|
1897 | __bool__ = __nonzero__ | |
1898 |
|
1898 | |||
1899 | def __len__(self): |
|
1899 | def __len__(self): | |
1900 | # no need to pay the cost of repoview.changelog |
|
1900 | # no need to pay the cost of repoview.changelog | |
1901 | unfi = self.unfiltered() |
|
1901 | unfi = self.unfiltered() | |
1902 | return len(unfi.changelog) |
|
1902 | return len(unfi.changelog) | |
1903 |
|
1903 | |||
1904 | def __iter__(self): |
|
1904 | def __iter__(self): | |
1905 | return iter(self.changelog) |
|
1905 | return iter(self.changelog) | |
1906 |
|
1906 | |||
1907 | def revs(self, expr, *args): |
|
1907 | def revs(self, expr, *args): | |
1908 | """Find revisions matching a revset. |
|
1908 | """Find revisions matching a revset. | |
1909 |
|
1909 | |||
1910 | The revset is specified as a string ``expr`` that may contain |
|
1910 | The revset is specified as a string ``expr`` that may contain | |
1911 | %-formatting to escape certain types. See ``revsetlang.formatspec``. |
|
1911 | %-formatting to escape certain types. See ``revsetlang.formatspec``. | |
1912 |
|
1912 | |||
1913 | Revset aliases from the configuration are not expanded. To expand |
|
1913 | Revset aliases from the configuration are not expanded. To expand | |
1914 | user aliases, consider calling ``scmutil.revrange()`` or |
|
1914 | user aliases, consider calling ``scmutil.revrange()`` or | |
1915 | ``repo.anyrevs([expr], user=True)``. |
|
1915 | ``repo.anyrevs([expr], user=True)``. | |
1916 |
|
1916 | |||
1917 | Returns a smartset.abstractsmartset, which is a list-like interface |
|
1917 | Returns a smartset.abstractsmartset, which is a list-like interface | |
1918 | that contains integer revisions. |
|
1918 | that contains integer revisions. | |
1919 | """ |
|
1919 | """ | |
1920 | tree = revsetlang.spectree(expr, *args) |
|
1920 | tree = revsetlang.spectree(expr, *args) | |
1921 | return revset.makematcher(tree)(self) |
|
1921 | return revset.makematcher(tree)(self) | |
1922 |
|
1922 | |||
1923 | def set(self, expr, *args): |
|
1923 | def set(self, expr, *args): | |
1924 | """Find revisions matching a revset and emit changectx instances. |
|
1924 | """Find revisions matching a revset and emit changectx instances. | |
1925 |
|
1925 | |||
1926 | This is a convenience wrapper around ``revs()`` that iterates the |
|
1926 | This is a convenience wrapper around ``revs()`` that iterates the | |
1927 | result and is a generator of changectx instances. |
|
1927 | result and is a generator of changectx instances. | |
1928 |
|
1928 | |||
1929 | Revset aliases from the configuration are not expanded. To expand |
|
1929 | Revset aliases from the configuration are not expanded. To expand | |
1930 | user aliases, consider calling ``scmutil.revrange()``. |
|
1930 | user aliases, consider calling ``scmutil.revrange()``. | |
1931 | """ |
|
1931 | """ | |
1932 | for r in self.revs(expr, *args): |
|
1932 | for r in self.revs(expr, *args): | |
1933 | yield self[r] |
|
1933 | yield self[r] | |
1934 |
|
1934 | |||
1935 | def anyrevs(self, specs, user=False, localalias=None): |
|
1935 | def anyrevs(self, specs, user=False, localalias=None): | |
1936 | """Find revisions matching one of the given revsets. |
|
1936 | """Find revisions matching one of the given revsets. | |
1937 |
|
1937 | |||
1938 | Revset aliases from the configuration are not expanded by default. To |
|
1938 | Revset aliases from the configuration are not expanded by default. To | |
1939 | expand user aliases, specify ``user=True``. To provide some local |
|
1939 | expand user aliases, specify ``user=True``. To provide some local | |
1940 | definitions overriding user aliases, set ``localalias`` to |
|
1940 | definitions overriding user aliases, set ``localalias`` to | |
1941 | ``{name: definitionstring}``. |
|
1941 | ``{name: definitionstring}``. | |
1942 | """ |
|
1942 | """ | |
1943 | if specs == [b'null']: |
|
1943 | if specs == [b'null']: | |
1944 | return revset.baseset([nullrev]) |
|
1944 | return revset.baseset([nullrev]) | |
1945 | if specs == [b'.']: |
|
1945 | if specs == [b'.']: | |
1946 | quick_data = self._quick_access_changeid.get(b'.') |
|
1946 | quick_data = self._quick_access_changeid.get(b'.') | |
1947 | if quick_data is not None: |
|
1947 | if quick_data is not None: | |
1948 | return revset.baseset([quick_data[0]]) |
|
1948 | return revset.baseset([quick_data[0]]) | |
1949 | if user: |
|
1949 | if user: | |
1950 | m = revset.matchany( |
|
1950 | m = revset.matchany( | |
1951 | self.ui, |
|
1951 | self.ui, | |
1952 | specs, |
|
1952 | specs, | |
1953 | lookup=revset.lookupfn(self), |
|
1953 | lookup=revset.lookupfn(self), | |
1954 | localalias=localalias, |
|
1954 | localalias=localalias, | |
1955 | ) |
|
1955 | ) | |
1956 | else: |
|
1956 | else: | |
1957 | m = revset.matchany(None, specs, localalias=localalias) |
|
1957 | m = revset.matchany(None, specs, localalias=localalias) | |
1958 | return m(self) |
|
1958 | return m(self) | |
1959 |
|
1959 | |||
1960 | def url(self): |
|
1960 | def url(self): | |
1961 | return b'file:' + self.root |
|
1961 | return b'file:' + self.root | |
1962 |
|
1962 | |||
1963 | def hook(self, name, throw=False, **args): |
|
1963 | def hook(self, name, throw=False, **args): | |
1964 | """Call a hook, passing this repo instance. |
|
1964 | """Call a hook, passing this repo instance. | |
1965 |
|
1965 | |||
1966 | This a convenience method to aid invoking hooks. Extensions likely |
|
1966 | This a convenience method to aid invoking hooks. Extensions likely | |
1967 | won't call this unless they have registered a custom hook or are |
|
1967 | won't call this unless they have registered a custom hook or are | |
1968 | replacing code that is expected to call a hook. |
|
1968 | replacing code that is expected to call a hook. | |
1969 | """ |
|
1969 | """ | |
1970 | return hook.hook(self.ui, self, name, throw, **args) |
|
1970 | return hook.hook(self.ui, self, name, throw, **args) | |
1971 |
|
1971 | |||
1972 | @filteredpropertycache |
|
1972 | @filteredpropertycache | |
1973 | def _tagscache(self): |
|
1973 | def _tagscache(self): | |
1974 | """Returns a tagscache object that contains various tags related |
|
1974 | """Returns a tagscache object that contains various tags related | |
1975 | caches.""" |
|
1975 | caches.""" | |
1976 |
|
1976 | |||
1977 | # This simplifies its cache management by having one decorated |
|
1977 | # This simplifies its cache management by having one decorated | |
1978 | # function (this one) and the rest simply fetch things from it. |
|
1978 | # function (this one) and the rest simply fetch things from it. | |
1979 | class tagscache(object): |
|
1979 | class tagscache(object): | |
1980 | def __init__(self): |
|
1980 | def __init__(self): | |
1981 | # These two define the set of tags for this repository. tags |
|
1981 | # These two define the set of tags for this repository. tags | |
1982 | # maps tag name to node; tagtypes maps tag name to 'global' or |
|
1982 | # maps tag name to node; tagtypes maps tag name to 'global' or | |
1983 | # 'local'. (Global tags are defined by .hgtags across all |
|
1983 | # 'local'. (Global tags are defined by .hgtags across all | |
1984 | # heads, and local tags are defined in .hg/localtags.) |
|
1984 | # heads, and local tags are defined in .hg/localtags.) | |
1985 | # They constitute the in-memory cache of tags. |
|
1985 | # They constitute the in-memory cache of tags. | |
1986 | self.tags = self.tagtypes = None |
|
1986 | self.tags = self.tagtypes = None | |
1987 |
|
1987 | |||
1988 | self.nodetagscache = self.tagslist = None |
|
1988 | self.nodetagscache = self.tagslist = None | |
1989 |
|
1989 | |||
1990 | cache = tagscache() |
|
1990 | cache = tagscache() | |
1991 | cache.tags, cache.tagtypes = self._findtags() |
|
1991 | cache.tags, cache.tagtypes = self._findtags() | |
1992 |
|
1992 | |||
1993 | return cache |
|
1993 | return cache | |
1994 |
|
1994 | |||
1995 | def tags(self): |
|
1995 | def tags(self): | |
1996 | '''return a mapping of tag to node''' |
|
1996 | '''return a mapping of tag to node''' | |
1997 | t = {} |
|
1997 | t = {} | |
1998 | if self.changelog.filteredrevs: |
|
1998 | if self.changelog.filteredrevs: | |
1999 | tags, tt = self._findtags() |
|
1999 | tags, tt = self._findtags() | |
2000 | else: |
|
2000 | else: | |
2001 | tags = self._tagscache.tags |
|
2001 | tags = self._tagscache.tags | |
2002 | rev = self.changelog.rev |
|
2002 | rev = self.changelog.rev | |
2003 | for k, v in pycompat.iteritems(tags): |
|
2003 | for k, v in pycompat.iteritems(tags): | |
2004 | try: |
|
2004 | try: | |
2005 | # ignore tags to unknown nodes |
|
2005 | # ignore tags to unknown nodes | |
2006 | rev(v) |
|
2006 | rev(v) | |
2007 | t[k] = v |
|
2007 | t[k] = v | |
2008 | except (error.LookupError, ValueError): |
|
2008 | except (error.LookupError, ValueError): | |
2009 | pass |
|
2009 | pass | |
2010 | return t |
|
2010 | return t | |
2011 |
|
2011 | |||
2012 | def _findtags(self): |
|
2012 | def _findtags(self): | |
2013 | """Do the hard work of finding tags. Return a pair of dicts |
|
2013 | """Do the hard work of finding tags. Return a pair of dicts | |
2014 | (tags, tagtypes) where tags maps tag name to node, and tagtypes |
|
2014 | (tags, tagtypes) where tags maps tag name to node, and tagtypes | |
2015 | maps tag name to a string like \'global\' or \'local\'. |
|
2015 | maps tag name to a string like \'global\' or \'local\'. | |
2016 | Subclasses or extensions are free to add their own tags, but |
|
2016 | Subclasses or extensions are free to add their own tags, but | |
2017 | should be aware that the returned dicts will be retained for the |
|
2017 | should be aware that the returned dicts will be retained for the | |
2018 | duration of the localrepo object.""" |
|
2018 | duration of the localrepo object.""" | |
2019 |
|
2019 | |||
2020 | # XXX what tagtype should subclasses/extensions use? Currently |
|
2020 | # XXX what tagtype should subclasses/extensions use? Currently | |
2021 | # mq and bookmarks add tags, but do not set the tagtype at all. |
|
2021 | # mq and bookmarks add tags, but do not set the tagtype at all. | |
2022 | # Should each extension invent its own tag type? Should there |
|
2022 | # Should each extension invent its own tag type? Should there | |
2023 | # be one tagtype for all such "virtual" tags? Or is the status |
|
2023 | # be one tagtype for all such "virtual" tags? Or is the status | |
2024 | # quo fine? |
|
2024 | # quo fine? | |
2025 |
|
2025 | |||
2026 | # map tag name to (node, hist) |
|
2026 | # map tag name to (node, hist) | |
2027 | alltags = tagsmod.findglobaltags(self.ui, self) |
|
2027 | alltags = tagsmod.findglobaltags(self.ui, self) | |
2028 | # map tag name to tag type |
|
2028 | # map tag name to tag type | |
2029 | tagtypes = {tag: b'global' for tag in alltags} |
|
2029 | tagtypes = {tag: b'global' for tag in alltags} | |
2030 |
|
2030 | |||
2031 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) |
|
2031 | tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) | |
2032 |
|
2032 | |||
2033 | # Build the return dicts. Have to re-encode tag names because |
|
2033 | # Build the return dicts. Have to re-encode tag names because | |
2034 | # the tags module always uses UTF-8 (in order not to lose info |
|
2034 | # the tags module always uses UTF-8 (in order not to lose info | |
2035 | # writing to the cache), but the rest of Mercurial wants them in |
|
2035 | # writing to the cache), but the rest of Mercurial wants them in | |
2036 | # local encoding. |
|
2036 | # local encoding. | |
2037 | tags = {} |
|
2037 | tags = {} | |
2038 | for (name, (node, hist)) in pycompat.iteritems(alltags): |
|
2038 | for (name, (node, hist)) in pycompat.iteritems(alltags): | |
2039 | if node != self.nullid: |
|
2039 | if node != self.nullid: | |
2040 | tags[encoding.tolocal(name)] = node |
|
2040 | tags[encoding.tolocal(name)] = node | |
2041 | tags[b'tip'] = self.changelog.tip() |
|
2041 | tags[b'tip'] = self.changelog.tip() | |
2042 | tagtypes = { |
|
2042 | tagtypes = { | |
2043 | encoding.tolocal(name): value |
|
2043 | encoding.tolocal(name): value | |
2044 | for (name, value) in pycompat.iteritems(tagtypes) |
|
2044 | for (name, value) in pycompat.iteritems(tagtypes) | |
2045 | } |
|
2045 | } | |
2046 | return (tags, tagtypes) |
|
2046 | return (tags, tagtypes) | |
2047 |
|
2047 | |||
2048 | def tagtype(self, tagname): |
|
2048 | def tagtype(self, tagname): | |
2049 | """ |
|
2049 | """ | |
2050 | return the type of the given tag. result can be: |
|
2050 | return the type of the given tag. result can be: | |
2051 |
|
2051 | |||
2052 | 'local' : a local tag |
|
2052 | 'local' : a local tag | |
2053 | 'global' : a global tag |
|
2053 | 'global' : a global tag | |
2054 | None : tag does not exist |
|
2054 | None : tag does not exist | |
2055 | """ |
|
2055 | """ | |
2056 |
|
2056 | |||
2057 | return self._tagscache.tagtypes.get(tagname) |
|
2057 | return self._tagscache.tagtypes.get(tagname) | |
2058 |
|
2058 | |||
2059 | def tagslist(self): |
|
2059 | def tagslist(self): | |
2060 | '''return a list of tags ordered by revision''' |
|
2060 | '''return a list of tags ordered by revision''' | |
2061 | if not self._tagscache.tagslist: |
|
2061 | if not self._tagscache.tagslist: | |
2062 | l = [] |
|
2062 | l = [] | |
2063 | for t, n in pycompat.iteritems(self.tags()): |
|
2063 | for t, n in pycompat.iteritems(self.tags()): | |
2064 | l.append((self.changelog.rev(n), t, n)) |
|
2064 | l.append((self.changelog.rev(n), t, n)) | |
2065 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] |
|
2065 | self._tagscache.tagslist = [(t, n) for r, t, n in sorted(l)] | |
2066 |
|
2066 | |||
2067 | return self._tagscache.tagslist |
|
2067 | return self._tagscache.tagslist | |
2068 |
|
2068 | |||
2069 | def nodetags(self, node): |
|
2069 | def nodetags(self, node): | |
2070 | '''return the tags associated with a node''' |
|
2070 | '''return the tags associated with a node''' | |
2071 | if not self._tagscache.nodetagscache: |
|
2071 | if not self._tagscache.nodetagscache: | |
2072 | nodetagscache = {} |
|
2072 | nodetagscache = {} | |
2073 | for t, n in pycompat.iteritems(self._tagscache.tags): |
|
2073 | for t, n in pycompat.iteritems(self._tagscache.tags): | |
2074 | nodetagscache.setdefault(n, []).append(t) |
|
2074 | nodetagscache.setdefault(n, []).append(t) | |
2075 | for tags in pycompat.itervalues(nodetagscache): |
|
2075 | for tags in pycompat.itervalues(nodetagscache): | |
2076 | tags.sort() |
|
2076 | tags.sort() | |
2077 | self._tagscache.nodetagscache = nodetagscache |
|
2077 | self._tagscache.nodetagscache = nodetagscache | |
2078 | return self._tagscache.nodetagscache.get(node, []) |
|
2078 | return self._tagscache.nodetagscache.get(node, []) | |
2079 |
|
2079 | |||
2080 | def nodebookmarks(self, node): |
|
2080 | def nodebookmarks(self, node): | |
2081 | """return the list of bookmarks pointing to the specified node""" |
|
2081 | """return the list of bookmarks pointing to the specified node""" | |
2082 | return self._bookmarks.names(node) |
|
2082 | return self._bookmarks.names(node) | |
2083 |
|
2083 | |||
2084 | def branchmap(self): |
|
2084 | def branchmap(self): | |
2085 | """returns a dictionary {branch: [branchheads]} with branchheads |
|
2085 | """returns a dictionary {branch: [branchheads]} with branchheads | |
2086 | ordered by increasing revision number""" |
|
2086 | ordered by increasing revision number""" | |
2087 | return self._branchcaches[self] |
|
2087 | return self._branchcaches[self] | |
2088 |
|
2088 | |||
2089 | @unfilteredmethod |
|
2089 | @unfilteredmethod | |
2090 | def revbranchcache(self): |
|
2090 | def revbranchcache(self): | |
2091 | if not self._revbranchcache: |
|
2091 | if not self._revbranchcache: | |
2092 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) |
|
2092 | self._revbranchcache = branchmap.revbranchcache(self.unfiltered()) | |
2093 | return self._revbranchcache |
|
2093 | return self._revbranchcache | |
2094 |
|
2094 | |||
2095 | def register_changeset(self, rev, changelogrevision): |
|
2095 | def register_changeset(self, rev, changelogrevision): | |
2096 | self.revbranchcache().setdata(rev, changelogrevision) |
|
2096 | self.revbranchcache().setdata(rev, changelogrevision) | |
2097 |
|
2097 | |||
2098 | def branchtip(self, branch, ignoremissing=False): |
|
2098 | def branchtip(self, branch, ignoremissing=False): | |
2099 | """return the tip node for a given branch |
|
2099 | """return the tip node for a given branch | |
2100 |
|
2100 | |||
2101 | If ignoremissing is True, then this method will not raise an error. |
|
2101 | If ignoremissing is True, then this method will not raise an error. | |
2102 | This is helpful for callers that only expect None for a missing branch |
|
2102 | This is helpful for callers that only expect None for a missing branch | |
2103 | (e.g. namespace). |
|
2103 | (e.g. namespace). | |
2104 |
|
2104 | |||
2105 | """ |
|
2105 | """ | |
2106 | try: |
|
2106 | try: | |
2107 | return self.branchmap().branchtip(branch) |
|
2107 | return self.branchmap().branchtip(branch) | |
2108 | except KeyError: |
|
2108 | except KeyError: | |
2109 | if not ignoremissing: |
|
2109 | if not ignoremissing: | |
2110 | raise error.RepoLookupError(_(b"unknown branch '%s'") % branch) |
|
2110 | raise error.RepoLookupError(_(b"unknown branch '%s'") % branch) | |
2111 | else: |
|
2111 | else: | |
2112 | pass |
|
2112 | pass | |
2113 |
|
2113 | |||
2114 | def lookup(self, key): |
|
2114 | def lookup(self, key): | |
2115 | node = scmutil.revsymbol(self, key).node() |
|
2115 | node = scmutil.revsymbol(self, key).node() | |
2116 | if node is None: |
|
2116 | if node is None: | |
2117 | raise error.RepoLookupError(_(b"unknown revision '%s'") % key) |
|
2117 | raise error.RepoLookupError(_(b"unknown revision '%s'") % key) | |
2118 | return node |
|
2118 | return node | |
2119 |
|
2119 | |||
2120 | def lookupbranch(self, key): |
|
2120 | def lookupbranch(self, key): | |
2121 | if self.branchmap().hasbranch(key): |
|
2121 | if self.branchmap().hasbranch(key): | |
2122 | return key |
|
2122 | return key | |
2123 |
|
2123 | |||
2124 | return scmutil.revsymbol(self, key).branch() |
|
2124 | return scmutil.revsymbol(self, key).branch() | |
2125 |
|
2125 | |||
2126 | def known(self, nodes): |
|
2126 | def known(self, nodes): | |
2127 | cl = self.changelog |
|
2127 | cl = self.changelog | |
2128 | get_rev = cl.index.get_rev |
|
2128 | get_rev = cl.index.get_rev | |
2129 | filtered = cl.filteredrevs |
|
2129 | filtered = cl.filteredrevs | |
2130 | result = [] |
|
2130 | result = [] | |
2131 | for n in nodes: |
|
2131 | for n in nodes: | |
2132 | r = get_rev(n) |
|
2132 | r = get_rev(n) | |
2133 | resp = not (r is None or r in filtered) |
|
2133 | resp = not (r is None or r in filtered) | |
2134 | result.append(resp) |
|
2134 | result.append(resp) | |
2135 | return result |
|
2135 | return result | |
2136 |
|
2136 | |||
2137 | def local(self): |
|
2137 | def local(self): | |
2138 | return self |
|
2138 | return self | |
2139 |
|
2139 | |||
2140 | def publishing(self): |
|
2140 | def publishing(self): | |
2141 | # it's safe (and desirable) to trust the publish flag unconditionally |
|
2141 | # it's safe (and desirable) to trust the publish flag unconditionally | |
2142 | # so that we don't finalize changes shared between users via ssh or nfs |
|
2142 | # so that we don't finalize changes shared between users via ssh or nfs | |
2143 | return self.ui.configbool(b'phases', b'publish', untrusted=True) |
|
2143 | return self.ui.configbool(b'phases', b'publish', untrusted=True) | |
2144 |
|
2144 | |||
2145 | def cancopy(self): |
|
2145 | def cancopy(self): | |
2146 | # so statichttprepo's override of local() works |
|
2146 | # so statichttprepo's override of local() works | |
2147 | if not self.local(): |
|
2147 | if not self.local(): | |
2148 | return False |
|
2148 | return False | |
2149 | if not self.publishing(): |
|
2149 | if not self.publishing(): | |
2150 | return True |
|
2150 | return True | |
2151 | # if publishing we can't copy if there is filtered content |
|
2151 | # if publishing we can't copy if there is filtered content | |
2152 | return not self.filtered(b'visible').changelog.filteredrevs |
|
2152 | return not self.filtered(b'visible').changelog.filteredrevs | |
2153 |
|
2153 | |||
2154 | def shared(self): |
|
2154 | def shared(self): | |
2155 | '''the type of shared repository (None if not shared)''' |
|
2155 | '''the type of shared repository (None if not shared)''' | |
2156 | if self.sharedpath != self.path: |
|
2156 | if self.sharedpath != self.path: | |
2157 | return b'store' |
|
2157 | return b'store' | |
2158 | return None |
|
2158 | return None | |
2159 |
|
2159 | |||
2160 | def wjoin(self, f, *insidef): |
|
2160 | def wjoin(self, f, *insidef): | |
2161 | return self.vfs.reljoin(self.root, f, *insidef) |
|
2161 | return self.vfs.reljoin(self.root, f, *insidef) | |
2162 |
|
2162 | |||
2163 | def setparents(self, p1, p2=None): |
|
2163 | def setparents(self, p1, p2=None): | |
2164 | if p2 is None: |
|
2164 | if p2 is None: | |
2165 | p2 = self.nullid |
|
2165 | p2 = self.nullid | |
2166 | self[None].setparents(p1, p2) |
|
2166 | self[None].setparents(p1, p2) | |
2167 | self._quick_access_changeid_invalidate() |
|
2167 | self._quick_access_changeid_invalidate() | |
2168 |
|
2168 | |||
2169 | def filectx(self, path, changeid=None, fileid=None, changectx=None): |
|
2169 | def filectx(self, path, changeid=None, fileid=None, changectx=None): | |
2170 | """changeid must be a changeset revision, if specified. |
|
2170 | """changeid must be a changeset revision, if specified. | |
2171 | fileid can be a file revision or node.""" |
|
2171 | fileid can be a file revision or node.""" | |
2172 | return context.filectx( |
|
2172 | return context.filectx( | |
2173 | self, path, changeid, fileid, changectx=changectx |
|
2173 | self, path, changeid, fileid, changectx=changectx | |
2174 | ) |
|
2174 | ) | |
2175 |
|
2175 | |||
2176 | def getcwd(self): |
|
2176 | def getcwd(self): | |
2177 | return self.dirstate.getcwd() |
|
2177 | return self.dirstate.getcwd() | |
2178 |
|
2178 | |||
2179 | def pathto(self, f, cwd=None): |
|
2179 | def pathto(self, f, cwd=None): | |
2180 | return self.dirstate.pathto(f, cwd) |
|
2180 | return self.dirstate.pathto(f, cwd) | |
2181 |
|
2181 | |||
2182 | def _loadfilter(self, filter): |
|
2182 | def _loadfilter(self, filter): | |
2183 | if filter not in self._filterpats: |
|
2183 | if filter not in self._filterpats: | |
2184 | l = [] |
|
2184 | l = [] | |
2185 | for pat, cmd in self.ui.configitems(filter): |
|
2185 | for pat, cmd in self.ui.configitems(filter): | |
2186 | if cmd == b'!': |
|
2186 | if cmd == b'!': | |
2187 | continue |
|
2187 | continue | |
2188 | mf = matchmod.match(self.root, b'', [pat]) |
|
2188 | mf = matchmod.match(self.root, b'', [pat]) | |
2189 | fn = None |
|
2189 | fn = None | |
2190 | params = cmd |
|
2190 | params = cmd | |
2191 | for name, filterfn in pycompat.iteritems(self._datafilters): |
|
2191 | for name, filterfn in pycompat.iteritems(self._datafilters): | |
2192 | if cmd.startswith(name): |
|
2192 | if cmd.startswith(name): | |
2193 | fn = filterfn |
|
2193 | fn = filterfn | |
2194 | params = cmd[len(name) :].lstrip() |
|
2194 | params = cmd[len(name) :].lstrip() | |
2195 | break |
|
2195 | break | |
2196 | if not fn: |
|
2196 | if not fn: | |
2197 | fn = lambda s, c, **kwargs: procutil.filter(s, c) |
|
2197 | fn = lambda s, c, **kwargs: procutil.filter(s, c) | |
2198 | fn.__name__ = 'commandfilter' |
|
2198 | fn.__name__ = 'commandfilter' | |
2199 | # Wrap old filters not supporting keyword arguments |
|
2199 | # Wrap old filters not supporting keyword arguments | |
2200 | if not pycompat.getargspec(fn)[2]: |
|
2200 | if not pycompat.getargspec(fn)[2]: | |
2201 | oldfn = fn |
|
2201 | oldfn = fn | |
2202 | fn = lambda s, c, oldfn=oldfn, **kwargs: oldfn(s, c) |
|
2202 | fn = lambda s, c, oldfn=oldfn, **kwargs: oldfn(s, c) | |
2203 | fn.__name__ = 'compat-' + oldfn.__name__ |
|
2203 | fn.__name__ = 'compat-' + oldfn.__name__ | |
2204 | l.append((mf, fn, params)) |
|
2204 | l.append((mf, fn, params)) | |
2205 | self._filterpats[filter] = l |
|
2205 | self._filterpats[filter] = l | |
2206 | return self._filterpats[filter] |
|
2206 | return self._filterpats[filter] | |
2207 |
|
2207 | |||
2208 | def _filter(self, filterpats, filename, data): |
|
2208 | def _filter(self, filterpats, filename, data): | |
2209 | for mf, fn, cmd in filterpats: |
|
2209 | for mf, fn, cmd in filterpats: | |
2210 | if mf(filename): |
|
2210 | if mf(filename): | |
2211 | self.ui.debug( |
|
2211 | self.ui.debug( | |
2212 | b"filtering %s through %s\n" |
|
2212 | b"filtering %s through %s\n" | |
2213 | % (filename, cmd or pycompat.sysbytes(fn.__name__)) |
|
2213 | % (filename, cmd or pycompat.sysbytes(fn.__name__)) | |
2214 | ) |
|
2214 | ) | |
2215 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) |
|
2215 | data = fn(data, cmd, ui=self.ui, repo=self, filename=filename) | |
2216 | break |
|
2216 | break | |
2217 |
|
2217 | |||
2218 | return data |
|
2218 | return data | |
2219 |
|
2219 | |||
2220 | @unfilteredpropertycache |
|
2220 | @unfilteredpropertycache | |
2221 | def _encodefilterpats(self): |
|
2221 | def _encodefilterpats(self): | |
2222 | return self._loadfilter(b'encode') |
|
2222 | return self._loadfilter(b'encode') | |
2223 |
|
2223 | |||
2224 | @unfilteredpropertycache |
|
2224 | @unfilteredpropertycache | |
2225 | def _decodefilterpats(self): |
|
2225 | def _decodefilterpats(self): | |
2226 | return self._loadfilter(b'decode') |
|
2226 | return self._loadfilter(b'decode') | |
2227 |
|
2227 | |||
2228 | def adddatafilter(self, name, filter): |
|
2228 | def adddatafilter(self, name, filter): | |
2229 | self._datafilters[name] = filter |
|
2229 | self._datafilters[name] = filter | |
2230 |
|
2230 | |||
2231 | def wread(self, filename): |
|
2231 | def wread(self, filename): | |
2232 | if self.wvfs.islink(filename): |
|
2232 | if self.wvfs.islink(filename): | |
2233 | data = self.wvfs.readlink(filename) |
|
2233 | data = self.wvfs.readlink(filename) | |
2234 | else: |
|
2234 | else: | |
2235 | data = self.wvfs.read(filename) |
|
2235 | data = self.wvfs.read(filename) | |
2236 | return self._filter(self._encodefilterpats, filename, data) |
|
2236 | return self._filter(self._encodefilterpats, filename, data) | |
2237 |
|
2237 | |||
2238 | def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs): |
|
2238 | def wwrite(self, filename, data, flags, backgroundclose=False, **kwargs): | |
2239 | """write ``data`` into ``filename`` in the working directory |
|
2239 | """write ``data`` into ``filename`` in the working directory | |
2240 |
|
2240 | |||
2241 | This returns length of written (maybe decoded) data. |
|
2241 | This returns length of written (maybe decoded) data. | |
2242 | """ |
|
2242 | """ | |
2243 | data = self._filter(self._decodefilterpats, filename, data) |
|
2243 | data = self._filter(self._decodefilterpats, filename, data) | |
2244 | if b'l' in flags: |
|
2244 | if b'l' in flags: | |
2245 | self.wvfs.symlink(data, filename) |
|
2245 | self.wvfs.symlink(data, filename) | |
2246 | else: |
|
2246 | else: | |
2247 | self.wvfs.write( |
|
2247 | self.wvfs.write( | |
2248 | filename, data, backgroundclose=backgroundclose, **kwargs |
|
2248 | filename, data, backgroundclose=backgroundclose, **kwargs | |
2249 | ) |
|
2249 | ) | |
2250 | if b'x' in flags: |
|
2250 | if b'x' in flags: | |
2251 | self.wvfs.setflags(filename, False, True) |
|
2251 | self.wvfs.setflags(filename, False, True) | |
2252 | else: |
|
2252 | else: | |
2253 | self.wvfs.setflags(filename, False, False) |
|
2253 | self.wvfs.setflags(filename, False, False) | |
2254 | return len(data) |
|
2254 | return len(data) | |
2255 |
|
2255 | |||
2256 | def wwritedata(self, filename, data): |
|
2256 | def wwritedata(self, filename, data): | |
2257 | return self._filter(self._decodefilterpats, filename, data) |
|
2257 | return self._filter(self._decodefilterpats, filename, data) | |
2258 |
|
2258 | |||
2259 | def currenttransaction(self): |
|
2259 | def currenttransaction(self): | |
2260 | """return the current transaction or None if non exists""" |
|
2260 | """return the current transaction or None if non exists""" | |
2261 | if self._transref: |
|
2261 | if self._transref: | |
2262 | tr = self._transref() |
|
2262 | tr = self._transref() | |
2263 | else: |
|
2263 | else: | |
2264 | tr = None |
|
2264 | tr = None | |
2265 |
|
2265 | |||
2266 | if tr and tr.running(): |
|
2266 | if tr and tr.running(): | |
2267 | return tr |
|
2267 | return tr | |
2268 | return None |
|
2268 | return None | |
2269 |
|
2269 | |||
2270 | def transaction(self, desc, report=None): |
|
2270 | def transaction(self, desc, report=None): | |
2271 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( |
|
2271 | if self.ui.configbool(b'devel', b'all-warnings') or self.ui.configbool( | |
2272 | b'devel', b'check-locks' |
|
2272 | b'devel', b'check-locks' | |
2273 | ): |
|
2273 | ): | |
2274 | if self._currentlock(self._lockref) is None: |
|
2274 | if self._currentlock(self._lockref) is None: | |
2275 | raise error.ProgrammingError(b'transaction requires locking') |
|
2275 | raise error.ProgrammingError(b'transaction requires locking') | |
2276 | tr = self.currenttransaction() |
|
2276 | tr = self.currenttransaction() | |
2277 | if tr is not None: |
|
2277 | if tr is not None: | |
2278 | return tr.nest(name=desc) |
|
2278 | return tr.nest(name=desc) | |
2279 |
|
2279 | |||
2280 | # abort here if the journal already exists |
|
2280 | # abort here if the journal already exists | |
2281 | if self.svfs.exists(b"journal"): |
|
2281 | if self.svfs.exists(b"journal"): | |
2282 | raise error.RepoError( |
|
2282 | raise error.RepoError( | |
2283 | _(b"abandoned transaction found"), |
|
2283 | _(b"abandoned transaction found"), | |
2284 | hint=_(b"run 'hg recover' to clean up transaction"), |
|
2284 | hint=_(b"run 'hg recover' to clean up transaction"), | |
2285 | ) |
|
2285 | ) | |
2286 |
|
2286 | |||
2287 | idbase = b"%.40f#%f" % (random.random(), time.time()) |
|
2287 | idbase = b"%.40f#%f" % (random.random(), time.time()) | |
2288 | ha = hex(hashutil.sha1(idbase).digest()) |
|
2288 | ha = hex(hashutil.sha1(idbase).digest()) | |
2289 | txnid = b'TXN:' + ha |
|
2289 | txnid = b'TXN:' + ha | |
2290 | self.hook(b'pretxnopen', throw=True, txnname=desc, txnid=txnid) |
|
2290 | self.hook(b'pretxnopen', throw=True, txnname=desc, txnid=txnid) | |
2291 |
|
2291 | |||
2292 | self._writejournal(desc) |
|
2292 | self._writejournal(desc) | |
2293 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] |
|
2293 | renames = [(vfs, x, undoname(x)) for vfs, x in self._journalfiles()] | |
2294 | if report: |
|
2294 | if report: | |
2295 | rp = report |
|
2295 | rp = report | |
2296 | else: |
|
2296 | else: | |
2297 | rp = self.ui.warn |
|
2297 | rp = self.ui.warn | |
2298 | vfsmap = {b'plain': self.vfs, b'store': self.svfs} # root of .hg/ |
|
2298 | vfsmap = {b'plain': self.vfs, b'store': self.svfs} # root of .hg/ | |
2299 | # we must avoid cyclic reference between repo and transaction. |
|
2299 | # we must avoid cyclic reference between repo and transaction. | |
2300 | reporef = weakref.ref(self) |
|
2300 | reporef = weakref.ref(self) | |
2301 | # Code to track tag movement |
|
2301 | # Code to track tag movement | |
2302 | # |
|
2302 | # | |
2303 | # Since tags are all handled as file content, it is actually quite hard |
|
2303 | # Since tags are all handled as file content, it is actually quite hard | |
2304 | # to track these movement from a code perspective. So we fallback to a |
|
2304 | # to track these movement from a code perspective. So we fallback to a | |
2305 | # tracking at the repository level. One could envision to track changes |
|
2305 | # tracking at the repository level. One could envision to track changes | |
2306 | # to the '.hgtags' file through changegroup apply but that fails to |
|
2306 | # to the '.hgtags' file through changegroup apply but that fails to | |
2307 | # cope with case where transaction expose new heads without changegroup |
|
2307 | # cope with case where transaction expose new heads without changegroup | |
2308 | # being involved (eg: phase movement). |
|
2308 | # being involved (eg: phase movement). | |
2309 | # |
|
2309 | # | |
2310 | # For now, We gate the feature behind a flag since this likely comes |
|
2310 | # For now, We gate the feature behind a flag since this likely comes | |
2311 | # with performance impacts. The current code run more often than needed |
|
2311 | # with performance impacts. The current code run more often than needed | |
2312 | # and do not use caches as much as it could. The current focus is on |
|
2312 | # and do not use caches as much as it could. The current focus is on | |
2313 | # the behavior of the feature so we disable it by default. The flag |
|
2313 | # the behavior of the feature so we disable it by default. The flag | |
2314 | # will be removed when we are happy with the performance impact. |
|
2314 | # will be removed when we are happy with the performance impact. | |
2315 | # |
|
2315 | # | |
2316 | # Once this feature is no longer experimental move the following |
|
2316 | # Once this feature is no longer experimental move the following | |
2317 | # documentation to the appropriate help section: |
|
2317 | # documentation to the appropriate help section: | |
2318 | # |
|
2318 | # | |
2319 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched |
|
2319 | # The ``HG_TAG_MOVED`` variable will be set if the transaction touched | |
2320 | # tags (new or changed or deleted tags). In addition the details of |
|
2320 | # tags (new or changed or deleted tags). In addition the details of | |
2321 | # these changes are made available in a file at: |
|
2321 | # these changes are made available in a file at: | |
2322 | # ``REPOROOT/.hg/changes/tags.changes``. |
|
2322 | # ``REPOROOT/.hg/changes/tags.changes``. | |
2323 | # Make sure you check for HG_TAG_MOVED before reading that file as it |
|
2323 | # Make sure you check for HG_TAG_MOVED before reading that file as it | |
2324 | # might exist from a previous transaction even if no tag were touched |
|
2324 | # might exist from a previous transaction even if no tag were touched | |
2325 | # in this one. Changes are recorded in a line base format:: |
|
2325 | # in this one. Changes are recorded in a line base format:: | |
2326 | # |
|
2326 | # | |
2327 | # <action> <hex-node> <tag-name>\n |
|
2327 | # <action> <hex-node> <tag-name>\n | |
2328 | # |
|
2328 | # | |
2329 | # Actions are defined as follow: |
|
2329 | # Actions are defined as follow: | |
2330 | # "-R": tag is removed, |
|
2330 | # "-R": tag is removed, | |
2331 | # "+A": tag is added, |
|
2331 | # "+A": tag is added, | |
2332 | # "-M": tag is moved (old value), |
|
2332 | # "-M": tag is moved (old value), | |
2333 | # "+M": tag is moved (new value), |
|
2333 | # "+M": tag is moved (new value), | |
2334 | tracktags = lambda x: None |
|
2334 | tracktags = lambda x: None | |
2335 | # experimental config: experimental.hook-track-tags |
|
2335 | # experimental config: experimental.hook-track-tags | |
2336 | shouldtracktags = self.ui.configbool( |
|
2336 | shouldtracktags = self.ui.configbool( | |
2337 | b'experimental', b'hook-track-tags' |
|
2337 | b'experimental', b'hook-track-tags' | |
2338 | ) |
|
2338 | ) | |
2339 | if desc != b'strip' and shouldtracktags: |
|
2339 | if desc != b'strip' and shouldtracktags: | |
2340 | oldheads = self.changelog.headrevs() |
|
2340 | oldheads = self.changelog.headrevs() | |
2341 |
|
2341 | |||
2342 | def tracktags(tr2): |
|
2342 | def tracktags(tr2): | |
2343 | repo = reporef() |
|
2343 | repo = reporef() | |
2344 | assert repo is not None # help pytype |
|
2344 | assert repo is not None # help pytype | |
2345 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) |
|
2345 | oldfnodes = tagsmod.fnoderevs(repo.ui, repo, oldheads) | |
2346 | newheads = repo.changelog.headrevs() |
|
2346 | newheads = repo.changelog.headrevs() | |
2347 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) |
|
2347 | newfnodes = tagsmod.fnoderevs(repo.ui, repo, newheads) | |
2348 | # notes: we compare lists here. |
|
2348 | # notes: we compare lists here. | |
2349 | # As we do it only once buiding set would not be cheaper |
|
2349 | # As we do it only once buiding set would not be cheaper | |
2350 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) |
|
2350 | changes = tagsmod.difftags(repo.ui, repo, oldfnodes, newfnodes) | |
2351 | if changes: |
|
2351 | if changes: | |
2352 | tr2.hookargs[b'tag_moved'] = b'1' |
|
2352 | tr2.hookargs[b'tag_moved'] = b'1' | |
2353 | with repo.vfs( |
|
2353 | with repo.vfs( | |
2354 | b'changes/tags.changes', b'w', atomictemp=True |
|
2354 | b'changes/tags.changes', b'w', atomictemp=True | |
2355 | ) as changesfile: |
|
2355 | ) as changesfile: | |
2356 | # note: we do not register the file to the transaction |
|
2356 | # note: we do not register the file to the transaction | |
2357 | # because we needs it to still exist on the transaction |
|
2357 | # because we needs it to still exist on the transaction | |
2358 | # is close (for txnclose hooks) |
|
2358 | # is close (for txnclose hooks) | |
2359 | tagsmod.writediff(changesfile, changes) |
|
2359 | tagsmod.writediff(changesfile, changes) | |
2360 |
|
2360 | |||
2361 | def validate(tr2): |
|
2361 | def validate(tr2): | |
2362 | """will run pre-closing hooks""" |
|
2362 | """will run pre-closing hooks""" | |
2363 | # XXX the transaction API is a bit lacking here so we take a hacky |
|
2363 | # XXX the transaction API is a bit lacking here so we take a hacky | |
2364 | # path for now |
|
2364 | # path for now | |
2365 | # |
|
2365 | # | |
2366 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' |
|
2366 | # We cannot add this as a "pending" hooks since the 'tr.hookargs' | |
2367 | # dict is copied before these run. In addition we needs the data |
|
2367 | # dict is copied before these run. In addition we needs the data | |
2368 | # available to in memory hooks too. |
|
2368 | # available to in memory hooks too. | |
2369 | # |
|
2369 | # | |
2370 | # Moreover, we also need to make sure this runs before txnclose |
|
2370 | # Moreover, we also need to make sure this runs before txnclose | |
2371 | # hooks and there is no "pending" mechanism that would execute |
|
2371 | # hooks and there is no "pending" mechanism that would execute | |
2372 | # logic only if hooks are about to run. |
|
2372 | # logic only if hooks are about to run. | |
2373 | # |
|
2373 | # | |
2374 | # Fixing this limitation of the transaction is also needed to track |
|
2374 | # Fixing this limitation of the transaction is also needed to track | |
2375 | # other families of changes (bookmarks, phases, obsolescence). |
|
2375 | # other families of changes (bookmarks, phases, obsolescence). | |
2376 | # |
|
2376 | # | |
2377 | # This will have to be fixed before we remove the experimental |
|
2377 | # This will have to be fixed before we remove the experimental | |
2378 | # gating. |
|
2378 | # gating. | |
2379 | tracktags(tr2) |
|
2379 | tracktags(tr2) | |
2380 | repo = reporef() |
|
2380 | repo = reporef() | |
2381 | assert repo is not None # help pytype |
|
2381 | assert repo is not None # help pytype | |
2382 |
|
2382 | |||
2383 | singleheadopt = (b'experimental', b'single-head-per-branch') |
|
2383 | singleheadopt = (b'experimental', b'single-head-per-branch') | |
2384 | singlehead = repo.ui.configbool(*singleheadopt) |
|
2384 | singlehead = repo.ui.configbool(*singleheadopt) | |
2385 | if singlehead: |
|
2385 | if singlehead: | |
2386 | singleheadsub = repo.ui.configsuboptions(*singleheadopt)[1] |
|
2386 | singleheadsub = repo.ui.configsuboptions(*singleheadopt)[1] | |
2387 | accountclosed = singleheadsub.get( |
|
2387 | accountclosed = singleheadsub.get( | |
2388 | b"account-closed-heads", False |
|
2388 | b"account-closed-heads", False | |
2389 | ) |
|
2389 | ) | |
2390 | if singleheadsub.get(b"public-changes-only", False): |
|
2390 | if singleheadsub.get(b"public-changes-only", False): | |
2391 | filtername = b"immutable" |
|
2391 | filtername = b"immutable" | |
2392 | else: |
|
2392 | else: | |
2393 | filtername = b"visible" |
|
2393 | filtername = b"visible" | |
2394 | scmutil.enforcesinglehead( |
|
2394 | scmutil.enforcesinglehead( | |
2395 | repo, tr2, desc, accountclosed, filtername |
|
2395 | repo, tr2, desc, accountclosed, filtername | |
2396 | ) |
|
2396 | ) | |
2397 | if hook.hashook(repo.ui, b'pretxnclose-bookmark'): |
|
2397 | if hook.hashook(repo.ui, b'pretxnclose-bookmark'): | |
2398 | for name, (old, new) in sorted( |
|
2398 | for name, (old, new) in sorted( | |
2399 | tr.changes[b'bookmarks'].items() |
|
2399 | tr.changes[b'bookmarks'].items() | |
2400 | ): |
|
2400 | ): | |
2401 | args = tr.hookargs.copy() |
|
2401 | args = tr.hookargs.copy() | |
2402 | args.update(bookmarks.preparehookargs(name, old, new)) |
|
2402 | args.update(bookmarks.preparehookargs(name, old, new)) | |
2403 | repo.hook( |
|
2403 | repo.hook( | |
2404 | b'pretxnclose-bookmark', |
|
2404 | b'pretxnclose-bookmark', | |
2405 | throw=True, |
|
2405 | throw=True, | |
2406 | **pycompat.strkwargs(args) |
|
2406 | **pycompat.strkwargs(args) | |
2407 | ) |
|
2407 | ) | |
2408 | if hook.hashook(repo.ui, b'pretxnclose-phase'): |
|
2408 | if hook.hashook(repo.ui, b'pretxnclose-phase'): | |
2409 | cl = repo.unfiltered().changelog |
|
2409 | cl = repo.unfiltered().changelog | |
2410 | for revs, (old, new) in tr.changes[b'phases']: |
|
2410 | for revs, (old, new) in tr.changes[b'phases']: | |
2411 | for rev in revs: |
|
2411 | for rev in revs: | |
2412 | args = tr.hookargs.copy() |
|
2412 | args = tr.hookargs.copy() | |
2413 | node = hex(cl.node(rev)) |
|
2413 | node = hex(cl.node(rev)) | |
2414 | args.update(phases.preparehookargs(node, old, new)) |
|
2414 | args.update(phases.preparehookargs(node, old, new)) | |
2415 | repo.hook( |
|
2415 | repo.hook( | |
2416 | b'pretxnclose-phase', |
|
2416 | b'pretxnclose-phase', | |
2417 | throw=True, |
|
2417 | throw=True, | |
2418 | **pycompat.strkwargs(args) |
|
2418 | **pycompat.strkwargs(args) | |
2419 | ) |
|
2419 | ) | |
2420 |
|
2420 | |||
2421 | repo.hook( |
|
2421 | repo.hook( | |
2422 | b'pretxnclose', throw=True, **pycompat.strkwargs(tr.hookargs) |
|
2422 | b'pretxnclose', throw=True, **pycompat.strkwargs(tr.hookargs) | |
2423 | ) |
|
2423 | ) | |
2424 |
|
2424 | |||
2425 | def releasefn(tr, success): |
|
2425 | def releasefn(tr, success): | |
2426 | repo = reporef() |
|
2426 | repo = reporef() | |
2427 | if repo is None: |
|
2427 | if repo is None: | |
2428 | # If the repo has been GC'd (and this release function is being |
|
2428 | # If the repo has been GC'd (and this release function is being | |
2429 | # called from transaction.__del__), there's not much we can do, |
|
2429 | # called from transaction.__del__), there's not much we can do, | |
2430 | # so just leave the unfinished transaction there and let the |
|
2430 | # so just leave the unfinished transaction there and let the | |
2431 | # user run `hg recover`. |
|
2431 | # user run `hg recover`. | |
2432 | return |
|
2432 | return | |
2433 | if success: |
|
2433 | if success: | |
2434 | # this should be explicitly invoked here, because |
|
2434 | # this should be explicitly invoked here, because | |
2435 | # in-memory changes aren't written out at closing |
|
2435 | # in-memory changes aren't written out at closing | |
2436 | # transaction, if tr.addfilegenerator (via |
|
2436 | # transaction, if tr.addfilegenerator (via | |
2437 | # dirstate.write or so) isn't invoked while |
|
2437 | # dirstate.write or so) isn't invoked while | |
2438 | # transaction running |
|
2438 | # transaction running | |
2439 | repo.dirstate.write(None) |
|
2439 | repo.dirstate.write(None) | |
2440 | else: |
|
2440 | else: | |
2441 | # discard all changes (including ones already written |
|
2441 | # discard all changes (including ones already written | |
2442 | # out) in this transaction |
|
2442 | # out) in this transaction | |
2443 | narrowspec.restorebackup(self, b'journal.narrowspec') |
|
2443 | narrowspec.restorebackup(self, b'journal.narrowspec') | |
2444 | narrowspec.restorewcbackup(self, b'journal.narrowspec.dirstate') |
|
2444 | narrowspec.restorewcbackup(self, b'journal.narrowspec.dirstate') | |
2445 | repo.dirstate.restorebackup(None, b'journal.dirstate') |
|
2445 | repo.dirstate.restorebackup(None, b'journal.dirstate') | |
2446 |
|
2446 | |||
2447 | repo.invalidate(clearfilecache=True) |
|
2447 | repo.invalidate(clearfilecache=True) | |
2448 |
|
2448 | |||
2449 | tr = transaction.transaction( |
|
2449 | tr = transaction.transaction( | |
2450 | rp, |
|
2450 | rp, | |
2451 | self.svfs, |
|
2451 | self.svfs, | |
2452 | vfsmap, |
|
2452 | vfsmap, | |
2453 | b"journal", |
|
2453 | b"journal", | |
2454 | b"undo", |
|
2454 | b"undo", | |
2455 | aftertrans(renames), |
|
2455 | aftertrans(renames), | |
2456 | self.store.createmode, |
|
2456 | self.store.createmode, | |
2457 | validator=validate, |
|
2457 | validator=validate, | |
2458 | releasefn=releasefn, |
|
2458 | releasefn=releasefn, | |
2459 | checkambigfiles=_cachedfiles, |
|
2459 | checkambigfiles=_cachedfiles, | |
2460 | name=desc, |
|
2460 | name=desc, | |
2461 | ) |
|
2461 | ) | |
2462 | tr.changes[b'origrepolen'] = len(self) |
|
2462 | tr.changes[b'origrepolen'] = len(self) | |
2463 | tr.changes[b'obsmarkers'] = set() |
|
2463 | tr.changes[b'obsmarkers'] = set() | |
2464 | tr.changes[b'phases'] = [] |
|
2464 | tr.changes[b'phases'] = [] | |
2465 | tr.changes[b'bookmarks'] = {} |
|
2465 | tr.changes[b'bookmarks'] = {} | |
2466 |
|
2466 | |||
2467 | tr.hookargs[b'txnid'] = txnid |
|
2467 | tr.hookargs[b'txnid'] = txnid | |
2468 | tr.hookargs[b'txnname'] = desc |
|
2468 | tr.hookargs[b'txnname'] = desc | |
2469 | tr.hookargs[b'changes'] = tr.changes |
|
2469 | tr.hookargs[b'changes'] = tr.changes | |
2470 | # note: writing the fncache only during finalize mean that the file is |
|
2470 | # note: writing the fncache only during finalize mean that the file is | |
2471 | # outdated when running hooks. As fncache is used for streaming clone, |
|
2471 | # outdated when running hooks. As fncache is used for streaming clone, | |
2472 | # this is not expected to break anything that happen during the hooks. |
|
2472 | # this is not expected to break anything that happen during the hooks. | |
2473 | tr.addfinalize(b'flush-fncache', self.store.write) |
|
2473 | tr.addfinalize(b'flush-fncache', self.store.write) | |
2474 |
|
2474 | |||
2475 | def txnclosehook(tr2): |
|
2475 | def txnclosehook(tr2): | |
2476 | """To be run if transaction is successful, will schedule a hook run""" |
|
2476 | """To be run if transaction is successful, will schedule a hook run""" | |
2477 | # Don't reference tr2 in hook() so we don't hold a reference. |
|
2477 | # Don't reference tr2 in hook() so we don't hold a reference. | |
2478 | # This reduces memory consumption when there are multiple |
|
2478 | # This reduces memory consumption when there are multiple | |
2479 | # transactions per lock. This can likely go away if issue5045 |
|
2479 | # transactions per lock. This can likely go away if issue5045 | |
2480 | # fixes the function accumulation. |
|
2480 | # fixes the function accumulation. | |
2481 | hookargs = tr2.hookargs |
|
2481 | hookargs = tr2.hookargs | |
2482 |
|
2482 | |||
2483 | def hookfunc(unused_success): |
|
2483 | def hookfunc(unused_success): | |
2484 | repo = reporef() |
|
2484 | repo = reporef() | |
2485 | assert repo is not None # help pytype |
|
2485 | assert repo is not None # help pytype | |
2486 |
|
2486 | |||
2487 | if hook.hashook(repo.ui, b'txnclose-bookmark'): |
|
2487 | if hook.hashook(repo.ui, b'txnclose-bookmark'): | |
2488 | bmchanges = sorted(tr.changes[b'bookmarks'].items()) |
|
2488 | bmchanges = sorted(tr.changes[b'bookmarks'].items()) | |
2489 | for name, (old, new) in bmchanges: |
|
2489 | for name, (old, new) in bmchanges: | |
2490 | args = tr.hookargs.copy() |
|
2490 | args = tr.hookargs.copy() | |
2491 | args.update(bookmarks.preparehookargs(name, old, new)) |
|
2491 | args.update(bookmarks.preparehookargs(name, old, new)) | |
2492 | repo.hook( |
|
2492 | repo.hook( | |
2493 | b'txnclose-bookmark', |
|
2493 | b'txnclose-bookmark', | |
2494 | throw=False, |
|
2494 | throw=False, | |
2495 | **pycompat.strkwargs(args) |
|
2495 | **pycompat.strkwargs(args) | |
2496 | ) |
|
2496 | ) | |
2497 |
|
2497 | |||
2498 | if hook.hashook(repo.ui, b'txnclose-phase'): |
|
2498 | if hook.hashook(repo.ui, b'txnclose-phase'): | |
2499 | cl = repo.unfiltered().changelog |
|
2499 | cl = repo.unfiltered().changelog | |
2500 | phasemv = sorted( |
|
2500 | phasemv = sorted( | |
2501 | tr.changes[b'phases'], key=lambda r: r[0][0] |
|
2501 | tr.changes[b'phases'], key=lambda r: r[0][0] | |
2502 | ) |
|
2502 | ) | |
2503 | for revs, (old, new) in phasemv: |
|
2503 | for revs, (old, new) in phasemv: | |
2504 | for rev in revs: |
|
2504 | for rev in revs: | |
2505 | args = tr.hookargs.copy() |
|
2505 | args = tr.hookargs.copy() | |
2506 | node = hex(cl.node(rev)) |
|
2506 | node = hex(cl.node(rev)) | |
2507 | args.update(phases.preparehookargs(node, old, new)) |
|
2507 | args.update(phases.preparehookargs(node, old, new)) | |
2508 | repo.hook( |
|
2508 | repo.hook( | |
2509 | b'txnclose-phase', |
|
2509 | b'txnclose-phase', | |
2510 | throw=False, |
|
2510 | throw=False, | |
2511 | **pycompat.strkwargs(args) |
|
2511 | **pycompat.strkwargs(args) | |
2512 | ) |
|
2512 | ) | |
2513 |
|
2513 | |||
2514 | repo.hook( |
|
2514 | repo.hook( | |
2515 | b'txnclose', throw=False, **pycompat.strkwargs(hookargs) |
|
2515 | b'txnclose', throw=False, **pycompat.strkwargs(hookargs) | |
2516 | ) |
|
2516 | ) | |
2517 |
|
2517 | |||
2518 | repo = reporef() |
|
2518 | repo = reporef() | |
2519 | assert repo is not None # help pytype |
|
2519 | assert repo is not None # help pytype | |
2520 | repo._afterlock(hookfunc) |
|
2520 | repo._afterlock(hookfunc) | |
2521 |
|
2521 | |||
2522 | tr.addfinalize(b'txnclose-hook', txnclosehook) |
|
2522 | tr.addfinalize(b'txnclose-hook', txnclosehook) | |
2523 | # Include a leading "-" to make it happen before the transaction summary |
|
2523 | # Include a leading "-" to make it happen before the transaction summary | |
2524 | # reports registered via scmutil.registersummarycallback() whose names |
|
2524 | # reports registered via scmutil.registersummarycallback() whose names | |
2525 | # are 00-txnreport etc. That way, the caches will be warm when the |
|
2525 | # are 00-txnreport etc. That way, the caches will be warm when the | |
2526 | # callbacks run. |
|
2526 | # callbacks run. | |
2527 | tr.addpostclose(b'-warm-cache', self._buildcacheupdater(tr)) |
|
2527 | tr.addpostclose(b'-warm-cache', self._buildcacheupdater(tr)) | |
2528 |
|
2528 | |||
2529 | def txnaborthook(tr2): |
|
2529 | def txnaborthook(tr2): | |
2530 | """To be run if transaction is aborted""" |
|
2530 | """To be run if transaction is aborted""" | |
2531 | repo = reporef() |
|
2531 | repo = reporef() | |
2532 | assert repo is not None # help pytype |
|
2532 | assert repo is not None # help pytype | |
2533 | repo.hook( |
|
2533 | repo.hook( | |
2534 | b'txnabort', throw=False, **pycompat.strkwargs(tr2.hookargs) |
|
2534 | b'txnabort', throw=False, **pycompat.strkwargs(tr2.hookargs) | |
2535 | ) |
|
2535 | ) | |
2536 |
|
2536 | |||
2537 | tr.addabort(b'txnabort-hook', txnaborthook) |
|
2537 | tr.addabort(b'txnabort-hook', txnaborthook) | |
2538 | # avoid eager cache invalidation. in-memory data should be identical |
|
2538 | # avoid eager cache invalidation. in-memory data should be identical | |
2539 | # to stored data if transaction has no error. |
|
2539 | # to stored data if transaction has no error. | |
2540 | tr.addpostclose(b'refresh-filecachestats', self._refreshfilecachestats) |
|
2540 | tr.addpostclose(b'refresh-filecachestats', self._refreshfilecachestats) | |
2541 | self._transref = weakref.ref(tr) |
|
2541 | self._transref = weakref.ref(tr) | |
2542 | scmutil.registersummarycallback(self, tr, desc) |
|
2542 | scmutil.registersummarycallback(self, tr, desc) | |
2543 | return tr |
|
2543 | return tr | |
2544 |
|
2544 | |||
2545 | def _journalfiles(self): |
|
2545 | def _journalfiles(self): | |
2546 | return ( |
|
2546 | return ( | |
2547 | (self.svfs, b'journal'), |
|
2547 | (self.svfs, b'journal'), | |
2548 | (self.svfs, b'journal.narrowspec'), |
|
2548 | (self.svfs, b'journal.narrowspec'), | |
2549 | (self.vfs, b'journal.narrowspec.dirstate'), |
|
2549 | (self.vfs, b'journal.narrowspec.dirstate'), | |
2550 | (self.vfs, b'journal.dirstate'), |
|
2550 | (self.vfs, b'journal.dirstate'), | |
2551 | (self.vfs, b'journal.branch'), |
|
2551 | (self.vfs, b'journal.branch'), | |
2552 | (self.vfs, b'journal.desc'), |
|
2552 | (self.vfs, b'journal.desc'), | |
2553 | (bookmarks.bookmarksvfs(self), b'journal.bookmarks'), |
|
2553 | (bookmarks.bookmarksvfs(self), b'journal.bookmarks'), | |
2554 | (self.svfs, b'journal.phaseroots'), |
|
2554 | (self.svfs, b'journal.phaseroots'), | |
2555 | ) |
|
2555 | ) | |
2556 |
|
2556 | |||
2557 | def undofiles(self): |
|
2557 | def undofiles(self): | |
2558 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] |
|
2558 | return [(vfs, undoname(x)) for vfs, x in self._journalfiles()] | |
2559 |
|
2559 | |||
2560 | @unfilteredmethod |
|
2560 | @unfilteredmethod | |
2561 | def _writejournal(self, desc): |
|
2561 | def _writejournal(self, desc): | |
2562 | self.dirstate.savebackup(None, b'journal.dirstate') |
|
2562 | self.dirstate.savebackup(None, b'journal.dirstate') | |
2563 | narrowspec.savewcbackup(self, b'journal.narrowspec.dirstate') |
|
2563 | narrowspec.savewcbackup(self, b'journal.narrowspec.dirstate') | |
2564 | narrowspec.savebackup(self, b'journal.narrowspec') |
|
2564 | narrowspec.savebackup(self, b'journal.narrowspec') | |
2565 | self.vfs.write( |
|
2565 | self.vfs.write( | |
2566 | b"journal.branch", encoding.fromlocal(self.dirstate.branch()) |
|
2566 | b"journal.branch", encoding.fromlocal(self.dirstate.branch()) | |
2567 | ) |
|
2567 | ) | |
2568 | self.vfs.write(b"journal.desc", b"%d\n%s\n" % (len(self), desc)) |
|
2568 | self.vfs.write(b"journal.desc", b"%d\n%s\n" % (len(self), desc)) | |
2569 | bookmarksvfs = bookmarks.bookmarksvfs(self) |
|
2569 | bookmarksvfs = bookmarks.bookmarksvfs(self) | |
2570 | bookmarksvfs.write( |
|
2570 | bookmarksvfs.write( | |
2571 | b"journal.bookmarks", bookmarksvfs.tryread(b"bookmarks") |
|
2571 | b"journal.bookmarks", bookmarksvfs.tryread(b"bookmarks") | |
2572 | ) |
|
2572 | ) | |
2573 | self.svfs.write(b"journal.phaseroots", self.svfs.tryread(b"phaseroots")) |
|
2573 | self.svfs.write(b"journal.phaseroots", self.svfs.tryread(b"phaseroots")) | |
2574 |
|
2574 | |||
2575 | def recover(self): |
|
2575 | def recover(self): | |
2576 | with self.lock(): |
|
2576 | with self.lock(): | |
2577 | if self.svfs.exists(b"journal"): |
|
2577 | if self.svfs.exists(b"journal"): | |
2578 | self.ui.status(_(b"rolling back interrupted transaction\n")) |
|
2578 | self.ui.status(_(b"rolling back interrupted transaction\n")) | |
2579 | vfsmap = { |
|
2579 | vfsmap = { | |
2580 | b'': self.svfs, |
|
2580 | b'': self.svfs, | |
2581 | b'plain': self.vfs, |
|
2581 | b'plain': self.vfs, | |
2582 | } |
|
2582 | } | |
2583 | transaction.rollback( |
|
2583 | transaction.rollback( | |
2584 | self.svfs, |
|
2584 | self.svfs, | |
2585 | vfsmap, |
|
2585 | vfsmap, | |
2586 | b"journal", |
|
2586 | b"journal", | |
2587 | self.ui.warn, |
|
2587 | self.ui.warn, | |
2588 | checkambigfiles=_cachedfiles, |
|
2588 | checkambigfiles=_cachedfiles, | |
2589 | ) |
|
2589 | ) | |
2590 | self.invalidate() |
|
2590 | self.invalidate() | |
2591 | return True |
|
2591 | return True | |
2592 | else: |
|
2592 | else: | |
2593 | self.ui.warn(_(b"no interrupted transaction available\n")) |
|
2593 | self.ui.warn(_(b"no interrupted transaction available\n")) | |
2594 | return False |
|
2594 | return False | |
2595 |
|
2595 | |||
2596 | def rollback(self, dryrun=False, force=False): |
|
2596 | def rollback(self, dryrun=False, force=False): | |
2597 | wlock = lock = dsguard = None |
|
2597 | wlock = lock = dsguard = None | |
2598 | try: |
|
2598 | try: | |
2599 | wlock = self.wlock() |
|
2599 | wlock = self.wlock() | |
2600 | lock = self.lock() |
|
2600 | lock = self.lock() | |
2601 | if self.svfs.exists(b"undo"): |
|
2601 | if self.svfs.exists(b"undo"): | |
2602 | dsguard = dirstateguard.dirstateguard(self, b'rollback') |
|
2602 | dsguard = dirstateguard.dirstateguard(self, b'rollback') | |
2603 |
|
2603 | |||
2604 | return self._rollback(dryrun, force, dsguard) |
|
2604 | return self._rollback(dryrun, force, dsguard) | |
2605 | else: |
|
2605 | else: | |
2606 | self.ui.warn(_(b"no rollback information available\n")) |
|
2606 | self.ui.warn(_(b"no rollback information available\n")) | |
2607 | return 1 |
|
2607 | return 1 | |
2608 | finally: |
|
2608 | finally: | |
2609 | release(dsguard, lock, wlock) |
|
2609 | release(dsguard, lock, wlock) | |
2610 |
|
2610 | |||
2611 | @unfilteredmethod # Until we get smarter cache management |
|
2611 | @unfilteredmethod # Until we get smarter cache management | |
2612 | def _rollback(self, dryrun, force, dsguard): |
|
2612 | def _rollback(self, dryrun, force, dsguard): | |
2613 | ui = self.ui |
|
2613 | ui = self.ui | |
2614 | try: |
|
2614 | try: | |
2615 | args = self.vfs.read(b'undo.desc').splitlines() |
|
2615 | args = self.vfs.read(b'undo.desc').splitlines() | |
2616 | (oldlen, desc, detail) = (int(args[0]), args[1], None) |
|
2616 | (oldlen, desc, detail) = (int(args[0]), args[1], None) | |
2617 | if len(args) >= 3: |
|
2617 | if len(args) >= 3: | |
2618 | detail = args[2] |
|
2618 | detail = args[2] | |
2619 | oldtip = oldlen - 1 |
|
2619 | oldtip = oldlen - 1 | |
2620 |
|
2620 | |||
2621 | if detail and ui.verbose: |
|
2621 | if detail and ui.verbose: | |
2622 | msg = _( |
|
2622 | msg = _( | |
2623 | b'repository tip rolled back to revision %d' |
|
2623 | b'repository tip rolled back to revision %d' | |
2624 | b' (undo %s: %s)\n' |
|
2624 | b' (undo %s: %s)\n' | |
2625 | ) % (oldtip, desc, detail) |
|
2625 | ) % (oldtip, desc, detail) | |
2626 | else: |
|
2626 | else: | |
2627 | msg = _( |
|
2627 | msg = _( | |
2628 | b'repository tip rolled back to revision %d (undo %s)\n' |
|
2628 | b'repository tip rolled back to revision %d (undo %s)\n' | |
2629 | ) % (oldtip, desc) |
|
2629 | ) % (oldtip, desc) | |
2630 | except IOError: |
|
2630 | except IOError: | |
2631 | msg = _(b'rolling back unknown transaction\n') |
|
2631 | msg = _(b'rolling back unknown transaction\n') | |
2632 | desc = None |
|
2632 | desc = None | |
2633 |
|
2633 | |||
2634 | if not force and self[b'.'] != self[b'tip'] and desc == b'commit': |
|
2634 | if not force and self[b'.'] != self[b'tip'] and desc == b'commit': | |
2635 | raise error.Abort( |
|
2635 | raise error.Abort( | |
2636 | _( |
|
2636 | _( | |
2637 | b'rollback of last commit while not checked out ' |
|
2637 | b'rollback of last commit while not checked out ' | |
2638 | b'may lose data' |
|
2638 | b'may lose data' | |
2639 | ), |
|
2639 | ), | |
2640 | hint=_(b'use -f to force'), |
|
2640 | hint=_(b'use -f to force'), | |
2641 | ) |
|
2641 | ) | |
2642 |
|
2642 | |||
2643 | ui.status(msg) |
|
2643 | ui.status(msg) | |
2644 | if dryrun: |
|
2644 | if dryrun: | |
2645 | return 0 |
|
2645 | return 0 | |
2646 |
|
2646 | |||
2647 | parents = self.dirstate.parents() |
|
2647 | parents = self.dirstate.parents() | |
2648 | self.destroying() |
|
2648 | self.destroying() | |
2649 | vfsmap = {b'plain': self.vfs, b'': self.svfs} |
|
2649 | vfsmap = {b'plain': self.vfs, b'': self.svfs} | |
2650 | transaction.rollback( |
|
2650 | transaction.rollback( | |
2651 | self.svfs, vfsmap, b'undo', ui.warn, checkambigfiles=_cachedfiles |
|
2651 | self.svfs, vfsmap, b'undo', ui.warn, checkambigfiles=_cachedfiles | |
2652 | ) |
|
2652 | ) | |
2653 | bookmarksvfs = bookmarks.bookmarksvfs(self) |
|
2653 | bookmarksvfs = bookmarks.bookmarksvfs(self) | |
2654 | if bookmarksvfs.exists(b'undo.bookmarks'): |
|
2654 | if bookmarksvfs.exists(b'undo.bookmarks'): | |
2655 | bookmarksvfs.rename( |
|
2655 | bookmarksvfs.rename( | |
2656 | b'undo.bookmarks', b'bookmarks', checkambig=True |
|
2656 | b'undo.bookmarks', b'bookmarks', checkambig=True | |
2657 | ) |
|
2657 | ) | |
2658 | if self.svfs.exists(b'undo.phaseroots'): |
|
2658 | if self.svfs.exists(b'undo.phaseroots'): | |
2659 | self.svfs.rename(b'undo.phaseroots', b'phaseroots', checkambig=True) |
|
2659 | self.svfs.rename(b'undo.phaseroots', b'phaseroots', checkambig=True) | |
2660 | self.invalidate() |
|
2660 | self.invalidate() | |
2661 |
|
2661 | |||
2662 | has_node = self.changelog.index.has_node |
|
2662 | has_node = self.changelog.index.has_node | |
2663 | parentgone = any(not has_node(p) for p in parents) |
|
2663 | parentgone = any(not has_node(p) for p in parents) | |
2664 | if parentgone: |
|
2664 | if parentgone: | |
2665 | # prevent dirstateguard from overwriting already restored one |
|
2665 | # prevent dirstateguard from overwriting already restored one | |
2666 | dsguard.close() |
|
2666 | dsguard.close() | |
2667 |
|
2667 | |||
2668 | narrowspec.restorebackup(self, b'undo.narrowspec') |
|
2668 | narrowspec.restorebackup(self, b'undo.narrowspec') | |
2669 | narrowspec.restorewcbackup(self, b'undo.narrowspec.dirstate') |
|
2669 | narrowspec.restorewcbackup(self, b'undo.narrowspec.dirstate') | |
2670 | self.dirstate.restorebackup(None, b'undo.dirstate') |
|
2670 | self.dirstate.restorebackup(None, b'undo.dirstate') | |
2671 | try: |
|
2671 | try: | |
2672 | branch = self.vfs.read(b'undo.branch') |
|
2672 | branch = self.vfs.read(b'undo.branch') | |
2673 | self.dirstate.setbranch(encoding.tolocal(branch)) |
|
2673 | self.dirstate.setbranch(encoding.tolocal(branch)) | |
2674 | except IOError: |
|
2674 | except IOError: | |
2675 | ui.warn( |
|
2675 | ui.warn( | |
2676 | _( |
|
2676 | _( | |
2677 | b'named branch could not be reset: ' |
|
2677 | b'named branch could not be reset: ' | |
2678 | b'current branch is still \'%s\'\n' |
|
2678 | b'current branch is still \'%s\'\n' | |
2679 | ) |
|
2679 | ) | |
2680 | % self.dirstate.branch() |
|
2680 | % self.dirstate.branch() | |
2681 | ) |
|
2681 | ) | |
2682 |
|
2682 | |||
2683 | parents = tuple([p.rev() for p in self[None].parents()]) |
|
2683 | parents = tuple([p.rev() for p in self[None].parents()]) | |
2684 | if len(parents) > 1: |
|
2684 | if len(parents) > 1: | |
2685 | ui.status( |
|
2685 | ui.status( | |
2686 | _( |
|
2686 | _( | |
2687 | b'working directory now based on ' |
|
2687 | b'working directory now based on ' | |
2688 | b'revisions %d and %d\n' |
|
2688 | b'revisions %d and %d\n' | |
2689 | ) |
|
2689 | ) | |
2690 | % parents |
|
2690 | % parents | |
2691 | ) |
|
2691 | ) | |
2692 | else: |
|
2692 | else: | |
2693 | ui.status( |
|
2693 | ui.status( | |
2694 | _(b'working directory now based on revision %d\n') % parents |
|
2694 | _(b'working directory now based on revision %d\n') % parents | |
2695 | ) |
|
2695 | ) | |
2696 | mergestatemod.mergestate.clean(self) |
|
2696 | mergestatemod.mergestate.clean(self) | |
2697 |
|
2697 | |||
2698 | # TODO: if we know which new heads may result from this rollback, pass |
|
2698 | # TODO: if we know which new heads may result from this rollback, pass | |
2699 | # them to destroy(), which will prevent the branchhead cache from being |
|
2699 | # them to destroy(), which will prevent the branchhead cache from being | |
2700 | # invalidated. |
|
2700 | # invalidated. | |
2701 | self.destroyed() |
|
2701 | self.destroyed() | |
2702 | return 0 |
|
2702 | return 0 | |
2703 |
|
2703 | |||
2704 | def _buildcacheupdater(self, newtransaction): |
|
2704 | def _buildcacheupdater(self, newtransaction): | |
2705 | """called during transaction to build the callback updating cache |
|
2705 | """called during transaction to build the callback updating cache | |
2706 |
|
2706 | |||
2707 | Lives on the repository to help extension who might want to augment |
|
2707 | Lives on the repository to help extension who might want to augment | |
2708 | this logic. For this purpose, the created transaction is passed to the |
|
2708 | this logic. For this purpose, the created transaction is passed to the | |
2709 | method. |
|
2709 | method. | |
2710 | """ |
|
2710 | """ | |
2711 | # we must avoid cyclic reference between repo and transaction. |
|
2711 | # we must avoid cyclic reference between repo and transaction. | |
2712 | reporef = weakref.ref(self) |
|
2712 | reporef = weakref.ref(self) | |
2713 |
|
2713 | |||
2714 | def updater(tr): |
|
2714 | def updater(tr): | |
2715 | repo = reporef() |
|
2715 | repo = reporef() | |
2716 | assert repo is not None # help pytype |
|
2716 | assert repo is not None # help pytype | |
2717 | repo.updatecaches(tr) |
|
2717 | repo.updatecaches(tr) | |
2718 |
|
2718 | |||
2719 | return updater |
|
2719 | return updater | |
2720 |
|
2720 | |||
2721 | @unfilteredmethod |
|
2721 | @unfilteredmethod | |
2722 | def updatecaches(self, tr=None, full=False): |
|
2722 | def updatecaches(self, tr=None, full=False): | |
2723 | """warm appropriate caches |
|
2723 | """warm appropriate caches | |
2724 |
|
2724 | |||
2725 | If this function is called after a transaction closed. The transaction |
|
2725 | If this function is called after a transaction closed. The transaction | |
2726 | will be available in the 'tr' argument. This can be used to selectively |
|
2726 | will be available in the 'tr' argument. This can be used to selectively | |
2727 | update caches relevant to the changes in that transaction. |
|
2727 | update caches relevant to the changes in that transaction. | |
2728 |
|
2728 | |||
2729 | If 'full' is set, make sure all caches the function knows about have |
|
2729 | If 'full' is set, make sure all caches the function knows about have | |
2730 | up-to-date data. Even the ones usually loaded more lazily. |
|
2730 | up-to-date data. Even the ones usually loaded more lazily. | |
2731 | """ |
|
2731 | """ | |
2732 | if tr is not None and tr.hookargs.get(b'source') == b'strip': |
|
2732 | if tr is not None and tr.hookargs.get(b'source') == b'strip': | |
2733 | # During strip, many caches are invalid but |
|
2733 | # During strip, many caches are invalid but | |
2734 | # later call to `destroyed` will refresh them. |
|
2734 | # later call to `destroyed` will refresh them. | |
2735 | return |
|
2735 | return | |
2736 |
|
2736 | |||
2737 | if tr is None or tr.changes[b'origrepolen'] < len(self): |
|
2737 | if tr is None or tr.changes[b'origrepolen'] < len(self): | |
2738 | # accessing the 'served' branchmap should refresh all the others, |
|
2738 | # accessing the 'served' branchmap should refresh all the others, | |
2739 | self.ui.debug(b'updating the branch cache\n') |
|
2739 | self.ui.debug(b'updating the branch cache\n') | |
2740 | self.filtered(b'served').branchmap() |
|
2740 | self.filtered(b'served').branchmap() | |
2741 | self.filtered(b'served.hidden').branchmap() |
|
2741 | self.filtered(b'served.hidden').branchmap() | |
2742 |
|
2742 | |||
2743 | if full: |
|
2743 | if full: | |
2744 | unfi = self.unfiltered() |
|
2744 | unfi = self.unfiltered() | |
2745 |
|
2745 | |||
2746 | self.changelog.update_caches(transaction=tr) |
|
2746 | self.changelog.update_caches(transaction=tr) | |
2747 | self.manifestlog.update_caches(transaction=tr) |
|
2747 | self.manifestlog.update_caches(transaction=tr) | |
2748 |
|
2748 | |||
2749 | rbc = unfi.revbranchcache() |
|
2749 | rbc = unfi.revbranchcache() | |
2750 | for r in unfi.changelog: |
|
2750 | for r in unfi.changelog: | |
2751 | rbc.branchinfo(r) |
|
2751 | rbc.branchinfo(r) | |
2752 | rbc.write() |
|
2752 | rbc.write() | |
2753 |
|
2753 | |||
2754 | # ensure the working copy parents are in the manifestfulltextcache |
|
2754 | # ensure the working copy parents are in the manifestfulltextcache | |
2755 | for ctx in self[b'.'].parents(): |
|
2755 | for ctx in self[b'.'].parents(): | |
2756 | ctx.manifest() # accessing the manifest is enough |
|
2756 | ctx.manifest() # accessing the manifest is enough | |
2757 |
|
2757 | |||
2758 | # accessing fnode cache warms the cache |
|
2758 | # accessing fnode cache warms the cache | |
2759 | tagsmod.fnoderevs(self.ui, unfi, unfi.changelog.revs()) |
|
2759 | tagsmod.fnoderevs(self.ui, unfi, unfi.changelog.revs()) | |
2760 | # accessing tags warm the cache |
|
2760 | # accessing tags warm the cache | |
2761 | self.tags() |
|
2761 | self.tags() | |
2762 | self.filtered(b'served').tags() |
|
2762 | self.filtered(b'served').tags() | |
2763 |
|
2763 | |||
2764 | # The `full` arg is documented as updating even the lazily-loaded |
|
2764 | # The `full` arg is documented as updating even the lazily-loaded | |
2765 | # caches immediately, so we're forcing a write to cause these caches |
|
2765 | # caches immediately, so we're forcing a write to cause these caches | |
2766 | # to be warmed up even if they haven't explicitly been requested |
|
2766 | # to be warmed up even if they haven't explicitly been requested | |
2767 | # yet (if they've never been used by hg, they won't ever have been |
|
2767 | # yet (if they've never been used by hg, they won't ever have been | |
2768 | # written, even if they're a subset of another kind of cache that |
|
2768 | # written, even if they're a subset of another kind of cache that | |
2769 | # *has* been used). |
|
2769 | # *has* been used). | |
2770 | for filt in repoview.filtertable.keys(): |
|
2770 | for filt in repoview.filtertable.keys(): | |
2771 | filtered = self.filtered(filt) |
|
2771 | filtered = self.filtered(filt) | |
2772 | filtered.branchmap().write(filtered) |
|
2772 | filtered.branchmap().write(filtered) | |
2773 |
|
2773 | |||
2774 | def invalidatecaches(self): |
|
2774 | def invalidatecaches(self): | |
2775 |
|
2775 | |||
2776 | if '_tagscache' in vars(self): |
|
2776 | if '_tagscache' in vars(self): | |
2777 | # can't use delattr on proxy |
|
2777 | # can't use delattr on proxy | |
2778 | del self.__dict__['_tagscache'] |
|
2778 | del self.__dict__['_tagscache'] | |
2779 |
|
2779 | |||
2780 | self._branchcaches.clear() |
|
2780 | self._branchcaches.clear() | |
2781 | self.invalidatevolatilesets() |
|
2781 | self.invalidatevolatilesets() | |
2782 | self._sparsesignaturecache.clear() |
|
2782 | self._sparsesignaturecache.clear() | |
2783 |
|
2783 | |||
2784 | def invalidatevolatilesets(self): |
|
2784 | def invalidatevolatilesets(self): | |
2785 | self.filteredrevcache.clear() |
|
2785 | self.filteredrevcache.clear() | |
2786 | obsolete.clearobscaches(self) |
|
2786 | obsolete.clearobscaches(self) | |
2787 | self._quick_access_changeid_invalidate() |
|
2787 | self._quick_access_changeid_invalidate() | |
2788 |
|
2788 | |||
2789 | def invalidatedirstate(self): |
|
2789 | def invalidatedirstate(self): | |
2790 | """Invalidates the dirstate, causing the next call to dirstate |
|
2790 | """Invalidates the dirstate, causing the next call to dirstate | |
2791 | to check if it was modified since the last time it was read, |
|
2791 | to check if it was modified since the last time it was read, | |
2792 | rereading it if it has. |
|
2792 | rereading it if it has. | |
2793 |
|
2793 | |||
2794 | This is different to dirstate.invalidate() that it doesn't always |
|
2794 | This is different to dirstate.invalidate() that it doesn't always | |
2795 | rereads the dirstate. Use dirstate.invalidate() if you want to |
|
2795 | rereads the dirstate. Use dirstate.invalidate() if you want to | |
2796 | explicitly read the dirstate again (i.e. restoring it to a previous |
|
2796 | explicitly read the dirstate again (i.e. restoring it to a previous | |
2797 | known good state).""" |
|
2797 | known good state).""" | |
2798 | if hasunfilteredcache(self, 'dirstate'): |
|
2798 | if hasunfilteredcache(self, 'dirstate'): | |
2799 | for k in self.dirstate._filecache: |
|
2799 | for k in self.dirstate._filecache: | |
2800 | try: |
|
2800 | try: | |
2801 | delattr(self.dirstate, k) |
|
2801 | delattr(self.dirstate, k) | |
2802 | except AttributeError: |
|
2802 | except AttributeError: | |
2803 | pass |
|
2803 | pass | |
2804 | delattr(self.unfiltered(), 'dirstate') |
|
2804 | delattr(self.unfiltered(), 'dirstate') | |
2805 |
|
2805 | |||
2806 | def invalidate(self, clearfilecache=False): |
|
2806 | def invalidate(self, clearfilecache=False): | |
2807 | """Invalidates both store and non-store parts other than dirstate |
|
2807 | """Invalidates both store and non-store parts other than dirstate | |
2808 |
|
2808 | |||
2809 | If a transaction is running, invalidation of store is omitted, |
|
2809 | If a transaction is running, invalidation of store is omitted, | |
2810 | because discarding in-memory changes might cause inconsistency |
|
2810 | because discarding in-memory changes might cause inconsistency | |
2811 | (e.g. incomplete fncache causes unintentional failure, but |
|
2811 | (e.g. incomplete fncache causes unintentional failure, but | |
2812 | redundant one doesn't). |
|
2812 | redundant one doesn't). | |
2813 | """ |
|
2813 | """ | |
2814 | unfiltered = self.unfiltered() # all file caches are stored unfiltered |
|
2814 | unfiltered = self.unfiltered() # all file caches are stored unfiltered | |
2815 | for k in list(self._filecache.keys()): |
|
2815 | for k in list(self._filecache.keys()): | |
2816 | # dirstate is invalidated separately in invalidatedirstate() |
|
2816 | # dirstate is invalidated separately in invalidatedirstate() | |
2817 | if k == b'dirstate': |
|
2817 | if k == b'dirstate': | |
2818 | continue |
|
2818 | continue | |
2819 | if ( |
|
2819 | if ( | |
2820 | k == b'changelog' |
|
2820 | k == b'changelog' | |
2821 | and self.currenttransaction() |
|
2821 | and self.currenttransaction() | |
2822 | and self.changelog._delayed |
|
2822 | and self.changelog._delayed | |
2823 | ): |
|
2823 | ): | |
2824 | # The changelog object may store unwritten revisions. We don't |
|
2824 | # The changelog object may store unwritten revisions. We don't | |
2825 | # want to lose them. |
|
2825 | # want to lose them. | |
2826 | # TODO: Solve the problem instead of working around it. |
|
2826 | # TODO: Solve the problem instead of working around it. | |
2827 | continue |
|
2827 | continue | |
2828 |
|
2828 | |||
2829 | if clearfilecache: |
|
2829 | if clearfilecache: | |
2830 | del self._filecache[k] |
|
2830 | del self._filecache[k] | |
2831 | try: |
|
2831 | try: | |
2832 | delattr(unfiltered, k) |
|
2832 | delattr(unfiltered, k) | |
2833 | except AttributeError: |
|
2833 | except AttributeError: | |
2834 | pass |
|
2834 | pass | |
2835 | self.invalidatecaches() |
|
2835 | self.invalidatecaches() | |
2836 | if not self.currenttransaction(): |
|
2836 | if not self.currenttransaction(): | |
2837 | # TODO: Changing contents of store outside transaction |
|
2837 | # TODO: Changing contents of store outside transaction | |
2838 | # causes inconsistency. We should make in-memory store |
|
2838 | # causes inconsistency. We should make in-memory store | |
2839 | # changes detectable, and abort if changed. |
|
2839 | # changes detectable, and abort if changed. | |
2840 | self.store.invalidatecaches() |
|
2840 | self.store.invalidatecaches() | |
2841 |
|
2841 | |||
2842 | def invalidateall(self): |
|
2842 | def invalidateall(self): | |
2843 | """Fully invalidates both store and non-store parts, causing the |
|
2843 | """Fully invalidates both store and non-store parts, causing the | |
2844 | subsequent operation to reread any outside changes.""" |
|
2844 | subsequent operation to reread any outside changes.""" | |
2845 | # extension should hook this to invalidate its caches |
|
2845 | # extension should hook this to invalidate its caches | |
2846 | self.invalidate() |
|
2846 | self.invalidate() | |
2847 | self.invalidatedirstate() |
|
2847 | self.invalidatedirstate() | |
2848 |
|
2848 | |||
2849 | @unfilteredmethod |
|
2849 | @unfilteredmethod | |
2850 | def _refreshfilecachestats(self, tr): |
|
2850 | def _refreshfilecachestats(self, tr): | |
2851 | """Reload stats of cached files so that they are flagged as valid""" |
|
2851 | """Reload stats of cached files so that they are flagged as valid""" | |
2852 | for k, ce in self._filecache.items(): |
|
2852 | for k, ce in self._filecache.items(): | |
2853 | k = pycompat.sysstr(k) |
|
2853 | k = pycompat.sysstr(k) | |
2854 | if k == 'dirstate' or k not in self.__dict__: |
|
2854 | if k == 'dirstate' or k not in self.__dict__: | |
2855 | continue |
|
2855 | continue | |
2856 | ce.refresh() |
|
2856 | ce.refresh() | |
2857 |
|
2857 | |||
2858 | def _lock( |
|
2858 | def _lock( | |
2859 | self, |
|
2859 | self, | |
2860 | vfs, |
|
2860 | vfs, | |
2861 | lockname, |
|
2861 | lockname, | |
2862 | wait, |
|
2862 | wait, | |
2863 | releasefn, |
|
2863 | releasefn, | |
2864 | acquirefn, |
|
2864 | acquirefn, | |
2865 | desc, |
|
2865 | desc, | |
2866 | ): |
|
2866 | ): | |
2867 | timeout = 0 |
|
2867 | timeout = 0 | |
2868 | warntimeout = 0 |
|
2868 | warntimeout = 0 | |
2869 | if wait: |
|
2869 | if wait: | |
2870 | timeout = self.ui.configint(b"ui", b"timeout") |
|
2870 | timeout = self.ui.configint(b"ui", b"timeout") | |
2871 | warntimeout = self.ui.configint(b"ui", b"timeout.warn") |
|
2871 | warntimeout = self.ui.configint(b"ui", b"timeout.warn") | |
2872 | # internal config: ui.signal-safe-lock |
|
2872 | # internal config: ui.signal-safe-lock | |
2873 | signalsafe = self.ui.configbool(b'ui', b'signal-safe-lock') |
|
2873 | signalsafe = self.ui.configbool(b'ui', b'signal-safe-lock') | |
2874 |
|
2874 | |||
2875 | l = lockmod.trylock( |
|
2875 | l = lockmod.trylock( | |
2876 | self.ui, |
|
2876 | self.ui, | |
2877 | vfs, |
|
2877 | vfs, | |
2878 | lockname, |
|
2878 | lockname, | |
2879 | timeout, |
|
2879 | timeout, | |
2880 | warntimeout, |
|
2880 | warntimeout, | |
2881 | releasefn=releasefn, |
|
2881 | releasefn=releasefn, | |
2882 | acquirefn=acquirefn, |
|
2882 | acquirefn=acquirefn, | |
2883 | desc=desc, |
|
2883 | desc=desc, | |
2884 | signalsafe=signalsafe, |
|
2884 | signalsafe=signalsafe, | |
2885 | ) |
|
2885 | ) | |
2886 | return l |
|
2886 | return l | |
2887 |
|
2887 | |||
2888 | def _afterlock(self, callback): |
|
2888 | def _afterlock(self, callback): | |
2889 | """add a callback to be run when the repository is fully unlocked |
|
2889 | """add a callback to be run when the repository is fully unlocked | |
2890 |
|
2890 | |||
2891 | The callback will be executed when the outermost lock is released |
|
2891 | The callback will be executed when the outermost lock is released | |
2892 | (with wlock being higher level than 'lock').""" |
|
2892 | (with wlock being higher level than 'lock').""" | |
2893 | for ref in (self._wlockref, self._lockref): |
|
2893 | for ref in (self._wlockref, self._lockref): | |
2894 | l = ref and ref() |
|
2894 | l = ref and ref() | |
2895 | if l and l.held: |
|
2895 | if l and l.held: | |
2896 | l.postrelease.append(callback) |
|
2896 | l.postrelease.append(callback) | |
2897 | break |
|
2897 | break | |
2898 | else: # no lock have been found. |
|
2898 | else: # no lock have been found. | |
2899 | callback(True) |
|
2899 | callback(True) | |
2900 |
|
2900 | |||
2901 | def lock(self, wait=True): |
|
2901 | def lock(self, wait=True): | |
2902 | """Lock the repository store (.hg/store) and return a weak reference |
|
2902 | """Lock the repository store (.hg/store) and return a weak reference | |
2903 | to the lock. Use this before modifying the store (e.g. committing or |
|
2903 | to the lock. Use this before modifying the store (e.g. committing or | |
2904 | stripping). If you are opening a transaction, get a lock as well.) |
|
2904 | stripping). If you are opening a transaction, get a lock as well.) | |
2905 |
|
2905 | |||
2906 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
2906 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
2907 | 'wlock' first to avoid a dead-lock hazard.""" |
|
2907 | 'wlock' first to avoid a dead-lock hazard.""" | |
2908 | l = self._currentlock(self._lockref) |
|
2908 | l = self._currentlock(self._lockref) | |
2909 | if l is not None: |
|
2909 | if l is not None: | |
2910 | l.lock() |
|
2910 | l.lock() | |
2911 | return l |
|
2911 | return l | |
2912 |
|
2912 | |||
2913 | l = self._lock( |
|
2913 | l = self._lock( | |
2914 | vfs=self.svfs, |
|
2914 | vfs=self.svfs, | |
2915 | lockname=b"lock", |
|
2915 | lockname=b"lock", | |
2916 | wait=wait, |
|
2916 | wait=wait, | |
2917 | releasefn=None, |
|
2917 | releasefn=None, | |
2918 | acquirefn=self.invalidate, |
|
2918 | acquirefn=self.invalidate, | |
2919 | desc=_(b'repository %s') % self.origroot, |
|
2919 | desc=_(b'repository %s') % self.origroot, | |
2920 | ) |
|
2920 | ) | |
2921 | self._lockref = weakref.ref(l) |
|
2921 | self._lockref = weakref.ref(l) | |
2922 | return l |
|
2922 | return l | |
2923 |
|
2923 | |||
2924 | def wlock(self, wait=True): |
|
2924 | def wlock(self, wait=True): | |
2925 | """Lock the non-store parts of the repository (everything under |
|
2925 | """Lock the non-store parts of the repository (everything under | |
2926 | .hg except .hg/store) and return a weak reference to the lock. |
|
2926 | .hg except .hg/store) and return a weak reference to the lock. | |
2927 |
|
2927 | |||
2928 | Use this before modifying files in .hg. |
|
2928 | Use this before modifying files in .hg. | |
2929 |
|
2929 | |||
2930 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires |
|
2930 | If both 'lock' and 'wlock' must be acquired, ensure you always acquires | |
2931 | 'wlock' first to avoid a dead-lock hazard.""" |
|
2931 | 'wlock' first to avoid a dead-lock hazard.""" | |
2932 | l = self._wlockref() if self._wlockref else None |
|
2932 | l = self._wlockref() if self._wlockref else None | |
2933 | if l is not None and l.held: |
|
2933 | if l is not None and l.held: | |
2934 | l.lock() |
|
2934 | l.lock() | |
2935 | return l |
|
2935 | return l | |
2936 |
|
2936 | |||
2937 | # We do not need to check for non-waiting lock acquisition. Such |
|
2937 | # We do not need to check for non-waiting lock acquisition. Such | |
2938 | # acquisition would not cause dead-lock as they would just fail. |
|
2938 | # acquisition would not cause dead-lock as they would just fail. | |
2939 | if wait and ( |
|
2939 | if wait and ( | |
2940 | self.ui.configbool(b'devel', b'all-warnings') |
|
2940 | self.ui.configbool(b'devel', b'all-warnings') | |
2941 | or self.ui.configbool(b'devel', b'check-locks') |
|
2941 | or self.ui.configbool(b'devel', b'check-locks') | |
2942 | ): |
|
2942 | ): | |
2943 | if self._currentlock(self._lockref) is not None: |
|
2943 | if self._currentlock(self._lockref) is not None: | |
2944 | self.ui.develwarn(b'"wlock" acquired after "lock"') |
|
2944 | self.ui.develwarn(b'"wlock" acquired after "lock"') | |
2945 |
|
2945 | |||
2946 | def unlock(): |
|
2946 | def unlock(): | |
2947 | if self.dirstate.pendingparentchange(): |
|
2947 | if self.dirstate.pendingparentchange(): | |
2948 | self.dirstate.invalidate() |
|
2948 | self.dirstate.invalidate() | |
2949 | else: |
|
2949 | else: | |
2950 | self.dirstate.write(None) |
|
2950 | self.dirstate.write(None) | |
2951 |
|
2951 | |||
2952 | self._filecache[b'dirstate'].refresh() |
|
2952 | self._filecache[b'dirstate'].refresh() | |
2953 |
|
2953 | |||
2954 | l = self._lock( |
|
2954 | l = self._lock( | |
2955 | self.vfs, |
|
2955 | self.vfs, | |
2956 | b"wlock", |
|
2956 | b"wlock", | |
2957 | wait, |
|
2957 | wait, | |
2958 | unlock, |
|
2958 | unlock, | |
2959 | self.invalidatedirstate, |
|
2959 | self.invalidatedirstate, | |
2960 | _(b'working directory of %s') % self.origroot, |
|
2960 | _(b'working directory of %s') % self.origroot, | |
2961 | ) |
|
2961 | ) | |
2962 | self._wlockref = weakref.ref(l) |
|
2962 | self._wlockref = weakref.ref(l) | |
2963 | return l |
|
2963 | return l | |
2964 |
|
2964 | |||
2965 | def _currentlock(self, lockref): |
|
2965 | def _currentlock(self, lockref): | |
2966 | """Returns the lock if it's held, or None if it's not.""" |
|
2966 | """Returns the lock if it's held, or None if it's not.""" | |
2967 | if lockref is None: |
|
2967 | if lockref is None: | |
2968 | return None |
|
2968 | return None | |
2969 | l = lockref() |
|
2969 | l = lockref() | |
2970 | if l is None or not l.held: |
|
2970 | if l is None or not l.held: | |
2971 | return None |
|
2971 | return None | |
2972 | return l |
|
2972 | return l | |
2973 |
|
2973 | |||
2974 | def currentwlock(self): |
|
2974 | def currentwlock(self): | |
2975 | """Returns the wlock if it's held, or None if it's not.""" |
|
2975 | """Returns the wlock if it's held, or None if it's not.""" | |
2976 | return self._currentlock(self._wlockref) |
|
2976 | return self._currentlock(self._wlockref) | |
2977 |
|
2977 | |||
2978 | def checkcommitpatterns(self, wctx, match, status, fail): |
|
2978 | def checkcommitpatterns(self, wctx, match, status, fail): | |
2979 | """check for commit arguments that aren't committable""" |
|
2979 | """check for commit arguments that aren't committable""" | |
2980 | if match.isexact() or match.prefix(): |
|
2980 | if match.isexact() or match.prefix(): | |
2981 | matched = set(status.modified + status.added + status.removed) |
|
2981 | matched = set(status.modified + status.added + status.removed) | |
2982 |
|
2982 | |||
2983 | for f in match.files(): |
|
2983 | for f in match.files(): | |
2984 | f = self.dirstate.normalize(f) |
|
2984 | f = self.dirstate.normalize(f) | |
2985 | if f == b'.' or f in matched or f in wctx.substate: |
|
2985 | if f == b'.' or f in matched or f in wctx.substate: | |
2986 | continue |
|
2986 | continue | |
2987 | if f in status.deleted: |
|
2987 | if f in status.deleted: | |
2988 | fail(f, _(b'file not found!')) |
|
2988 | fail(f, _(b'file not found!')) | |
2989 | # Is it a directory that exists or used to exist? |
|
2989 | # Is it a directory that exists or used to exist? | |
2990 | if self.wvfs.isdir(f) or wctx.p1().hasdir(f): |
|
2990 | if self.wvfs.isdir(f) or wctx.p1().hasdir(f): | |
2991 | d = f + b'/' |
|
2991 | d = f + b'/' | |
2992 | for mf in matched: |
|
2992 | for mf in matched: | |
2993 | if mf.startswith(d): |
|
2993 | if mf.startswith(d): | |
2994 | break |
|
2994 | break | |
2995 | else: |
|
2995 | else: | |
2996 | fail(f, _(b"no match under directory!")) |
|
2996 | fail(f, _(b"no match under directory!")) | |
2997 | elif f not in self.dirstate: |
|
2997 | elif f not in self.dirstate: | |
2998 | fail(f, _(b"file not tracked!")) |
|
2998 | fail(f, _(b"file not tracked!")) | |
2999 |
|
2999 | |||
3000 | @unfilteredmethod |
|
3000 | @unfilteredmethod | |
3001 | def commit( |
|
3001 | def commit( | |
3002 | self, |
|
3002 | self, | |
3003 | text=b"", |
|
3003 | text=b"", | |
3004 | user=None, |
|
3004 | user=None, | |
3005 | date=None, |
|
3005 | date=None, | |
3006 | match=None, |
|
3006 | match=None, | |
3007 | force=False, |
|
3007 | force=False, | |
3008 | editor=None, |
|
3008 | editor=None, | |
3009 | extra=None, |
|
3009 | extra=None, | |
3010 | ): |
|
3010 | ): | |
3011 | """Add a new revision to current repository. |
|
3011 | """Add a new revision to current repository. | |
3012 |
|
3012 | |||
3013 | Revision information is gathered from the working directory, |
|
3013 | Revision information is gathered from the working directory, | |
3014 | match can be used to filter the committed files. If editor is |
|
3014 | match can be used to filter the committed files. If editor is | |
3015 | supplied, it is called to get a commit message. |
|
3015 | supplied, it is called to get a commit message. | |
3016 | """ |
|
3016 | """ | |
3017 | if extra is None: |
|
3017 | if extra is None: | |
3018 | extra = {} |
|
3018 | extra = {} | |
3019 |
|
3019 | |||
3020 | def fail(f, msg): |
|
3020 | def fail(f, msg): | |
3021 | raise error.InputError(b'%s: %s' % (f, msg)) |
|
3021 | raise error.InputError(b'%s: %s' % (f, msg)) | |
3022 |
|
3022 | |||
3023 | if not match: |
|
3023 | if not match: | |
3024 | match = matchmod.always() |
|
3024 | match = matchmod.always() | |
3025 |
|
3025 | |||
3026 | if not force: |
|
3026 | if not force: | |
3027 | match.bad = fail |
|
3027 | match.bad = fail | |
3028 |
|
3028 | |||
3029 | # lock() for recent changelog (see issue4368) |
|
3029 | # lock() for recent changelog (see issue4368) | |
3030 | with self.wlock(), self.lock(): |
|
3030 | with self.wlock(), self.lock(): | |
3031 | wctx = self[None] |
|
3031 | wctx = self[None] | |
3032 | merge = len(wctx.parents()) > 1 |
|
3032 | merge = len(wctx.parents()) > 1 | |
3033 |
|
3033 | |||
3034 | if not force and merge and not match.always(): |
|
3034 | if not force and merge and not match.always(): | |
3035 | raise error.Abort( |
|
3035 | raise error.Abort( | |
3036 | _( |
|
3036 | _( | |
3037 | b'cannot partially commit a merge ' |
|
3037 | b'cannot partially commit a merge ' | |
3038 | b'(do not specify files or patterns)' |
|
3038 | b'(do not specify files or patterns)' | |
3039 | ) |
|
3039 | ) | |
3040 | ) |
|
3040 | ) | |
3041 |
|
3041 | |||
3042 | status = self.status(match=match, clean=force) |
|
3042 | status = self.status(match=match, clean=force) | |
3043 | if force: |
|
3043 | if force: | |
3044 | status.modified.extend( |
|
3044 | status.modified.extend( | |
3045 | status.clean |
|
3045 | status.clean | |
3046 | ) # mq may commit clean files |
|
3046 | ) # mq may commit clean files | |
3047 |
|
3047 | |||
3048 | # check subrepos |
|
3048 | # check subrepos | |
3049 | subs, commitsubs, newstate = subrepoutil.precommit( |
|
3049 | subs, commitsubs, newstate = subrepoutil.precommit( | |
3050 | self.ui, wctx, status, match, force=force |
|
3050 | self.ui, wctx, status, match, force=force | |
3051 | ) |
|
3051 | ) | |
3052 |
|
3052 | |||
3053 | # make sure all explicit patterns are matched |
|
3053 | # make sure all explicit patterns are matched | |
3054 | if not force: |
|
3054 | if not force: | |
3055 | self.checkcommitpatterns(wctx, match, status, fail) |
|
3055 | self.checkcommitpatterns(wctx, match, status, fail) | |
3056 |
|
3056 | |||
3057 | cctx = context.workingcommitctx( |
|
3057 | cctx = context.workingcommitctx( | |
3058 | self, status, text, user, date, extra |
|
3058 | self, status, text, user, date, extra | |
3059 | ) |
|
3059 | ) | |
3060 |
|
3060 | |||
3061 | ms = mergestatemod.mergestate.read(self) |
|
3061 | ms = mergestatemod.mergestate.read(self) | |
3062 | mergeutil.checkunresolved(ms) |
|
3062 | mergeutil.checkunresolved(ms) | |
3063 |
|
3063 | |||
3064 | # internal config: ui.allowemptycommit |
|
3064 | # internal config: ui.allowemptycommit | |
3065 | if cctx.isempty() and not self.ui.configbool( |
|
3065 | if cctx.isempty() and not self.ui.configbool( | |
3066 | b'ui', b'allowemptycommit' |
|
3066 | b'ui', b'allowemptycommit' | |
3067 | ): |
|
3067 | ): | |
3068 | self.ui.debug(b'nothing to commit, clearing merge state\n') |
|
3068 | self.ui.debug(b'nothing to commit, clearing merge state\n') | |
3069 | ms.reset() |
|
3069 | ms.reset() | |
3070 | return None |
|
3070 | return None | |
3071 |
|
3071 | |||
3072 | if merge and cctx.deleted(): |
|
3072 | if merge and cctx.deleted(): | |
3073 | raise error.Abort(_(b"cannot commit merge with missing files")) |
|
3073 | raise error.Abort(_(b"cannot commit merge with missing files")) | |
3074 |
|
3074 | |||
3075 | if editor: |
|
3075 | if editor: | |
3076 | cctx._text = editor(self, cctx, subs) |
|
3076 | cctx._text = editor(self, cctx, subs) | |
3077 | edited = text != cctx._text |
|
3077 | edited = text != cctx._text | |
3078 |
|
3078 | |||
3079 | # Save commit message in case this transaction gets rolled back |
|
3079 | # Save commit message in case this transaction gets rolled back | |
3080 | # (e.g. by a pretxncommit hook). Leave the content alone on |
|
3080 | # (e.g. by a pretxncommit hook). Leave the content alone on | |
3081 | # the assumption that the user will use the same editor again. |
|
3081 | # the assumption that the user will use the same editor again. | |
3082 | msgfn = self.savecommitmessage(cctx._text) |
|
3082 | msgfn = self.savecommitmessage(cctx._text) | |
3083 |
|
3083 | |||
3084 | # commit subs and write new state |
|
3084 | # commit subs and write new state | |
3085 | if subs: |
|
3085 | if subs: | |
3086 | uipathfn = scmutil.getuipathfn(self) |
|
3086 | uipathfn = scmutil.getuipathfn(self) | |
3087 | for s in sorted(commitsubs): |
|
3087 | for s in sorted(commitsubs): | |
3088 | sub = wctx.sub(s) |
|
3088 | sub = wctx.sub(s) | |
3089 | self.ui.status( |
|
3089 | self.ui.status( | |
3090 | _(b'committing subrepository %s\n') |
|
3090 | _(b'committing subrepository %s\n') | |
3091 | % uipathfn(subrepoutil.subrelpath(sub)) |
|
3091 | % uipathfn(subrepoutil.subrelpath(sub)) | |
3092 | ) |
|
3092 | ) | |
3093 | sr = sub.commit(cctx._text, user, date) |
|
3093 | sr = sub.commit(cctx._text, user, date) | |
3094 | newstate[s] = (newstate[s][0], sr) |
|
3094 | newstate[s] = (newstate[s][0], sr) | |
3095 | subrepoutil.writestate(self, newstate) |
|
3095 | subrepoutil.writestate(self, newstate) | |
3096 |
|
3096 | |||
3097 | p1, p2 = self.dirstate.parents() |
|
3097 | p1, p2 = self.dirstate.parents() | |
3098 | hookp1, hookp2 = hex(p1), (p2 != self.nullid and hex(p2) or b'') |
|
3098 | hookp1, hookp2 = hex(p1), (p2 != self.nullid and hex(p2) or b'') | |
3099 | try: |
|
3099 | try: | |
3100 | self.hook( |
|
3100 | self.hook( | |
3101 | b"precommit", throw=True, parent1=hookp1, parent2=hookp2 |
|
3101 | b"precommit", throw=True, parent1=hookp1, parent2=hookp2 | |
3102 | ) |
|
3102 | ) | |
3103 | with self.transaction(b'commit'): |
|
3103 | with self.transaction(b'commit'): | |
3104 | ret = self.commitctx(cctx, True) |
|
3104 | ret = self.commitctx(cctx, True) | |
3105 | # update bookmarks, dirstate and mergestate |
|
3105 | # update bookmarks, dirstate and mergestate | |
3106 | bookmarks.update(self, [p1, p2], ret) |
|
3106 | bookmarks.update(self, [p1, p2], ret) | |
3107 | cctx.markcommitted(ret) |
|
3107 | cctx.markcommitted(ret) | |
3108 | ms.reset() |
|
3108 | ms.reset() | |
3109 | except: # re-raises |
|
3109 | except: # re-raises | |
3110 | if edited: |
|
3110 | if edited: | |
3111 | self.ui.write( |
|
3111 | self.ui.write( | |
3112 | _(b'note: commit message saved in %s\n') % msgfn |
|
3112 | _(b'note: commit message saved in %s\n') % msgfn | |
3113 | ) |
|
3113 | ) | |
3114 | self.ui.write( |
|
3114 | self.ui.write( | |
3115 | _( |
|
3115 | _( | |
3116 | b"note: use 'hg commit --logfile " |
|
3116 | b"note: use 'hg commit --logfile " | |
3117 | b".hg/last-message.txt --edit' to reuse it\n" |
|
3117 | b".hg/last-message.txt --edit' to reuse it\n" | |
3118 | ) |
|
3118 | ) | |
3119 | ) |
|
3119 | ) | |
3120 | raise |
|
3120 | raise | |
3121 |
|
3121 | |||
3122 | def commithook(unused_success): |
|
3122 | def commithook(unused_success): | |
3123 | # hack for command that use a temporary commit (eg: histedit) |
|
3123 | # hack for command that use a temporary commit (eg: histedit) | |
3124 | # temporary commit got stripped before hook release |
|
3124 | # temporary commit got stripped before hook release | |
3125 | if self.changelog.hasnode(ret): |
|
3125 | if self.changelog.hasnode(ret): | |
3126 | self.hook( |
|
3126 | self.hook( | |
3127 | b"commit", node=hex(ret), parent1=hookp1, parent2=hookp2 |
|
3127 | b"commit", node=hex(ret), parent1=hookp1, parent2=hookp2 | |
3128 | ) |
|
3128 | ) | |
3129 |
|
3129 | |||
3130 | self._afterlock(commithook) |
|
3130 | self._afterlock(commithook) | |
3131 | return ret |
|
3131 | return ret | |
3132 |
|
3132 | |||
3133 | @unfilteredmethod |
|
3133 | @unfilteredmethod | |
3134 | def commitctx(self, ctx, error=False, origctx=None): |
|
3134 | def commitctx(self, ctx, error=False, origctx=None): | |
3135 | return commit.commitctx(self, ctx, error=error, origctx=origctx) |
|
3135 | return commit.commitctx(self, ctx, error=error, origctx=origctx) | |
3136 |
|
3136 | |||
3137 | @unfilteredmethod |
|
3137 | @unfilteredmethod | |
3138 | def destroying(self): |
|
3138 | def destroying(self): | |
3139 | """Inform the repository that nodes are about to be destroyed. |
|
3139 | """Inform the repository that nodes are about to be destroyed. | |
3140 | Intended for use by strip and rollback, so there's a common |
|
3140 | Intended for use by strip and rollback, so there's a common | |
3141 | place for anything that has to be done before destroying history. |
|
3141 | place for anything that has to be done before destroying history. | |
3142 |
|
3142 | |||
3143 | This is mostly useful for saving state that is in memory and waiting |
|
3143 | This is mostly useful for saving state that is in memory and waiting | |
3144 | to be flushed when the current lock is released. Because a call to |
|
3144 | to be flushed when the current lock is released. Because a call to | |
3145 | destroyed is imminent, the repo will be invalidated causing those |
|
3145 | destroyed is imminent, the repo will be invalidated causing those | |
3146 | changes to stay in memory (waiting for the next unlock), or vanish |
|
3146 | changes to stay in memory (waiting for the next unlock), or vanish | |
3147 | completely. |
|
3147 | completely. | |
3148 | """ |
|
3148 | """ | |
3149 | # When using the same lock to commit and strip, the phasecache is left |
|
3149 | # When using the same lock to commit and strip, the phasecache is left | |
3150 | # dirty after committing. Then when we strip, the repo is invalidated, |
|
3150 | # dirty after committing. Then when we strip, the repo is invalidated, | |
3151 | # causing those changes to disappear. |
|
3151 | # causing those changes to disappear. | |
3152 | if '_phasecache' in vars(self): |
|
3152 | if '_phasecache' in vars(self): | |
3153 | self._phasecache.write() |
|
3153 | self._phasecache.write() | |
3154 |
|
3154 | |||
3155 | @unfilteredmethod |
|
3155 | @unfilteredmethod | |
3156 | def destroyed(self): |
|
3156 | def destroyed(self): | |
3157 | """Inform the repository that nodes have been destroyed. |
|
3157 | """Inform the repository that nodes have been destroyed. | |
3158 | Intended for use by strip and rollback, so there's a common |
|
3158 | Intended for use by strip and rollback, so there's a common | |
3159 | place for anything that has to be done after destroying history. |
|
3159 | place for anything that has to be done after destroying history. | |
3160 | """ |
|
3160 | """ | |
3161 | # When one tries to: |
|
3161 | # When one tries to: | |
3162 | # 1) destroy nodes thus calling this method (e.g. strip) |
|
3162 | # 1) destroy nodes thus calling this method (e.g. strip) | |
3163 | # 2) use phasecache somewhere (e.g. commit) |
|
3163 | # 2) use phasecache somewhere (e.g. commit) | |
3164 | # |
|
3164 | # | |
3165 | # then 2) will fail because the phasecache contains nodes that were |
|
3165 | # then 2) will fail because the phasecache contains nodes that were | |
3166 | # removed. We can either remove phasecache from the filecache, |
|
3166 | # removed. We can either remove phasecache from the filecache, | |
3167 | # causing it to reload next time it is accessed, or simply filter |
|
3167 | # causing it to reload next time it is accessed, or simply filter | |
3168 | # the removed nodes now and write the updated cache. |
|
3168 | # the removed nodes now and write the updated cache. | |
3169 | self._phasecache.filterunknown(self) |
|
3169 | self._phasecache.filterunknown(self) | |
3170 | self._phasecache.write() |
|
3170 | self._phasecache.write() | |
3171 |
|
3171 | |||
3172 | # refresh all repository caches |
|
3172 | # refresh all repository caches | |
3173 | self.updatecaches() |
|
3173 | self.updatecaches() | |
3174 |
|
3174 | |||
3175 | # Ensure the persistent tag cache is updated. Doing it now |
|
3175 | # Ensure the persistent tag cache is updated. Doing it now | |
3176 | # means that the tag cache only has to worry about destroyed |
|
3176 | # means that the tag cache only has to worry about destroyed | |
3177 | # heads immediately after a strip/rollback. That in turn |
|
3177 | # heads immediately after a strip/rollback. That in turn | |
3178 | # guarantees that "cachetip == currenttip" (comparing both rev |
|
3178 | # guarantees that "cachetip == currenttip" (comparing both rev | |
3179 | # and node) always means no nodes have been added or destroyed. |
|
3179 | # and node) always means no nodes have been added or destroyed. | |
3180 |
|
3180 | |||
3181 | # XXX this is suboptimal when qrefresh'ing: we strip the current |
|
3181 | # XXX this is suboptimal when qrefresh'ing: we strip the current | |
3182 | # head, refresh the tag cache, then immediately add a new head. |
|
3182 | # head, refresh the tag cache, then immediately add a new head. | |
3183 | # But I think doing it this way is necessary for the "instant |
|
3183 | # But I think doing it this way is necessary for the "instant | |
3184 | # tag cache retrieval" case to work. |
|
3184 | # tag cache retrieval" case to work. | |
3185 | self.invalidate() |
|
3185 | self.invalidate() | |
3186 |
|
3186 | |||
3187 | def status( |
|
3187 | def status( | |
3188 | self, |
|
3188 | self, | |
3189 | node1=b'.', |
|
3189 | node1=b'.', | |
3190 | node2=None, |
|
3190 | node2=None, | |
3191 | match=None, |
|
3191 | match=None, | |
3192 | ignored=False, |
|
3192 | ignored=False, | |
3193 | clean=False, |
|
3193 | clean=False, | |
3194 | unknown=False, |
|
3194 | unknown=False, | |
3195 | listsubrepos=False, |
|
3195 | listsubrepos=False, | |
3196 | ): |
|
3196 | ): | |
3197 | '''a convenience method that calls node1.status(node2)''' |
|
3197 | '''a convenience method that calls node1.status(node2)''' | |
3198 | return self[node1].status( |
|
3198 | return self[node1].status( | |
3199 | node2, match, ignored, clean, unknown, listsubrepos |
|
3199 | node2, match, ignored, clean, unknown, listsubrepos | |
3200 | ) |
|
3200 | ) | |
3201 |
|
3201 | |||
3202 | def addpostdsstatus(self, ps): |
|
3202 | def addpostdsstatus(self, ps): | |
3203 | """Add a callback to run within the wlock, at the point at which status |
|
3203 | """Add a callback to run within the wlock, at the point at which status | |
3204 | fixups happen. |
|
3204 | fixups happen. | |
3205 |
|
3205 | |||
3206 | On status completion, callback(wctx, status) will be called with the |
|
3206 | On status completion, callback(wctx, status) will be called with the | |
3207 | wlock held, unless the dirstate has changed from underneath or the wlock |
|
3207 | wlock held, unless the dirstate has changed from underneath or the wlock | |
3208 | couldn't be grabbed. |
|
3208 | couldn't be grabbed. | |
3209 |
|
3209 | |||
3210 | Callbacks should not capture and use a cached copy of the dirstate -- |
|
3210 | Callbacks should not capture and use a cached copy of the dirstate -- | |
3211 | it might change in the meanwhile. Instead, they should access the |
|
3211 | it might change in the meanwhile. Instead, they should access the | |
3212 | dirstate via wctx.repo().dirstate. |
|
3212 | dirstate via wctx.repo().dirstate. | |
3213 |
|
3213 | |||
3214 | This list is emptied out after each status run -- extensions should |
|
3214 | This list is emptied out after each status run -- extensions should | |
3215 | make sure it adds to this list each time dirstate.status is called. |
|
3215 | make sure it adds to this list each time dirstate.status is called. | |
3216 | Extensions should also make sure they don't call this for statuses |
|
3216 | Extensions should also make sure they don't call this for statuses | |
3217 | that don't involve the dirstate. |
|
3217 | that don't involve the dirstate. | |
3218 | """ |
|
3218 | """ | |
3219 |
|
3219 | |||
3220 | # The list is located here for uniqueness reasons -- it is actually |
|
3220 | # The list is located here for uniqueness reasons -- it is actually | |
3221 | # managed by the workingctx, but that isn't unique per-repo. |
|
3221 | # managed by the workingctx, but that isn't unique per-repo. | |
3222 | self._postdsstatus.append(ps) |
|
3222 | self._postdsstatus.append(ps) | |
3223 |
|
3223 | |||
3224 | def postdsstatus(self): |
|
3224 | def postdsstatus(self): | |
3225 | """Used by workingctx to get the list of post-dirstate-status hooks.""" |
|
3225 | """Used by workingctx to get the list of post-dirstate-status hooks.""" | |
3226 | return self._postdsstatus |
|
3226 | return self._postdsstatus | |
3227 |
|
3227 | |||
3228 | def clearpostdsstatus(self): |
|
3228 | def clearpostdsstatus(self): | |
3229 | """Used by workingctx to clear post-dirstate-status hooks.""" |
|
3229 | """Used by workingctx to clear post-dirstate-status hooks.""" | |
3230 | del self._postdsstatus[:] |
|
3230 | del self._postdsstatus[:] | |
3231 |
|
3231 | |||
3232 | def heads(self, start=None): |
|
3232 | def heads(self, start=None): | |
3233 | if start is None: |
|
3233 | if start is None: | |
3234 | cl = self.changelog |
|
3234 | cl = self.changelog | |
3235 | headrevs = reversed(cl.headrevs()) |
|
3235 | headrevs = reversed(cl.headrevs()) | |
3236 | return [cl.node(rev) for rev in headrevs] |
|
3236 | return [cl.node(rev) for rev in headrevs] | |
3237 |
|
3237 | |||
3238 | heads = self.changelog.heads(start) |
|
3238 | heads = self.changelog.heads(start) | |
3239 | # sort the output in rev descending order |
|
3239 | # sort the output in rev descending order | |
3240 | return sorted(heads, key=self.changelog.rev, reverse=True) |
|
3240 | return sorted(heads, key=self.changelog.rev, reverse=True) | |
3241 |
|
3241 | |||
3242 | def branchheads(self, branch=None, start=None, closed=False): |
|
3242 | def branchheads(self, branch=None, start=None, closed=False): | |
3243 | """return a (possibly filtered) list of heads for the given branch |
|
3243 | """return a (possibly filtered) list of heads for the given branch | |
3244 |
|
3244 | |||
3245 | Heads are returned in topological order, from newest to oldest. |
|
3245 | Heads are returned in topological order, from newest to oldest. | |
3246 | If branch is None, use the dirstate branch. |
|
3246 | If branch is None, use the dirstate branch. | |
3247 | If start is not None, return only heads reachable from start. |
|
3247 | If start is not None, return only heads reachable from start. | |
3248 | If closed is True, return heads that are marked as closed as well. |
|
3248 | If closed is True, return heads that are marked as closed as well. | |
3249 | """ |
|
3249 | """ | |
3250 | if branch is None: |
|
3250 | if branch is None: | |
3251 | branch = self[None].branch() |
|
3251 | branch = self[None].branch() | |
3252 | branches = self.branchmap() |
|
3252 | branches = self.branchmap() | |
3253 | if not branches.hasbranch(branch): |
|
3253 | if not branches.hasbranch(branch): | |
3254 | return [] |
|
3254 | return [] | |
3255 | # the cache returns heads ordered lowest to highest |
|
3255 | # the cache returns heads ordered lowest to highest | |
3256 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) |
|
3256 | bheads = list(reversed(branches.branchheads(branch, closed=closed))) | |
3257 | if start is not None: |
|
3257 | if start is not None: | |
3258 | # filter out the heads that cannot be reached from startrev |
|
3258 | # filter out the heads that cannot be reached from startrev | |
3259 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) |
|
3259 | fbheads = set(self.changelog.nodesbetween([start], bheads)[2]) | |
3260 | bheads = [h for h in bheads if h in fbheads] |
|
3260 | bheads = [h for h in bheads if h in fbheads] | |
3261 | return bheads |
|
3261 | return bheads | |
3262 |
|
3262 | |||
3263 | def branches(self, nodes): |
|
3263 | def branches(self, nodes): | |
3264 | if not nodes: |
|
3264 | if not nodes: | |
3265 | nodes = [self.changelog.tip()] |
|
3265 | nodes = [self.changelog.tip()] | |
3266 | b = [] |
|
3266 | b = [] | |
3267 | for n in nodes: |
|
3267 | for n in nodes: | |
3268 | t = n |
|
3268 | t = n | |
3269 | while True: |
|
3269 | while True: | |
3270 | p = self.changelog.parents(n) |
|
3270 | p = self.changelog.parents(n) | |
3271 | if p[1] != self.nullid or p[0] == self.nullid: |
|
3271 | if p[1] != self.nullid or p[0] == self.nullid: | |
3272 | b.append((t, n, p[0], p[1])) |
|
3272 | b.append((t, n, p[0], p[1])) | |
3273 | break |
|
3273 | break | |
3274 | n = p[0] |
|
3274 | n = p[0] | |
3275 | return b |
|
3275 | return b | |
3276 |
|
3276 | |||
3277 | def between(self, pairs): |
|
3277 | def between(self, pairs): | |
3278 | r = [] |
|
3278 | r = [] | |
3279 |
|
3279 | |||
3280 | for top, bottom in pairs: |
|
3280 | for top, bottom in pairs: | |
3281 | n, l, i = top, [], 0 |
|
3281 | n, l, i = top, [], 0 | |
3282 | f = 1 |
|
3282 | f = 1 | |
3283 |
|
3283 | |||
3284 | while n != bottom and n != self.nullid: |
|
3284 | while n != bottom and n != self.nullid: | |
3285 | p = self.changelog.parents(n)[0] |
|
3285 | p = self.changelog.parents(n)[0] | |
3286 | if i == f: |
|
3286 | if i == f: | |
3287 | l.append(n) |
|
3287 | l.append(n) | |
3288 | f = f * 2 |
|
3288 | f = f * 2 | |
3289 | n = p |
|
3289 | n = p | |
3290 | i += 1 |
|
3290 | i += 1 | |
3291 |
|
3291 | |||
3292 | r.append(l) |
|
3292 | r.append(l) | |
3293 |
|
3293 | |||
3294 | return r |
|
3294 | return r | |
3295 |
|
3295 | |||
3296 | def checkpush(self, pushop): |
|
3296 | def checkpush(self, pushop): | |
3297 | """Extensions can override this function if additional checks have |
|
3297 | """Extensions can override this function if additional checks have | |
3298 | to be performed before pushing, or call it if they override push |
|
3298 | to be performed before pushing, or call it if they override push | |
3299 | command. |
|
3299 | command. | |
3300 | """ |
|
3300 | """ | |
3301 |
|
3301 | |||
3302 | @unfilteredpropertycache |
|
3302 | @unfilteredpropertycache | |
3303 | def prepushoutgoinghooks(self): |
|
3303 | def prepushoutgoinghooks(self): | |
3304 | """Return util.hooks consists of a pushop with repo, remote, outgoing |
|
3304 | """Return util.hooks consists of a pushop with repo, remote, outgoing | |
3305 | methods, which are called before pushing changesets. |
|
3305 | methods, which are called before pushing changesets. | |
3306 | """ |
|
3306 | """ | |
3307 | return util.hooks() |
|
3307 | return util.hooks() | |
3308 |
|
3308 | |||
3309 | def pushkey(self, namespace, key, old, new): |
|
3309 | def pushkey(self, namespace, key, old, new): | |
3310 | try: |
|
3310 | try: | |
3311 | tr = self.currenttransaction() |
|
3311 | tr = self.currenttransaction() | |
3312 | hookargs = {} |
|
3312 | hookargs = {} | |
3313 | if tr is not None: |
|
3313 | if tr is not None: | |
3314 | hookargs.update(tr.hookargs) |
|
3314 | hookargs.update(tr.hookargs) | |
3315 | hookargs = pycompat.strkwargs(hookargs) |
|
3315 | hookargs = pycompat.strkwargs(hookargs) | |
3316 | hookargs['namespace'] = namespace |
|
3316 | hookargs['namespace'] = namespace | |
3317 | hookargs['key'] = key |
|
3317 | hookargs['key'] = key | |
3318 | hookargs['old'] = old |
|
3318 | hookargs['old'] = old | |
3319 | hookargs['new'] = new |
|
3319 | hookargs['new'] = new | |
3320 | self.hook(b'prepushkey', throw=True, **hookargs) |
|
3320 | self.hook(b'prepushkey', throw=True, **hookargs) | |
3321 | except error.HookAbort as exc: |
|
3321 | except error.HookAbort as exc: | |
3322 | self.ui.write_err(_(b"pushkey-abort: %s\n") % exc) |
|
3322 | self.ui.write_err(_(b"pushkey-abort: %s\n") % exc) | |
3323 | if exc.hint: |
|
3323 | if exc.hint: | |
3324 | self.ui.write_err(_(b"(%s)\n") % exc.hint) |
|
3324 | self.ui.write_err(_(b"(%s)\n") % exc.hint) | |
3325 | return False |
|
3325 | return False | |
3326 | self.ui.debug(b'pushing key for "%s:%s"\n' % (namespace, key)) |
|
3326 | self.ui.debug(b'pushing key for "%s:%s"\n' % (namespace, key)) | |
3327 | ret = pushkey.push(self, namespace, key, old, new) |
|
3327 | ret = pushkey.push(self, namespace, key, old, new) | |
3328 |
|
3328 | |||
3329 | def runhook(unused_success): |
|
3329 | def runhook(unused_success): | |
3330 | self.hook( |
|
3330 | self.hook( | |
3331 | b'pushkey', |
|
3331 | b'pushkey', | |
3332 | namespace=namespace, |
|
3332 | namespace=namespace, | |
3333 | key=key, |
|
3333 | key=key, | |
3334 | old=old, |
|
3334 | old=old, | |
3335 | new=new, |
|
3335 | new=new, | |
3336 | ret=ret, |
|
3336 | ret=ret, | |
3337 | ) |
|
3337 | ) | |
3338 |
|
3338 | |||
3339 | self._afterlock(runhook) |
|
3339 | self._afterlock(runhook) | |
3340 | return ret |
|
3340 | return ret | |
3341 |
|
3341 | |||
3342 | def listkeys(self, namespace): |
|
3342 | def listkeys(self, namespace): | |
3343 | self.hook(b'prelistkeys', throw=True, namespace=namespace) |
|
3343 | self.hook(b'prelistkeys', throw=True, namespace=namespace) | |
3344 | self.ui.debug(b'listing keys for "%s"\n' % namespace) |
|
3344 | self.ui.debug(b'listing keys for "%s"\n' % namespace) | |
3345 | values = pushkey.list(self, namespace) |
|
3345 | values = pushkey.list(self, namespace) | |
3346 | self.hook(b'listkeys', namespace=namespace, values=values) |
|
3346 | self.hook(b'listkeys', namespace=namespace, values=values) | |
3347 | return values |
|
3347 | return values | |
3348 |
|
3348 | |||
3349 | def debugwireargs(self, one, two, three=None, four=None, five=None): |
|
3349 | def debugwireargs(self, one, two, three=None, four=None, five=None): | |
3350 | '''used to test argument passing over the wire''' |
|
3350 | '''used to test argument passing over the wire''' | |
3351 | return b"%s %s %s %s %s" % ( |
|
3351 | return b"%s %s %s %s %s" % ( | |
3352 | one, |
|
3352 | one, | |
3353 | two, |
|
3353 | two, | |
3354 | pycompat.bytestr(three), |
|
3354 | pycompat.bytestr(three), | |
3355 | pycompat.bytestr(four), |
|
3355 | pycompat.bytestr(four), | |
3356 | pycompat.bytestr(five), |
|
3356 | pycompat.bytestr(five), | |
3357 | ) |
|
3357 | ) | |
3358 |
|
3358 | |||
3359 | def savecommitmessage(self, text): |
|
3359 | def savecommitmessage(self, text): | |
3360 | fp = self.vfs(b'last-message.txt', b'wb') |
|
3360 | fp = self.vfs(b'last-message.txt', b'wb') | |
3361 | try: |
|
3361 | try: | |
3362 | fp.write(text) |
|
3362 | fp.write(text) | |
3363 | finally: |
|
3363 | finally: | |
3364 | fp.close() |
|
3364 | fp.close() | |
3365 | return self.pathto(fp.name[len(self.root) + 1 :]) |
|
3365 | return self.pathto(fp.name[len(self.root) + 1 :]) | |
3366 |
|
3366 | |||
3367 | def register_wanted_sidedata(self, category): |
|
3367 | def register_wanted_sidedata(self, category): | |
|
3368 | if requirementsmod.REVLOGV2_REQUIREMENT not in self.requirements: | |||
|
3369 | # Only revlogv2 repos can want sidedata. | |||
|
3370 | return | |||
3368 | self._wanted_sidedata.add(pycompat.bytestr(category)) |
|
3371 | self._wanted_sidedata.add(pycompat.bytestr(category)) | |
3369 |
|
3372 | |||
3370 | def register_sidedata_computer(self, kind, category, keys, computer): |
|
3373 | def register_sidedata_computer(self, kind, category, keys, computer): | |
3371 | if kind not in revlogconst.ALL_KINDS: |
|
3374 | if kind not in revlogconst.ALL_KINDS: | |
3372 | msg = _(b"unexpected revlog kind %r.") |
|
3375 | msg = _(b"unexpected revlog kind %r.") | |
3373 | raise error.ProgrammingError(msg % kind) |
|
3376 | raise error.ProgrammingError(msg % kind) | |
3374 | category = pycompat.bytestr(category) |
|
3377 | category = pycompat.bytestr(category) | |
3375 | if category in self._sidedata_computers.get(kind, []): |
|
3378 | if category in self._sidedata_computers.get(kind, []): | |
3376 | msg = _( |
|
3379 | msg = _( | |
3377 | b"cannot register a sidedata computer twice for category '%s'." |
|
3380 | b"cannot register a sidedata computer twice for category '%s'." | |
3378 | ) |
|
3381 | ) | |
3379 | raise error.ProgrammingError(msg % category) |
|
3382 | raise error.ProgrammingError(msg % category) | |
3380 | self._sidedata_computers.setdefault(kind, {}) |
|
3383 | self._sidedata_computers.setdefault(kind, {}) | |
3381 | self._sidedata_computers[kind][category] = (keys, computer) |
|
3384 | self._sidedata_computers[kind][category] = (keys, computer) | |
3382 |
|
3385 | |||
3383 |
|
3386 | |||
3384 | # used to avoid circular references so destructors work |
|
3387 | # used to avoid circular references so destructors work | |
3385 | def aftertrans(files): |
|
3388 | def aftertrans(files): | |
3386 | renamefiles = [tuple(t) for t in files] |
|
3389 | renamefiles = [tuple(t) for t in files] | |
3387 |
|
3390 | |||
3388 | def a(): |
|
3391 | def a(): | |
3389 | for vfs, src, dest in renamefiles: |
|
3392 | for vfs, src, dest in renamefiles: | |
3390 | # if src and dest refer to a same file, vfs.rename is a no-op, |
|
3393 | # if src and dest refer to a same file, vfs.rename is a no-op, | |
3391 | # leaving both src and dest on disk. delete dest to make sure |
|
3394 | # leaving both src and dest on disk. delete dest to make sure | |
3392 | # the rename couldn't be such a no-op. |
|
3395 | # the rename couldn't be such a no-op. | |
3393 | vfs.tryunlink(dest) |
|
3396 | vfs.tryunlink(dest) | |
3394 | try: |
|
3397 | try: | |
3395 | vfs.rename(src, dest) |
|
3398 | vfs.rename(src, dest) | |
3396 | except OSError: # journal file does not yet exist |
|
3399 | except OSError: # journal file does not yet exist | |
3397 | pass |
|
3400 | pass | |
3398 |
|
3401 | |||
3399 | return a |
|
3402 | return a | |
3400 |
|
3403 | |||
3401 |
|
3404 | |||
3402 | def undoname(fn): |
|
3405 | def undoname(fn): | |
3403 | base, name = os.path.split(fn) |
|
3406 | base, name = os.path.split(fn) | |
3404 | assert name.startswith(b'journal') |
|
3407 | assert name.startswith(b'journal') | |
3405 | return os.path.join(base, name.replace(b'journal', b'undo', 1)) |
|
3408 | return os.path.join(base, name.replace(b'journal', b'undo', 1)) | |
3406 |
|
3409 | |||
3407 |
|
3410 | |||
3408 | def instance(ui, path, create, intents=None, createopts=None): |
|
3411 | def instance(ui, path, create, intents=None, createopts=None): | |
3409 | localpath = urlutil.urllocalpath(path) |
|
3412 | localpath = urlutil.urllocalpath(path) | |
3410 | if create: |
|
3413 | if create: | |
3411 | createrepository(ui, localpath, createopts=createopts) |
|
3414 | createrepository(ui, localpath, createopts=createopts) | |
3412 |
|
3415 | |||
3413 | return makelocalrepository(ui, localpath, intents=intents) |
|
3416 | return makelocalrepository(ui, localpath, intents=intents) | |
3414 |
|
3417 | |||
3415 |
|
3418 | |||
3416 | def islocal(path): |
|
3419 | def islocal(path): | |
3417 | return True |
|
3420 | return True | |
3418 |
|
3421 | |||
3419 |
|
3422 | |||
3420 | def defaultcreateopts(ui, createopts=None): |
|
3423 | def defaultcreateopts(ui, createopts=None): | |
3421 | """Populate the default creation options for a repository. |
|
3424 | """Populate the default creation options for a repository. | |
3422 |
|
3425 | |||
3423 | A dictionary of explicitly requested creation options can be passed |
|
3426 | A dictionary of explicitly requested creation options can be passed | |
3424 | in. Missing keys will be populated. |
|
3427 | in. Missing keys will be populated. | |
3425 | """ |
|
3428 | """ | |
3426 | createopts = dict(createopts or {}) |
|
3429 | createopts = dict(createopts or {}) | |
3427 |
|
3430 | |||
3428 | if b'backend' not in createopts: |
|
3431 | if b'backend' not in createopts: | |
3429 | # experimental config: storage.new-repo-backend |
|
3432 | # experimental config: storage.new-repo-backend | |
3430 | createopts[b'backend'] = ui.config(b'storage', b'new-repo-backend') |
|
3433 | createopts[b'backend'] = ui.config(b'storage', b'new-repo-backend') | |
3431 |
|
3434 | |||
3432 | return createopts |
|
3435 | return createopts | |
3433 |
|
3436 | |||
3434 |
|
3437 | |||
3435 | def newreporequirements(ui, createopts): |
|
3438 | def newreporequirements(ui, createopts): | |
3436 | """Determine the set of requirements for a new local repository. |
|
3439 | """Determine the set of requirements for a new local repository. | |
3437 |
|
3440 | |||
3438 | Extensions can wrap this function to specify custom requirements for |
|
3441 | Extensions can wrap this function to specify custom requirements for | |
3439 | new repositories. |
|
3442 | new repositories. | |
3440 | """ |
|
3443 | """ | |
3441 | # If the repo is being created from a shared repository, we copy |
|
3444 | # If the repo is being created from a shared repository, we copy | |
3442 | # its requirements. |
|
3445 | # its requirements. | |
3443 | if b'sharedrepo' in createopts: |
|
3446 | if b'sharedrepo' in createopts: | |
3444 | requirements = set(createopts[b'sharedrepo'].requirements) |
|
3447 | requirements = set(createopts[b'sharedrepo'].requirements) | |
3445 | if createopts.get(b'sharedrelative'): |
|
3448 | if createopts.get(b'sharedrelative'): | |
3446 | requirements.add(requirementsmod.RELATIVE_SHARED_REQUIREMENT) |
|
3449 | requirements.add(requirementsmod.RELATIVE_SHARED_REQUIREMENT) | |
3447 | else: |
|
3450 | else: | |
3448 | requirements.add(requirementsmod.SHARED_REQUIREMENT) |
|
3451 | requirements.add(requirementsmod.SHARED_REQUIREMENT) | |
3449 |
|
3452 | |||
3450 | return requirements |
|
3453 | return requirements | |
3451 |
|
3454 | |||
3452 | if b'backend' not in createopts: |
|
3455 | if b'backend' not in createopts: | |
3453 | raise error.ProgrammingError( |
|
3456 | raise error.ProgrammingError( | |
3454 | b'backend key not present in createopts; ' |
|
3457 | b'backend key not present in createopts; ' | |
3455 | b'was defaultcreateopts() called?' |
|
3458 | b'was defaultcreateopts() called?' | |
3456 | ) |
|
3459 | ) | |
3457 |
|
3460 | |||
3458 | if createopts[b'backend'] != b'revlogv1': |
|
3461 | if createopts[b'backend'] != b'revlogv1': | |
3459 | raise error.Abort( |
|
3462 | raise error.Abort( | |
3460 | _( |
|
3463 | _( | |
3461 | b'unable to determine repository requirements for ' |
|
3464 | b'unable to determine repository requirements for ' | |
3462 | b'storage backend: %s' |
|
3465 | b'storage backend: %s' | |
3463 | ) |
|
3466 | ) | |
3464 | % createopts[b'backend'] |
|
3467 | % createopts[b'backend'] | |
3465 | ) |
|
3468 | ) | |
3466 |
|
3469 | |||
3467 | requirements = {requirementsmod.REVLOGV1_REQUIREMENT} |
|
3470 | requirements = {requirementsmod.REVLOGV1_REQUIREMENT} | |
3468 | if ui.configbool(b'format', b'usestore'): |
|
3471 | if ui.configbool(b'format', b'usestore'): | |
3469 | requirements.add(requirementsmod.STORE_REQUIREMENT) |
|
3472 | requirements.add(requirementsmod.STORE_REQUIREMENT) | |
3470 | if ui.configbool(b'format', b'usefncache'): |
|
3473 | if ui.configbool(b'format', b'usefncache'): | |
3471 | requirements.add(requirementsmod.FNCACHE_REQUIREMENT) |
|
3474 | requirements.add(requirementsmod.FNCACHE_REQUIREMENT) | |
3472 | if ui.configbool(b'format', b'dotencode'): |
|
3475 | if ui.configbool(b'format', b'dotencode'): | |
3473 | requirements.add(requirementsmod.DOTENCODE_REQUIREMENT) |
|
3476 | requirements.add(requirementsmod.DOTENCODE_REQUIREMENT) | |
3474 |
|
3477 | |||
3475 | compengines = ui.configlist(b'format', b'revlog-compression') |
|
3478 | compengines = ui.configlist(b'format', b'revlog-compression') | |
3476 | for compengine in compengines: |
|
3479 | for compengine in compengines: | |
3477 | if compengine in util.compengines: |
|
3480 | if compengine in util.compengines: | |
3478 | engine = util.compengines[compengine] |
|
3481 | engine = util.compengines[compengine] | |
3479 | if engine.available() and engine.revlogheader(): |
|
3482 | if engine.available() and engine.revlogheader(): | |
3480 | break |
|
3483 | break | |
3481 | else: |
|
3484 | else: | |
3482 | raise error.Abort( |
|
3485 | raise error.Abort( | |
3483 | _( |
|
3486 | _( | |
3484 | b'compression engines %s defined by ' |
|
3487 | b'compression engines %s defined by ' | |
3485 | b'format.revlog-compression not available' |
|
3488 | b'format.revlog-compression not available' | |
3486 | ) |
|
3489 | ) | |
3487 | % b', '.join(b'"%s"' % e for e in compengines), |
|
3490 | % b', '.join(b'"%s"' % e for e in compengines), | |
3488 | hint=_( |
|
3491 | hint=_( | |
3489 | b'run "hg debuginstall" to list available ' |
|
3492 | b'run "hg debuginstall" to list available ' | |
3490 | b'compression engines' |
|
3493 | b'compression engines' | |
3491 | ), |
|
3494 | ), | |
3492 | ) |
|
3495 | ) | |
3493 |
|
3496 | |||
3494 | # zlib is the historical default and doesn't need an explicit requirement. |
|
3497 | # zlib is the historical default and doesn't need an explicit requirement. | |
3495 | if compengine == b'zstd': |
|
3498 | if compengine == b'zstd': | |
3496 | requirements.add(b'revlog-compression-zstd') |
|
3499 | requirements.add(b'revlog-compression-zstd') | |
3497 | elif compengine != b'zlib': |
|
3500 | elif compengine != b'zlib': | |
3498 | requirements.add(b'exp-compression-%s' % compengine) |
|
3501 | requirements.add(b'exp-compression-%s' % compengine) | |
3499 |
|
3502 | |||
3500 | if scmutil.gdinitconfig(ui): |
|
3503 | if scmutil.gdinitconfig(ui): | |
3501 | requirements.add(requirementsmod.GENERALDELTA_REQUIREMENT) |
|
3504 | requirements.add(requirementsmod.GENERALDELTA_REQUIREMENT) | |
3502 | if ui.configbool(b'format', b'sparse-revlog'): |
|
3505 | if ui.configbool(b'format', b'sparse-revlog'): | |
3503 | requirements.add(requirementsmod.SPARSEREVLOG_REQUIREMENT) |
|
3506 | requirements.add(requirementsmod.SPARSEREVLOG_REQUIREMENT) | |
3504 |
|
3507 | |||
3505 | # experimental config: format.exp-use-side-data |
|
3508 | # experimental config: format.exp-use-side-data | |
3506 | if ui.configbool(b'format', b'exp-use-side-data'): |
|
3509 | if ui.configbool(b'format', b'exp-use-side-data'): | |
3507 | requirements.discard(requirementsmod.REVLOGV1_REQUIREMENT) |
|
3510 | requirements.discard(requirementsmod.REVLOGV1_REQUIREMENT) | |
3508 | requirements.add(requirementsmod.REVLOGV2_REQUIREMENT) |
|
3511 | requirements.add(requirementsmod.REVLOGV2_REQUIREMENT) | |
3509 | requirements.add(requirementsmod.SIDEDATA_REQUIREMENT) |
|
3512 | requirements.add(requirementsmod.SIDEDATA_REQUIREMENT) | |
3510 | # experimental config: format.exp-use-copies-side-data-changeset |
|
3513 | # experimental config: format.exp-use-copies-side-data-changeset | |
3511 | if ui.configbool(b'format', b'exp-use-copies-side-data-changeset'): |
|
3514 | if ui.configbool(b'format', b'exp-use-copies-side-data-changeset'): | |
3512 | requirements.discard(requirementsmod.REVLOGV1_REQUIREMENT) |
|
3515 | requirements.discard(requirementsmod.REVLOGV1_REQUIREMENT) | |
3513 | requirements.add(requirementsmod.REVLOGV2_REQUIREMENT) |
|
3516 | requirements.add(requirementsmod.REVLOGV2_REQUIREMENT) | |
3514 | requirements.add(requirementsmod.SIDEDATA_REQUIREMENT) |
|
3517 | requirements.add(requirementsmod.SIDEDATA_REQUIREMENT) | |
3515 | requirements.add(requirementsmod.COPIESSDC_REQUIREMENT) |
|
3518 | requirements.add(requirementsmod.COPIESSDC_REQUIREMENT) | |
3516 | if ui.configbool(b'experimental', b'treemanifest'): |
|
3519 | if ui.configbool(b'experimental', b'treemanifest'): | |
3517 | requirements.add(requirementsmod.TREEMANIFEST_REQUIREMENT) |
|
3520 | requirements.add(requirementsmod.TREEMANIFEST_REQUIREMENT) | |
3518 |
|
3521 | |||
3519 | revlogv2 = ui.config(b'experimental', b'revlogv2') |
|
3522 | revlogv2 = ui.config(b'experimental', b'revlogv2') | |
3520 | if revlogv2 == b'enable-unstable-format-and-corrupt-my-data': |
|
3523 | if revlogv2 == b'enable-unstable-format-and-corrupt-my-data': | |
3521 | requirements.discard(requirementsmod.REVLOGV1_REQUIREMENT) |
|
3524 | requirements.discard(requirementsmod.REVLOGV1_REQUIREMENT) | |
3522 | # generaldelta is implied by revlogv2. |
|
3525 | # generaldelta is implied by revlogv2. | |
3523 | requirements.discard(requirementsmod.GENERALDELTA_REQUIREMENT) |
|
3526 | requirements.discard(requirementsmod.GENERALDELTA_REQUIREMENT) | |
3524 | requirements.add(requirementsmod.REVLOGV2_REQUIREMENT) |
|
3527 | requirements.add(requirementsmod.REVLOGV2_REQUIREMENT) | |
3525 | # experimental config: format.internal-phase |
|
3528 | # experimental config: format.internal-phase | |
3526 | if ui.configbool(b'format', b'internal-phase'): |
|
3529 | if ui.configbool(b'format', b'internal-phase'): | |
3527 | requirements.add(requirementsmod.INTERNAL_PHASE_REQUIREMENT) |
|
3530 | requirements.add(requirementsmod.INTERNAL_PHASE_REQUIREMENT) | |
3528 |
|
3531 | |||
3529 | if createopts.get(b'narrowfiles'): |
|
3532 | if createopts.get(b'narrowfiles'): | |
3530 | requirements.add(requirementsmod.NARROW_REQUIREMENT) |
|
3533 | requirements.add(requirementsmod.NARROW_REQUIREMENT) | |
3531 |
|
3534 | |||
3532 | if createopts.get(b'lfs'): |
|
3535 | if createopts.get(b'lfs'): | |
3533 | requirements.add(b'lfs') |
|
3536 | requirements.add(b'lfs') | |
3534 |
|
3537 | |||
3535 | if ui.configbool(b'format', b'bookmarks-in-store'): |
|
3538 | if ui.configbool(b'format', b'bookmarks-in-store'): | |
3536 | requirements.add(bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT) |
|
3539 | requirements.add(bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT) | |
3537 |
|
3540 | |||
3538 | if ui.configbool(b'format', b'use-persistent-nodemap'): |
|
3541 | if ui.configbool(b'format', b'use-persistent-nodemap'): | |
3539 | requirements.add(requirementsmod.NODEMAP_REQUIREMENT) |
|
3542 | requirements.add(requirementsmod.NODEMAP_REQUIREMENT) | |
3540 |
|
3543 | |||
3541 | # if share-safe is enabled, let's create the new repository with the new |
|
3544 | # if share-safe is enabled, let's create the new repository with the new | |
3542 | # requirement |
|
3545 | # requirement | |
3543 | if ui.configbool(b'format', b'use-share-safe'): |
|
3546 | if ui.configbool(b'format', b'use-share-safe'): | |
3544 | requirements.add(requirementsmod.SHARESAFE_REQUIREMENT) |
|
3547 | requirements.add(requirementsmod.SHARESAFE_REQUIREMENT) | |
3545 |
|
3548 | |||
3546 | return requirements |
|
3549 | return requirements | |
3547 |
|
3550 | |||
3548 |
|
3551 | |||
3549 | def checkrequirementscompat(ui, requirements): |
|
3552 | def checkrequirementscompat(ui, requirements): | |
3550 | """Checks compatibility of repository requirements enabled and disabled. |
|
3553 | """Checks compatibility of repository requirements enabled and disabled. | |
3551 |
|
3554 | |||
3552 | Returns a set of requirements which needs to be dropped because dependend |
|
3555 | Returns a set of requirements which needs to be dropped because dependend | |
3553 | requirements are not enabled. Also warns users about it""" |
|
3556 | requirements are not enabled. Also warns users about it""" | |
3554 |
|
3557 | |||
3555 | dropped = set() |
|
3558 | dropped = set() | |
3556 |
|
3559 | |||
3557 | if requirementsmod.STORE_REQUIREMENT not in requirements: |
|
3560 | if requirementsmod.STORE_REQUIREMENT not in requirements: | |
3558 | if bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT in requirements: |
|
3561 | if bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT in requirements: | |
3559 | ui.warn( |
|
3562 | ui.warn( | |
3560 | _( |
|
3563 | _( | |
3561 | b'ignoring enabled \'format.bookmarks-in-store\' config ' |
|
3564 | b'ignoring enabled \'format.bookmarks-in-store\' config ' | |
3562 | b'beacuse it is incompatible with disabled ' |
|
3565 | b'beacuse it is incompatible with disabled ' | |
3563 | b'\'format.usestore\' config\n' |
|
3566 | b'\'format.usestore\' config\n' | |
3564 | ) |
|
3567 | ) | |
3565 | ) |
|
3568 | ) | |
3566 | dropped.add(bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT) |
|
3569 | dropped.add(bookmarks.BOOKMARKS_IN_STORE_REQUIREMENT) | |
3567 |
|
3570 | |||
3568 | if ( |
|
3571 | if ( | |
3569 | requirementsmod.SHARED_REQUIREMENT in requirements |
|
3572 | requirementsmod.SHARED_REQUIREMENT in requirements | |
3570 | or requirementsmod.RELATIVE_SHARED_REQUIREMENT in requirements |
|
3573 | or requirementsmod.RELATIVE_SHARED_REQUIREMENT in requirements | |
3571 | ): |
|
3574 | ): | |
3572 | raise error.Abort( |
|
3575 | raise error.Abort( | |
3573 | _( |
|
3576 | _( | |
3574 | b"cannot create shared repository as source was created" |
|
3577 | b"cannot create shared repository as source was created" | |
3575 | b" with 'format.usestore' config disabled" |
|
3578 | b" with 'format.usestore' config disabled" | |
3576 | ) |
|
3579 | ) | |
3577 | ) |
|
3580 | ) | |
3578 |
|
3581 | |||
3579 | if requirementsmod.SHARESAFE_REQUIREMENT in requirements: |
|
3582 | if requirementsmod.SHARESAFE_REQUIREMENT in requirements: | |
3580 | ui.warn( |
|
3583 | ui.warn( | |
3581 | _( |
|
3584 | _( | |
3582 | b"ignoring enabled 'format.use-share-safe' config because " |
|
3585 | b"ignoring enabled 'format.use-share-safe' config because " | |
3583 | b"it is incompatible with disabled 'format.usestore'" |
|
3586 | b"it is incompatible with disabled 'format.usestore'" | |
3584 | b" config\n" |
|
3587 | b" config\n" | |
3585 | ) |
|
3588 | ) | |
3586 | ) |
|
3589 | ) | |
3587 | dropped.add(requirementsmod.SHARESAFE_REQUIREMENT) |
|
3590 | dropped.add(requirementsmod.SHARESAFE_REQUIREMENT) | |
3588 |
|
3591 | |||
3589 | return dropped |
|
3592 | return dropped | |
3590 |
|
3593 | |||
3591 |
|
3594 | |||
3592 | def filterknowncreateopts(ui, createopts): |
|
3595 | def filterknowncreateopts(ui, createopts): | |
3593 | """Filters a dict of repo creation options against options that are known. |
|
3596 | """Filters a dict of repo creation options against options that are known. | |
3594 |
|
3597 | |||
3595 | Receives a dict of repo creation options and returns a dict of those |
|
3598 | Receives a dict of repo creation options and returns a dict of those | |
3596 | options that we don't know how to handle. |
|
3599 | options that we don't know how to handle. | |
3597 |
|
3600 | |||
3598 | This function is called as part of repository creation. If the |
|
3601 | This function is called as part of repository creation. If the | |
3599 | returned dict contains any items, repository creation will not |
|
3602 | returned dict contains any items, repository creation will not | |
3600 | be allowed, as it means there was a request to create a repository |
|
3603 | be allowed, as it means there was a request to create a repository | |
3601 | with options not recognized by loaded code. |
|
3604 | with options not recognized by loaded code. | |
3602 |
|
3605 | |||
3603 | Extensions can wrap this function to filter out creation options |
|
3606 | Extensions can wrap this function to filter out creation options | |
3604 | they know how to handle. |
|
3607 | they know how to handle. | |
3605 | """ |
|
3608 | """ | |
3606 | known = { |
|
3609 | known = { | |
3607 | b'backend', |
|
3610 | b'backend', | |
3608 | b'lfs', |
|
3611 | b'lfs', | |
3609 | b'narrowfiles', |
|
3612 | b'narrowfiles', | |
3610 | b'sharedrepo', |
|
3613 | b'sharedrepo', | |
3611 | b'sharedrelative', |
|
3614 | b'sharedrelative', | |
3612 | b'shareditems', |
|
3615 | b'shareditems', | |
3613 | b'shallowfilestore', |
|
3616 | b'shallowfilestore', | |
3614 | } |
|
3617 | } | |
3615 |
|
3618 | |||
3616 | return {k: v for k, v in createopts.items() if k not in known} |
|
3619 | return {k: v for k, v in createopts.items() if k not in known} | |
3617 |
|
3620 | |||
3618 |
|
3621 | |||
3619 | def createrepository(ui, path, createopts=None): |
|
3622 | def createrepository(ui, path, createopts=None): | |
3620 | """Create a new repository in a vfs. |
|
3623 | """Create a new repository in a vfs. | |
3621 |
|
3624 | |||
3622 | ``path`` path to the new repo's working directory. |
|
3625 | ``path`` path to the new repo's working directory. | |
3623 | ``createopts`` options for the new repository. |
|
3626 | ``createopts`` options for the new repository. | |
3624 |
|
3627 | |||
3625 | The following keys for ``createopts`` are recognized: |
|
3628 | The following keys for ``createopts`` are recognized: | |
3626 |
|
3629 | |||
3627 | backend |
|
3630 | backend | |
3628 | The storage backend to use. |
|
3631 | The storage backend to use. | |
3629 | lfs |
|
3632 | lfs | |
3630 | Repository will be created with ``lfs`` requirement. The lfs extension |
|
3633 | Repository will be created with ``lfs`` requirement. The lfs extension | |
3631 | will automatically be loaded when the repository is accessed. |
|
3634 | will automatically be loaded when the repository is accessed. | |
3632 | narrowfiles |
|
3635 | narrowfiles | |
3633 | Set up repository to support narrow file storage. |
|
3636 | Set up repository to support narrow file storage. | |
3634 | sharedrepo |
|
3637 | sharedrepo | |
3635 | Repository object from which storage should be shared. |
|
3638 | Repository object from which storage should be shared. | |
3636 | sharedrelative |
|
3639 | sharedrelative | |
3637 | Boolean indicating if the path to the shared repo should be |
|
3640 | Boolean indicating if the path to the shared repo should be | |
3638 | stored as relative. By default, the pointer to the "parent" repo |
|
3641 | stored as relative. By default, the pointer to the "parent" repo | |
3639 | is stored as an absolute path. |
|
3642 | is stored as an absolute path. | |
3640 | shareditems |
|
3643 | shareditems | |
3641 | Set of items to share to the new repository (in addition to storage). |
|
3644 | Set of items to share to the new repository (in addition to storage). | |
3642 | shallowfilestore |
|
3645 | shallowfilestore | |
3643 | Indicates that storage for files should be shallow (not all ancestor |
|
3646 | Indicates that storage for files should be shallow (not all ancestor | |
3644 | revisions are known). |
|
3647 | revisions are known). | |
3645 | """ |
|
3648 | """ | |
3646 | createopts = defaultcreateopts(ui, createopts=createopts) |
|
3649 | createopts = defaultcreateopts(ui, createopts=createopts) | |
3647 |
|
3650 | |||
3648 | unknownopts = filterknowncreateopts(ui, createopts) |
|
3651 | unknownopts = filterknowncreateopts(ui, createopts) | |
3649 |
|
3652 | |||
3650 | if not isinstance(unknownopts, dict): |
|
3653 | if not isinstance(unknownopts, dict): | |
3651 | raise error.ProgrammingError( |
|
3654 | raise error.ProgrammingError( | |
3652 | b'filterknowncreateopts() did not return a dict' |
|
3655 | b'filterknowncreateopts() did not return a dict' | |
3653 | ) |
|
3656 | ) | |
3654 |
|
3657 | |||
3655 | if unknownopts: |
|
3658 | if unknownopts: | |
3656 | raise error.Abort( |
|
3659 | raise error.Abort( | |
3657 | _( |
|
3660 | _( | |
3658 | b'unable to create repository because of unknown ' |
|
3661 | b'unable to create repository because of unknown ' | |
3659 | b'creation option: %s' |
|
3662 | b'creation option: %s' | |
3660 | ) |
|
3663 | ) | |
3661 | % b', '.join(sorted(unknownopts)), |
|
3664 | % b', '.join(sorted(unknownopts)), | |
3662 | hint=_(b'is a required extension not loaded?'), |
|
3665 | hint=_(b'is a required extension not loaded?'), | |
3663 | ) |
|
3666 | ) | |
3664 |
|
3667 | |||
3665 | requirements = newreporequirements(ui, createopts=createopts) |
|
3668 | requirements = newreporequirements(ui, createopts=createopts) | |
3666 | requirements -= checkrequirementscompat(ui, requirements) |
|
3669 | requirements -= checkrequirementscompat(ui, requirements) | |
3667 |
|
3670 | |||
3668 | wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) |
|
3671 | wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True) | |
3669 |
|
3672 | |||
3670 | hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg')) |
|
3673 | hgvfs = vfsmod.vfs(wdirvfs.join(b'.hg')) | |
3671 | if hgvfs.exists(): |
|
3674 | if hgvfs.exists(): | |
3672 | raise error.RepoError(_(b'repository %s already exists') % path) |
|
3675 | raise error.RepoError(_(b'repository %s already exists') % path) | |
3673 |
|
3676 | |||
3674 | if b'sharedrepo' in createopts: |
|
3677 | if b'sharedrepo' in createopts: | |
3675 | sharedpath = createopts[b'sharedrepo'].sharedpath |
|
3678 | sharedpath = createopts[b'sharedrepo'].sharedpath | |
3676 |
|
3679 | |||
3677 | if createopts.get(b'sharedrelative'): |
|
3680 | if createopts.get(b'sharedrelative'): | |
3678 | try: |
|
3681 | try: | |
3679 | sharedpath = os.path.relpath(sharedpath, hgvfs.base) |
|
3682 | sharedpath = os.path.relpath(sharedpath, hgvfs.base) | |
3680 | sharedpath = util.pconvert(sharedpath) |
|
3683 | sharedpath = util.pconvert(sharedpath) | |
3681 | except (IOError, ValueError) as e: |
|
3684 | except (IOError, ValueError) as e: | |
3682 | # ValueError is raised on Windows if the drive letters differ |
|
3685 | # ValueError is raised on Windows if the drive letters differ | |
3683 | # on each path. |
|
3686 | # on each path. | |
3684 | raise error.Abort( |
|
3687 | raise error.Abort( | |
3685 | _(b'cannot calculate relative path'), |
|
3688 | _(b'cannot calculate relative path'), | |
3686 | hint=stringutil.forcebytestr(e), |
|
3689 | hint=stringutil.forcebytestr(e), | |
3687 | ) |
|
3690 | ) | |
3688 |
|
3691 | |||
3689 | if not wdirvfs.exists(): |
|
3692 | if not wdirvfs.exists(): | |
3690 | wdirvfs.makedirs() |
|
3693 | wdirvfs.makedirs() | |
3691 |
|
3694 | |||
3692 | hgvfs.makedir(notindexed=True) |
|
3695 | hgvfs.makedir(notindexed=True) | |
3693 | if b'sharedrepo' not in createopts: |
|
3696 | if b'sharedrepo' not in createopts: | |
3694 | hgvfs.mkdir(b'cache') |
|
3697 | hgvfs.mkdir(b'cache') | |
3695 | hgvfs.mkdir(b'wcache') |
|
3698 | hgvfs.mkdir(b'wcache') | |
3696 |
|
3699 | |||
3697 | has_store = requirementsmod.STORE_REQUIREMENT in requirements |
|
3700 | has_store = requirementsmod.STORE_REQUIREMENT in requirements | |
3698 | if has_store and b'sharedrepo' not in createopts: |
|
3701 | if has_store and b'sharedrepo' not in createopts: | |
3699 | hgvfs.mkdir(b'store') |
|
3702 | hgvfs.mkdir(b'store') | |
3700 |
|
3703 | |||
3701 | # We create an invalid changelog outside the store so very old |
|
3704 | # We create an invalid changelog outside the store so very old | |
3702 | # Mercurial versions (which didn't know about the requirements |
|
3705 | # Mercurial versions (which didn't know about the requirements | |
3703 | # file) encounter an error on reading the changelog. This |
|
3706 | # file) encounter an error on reading the changelog. This | |
3704 | # effectively locks out old clients and prevents them from |
|
3707 | # effectively locks out old clients and prevents them from | |
3705 | # mucking with a repo in an unknown format. |
|
3708 | # mucking with a repo in an unknown format. | |
3706 | # |
|
3709 | # | |
3707 | # The revlog header has version 65535, which won't be recognized by |
|
3710 | # The revlog header has version 65535, which won't be recognized by | |
3708 | # such old clients. |
|
3711 | # such old clients. | |
3709 | hgvfs.append( |
|
3712 | hgvfs.append( | |
3710 | b'00changelog.i', |
|
3713 | b'00changelog.i', | |
3711 | b'\0\0\xFF\xFF dummy changelog to prevent using the old repo ' |
|
3714 | b'\0\0\xFF\xFF dummy changelog to prevent using the old repo ' | |
3712 | b'layout', |
|
3715 | b'layout', | |
3713 | ) |
|
3716 | ) | |
3714 |
|
3717 | |||
3715 | # Filter the requirements into working copy and store ones |
|
3718 | # Filter the requirements into working copy and store ones | |
3716 | wcreq, storereq = scmutil.filterrequirements(requirements) |
|
3719 | wcreq, storereq = scmutil.filterrequirements(requirements) | |
3717 | # write working copy ones |
|
3720 | # write working copy ones | |
3718 | scmutil.writerequires(hgvfs, wcreq) |
|
3721 | scmutil.writerequires(hgvfs, wcreq) | |
3719 | # If there are store requirements and the current repository |
|
3722 | # If there are store requirements and the current repository | |
3720 | # is not a shared one, write stored requirements |
|
3723 | # is not a shared one, write stored requirements | |
3721 | # For new shared repository, we don't need to write the store |
|
3724 | # For new shared repository, we don't need to write the store | |
3722 | # requirements as they are already present in store requires |
|
3725 | # requirements as they are already present in store requires | |
3723 | if storereq and b'sharedrepo' not in createopts: |
|
3726 | if storereq and b'sharedrepo' not in createopts: | |
3724 | storevfs = vfsmod.vfs(hgvfs.join(b'store'), cacheaudited=True) |
|
3727 | storevfs = vfsmod.vfs(hgvfs.join(b'store'), cacheaudited=True) | |
3725 | scmutil.writerequires(storevfs, storereq) |
|
3728 | scmutil.writerequires(storevfs, storereq) | |
3726 |
|
3729 | |||
3727 | # Write out file telling readers where to find the shared store. |
|
3730 | # Write out file telling readers where to find the shared store. | |
3728 | if b'sharedrepo' in createopts: |
|
3731 | if b'sharedrepo' in createopts: | |
3729 | hgvfs.write(b'sharedpath', sharedpath) |
|
3732 | hgvfs.write(b'sharedpath', sharedpath) | |
3730 |
|
3733 | |||
3731 | if createopts.get(b'shareditems'): |
|
3734 | if createopts.get(b'shareditems'): | |
3732 | shared = b'\n'.join(sorted(createopts[b'shareditems'])) + b'\n' |
|
3735 | shared = b'\n'.join(sorted(createopts[b'shareditems'])) + b'\n' | |
3733 | hgvfs.write(b'shared', shared) |
|
3736 | hgvfs.write(b'shared', shared) | |
3734 |
|
3737 | |||
3735 |
|
3738 | |||
3736 | def poisonrepository(repo): |
|
3739 | def poisonrepository(repo): | |
3737 | """Poison a repository instance so it can no longer be used.""" |
|
3740 | """Poison a repository instance so it can no longer be used.""" | |
3738 | # Perform any cleanup on the instance. |
|
3741 | # Perform any cleanup on the instance. | |
3739 | repo.close() |
|
3742 | repo.close() | |
3740 |
|
3743 | |||
3741 | # Our strategy is to replace the type of the object with one that |
|
3744 | # Our strategy is to replace the type of the object with one that | |
3742 | # has all attribute lookups result in error. |
|
3745 | # has all attribute lookups result in error. | |
3743 | # |
|
3746 | # | |
3744 | # But we have to allow the close() method because some constructors |
|
3747 | # But we have to allow the close() method because some constructors | |
3745 | # of repos call close() on repo references. |
|
3748 | # of repos call close() on repo references. | |
3746 | class poisonedrepository(object): |
|
3749 | class poisonedrepository(object): | |
3747 | def __getattribute__(self, item): |
|
3750 | def __getattribute__(self, item): | |
3748 | if item == 'close': |
|
3751 | if item == 'close': | |
3749 | return object.__getattribute__(self, item) |
|
3752 | return object.__getattribute__(self, item) | |
3750 |
|
3753 | |||
3751 | raise error.ProgrammingError( |
|
3754 | raise error.ProgrammingError( | |
3752 | b'repo instances should not be used after unshare' |
|
3755 | b'repo instances should not be used after unshare' | |
3753 | ) |
|
3756 | ) | |
3754 |
|
3757 | |||
3755 | def close(self): |
|
3758 | def close(self): | |
3756 | pass |
|
3759 | pass | |
3757 |
|
3760 | |||
3758 | # We may have a repoview, which intercepts __setattr__. So be sure |
|
3761 | # We may have a repoview, which intercepts __setattr__. So be sure | |
3759 | # we operate at the lowest level possible. |
|
3762 | # we operate at the lowest level possible. | |
3760 | object.__setattr__(repo, '__class__', poisonedrepository) |
|
3763 | object.__setattr__(repo, '__class__', poisonedrepository) |
@@ -1,3142 +1,3142 b'' | |||||
1 | # revlog.py - storage back-end for mercurial |
|
1 | # revlog.py - storage back-end for mercurial | |
2 | # |
|
2 | # | |
3 | # Copyright 2005-2007 Olivia Mackall <olivia@selenic.com> |
|
3 | # Copyright 2005-2007 Olivia Mackall <olivia@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 | """Storage back-end for Mercurial. |
|
8 | """Storage back-end for Mercurial. | |
9 |
|
9 | |||
10 | This provides efficient delta storage with O(1) retrieve and append |
|
10 | This provides efficient delta storage with O(1) retrieve and append | |
11 | and O(changes) merge between branches. |
|
11 | and O(changes) merge between branches. | |
12 | """ |
|
12 | """ | |
13 |
|
13 | |||
14 | from __future__ import absolute_import |
|
14 | from __future__ import absolute_import | |
15 |
|
15 | |||
16 | import binascii |
|
16 | import binascii | |
17 | import collections |
|
17 | import collections | |
18 | import contextlib |
|
18 | import contextlib | |
19 | import errno |
|
19 | import errno | |
20 | import io |
|
20 | import io | |
21 | import os |
|
21 | import os | |
22 | import struct |
|
22 | import struct | |
23 | import zlib |
|
23 | import zlib | |
24 |
|
24 | |||
25 | # import stuff from node for others to import from revlog |
|
25 | # import stuff from node for others to import from revlog | |
26 | from .node import ( |
|
26 | from .node import ( | |
27 | bin, |
|
27 | bin, | |
28 | hex, |
|
28 | hex, | |
29 | nullrev, |
|
29 | nullrev, | |
30 | sha1nodeconstants, |
|
30 | sha1nodeconstants, | |
31 | short, |
|
31 | short, | |
32 | wdirrev, |
|
32 | wdirrev, | |
33 | ) |
|
33 | ) | |
34 | from .i18n import _ |
|
34 | from .i18n import _ | |
35 | from .pycompat import getattr |
|
35 | from .pycompat import getattr | |
36 | from .revlogutils.constants import ( |
|
36 | from .revlogutils.constants import ( | |
37 | ALL_KINDS, |
|
37 | ALL_KINDS, | |
38 | FLAG_GENERALDELTA, |
|
38 | FLAG_GENERALDELTA, | |
39 | FLAG_INLINE_DATA, |
|
39 | FLAG_INLINE_DATA, | |
40 | INDEX_HEADER, |
|
40 | INDEX_HEADER, | |
41 | REVLOGV0, |
|
41 | REVLOGV0, | |
42 | REVLOGV1, |
|
42 | REVLOGV1, | |
43 | REVLOGV1_FLAGS, |
|
43 | REVLOGV1_FLAGS, | |
44 | REVLOGV2, |
|
44 | REVLOGV2, | |
45 | REVLOGV2_FLAGS, |
|
45 | REVLOGV2_FLAGS, | |
46 | REVLOG_DEFAULT_FLAGS, |
|
46 | REVLOG_DEFAULT_FLAGS, | |
47 | REVLOG_DEFAULT_FORMAT, |
|
47 | REVLOG_DEFAULT_FORMAT, | |
48 | REVLOG_DEFAULT_VERSION, |
|
48 | REVLOG_DEFAULT_VERSION, | |
49 | ) |
|
49 | ) | |
50 | from .revlogutils.flagutil import ( |
|
50 | from .revlogutils.flagutil import ( | |
51 | REVIDX_DEFAULT_FLAGS, |
|
51 | REVIDX_DEFAULT_FLAGS, | |
52 | REVIDX_ELLIPSIS, |
|
52 | REVIDX_ELLIPSIS, | |
53 | REVIDX_EXTSTORED, |
|
53 | REVIDX_EXTSTORED, | |
54 | REVIDX_FLAGS_ORDER, |
|
54 | REVIDX_FLAGS_ORDER, | |
55 | REVIDX_HASCOPIESINFO, |
|
55 | REVIDX_HASCOPIESINFO, | |
56 | REVIDX_ISCENSORED, |
|
56 | REVIDX_ISCENSORED, | |
57 | REVIDX_RAWTEXT_CHANGING_FLAGS, |
|
57 | REVIDX_RAWTEXT_CHANGING_FLAGS, | |
58 | REVIDX_SIDEDATA, |
|
58 | REVIDX_SIDEDATA, | |
59 | ) |
|
59 | ) | |
60 | from .thirdparty import attr |
|
60 | from .thirdparty import attr | |
61 | from . import ( |
|
61 | from . import ( | |
62 | ancestor, |
|
62 | ancestor, | |
63 | dagop, |
|
63 | dagop, | |
64 | error, |
|
64 | error, | |
65 | mdiff, |
|
65 | mdiff, | |
66 | policy, |
|
66 | policy, | |
67 | pycompat, |
|
67 | pycompat, | |
68 | templatefilters, |
|
68 | templatefilters, | |
69 | util, |
|
69 | util, | |
70 | ) |
|
70 | ) | |
71 | from .interfaces import ( |
|
71 | from .interfaces import ( | |
72 | repository, |
|
72 | repository, | |
73 | util as interfaceutil, |
|
73 | util as interfaceutil, | |
74 | ) |
|
74 | ) | |
75 | from .revlogutils import ( |
|
75 | from .revlogutils import ( | |
76 | deltas as deltautil, |
|
76 | deltas as deltautil, | |
77 | flagutil, |
|
77 | flagutil, | |
78 | nodemap as nodemaputil, |
|
78 | nodemap as nodemaputil, | |
79 | revlogv0, |
|
79 | revlogv0, | |
80 | sidedata as sidedatautil, |
|
80 | sidedata as sidedatautil, | |
81 | ) |
|
81 | ) | |
82 | from .utils import ( |
|
82 | from .utils import ( | |
83 | storageutil, |
|
83 | storageutil, | |
84 | stringutil, |
|
84 | stringutil, | |
85 | ) |
|
85 | ) | |
86 |
|
86 | |||
87 | # blanked usage of all the name to prevent pyflakes constraints |
|
87 | # blanked usage of all the name to prevent pyflakes constraints | |
88 | # We need these name available in the module for extensions. |
|
88 | # We need these name available in the module for extensions. | |
89 | REVLOGV0 |
|
89 | REVLOGV0 | |
90 | REVLOGV1 |
|
90 | REVLOGV1 | |
91 | REVLOGV2 |
|
91 | REVLOGV2 | |
92 | FLAG_INLINE_DATA |
|
92 | FLAG_INLINE_DATA | |
93 | FLAG_GENERALDELTA |
|
93 | FLAG_GENERALDELTA | |
94 | REVLOG_DEFAULT_FLAGS |
|
94 | REVLOG_DEFAULT_FLAGS | |
95 | REVLOG_DEFAULT_FORMAT |
|
95 | REVLOG_DEFAULT_FORMAT | |
96 | REVLOG_DEFAULT_VERSION |
|
96 | REVLOG_DEFAULT_VERSION | |
97 | REVLOGV1_FLAGS |
|
97 | REVLOGV1_FLAGS | |
98 | REVLOGV2_FLAGS |
|
98 | REVLOGV2_FLAGS | |
99 | REVIDX_ISCENSORED |
|
99 | REVIDX_ISCENSORED | |
100 | REVIDX_ELLIPSIS |
|
100 | REVIDX_ELLIPSIS | |
101 | REVIDX_SIDEDATA |
|
101 | REVIDX_SIDEDATA | |
102 | REVIDX_HASCOPIESINFO |
|
102 | REVIDX_HASCOPIESINFO | |
103 | REVIDX_EXTSTORED |
|
103 | REVIDX_EXTSTORED | |
104 | REVIDX_DEFAULT_FLAGS |
|
104 | REVIDX_DEFAULT_FLAGS | |
105 | REVIDX_FLAGS_ORDER |
|
105 | REVIDX_FLAGS_ORDER | |
106 | REVIDX_RAWTEXT_CHANGING_FLAGS |
|
106 | REVIDX_RAWTEXT_CHANGING_FLAGS | |
107 |
|
107 | |||
108 | parsers = policy.importmod('parsers') |
|
108 | parsers = policy.importmod('parsers') | |
109 | rustancestor = policy.importrust('ancestor') |
|
109 | rustancestor = policy.importrust('ancestor') | |
110 | rustdagop = policy.importrust('dagop') |
|
110 | rustdagop = policy.importrust('dagop') | |
111 | rustrevlog = policy.importrust('revlog') |
|
111 | rustrevlog = policy.importrust('revlog') | |
112 |
|
112 | |||
113 | # Aliased for performance. |
|
113 | # Aliased for performance. | |
114 | _zlibdecompress = zlib.decompress |
|
114 | _zlibdecompress = zlib.decompress | |
115 |
|
115 | |||
116 | # max size of revlog with inline data |
|
116 | # max size of revlog with inline data | |
117 | _maxinline = 131072 |
|
117 | _maxinline = 131072 | |
118 | _chunksize = 1048576 |
|
118 | _chunksize = 1048576 | |
119 |
|
119 | |||
120 | # Flag processors for REVIDX_ELLIPSIS. |
|
120 | # Flag processors for REVIDX_ELLIPSIS. | |
121 | def ellipsisreadprocessor(rl, text): |
|
121 | def ellipsisreadprocessor(rl, text): | |
122 | return text, False |
|
122 | return text, False | |
123 |
|
123 | |||
124 |
|
124 | |||
125 | def ellipsiswriteprocessor(rl, text): |
|
125 | def ellipsiswriteprocessor(rl, text): | |
126 | return text, False |
|
126 | return text, False | |
127 |
|
127 | |||
128 |
|
128 | |||
129 | def ellipsisrawprocessor(rl, text): |
|
129 | def ellipsisrawprocessor(rl, text): | |
130 | return False |
|
130 | return False | |
131 |
|
131 | |||
132 |
|
132 | |||
133 | ellipsisprocessor = ( |
|
133 | ellipsisprocessor = ( | |
134 | ellipsisreadprocessor, |
|
134 | ellipsisreadprocessor, | |
135 | ellipsiswriteprocessor, |
|
135 | ellipsiswriteprocessor, | |
136 | ellipsisrawprocessor, |
|
136 | ellipsisrawprocessor, | |
137 | ) |
|
137 | ) | |
138 |
|
138 | |||
139 |
|
139 | |||
140 | def offset_type(offset, type): |
|
140 | def offset_type(offset, type): | |
141 | if (type & ~flagutil.REVIDX_KNOWN_FLAGS) != 0: |
|
141 | if (type & ~flagutil.REVIDX_KNOWN_FLAGS) != 0: | |
142 | raise ValueError(b'unknown revlog index flags') |
|
142 | raise ValueError(b'unknown revlog index flags') | |
143 | return int(int(offset) << 16 | type) |
|
143 | return int(int(offset) << 16 | type) | |
144 |
|
144 | |||
145 |
|
145 | |||
146 | def _verify_revision(rl, skipflags, state, node): |
|
146 | def _verify_revision(rl, skipflags, state, node): | |
147 | """Verify the integrity of the given revlog ``node`` while providing a hook |
|
147 | """Verify the integrity of the given revlog ``node`` while providing a hook | |
148 | point for extensions to influence the operation.""" |
|
148 | point for extensions to influence the operation.""" | |
149 | if skipflags: |
|
149 | if skipflags: | |
150 | state[b'skipread'].add(node) |
|
150 | state[b'skipread'].add(node) | |
151 | else: |
|
151 | else: | |
152 | # Side-effect: read content and verify hash. |
|
152 | # Side-effect: read content and verify hash. | |
153 | rl.revision(node) |
|
153 | rl.revision(node) | |
154 |
|
154 | |||
155 |
|
155 | |||
156 | # True if a fast implementation for persistent-nodemap is available |
|
156 | # True if a fast implementation for persistent-nodemap is available | |
157 | # |
|
157 | # | |
158 | # We also consider we have a "fast" implementation in "pure" python because |
|
158 | # We also consider we have a "fast" implementation in "pure" python because | |
159 | # people using pure don't really have performance consideration (and a |
|
159 | # people using pure don't really have performance consideration (and a | |
160 | # wheelbarrow of other slowness source) |
|
160 | # wheelbarrow of other slowness source) | |
161 | HAS_FAST_PERSISTENT_NODEMAP = rustrevlog is not None or util.safehasattr( |
|
161 | HAS_FAST_PERSISTENT_NODEMAP = rustrevlog is not None or util.safehasattr( | |
162 | parsers, 'BaseIndexObject' |
|
162 | parsers, 'BaseIndexObject' | |
163 | ) |
|
163 | ) | |
164 |
|
164 | |||
165 |
|
165 | |||
166 | @attr.s(slots=True, frozen=True) |
|
166 | @attr.s(slots=True, frozen=True) | |
167 | class _revisioninfo(object): |
|
167 | class _revisioninfo(object): | |
168 | """Information about a revision that allows building its fulltext |
|
168 | """Information about a revision that allows building its fulltext | |
169 | node: expected hash of the revision |
|
169 | node: expected hash of the revision | |
170 | p1, p2: parent revs of the revision |
|
170 | p1, p2: parent revs of the revision | |
171 | btext: built text cache consisting of a one-element list |
|
171 | btext: built text cache consisting of a one-element list | |
172 | cachedelta: (baserev, uncompressed_delta) or None |
|
172 | cachedelta: (baserev, uncompressed_delta) or None | |
173 | flags: flags associated to the revision storage |
|
173 | flags: flags associated to the revision storage | |
174 |
|
174 | |||
175 | One of btext[0] or cachedelta must be set. |
|
175 | One of btext[0] or cachedelta must be set. | |
176 | """ |
|
176 | """ | |
177 |
|
177 | |||
178 | node = attr.ib() |
|
178 | node = attr.ib() | |
179 | p1 = attr.ib() |
|
179 | p1 = attr.ib() | |
180 | p2 = attr.ib() |
|
180 | p2 = attr.ib() | |
181 | btext = attr.ib() |
|
181 | btext = attr.ib() | |
182 | textlen = attr.ib() |
|
182 | textlen = attr.ib() | |
183 | cachedelta = attr.ib() |
|
183 | cachedelta = attr.ib() | |
184 | flags = attr.ib() |
|
184 | flags = attr.ib() | |
185 |
|
185 | |||
186 |
|
186 | |||
187 | @interfaceutil.implementer(repository.irevisiondelta) |
|
187 | @interfaceutil.implementer(repository.irevisiondelta) | |
188 | @attr.s(slots=True) |
|
188 | @attr.s(slots=True) | |
189 | class revlogrevisiondelta(object): |
|
189 | class revlogrevisiondelta(object): | |
190 | node = attr.ib() |
|
190 | node = attr.ib() | |
191 | p1node = attr.ib() |
|
191 | p1node = attr.ib() | |
192 | p2node = attr.ib() |
|
192 | p2node = attr.ib() | |
193 | basenode = attr.ib() |
|
193 | basenode = attr.ib() | |
194 | flags = attr.ib() |
|
194 | flags = attr.ib() | |
195 | baserevisionsize = attr.ib() |
|
195 | baserevisionsize = attr.ib() | |
196 | revision = attr.ib() |
|
196 | revision = attr.ib() | |
197 | delta = attr.ib() |
|
197 | delta = attr.ib() | |
198 | sidedata = attr.ib() |
|
198 | sidedata = attr.ib() | |
199 | linknode = attr.ib(default=None) |
|
199 | linknode = attr.ib(default=None) | |
200 |
|
200 | |||
201 |
|
201 | |||
202 | @interfaceutil.implementer(repository.iverifyproblem) |
|
202 | @interfaceutil.implementer(repository.iverifyproblem) | |
203 | @attr.s(frozen=True) |
|
203 | @attr.s(frozen=True) | |
204 | class revlogproblem(object): |
|
204 | class revlogproblem(object): | |
205 | warning = attr.ib(default=None) |
|
205 | warning = attr.ib(default=None) | |
206 | error = attr.ib(default=None) |
|
206 | error = attr.ib(default=None) | |
207 | node = attr.ib(default=None) |
|
207 | node = attr.ib(default=None) | |
208 |
|
208 | |||
209 |
|
209 | |||
210 | def parse_index_v1(data, inline): |
|
210 | def parse_index_v1(data, inline): | |
211 | # call the C implementation to parse the index data |
|
211 | # call the C implementation to parse the index data | |
212 | index, cache = parsers.parse_index2(data, inline) |
|
212 | index, cache = parsers.parse_index2(data, inline) | |
213 | return index, cache |
|
213 | return index, cache | |
214 |
|
214 | |||
215 |
|
215 | |||
216 | def parse_index_v2(data, inline): |
|
216 | def parse_index_v2(data, inline): | |
217 | # call the C implementation to parse the index data |
|
217 | # call the C implementation to parse the index data | |
218 | index, cache = parsers.parse_index2(data, inline, revlogv2=True) |
|
218 | index, cache = parsers.parse_index2(data, inline, revlogv2=True) | |
219 | return index, cache |
|
219 | return index, cache | |
220 |
|
220 | |||
221 |
|
221 | |||
222 | if util.safehasattr(parsers, 'parse_index_devel_nodemap'): |
|
222 | if util.safehasattr(parsers, 'parse_index_devel_nodemap'): | |
223 |
|
223 | |||
224 | def parse_index_v1_nodemap(data, inline): |
|
224 | def parse_index_v1_nodemap(data, inline): | |
225 | index, cache = parsers.parse_index_devel_nodemap(data, inline) |
|
225 | index, cache = parsers.parse_index_devel_nodemap(data, inline) | |
226 | return index, cache |
|
226 | return index, cache | |
227 |
|
227 | |||
228 |
|
228 | |||
229 | else: |
|
229 | else: | |
230 | parse_index_v1_nodemap = None |
|
230 | parse_index_v1_nodemap = None | |
231 |
|
231 | |||
232 |
|
232 | |||
233 | def parse_index_v1_mixed(data, inline): |
|
233 | def parse_index_v1_mixed(data, inline): | |
234 | index, cache = parse_index_v1(data, inline) |
|
234 | index, cache = parse_index_v1(data, inline) | |
235 | return rustrevlog.MixedIndex(index), cache |
|
235 | return rustrevlog.MixedIndex(index), cache | |
236 |
|
236 | |||
237 |
|
237 | |||
238 | # corresponds to uncompressed length of indexformatng (2 gigs, 4-byte |
|
238 | # corresponds to uncompressed length of indexformatng (2 gigs, 4-byte | |
239 | # signed integer) |
|
239 | # signed integer) | |
240 | _maxentrysize = 0x7FFFFFFF |
|
240 | _maxentrysize = 0x7FFFFFFF | |
241 |
|
241 | |||
242 |
|
242 | |||
243 | class revlog(object): |
|
243 | class revlog(object): | |
244 | """ |
|
244 | """ | |
245 | the underlying revision storage object |
|
245 | the underlying revision storage object | |
246 |
|
246 | |||
247 | A revlog consists of two parts, an index and the revision data. |
|
247 | A revlog consists of two parts, an index and the revision data. | |
248 |
|
248 | |||
249 | The index is a file with a fixed record size containing |
|
249 | The index is a file with a fixed record size containing | |
250 | information on each revision, including its nodeid (hash), the |
|
250 | information on each revision, including its nodeid (hash), the | |
251 | nodeids of its parents, the position and offset of its data within |
|
251 | nodeids of its parents, the position and offset of its data within | |
252 | the data file, and the revision it's based on. Finally, each entry |
|
252 | the data file, and the revision it's based on. Finally, each entry | |
253 | contains a linkrev entry that can serve as a pointer to external |
|
253 | contains a linkrev entry that can serve as a pointer to external | |
254 | data. |
|
254 | data. | |
255 |
|
255 | |||
256 | The revision data itself is a linear collection of data chunks. |
|
256 | The revision data itself is a linear collection of data chunks. | |
257 | Each chunk represents a revision and is usually represented as a |
|
257 | Each chunk represents a revision and is usually represented as a | |
258 | delta against the previous chunk. To bound lookup time, runs of |
|
258 | delta against the previous chunk. To bound lookup time, runs of | |
259 | deltas are limited to about 2 times the length of the original |
|
259 | deltas are limited to about 2 times the length of the original | |
260 | version data. This makes retrieval of a version proportional to |
|
260 | version data. This makes retrieval of a version proportional to | |
261 | its size, or O(1) relative to the number of revisions. |
|
261 | its size, or O(1) relative to the number of revisions. | |
262 |
|
262 | |||
263 | Both pieces of the revlog are written to in an append-only |
|
263 | Both pieces of the revlog are written to in an append-only | |
264 | fashion, which means we never need to rewrite a file to insert or |
|
264 | fashion, which means we never need to rewrite a file to insert or | |
265 | remove data, and can use some simple techniques to avoid the need |
|
265 | remove data, and can use some simple techniques to avoid the need | |
266 | for locking while reading. |
|
266 | for locking while reading. | |
267 |
|
267 | |||
268 | If checkambig, indexfile is opened with checkambig=True at |
|
268 | If checkambig, indexfile is opened with checkambig=True at | |
269 | writing, to avoid file stat ambiguity. |
|
269 | writing, to avoid file stat ambiguity. | |
270 |
|
270 | |||
271 | If mmaplargeindex is True, and an mmapindexthreshold is set, the |
|
271 | If mmaplargeindex is True, and an mmapindexthreshold is set, the | |
272 | index will be mmapped rather than read if it is larger than the |
|
272 | index will be mmapped rather than read if it is larger than the | |
273 | configured threshold. |
|
273 | configured threshold. | |
274 |
|
274 | |||
275 | If censorable is True, the revlog can have censored revisions. |
|
275 | If censorable is True, the revlog can have censored revisions. | |
276 |
|
276 | |||
277 | If `upperboundcomp` is not None, this is the expected maximal gain from |
|
277 | If `upperboundcomp` is not None, this is the expected maximal gain from | |
278 | compression for the data content. |
|
278 | compression for the data content. | |
279 |
|
279 | |||
280 | `concurrencychecker` is an optional function that receives 3 arguments: a |
|
280 | `concurrencychecker` is an optional function that receives 3 arguments: a | |
281 | file handle, a filename, and an expected position. It should check whether |
|
281 | file handle, a filename, and an expected position. It should check whether | |
282 | the current position in the file handle is valid, and log/warn/fail (by |
|
282 | the current position in the file handle is valid, and log/warn/fail (by | |
283 | raising). |
|
283 | raising). | |
284 | """ |
|
284 | """ | |
285 |
|
285 | |||
286 | _flagserrorclass = error.RevlogError |
|
286 | _flagserrorclass = error.RevlogError | |
287 |
|
287 | |||
288 | def __init__( |
|
288 | def __init__( | |
289 | self, |
|
289 | self, | |
290 | opener, |
|
290 | opener, | |
291 | target, |
|
291 | target, | |
292 | indexfile=None, |
|
292 | indexfile=None, | |
293 | datafile=None, |
|
293 | datafile=None, | |
294 | checkambig=False, |
|
294 | checkambig=False, | |
295 | mmaplargeindex=False, |
|
295 | mmaplargeindex=False, | |
296 | censorable=False, |
|
296 | censorable=False, | |
297 | upperboundcomp=None, |
|
297 | upperboundcomp=None, | |
298 | persistentnodemap=False, |
|
298 | persistentnodemap=False, | |
299 | concurrencychecker=None, |
|
299 | concurrencychecker=None, | |
300 | ): |
|
300 | ): | |
301 | """ |
|
301 | """ | |
302 | create a revlog object |
|
302 | create a revlog object | |
303 |
|
303 | |||
304 | opener is a function that abstracts the file opening operation |
|
304 | opener is a function that abstracts the file opening operation | |
305 | and can be used to implement COW semantics or the like. |
|
305 | and can be used to implement COW semantics or the like. | |
306 |
|
306 | |||
307 | `target`: a (KIND, ID) tuple that identify the content stored in |
|
307 | `target`: a (KIND, ID) tuple that identify the content stored in | |
308 | this revlog. It help the rest of the code to understand what the revlog |
|
308 | this revlog. It help the rest of the code to understand what the revlog | |
309 | is about without having to resort to heuristic and index filename |
|
309 | is about without having to resort to heuristic and index filename | |
310 | analysis. Note: that this must be reliably be set by normal code, but |
|
310 | analysis. Note: that this must be reliably be set by normal code, but | |
311 | that test, debug, or performance measurement code might not set this to |
|
311 | that test, debug, or performance measurement code might not set this to | |
312 | accurate value. |
|
312 | accurate value. | |
313 | """ |
|
313 | """ | |
314 | self.upperboundcomp = upperboundcomp |
|
314 | self.upperboundcomp = upperboundcomp | |
315 | self.indexfile = indexfile |
|
315 | self.indexfile = indexfile | |
316 | self.datafile = datafile or (indexfile[:-2] + b".d") |
|
316 | self.datafile = datafile or (indexfile[:-2] + b".d") | |
317 | self.nodemap_file = None |
|
317 | self.nodemap_file = None | |
318 | if persistentnodemap: |
|
318 | if persistentnodemap: | |
319 | self.nodemap_file = nodemaputil.get_nodemap_file( |
|
319 | self.nodemap_file = nodemaputil.get_nodemap_file( | |
320 | opener, self.indexfile |
|
320 | opener, self.indexfile | |
321 | ) |
|
321 | ) | |
322 |
|
322 | |||
323 | self.opener = opener |
|
323 | self.opener = opener | |
324 | assert target[0] in ALL_KINDS |
|
324 | assert target[0] in ALL_KINDS | |
325 | assert len(target) == 2 |
|
325 | assert len(target) == 2 | |
326 | self.target = target |
|
326 | self.target = target | |
327 | # When True, indexfile is opened with checkambig=True at writing, to |
|
327 | # When True, indexfile is opened with checkambig=True at writing, to | |
328 | # avoid file stat ambiguity. |
|
328 | # avoid file stat ambiguity. | |
329 | self._checkambig = checkambig |
|
329 | self._checkambig = checkambig | |
330 | self._mmaplargeindex = mmaplargeindex |
|
330 | self._mmaplargeindex = mmaplargeindex | |
331 | self._censorable = censorable |
|
331 | self._censorable = censorable | |
332 | # 3-tuple of (node, rev, text) for a raw revision. |
|
332 | # 3-tuple of (node, rev, text) for a raw revision. | |
333 | self._revisioncache = None |
|
333 | self._revisioncache = None | |
334 | # Maps rev to chain base rev. |
|
334 | # Maps rev to chain base rev. | |
335 | self._chainbasecache = util.lrucachedict(100) |
|
335 | self._chainbasecache = util.lrucachedict(100) | |
336 | # 2-tuple of (offset, data) of raw data from the revlog at an offset. |
|
336 | # 2-tuple of (offset, data) of raw data from the revlog at an offset. | |
337 | self._chunkcache = (0, b'') |
|
337 | self._chunkcache = (0, b'') | |
338 | # How much data to read and cache into the raw revlog data cache. |
|
338 | # How much data to read and cache into the raw revlog data cache. | |
339 | self._chunkcachesize = 65536 |
|
339 | self._chunkcachesize = 65536 | |
340 | self._maxchainlen = None |
|
340 | self._maxchainlen = None | |
341 | self._deltabothparents = True |
|
341 | self._deltabothparents = True | |
342 | self.index = None |
|
342 | self.index = None | |
343 | self._nodemap_docket = None |
|
343 | self._nodemap_docket = None | |
344 | # Mapping of partial identifiers to full nodes. |
|
344 | # Mapping of partial identifiers to full nodes. | |
345 | self._pcache = {} |
|
345 | self._pcache = {} | |
346 | # Mapping of revision integer to full node. |
|
346 | # Mapping of revision integer to full node. | |
347 | self._compengine = b'zlib' |
|
347 | self._compengine = b'zlib' | |
348 | self._compengineopts = {} |
|
348 | self._compengineopts = {} | |
349 | self._maxdeltachainspan = -1 |
|
349 | self._maxdeltachainspan = -1 | |
350 | self._withsparseread = False |
|
350 | self._withsparseread = False | |
351 | self._sparserevlog = False |
|
351 | self._sparserevlog = False | |
352 | self._srdensitythreshold = 0.50 |
|
352 | self._srdensitythreshold = 0.50 | |
353 | self._srmingapsize = 262144 |
|
353 | self._srmingapsize = 262144 | |
354 |
|
354 | |||
355 | # Make copy of flag processors so each revlog instance can support |
|
355 | # Make copy of flag processors so each revlog instance can support | |
356 | # custom flags. |
|
356 | # custom flags. | |
357 | self._flagprocessors = dict(flagutil.flagprocessors) |
|
357 | self._flagprocessors = dict(flagutil.flagprocessors) | |
358 |
|
358 | |||
359 | # 2-tuple of file handles being used for active writing. |
|
359 | # 2-tuple of file handles being used for active writing. | |
360 | self._writinghandles = None |
|
360 | self._writinghandles = None | |
361 |
|
361 | |||
362 | self._loadindex() |
|
362 | self._loadindex() | |
363 |
|
363 | |||
364 | self._concurrencychecker = concurrencychecker |
|
364 | self._concurrencychecker = concurrencychecker | |
365 |
|
365 | |||
366 | def _loadindex(self): |
|
366 | def _loadindex(self): | |
367 | mmapindexthreshold = None |
|
367 | mmapindexthreshold = None | |
368 | opts = self.opener.options |
|
368 | opts = self.opener.options | |
369 |
|
369 | |||
370 | if b'revlogv2' in opts: |
|
370 | if b'revlogv2' in opts: | |
371 | newversionflags = REVLOGV2 | FLAG_INLINE_DATA |
|
371 | newversionflags = REVLOGV2 | FLAG_INLINE_DATA | |
372 | elif b'revlogv1' in opts: |
|
372 | elif b'revlogv1' in opts: | |
373 | newversionflags = REVLOGV1 | FLAG_INLINE_DATA |
|
373 | newversionflags = REVLOGV1 | FLAG_INLINE_DATA | |
374 | if b'generaldelta' in opts: |
|
374 | if b'generaldelta' in opts: | |
375 | newversionflags |= FLAG_GENERALDELTA |
|
375 | newversionflags |= FLAG_GENERALDELTA | |
376 | elif b'revlogv0' in self.opener.options: |
|
376 | elif b'revlogv0' in self.opener.options: | |
377 | newversionflags = REVLOGV0 |
|
377 | newversionflags = REVLOGV0 | |
378 | else: |
|
378 | else: | |
379 | newversionflags = REVLOG_DEFAULT_VERSION |
|
379 | newversionflags = REVLOG_DEFAULT_VERSION | |
380 |
|
380 | |||
381 | if b'chunkcachesize' in opts: |
|
381 | if b'chunkcachesize' in opts: | |
382 | self._chunkcachesize = opts[b'chunkcachesize'] |
|
382 | self._chunkcachesize = opts[b'chunkcachesize'] | |
383 | if b'maxchainlen' in opts: |
|
383 | if b'maxchainlen' in opts: | |
384 | self._maxchainlen = opts[b'maxchainlen'] |
|
384 | self._maxchainlen = opts[b'maxchainlen'] | |
385 | if b'deltabothparents' in opts: |
|
385 | if b'deltabothparents' in opts: | |
386 | self._deltabothparents = opts[b'deltabothparents'] |
|
386 | self._deltabothparents = opts[b'deltabothparents'] | |
387 | self._lazydelta = bool(opts.get(b'lazydelta', True)) |
|
387 | self._lazydelta = bool(opts.get(b'lazydelta', True)) | |
388 | self._lazydeltabase = False |
|
388 | self._lazydeltabase = False | |
389 | if self._lazydelta: |
|
389 | if self._lazydelta: | |
390 | self._lazydeltabase = bool(opts.get(b'lazydeltabase', False)) |
|
390 | self._lazydeltabase = bool(opts.get(b'lazydeltabase', False)) | |
391 | if b'compengine' in opts: |
|
391 | if b'compengine' in opts: | |
392 | self._compengine = opts[b'compengine'] |
|
392 | self._compengine = opts[b'compengine'] | |
393 | if b'zlib.level' in opts: |
|
393 | if b'zlib.level' in opts: | |
394 | self._compengineopts[b'zlib.level'] = opts[b'zlib.level'] |
|
394 | self._compengineopts[b'zlib.level'] = opts[b'zlib.level'] | |
395 | if b'zstd.level' in opts: |
|
395 | if b'zstd.level' in opts: | |
396 | self._compengineopts[b'zstd.level'] = opts[b'zstd.level'] |
|
396 | self._compengineopts[b'zstd.level'] = opts[b'zstd.level'] | |
397 | if b'maxdeltachainspan' in opts: |
|
397 | if b'maxdeltachainspan' in opts: | |
398 | self._maxdeltachainspan = opts[b'maxdeltachainspan'] |
|
398 | self._maxdeltachainspan = opts[b'maxdeltachainspan'] | |
399 | if self._mmaplargeindex and b'mmapindexthreshold' in opts: |
|
399 | if self._mmaplargeindex and b'mmapindexthreshold' in opts: | |
400 | mmapindexthreshold = opts[b'mmapindexthreshold'] |
|
400 | mmapindexthreshold = opts[b'mmapindexthreshold'] | |
401 | self.hassidedata = bool(opts.get(b'side-data', False)) |
|
401 | self.hassidedata = bool(opts.get(b'side-data', False)) | |
402 | self._sparserevlog = bool(opts.get(b'sparse-revlog', False)) |
|
402 | self._sparserevlog = bool(opts.get(b'sparse-revlog', False)) | |
403 | withsparseread = bool(opts.get(b'with-sparse-read', False)) |
|
403 | withsparseread = bool(opts.get(b'with-sparse-read', False)) | |
404 | # sparse-revlog forces sparse-read |
|
404 | # sparse-revlog forces sparse-read | |
405 | self._withsparseread = self._sparserevlog or withsparseread |
|
405 | self._withsparseread = self._sparserevlog or withsparseread | |
406 | if b'sparse-read-density-threshold' in opts: |
|
406 | if b'sparse-read-density-threshold' in opts: | |
407 | self._srdensitythreshold = opts[b'sparse-read-density-threshold'] |
|
407 | self._srdensitythreshold = opts[b'sparse-read-density-threshold'] | |
408 | if b'sparse-read-min-gap-size' in opts: |
|
408 | if b'sparse-read-min-gap-size' in opts: | |
409 | self._srmingapsize = opts[b'sparse-read-min-gap-size'] |
|
409 | self._srmingapsize = opts[b'sparse-read-min-gap-size'] | |
410 | if opts.get(b'enableellipsis'): |
|
410 | if opts.get(b'enableellipsis'): | |
411 | self._flagprocessors[REVIDX_ELLIPSIS] = ellipsisprocessor |
|
411 | self._flagprocessors[REVIDX_ELLIPSIS] = ellipsisprocessor | |
412 |
|
412 | |||
413 | # revlog v0 doesn't have flag processors |
|
413 | # revlog v0 doesn't have flag processors | |
414 | for flag, processor in pycompat.iteritems( |
|
414 | for flag, processor in pycompat.iteritems( | |
415 | opts.get(b'flagprocessors', {}) |
|
415 | opts.get(b'flagprocessors', {}) | |
416 | ): |
|
416 | ): | |
417 | flagutil.insertflagprocessor(flag, processor, self._flagprocessors) |
|
417 | flagutil.insertflagprocessor(flag, processor, self._flagprocessors) | |
418 |
|
418 | |||
419 | if self._chunkcachesize <= 0: |
|
419 | if self._chunkcachesize <= 0: | |
420 | raise error.RevlogError( |
|
420 | raise error.RevlogError( | |
421 | _(b'revlog chunk cache size %r is not greater than 0') |
|
421 | _(b'revlog chunk cache size %r is not greater than 0') | |
422 | % self._chunkcachesize |
|
422 | % self._chunkcachesize | |
423 | ) |
|
423 | ) | |
424 | elif self._chunkcachesize & (self._chunkcachesize - 1): |
|
424 | elif self._chunkcachesize & (self._chunkcachesize - 1): | |
425 | raise error.RevlogError( |
|
425 | raise error.RevlogError( | |
426 | _(b'revlog chunk cache size %r is not a power of 2') |
|
426 | _(b'revlog chunk cache size %r is not a power of 2') | |
427 | % self._chunkcachesize |
|
427 | % self._chunkcachesize | |
428 | ) |
|
428 | ) | |
429 |
|
429 | |||
430 | indexdata = b'' |
|
430 | indexdata = b'' | |
431 | self._initempty = True |
|
431 | self._initempty = True | |
432 | try: |
|
432 | try: | |
433 | with self._indexfp() as f: |
|
433 | with self._indexfp() as f: | |
434 | if ( |
|
434 | if ( | |
435 | mmapindexthreshold is not None |
|
435 | mmapindexthreshold is not None | |
436 | and self.opener.fstat(f).st_size >= mmapindexthreshold |
|
436 | and self.opener.fstat(f).st_size >= mmapindexthreshold | |
437 | ): |
|
437 | ): | |
438 | # TODO: should .close() to release resources without |
|
438 | # TODO: should .close() to release resources without | |
439 | # relying on Python GC |
|
439 | # relying on Python GC | |
440 | indexdata = util.buffer(util.mmapread(f)) |
|
440 | indexdata = util.buffer(util.mmapread(f)) | |
441 | else: |
|
441 | else: | |
442 | indexdata = f.read() |
|
442 | indexdata = f.read() | |
443 | if len(indexdata) > 0: |
|
443 | if len(indexdata) > 0: | |
444 | versionflags = INDEX_HEADER.unpack(indexdata[:4])[0] |
|
444 | versionflags = INDEX_HEADER.unpack(indexdata[:4])[0] | |
445 | self._initempty = False |
|
445 | self._initempty = False | |
446 | else: |
|
446 | else: | |
447 | versionflags = newversionflags |
|
447 | versionflags = newversionflags | |
448 | except IOError as inst: |
|
448 | except IOError as inst: | |
449 | if inst.errno != errno.ENOENT: |
|
449 | if inst.errno != errno.ENOENT: | |
450 | raise |
|
450 | raise | |
451 |
|
451 | |||
452 | versionflags = newversionflags |
|
452 | versionflags = newversionflags | |
453 |
|
453 | |||
454 | self.version = versionflags |
|
454 | self.version = versionflags | |
455 |
|
455 | |||
456 | flags = versionflags & ~0xFFFF |
|
456 | flags = versionflags & ~0xFFFF | |
457 | fmt = versionflags & 0xFFFF |
|
457 | fmt = versionflags & 0xFFFF | |
458 |
|
458 | |||
459 | if fmt == REVLOGV0: |
|
459 | if fmt == REVLOGV0: | |
460 | if flags: |
|
460 | if flags: | |
461 | raise error.RevlogError( |
|
461 | raise error.RevlogError( | |
462 | _(b'unknown flags (%#04x) in version %d revlog %s') |
|
462 | _(b'unknown flags (%#04x) in version %d revlog %s') | |
463 | % (flags >> 16, fmt, self.indexfile) |
|
463 | % (flags >> 16, fmt, self.indexfile) | |
464 | ) |
|
464 | ) | |
465 |
|
465 | |||
466 | self._inline = False |
|
466 | self._inline = False | |
467 | self._generaldelta = False |
|
467 | self._generaldelta = False | |
468 |
|
468 | |||
469 | elif fmt == REVLOGV1: |
|
469 | elif fmt == REVLOGV1: | |
470 | if flags & ~REVLOGV1_FLAGS: |
|
470 | if flags & ~REVLOGV1_FLAGS: | |
471 | raise error.RevlogError( |
|
471 | raise error.RevlogError( | |
472 | _(b'unknown flags (%#04x) in version %d revlog %s') |
|
472 | _(b'unknown flags (%#04x) in version %d revlog %s') | |
473 | % (flags >> 16, fmt, self.indexfile) |
|
473 | % (flags >> 16, fmt, self.indexfile) | |
474 | ) |
|
474 | ) | |
475 |
|
475 | |||
476 | self._inline = versionflags & FLAG_INLINE_DATA |
|
476 | self._inline = versionflags & FLAG_INLINE_DATA | |
477 | self._generaldelta = versionflags & FLAG_GENERALDELTA |
|
477 | self._generaldelta = versionflags & FLAG_GENERALDELTA | |
478 |
|
478 | |||
479 | elif fmt == REVLOGV2: |
|
479 | elif fmt == REVLOGV2: | |
480 | if flags & ~REVLOGV2_FLAGS: |
|
480 | if flags & ~REVLOGV2_FLAGS: | |
481 | raise error.RevlogError( |
|
481 | raise error.RevlogError( | |
482 | _(b'unknown flags (%#04x) in version %d revlog %s') |
|
482 | _(b'unknown flags (%#04x) in version %d revlog %s') | |
483 | % (flags >> 16, fmt, self.indexfile) |
|
483 | % (flags >> 16, fmt, self.indexfile) | |
484 | ) |
|
484 | ) | |
485 |
|
485 | |||
486 | # There is a bug in the transaction handling when going from an |
|
486 | # There is a bug in the transaction handling when going from an | |
487 | # inline revlog to a separate index and data file. Turn it off until |
|
487 | # inline revlog to a separate index and data file. Turn it off until | |
488 | # it's fixed, since v2 revlogs sometimes get rewritten on exchange. |
|
488 | # it's fixed, since v2 revlogs sometimes get rewritten on exchange. | |
489 | # See issue6485 |
|
489 | # See issue6485 | |
490 | self._inline = False |
|
490 | self._inline = False | |
491 | # generaldelta implied by version 2 revlogs. |
|
491 | # generaldelta implied by version 2 revlogs. | |
492 | self._generaldelta = True |
|
492 | self._generaldelta = True | |
493 |
|
493 | |||
494 | else: |
|
494 | else: | |
495 | raise error.RevlogError( |
|
495 | raise error.RevlogError( | |
496 | _(b'unknown version (%d) in revlog %s') % (fmt, self.indexfile) |
|
496 | _(b'unknown version (%d) in revlog %s') % (fmt, self.indexfile) | |
497 | ) |
|
497 | ) | |
498 |
|
498 | |||
499 | self.nodeconstants = sha1nodeconstants |
|
499 | self.nodeconstants = sha1nodeconstants | |
500 | self.nullid = self.nodeconstants.nullid |
|
500 | self.nullid = self.nodeconstants.nullid | |
501 |
|
501 | |||
502 | # sparse-revlog can't be on without general-delta (issue6056) |
|
502 | # sparse-revlog can't be on without general-delta (issue6056) | |
503 | if not self._generaldelta: |
|
503 | if not self._generaldelta: | |
504 | self._sparserevlog = False |
|
504 | self._sparserevlog = False | |
505 |
|
505 | |||
506 | self._storedeltachains = True |
|
506 | self._storedeltachains = True | |
507 |
|
507 | |||
508 | devel_nodemap = ( |
|
508 | devel_nodemap = ( | |
509 | self.nodemap_file |
|
509 | self.nodemap_file | |
510 | and opts.get(b'devel-force-nodemap', False) |
|
510 | and opts.get(b'devel-force-nodemap', False) | |
511 | and parse_index_v1_nodemap is not None |
|
511 | and parse_index_v1_nodemap is not None | |
512 | ) |
|
512 | ) | |
513 |
|
513 | |||
514 | use_rust_index = False |
|
514 | use_rust_index = False | |
515 | if rustrevlog is not None: |
|
515 | if rustrevlog is not None: | |
516 | if self.nodemap_file is not None: |
|
516 | if self.nodemap_file is not None: | |
517 | use_rust_index = True |
|
517 | use_rust_index = True | |
518 | else: |
|
518 | else: | |
519 | use_rust_index = self.opener.options.get(b'rust.index') |
|
519 | use_rust_index = self.opener.options.get(b'rust.index') | |
520 |
|
520 | |||
521 | self._parse_index = parse_index_v1 |
|
521 | self._parse_index = parse_index_v1 | |
522 | if self.version == REVLOGV0: |
|
522 | if self.version == REVLOGV0: | |
523 | self._parse_index = revlogv0.parse_index_v0 |
|
523 | self._parse_index = revlogv0.parse_index_v0 | |
524 | elif fmt == REVLOGV2: |
|
524 | elif fmt == REVLOGV2: | |
525 | self._parse_index = parse_index_v2 |
|
525 | self._parse_index = parse_index_v2 | |
526 | elif devel_nodemap: |
|
526 | elif devel_nodemap: | |
527 | self._parse_index = parse_index_v1_nodemap |
|
527 | self._parse_index = parse_index_v1_nodemap | |
528 | elif use_rust_index: |
|
528 | elif use_rust_index: | |
529 | self._parse_index = parse_index_v1_mixed |
|
529 | self._parse_index = parse_index_v1_mixed | |
530 | try: |
|
530 | try: | |
531 | d = self._parse_index(indexdata, self._inline) |
|
531 | d = self._parse_index(indexdata, self._inline) | |
532 | index, _chunkcache = d |
|
532 | index, _chunkcache = d | |
533 | use_nodemap = ( |
|
533 | use_nodemap = ( | |
534 | not self._inline |
|
534 | not self._inline | |
535 | and self.nodemap_file is not None |
|
535 | and self.nodemap_file is not None | |
536 | and util.safehasattr(index, 'update_nodemap_data') |
|
536 | and util.safehasattr(index, 'update_nodemap_data') | |
537 | ) |
|
537 | ) | |
538 | if use_nodemap: |
|
538 | if use_nodemap: | |
539 | nodemap_data = nodemaputil.persisted_data(self) |
|
539 | nodemap_data = nodemaputil.persisted_data(self) | |
540 | if nodemap_data is not None: |
|
540 | if nodemap_data is not None: | |
541 | docket = nodemap_data[0] |
|
541 | docket = nodemap_data[0] | |
542 | if ( |
|
542 | if ( | |
543 | len(d[0]) > docket.tip_rev |
|
543 | len(d[0]) > docket.tip_rev | |
544 | and d[0][docket.tip_rev][7] == docket.tip_node |
|
544 | and d[0][docket.tip_rev][7] == docket.tip_node | |
545 | ): |
|
545 | ): | |
546 | # no changelog tampering |
|
546 | # no changelog tampering | |
547 | self._nodemap_docket = docket |
|
547 | self._nodemap_docket = docket | |
548 | index.update_nodemap_data(*nodemap_data) |
|
548 | index.update_nodemap_data(*nodemap_data) | |
549 | except (ValueError, IndexError): |
|
549 | except (ValueError, IndexError): | |
550 | raise error.RevlogError( |
|
550 | raise error.RevlogError( | |
551 | _(b"index %s is corrupted") % self.indexfile |
|
551 | _(b"index %s is corrupted") % self.indexfile | |
552 | ) |
|
552 | ) | |
553 | self.index, self._chunkcache = d |
|
553 | self.index, self._chunkcache = d | |
554 | if not self._chunkcache: |
|
554 | if not self._chunkcache: | |
555 | self._chunkclear() |
|
555 | self._chunkclear() | |
556 | # revnum -> (chain-length, sum-delta-length) |
|
556 | # revnum -> (chain-length, sum-delta-length) | |
557 | self._chaininfocache = util.lrucachedict(500) |
|
557 | self._chaininfocache = util.lrucachedict(500) | |
558 | # revlog header -> revlog compressor |
|
558 | # revlog header -> revlog compressor | |
559 | self._decompressors = {} |
|
559 | self._decompressors = {} | |
560 |
|
560 | |||
561 | @util.propertycache |
|
561 | @util.propertycache | |
562 | def revlog_kind(self): |
|
562 | def revlog_kind(self): | |
563 | return self.target[0] |
|
563 | return self.target[0] | |
564 |
|
564 | |||
565 | @util.propertycache |
|
565 | @util.propertycache | |
566 | def _compressor(self): |
|
566 | def _compressor(self): | |
567 | engine = util.compengines[self._compengine] |
|
567 | engine = util.compengines[self._compengine] | |
568 | return engine.revlogcompressor(self._compengineopts) |
|
568 | return engine.revlogcompressor(self._compengineopts) | |
569 |
|
569 | |||
570 | def _indexfp(self, mode=b'r'): |
|
570 | def _indexfp(self, mode=b'r'): | |
571 | """file object for the revlog's index file""" |
|
571 | """file object for the revlog's index file""" | |
572 | args = {'mode': mode} |
|
572 | args = {'mode': mode} | |
573 | if mode != b'r': |
|
573 | if mode != b'r': | |
574 | args['checkambig'] = self._checkambig |
|
574 | args['checkambig'] = self._checkambig | |
575 | if mode == b'w': |
|
575 | if mode == b'w': | |
576 | args['atomictemp'] = True |
|
576 | args['atomictemp'] = True | |
577 | return self.opener(self.indexfile, **args) |
|
577 | return self.opener(self.indexfile, **args) | |
578 |
|
578 | |||
579 | def _datafp(self, mode=b'r'): |
|
579 | def _datafp(self, mode=b'r'): | |
580 | """file object for the revlog's data file""" |
|
580 | """file object for the revlog's data file""" | |
581 | return self.opener(self.datafile, mode=mode) |
|
581 | return self.opener(self.datafile, mode=mode) | |
582 |
|
582 | |||
583 | @contextlib.contextmanager |
|
583 | @contextlib.contextmanager | |
584 | def _datareadfp(self, existingfp=None): |
|
584 | def _datareadfp(self, existingfp=None): | |
585 | """file object suitable to read data""" |
|
585 | """file object suitable to read data""" | |
586 | # Use explicit file handle, if given. |
|
586 | # Use explicit file handle, if given. | |
587 | if existingfp is not None: |
|
587 | if existingfp is not None: | |
588 | yield existingfp |
|
588 | yield existingfp | |
589 |
|
589 | |||
590 | # Use a file handle being actively used for writes, if available. |
|
590 | # Use a file handle being actively used for writes, if available. | |
591 | # There is some danger to doing this because reads will seek the |
|
591 | # There is some danger to doing this because reads will seek the | |
592 | # file. However, _writeentry() performs a SEEK_END before all writes, |
|
592 | # file. However, _writeentry() performs a SEEK_END before all writes, | |
593 | # so we should be safe. |
|
593 | # so we should be safe. | |
594 | elif self._writinghandles: |
|
594 | elif self._writinghandles: | |
595 | if self._inline: |
|
595 | if self._inline: | |
596 | yield self._writinghandles[0] |
|
596 | yield self._writinghandles[0] | |
597 | else: |
|
597 | else: | |
598 | yield self._writinghandles[1] |
|
598 | yield self._writinghandles[1] | |
599 |
|
599 | |||
600 | # Otherwise open a new file handle. |
|
600 | # Otherwise open a new file handle. | |
601 | else: |
|
601 | else: | |
602 | if self._inline: |
|
602 | if self._inline: | |
603 | func = self._indexfp |
|
603 | func = self._indexfp | |
604 | else: |
|
604 | else: | |
605 | func = self._datafp |
|
605 | func = self._datafp | |
606 | with func() as fp: |
|
606 | with func() as fp: | |
607 | yield fp |
|
607 | yield fp | |
608 |
|
608 | |||
609 | def tiprev(self): |
|
609 | def tiprev(self): | |
610 | return len(self.index) - 1 |
|
610 | return len(self.index) - 1 | |
611 |
|
611 | |||
612 | def tip(self): |
|
612 | def tip(self): | |
613 | return self.node(self.tiprev()) |
|
613 | return self.node(self.tiprev()) | |
614 |
|
614 | |||
615 | def __contains__(self, rev): |
|
615 | def __contains__(self, rev): | |
616 | return 0 <= rev < len(self) |
|
616 | return 0 <= rev < len(self) | |
617 |
|
617 | |||
618 | def __len__(self): |
|
618 | def __len__(self): | |
619 | return len(self.index) |
|
619 | return len(self.index) | |
620 |
|
620 | |||
621 | def __iter__(self): |
|
621 | def __iter__(self): | |
622 | return iter(pycompat.xrange(len(self))) |
|
622 | return iter(pycompat.xrange(len(self))) | |
623 |
|
623 | |||
624 | def revs(self, start=0, stop=None): |
|
624 | def revs(self, start=0, stop=None): | |
625 | """iterate over all rev in this revlog (from start to stop)""" |
|
625 | """iterate over all rev in this revlog (from start to stop)""" | |
626 | return storageutil.iterrevs(len(self), start=start, stop=stop) |
|
626 | return storageutil.iterrevs(len(self), start=start, stop=stop) | |
627 |
|
627 | |||
628 | @property |
|
628 | @property | |
629 | def nodemap(self): |
|
629 | def nodemap(self): | |
630 | msg = ( |
|
630 | msg = ( | |
631 | b"revlog.nodemap is deprecated, " |
|
631 | b"revlog.nodemap is deprecated, " | |
632 | b"use revlog.index.[has_node|rev|get_rev]" |
|
632 | b"use revlog.index.[has_node|rev|get_rev]" | |
633 | ) |
|
633 | ) | |
634 | util.nouideprecwarn(msg, b'5.3', stacklevel=2) |
|
634 | util.nouideprecwarn(msg, b'5.3', stacklevel=2) | |
635 | return self.index.nodemap |
|
635 | return self.index.nodemap | |
636 |
|
636 | |||
637 | @property |
|
637 | @property | |
638 | def _nodecache(self): |
|
638 | def _nodecache(self): | |
639 | msg = b"revlog._nodecache is deprecated, use revlog.index.nodemap" |
|
639 | msg = b"revlog._nodecache is deprecated, use revlog.index.nodemap" | |
640 | util.nouideprecwarn(msg, b'5.3', stacklevel=2) |
|
640 | util.nouideprecwarn(msg, b'5.3', stacklevel=2) | |
641 | return self.index.nodemap |
|
641 | return self.index.nodemap | |
642 |
|
642 | |||
643 | def hasnode(self, node): |
|
643 | def hasnode(self, node): | |
644 | try: |
|
644 | try: | |
645 | self.rev(node) |
|
645 | self.rev(node) | |
646 | return True |
|
646 | return True | |
647 | except KeyError: |
|
647 | except KeyError: | |
648 | return False |
|
648 | return False | |
649 |
|
649 | |||
650 | def candelta(self, baserev, rev): |
|
650 | def candelta(self, baserev, rev): | |
651 | """whether two revisions (baserev, rev) can be delta-ed or not""" |
|
651 | """whether two revisions (baserev, rev) can be delta-ed or not""" | |
652 | # Disable delta if either rev requires a content-changing flag |
|
652 | # Disable delta if either rev requires a content-changing flag | |
653 | # processor (ex. LFS). This is because such flag processor can alter |
|
653 | # processor (ex. LFS). This is because such flag processor can alter | |
654 | # the rawtext content that the delta will be based on, and two clients |
|
654 | # the rawtext content that the delta will be based on, and two clients | |
655 | # could have a same revlog node with different flags (i.e. different |
|
655 | # could have a same revlog node with different flags (i.e. different | |
656 | # rawtext contents) and the delta could be incompatible. |
|
656 | # rawtext contents) and the delta could be incompatible. | |
657 | if (self.flags(baserev) & REVIDX_RAWTEXT_CHANGING_FLAGS) or ( |
|
657 | if (self.flags(baserev) & REVIDX_RAWTEXT_CHANGING_FLAGS) or ( | |
658 | self.flags(rev) & REVIDX_RAWTEXT_CHANGING_FLAGS |
|
658 | self.flags(rev) & REVIDX_RAWTEXT_CHANGING_FLAGS | |
659 | ): |
|
659 | ): | |
660 | return False |
|
660 | return False | |
661 | return True |
|
661 | return True | |
662 |
|
662 | |||
663 | def update_caches(self, transaction): |
|
663 | def update_caches(self, transaction): | |
664 | if self.nodemap_file is not None: |
|
664 | if self.nodemap_file is not None: | |
665 | if transaction is None: |
|
665 | if transaction is None: | |
666 | nodemaputil.update_persistent_nodemap(self) |
|
666 | nodemaputil.update_persistent_nodemap(self) | |
667 | else: |
|
667 | else: | |
668 | nodemaputil.setup_persistent_nodemap(transaction, self) |
|
668 | nodemaputil.setup_persistent_nodemap(transaction, self) | |
669 |
|
669 | |||
670 | def clearcaches(self): |
|
670 | def clearcaches(self): | |
671 | self._revisioncache = None |
|
671 | self._revisioncache = None | |
672 | self._chainbasecache.clear() |
|
672 | self._chainbasecache.clear() | |
673 | self._chunkcache = (0, b'') |
|
673 | self._chunkcache = (0, b'') | |
674 | self._pcache = {} |
|
674 | self._pcache = {} | |
675 | self._nodemap_docket = None |
|
675 | self._nodemap_docket = None | |
676 | self.index.clearcaches() |
|
676 | self.index.clearcaches() | |
677 | # The python code is the one responsible for validating the docket, we |
|
677 | # The python code is the one responsible for validating the docket, we | |
678 | # end up having to refresh it here. |
|
678 | # end up having to refresh it here. | |
679 | use_nodemap = ( |
|
679 | use_nodemap = ( | |
680 | not self._inline |
|
680 | not self._inline | |
681 | and self.nodemap_file is not None |
|
681 | and self.nodemap_file is not None | |
682 | and util.safehasattr(self.index, 'update_nodemap_data') |
|
682 | and util.safehasattr(self.index, 'update_nodemap_data') | |
683 | ) |
|
683 | ) | |
684 | if use_nodemap: |
|
684 | if use_nodemap: | |
685 | nodemap_data = nodemaputil.persisted_data(self) |
|
685 | nodemap_data = nodemaputil.persisted_data(self) | |
686 | if nodemap_data is not None: |
|
686 | if nodemap_data is not None: | |
687 | self._nodemap_docket = nodemap_data[0] |
|
687 | self._nodemap_docket = nodemap_data[0] | |
688 | self.index.update_nodemap_data(*nodemap_data) |
|
688 | self.index.update_nodemap_data(*nodemap_data) | |
689 |
|
689 | |||
690 | def rev(self, node): |
|
690 | def rev(self, node): | |
691 | try: |
|
691 | try: | |
692 | return self.index.rev(node) |
|
692 | return self.index.rev(node) | |
693 | except TypeError: |
|
693 | except TypeError: | |
694 | raise |
|
694 | raise | |
695 | except error.RevlogError: |
|
695 | except error.RevlogError: | |
696 | # parsers.c radix tree lookup failed |
|
696 | # parsers.c radix tree lookup failed | |
697 | if ( |
|
697 | if ( | |
698 | node == self.nodeconstants.wdirid |
|
698 | node == self.nodeconstants.wdirid | |
699 | or node in self.nodeconstants.wdirfilenodeids |
|
699 | or node in self.nodeconstants.wdirfilenodeids | |
700 | ): |
|
700 | ): | |
701 | raise error.WdirUnsupported |
|
701 | raise error.WdirUnsupported | |
702 | raise error.LookupError(node, self.indexfile, _(b'no node')) |
|
702 | raise error.LookupError(node, self.indexfile, _(b'no node')) | |
703 |
|
703 | |||
704 | # Accessors for index entries. |
|
704 | # Accessors for index entries. | |
705 |
|
705 | |||
706 | # First tuple entry is 8 bytes. First 6 bytes are offset. Last 2 bytes |
|
706 | # First tuple entry is 8 bytes. First 6 bytes are offset. Last 2 bytes | |
707 | # are flags. |
|
707 | # are flags. | |
708 | def start(self, rev): |
|
708 | def start(self, rev): | |
709 | return int(self.index[rev][0] >> 16) |
|
709 | return int(self.index[rev][0] >> 16) | |
710 |
|
710 | |||
711 | def flags(self, rev): |
|
711 | def flags(self, rev): | |
712 | return self.index[rev][0] & 0xFFFF |
|
712 | return self.index[rev][0] & 0xFFFF | |
713 |
|
713 | |||
714 | def length(self, rev): |
|
714 | def length(self, rev): | |
715 | return self.index[rev][1] |
|
715 | return self.index[rev][1] | |
716 |
|
716 | |||
717 | def sidedata_length(self, rev): |
|
717 | def sidedata_length(self, rev): | |
718 | if self.version & 0xFFFF != REVLOGV2: |
|
718 | if self.version & 0xFFFF != REVLOGV2: | |
719 | return 0 |
|
719 | return 0 | |
720 | return self.index[rev][9] |
|
720 | return self.index[rev][9] | |
721 |
|
721 | |||
722 | def rawsize(self, rev): |
|
722 | def rawsize(self, rev): | |
723 | """return the length of the uncompressed text for a given revision""" |
|
723 | """return the length of the uncompressed text for a given revision""" | |
724 | l = self.index[rev][2] |
|
724 | l = self.index[rev][2] | |
725 | if l >= 0: |
|
725 | if l >= 0: | |
726 | return l |
|
726 | return l | |
727 |
|
727 | |||
728 | t = self.rawdata(rev) |
|
728 | t = self.rawdata(rev) | |
729 | return len(t) |
|
729 | return len(t) | |
730 |
|
730 | |||
731 | def size(self, rev): |
|
731 | def size(self, rev): | |
732 | """length of non-raw text (processed by a "read" flag processor)""" |
|
732 | """length of non-raw text (processed by a "read" flag processor)""" | |
733 | # fast path: if no "read" flag processor could change the content, |
|
733 | # fast path: if no "read" flag processor could change the content, | |
734 | # size is rawsize. note: ELLIPSIS is known to not change the content. |
|
734 | # size is rawsize. note: ELLIPSIS is known to not change the content. | |
735 | flags = self.flags(rev) |
|
735 | flags = self.flags(rev) | |
736 | if flags & (flagutil.REVIDX_KNOWN_FLAGS ^ REVIDX_ELLIPSIS) == 0: |
|
736 | if flags & (flagutil.REVIDX_KNOWN_FLAGS ^ REVIDX_ELLIPSIS) == 0: | |
737 | return self.rawsize(rev) |
|
737 | return self.rawsize(rev) | |
738 |
|
738 | |||
739 | return len(self.revision(rev, raw=False)) |
|
739 | return len(self.revision(rev, raw=False)) | |
740 |
|
740 | |||
741 | def chainbase(self, rev): |
|
741 | def chainbase(self, rev): | |
742 | base = self._chainbasecache.get(rev) |
|
742 | base = self._chainbasecache.get(rev) | |
743 | if base is not None: |
|
743 | if base is not None: | |
744 | return base |
|
744 | return base | |
745 |
|
745 | |||
746 | index = self.index |
|
746 | index = self.index | |
747 | iterrev = rev |
|
747 | iterrev = rev | |
748 | base = index[iterrev][3] |
|
748 | base = index[iterrev][3] | |
749 | while base != iterrev: |
|
749 | while base != iterrev: | |
750 | iterrev = base |
|
750 | iterrev = base | |
751 | base = index[iterrev][3] |
|
751 | base = index[iterrev][3] | |
752 |
|
752 | |||
753 | self._chainbasecache[rev] = base |
|
753 | self._chainbasecache[rev] = base | |
754 | return base |
|
754 | return base | |
755 |
|
755 | |||
756 | def linkrev(self, rev): |
|
756 | def linkrev(self, rev): | |
757 | return self.index[rev][4] |
|
757 | return self.index[rev][4] | |
758 |
|
758 | |||
759 | def parentrevs(self, rev): |
|
759 | def parentrevs(self, rev): | |
760 | try: |
|
760 | try: | |
761 | entry = self.index[rev] |
|
761 | entry = self.index[rev] | |
762 | except IndexError: |
|
762 | except IndexError: | |
763 | if rev == wdirrev: |
|
763 | if rev == wdirrev: | |
764 | raise error.WdirUnsupported |
|
764 | raise error.WdirUnsupported | |
765 | raise |
|
765 | raise | |
766 | if entry[5] == nullrev: |
|
766 | if entry[5] == nullrev: | |
767 | return entry[6], entry[5] |
|
767 | return entry[6], entry[5] | |
768 | else: |
|
768 | else: | |
769 | return entry[5], entry[6] |
|
769 | return entry[5], entry[6] | |
770 |
|
770 | |||
771 | # fast parentrevs(rev) where rev isn't filtered |
|
771 | # fast parentrevs(rev) where rev isn't filtered | |
772 | _uncheckedparentrevs = parentrevs |
|
772 | _uncheckedparentrevs = parentrevs | |
773 |
|
773 | |||
774 | def node(self, rev): |
|
774 | def node(self, rev): | |
775 | try: |
|
775 | try: | |
776 | return self.index[rev][7] |
|
776 | return self.index[rev][7] | |
777 | except IndexError: |
|
777 | except IndexError: | |
778 | if rev == wdirrev: |
|
778 | if rev == wdirrev: | |
779 | raise error.WdirUnsupported |
|
779 | raise error.WdirUnsupported | |
780 | raise |
|
780 | raise | |
781 |
|
781 | |||
782 | # Derived from index values. |
|
782 | # Derived from index values. | |
783 |
|
783 | |||
784 | def end(self, rev): |
|
784 | def end(self, rev): | |
785 | return self.start(rev) + self.length(rev) |
|
785 | return self.start(rev) + self.length(rev) | |
786 |
|
786 | |||
787 | def parents(self, node): |
|
787 | def parents(self, node): | |
788 | i = self.index |
|
788 | i = self.index | |
789 | d = i[self.rev(node)] |
|
789 | d = i[self.rev(node)] | |
790 | # inline node() to avoid function call overhead |
|
790 | # inline node() to avoid function call overhead | |
791 | if d[5] == self.nullid: |
|
791 | if d[5] == self.nullid: | |
792 | return i[d[6]][7], i[d[5]][7] |
|
792 | return i[d[6]][7], i[d[5]][7] | |
793 | else: |
|
793 | else: | |
794 | return i[d[5]][7], i[d[6]][7] |
|
794 | return i[d[5]][7], i[d[6]][7] | |
795 |
|
795 | |||
796 | def chainlen(self, rev): |
|
796 | def chainlen(self, rev): | |
797 | return self._chaininfo(rev)[0] |
|
797 | return self._chaininfo(rev)[0] | |
798 |
|
798 | |||
799 | def _chaininfo(self, rev): |
|
799 | def _chaininfo(self, rev): | |
800 | chaininfocache = self._chaininfocache |
|
800 | chaininfocache = self._chaininfocache | |
801 | if rev in chaininfocache: |
|
801 | if rev in chaininfocache: | |
802 | return chaininfocache[rev] |
|
802 | return chaininfocache[rev] | |
803 | index = self.index |
|
803 | index = self.index | |
804 | generaldelta = self._generaldelta |
|
804 | generaldelta = self._generaldelta | |
805 | iterrev = rev |
|
805 | iterrev = rev | |
806 | e = index[iterrev] |
|
806 | e = index[iterrev] | |
807 | clen = 0 |
|
807 | clen = 0 | |
808 | compresseddeltalen = 0 |
|
808 | compresseddeltalen = 0 | |
809 | while iterrev != e[3]: |
|
809 | while iterrev != e[3]: | |
810 | clen += 1 |
|
810 | clen += 1 | |
811 | compresseddeltalen += e[1] |
|
811 | compresseddeltalen += e[1] | |
812 | if generaldelta: |
|
812 | if generaldelta: | |
813 | iterrev = e[3] |
|
813 | iterrev = e[3] | |
814 | else: |
|
814 | else: | |
815 | iterrev -= 1 |
|
815 | iterrev -= 1 | |
816 | if iterrev in chaininfocache: |
|
816 | if iterrev in chaininfocache: | |
817 | t = chaininfocache[iterrev] |
|
817 | t = chaininfocache[iterrev] | |
818 | clen += t[0] |
|
818 | clen += t[0] | |
819 | compresseddeltalen += t[1] |
|
819 | compresseddeltalen += t[1] | |
820 | break |
|
820 | break | |
821 | e = index[iterrev] |
|
821 | e = index[iterrev] | |
822 | else: |
|
822 | else: | |
823 | # Add text length of base since decompressing that also takes |
|
823 | # Add text length of base since decompressing that also takes | |
824 | # work. For cache hits the length is already included. |
|
824 | # work. For cache hits the length is already included. | |
825 | compresseddeltalen += e[1] |
|
825 | compresseddeltalen += e[1] | |
826 | r = (clen, compresseddeltalen) |
|
826 | r = (clen, compresseddeltalen) | |
827 | chaininfocache[rev] = r |
|
827 | chaininfocache[rev] = r | |
828 | return r |
|
828 | return r | |
829 |
|
829 | |||
830 | def _deltachain(self, rev, stoprev=None): |
|
830 | def _deltachain(self, rev, stoprev=None): | |
831 | """Obtain the delta chain for a revision. |
|
831 | """Obtain the delta chain for a revision. | |
832 |
|
832 | |||
833 | ``stoprev`` specifies a revision to stop at. If not specified, we |
|
833 | ``stoprev`` specifies a revision to stop at. If not specified, we | |
834 | stop at the base of the chain. |
|
834 | stop at the base of the chain. | |
835 |
|
835 | |||
836 | Returns a 2-tuple of (chain, stopped) where ``chain`` is a list of |
|
836 | Returns a 2-tuple of (chain, stopped) where ``chain`` is a list of | |
837 | revs in ascending order and ``stopped`` is a bool indicating whether |
|
837 | revs in ascending order and ``stopped`` is a bool indicating whether | |
838 | ``stoprev`` was hit. |
|
838 | ``stoprev`` was hit. | |
839 | """ |
|
839 | """ | |
840 | # Try C implementation. |
|
840 | # Try C implementation. | |
841 | try: |
|
841 | try: | |
842 | return self.index.deltachain(rev, stoprev, self._generaldelta) |
|
842 | return self.index.deltachain(rev, stoprev, self._generaldelta) | |
843 | except AttributeError: |
|
843 | except AttributeError: | |
844 | pass |
|
844 | pass | |
845 |
|
845 | |||
846 | chain = [] |
|
846 | chain = [] | |
847 |
|
847 | |||
848 | # Alias to prevent attribute lookup in tight loop. |
|
848 | # Alias to prevent attribute lookup in tight loop. | |
849 | index = self.index |
|
849 | index = self.index | |
850 | generaldelta = self._generaldelta |
|
850 | generaldelta = self._generaldelta | |
851 |
|
851 | |||
852 | iterrev = rev |
|
852 | iterrev = rev | |
853 | e = index[iterrev] |
|
853 | e = index[iterrev] | |
854 | while iterrev != e[3] and iterrev != stoprev: |
|
854 | while iterrev != e[3] and iterrev != stoprev: | |
855 | chain.append(iterrev) |
|
855 | chain.append(iterrev) | |
856 | if generaldelta: |
|
856 | if generaldelta: | |
857 | iterrev = e[3] |
|
857 | iterrev = e[3] | |
858 | else: |
|
858 | else: | |
859 | iterrev -= 1 |
|
859 | iterrev -= 1 | |
860 | e = index[iterrev] |
|
860 | e = index[iterrev] | |
861 |
|
861 | |||
862 | if iterrev == stoprev: |
|
862 | if iterrev == stoprev: | |
863 | stopped = True |
|
863 | stopped = True | |
864 | else: |
|
864 | else: | |
865 | chain.append(iterrev) |
|
865 | chain.append(iterrev) | |
866 | stopped = False |
|
866 | stopped = False | |
867 |
|
867 | |||
868 | chain.reverse() |
|
868 | chain.reverse() | |
869 | return chain, stopped |
|
869 | return chain, stopped | |
870 |
|
870 | |||
871 | def ancestors(self, revs, stoprev=0, inclusive=False): |
|
871 | def ancestors(self, revs, stoprev=0, inclusive=False): | |
872 | """Generate the ancestors of 'revs' in reverse revision order. |
|
872 | """Generate the ancestors of 'revs' in reverse revision order. | |
873 | Does not generate revs lower than stoprev. |
|
873 | Does not generate revs lower than stoprev. | |
874 |
|
874 | |||
875 | See the documentation for ancestor.lazyancestors for more details.""" |
|
875 | See the documentation for ancestor.lazyancestors for more details.""" | |
876 |
|
876 | |||
877 | # first, make sure start revisions aren't filtered |
|
877 | # first, make sure start revisions aren't filtered | |
878 | revs = list(revs) |
|
878 | revs = list(revs) | |
879 | checkrev = self.node |
|
879 | checkrev = self.node | |
880 | for r in revs: |
|
880 | for r in revs: | |
881 | checkrev(r) |
|
881 | checkrev(r) | |
882 | # and we're sure ancestors aren't filtered as well |
|
882 | # and we're sure ancestors aren't filtered as well | |
883 |
|
883 | |||
884 | if rustancestor is not None: |
|
884 | if rustancestor is not None: | |
885 | lazyancestors = rustancestor.LazyAncestors |
|
885 | lazyancestors = rustancestor.LazyAncestors | |
886 | arg = self.index |
|
886 | arg = self.index | |
887 | else: |
|
887 | else: | |
888 | lazyancestors = ancestor.lazyancestors |
|
888 | lazyancestors = ancestor.lazyancestors | |
889 | arg = self._uncheckedparentrevs |
|
889 | arg = self._uncheckedparentrevs | |
890 | return lazyancestors(arg, revs, stoprev=stoprev, inclusive=inclusive) |
|
890 | return lazyancestors(arg, revs, stoprev=stoprev, inclusive=inclusive) | |
891 |
|
891 | |||
892 | def descendants(self, revs): |
|
892 | def descendants(self, revs): | |
893 | return dagop.descendantrevs(revs, self.revs, self.parentrevs) |
|
893 | return dagop.descendantrevs(revs, self.revs, self.parentrevs) | |
894 |
|
894 | |||
895 | def findcommonmissing(self, common=None, heads=None): |
|
895 | def findcommonmissing(self, common=None, heads=None): | |
896 | """Return a tuple of the ancestors of common and the ancestors of heads |
|
896 | """Return a tuple of the ancestors of common and the ancestors of heads | |
897 | that are not ancestors of common. In revset terminology, we return the |
|
897 | that are not ancestors of common. In revset terminology, we return the | |
898 | tuple: |
|
898 | tuple: | |
899 |
|
899 | |||
900 | ::common, (::heads) - (::common) |
|
900 | ::common, (::heads) - (::common) | |
901 |
|
901 | |||
902 | The list is sorted by revision number, meaning it is |
|
902 | The list is sorted by revision number, meaning it is | |
903 | topologically sorted. |
|
903 | topologically sorted. | |
904 |
|
904 | |||
905 | 'heads' and 'common' are both lists of node IDs. If heads is |
|
905 | 'heads' and 'common' are both lists of node IDs. If heads is | |
906 | not supplied, uses all of the revlog's heads. If common is not |
|
906 | not supplied, uses all of the revlog's heads. If common is not | |
907 | supplied, uses nullid.""" |
|
907 | supplied, uses nullid.""" | |
908 | if common is None: |
|
908 | if common is None: | |
909 | common = [self.nullid] |
|
909 | common = [self.nullid] | |
910 | if heads is None: |
|
910 | if heads is None: | |
911 | heads = self.heads() |
|
911 | heads = self.heads() | |
912 |
|
912 | |||
913 | common = [self.rev(n) for n in common] |
|
913 | common = [self.rev(n) for n in common] | |
914 | heads = [self.rev(n) for n in heads] |
|
914 | heads = [self.rev(n) for n in heads] | |
915 |
|
915 | |||
916 | # we want the ancestors, but inclusive |
|
916 | # we want the ancestors, but inclusive | |
917 | class lazyset(object): |
|
917 | class lazyset(object): | |
918 | def __init__(self, lazyvalues): |
|
918 | def __init__(self, lazyvalues): | |
919 | self.addedvalues = set() |
|
919 | self.addedvalues = set() | |
920 | self.lazyvalues = lazyvalues |
|
920 | self.lazyvalues = lazyvalues | |
921 |
|
921 | |||
922 | def __contains__(self, value): |
|
922 | def __contains__(self, value): | |
923 | return value in self.addedvalues or value in self.lazyvalues |
|
923 | return value in self.addedvalues or value in self.lazyvalues | |
924 |
|
924 | |||
925 | def __iter__(self): |
|
925 | def __iter__(self): | |
926 | added = self.addedvalues |
|
926 | added = self.addedvalues | |
927 | for r in added: |
|
927 | for r in added: | |
928 | yield r |
|
928 | yield r | |
929 | for r in self.lazyvalues: |
|
929 | for r in self.lazyvalues: | |
930 | if not r in added: |
|
930 | if not r in added: | |
931 | yield r |
|
931 | yield r | |
932 |
|
932 | |||
933 | def add(self, value): |
|
933 | def add(self, value): | |
934 | self.addedvalues.add(value) |
|
934 | self.addedvalues.add(value) | |
935 |
|
935 | |||
936 | def update(self, values): |
|
936 | def update(self, values): | |
937 | self.addedvalues.update(values) |
|
937 | self.addedvalues.update(values) | |
938 |
|
938 | |||
939 | has = lazyset(self.ancestors(common)) |
|
939 | has = lazyset(self.ancestors(common)) | |
940 | has.add(nullrev) |
|
940 | has.add(nullrev) | |
941 | has.update(common) |
|
941 | has.update(common) | |
942 |
|
942 | |||
943 | # take all ancestors from heads that aren't in has |
|
943 | # take all ancestors from heads that aren't in has | |
944 | missing = set() |
|
944 | missing = set() | |
945 | visit = collections.deque(r for r in heads if r not in has) |
|
945 | visit = collections.deque(r for r in heads if r not in has) | |
946 | while visit: |
|
946 | while visit: | |
947 | r = visit.popleft() |
|
947 | r = visit.popleft() | |
948 | if r in missing: |
|
948 | if r in missing: | |
949 | continue |
|
949 | continue | |
950 | else: |
|
950 | else: | |
951 | missing.add(r) |
|
951 | missing.add(r) | |
952 | for p in self.parentrevs(r): |
|
952 | for p in self.parentrevs(r): | |
953 | if p not in has: |
|
953 | if p not in has: | |
954 | visit.append(p) |
|
954 | visit.append(p) | |
955 | missing = list(missing) |
|
955 | missing = list(missing) | |
956 | missing.sort() |
|
956 | missing.sort() | |
957 | return has, [self.node(miss) for miss in missing] |
|
957 | return has, [self.node(miss) for miss in missing] | |
958 |
|
958 | |||
959 | def incrementalmissingrevs(self, common=None): |
|
959 | def incrementalmissingrevs(self, common=None): | |
960 | """Return an object that can be used to incrementally compute the |
|
960 | """Return an object that can be used to incrementally compute the | |
961 | revision numbers of the ancestors of arbitrary sets that are not |
|
961 | revision numbers of the ancestors of arbitrary sets that are not | |
962 | ancestors of common. This is an ancestor.incrementalmissingancestors |
|
962 | ancestors of common. This is an ancestor.incrementalmissingancestors | |
963 | object. |
|
963 | object. | |
964 |
|
964 | |||
965 | 'common' is a list of revision numbers. If common is not supplied, uses |
|
965 | 'common' is a list of revision numbers. If common is not supplied, uses | |
966 | nullrev. |
|
966 | nullrev. | |
967 | """ |
|
967 | """ | |
968 | if common is None: |
|
968 | if common is None: | |
969 | common = [nullrev] |
|
969 | common = [nullrev] | |
970 |
|
970 | |||
971 | if rustancestor is not None: |
|
971 | if rustancestor is not None: | |
972 | return rustancestor.MissingAncestors(self.index, common) |
|
972 | return rustancestor.MissingAncestors(self.index, common) | |
973 | return ancestor.incrementalmissingancestors(self.parentrevs, common) |
|
973 | return ancestor.incrementalmissingancestors(self.parentrevs, common) | |
974 |
|
974 | |||
975 | def findmissingrevs(self, common=None, heads=None): |
|
975 | def findmissingrevs(self, common=None, heads=None): | |
976 | """Return the revision numbers of the ancestors of heads that |
|
976 | """Return the revision numbers of the ancestors of heads that | |
977 | are not ancestors of common. |
|
977 | are not ancestors of common. | |
978 |
|
978 | |||
979 | More specifically, return a list of revision numbers corresponding to |
|
979 | More specifically, return a list of revision numbers corresponding to | |
980 | nodes N such that every N satisfies the following constraints: |
|
980 | nodes N such that every N satisfies the following constraints: | |
981 |
|
981 | |||
982 | 1. N is an ancestor of some node in 'heads' |
|
982 | 1. N is an ancestor of some node in 'heads' | |
983 | 2. N is not an ancestor of any node in 'common' |
|
983 | 2. N is not an ancestor of any node in 'common' | |
984 |
|
984 | |||
985 | The list is sorted by revision number, meaning it is |
|
985 | The list is sorted by revision number, meaning it is | |
986 | topologically sorted. |
|
986 | topologically sorted. | |
987 |
|
987 | |||
988 | 'heads' and 'common' are both lists of revision numbers. If heads is |
|
988 | 'heads' and 'common' are both lists of revision numbers. If heads is | |
989 | not supplied, uses all of the revlog's heads. If common is not |
|
989 | not supplied, uses all of the revlog's heads. If common is not | |
990 | supplied, uses nullid.""" |
|
990 | supplied, uses nullid.""" | |
991 | if common is None: |
|
991 | if common is None: | |
992 | common = [nullrev] |
|
992 | common = [nullrev] | |
993 | if heads is None: |
|
993 | if heads is None: | |
994 | heads = self.headrevs() |
|
994 | heads = self.headrevs() | |
995 |
|
995 | |||
996 | inc = self.incrementalmissingrevs(common=common) |
|
996 | inc = self.incrementalmissingrevs(common=common) | |
997 | return inc.missingancestors(heads) |
|
997 | return inc.missingancestors(heads) | |
998 |
|
998 | |||
999 | def findmissing(self, common=None, heads=None): |
|
999 | def findmissing(self, common=None, heads=None): | |
1000 | """Return the ancestors of heads that are not ancestors of common. |
|
1000 | """Return the ancestors of heads that are not ancestors of common. | |
1001 |
|
1001 | |||
1002 | More specifically, return a list of nodes N such that every N |
|
1002 | More specifically, return a list of nodes N such that every N | |
1003 | satisfies the following constraints: |
|
1003 | satisfies the following constraints: | |
1004 |
|
1004 | |||
1005 | 1. N is an ancestor of some node in 'heads' |
|
1005 | 1. N is an ancestor of some node in 'heads' | |
1006 | 2. N is not an ancestor of any node in 'common' |
|
1006 | 2. N is not an ancestor of any node in 'common' | |
1007 |
|
1007 | |||
1008 | The list is sorted by revision number, meaning it is |
|
1008 | The list is sorted by revision number, meaning it is | |
1009 | topologically sorted. |
|
1009 | topologically sorted. | |
1010 |
|
1010 | |||
1011 | 'heads' and 'common' are both lists of node IDs. If heads is |
|
1011 | 'heads' and 'common' are both lists of node IDs. If heads is | |
1012 | not supplied, uses all of the revlog's heads. If common is not |
|
1012 | not supplied, uses all of the revlog's heads. If common is not | |
1013 | supplied, uses nullid.""" |
|
1013 | supplied, uses nullid.""" | |
1014 | if common is None: |
|
1014 | if common is None: | |
1015 | common = [self.nullid] |
|
1015 | common = [self.nullid] | |
1016 | if heads is None: |
|
1016 | if heads is None: | |
1017 | heads = self.heads() |
|
1017 | heads = self.heads() | |
1018 |
|
1018 | |||
1019 | common = [self.rev(n) for n in common] |
|
1019 | common = [self.rev(n) for n in common] | |
1020 | heads = [self.rev(n) for n in heads] |
|
1020 | heads = [self.rev(n) for n in heads] | |
1021 |
|
1021 | |||
1022 | inc = self.incrementalmissingrevs(common=common) |
|
1022 | inc = self.incrementalmissingrevs(common=common) | |
1023 | return [self.node(r) for r in inc.missingancestors(heads)] |
|
1023 | return [self.node(r) for r in inc.missingancestors(heads)] | |
1024 |
|
1024 | |||
1025 | def nodesbetween(self, roots=None, heads=None): |
|
1025 | def nodesbetween(self, roots=None, heads=None): | |
1026 | """Return a topological path from 'roots' to 'heads'. |
|
1026 | """Return a topological path from 'roots' to 'heads'. | |
1027 |
|
1027 | |||
1028 | Return a tuple (nodes, outroots, outheads) where 'nodes' is a |
|
1028 | Return a tuple (nodes, outroots, outheads) where 'nodes' is a | |
1029 | topologically sorted list of all nodes N that satisfy both of |
|
1029 | topologically sorted list of all nodes N that satisfy both of | |
1030 | these constraints: |
|
1030 | these constraints: | |
1031 |
|
1031 | |||
1032 | 1. N is a descendant of some node in 'roots' |
|
1032 | 1. N is a descendant of some node in 'roots' | |
1033 | 2. N is an ancestor of some node in 'heads' |
|
1033 | 2. N is an ancestor of some node in 'heads' | |
1034 |
|
1034 | |||
1035 | Every node is considered to be both a descendant and an ancestor |
|
1035 | Every node is considered to be both a descendant and an ancestor | |
1036 | of itself, so every reachable node in 'roots' and 'heads' will be |
|
1036 | of itself, so every reachable node in 'roots' and 'heads' will be | |
1037 | included in 'nodes'. |
|
1037 | included in 'nodes'. | |
1038 |
|
1038 | |||
1039 | 'outroots' is the list of reachable nodes in 'roots', i.e., the |
|
1039 | 'outroots' is the list of reachable nodes in 'roots', i.e., the | |
1040 | subset of 'roots' that is returned in 'nodes'. Likewise, |
|
1040 | subset of 'roots' that is returned in 'nodes'. Likewise, | |
1041 | 'outheads' is the subset of 'heads' that is also in 'nodes'. |
|
1041 | 'outheads' is the subset of 'heads' that is also in 'nodes'. | |
1042 |
|
1042 | |||
1043 | 'roots' and 'heads' are both lists of node IDs. If 'roots' is |
|
1043 | 'roots' and 'heads' are both lists of node IDs. If 'roots' is | |
1044 | unspecified, uses nullid as the only root. If 'heads' is |
|
1044 | unspecified, uses nullid as the only root. If 'heads' is | |
1045 | unspecified, uses list of all of the revlog's heads.""" |
|
1045 | unspecified, uses list of all of the revlog's heads.""" | |
1046 | nonodes = ([], [], []) |
|
1046 | nonodes = ([], [], []) | |
1047 | if roots is not None: |
|
1047 | if roots is not None: | |
1048 | roots = list(roots) |
|
1048 | roots = list(roots) | |
1049 | if not roots: |
|
1049 | if not roots: | |
1050 | return nonodes |
|
1050 | return nonodes | |
1051 | lowestrev = min([self.rev(n) for n in roots]) |
|
1051 | lowestrev = min([self.rev(n) for n in roots]) | |
1052 | else: |
|
1052 | else: | |
1053 | roots = [self.nullid] # Everybody's a descendant of nullid |
|
1053 | roots = [self.nullid] # Everybody's a descendant of nullid | |
1054 | lowestrev = nullrev |
|
1054 | lowestrev = nullrev | |
1055 | if (lowestrev == nullrev) and (heads is None): |
|
1055 | if (lowestrev == nullrev) and (heads is None): | |
1056 | # We want _all_ the nodes! |
|
1056 | # We want _all_ the nodes! | |
1057 | return ( |
|
1057 | return ( | |
1058 | [self.node(r) for r in self], |
|
1058 | [self.node(r) for r in self], | |
1059 | [self.nullid], |
|
1059 | [self.nullid], | |
1060 | list(self.heads()), |
|
1060 | list(self.heads()), | |
1061 | ) |
|
1061 | ) | |
1062 | if heads is None: |
|
1062 | if heads is None: | |
1063 | # All nodes are ancestors, so the latest ancestor is the last |
|
1063 | # All nodes are ancestors, so the latest ancestor is the last | |
1064 | # node. |
|
1064 | # node. | |
1065 | highestrev = len(self) - 1 |
|
1065 | highestrev = len(self) - 1 | |
1066 | # Set ancestors to None to signal that every node is an ancestor. |
|
1066 | # Set ancestors to None to signal that every node is an ancestor. | |
1067 | ancestors = None |
|
1067 | ancestors = None | |
1068 | # Set heads to an empty dictionary for later discovery of heads |
|
1068 | # Set heads to an empty dictionary for later discovery of heads | |
1069 | heads = {} |
|
1069 | heads = {} | |
1070 | else: |
|
1070 | else: | |
1071 | heads = list(heads) |
|
1071 | heads = list(heads) | |
1072 | if not heads: |
|
1072 | if not heads: | |
1073 | return nonodes |
|
1073 | return nonodes | |
1074 | ancestors = set() |
|
1074 | ancestors = set() | |
1075 | # Turn heads into a dictionary so we can remove 'fake' heads. |
|
1075 | # Turn heads into a dictionary so we can remove 'fake' heads. | |
1076 | # Also, later we will be using it to filter out the heads we can't |
|
1076 | # Also, later we will be using it to filter out the heads we can't | |
1077 | # find from roots. |
|
1077 | # find from roots. | |
1078 | heads = dict.fromkeys(heads, False) |
|
1078 | heads = dict.fromkeys(heads, False) | |
1079 | # Start at the top and keep marking parents until we're done. |
|
1079 | # Start at the top and keep marking parents until we're done. | |
1080 | nodestotag = set(heads) |
|
1080 | nodestotag = set(heads) | |
1081 | # Remember where the top was so we can use it as a limit later. |
|
1081 | # Remember where the top was so we can use it as a limit later. | |
1082 | highestrev = max([self.rev(n) for n in nodestotag]) |
|
1082 | highestrev = max([self.rev(n) for n in nodestotag]) | |
1083 | while nodestotag: |
|
1083 | while nodestotag: | |
1084 | # grab a node to tag |
|
1084 | # grab a node to tag | |
1085 | n = nodestotag.pop() |
|
1085 | n = nodestotag.pop() | |
1086 | # Never tag nullid |
|
1086 | # Never tag nullid | |
1087 | if n == self.nullid: |
|
1087 | if n == self.nullid: | |
1088 | continue |
|
1088 | continue | |
1089 | # A node's revision number represents its place in a |
|
1089 | # A node's revision number represents its place in a | |
1090 | # topologically sorted list of nodes. |
|
1090 | # topologically sorted list of nodes. | |
1091 | r = self.rev(n) |
|
1091 | r = self.rev(n) | |
1092 | if r >= lowestrev: |
|
1092 | if r >= lowestrev: | |
1093 | if n not in ancestors: |
|
1093 | if n not in ancestors: | |
1094 | # If we are possibly a descendant of one of the roots |
|
1094 | # If we are possibly a descendant of one of the roots | |
1095 | # and we haven't already been marked as an ancestor |
|
1095 | # and we haven't already been marked as an ancestor | |
1096 | ancestors.add(n) # Mark as ancestor |
|
1096 | ancestors.add(n) # Mark as ancestor | |
1097 | # Add non-nullid parents to list of nodes to tag. |
|
1097 | # Add non-nullid parents to list of nodes to tag. | |
1098 | nodestotag.update( |
|
1098 | nodestotag.update( | |
1099 | [p for p in self.parents(n) if p != self.nullid] |
|
1099 | [p for p in self.parents(n) if p != self.nullid] | |
1100 | ) |
|
1100 | ) | |
1101 | elif n in heads: # We've seen it before, is it a fake head? |
|
1101 | elif n in heads: # We've seen it before, is it a fake head? | |
1102 | # So it is, real heads should not be the ancestors of |
|
1102 | # So it is, real heads should not be the ancestors of | |
1103 | # any other heads. |
|
1103 | # any other heads. | |
1104 | heads.pop(n) |
|
1104 | heads.pop(n) | |
1105 | if not ancestors: |
|
1105 | if not ancestors: | |
1106 | return nonodes |
|
1106 | return nonodes | |
1107 | # Now that we have our set of ancestors, we want to remove any |
|
1107 | # Now that we have our set of ancestors, we want to remove any | |
1108 | # roots that are not ancestors. |
|
1108 | # roots that are not ancestors. | |
1109 |
|
1109 | |||
1110 | # If one of the roots was nullid, everything is included anyway. |
|
1110 | # If one of the roots was nullid, everything is included anyway. | |
1111 | if lowestrev > nullrev: |
|
1111 | if lowestrev > nullrev: | |
1112 | # But, since we weren't, let's recompute the lowest rev to not |
|
1112 | # But, since we weren't, let's recompute the lowest rev to not | |
1113 | # include roots that aren't ancestors. |
|
1113 | # include roots that aren't ancestors. | |
1114 |
|
1114 | |||
1115 | # Filter out roots that aren't ancestors of heads |
|
1115 | # Filter out roots that aren't ancestors of heads | |
1116 | roots = [root for root in roots if root in ancestors] |
|
1116 | roots = [root for root in roots if root in ancestors] | |
1117 | # Recompute the lowest revision |
|
1117 | # Recompute the lowest revision | |
1118 | if roots: |
|
1118 | if roots: | |
1119 | lowestrev = min([self.rev(root) for root in roots]) |
|
1119 | lowestrev = min([self.rev(root) for root in roots]) | |
1120 | else: |
|
1120 | else: | |
1121 | # No more roots? Return empty list |
|
1121 | # No more roots? Return empty list | |
1122 | return nonodes |
|
1122 | return nonodes | |
1123 | else: |
|
1123 | else: | |
1124 | # We are descending from nullid, and don't need to care about |
|
1124 | # We are descending from nullid, and don't need to care about | |
1125 | # any other roots. |
|
1125 | # any other roots. | |
1126 | lowestrev = nullrev |
|
1126 | lowestrev = nullrev | |
1127 | roots = [self.nullid] |
|
1127 | roots = [self.nullid] | |
1128 | # Transform our roots list into a set. |
|
1128 | # Transform our roots list into a set. | |
1129 | descendants = set(roots) |
|
1129 | descendants = set(roots) | |
1130 | # Also, keep the original roots so we can filter out roots that aren't |
|
1130 | # Also, keep the original roots so we can filter out roots that aren't | |
1131 | # 'real' roots (i.e. are descended from other roots). |
|
1131 | # 'real' roots (i.e. are descended from other roots). | |
1132 | roots = descendants.copy() |
|
1132 | roots = descendants.copy() | |
1133 | # Our topologically sorted list of output nodes. |
|
1133 | # Our topologically sorted list of output nodes. | |
1134 | orderedout = [] |
|
1134 | orderedout = [] | |
1135 | # Don't start at nullid since we don't want nullid in our output list, |
|
1135 | # Don't start at nullid since we don't want nullid in our output list, | |
1136 | # and if nullid shows up in descendants, empty parents will look like |
|
1136 | # and if nullid shows up in descendants, empty parents will look like | |
1137 | # they're descendants. |
|
1137 | # they're descendants. | |
1138 | for r in self.revs(start=max(lowestrev, 0), stop=highestrev + 1): |
|
1138 | for r in self.revs(start=max(lowestrev, 0), stop=highestrev + 1): | |
1139 | n = self.node(r) |
|
1139 | n = self.node(r) | |
1140 | isdescendant = False |
|
1140 | isdescendant = False | |
1141 | if lowestrev == nullrev: # Everybody is a descendant of nullid |
|
1141 | if lowestrev == nullrev: # Everybody is a descendant of nullid | |
1142 | isdescendant = True |
|
1142 | isdescendant = True | |
1143 | elif n in descendants: |
|
1143 | elif n in descendants: | |
1144 | # n is already a descendant |
|
1144 | # n is already a descendant | |
1145 | isdescendant = True |
|
1145 | isdescendant = True | |
1146 | # This check only needs to be done here because all the roots |
|
1146 | # This check only needs to be done here because all the roots | |
1147 | # will start being marked is descendants before the loop. |
|
1147 | # will start being marked is descendants before the loop. | |
1148 | if n in roots: |
|
1148 | if n in roots: | |
1149 | # If n was a root, check if it's a 'real' root. |
|
1149 | # If n was a root, check if it's a 'real' root. | |
1150 | p = tuple(self.parents(n)) |
|
1150 | p = tuple(self.parents(n)) | |
1151 | # If any of its parents are descendants, it's not a root. |
|
1151 | # If any of its parents are descendants, it's not a root. | |
1152 | if (p[0] in descendants) or (p[1] in descendants): |
|
1152 | if (p[0] in descendants) or (p[1] in descendants): | |
1153 | roots.remove(n) |
|
1153 | roots.remove(n) | |
1154 | else: |
|
1154 | else: | |
1155 | p = tuple(self.parents(n)) |
|
1155 | p = tuple(self.parents(n)) | |
1156 | # A node is a descendant if either of its parents are |
|
1156 | # A node is a descendant if either of its parents are | |
1157 | # descendants. (We seeded the dependents list with the roots |
|
1157 | # descendants. (We seeded the dependents list with the roots | |
1158 | # up there, remember?) |
|
1158 | # up there, remember?) | |
1159 | if (p[0] in descendants) or (p[1] in descendants): |
|
1159 | if (p[0] in descendants) or (p[1] in descendants): | |
1160 | descendants.add(n) |
|
1160 | descendants.add(n) | |
1161 | isdescendant = True |
|
1161 | isdescendant = True | |
1162 | if isdescendant and ((ancestors is None) or (n in ancestors)): |
|
1162 | if isdescendant and ((ancestors is None) or (n in ancestors)): | |
1163 | # Only include nodes that are both descendants and ancestors. |
|
1163 | # Only include nodes that are both descendants and ancestors. | |
1164 | orderedout.append(n) |
|
1164 | orderedout.append(n) | |
1165 | if (ancestors is not None) and (n in heads): |
|
1165 | if (ancestors is not None) and (n in heads): | |
1166 | # We're trying to figure out which heads are reachable |
|
1166 | # We're trying to figure out which heads are reachable | |
1167 | # from roots. |
|
1167 | # from roots. | |
1168 | # Mark this head as having been reached |
|
1168 | # Mark this head as having been reached | |
1169 | heads[n] = True |
|
1169 | heads[n] = True | |
1170 | elif ancestors is None: |
|
1170 | elif ancestors is None: | |
1171 | # Otherwise, we're trying to discover the heads. |
|
1171 | # Otherwise, we're trying to discover the heads. | |
1172 | # Assume this is a head because if it isn't, the next step |
|
1172 | # Assume this is a head because if it isn't, the next step | |
1173 | # will eventually remove it. |
|
1173 | # will eventually remove it. | |
1174 | heads[n] = True |
|
1174 | heads[n] = True | |
1175 | # But, obviously its parents aren't. |
|
1175 | # But, obviously its parents aren't. | |
1176 | for p in self.parents(n): |
|
1176 | for p in self.parents(n): | |
1177 | heads.pop(p, None) |
|
1177 | heads.pop(p, None) | |
1178 | heads = [head for head, flag in pycompat.iteritems(heads) if flag] |
|
1178 | heads = [head for head, flag in pycompat.iteritems(heads) if flag] | |
1179 | roots = list(roots) |
|
1179 | roots = list(roots) | |
1180 | assert orderedout |
|
1180 | assert orderedout | |
1181 | assert roots |
|
1181 | assert roots | |
1182 | assert heads |
|
1182 | assert heads | |
1183 | return (orderedout, roots, heads) |
|
1183 | return (orderedout, roots, heads) | |
1184 |
|
1184 | |||
1185 | def headrevs(self, revs=None): |
|
1185 | def headrevs(self, revs=None): | |
1186 | if revs is None: |
|
1186 | if revs is None: | |
1187 | try: |
|
1187 | try: | |
1188 | return self.index.headrevs() |
|
1188 | return self.index.headrevs() | |
1189 | except AttributeError: |
|
1189 | except AttributeError: | |
1190 | return self._headrevs() |
|
1190 | return self._headrevs() | |
1191 | if rustdagop is not None: |
|
1191 | if rustdagop is not None: | |
1192 | return rustdagop.headrevs(self.index, revs) |
|
1192 | return rustdagop.headrevs(self.index, revs) | |
1193 | return dagop.headrevs(revs, self._uncheckedparentrevs) |
|
1193 | return dagop.headrevs(revs, self._uncheckedparentrevs) | |
1194 |
|
1194 | |||
1195 | def computephases(self, roots): |
|
1195 | def computephases(self, roots): | |
1196 | return self.index.computephasesmapsets(roots) |
|
1196 | return self.index.computephasesmapsets(roots) | |
1197 |
|
1197 | |||
1198 | def _headrevs(self): |
|
1198 | def _headrevs(self): | |
1199 | count = len(self) |
|
1199 | count = len(self) | |
1200 | if not count: |
|
1200 | if not count: | |
1201 | return [nullrev] |
|
1201 | return [nullrev] | |
1202 | # we won't iter over filtered rev so nobody is a head at start |
|
1202 | # we won't iter over filtered rev so nobody is a head at start | |
1203 | ishead = [0] * (count + 1) |
|
1203 | ishead = [0] * (count + 1) | |
1204 | index = self.index |
|
1204 | index = self.index | |
1205 | for r in self: |
|
1205 | for r in self: | |
1206 | ishead[r] = 1 # I may be an head |
|
1206 | ishead[r] = 1 # I may be an head | |
1207 | e = index[r] |
|
1207 | e = index[r] | |
1208 | ishead[e[5]] = ishead[e[6]] = 0 # my parent are not |
|
1208 | ishead[e[5]] = ishead[e[6]] = 0 # my parent are not | |
1209 | return [r for r, val in enumerate(ishead) if val] |
|
1209 | return [r for r, val in enumerate(ishead) if val] | |
1210 |
|
1210 | |||
1211 | def heads(self, start=None, stop=None): |
|
1211 | def heads(self, start=None, stop=None): | |
1212 | """return the list of all nodes that have no children |
|
1212 | """return the list of all nodes that have no children | |
1213 |
|
1213 | |||
1214 | if start is specified, only heads that are descendants of |
|
1214 | if start is specified, only heads that are descendants of | |
1215 | start will be returned |
|
1215 | start will be returned | |
1216 | if stop is specified, it will consider all the revs from stop |
|
1216 | if stop is specified, it will consider all the revs from stop | |
1217 | as if they had no children |
|
1217 | as if they had no children | |
1218 | """ |
|
1218 | """ | |
1219 | if start is None and stop is None: |
|
1219 | if start is None and stop is None: | |
1220 | if not len(self): |
|
1220 | if not len(self): | |
1221 | return [self.nullid] |
|
1221 | return [self.nullid] | |
1222 | return [self.node(r) for r in self.headrevs()] |
|
1222 | return [self.node(r) for r in self.headrevs()] | |
1223 |
|
1223 | |||
1224 | if start is None: |
|
1224 | if start is None: | |
1225 | start = nullrev |
|
1225 | start = nullrev | |
1226 | else: |
|
1226 | else: | |
1227 | start = self.rev(start) |
|
1227 | start = self.rev(start) | |
1228 |
|
1228 | |||
1229 | stoprevs = {self.rev(n) for n in stop or []} |
|
1229 | stoprevs = {self.rev(n) for n in stop or []} | |
1230 |
|
1230 | |||
1231 | revs = dagop.headrevssubset( |
|
1231 | revs = dagop.headrevssubset( | |
1232 | self.revs, self.parentrevs, startrev=start, stoprevs=stoprevs |
|
1232 | self.revs, self.parentrevs, startrev=start, stoprevs=stoprevs | |
1233 | ) |
|
1233 | ) | |
1234 |
|
1234 | |||
1235 | return [self.node(rev) for rev in revs] |
|
1235 | return [self.node(rev) for rev in revs] | |
1236 |
|
1236 | |||
1237 | def children(self, node): |
|
1237 | def children(self, node): | |
1238 | """find the children of a given node""" |
|
1238 | """find the children of a given node""" | |
1239 | c = [] |
|
1239 | c = [] | |
1240 | p = self.rev(node) |
|
1240 | p = self.rev(node) | |
1241 | for r in self.revs(start=p + 1): |
|
1241 | for r in self.revs(start=p + 1): | |
1242 | prevs = [pr for pr in self.parentrevs(r) if pr != nullrev] |
|
1242 | prevs = [pr for pr in self.parentrevs(r) if pr != nullrev] | |
1243 | if prevs: |
|
1243 | if prevs: | |
1244 | for pr in prevs: |
|
1244 | for pr in prevs: | |
1245 | if pr == p: |
|
1245 | if pr == p: | |
1246 | c.append(self.node(r)) |
|
1246 | c.append(self.node(r)) | |
1247 | elif p == nullrev: |
|
1247 | elif p == nullrev: | |
1248 | c.append(self.node(r)) |
|
1248 | c.append(self.node(r)) | |
1249 | return c |
|
1249 | return c | |
1250 |
|
1250 | |||
1251 | def commonancestorsheads(self, a, b): |
|
1251 | def commonancestorsheads(self, a, b): | |
1252 | """calculate all the heads of the common ancestors of nodes a and b""" |
|
1252 | """calculate all the heads of the common ancestors of nodes a and b""" | |
1253 | a, b = self.rev(a), self.rev(b) |
|
1253 | a, b = self.rev(a), self.rev(b) | |
1254 | ancs = self._commonancestorsheads(a, b) |
|
1254 | ancs = self._commonancestorsheads(a, b) | |
1255 | return pycompat.maplist(self.node, ancs) |
|
1255 | return pycompat.maplist(self.node, ancs) | |
1256 |
|
1256 | |||
1257 | def _commonancestorsheads(self, *revs): |
|
1257 | def _commonancestorsheads(self, *revs): | |
1258 | """calculate all the heads of the common ancestors of revs""" |
|
1258 | """calculate all the heads of the common ancestors of revs""" | |
1259 | try: |
|
1259 | try: | |
1260 | ancs = self.index.commonancestorsheads(*revs) |
|
1260 | ancs = self.index.commonancestorsheads(*revs) | |
1261 | except (AttributeError, OverflowError): # C implementation failed |
|
1261 | except (AttributeError, OverflowError): # C implementation failed | |
1262 | ancs = ancestor.commonancestorsheads(self.parentrevs, *revs) |
|
1262 | ancs = ancestor.commonancestorsheads(self.parentrevs, *revs) | |
1263 | return ancs |
|
1263 | return ancs | |
1264 |
|
1264 | |||
1265 | def isancestor(self, a, b): |
|
1265 | def isancestor(self, a, b): | |
1266 | """return True if node a is an ancestor of node b |
|
1266 | """return True if node a is an ancestor of node b | |
1267 |
|
1267 | |||
1268 | A revision is considered an ancestor of itself.""" |
|
1268 | A revision is considered an ancestor of itself.""" | |
1269 | a, b = self.rev(a), self.rev(b) |
|
1269 | a, b = self.rev(a), self.rev(b) | |
1270 | return self.isancestorrev(a, b) |
|
1270 | return self.isancestorrev(a, b) | |
1271 |
|
1271 | |||
1272 | def isancestorrev(self, a, b): |
|
1272 | def isancestorrev(self, a, b): | |
1273 | """return True if revision a is an ancestor of revision b |
|
1273 | """return True if revision a is an ancestor of revision b | |
1274 |
|
1274 | |||
1275 | A revision is considered an ancestor of itself. |
|
1275 | A revision is considered an ancestor of itself. | |
1276 |
|
1276 | |||
1277 | The implementation of this is trivial but the use of |
|
1277 | The implementation of this is trivial but the use of | |
1278 | reachableroots is not.""" |
|
1278 | reachableroots is not.""" | |
1279 | if a == nullrev: |
|
1279 | if a == nullrev: | |
1280 | return True |
|
1280 | return True | |
1281 | elif a == b: |
|
1281 | elif a == b: | |
1282 | return True |
|
1282 | return True | |
1283 | elif a > b: |
|
1283 | elif a > b: | |
1284 | return False |
|
1284 | return False | |
1285 | return bool(self.reachableroots(a, [b], [a], includepath=False)) |
|
1285 | return bool(self.reachableroots(a, [b], [a], includepath=False)) | |
1286 |
|
1286 | |||
1287 | def reachableroots(self, minroot, heads, roots, includepath=False): |
|
1287 | def reachableroots(self, minroot, heads, roots, includepath=False): | |
1288 | """return (heads(::(<roots> and <roots>::<heads>))) |
|
1288 | """return (heads(::(<roots> and <roots>::<heads>))) | |
1289 |
|
1289 | |||
1290 | If includepath is True, return (<roots>::<heads>).""" |
|
1290 | If includepath is True, return (<roots>::<heads>).""" | |
1291 | try: |
|
1291 | try: | |
1292 | return self.index.reachableroots2( |
|
1292 | return self.index.reachableroots2( | |
1293 | minroot, heads, roots, includepath |
|
1293 | minroot, heads, roots, includepath | |
1294 | ) |
|
1294 | ) | |
1295 | except AttributeError: |
|
1295 | except AttributeError: | |
1296 | return dagop._reachablerootspure( |
|
1296 | return dagop._reachablerootspure( | |
1297 | self.parentrevs, minroot, roots, heads, includepath |
|
1297 | self.parentrevs, minroot, roots, heads, includepath | |
1298 | ) |
|
1298 | ) | |
1299 |
|
1299 | |||
1300 | def ancestor(self, a, b): |
|
1300 | def ancestor(self, a, b): | |
1301 | """calculate the "best" common ancestor of nodes a and b""" |
|
1301 | """calculate the "best" common ancestor of nodes a and b""" | |
1302 |
|
1302 | |||
1303 | a, b = self.rev(a), self.rev(b) |
|
1303 | a, b = self.rev(a), self.rev(b) | |
1304 | try: |
|
1304 | try: | |
1305 | ancs = self.index.ancestors(a, b) |
|
1305 | ancs = self.index.ancestors(a, b) | |
1306 | except (AttributeError, OverflowError): |
|
1306 | except (AttributeError, OverflowError): | |
1307 | ancs = ancestor.ancestors(self.parentrevs, a, b) |
|
1307 | ancs = ancestor.ancestors(self.parentrevs, a, b) | |
1308 | if ancs: |
|
1308 | if ancs: | |
1309 | # choose a consistent winner when there's a tie |
|
1309 | # choose a consistent winner when there's a tie | |
1310 | return min(map(self.node, ancs)) |
|
1310 | return min(map(self.node, ancs)) | |
1311 | return self.nullid |
|
1311 | return self.nullid | |
1312 |
|
1312 | |||
1313 | def _match(self, id): |
|
1313 | def _match(self, id): | |
1314 | if isinstance(id, int): |
|
1314 | if isinstance(id, int): | |
1315 | # rev |
|
1315 | # rev | |
1316 | return self.node(id) |
|
1316 | return self.node(id) | |
1317 | if len(id) == self.nodeconstants.nodelen: |
|
1317 | if len(id) == self.nodeconstants.nodelen: | |
1318 | # possibly a binary node |
|
1318 | # possibly a binary node | |
1319 | # odds of a binary node being all hex in ASCII are 1 in 10**25 |
|
1319 | # odds of a binary node being all hex in ASCII are 1 in 10**25 | |
1320 | try: |
|
1320 | try: | |
1321 | node = id |
|
1321 | node = id | |
1322 | self.rev(node) # quick search the index |
|
1322 | self.rev(node) # quick search the index | |
1323 | return node |
|
1323 | return node | |
1324 | except error.LookupError: |
|
1324 | except error.LookupError: | |
1325 | pass # may be partial hex id |
|
1325 | pass # may be partial hex id | |
1326 | try: |
|
1326 | try: | |
1327 | # str(rev) |
|
1327 | # str(rev) | |
1328 | rev = int(id) |
|
1328 | rev = int(id) | |
1329 | if b"%d" % rev != id: |
|
1329 | if b"%d" % rev != id: | |
1330 | raise ValueError |
|
1330 | raise ValueError | |
1331 | if rev < 0: |
|
1331 | if rev < 0: | |
1332 | rev = len(self) + rev |
|
1332 | rev = len(self) + rev | |
1333 | if rev < 0 or rev >= len(self): |
|
1333 | if rev < 0 or rev >= len(self): | |
1334 | raise ValueError |
|
1334 | raise ValueError | |
1335 | return self.node(rev) |
|
1335 | return self.node(rev) | |
1336 | except (ValueError, OverflowError): |
|
1336 | except (ValueError, OverflowError): | |
1337 | pass |
|
1337 | pass | |
1338 | if len(id) == 2 * self.nodeconstants.nodelen: |
|
1338 | if len(id) == 2 * self.nodeconstants.nodelen: | |
1339 | try: |
|
1339 | try: | |
1340 | # a full hex nodeid? |
|
1340 | # a full hex nodeid? | |
1341 | node = bin(id) |
|
1341 | node = bin(id) | |
1342 | self.rev(node) |
|
1342 | self.rev(node) | |
1343 | return node |
|
1343 | return node | |
1344 | except (TypeError, error.LookupError): |
|
1344 | except (TypeError, error.LookupError): | |
1345 | pass |
|
1345 | pass | |
1346 |
|
1346 | |||
1347 | def _partialmatch(self, id): |
|
1347 | def _partialmatch(self, id): | |
1348 | # we don't care wdirfilenodeids as they should be always full hash |
|
1348 | # we don't care wdirfilenodeids as they should be always full hash | |
1349 | maybewdir = self.nodeconstants.wdirhex.startswith(id) |
|
1349 | maybewdir = self.nodeconstants.wdirhex.startswith(id) | |
1350 | try: |
|
1350 | try: | |
1351 | partial = self.index.partialmatch(id) |
|
1351 | partial = self.index.partialmatch(id) | |
1352 | if partial and self.hasnode(partial): |
|
1352 | if partial and self.hasnode(partial): | |
1353 | if maybewdir: |
|
1353 | if maybewdir: | |
1354 | # single 'ff...' match in radix tree, ambiguous with wdir |
|
1354 | # single 'ff...' match in radix tree, ambiguous with wdir | |
1355 | raise error.RevlogError |
|
1355 | raise error.RevlogError | |
1356 | return partial |
|
1356 | return partial | |
1357 | if maybewdir: |
|
1357 | if maybewdir: | |
1358 | # no 'ff...' match in radix tree, wdir identified |
|
1358 | # no 'ff...' match in radix tree, wdir identified | |
1359 | raise error.WdirUnsupported |
|
1359 | raise error.WdirUnsupported | |
1360 | return None |
|
1360 | return None | |
1361 | except error.RevlogError: |
|
1361 | except error.RevlogError: | |
1362 | # parsers.c radix tree lookup gave multiple matches |
|
1362 | # parsers.c radix tree lookup gave multiple matches | |
1363 | # fast path: for unfiltered changelog, radix tree is accurate |
|
1363 | # fast path: for unfiltered changelog, radix tree is accurate | |
1364 | if not getattr(self, 'filteredrevs', None): |
|
1364 | if not getattr(self, 'filteredrevs', None): | |
1365 | raise error.AmbiguousPrefixLookupError( |
|
1365 | raise error.AmbiguousPrefixLookupError( | |
1366 | id, self.indexfile, _(b'ambiguous identifier') |
|
1366 | id, self.indexfile, _(b'ambiguous identifier') | |
1367 | ) |
|
1367 | ) | |
1368 | # fall through to slow path that filters hidden revisions |
|
1368 | # fall through to slow path that filters hidden revisions | |
1369 | except (AttributeError, ValueError): |
|
1369 | except (AttributeError, ValueError): | |
1370 | # we are pure python, or key was too short to search radix tree |
|
1370 | # we are pure python, or key was too short to search radix tree | |
1371 | pass |
|
1371 | pass | |
1372 |
|
1372 | |||
1373 | if id in self._pcache: |
|
1373 | if id in self._pcache: | |
1374 | return self._pcache[id] |
|
1374 | return self._pcache[id] | |
1375 |
|
1375 | |||
1376 | if len(id) <= 40: |
|
1376 | if len(id) <= 40: | |
1377 | try: |
|
1377 | try: | |
1378 | # hex(node)[:...] |
|
1378 | # hex(node)[:...] | |
1379 | l = len(id) // 2 # grab an even number of digits |
|
1379 | l = len(id) // 2 # grab an even number of digits | |
1380 | prefix = bin(id[: l * 2]) |
|
1380 | prefix = bin(id[: l * 2]) | |
1381 | nl = [e[7] for e in self.index if e[7].startswith(prefix)] |
|
1381 | nl = [e[7] for e in self.index if e[7].startswith(prefix)] | |
1382 | nl = [ |
|
1382 | nl = [ | |
1383 | n for n in nl if hex(n).startswith(id) and self.hasnode(n) |
|
1383 | n for n in nl if hex(n).startswith(id) and self.hasnode(n) | |
1384 | ] |
|
1384 | ] | |
1385 | if self.nodeconstants.nullhex.startswith(id): |
|
1385 | if self.nodeconstants.nullhex.startswith(id): | |
1386 | nl.append(self.nullid) |
|
1386 | nl.append(self.nullid) | |
1387 | if len(nl) > 0: |
|
1387 | if len(nl) > 0: | |
1388 | if len(nl) == 1 and not maybewdir: |
|
1388 | if len(nl) == 1 and not maybewdir: | |
1389 | self._pcache[id] = nl[0] |
|
1389 | self._pcache[id] = nl[0] | |
1390 | return nl[0] |
|
1390 | return nl[0] | |
1391 | raise error.AmbiguousPrefixLookupError( |
|
1391 | raise error.AmbiguousPrefixLookupError( | |
1392 | id, self.indexfile, _(b'ambiguous identifier') |
|
1392 | id, self.indexfile, _(b'ambiguous identifier') | |
1393 | ) |
|
1393 | ) | |
1394 | if maybewdir: |
|
1394 | if maybewdir: | |
1395 | raise error.WdirUnsupported |
|
1395 | raise error.WdirUnsupported | |
1396 | return None |
|
1396 | return None | |
1397 | except TypeError: |
|
1397 | except TypeError: | |
1398 | pass |
|
1398 | pass | |
1399 |
|
1399 | |||
1400 | def lookup(self, id): |
|
1400 | def lookup(self, id): | |
1401 | """locate a node based on: |
|
1401 | """locate a node based on: | |
1402 | - revision number or str(revision number) |
|
1402 | - revision number or str(revision number) | |
1403 | - nodeid or subset of hex nodeid |
|
1403 | - nodeid or subset of hex nodeid | |
1404 | """ |
|
1404 | """ | |
1405 | n = self._match(id) |
|
1405 | n = self._match(id) | |
1406 | if n is not None: |
|
1406 | if n is not None: | |
1407 | return n |
|
1407 | return n | |
1408 | n = self._partialmatch(id) |
|
1408 | n = self._partialmatch(id) | |
1409 | if n: |
|
1409 | if n: | |
1410 | return n |
|
1410 | return n | |
1411 |
|
1411 | |||
1412 | raise error.LookupError(id, self.indexfile, _(b'no match found')) |
|
1412 | raise error.LookupError(id, self.indexfile, _(b'no match found')) | |
1413 |
|
1413 | |||
1414 | def shortest(self, node, minlength=1): |
|
1414 | def shortest(self, node, minlength=1): | |
1415 | """Find the shortest unambiguous prefix that matches node.""" |
|
1415 | """Find the shortest unambiguous prefix that matches node.""" | |
1416 |
|
1416 | |||
1417 | def isvalid(prefix): |
|
1417 | def isvalid(prefix): | |
1418 | try: |
|
1418 | try: | |
1419 | matchednode = self._partialmatch(prefix) |
|
1419 | matchednode = self._partialmatch(prefix) | |
1420 | except error.AmbiguousPrefixLookupError: |
|
1420 | except error.AmbiguousPrefixLookupError: | |
1421 | return False |
|
1421 | return False | |
1422 | except error.WdirUnsupported: |
|
1422 | except error.WdirUnsupported: | |
1423 | # single 'ff...' match |
|
1423 | # single 'ff...' match | |
1424 | return True |
|
1424 | return True | |
1425 | if matchednode is None: |
|
1425 | if matchednode is None: | |
1426 | raise error.LookupError(node, self.indexfile, _(b'no node')) |
|
1426 | raise error.LookupError(node, self.indexfile, _(b'no node')) | |
1427 | return True |
|
1427 | return True | |
1428 |
|
1428 | |||
1429 | def maybewdir(prefix): |
|
1429 | def maybewdir(prefix): | |
1430 | return all(c == b'f' for c in pycompat.iterbytestr(prefix)) |
|
1430 | return all(c == b'f' for c in pycompat.iterbytestr(prefix)) | |
1431 |
|
1431 | |||
1432 | hexnode = hex(node) |
|
1432 | hexnode = hex(node) | |
1433 |
|
1433 | |||
1434 | def disambiguate(hexnode, minlength): |
|
1434 | def disambiguate(hexnode, minlength): | |
1435 | """Disambiguate against wdirid.""" |
|
1435 | """Disambiguate against wdirid.""" | |
1436 | for length in range(minlength, len(hexnode) + 1): |
|
1436 | for length in range(minlength, len(hexnode) + 1): | |
1437 | prefix = hexnode[:length] |
|
1437 | prefix = hexnode[:length] | |
1438 | if not maybewdir(prefix): |
|
1438 | if not maybewdir(prefix): | |
1439 | return prefix |
|
1439 | return prefix | |
1440 |
|
1440 | |||
1441 | if not getattr(self, 'filteredrevs', None): |
|
1441 | if not getattr(self, 'filteredrevs', None): | |
1442 | try: |
|
1442 | try: | |
1443 | length = max(self.index.shortest(node), minlength) |
|
1443 | length = max(self.index.shortest(node), minlength) | |
1444 | return disambiguate(hexnode, length) |
|
1444 | return disambiguate(hexnode, length) | |
1445 | except error.RevlogError: |
|
1445 | except error.RevlogError: | |
1446 | if node != self.nodeconstants.wdirid: |
|
1446 | if node != self.nodeconstants.wdirid: | |
1447 | raise error.LookupError(node, self.indexfile, _(b'no node')) |
|
1447 | raise error.LookupError(node, self.indexfile, _(b'no node')) | |
1448 | except AttributeError: |
|
1448 | except AttributeError: | |
1449 | # Fall through to pure code |
|
1449 | # Fall through to pure code | |
1450 | pass |
|
1450 | pass | |
1451 |
|
1451 | |||
1452 | if node == self.nodeconstants.wdirid: |
|
1452 | if node == self.nodeconstants.wdirid: | |
1453 | for length in range(minlength, len(hexnode) + 1): |
|
1453 | for length in range(minlength, len(hexnode) + 1): | |
1454 | prefix = hexnode[:length] |
|
1454 | prefix = hexnode[:length] | |
1455 | if isvalid(prefix): |
|
1455 | if isvalid(prefix): | |
1456 | return prefix |
|
1456 | return prefix | |
1457 |
|
1457 | |||
1458 | for length in range(minlength, len(hexnode) + 1): |
|
1458 | for length in range(minlength, len(hexnode) + 1): | |
1459 | prefix = hexnode[:length] |
|
1459 | prefix = hexnode[:length] | |
1460 | if isvalid(prefix): |
|
1460 | if isvalid(prefix): | |
1461 | return disambiguate(hexnode, length) |
|
1461 | return disambiguate(hexnode, length) | |
1462 |
|
1462 | |||
1463 | def cmp(self, node, text): |
|
1463 | def cmp(self, node, text): | |
1464 | """compare text with a given file revision |
|
1464 | """compare text with a given file revision | |
1465 |
|
1465 | |||
1466 | returns True if text is different than what is stored. |
|
1466 | returns True if text is different than what is stored. | |
1467 | """ |
|
1467 | """ | |
1468 | p1, p2 = self.parents(node) |
|
1468 | p1, p2 = self.parents(node) | |
1469 | return storageutil.hashrevisionsha1(text, p1, p2) != node |
|
1469 | return storageutil.hashrevisionsha1(text, p1, p2) != node | |
1470 |
|
1470 | |||
1471 | def _cachesegment(self, offset, data): |
|
1471 | def _cachesegment(self, offset, data): | |
1472 | """Add a segment to the revlog cache. |
|
1472 | """Add a segment to the revlog cache. | |
1473 |
|
1473 | |||
1474 | Accepts an absolute offset and the data that is at that location. |
|
1474 | Accepts an absolute offset and the data that is at that location. | |
1475 | """ |
|
1475 | """ | |
1476 | o, d = self._chunkcache |
|
1476 | o, d = self._chunkcache | |
1477 | # try to add to existing cache |
|
1477 | # try to add to existing cache | |
1478 | if o + len(d) == offset and len(d) + len(data) < _chunksize: |
|
1478 | if o + len(d) == offset and len(d) + len(data) < _chunksize: | |
1479 | self._chunkcache = o, d + data |
|
1479 | self._chunkcache = o, d + data | |
1480 | else: |
|
1480 | else: | |
1481 | self._chunkcache = offset, data |
|
1481 | self._chunkcache = offset, data | |
1482 |
|
1482 | |||
1483 | def _readsegment(self, offset, length, df=None): |
|
1483 | def _readsegment(self, offset, length, df=None): | |
1484 | """Load a segment of raw data from the revlog. |
|
1484 | """Load a segment of raw data from the revlog. | |
1485 |
|
1485 | |||
1486 | Accepts an absolute offset, length to read, and an optional existing |
|
1486 | Accepts an absolute offset, length to read, and an optional existing | |
1487 | file handle to read from. |
|
1487 | file handle to read from. | |
1488 |
|
1488 | |||
1489 | If an existing file handle is passed, it will be seeked and the |
|
1489 | If an existing file handle is passed, it will be seeked and the | |
1490 | original seek position will NOT be restored. |
|
1490 | original seek position will NOT be restored. | |
1491 |
|
1491 | |||
1492 | Returns a str or buffer of raw byte data. |
|
1492 | Returns a str or buffer of raw byte data. | |
1493 |
|
1493 | |||
1494 | Raises if the requested number of bytes could not be read. |
|
1494 | Raises if the requested number of bytes could not be read. | |
1495 | """ |
|
1495 | """ | |
1496 | # Cache data both forward and backward around the requested |
|
1496 | # Cache data both forward and backward around the requested | |
1497 | # data, in a fixed size window. This helps speed up operations |
|
1497 | # data, in a fixed size window. This helps speed up operations | |
1498 | # involving reading the revlog backwards. |
|
1498 | # involving reading the revlog backwards. | |
1499 | cachesize = self._chunkcachesize |
|
1499 | cachesize = self._chunkcachesize | |
1500 | realoffset = offset & ~(cachesize - 1) |
|
1500 | realoffset = offset & ~(cachesize - 1) | |
1501 | reallength = ( |
|
1501 | reallength = ( | |
1502 | (offset + length + cachesize) & ~(cachesize - 1) |
|
1502 | (offset + length + cachesize) & ~(cachesize - 1) | |
1503 | ) - realoffset |
|
1503 | ) - realoffset | |
1504 | with self._datareadfp(df) as df: |
|
1504 | with self._datareadfp(df) as df: | |
1505 | df.seek(realoffset) |
|
1505 | df.seek(realoffset) | |
1506 | d = df.read(reallength) |
|
1506 | d = df.read(reallength) | |
1507 |
|
1507 | |||
1508 | self._cachesegment(realoffset, d) |
|
1508 | self._cachesegment(realoffset, d) | |
1509 | if offset != realoffset or reallength != length: |
|
1509 | if offset != realoffset or reallength != length: | |
1510 | startoffset = offset - realoffset |
|
1510 | startoffset = offset - realoffset | |
1511 | if len(d) - startoffset < length: |
|
1511 | if len(d) - startoffset < length: | |
1512 | raise error.RevlogError( |
|
1512 | raise error.RevlogError( | |
1513 | _( |
|
1513 | _( | |
1514 | b'partial read of revlog %s; expected %d bytes from ' |
|
1514 | b'partial read of revlog %s; expected %d bytes from ' | |
1515 | b'offset %d, got %d' |
|
1515 | b'offset %d, got %d' | |
1516 | ) |
|
1516 | ) | |
1517 | % ( |
|
1517 | % ( | |
1518 | self.indexfile if self._inline else self.datafile, |
|
1518 | self.indexfile if self._inline else self.datafile, | |
1519 | length, |
|
1519 | length, | |
1520 | realoffset, |
|
1520 | realoffset, | |
1521 | len(d) - startoffset, |
|
1521 | len(d) - startoffset, | |
1522 | ) |
|
1522 | ) | |
1523 | ) |
|
1523 | ) | |
1524 |
|
1524 | |||
1525 | return util.buffer(d, startoffset, length) |
|
1525 | return util.buffer(d, startoffset, length) | |
1526 |
|
1526 | |||
1527 | if len(d) < length: |
|
1527 | if len(d) < length: | |
1528 | raise error.RevlogError( |
|
1528 | raise error.RevlogError( | |
1529 | _( |
|
1529 | _( | |
1530 | b'partial read of revlog %s; expected %d bytes from offset ' |
|
1530 | b'partial read of revlog %s; expected %d bytes from offset ' | |
1531 | b'%d, got %d' |
|
1531 | b'%d, got %d' | |
1532 | ) |
|
1532 | ) | |
1533 | % ( |
|
1533 | % ( | |
1534 | self.indexfile if self._inline else self.datafile, |
|
1534 | self.indexfile if self._inline else self.datafile, | |
1535 | length, |
|
1535 | length, | |
1536 | offset, |
|
1536 | offset, | |
1537 | len(d), |
|
1537 | len(d), | |
1538 | ) |
|
1538 | ) | |
1539 | ) |
|
1539 | ) | |
1540 |
|
1540 | |||
1541 | return d |
|
1541 | return d | |
1542 |
|
1542 | |||
1543 | def _getsegment(self, offset, length, df=None): |
|
1543 | def _getsegment(self, offset, length, df=None): | |
1544 | """Obtain a segment of raw data from the revlog. |
|
1544 | """Obtain a segment of raw data from the revlog. | |
1545 |
|
1545 | |||
1546 | Accepts an absolute offset, length of bytes to obtain, and an |
|
1546 | Accepts an absolute offset, length of bytes to obtain, and an | |
1547 | optional file handle to the already-opened revlog. If the file |
|
1547 | optional file handle to the already-opened revlog. If the file | |
1548 | handle is used, it's original seek position will not be preserved. |
|
1548 | handle is used, it's original seek position will not be preserved. | |
1549 |
|
1549 | |||
1550 | Requests for data may be returned from a cache. |
|
1550 | Requests for data may be returned from a cache. | |
1551 |
|
1551 | |||
1552 | Returns a str or a buffer instance of raw byte data. |
|
1552 | Returns a str or a buffer instance of raw byte data. | |
1553 | """ |
|
1553 | """ | |
1554 | o, d = self._chunkcache |
|
1554 | o, d = self._chunkcache | |
1555 | l = len(d) |
|
1555 | l = len(d) | |
1556 |
|
1556 | |||
1557 | # is it in the cache? |
|
1557 | # is it in the cache? | |
1558 | cachestart = offset - o |
|
1558 | cachestart = offset - o | |
1559 | cacheend = cachestart + length |
|
1559 | cacheend = cachestart + length | |
1560 | if cachestart >= 0 and cacheend <= l: |
|
1560 | if cachestart >= 0 and cacheend <= l: | |
1561 | if cachestart == 0 and cacheend == l: |
|
1561 | if cachestart == 0 and cacheend == l: | |
1562 | return d # avoid a copy |
|
1562 | return d # avoid a copy | |
1563 | return util.buffer(d, cachestart, cacheend - cachestart) |
|
1563 | return util.buffer(d, cachestart, cacheend - cachestart) | |
1564 |
|
1564 | |||
1565 | return self._readsegment(offset, length, df=df) |
|
1565 | return self._readsegment(offset, length, df=df) | |
1566 |
|
1566 | |||
1567 | def _getsegmentforrevs(self, startrev, endrev, df=None): |
|
1567 | def _getsegmentforrevs(self, startrev, endrev, df=None): | |
1568 | """Obtain a segment of raw data corresponding to a range of revisions. |
|
1568 | """Obtain a segment of raw data corresponding to a range of revisions. | |
1569 |
|
1569 | |||
1570 | Accepts the start and end revisions and an optional already-open |
|
1570 | Accepts the start and end revisions and an optional already-open | |
1571 | file handle to be used for reading. If the file handle is read, its |
|
1571 | file handle to be used for reading. If the file handle is read, its | |
1572 | seek position will not be preserved. |
|
1572 | seek position will not be preserved. | |
1573 |
|
1573 | |||
1574 | Requests for data may be satisfied by a cache. |
|
1574 | Requests for data may be satisfied by a cache. | |
1575 |
|
1575 | |||
1576 | Returns a 2-tuple of (offset, data) for the requested range of |
|
1576 | Returns a 2-tuple of (offset, data) for the requested range of | |
1577 | revisions. Offset is the integer offset from the beginning of the |
|
1577 | revisions. Offset is the integer offset from the beginning of the | |
1578 | revlog and data is a str or buffer of the raw byte data. |
|
1578 | revlog and data is a str or buffer of the raw byte data. | |
1579 |
|
1579 | |||
1580 | Callers will need to call ``self.start(rev)`` and ``self.length(rev)`` |
|
1580 | Callers will need to call ``self.start(rev)`` and ``self.length(rev)`` | |
1581 | to determine where each revision's data begins and ends. |
|
1581 | to determine where each revision's data begins and ends. | |
1582 | """ |
|
1582 | """ | |
1583 | # Inlined self.start(startrev) & self.end(endrev) for perf reasons |
|
1583 | # Inlined self.start(startrev) & self.end(endrev) for perf reasons | |
1584 | # (functions are expensive). |
|
1584 | # (functions are expensive). | |
1585 | index = self.index |
|
1585 | index = self.index | |
1586 | istart = index[startrev] |
|
1586 | istart = index[startrev] | |
1587 | start = int(istart[0] >> 16) |
|
1587 | start = int(istart[0] >> 16) | |
1588 | if startrev == endrev: |
|
1588 | if startrev == endrev: | |
1589 | end = start + istart[1] |
|
1589 | end = start + istart[1] | |
1590 | else: |
|
1590 | else: | |
1591 | iend = index[endrev] |
|
1591 | iend = index[endrev] | |
1592 | end = int(iend[0] >> 16) + iend[1] |
|
1592 | end = int(iend[0] >> 16) + iend[1] | |
1593 |
|
1593 | |||
1594 | if self._inline: |
|
1594 | if self._inline: | |
1595 | start += (startrev + 1) * self.index.entry_size |
|
1595 | start += (startrev + 1) * self.index.entry_size | |
1596 | end += (endrev + 1) * self.index.entry_size |
|
1596 | end += (endrev + 1) * self.index.entry_size | |
1597 | length = end - start |
|
1597 | length = end - start | |
1598 |
|
1598 | |||
1599 | return start, self._getsegment(start, length, df=df) |
|
1599 | return start, self._getsegment(start, length, df=df) | |
1600 |
|
1600 | |||
1601 | def _chunk(self, rev, df=None): |
|
1601 | def _chunk(self, rev, df=None): | |
1602 | """Obtain a single decompressed chunk for a revision. |
|
1602 | """Obtain a single decompressed chunk for a revision. | |
1603 |
|
1603 | |||
1604 | Accepts an integer revision and an optional already-open file handle |
|
1604 | Accepts an integer revision and an optional already-open file handle | |
1605 | to be used for reading. If used, the seek position of the file will not |
|
1605 | to be used for reading. If used, the seek position of the file will not | |
1606 | be preserved. |
|
1606 | be preserved. | |
1607 |
|
1607 | |||
1608 | Returns a str holding uncompressed data for the requested revision. |
|
1608 | Returns a str holding uncompressed data for the requested revision. | |
1609 | """ |
|
1609 | """ | |
1610 | return self.decompress(self._getsegmentforrevs(rev, rev, df=df)[1]) |
|
1610 | return self.decompress(self._getsegmentforrevs(rev, rev, df=df)[1]) | |
1611 |
|
1611 | |||
1612 | def _chunks(self, revs, df=None, targetsize=None): |
|
1612 | def _chunks(self, revs, df=None, targetsize=None): | |
1613 | """Obtain decompressed chunks for the specified revisions. |
|
1613 | """Obtain decompressed chunks for the specified revisions. | |
1614 |
|
1614 | |||
1615 | Accepts an iterable of numeric revisions that are assumed to be in |
|
1615 | Accepts an iterable of numeric revisions that are assumed to be in | |
1616 | ascending order. Also accepts an optional already-open file handle |
|
1616 | ascending order. Also accepts an optional already-open file handle | |
1617 | to be used for reading. If used, the seek position of the file will |
|
1617 | to be used for reading. If used, the seek position of the file will | |
1618 | not be preserved. |
|
1618 | not be preserved. | |
1619 |
|
1619 | |||
1620 | This function is similar to calling ``self._chunk()`` multiple times, |
|
1620 | This function is similar to calling ``self._chunk()`` multiple times, | |
1621 | but is faster. |
|
1621 | but is faster. | |
1622 |
|
1622 | |||
1623 | Returns a list with decompressed data for each requested revision. |
|
1623 | Returns a list with decompressed data for each requested revision. | |
1624 | """ |
|
1624 | """ | |
1625 | if not revs: |
|
1625 | if not revs: | |
1626 | return [] |
|
1626 | return [] | |
1627 | start = self.start |
|
1627 | start = self.start | |
1628 | length = self.length |
|
1628 | length = self.length | |
1629 | inline = self._inline |
|
1629 | inline = self._inline | |
1630 | iosize = self.index.entry_size |
|
1630 | iosize = self.index.entry_size | |
1631 | buffer = util.buffer |
|
1631 | buffer = util.buffer | |
1632 |
|
1632 | |||
1633 | l = [] |
|
1633 | l = [] | |
1634 | ladd = l.append |
|
1634 | ladd = l.append | |
1635 |
|
1635 | |||
1636 | if not self._withsparseread: |
|
1636 | if not self._withsparseread: | |
1637 | slicedchunks = (revs,) |
|
1637 | slicedchunks = (revs,) | |
1638 | else: |
|
1638 | else: | |
1639 | slicedchunks = deltautil.slicechunk( |
|
1639 | slicedchunks = deltautil.slicechunk( | |
1640 | self, revs, targetsize=targetsize |
|
1640 | self, revs, targetsize=targetsize | |
1641 | ) |
|
1641 | ) | |
1642 |
|
1642 | |||
1643 | for revschunk in slicedchunks: |
|
1643 | for revschunk in slicedchunks: | |
1644 | firstrev = revschunk[0] |
|
1644 | firstrev = revschunk[0] | |
1645 | # Skip trailing revisions with empty diff |
|
1645 | # Skip trailing revisions with empty diff | |
1646 | for lastrev in revschunk[::-1]: |
|
1646 | for lastrev in revschunk[::-1]: | |
1647 | if length(lastrev) != 0: |
|
1647 | if length(lastrev) != 0: | |
1648 | break |
|
1648 | break | |
1649 |
|
1649 | |||
1650 | try: |
|
1650 | try: | |
1651 | offset, data = self._getsegmentforrevs(firstrev, lastrev, df=df) |
|
1651 | offset, data = self._getsegmentforrevs(firstrev, lastrev, df=df) | |
1652 | except OverflowError: |
|
1652 | except OverflowError: | |
1653 | # issue4215 - we can't cache a run of chunks greater than |
|
1653 | # issue4215 - we can't cache a run of chunks greater than | |
1654 | # 2G on Windows |
|
1654 | # 2G on Windows | |
1655 | return [self._chunk(rev, df=df) for rev in revschunk] |
|
1655 | return [self._chunk(rev, df=df) for rev in revschunk] | |
1656 |
|
1656 | |||
1657 | decomp = self.decompress |
|
1657 | decomp = self.decompress | |
1658 | for rev in revschunk: |
|
1658 | for rev in revschunk: | |
1659 | chunkstart = start(rev) |
|
1659 | chunkstart = start(rev) | |
1660 | if inline: |
|
1660 | if inline: | |
1661 | chunkstart += (rev + 1) * iosize |
|
1661 | chunkstart += (rev + 1) * iosize | |
1662 | chunklength = length(rev) |
|
1662 | chunklength = length(rev) | |
1663 | ladd(decomp(buffer(data, chunkstart - offset, chunklength))) |
|
1663 | ladd(decomp(buffer(data, chunkstart - offset, chunklength))) | |
1664 |
|
1664 | |||
1665 | return l |
|
1665 | return l | |
1666 |
|
1666 | |||
1667 | def _chunkclear(self): |
|
1667 | def _chunkclear(self): | |
1668 | """Clear the raw chunk cache.""" |
|
1668 | """Clear the raw chunk cache.""" | |
1669 | self._chunkcache = (0, b'') |
|
1669 | self._chunkcache = (0, b'') | |
1670 |
|
1670 | |||
1671 | def deltaparent(self, rev): |
|
1671 | def deltaparent(self, rev): | |
1672 | """return deltaparent of the given revision""" |
|
1672 | """return deltaparent of the given revision""" | |
1673 | base = self.index[rev][3] |
|
1673 | base = self.index[rev][3] | |
1674 | if base == rev: |
|
1674 | if base == rev: | |
1675 | return nullrev |
|
1675 | return nullrev | |
1676 | elif self._generaldelta: |
|
1676 | elif self._generaldelta: | |
1677 | return base |
|
1677 | return base | |
1678 | else: |
|
1678 | else: | |
1679 | return rev - 1 |
|
1679 | return rev - 1 | |
1680 |
|
1680 | |||
1681 | def issnapshot(self, rev): |
|
1681 | def issnapshot(self, rev): | |
1682 | """tells whether rev is a snapshot""" |
|
1682 | """tells whether rev is a snapshot""" | |
1683 | if not self._sparserevlog: |
|
1683 | if not self._sparserevlog: | |
1684 | return self.deltaparent(rev) == nullrev |
|
1684 | return self.deltaparent(rev) == nullrev | |
1685 | elif util.safehasattr(self.index, b'issnapshot'): |
|
1685 | elif util.safehasattr(self.index, b'issnapshot'): | |
1686 | # directly assign the method to cache the testing and access |
|
1686 | # directly assign the method to cache the testing and access | |
1687 | self.issnapshot = self.index.issnapshot |
|
1687 | self.issnapshot = self.index.issnapshot | |
1688 | return self.issnapshot(rev) |
|
1688 | return self.issnapshot(rev) | |
1689 | if rev == nullrev: |
|
1689 | if rev == nullrev: | |
1690 | return True |
|
1690 | return True | |
1691 | entry = self.index[rev] |
|
1691 | entry = self.index[rev] | |
1692 | base = entry[3] |
|
1692 | base = entry[3] | |
1693 | if base == rev: |
|
1693 | if base == rev: | |
1694 | return True |
|
1694 | return True | |
1695 | if base == nullrev: |
|
1695 | if base == nullrev: | |
1696 | return True |
|
1696 | return True | |
1697 | p1 = entry[5] |
|
1697 | p1 = entry[5] | |
1698 | p2 = entry[6] |
|
1698 | p2 = entry[6] | |
1699 | if base == p1 or base == p2: |
|
1699 | if base == p1 or base == p2: | |
1700 | return False |
|
1700 | return False | |
1701 | return self.issnapshot(base) |
|
1701 | return self.issnapshot(base) | |
1702 |
|
1702 | |||
1703 | def snapshotdepth(self, rev): |
|
1703 | def snapshotdepth(self, rev): | |
1704 | """number of snapshot in the chain before this one""" |
|
1704 | """number of snapshot in the chain before this one""" | |
1705 | if not self.issnapshot(rev): |
|
1705 | if not self.issnapshot(rev): | |
1706 | raise error.ProgrammingError(b'revision %d not a snapshot') |
|
1706 | raise error.ProgrammingError(b'revision %d not a snapshot') | |
1707 | return len(self._deltachain(rev)[0]) - 1 |
|
1707 | return len(self._deltachain(rev)[0]) - 1 | |
1708 |
|
1708 | |||
1709 | def revdiff(self, rev1, rev2): |
|
1709 | def revdiff(self, rev1, rev2): | |
1710 | """return or calculate a delta between two revisions |
|
1710 | """return or calculate a delta between two revisions | |
1711 |
|
1711 | |||
1712 | The delta calculated is in binary form and is intended to be written to |
|
1712 | The delta calculated is in binary form and is intended to be written to | |
1713 | revlog data directly. So this function needs raw revision data. |
|
1713 | revlog data directly. So this function needs raw revision data. | |
1714 | """ |
|
1714 | """ | |
1715 | if rev1 != nullrev and self.deltaparent(rev2) == rev1: |
|
1715 | if rev1 != nullrev and self.deltaparent(rev2) == rev1: | |
1716 | return bytes(self._chunk(rev2)) |
|
1716 | return bytes(self._chunk(rev2)) | |
1717 |
|
1717 | |||
1718 | return mdiff.textdiff(self.rawdata(rev1), self.rawdata(rev2)) |
|
1718 | return mdiff.textdiff(self.rawdata(rev1), self.rawdata(rev2)) | |
1719 |
|
1719 | |||
1720 | def _processflags(self, text, flags, operation, raw=False): |
|
1720 | def _processflags(self, text, flags, operation, raw=False): | |
1721 | """deprecated entry point to access flag processors""" |
|
1721 | """deprecated entry point to access flag processors""" | |
1722 | msg = b'_processflag(...) use the specialized variant' |
|
1722 | msg = b'_processflag(...) use the specialized variant' | |
1723 | util.nouideprecwarn(msg, b'5.2', stacklevel=2) |
|
1723 | util.nouideprecwarn(msg, b'5.2', stacklevel=2) | |
1724 | if raw: |
|
1724 | if raw: | |
1725 | return text, flagutil.processflagsraw(self, text, flags) |
|
1725 | return text, flagutil.processflagsraw(self, text, flags) | |
1726 | elif operation == b'read': |
|
1726 | elif operation == b'read': | |
1727 | return flagutil.processflagsread(self, text, flags) |
|
1727 | return flagutil.processflagsread(self, text, flags) | |
1728 | else: # write operation |
|
1728 | else: # write operation | |
1729 | return flagutil.processflagswrite(self, text, flags) |
|
1729 | return flagutil.processflagswrite(self, text, flags) | |
1730 |
|
1730 | |||
1731 | def revision(self, nodeorrev, _df=None, raw=False): |
|
1731 | def revision(self, nodeorrev, _df=None, raw=False): | |
1732 | """return an uncompressed revision of a given node or revision |
|
1732 | """return an uncompressed revision of a given node or revision | |
1733 | number. |
|
1733 | number. | |
1734 |
|
1734 | |||
1735 | _df - an existing file handle to read from. (internal-only) |
|
1735 | _df - an existing file handle to read from. (internal-only) | |
1736 | raw - an optional argument specifying if the revision data is to be |
|
1736 | raw - an optional argument specifying if the revision data is to be | |
1737 | treated as raw data when applying flag transforms. 'raw' should be set |
|
1737 | treated as raw data when applying flag transforms. 'raw' should be set | |
1738 | to True when generating changegroups or in debug commands. |
|
1738 | to True when generating changegroups or in debug commands. | |
1739 | """ |
|
1739 | """ | |
1740 | if raw: |
|
1740 | if raw: | |
1741 | msg = ( |
|
1741 | msg = ( | |
1742 | b'revlog.revision(..., raw=True) is deprecated, ' |
|
1742 | b'revlog.revision(..., raw=True) is deprecated, ' | |
1743 | b'use revlog.rawdata(...)' |
|
1743 | b'use revlog.rawdata(...)' | |
1744 | ) |
|
1744 | ) | |
1745 | util.nouideprecwarn(msg, b'5.2', stacklevel=2) |
|
1745 | util.nouideprecwarn(msg, b'5.2', stacklevel=2) | |
1746 | return self._revisiondata(nodeorrev, _df, raw=raw)[0] |
|
1746 | return self._revisiondata(nodeorrev, _df, raw=raw)[0] | |
1747 |
|
1747 | |||
1748 | def sidedata(self, nodeorrev, _df=None): |
|
1748 | def sidedata(self, nodeorrev, _df=None): | |
1749 | """a map of extra data related to the changeset but not part of the hash |
|
1749 | """a map of extra data related to the changeset but not part of the hash | |
1750 |
|
1750 | |||
1751 | This function currently return a dictionary. However, more advanced |
|
1751 | This function currently return a dictionary. However, more advanced | |
1752 | mapping object will likely be used in the future for a more |
|
1752 | mapping object will likely be used in the future for a more | |
1753 | efficient/lazy code. |
|
1753 | efficient/lazy code. | |
1754 | """ |
|
1754 | """ | |
1755 | return self._revisiondata(nodeorrev, _df)[1] |
|
1755 | return self._revisiondata(nodeorrev, _df)[1] | |
1756 |
|
1756 | |||
1757 | def _revisiondata(self, nodeorrev, _df=None, raw=False): |
|
1757 | def _revisiondata(self, nodeorrev, _df=None, raw=False): | |
1758 | # deal with <nodeorrev> argument type |
|
1758 | # deal with <nodeorrev> argument type | |
1759 | if isinstance(nodeorrev, int): |
|
1759 | if isinstance(nodeorrev, int): | |
1760 | rev = nodeorrev |
|
1760 | rev = nodeorrev | |
1761 | node = self.node(rev) |
|
1761 | node = self.node(rev) | |
1762 | else: |
|
1762 | else: | |
1763 | node = nodeorrev |
|
1763 | node = nodeorrev | |
1764 | rev = None |
|
1764 | rev = None | |
1765 |
|
1765 | |||
1766 | # fast path the special `nullid` rev |
|
1766 | # fast path the special `nullid` rev | |
1767 | if node == self.nullid: |
|
1767 | if node == self.nullid: | |
1768 | return b"", {} |
|
1768 | return b"", {} | |
1769 |
|
1769 | |||
1770 | # ``rawtext`` is the text as stored inside the revlog. Might be the |
|
1770 | # ``rawtext`` is the text as stored inside the revlog. Might be the | |
1771 | # revision or might need to be processed to retrieve the revision. |
|
1771 | # revision or might need to be processed to retrieve the revision. | |
1772 | rev, rawtext, validated = self._rawtext(node, rev, _df=_df) |
|
1772 | rev, rawtext, validated = self._rawtext(node, rev, _df=_df) | |
1773 |
|
1773 | |||
1774 | if self.version & 0xFFFF == REVLOGV2: |
|
1774 | if self.version & 0xFFFF == REVLOGV2: | |
1775 | if rev is None: |
|
1775 | if rev is None: | |
1776 | rev = self.rev(node) |
|
1776 | rev = self.rev(node) | |
1777 | sidedata = self._sidedata(rev) |
|
1777 | sidedata = self._sidedata(rev) | |
1778 | else: |
|
1778 | else: | |
1779 | sidedata = {} |
|
1779 | sidedata = {} | |
1780 |
|
1780 | |||
1781 | if raw and validated: |
|
1781 | if raw and validated: | |
1782 | # if we don't want to process the raw text and that raw |
|
1782 | # if we don't want to process the raw text and that raw | |
1783 | # text is cached, we can exit early. |
|
1783 | # text is cached, we can exit early. | |
1784 | return rawtext, sidedata |
|
1784 | return rawtext, sidedata | |
1785 | if rev is None: |
|
1785 | if rev is None: | |
1786 | rev = self.rev(node) |
|
1786 | rev = self.rev(node) | |
1787 | # the revlog's flag for this revision |
|
1787 | # the revlog's flag for this revision | |
1788 | # (usually alter its state or content) |
|
1788 | # (usually alter its state or content) | |
1789 | flags = self.flags(rev) |
|
1789 | flags = self.flags(rev) | |
1790 |
|
1790 | |||
1791 | if validated and flags == REVIDX_DEFAULT_FLAGS: |
|
1791 | if validated and flags == REVIDX_DEFAULT_FLAGS: | |
1792 | # no extra flags set, no flag processor runs, text = rawtext |
|
1792 | # no extra flags set, no flag processor runs, text = rawtext | |
1793 | return rawtext, sidedata |
|
1793 | return rawtext, sidedata | |
1794 |
|
1794 | |||
1795 | if raw: |
|
1795 | if raw: | |
1796 | validatehash = flagutil.processflagsraw(self, rawtext, flags) |
|
1796 | validatehash = flagutil.processflagsraw(self, rawtext, flags) | |
1797 | text = rawtext |
|
1797 | text = rawtext | |
1798 | else: |
|
1798 | else: | |
1799 | r = flagutil.processflagsread(self, rawtext, flags) |
|
1799 | r = flagutil.processflagsread(self, rawtext, flags) | |
1800 | text, validatehash = r |
|
1800 | text, validatehash = r | |
1801 | if validatehash: |
|
1801 | if validatehash: | |
1802 | self.checkhash(text, node, rev=rev) |
|
1802 | self.checkhash(text, node, rev=rev) | |
1803 | if not validated: |
|
1803 | if not validated: | |
1804 | self._revisioncache = (node, rev, rawtext) |
|
1804 | self._revisioncache = (node, rev, rawtext) | |
1805 |
|
1805 | |||
1806 | return text, sidedata |
|
1806 | return text, sidedata | |
1807 |
|
1807 | |||
1808 | def _rawtext(self, node, rev, _df=None): |
|
1808 | def _rawtext(self, node, rev, _df=None): | |
1809 | """return the possibly unvalidated rawtext for a revision |
|
1809 | """return the possibly unvalidated rawtext for a revision | |
1810 |
|
1810 | |||
1811 | returns (rev, rawtext, validated) |
|
1811 | returns (rev, rawtext, validated) | |
1812 | """ |
|
1812 | """ | |
1813 |
|
1813 | |||
1814 | # revision in the cache (could be useful to apply delta) |
|
1814 | # revision in the cache (could be useful to apply delta) | |
1815 | cachedrev = None |
|
1815 | cachedrev = None | |
1816 | # An intermediate text to apply deltas to |
|
1816 | # An intermediate text to apply deltas to | |
1817 | basetext = None |
|
1817 | basetext = None | |
1818 |
|
1818 | |||
1819 | # Check if we have the entry in cache |
|
1819 | # Check if we have the entry in cache | |
1820 | # The cache entry looks like (node, rev, rawtext) |
|
1820 | # The cache entry looks like (node, rev, rawtext) | |
1821 | if self._revisioncache: |
|
1821 | if self._revisioncache: | |
1822 | if self._revisioncache[0] == node: |
|
1822 | if self._revisioncache[0] == node: | |
1823 | return (rev, self._revisioncache[2], True) |
|
1823 | return (rev, self._revisioncache[2], True) | |
1824 | cachedrev = self._revisioncache[1] |
|
1824 | cachedrev = self._revisioncache[1] | |
1825 |
|
1825 | |||
1826 | if rev is None: |
|
1826 | if rev is None: | |
1827 | rev = self.rev(node) |
|
1827 | rev = self.rev(node) | |
1828 |
|
1828 | |||
1829 | chain, stopped = self._deltachain(rev, stoprev=cachedrev) |
|
1829 | chain, stopped = self._deltachain(rev, stoprev=cachedrev) | |
1830 | if stopped: |
|
1830 | if stopped: | |
1831 | basetext = self._revisioncache[2] |
|
1831 | basetext = self._revisioncache[2] | |
1832 |
|
1832 | |||
1833 | # drop cache to save memory, the caller is expected to |
|
1833 | # drop cache to save memory, the caller is expected to | |
1834 | # update self._revisioncache after validating the text |
|
1834 | # update self._revisioncache after validating the text | |
1835 | self._revisioncache = None |
|
1835 | self._revisioncache = None | |
1836 |
|
1836 | |||
1837 | targetsize = None |
|
1837 | targetsize = None | |
1838 | rawsize = self.index[rev][2] |
|
1838 | rawsize = self.index[rev][2] | |
1839 | if 0 <= rawsize: |
|
1839 | if 0 <= rawsize: | |
1840 | targetsize = 4 * rawsize |
|
1840 | targetsize = 4 * rawsize | |
1841 |
|
1841 | |||
1842 | bins = self._chunks(chain, df=_df, targetsize=targetsize) |
|
1842 | bins = self._chunks(chain, df=_df, targetsize=targetsize) | |
1843 | if basetext is None: |
|
1843 | if basetext is None: | |
1844 | basetext = bytes(bins[0]) |
|
1844 | basetext = bytes(bins[0]) | |
1845 | bins = bins[1:] |
|
1845 | bins = bins[1:] | |
1846 |
|
1846 | |||
1847 | rawtext = mdiff.patches(basetext, bins) |
|
1847 | rawtext = mdiff.patches(basetext, bins) | |
1848 | del basetext # let us have a chance to free memory early |
|
1848 | del basetext # let us have a chance to free memory early | |
1849 | return (rev, rawtext, False) |
|
1849 | return (rev, rawtext, False) | |
1850 |
|
1850 | |||
1851 | def _sidedata(self, rev): |
|
1851 | def _sidedata(self, rev): | |
1852 | """Return the sidedata for a given revision number.""" |
|
1852 | """Return the sidedata for a given revision number.""" | |
1853 | index_entry = self.index[rev] |
|
1853 | index_entry = self.index[rev] | |
1854 | sidedata_offset = index_entry[8] |
|
1854 | sidedata_offset = index_entry[8] | |
1855 | sidedata_size = index_entry[9] |
|
1855 | sidedata_size = index_entry[9] | |
1856 |
|
1856 | |||
1857 | if self._inline: |
|
1857 | if self._inline: | |
1858 | sidedata_offset += self.index.entry_size * (1 + rev) |
|
1858 | sidedata_offset += self.index.entry_size * (1 + rev) | |
1859 | if sidedata_size == 0: |
|
1859 | if sidedata_size == 0: | |
1860 | return {} |
|
1860 | return {} | |
1861 |
|
1861 | |||
1862 | segment = self._getsegment(sidedata_offset, sidedata_size) |
|
1862 | segment = self._getsegment(sidedata_offset, sidedata_size) | |
1863 | sidedata = sidedatautil.deserialize_sidedata(segment) |
|
1863 | sidedata = sidedatautil.deserialize_sidedata(segment) | |
1864 | return sidedata |
|
1864 | return sidedata | |
1865 |
|
1865 | |||
1866 | def rawdata(self, nodeorrev, _df=None): |
|
1866 | def rawdata(self, nodeorrev, _df=None): | |
1867 | """return an uncompressed raw data of a given node or revision number. |
|
1867 | """return an uncompressed raw data of a given node or revision number. | |
1868 |
|
1868 | |||
1869 | _df - an existing file handle to read from. (internal-only) |
|
1869 | _df - an existing file handle to read from. (internal-only) | |
1870 | """ |
|
1870 | """ | |
1871 | return self._revisiondata(nodeorrev, _df, raw=True)[0] |
|
1871 | return self._revisiondata(nodeorrev, _df, raw=True)[0] | |
1872 |
|
1872 | |||
1873 | def hash(self, text, p1, p2): |
|
1873 | def hash(self, text, p1, p2): | |
1874 | """Compute a node hash. |
|
1874 | """Compute a node hash. | |
1875 |
|
1875 | |||
1876 | Available as a function so that subclasses can replace the hash |
|
1876 | Available as a function so that subclasses can replace the hash | |
1877 | as needed. |
|
1877 | as needed. | |
1878 | """ |
|
1878 | """ | |
1879 | return storageutil.hashrevisionsha1(text, p1, p2) |
|
1879 | return storageutil.hashrevisionsha1(text, p1, p2) | |
1880 |
|
1880 | |||
1881 | def checkhash(self, text, node, p1=None, p2=None, rev=None): |
|
1881 | def checkhash(self, text, node, p1=None, p2=None, rev=None): | |
1882 | """Check node hash integrity. |
|
1882 | """Check node hash integrity. | |
1883 |
|
1883 | |||
1884 | Available as a function so that subclasses can extend hash mismatch |
|
1884 | Available as a function so that subclasses can extend hash mismatch | |
1885 | behaviors as needed. |
|
1885 | behaviors as needed. | |
1886 | """ |
|
1886 | """ | |
1887 | try: |
|
1887 | try: | |
1888 | if p1 is None and p2 is None: |
|
1888 | if p1 is None and p2 is None: | |
1889 | p1, p2 = self.parents(node) |
|
1889 | p1, p2 = self.parents(node) | |
1890 | if node != self.hash(text, p1, p2): |
|
1890 | if node != self.hash(text, p1, p2): | |
1891 | # Clear the revision cache on hash failure. The revision cache |
|
1891 | # Clear the revision cache on hash failure. The revision cache | |
1892 | # only stores the raw revision and clearing the cache does have |
|
1892 | # only stores the raw revision and clearing the cache does have | |
1893 | # the side-effect that we won't have a cache hit when the raw |
|
1893 | # the side-effect that we won't have a cache hit when the raw | |
1894 | # revision data is accessed. But this case should be rare and |
|
1894 | # revision data is accessed. But this case should be rare and | |
1895 | # it is extra work to teach the cache about the hash |
|
1895 | # it is extra work to teach the cache about the hash | |
1896 | # verification state. |
|
1896 | # verification state. | |
1897 | if self._revisioncache and self._revisioncache[0] == node: |
|
1897 | if self._revisioncache and self._revisioncache[0] == node: | |
1898 | self._revisioncache = None |
|
1898 | self._revisioncache = None | |
1899 |
|
1899 | |||
1900 | revornode = rev |
|
1900 | revornode = rev | |
1901 | if revornode is None: |
|
1901 | if revornode is None: | |
1902 | revornode = templatefilters.short(hex(node)) |
|
1902 | revornode = templatefilters.short(hex(node)) | |
1903 | raise error.RevlogError( |
|
1903 | raise error.RevlogError( | |
1904 | _(b"integrity check failed on %s:%s") |
|
1904 | _(b"integrity check failed on %s:%s") | |
1905 | % (self.indexfile, pycompat.bytestr(revornode)) |
|
1905 | % (self.indexfile, pycompat.bytestr(revornode)) | |
1906 | ) |
|
1906 | ) | |
1907 | except error.RevlogError: |
|
1907 | except error.RevlogError: | |
1908 | if self._censorable and storageutil.iscensoredtext(text): |
|
1908 | if self._censorable and storageutil.iscensoredtext(text): | |
1909 | raise error.CensoredNodeError(self.indexfile, node, text) |
|
1909 | raise error.CensoredNodeError(self.indexfile, node, text) | |
1910 | raise |
|
1910 | raise | |
1911 |
|
1911 | |||
1912 | def _enforceinlinesize(self, tr, fp=None): |
|
1912 | def _enforceinlinesize(self, tr, fp=None): | |
1913 | """Check if the revlog is too big for inline and convert if so. |
|
1913 | """Check if the revlog is too big for inline and convert if so. | |
1914 |
|
1914 | |||
1915 | This should be called after revisions are added to the revlog. If the |
|
1915 | This should be called after revisions are added to the revlog. If the | |
1916 | revlog has grown too large to be an inline revlog, it will convert it |
|
1916 | revlog has grown too large to be an inline revlog, it will convert it | |
1917 | to use multiple index and data files. |
|
1917 | to use multiple index and data files. | |
1918 | """ |
|
1918 | """ | |
1919 | tiprev = len(self) - 1 |
|
1919 | tiprev = len(self) - 1 | |
1920 | if ( |
|
1920 | if ( | |
1921 | not self._inline |
|
1921 | not self._inline | |
1922 | or (self.start(tiprev) + self.length(tiprev)) < _maxinline |
|
1922 | or (self.start(tiprev) + self.length(tiprev)) < _maxinline | |
1923 | ): |
|
1923 | ): | |
1924 | return |
|
1924 | return | |
1925 |
|
1925 | |||
1926 | troffset = tr.findoffset(self.indexfile) |
|
1926 | troffset = tr.findoffset(self.indexfile) | |
1927 | if troffset is None: |
|
1927 | if troffset is None: | |
1928 | raise error.RevlogError( |
|
1928 | raise error.RevlogError( | |
1929 | _(b"%s not found in the transaction") % self.indexfile |
|
1929 | _(b"%s not found in the transaction") % self.indexfile | |
1930 | ) |
|
1930 | ) | |
1931 | trindex = 0 |
|
1931 | trindex = 0 | |
1932 | tr.add(self.datafile, 0) |
|
1932 | tr.add(self.datafile, 0) | |
1933 |
|
1933 | |||
1934 | if fp: |
|
1934 | if fp: | |
1935 | fp.flush() |
|
1935 | fp.flush() | |
1936 | fp.close() |
|
1936 | fp.close() | |
1937 | # We can't use the cached file handle after close(). So prevent |
|
1937 | # We can't use the cached file handle after close(). So prevent | |
1938 | # its usage. |
|
1938 | # its usage. | |
1939 | self._writinghandles = None |
|
1939 | self._writinghandles = None | |
1940 |
|
1940 | |||
1941 | with self._indexfp(b'r') as ifh, self._datafp(b'w') as dfh: |
|
1941 | with self._indexfp(b'r') as ifh, self._datafp(b'w') as dfh: | |
1942 | for r in self: |
|
1942 | for r in self: | |
1943 | dfh.write(self._getsegmentforrevs(r, r, df=ifh)[1]) |
|
1943 | dfh.write(self._getsegmentforrevs(r, r, df=ifh)[1]) | |
1944 | if troffset <= self.start(r): |
|
1944 | if troffset <= self.start(r): | |
1945 | trindex = r |
|
1945 | trindex = r | |
1946 |
|
1946 | |||
1947 | with self._indexfp(b'w') as fp: |
|
1947 | with self._indexfp(b'w') as fp: | |
1948 | self.version &= ~FLAG_INLINE_DATA |
|
1948 | self.version &= ~FLAG_INLINE_DATA | |
1949 | self._inline = False |
|
1949 | self._inline = False | |
1950 | for i in self: |
|
1950 | for i in self: | |
1951 | e = self.index.entry_binary(i) |
|
1951 | e = self.index.entry_binary(i) | |
1952 | if i == 0: |
|
1952 | if i == 0: | |
1953 | header = self.index.pack_header(self.version) |
|
1953 | header = self.index.pack_header(self.version) | |
1954 | e = header + e |
|
1954 | e = header + e | |
1955 | fp.write(e) |
|
1955 | fp.write(e) | |
1956 |
|
1956 | |||
1957 | # the temp file replace the real index when we exit the context |
|
1957 | # the temp file replace the real index when we exit the context | |
1958 | # manager |
|
1958 | # manager | |
1959 |
|
1959 | |||
1960 | tr.replace(self.indexfile, trindex * self.index.entry_size) |
|
1960 | tr.replace(self.indexfile, trindex * self.index.entry_size) | |
1961 | nodemaputil.setup_persistent_nodemap(tr, self) |
|
1961 | nodemaputil.setup_persistent_nodemap(tr, self) | |
1962 | self._chunkclear() |
|
1962 | self._chunkclear() | |
1963 |
|
1963 | |||
1964 | def _nodeduplicatecallback(self, transaction, node): |
|
1964 | def _nodeduplicatecallback(self, transaction, node): | |
1965 | """called when trying to add a node already stored.""" |
|
1965 | """called when trying to add a node already stored.""" | |
1966 |
|
1966 | |||
1967 | def addrevision( |
|
1967 | def addrevision( | |
1968 | self, |
|
1968 | self, | |
1969 | text, |
|
1969 | text, | |
1970 | transaction, |
|
1970 | transaction, | |
1971 | link, |
|
1971 | link, | |
1972 | p1, |
|
1972 | p1, | |
1973 | p2, |
|
1973 | p2, | |
1974 | cachedelta=None, |
|
1974 | cachedelta=None, | |
1975 | node=None, |
|
1975 | node=None, | |
1976 | flags=REVIDX_DEFAULT_FLAGS, |
|
1976 | flags=REVIDX_DEFAULT_FLAGS, | |
1977 | deltacomputer=None, |
|
1977 | deltacomputer=None, | |
1978 | sidedata=None, |
|
1978 | sidedata=None, | |
1979 | ): |
|
1979 | ): | |
1980 | """add a revision to the log |
|
1980 | """add a revision to the log | |
1981 |
|
1981 | |||
1982 | text - the revision data to add |
|
1982 | text - the revision data to add | |
1983 | transaction - the transaction object used for rollback |
|
1983 | transaction - the transaction object used for rollback | |
1984 | link - the linkrev data to add |
|
1984 | link - the linkrev data to add | |
1985 | p1, p2 - the parent nodeids of the revision |
|
1985 | p1, p2 - the parent nodeids of the revision | |
1986 | cachedelta - an optional precomputed delta |
|
1986 | cachedelta - an optional precomputed delta | |
1987 | node - nodeid of revision; typically node is not specified, and it is |
|
1987 | node - nodeid of revision; typically node is not specified, and it is | |
1988 | computed by default as hash(text, p1, p2), however subclasses might |
|
1988 | computed by default as hash(text, p1, p2), however subclasses might | |
1989 | use different hashing method (and override checkhash() in such case) |
|
1989 | use different hashing method (and override checkhash() in such case) | |
1990 | flags - the known flags to set on the revision |
|
1990 | flags - the known flags to set on the revision | |
1991 | deltacomputer - an optional deltacomputer instance shared between |
|
1991 | deltacomputer - an optional deltacomputer instance shared between | |
1992 | multiple calls |
|
1992 | multiple calls | |
1993 | """ |
|
1993 | """ | |
1994 | if link == nullrev: |
|
1994 | if link == nullrev: | |
1995 | raise error.RevlogError( |
|
1995 | raise error.RevlogError( | |
1996 | _(b"attempted to add linkrev -1 to %s") % self.indexfile |
|
1996 | _(b"attempted to add linkrev -1 to %s") % self.indexfile | |
1997 | ) |
|
1997 | ) | |
1998 |
|
1998 | |||
1999 | if sidedata is None: |
|
1999 | if sidedata is None: | |
2000 | sidedata = {} |
|
2000 | sidedata = {} | |
2001 | elif not self.hassidedata: |
|
2001 | elif not self.hassidedata: | |
2002 | raise error.ProgrammingError( |
|
2002 | raise error.ProgrammingError( | |
2003 | _(b"trying to add sidedata to a revlog who don't support them") |
|
2003 | _(b"trying to add sidedata to a revlog who don't support them") | |
2004 | ) |
|
2004 | ) | |
2005 |
|
2005 | |||
2006 | if flags: |
|
2006 | if flags: | |
2007 | node = node or self.hash(text, p1, p2) |
|
2007 | node = node or self.hash(text, p1, p2) | |
2008 |
|
2008 | |||
2009 | rawtext, validatehash = flagutil.processflagswrite(self, text, flags) |
|
2009 | rawtext, validatehash = flagutil.processflagswrite(self, text, flags) | |
2010 |
|
2010 | |||
2011 | # If the flag processor modifies the revision data, ignore any provided |
|
2011 | # If the flag processor modifies the revision data, ignore any provided | |
2012 | # cachedelta. |
|
2012 | # cachedelta. | |
2013 | if rawtext != text: |
|
2013 | if rawtext != text: | |
2014 | cachedelta = None |
|
2014 | cachedelta = None | |
2015 |
|
2015 | |||
2016 | if len(rawtext) > _maxentrysize: |
|
2016 | if len(rawtext) > _maxentrysize: | |
2017 | raise error.RevlogError( |
|
2017 | raise error.RevlogError( | |
2018 | _( |
|
2018 | _( | |
2019 | b"%s: size of %d bytes exceeds maximum revlog storage of 2GiB" |
|
2019 | b"%s: size of %d bytes exceeds maximum revlog storage of 2GiB" | |
2020 | ) |
|
2020 | ) | |
2021 | % (self.indexfile, len(rawtext)) |
|
2021 | % (self.indexfile, len(rawtext)) | |
2022 | ) |
|
2022 | ) | |
2023 |
|
2023 | |||
2024 | node = node or self.hash(rawtext, p1, p2) |
|
2024 | node = node or self.hash(rawtext, p1, p2) | |
2025 | rev = self.index.get_rev(node) |
|
2025 | rev = self.index.get_rev(node) | |
2026 | if rev is not None: |
|
2026 | if rev is not None: | |
2027 | return rev |
|
2027 | return rev | |
2028 |
|
2028 | |||
2029 | if validatehash: |
|
2029 | if validatehash: | |
2030 | self.checkhash(rawtext, node, p1=p1, p2=p2) |
|
2030 | self.checkhash(rawtext, node, p1=p1, p2=p2) | |
2031 |
|
2031 | |||
2032 | return self.addrawrevision( |
|
2032 | return self.addrawrevision( | |
2033 | rawtext, |
|
2033 | rawtext, | |
2034 | transaction, |
|
2034 | transaction, | |
2035 | link, |
|
2035 | link, | |
2036 | p1, |
|
2036 | p1, | |
2037 | p2, |
|
2037 | p2, | |
2038 | node, |
|
2038 | node, | |
2039 | flags, |
|
2039 | flags, | |
2040 | cachedelta=cachedelta, |
|
2040 | cachedelta=cachedelta, | |
2041 | deltacomputer=deltacomputer, |
|
2041 | deltacomputer=deltacomputer, | |
2042 | sidedata=sidedata, |
|
2042 | sidedata=sidedata, | |
2043 | ) |
|
2043 | ) | |
2044 |
|
2044 | |||
2045 | def addrawrevision( |
|
2045 | def addrawrevision( | |
2046 | self, |
|
2046 | self, | |
2047 | rawtext, |
|
2047 | rawtext, | |
2048 | transaction, |
|
2048 | transaction, | |
2049 | link, |
|
2049 | link, | |
2050 | p1, |
|
2050 | p1, | |
2051 | p2, |
|
2051 | p2, | |
2052 | node, |
|
2052 | node, | |
2053 | flags, |
|
2053 | flags, | |
2054 | cachedelta=None, |
|
2054 | cachedelta=None, | |
2055 | deltacomputer=None, |
|
2055 | deltacomputer=None, | |
2056 | sidedata=None, |
|
2056 | sidedata=None, | |
2057 | ): |
|
2057 | ): | |
2058 | """add a raw revision with known flags, node and parents |
|
2058 | """add a raw revision with known flags, node and parents | |
2059 | useful when reusing a revision not stored in this revlog (ex: received |
|
2059 | useful when reusing a revision not stored in this revlog (ex: received | |
2060 | over wire, or read from an external bundle). |
|
2060 | over wire, or read from an external bundle). | |
2061 | """ |
|
2061 | """ | |
2062 | dfh = None |
|
2062 | dfh = None | |
2063 | if not self._inline: |
|
2063 | if not self._inline: | |
2064 | dfh = self._datafp(b"a+") |
|
2064 | dfh = self._datafp(b"a+") | |
2065 | ifh = self._indexfp(b"a+") |
|
2065 | ifh = self._indexfp(b"a+") | |
2066 | try: |
|
2066 | try: | |
2067 | return self._addrevision( |
|
2067 | return self._addrevision( | |
2068 | node, |
|
2068 | node, | |
2069 | rawtext, |
|
2069 | rawtext, | |
2070 | transaction, |
|
2070 | transaction, | |
2071 | link, |
|
2071 | link, | |
2072 | p1, |
|
2072 | p1, | |
2073 | p2, |
|
2073 | p2, | |
2074 | flags, |
|
2074 | flags, | |
2075 | cachedelta, |
|
2075 | cachedelta, | |
2076 | ifh, |
|
2076 | ifh, | |
2077 | dfh, |
|
2077 | dfh, | |
2078 | deltacomputer=deltacomputer, |
|
2078 | deltacomputer=deltacomputer, | |
2079 | sidedata=sidedata, |
|
2079 | sidedata=sidedata, | |
2080 | ) |
|
2080 | ) | |
2081 | finally: |
|
2081 | finally: | |
2082 | if dfh: |
|
2082 | if dfh: | |
2083 | dfh.close() |
|
2083 | dfh.close() | |
2084 | ifh.close() |
|
2084 | ifh.close() | |
2085 |
|
2085 | |||
2086 | def compress(self, data): |
|
2086 | def compress(self, data): | |
2087 | """Generate a possibly-compressed representation of data.""" |
|
2087 | """Generate a possibly-compressed representation of data.""" | |
2088 | if not data: |
|
2088 | if not data: | |
2089 | return b'', data |
|
2089 | return b'', data | |
2090 |
|
2090 | |||
2091 | compressed = self._compressor.compress(data) |
|
2091 | compressed = self._compressor.compress(data) | |
2092 |
|
2092 | |||
2093 | if compressed: |
|
2093 | if compressed: | |
2094 | # The revlog compressor added the header in the returned data. |
|
2094 | # The revlog compressor added the header in the returned data. | |
2095 | return b'', compressed |
|
2095 | return b'', compressed | |
2096 |
|
2096 | |||
2097 | if data[0:1] == b'\0': |
|
2097 | if data[0:1] == b'\0': | |
2098 | return b'', data |
|
2098 | return b'', data | |
2099 | return b'u', data |
|
2099 | return b'u', data | |
2100 |
|
2100 | |||
2101 | def decompress(self, data): |
|
2101 | def decompress(self, data): | |
2102 | """Decompress a revlog chunk. |
|
2102 | """Decompress a revlog chunk. | |
2103 |
|
2103 | |||
2104 | The chunk is expected to begin with a header identifying the |
|
2104 | The chunk is expected to begin with a header identifying the | |
2105 | format type so it can be routed to an appropriate decompressor. |
|
2105 | format type so it can be routed to an appropriate decompressor. | |
2106 | """ |
|
2106 | """ | |
2107 | if not data: |
|
2107 | if not data: | |
2108 | return data |
|
2108 | return data | |
2109 |
|
2109 | |||
2110 | # Revlogs are read much more frequently than they are written and many |
|
2110 | # Revlogs are read much more frequently than they are written and many | |
2111 | # chunks only take microseconds to decompress, so performance is |
|
2111 | # chunks only take microseconds to decompress, so performance is | |
2112 | # important here. |
|
2112 | # important here. | |
2113 | # |
|
2113 | # | |
2114 | # We can make a few assumptions about revlogs: |
|
2114 | # We can make a few assumptions about revlogs: | |
2115 | # |
|
2115 | # | |
2116 | # 1) the majority of chunks will be compressed (as opposed to inline |
|
2116 | # 1) the majority of chunks will be compressed (as opposed to inline | |
2117 | # raw data). |
|
2117 | # raw data). | |
2118 | # 2) decompressing *any* data will likely by at least 10x slower than |
|
2118 | # 2) decompressing *any* data will likely by at least 10x slower than | |
2119 | # returning raw inline data. |
|
2119 | # returning raw inline data. | |
2120 | # 3) we want to prioritize common and officially supported compression |
|
2120 | # 3) we want to prioritize common and officially supported compression | |
2121 | # engines |
|
2121 | # engines | |
2122 | # |
|
2122 | # | |
2123 | # It follows that we want to optimize for "decompress compressed data |
|
2123 | # It follows that we want to optimize for "decompress compressed data | |
2124 | # when encoded with common and officially supported compression engines" |
|
2124 | # when encoded with common and officially supported compression engines" | |
2125 | # case over "raw data" and "data encoded by less common or non-official |
|
2125 | # case over "raw data" and "data encoded by less common or non-official | |
2126 | # compression engines." That is why we have the inline lookup first |
|
2126 | # compression engines." That is why we have the inline lookup first | |
2127 | # followed by the compengines lookup. |
|
2127 | # followed by the compengines lookup. | |
2128 | # |
|
2128 | # | |
2129 | # According to `hg perfrevlogchunks`, this is ~0.5% faster for zlib |
|
2129 | # According to `hg perfrevlogchunks`, this is ~0.5% faster for zlib | |
2130 | # compressed chunks. And this matters for changelog and manifest reads. |
|
2130 | # compressed chunks. And this matters for changelog and manifest reads. | |
2131 | t = data[0:1] |
|
2131 | t = data[0:1] | |
2132 |
|
2132 | |||
2133 | if t == b'x': |
|
2133 | if t == b'x': | |
2134 | try: |
|
2134 | try: | |
2135 | return _zlibdecompress(data) |
|
2135 | return _zlibdecompress(data) | |
2136 | except zlib.error as e: |
|
2136 | except zlib.error as e: | |
2137 | raise error.RevlogError( |
|
2137 | raise error.RevlogError( | |
2138 | _(b'revlog decompress error: %s') |
|
2138 | _(b'revlog decompress error: %s') | |
2139 | % stringutil.forcebytestr(e) |
|
2139 | % stringutil.forcebytestr(e) | |
2140 | ) |
|
2140 | ) | |
2141 | # '\0' is more common than 'u' so it goes first. |
|
2141 | # '\0' is more common than 'u' so it goes first. | |
2142 | elif t == b'\0': |
|
2142 | elif t == b'\0': | |
2143 | return data |
|
2143 | return data | |
2144 | elif t == b'u': |
|
2144 | elif t == b'u': | |
2145 | return util.buffer(data, 1) |
|
2145 | return util.buffer(data, 1) | |
2146 |
|
2146 | |||
2147 | try: |
|
2147 | try: | |
2148 | compressor = self._decompressors[t] |
|
2148 | compressor = self._decompressors[t] | |
2149 | except KeyError: |
|
2149 | except KeyError: | |
2150 | try: |
|
2150 | try: | |
2151 | engine = util.compengines.forrevlogheader(t) |
|
2151 | engine = util.compengines.forrevlogheader(t) | |
2152 | compressor = engine.revlogcompressor(self._compengineopts) |
|
2152 | compressor = engine.revlogcompressor(self._compengineopts) | |
2153 | self._decompressors[t] = compressor |
|
2153 | self._decompressors[t] = compressor | |
2154 | except KeyError: |
|
2154 | except KeyError: | |
2155 | raise error.RevlogError( |
|
2155 | raise error.RevlogError( | |
2156 | _(b'unknown compression type %s') % binascii.hexlify(t) |
|
2156 | _(b'unknown compression type %s') % binascii.hexlify(t) | |
2157 | ) |
|
2157 | ) | |
2158 |
|
2158 | |||
2159 | return compressor.decompress(data) |
|
2159 | return compressor.decompress(data) | |
2160 |
|
2160 | |||
2161 | def _addrevision( |
|
2161 | def _addrevision( | |
2162 | self, |
|
2162 | self, | |
2163 | node, |
|
2163 | node, | |
2164 | rawtext, |
|
2164 | rawtext, | |
2165 | transaction, |
|
2165 | transaction, | |
2166 | link, |
|
2166 | link, | |
2167 | p1, |
|
2167 | p1, | |
2168 | p2, |
|
2168 | p2, | |
2169 | flags, |
|
2169 | flags, | |
2170 | cachedelta, |
|
2170 | cachedelta, | |
2171 | ifh, |
|
2171 | ifh, | |
2172 | dfh, |
|
2172 | dfh, | |
2173 | alwayscache=False, |
|
2173 | alwayscache=False, | |
2174 | deltacomputer=None, |
|
2174 | deltacomputer=None, | |
2175 | sidedata=None, |
|
2175 | sidedata=None, | |
2176 | ): |
|
2176 | ): | |
2177 | """internal function to add revisions to the log |
|
2177 | """internal function to add revisions to the log | |
2178 |
|
2178 | |||
2179 | see addrevision for argument descriptions. |
|
2179 | see addrevision for argument descriptions. | |
2180 |
|
2180 | |||
2181 | note: "addrevision" takes non-raw text, "_addrevision" takes raw text. |
|
2181 | note: "addrevision" takes non-raw text, "_addrevision" takes raw text. | |
2182 |
|
2182 | |||
2183 | if "deltacomputer" is not provided or None, a defaultdeltacomputer will |
|
2183 | if "deltacomputer" is not provided or None, a defaultdeltacomputer will | |
2184 | be used. |
|
2184 | be used. | |
2185 |
|
2185 | |||
2186 | invariants: |
|
2186 | invariants: | |
2187 | - rawtext is optional (can be None); if not set, cachedelta must be set. |
|
2187 | - rawtext is optional (can be None); if not set, cachedelta must be set. | |
2188 | if both are set, they must correspond to each other. |
|
2188 | if both are set, they must correspond to each other. | |
2189 | """ |
|
2189 | """ | |
2190 | if node == self.nullid: |
|
2190 | if node == self.nullid: | |
2191 | raise error.RevlogError( |
|
2191 | raise error.RevlogError( | |
2192 | _(b"%s: attempt to add null revision") % self.indexfile |
|
2192 | _(b"%s: attempt to add null revision") % self.indexfile | |
2193 | ) |
|
2193 | ) | |
2194 | if ( |
|
2194 | if ( | |
2195 | node == self.nodeconstants.wdirid |
|
2195 | node == self.nodeconstants.wdirid | |
2196 | or node in self.nodeconstants.wdirfilenodeids |
|
2196 | or node in self.nodeconstants.wdirfilenodeids | |
2197 | ): |
|
2197 | ): | |
2198 | raise error.RevlogError( |
|
2198 | raise error.RevlogError( | |
2199 | _(b"%s: attempt to add wdir revision") % self.indexfile |
|
2199 | _(b"%s: attempt to add wdir revision") % self.indexfile | |
2200 | ) |
|
2200 | ) | |
2201 |
|
2201 | |||
2202 | if self._inline: |
|
2202 | if self._inline: | |
2203 | fh = ifh |
|
2203 | fh = ifh | |
2204 | else: |
|
2204 | else: | |
2205 | fh = dfh |
|
2205 | fh = dfh | |
2206 |
|
2206 | |||
2207 | btext = [rawtext] |
|
2207 | btext = [rawtext] | |
2208 |
|
2208 | |||
2209 | curr = len(self) |
|
2209 | curr = len(self) | |
2210 | prev = curr - 1 |
|
2210 | prev = curr - 1 | |
2211 |
|
2211 | |||
2212 | offset = self._get_data_offset(prev) |
|
2212 | offset = self._get_data_offset(prev) | |
2213 |
|
2213 | |||
2214 | if self._concurrencychecker: |
|
2214 | if self._concurrencychecker: | |
2215 | if self._inline: |
|
2215 | if self._inline: | |
2216 | # offset is "as if" it were in the .d file, so we need to add on |
|
2216 | # offset is "as if" it were in the .d file, so we need to add on | |
2217 | # the size of the entry metadata. |
|
2217 | # the size of the entry metadata. | |
2218 | self._concurrencychecker( |
|
2218 | self._concurrencychecker( | |
2219 | ifh, self.indexfile, offset + curr * self.index.entry_size |
|
2219 | ifh, self.indexfile, offset + curr * self.index.entry_size | |
2220 | ) |
|
2220 | ) | |
2221 | else: |
|
2221 | else: | |
2222 | # Entries in the .i are a consistent size. |
|
2222 | # Entries in the .i are a consistent size. | |
2223 | self._concurrencychecker( |
|
2223 | self._concurrencychecker( | |
2224 | ifh, self.indexfile, curr * self.index.entry_size |
|
2224 | ifh, self.indexfile, curr * self.index.entry_size | |
2225 | ) |
|
2225 | ) | |
2226 | self._concurrencychecker(dfh, self.datafile, offset) |
|
2226 | self._concurrencychecker(dfh, self.datafile, offset) | |
2227 |
|
2227 | |||
2228 | p1r, p2r = self.rev(p1), self.rev(p2) |
|
2228 | p1r, p2r = self.rev(p1), self.rev(p2) | |
2229 |
|
2229 | |||
2230 | # full versions are inserted when the needed deltas |
|
2230 | # full versions are inserted when the needed deltas | |
2231 | # become comparable to the uncompressed text |
|
2231 | # become comparable to the uncompressed text | |
2232 | if rawtext is None: |
|
2232 | if rawtext is None: | |
2233 | # need rawtext size, before changed by flag processors, which is |
|
2233 | # need rawtext size, before changed by flag processors, which is | |
2234 | # the non-raw size. use revlog explicitly to avoid filelog's extra |
|
2234 | # the non-raw size. use revlog explicitly to avoid filelog's extra | |
2235 | # logic that might remove metadata size. |
|
2235 | # logic that might remove metadata size. | |
2236 | textlen = mdiff.patchedsize( |
|
2236 | textlen = mdiff.patchedsize( | |
2237 | revlog.size(self, cachedelta[0]), cachedelta[1] |
|
2237 | revlog.size(self, cachedelta[0]), cachedelta[1] | |
2238 | ) |
|
2238 | ) | |
2239 | else: |
|
2239 | else: | |
2240 | textlen = len(rawtext) |
|
2240 | textlen = len(rawtext) | |
2241 |
|
2241 | |||
2242 | if deltacomputer is None: |
|
2242 | if deltacomputer is None: | |
2243 | deltacomputer = deltautil.deltacomputer(self) |
|
2243 | deltacomputer = deltautil.deltacomputer(self) | |
2244 |
|
2244 | |||
2245 | revinfo = _revisioninfo(node, p1, p2, btext, textlen, cachedelta, flags) |
|
2245 | revinfo = _revisioninfo(node, p1, p2, btext, textlen, cachedelta, flags) | |
2246 |
|
2246 | |||
2247 | deltainfo = deltacomputer.finddeltainfo(revinfo, fh) |
|
2247 | deltainfo = deltacomputer.finddeltainfo(revinfo, fh) | |
2248 |
|
2248 | |||
2249 | if sidedata: |
|
2249 | if sidedata and self.version & 0xFFFF == REVLOGV2: | |
2250 | serialized_sidedata = sidedatautil.serialize_sidedata(sidedata) |
|
2250 | serialized_sidedata = sidedatautil.serialize_sidedata(sidedata) | |
2251 | sidedata_offset = offset + deltainfo.deltalen |
|
2251 | sidedata_offset = offset + deltainfo.deltalen | |
2252 | else: |
|
2252 | else: | |
2253 | serialized_sidedata = b"" |
|
2253 | serialized_sidedata = b"" | |
2254 | # Don't store the offset if the sidedata is empty, that way |
|
2254 | # Don't store the offset if the sidedata is empty, that way | |
2255 | # we can easily detect empty sidedata and they will be no different |
|
2255 | # we can easily detect empty sidedata and they will be no different | |
2256 | # than ones we manually add. |
|
2256 | # than ones we manually add. | |
2257 | sidedata_offset = 0 |
|
2257 | sidedata_offset = 0 | |
2258 |
|
2258 | |||
2259 | e = ( |
|
2259 | e = ( | |
2260 | offset_type(offset, flags), |
|
2260 | offset_type(offset, flags), | |
2261 | deltainfo.deltalen, |
|
2261 | deltainfo.deltalen, | |
2262 | textlen, |
|
2262 | textlen, | |
2263 | deltainfo.base, |
|
2263 | deltainfo.base, | |
2264 | link, |
|
2264 | link, | |
2265 | p1r, |
|
2265 | p1r, | |
2266 | p2r, |
|
2266 | p2r, | |
2267 | node, |
|
2267 | node, | |
2268 | sidedata_offset, |
|
2268 | sidedata_offset, | |
2269 | len(serialized_sidedata), |
|
2269 | len(serialized_sidedata), | |
2270 | ) |
|
2270 | ) | |
2271 |
|
2271 | |||
2272 | if self.version & 0xFFFF != REVLOGV2: |
|
2272 | if self.version & 0xFFFF != REVLOGV2: | |
2273 | e = e[:8] |
|
2273 | e = e[:8] | |
2274 |
|
2274 | |||
2275 | self.index.append(e) |
|
2275 | self.index.append(e) | |
2276 | entry = self.index.entry_binary(curr) |
|
2276 | entry = self.index.entry_binary(curr) | |
2277 | if curr == 0: |
|
2277 | if curr == 0: | |
2278 | header = self.index.pack_header(self.version) |
|
2278 | header = self.index.pack_header(self.version) | |
2279 | entry = header + entry |
|
2279 | entry = header + entry | |
2280 | self._writeentry( |
|
2280 | self._writeentry( | |
2281 | transaction, |
|
2281 | transaction, | |
2282 | ifh, |
|
2282 | ifh, | |
2283 | dfh, |
|
2283 | dfh, | |
2284 | entry, |
|
2284 | entry, | |
2285 | deltainfo.data, |
|
2285 | deltainfo.data, | |
2286 | link, |
|
2286 | link, | |
2287 | offset, |
|
2287 | offset, | |
2288 | serialized_sidedata, |
|
2288 | serialized_sidedata, | |
2289 | ) |
|
2289 | ) | |
2290 |
|
2290 | |||
2291 | rawtext = btext[0] |
|
2291 | rawtext = btext[0] | |
2292 |
|
2292 | |||
2293 | if alwayscache and rawtext is None: |
|
2293 | if alwayscache and rawtext is None: | |
2294 | rawtext = deltacomputer.buildtext(revinfo, fh) |
|
2294 | rawtext = deltacomputer.buildtext(revinfo, fh) | |
2295 |
|
2295 | |||
2296 | if type(rawtext) == bytes: # only accept immutable objects |
|
2296 | if type(rawtext) == bytes: # only accept immutable objects | |
2297 | self._revisioncache = (node, curr, rawtext) |
|
2297 | self._revisioncache = (node, curr, rawtext) | |
2298 | self._chainbasecache[curr] = deltainfo.chainbase |
|
2298 | self._chainbasecache[curr] = deltainfo.chainbase | |
2299 | return curr |
|
2299 | return curr | |
2300 |
|
2300 | |||
2301 | def _get_data_offset(self, prev): |
|
2301 | def _get_data_offset(self, prev): | |
2302 | """Returns the current offset in the (in-transaction) data file. |
|
2302 | """Returns the current offset in the (in-transaction) data file. | |
2303 | Versions < 2 of the revlog can get this 0(1), revlog v2 needs a docket |
|
2303 | Versions < 2 of the revlog can get this 0(1), revlog v2 needs a docket | |
2304 | file to store that information: since sidedata can be rewritten to the |
|
2304 | file to store that information: since sidedata can be rewritten to the | |
2305 | end of the data file within a transaction, you can have cases where, for |
|
2305 | end of the data file within a transaction, you can have cases where, for | |
2306 | example, rev `n` does not have sidedata while rev `n - 1` does, leading |
|
2306 | example, rev `n` does not have sidedata while rev `n - 1` does, leading | |
2307 | to `n - 1`'s sidedata being written after `n`'s data. |
|
2307 | to `n - 1`'s sidedata being written after `n`'s data. | |
2308 |
|
2308 | |||
2309 | TODO cache this in a docket file before getting out of experimental.""" |
|
2309 | TODO cache this in a docket file before getting out of experimental.""" | |
2310 | if self.version & 0xFFFF != REVLOGV2: |
|
2310 | if self.version & 0xFFFF != REVLOGV2: | |
2311 | return self.end(prev) |
|
2311 | return self.end(prev) | |
2312 |
|
2312 | |||
2313 | offset = 0 |
|
2313 | offset = 0 | |
2314 | for rev, entry in enumerate(self.index): |
|
2314 | for rev, entry in enumerate(self.index): | |
2315 | sidedata_end = entry[8] + entry[9] |
|
2315 | sidedata_end = entry[8] + entry[9] | |
2316 | # Sidedata for a previous rev has potentially been written after |
|
2316 | # Sidedata for a previous rev has potentially been written after | |
2317 | # this rev's end, so take the max. |
|
2317 | # this rev's end, so take the max. | |
2318 | offset = max(self.end(rev), offset, sidedata_end) |
|
2318 | offset = max(self.end(rev), offset, sidedata_end) | |
2319 | return offset |
|
2319 | return offset | |
2320 |
|
2320 | |||
2321 | def _writeentry( |
|
2321 | def _writeentry( | |
2322 | self, transaction, ifh, dfh, entry, data, link, offset, sidedata |
|
2322 | self, transaction, ifh, dfh, entry, data, link, offset, sidedata | |
2323 | ): |
|
2323 | ): | |
2324 | # Files opened in a+ mode have inconsistent behavior on various |
|
2324 | # Files opened in a+ mode have inconsistent behavior on various | |
2325 | # platforms. Windows requires that a file positioning call be made |
|
2325 | # platforms. Windows requires that a file positioning call be made | |
2326 | # when the file handle transitions between reads and writes. See |
|
2326 | # when the file handle transitions between reads and writes. See | |
2327 | # 3686fa2b8eee and the mixedfilemodewrapper in windows.py. On other |
|
2327 | # 3686fa2b8eee and the mixedfilemodewrapper in windows.py. On other | |
2328 | # platforms, Python or the platform itself can be buggy. Some versions |
|
2328 | # platforms, Python or the platform itself can be buggy. Some versions | |
2329 | # of Solaris have been observed to not append at the end of the file |
|
2329 | # of Solaris have been observed to not append at the end of the file | |
2330 | # if the file was seeked to before the end. See issue4943 for more. |
|
2330 | # if the file was seeked to before the end. See issue4943 for more. | |
2331 | # |
|
2331 | # | |
2332 | # We work around this issue by inserting a seek() before writing. |
|
2332 | # We work around this issue by inserting a seek() before writing. | |
2333 | # Note: This is likely not necessary on Python 3. However, because |
|
2333 | # Note: This is likely not necessary on Python 3. However, because | |
2334 | # the file handle is reused for reads and may be seeked there, we need |
|
2334 | # the file handle is reused for reads and may be seeked there, we need | |
2335 | # to be careful before changing this. |
|
2335 | # to be careful before changing this. | |
2336 | ifh.seek(0, os.SEEK_END) |
|
2336 | ifh.seek(0, os.SEEK_END) | |
2337 | if dfh: |
|
2337 | if dfh: | |
2338 | dfh.seek(0, os.SEEK_END) |
|
2338 | dfh.seek(0, os.SEEK_END) | |
2339 |
|
2339 | |||
2340 | curr = len(self) - 1 |
|
2340 | curr = len(self) - 1 | |
2341 | if not self._inline: |
|
2341 | if not self._inline: | |
2342 | transaction.add(self.datafile, offset) |
|
2342 | transaction.add(self.datafile, offset) | |
2343 | transaction.add(self.indexfile, curr * len(entry)) |
|
2343 | transaction.add(self.indexfile, curr * len(entry)) | |
2344 | if data[0]: |
|
2344 | if data[0]: | |
2345 | dfh.write(data[0]) |
|
2345 | dfh.write(data[0]) | |
2346 | dfh.write(data[1]) |
|
2346 | dfh.write(data[1]) | |
2347 | if sidedata: |
|
2347 | if sidedata: | |
2348 | dfh.write(sidedata) |
|
2348 | dfh.write(sidedata) | |
2349 | ifh.write(entry) |
|
2349 | ifh.write(entry) | |
2350 | else: |
|
2350 | else: | |
2351 | offset += curr * self.index.entry_size |
|
2351 | offset += curr * self.index.entry_size | |
2352 | transaction.add(self.indexfile, offset) |
|
2352 | transaction.add(self.indexfile, offset) | |
2353 | ifh.write(entry) |
|
2353 | ifh.write(entry) | |
2354 | ifh.write(data[0]) |
|
2354 | ifh.write(data[0]) | |
2355 | ifh.write(data[1]) |
|
2355 | ifh.write(data[1]) | |
2356 | if sidedata: |
|
2356 | if sidedata: | |
2357 | ifh.write(sidedata) |
|
2357 | ifh.write(sidedata) | |
2358 | self._enforceinlinesize(transaction, ifh) |
|
2358 | self._enforceinlinesize(transaction, ifh) | |
2359 | nodemaputil.setup_persistent_nodemap(transaction, self) |
|
2359 | nodemaputil.setup_persistent_nodemap(transaction, self) | |
2360 |
|
2360 | |||
2361 | def addgroup( |
|
2361 | def addgroup( | |
2362 | self, |
|
2362 | self, | |
2363 | deltas, |
|
2363 | deltas, | |
2364 | linkmapper, |
|
2364 | linkmapper, | |
2365 | transaction, |
|
2365 | transaction, | |
2366 | alwayscache=False, |
|
2366 | alwayscache=False, | |
2367 | addrevisioncb=None, |
|
2367 | addrevisioncb=None, | |
2368 | duplicaterevisioncb=None, |
|
2368 | duplicaterevisioncb=None, | |
2369 | ): |
|
2369 | ): | |
2370 | """ |
|
2370 | """ | |
2371 | add a delta group |
|
2371 | add a delta group | |
2372 |
|
2372 | |||
2373 | given a set of deltas, add them to the revision log. the |
|
2373 | given a set of deltas, add them to the revision log. the | |
2374 | first delta is against its parent, which should be in our |
|
2374 | first delta is against its parent, which should be in our | |
2375 | log, the rest are against the previous delta. |
|
2375 | log, the rest are against the previous delta. | |
2376 |
|
2376 | |||
2377 | If ``addrevisioncb`` is defined, it will be called with arguments of |
|
2377 | If ``addrevisioncb`` is defined, it will be called with arguments of | |
2378 | this revlog and the node that was added. |
|
2378 | this revlog and the node that was added. | |
2379 | """ |
|
2379 | """ | |
2380 |
|
2380 | |||
2381 | if self._writinghandles: |
|
2381 | if self._writinghandles: | |
2382 | raise error.ProgrammingError(b'cannot nest addgroup() calls') |
|
2382 | raise error.ProgrammingError(b'cannot nest addgroup() calls') | |
2383 |
|
2383 | |||
2384 | r = len(self) |
|
2384 | r = len(self) | |
2385 | end = 0 |
|
2385 | end = 0 | |
2386 | if r: |
|
2386 | if r: | |
2387 | end = self.end(r - 1) |
|
2387 | end = self.end(r - 1) | |
2388 | ifh = self._indexfp(b"a+") |
|
2388 | ifh = self._indexfp(b"a+") | |
2389 | isize = r * self.index.entry_size |
|
2389 | isize = r * self.index.entry_size | |
2390 | if self._inline: |
|
2390 | if self._inline: | |
2391 | transaction.add(self.indexfile, end + isize) |
|
2391 | transaction.add(self.indexfile, end + isize) | |
2392 | dfh = None |
|
2392 | dfh = None | |
2393 | else: |
|
2393 | else: | |
2394 | transaction.add(self.indexfile, isize) |
|
2394 | transaction.add(self.indexfile, isize) | |
2395 | transaction.add(self.datafile, end) |
|
2395 | transaction.add(self.datafile, end) | |
2396 | dfh = self._datafp(b"a+") |
|
2396 | dfh = self._datafp(b"a+") | |
2397 |
|
2397 | |||
2398 | def flush(): |
|
2398 | def flush(): | |
2399 | if dfh: |
|
2399 | if dfh: | |
2400 | dfh.flush() |
|
2400 | dfh.flush() | |
2401 | ifh.flush() |
|
2401 | ifh.flush() | |
2402 |
|
2402 | |||
2403 | self._writinghandles = (ifh, dfh) |
|
2403 | self._writinghandles = (ifh, dfh) | |
2404 | empty = True |
|
2404 | empty = True | |
2405 |
|
2405 | |||
2406 | try: |
|
2406 | try: | |
2407 | deltacomputer = deltautil.deltacomputer(self) |
|
2407 | deltacomputer = deltautil.deltacomputer(self) | |
2408 | # loop through our set of deltas |
|
2408 | # loop through our set of deltas | |
2409 | for data in deltas: |
|
2409 | for data in deltas: | |
2410 | node, p1, p2, linknode, deltabase, delta, flags, sidedata = data |
|
2410 | node, p1, p2, linknode, deltabase, delta, flags, sidedata = data | |
2411 | link = linkmapper(linknode) |
|
2411 | link = linkmapper(linknode) | |
2412 | flags = flags or REVIDX_DEFAULT_FLAGS |
|
2412 | flags = flags or REVIDX_DEFAULT_FLAGS | |
2413 |
|
2413 | |||
2414 | rev = self.index.get_rev(node) |
|
2414 | rev = self.index.get_rev(node) | |
2415 | if rev is not None: |
|
2415 | if rev is not None: | |
2416 | # this can happen if two branches make the same change |
|
2416 | # this can happen if two branches make the same change | |
2417 | self._nodeduplicatecallback(transaction, rev) |
|
2417 | self._nodeduplicatecallback(transaction, rev) | |
2418 | if duplicaterevisioncb: |
|
2418 | if duplicaterevisioncb: | |
2419 | duplicaterevisioncb(self, rev) |
|
2419 | duplicaterevisioncb(self, rev) | |
2420 | empty = False |
|
2420 | empty = False | |
2421 | continue |
|
2421 | continue | |
2422 |
|
2422 | |||
2423 | for p in (p1, p2): |
|
2423 | for p in (p1, p2): | |
2424 | if not self.index.has_node(p): |
|
2424 | if not self.index.has_node(p): | |
2425 | raise error.LookupError( |
|
2425 | raise error.LookupError( | |
2426 | p, self.indexfile, _(b'unknown parent') |
|
2426 | p, self.indexfile, _(b'unknown parent') | |
2427 | ) |
|
2427 | ) | |
2428 |
|
2428 | |||
2429 | if not self.index.has_node(deltabase): |
|
2429 | if not self.index.has_node(deltabase): | |
2430 | raise error.LookupError( |
|
2430 | raise error.LookupError( | |
2431 | deltabase, self.indexfile, _(b'unknown delta base') |
|
2431 | deltabase, self.indexfile, _(b'unknown delta base') | |
2432 | ) |
|
2432 | ) | |
2433 |
|
2433 | |||
2434 | baserev = self.rev(deltabase) |
|
2434 | baserev = self.rev(deltabase) | |
2435 |
|
2435 | |||
2436 | if baserev != nullrev and self.iscensored(baserev): |
|
2436 | if baserev != nullrev and self.iscensored(baserev): | |
2437 | # if base is censored, delta must be full replacement in a |
|
2437 | # if base is censored, delta must be full replacement in a | |
2438 | # single patch operation |
|
2438 | # single patch operation | |
2439 | hlen = struct.calcsize(b">lll") |
|
2439 | hlen = struct.calcsize(b">lll") | |
2440 | oldlen = self.rawsize(baserev) |
|
2440 | oldlen = self.rawsize(baserev) | |
2441 | newlen = len(delta) - hlen |
|
2441 | newlen = len(delta) - hlen | |
2442 | if delta[:hlen] != mdiff.replacediffheader(oldlen, newlen): |
|
2442 | if delta[:hlen] != mdiff.replacediffheader(oldlen, newlen): | |
2443 | raise error.CensoredBaseError( |
|
2443 | raise error.CensoredBaseError( | |
2444 | self.indexfile, self.node(baserev) |
|
2444 | self.indexfile, self.node(baserev) | |
2445 | ) |
|
2445 | ) | |
2446 |
|
2446 | |||
2447 | if not flags and self._peek_iscensored(baserev, delta, flush): |
|
2447 | if not flags and self._peek_iscensored(baserev, delta, flush): | |
2448 | flags |= REVIDX_ISCENSORED |
|
2448 | flags |= REVIDX_ISCENSORED | |
2449 |
|
2449 | |||
2450 | # We assume consumers of addrevisioncb will want to retrieve |
|
2450 | # We assume consumers of addrevisioncb will want to retrieve | |
2451 | # the added revision, which will require a call to |
|
2451 | # the added revision, which will require a call to | |
2452 | # revision(). revision() will fast path if there is a cache |
|
2452 | # revision(). revision() will fast path if there is a cache | |
2453 | # hit. So, we tell _addrevision() to always cache in this case. |
|
2453 | # hit. So, we tell _addrevision() to always cache in this case. | |
2454 | # We're only using addgroup() in the context of changegroup |
|
2454 | # We're only using addgroup() in the context of changegroup | |
2455 | # generation so the revision data can always be handled as raw |
|
2455 | # generation so the revision data can always be handled as raw | |
2456 | # by the flagprocessor. |
|
2456 | # by the flagprocessor. | |
2457 | rev = self._addrevision( |
|
2457 | rev = self._addrevision( | |
2458 | node, |
|
2458 | node, | |
2459 | None, |
|
2459 | None, | |
2460 | transaction, |
|
2460 | transaction, | |
2461 | link, |
|
2461 | link, | |
2462 | p1, |
|
2462 | p1, | |
2463 | p2, |
|
2463 | p2, | |
2464 | flags, |
|
2464 | flags, | |
2465 | (baserev, delta), |
|
2465 | (baserev, delta), | |
2466 | ifh, |
|
2466 | ifh, | |
2467 | dfh, |
|
2467 | dfh, | |
2468 | alwayscache=alwayscache, |
|
2468 | alwayscache=alwayscache, | |
2469 | deltacomputer=deltacomputer, |
|
2469 | deltacomputer=deltacomputer, | |
2470 | sidedata=sidedata, |
|
2470 | sidedata=sidedata, | |
2471 | ) |
|
2471 | ) | |
2472 |
|
2472 | |||
2473 | if addrevisioncb: |
|
2473 | if addrevisioncb: | |
2474 | addrevisioncb(self, rev) |
|
2474 | addrevisioncb(self, rev) | |
2475 | empty = False |
|
2475 | empty = False | |
2476 |
|
2476 | |||
2477 | if not dfh and not self._inline: |
|
2477 | if not dfh and not self._inline: | |
2478 | # addrevision switched from inline to conventional |
|
2478 | # addrevision switched from inline to conventional | |
2479 | # reopen the index |
|
2479 | # reopen the index | |
2480 | ifh.close() |
|
2480 | ifh.close() | |
2481 | dfh = self._datafp(b"a+") |
|
2481 | dfh = self._datafp(b"a+") | |
2482 | ifh = self._indexfp(b"a+") |
|
2482 | ifh = self._indexfp(b"a+") | |
2483 | self._writinghandles = (ifh, dfh) |
|
2483 | self._writinghandles = (ifh, dfh) | |
2484 | finally: |
|
2484 | finally: | |
2485 | self._writinghandles = None |
|
2485 | self._writinghandles = None | |
2486 |
|
2486 | |||
2487 | if dfh: |
|
2487 | if dfh: | |
2488 | dfh.close() |
|
2488 | dfh.close() | |
2489 | ifh.close() |
|
2489 | ifh.close() | |
2490 | return not empty |
|
2490 | return not empty | |
2491 |
|
2491 | |||
2492 | def iscensored(self, rev): |
|
2492 | def iscensored(self, rev): | |
2493 | """Check if a file revision is censored.""" |
|
2493 | """Check if a file revision is censored.""" | |
2494 | if not self._censorable: |
|
2494 | if not self._censorable: | |
2495 | return False |
|
2495 | return False | |
2496 |
|
2496 | |||
2497 | return self.flags(rev) & REVIDX_ISCENSORED |
|
2497 | return self.flags(rev) & REVIDX_ISCENSORED | |
2498 |
|
2498 | |||
2499 | def _peek_iscensored(self, baserev, delta, flush): |
|
2499 | def _peek_iscensored(self, baserev, delta, flush): | |
2500 | """Quickly check if a delta produces a censored revision.""" |
|
2500 | """Quickly check if a delta produces a censored revision.""" | |
2501 | if not self._censorable: |
|
2501 | if not self._censorable: | |
2502 | return False |
|
2502 | return False | |
2503 |
|
2503 | |||
2504 | return storageutil.deltaiscensored(delta, baserev, self.rawsize) |
|
2504 | return storageutil.deltaiscensored(delta, baserev, self.rawsize) | |
2505 |
|
2505 | |||
2506 | def getstrippoint(self, minlink): |
|
2506 | def getstrippoint(self, minlink): | |
2507 | """find the minimum rev that must be stripped to strip the linkrev |
|
2507 | """find the minimum rev that must be stripped to strip the linkrev | |
2508 |
|
2508 | |||
2509 | Returns a tuple containing the minimum rev and a set of all revs that |
|
2509 | Returns a tuple containing the minimum rev and a set of all revs that | |
2510 | have linkrevs that will be broken by this strip. |
|
2510 | have linkrevs that will be broken by this strip. | |
2511 | """ |
|
2511 | """ | |
2512 | return storageutil.resolvestripinfo( |
|
2512 | return storageutil.resolvestripinfo( | |
2513 | minlink, |
|
2513 | minlink, | |
2514 | len(self) - 1, |
|
2514 | len(self) - 1, | |
2515 | self.headrevs(), |
|
2515 | self.headrevs(), | |
2516 | self.linkrev, |
|
2516 | self.linkrev, | |
2517 | self.parentrevs, |
|
2517 | self.parentrevs, | |
2518 | ) |
|
2518 | ) | |
2519 |
|
2519 | |||
2520 | def strip(self, minlink, transaction): |
|
2520 | def strip(self, minlink, transaction): | |
2521 | """truncate the revlog on the first revision with a linkrev >= minlink |
|
2521 | """truncate the revlog on the first revision with a linkrev >= minlink | |
2522 |
|
2522 | |||
2523 | This function is called when we're stripping revision minlink and |
|
2523 | This function is called when we're stripping revision minlink and | |
2524 | its descendants from the repository. |
|
2524 | its descendants from the repository. | |
2525 |
|
2525 | |||
2526 | We have to remove all revisions with linkrev >= minlink, because |
|
2526 | We have to remove all revisions with linkrev >= minlink, because | |
2527 | the equivalent changelog revisions will be renumbered after the |
|
2527 | the equivalent changelog revisions will be renumbered after the | |
2528 | strip. |
|
2528 | strip. | |
2529 |
|
2529 | |||
2530 | So we truncate the revlog on the first of these revisions, and |
|
2530 | So we truncate the revlog on the first of these revisions, and | |
2531 | trust that the caller has saved the revisions that shouldn't be |
|
2531 | trust that the caller has saved the revisions that shouldn't be | |
2532 | removed and that it'll re-add them after this truncation. |
|
2532 | removed and that it'll re-add them after this truncation. | |
2533 | """ |
|
2533 | """ | |
2534 | if len(self) == 0: |
|
2534 | if len(self) == 0: | |
2535 | return |
|
2535 | return | |
2536 |
|
2536 | |||
2537 | rev, _ = self.getstrippoint(minlink) |
|
2537 | rev, _ = self.getstrippoint(minlink) | |
2538 | if rev == len(self): |
|
2538 | if rev == len(self): | |
2539 | return |
|
2539 | return | |
2540 |
|
2540 | |||
2541 | # first truncate the files on disk |
|
2541 | # first truncate the files on disk | |
2542 | end = self.start(rev) |
|
2542 | end = self.start(rev) | |
2543 | if not self._inline: |
|
2543 | if not self._inline: | |
2544 | transaction.add(self.datafile, end) |
|
2544 | transaction.add(self.datafile, end) | |
2545 | end = rev * self.index.entry_size |
|
2545 | end = rev * self.index.entry_size | |
2546 | else: |
|
2546 | else: | |
2547 | end += rev * self.index.entry_size |
|
2547 | end += rev * self.index.entry_size | |
2548 |
|
2548 | |||
2549 | transaction.add(self.indexfile, end) |
|
2549 | transaction.add(self.indexfile, end) | |
2550 |
|
2550 | |||
2551 | # then reset internal state in memory to forget those revisions |
|
2551 | # then reset internal state in memory to forget those revisions | |
2552 | self._revisioncache = None |
|
2552 | self._revisioncache = None | |
2553 | self._chaininfocache = util.lrucachedict(500) |
|
2553 | self._chaininfocache = util.lrucachedict(500) | |
2554 | self._chunkclear() |
|
2554 | self._chunkclear() | |
2555 |
|
2555 | |||
2556 | del self.index[rev:-1] |
|
2556 | del self.index[rev:-1] | |
2557 |
|
2557 | |||
2558 | def checksize(self): |
|
2558 | def checksize(self): | |
2559 | """Check size of index and data files |
|
2559 | """Check size of index and data files | |
2560 |
|
2560 | |||
2561 | return a (dd, di) tuple. |
|
2561 | return a (dd, di) tuple. | |
2562 | - dd: extra bytes for the "data" file |
|
2562 | - dd: extra bytes for the "data" file | |
2563 | - di: extra bytes for the "index" file |
|
2563 | - di: extra bytes for the "index" file | |
2564 |
|
2564 | |||
2565 | A healthy revlog will return (0, 0). |
|
2565 | A healthy revlog will return (0, 0). | |
2566 | """ |
|
2566 | """ | |
2567 | expected = 0 |
|
2567 | expected = 0 | |
2568 | if len(self): |
|
2568 | if len(self): | |
2569 | expected = max(0, self.end(len(self) - 1)) |
|
2569 | expected = max(0, self.end(len(self) - 1)) | |
2570 |
|
2570 | |||
2571 | try: |
|
2571 | try: | |
2572 | with self._datafp() as f: |
|
2572 | with self._datafp() as f: | |
2573 | f.seek(0, io.SEEK_END) |
|
2573 | f.seek(0, io.SEEK_END) | |
2574 | actual = f.tell() |
|
2574 | actual = f.tell() | |
2575 | dd = actual - expected |
|
2575 | dd = actual - expected | |
2576 | except IOError as inst: |
|
2576 | except IOError as inst: | |
2577 | if inst.errno != errno.ENOENT: |
|
2577 | if inst.errno != errno.ENOENT: | |
2578 | raise |
|
2578 | raise | |
2579 | dd = 0 |
|
2579 | dd = 0 | |
2580 |
|
2580 | |||
2581 | try: |
|
2581 | try: | |
2582 | f = self.opener(self.indexfile) |
|
2582 | f = self.opener(self.indexfile) | |
2583 | f.seek(0, io.SEEK_END) |
|
2583 | f.seek(0, io.SEEK_END) | |
2584 | actual = f.tell() |
|
2584 | actual = f.tell() | |
2585 | f.close() |
|
2585 | f.close() | |
2586 | s = self.index.entry_size |
|
2586 | s = self.index.entry_size | |
2587 | i = max(0, actual // s) |
|
2587 | i = max(0, actual // s) | |
2588 | di = actual - (i * s) |
|
2588 | di = actual - (i * s) | |
2589 | if self._inline: |
|
2589 | if self._inline: | |
2590 | databytes = 0 |
|
2590 | databytes = 0 | |
2591 | for r in self: |
|
2591 | for r in self: | |
2592 | databytes += max(0, self.length(r)) |
|
2592 | databytes += max(0, self.length(r)) | |
2593 | dd = 0 |
|
2593 | dd = 0 | |
2594 | di = actual - len(self) * s - databytes |
|
2594 | di = actual - len(self) * s - databytes | |
2595 | except IOError as inst: |
|
2595 | except IOError as inst: | |
2596 | if inst.errno != errno.ENOENT: |
|
2596 | if inst.errno != errno.ENOENT: | |
2597 | raise |
|
2597 | raise | |
2598 | di = 0 |
|
2598 | di = 0 | |
2599 |
|
2599 | |||
2600 | return (dd, di) |
|
2600 | return (dd, di) | |
2601 |
|
2601 | |||
2602 | def files(self): |
|
2602 | def files(self): | |
2603 | res = [self.indexfile] |
|
2603 | res = [self.indexfile] | |
2604 | if not self._inline: |
|
2604 | if not self._inline: | |
2605 | res.append(self.datafile) |
|
2605 | res.append(self.datafile) | |
2606 | return res |
|
2606 | return res | |
2607 |
|
2607 | |||
2608 | def emitrevisions( |
|
2608 | def emitrevisions( | |
2609 | self, |
|
2609 | self, | |
2610 | nodes, |
|
2610 | nodes, | |
2611 | nodesorder=None, |
|
2611 | nodesorder=None, | |
2612 | revisiondata=False, |
|
2612 | revisiondata=False, | |
2613 | assumehaveparentrevisions=False, |
|
2613 | assumehaveparentrevisions=False, | |
2614 | deltamode=repository.CG_DELTAMODE_STD, |
|
2614 | deltamode=repository.CG_DELTAMODE_STD, | |
2615 | sidedata_helpers=None, |
|
2615 | sidedata_helpers=None, | |
2616 | ): |
|
2616 | ): | |
2617 | if nodesorder not in (b'nodes', b'storage', b'linear', None): |
|
2617 | if nodesorder not in (b'nodes', b'storage', b'linear', None): | |
2618 | raise error.ProgrammingError( |
|
2618 | raise error.ProgrammingError( | |
2619 | b'unhandled value for nodesorder: %s' % nodesorder |
|
2619 | b'unhandled value for nodesorder: %s' % nodesorder | |
2620 | ) |
|
2620 | ) | |
2621 |
|
2621 | |||
2622 | if nodesorder is None and not self._generaldelta: |
|
2622 | if nodesorder is None and not self._generaldelta: | |
2623 | nodesorder = b'storage' |
|
2623 | nodesorder = b'storage' | |
2624 |
|
2624 | |||
2625 | if ( |
|
2625 | if ( | |
2626 | not self._storedeltachains |
|
2626 | not self._storedeltachains | |
2627 | and deltamode != repository.CG_DELTAMODE_PREV |
|
2627 | and deltamode != repository.CG_DELTAMODE_PREV | |
2628 | ): |
|
2628 | ): | |
2629 | deltamode = repository.CG_DELTAMODE_FULL |
|
2629 | deltamode = repository.CG_DELTAMODE_FULL | |
2630 |
|
2630 | |||
2631 | return storageutil.emitrevisions( |
|
2631 | return storageutil.emitrevisions( | |
2632 | self, |
|
2632 | self, | |
2633 | nodes, |
|
2633 | nodes, | |
2634 | nodesorder, |
|
2634 | nodesorder, | |
2635 | revlogrevisiondelta, |
|
2635 | revlogrevisiondelta, | |
2636 | deltaparentfn=self.deltaparent, |
|
2636 | deltaparentfn=self.deltaparent, | |
2637 | candeltafn=self.candelta, |
|
2637 | candeltafn=self.candelta, | |
2638 | rawsizefn=self.rawsize, |
|
2638 | rawsizefn=self.rawsize, | |
2639 | revdifffn=self.revdiff, |
|
2639 | revdifffn=self.revdiff, | |
2640 | flagsfn=self.flags, |
|
2640 | flagsfn=self.flags, | |
2641 | deltamode=deltamode, |
|
2641 | deltamode=deltamode, | |
2642 | revisiondata=revisiondata, |
|
2642 | revisiondata=revisiondata, | |
2643 | assumehaveparentrevisions=assumehaveparentrevisions, |
|
2643 | assumehaveparentrevisions=assumehaveparentrevisions, | |
2644 | sidedata_helpers=sidedata_helpers, |
|
2644 | sidedata_helpers=sidedata_helpers, | |
2645 | ) |
|
2645 | ) | |
2646 |
|
2646 | |||
2647 | DELTAREUSEALWAYS = b'always' |
|
2647 | DELTAREUSEALWAYS = b'always' | |
2648 | DELTAREUSESAMEREVS = b'samerevs' |
|
2648 | DELTAREUSESAMEREVS = b'samerevs' | |
2649 | DELTAREUSENEVER = b'never' |
|
2649 | DELTAREUSENEVER = b'never' | |
2650 |
|
2650 | |||
2651 | DELTAREUSEFULLADD = b'fulladd' |
|
2651 | DELTAREUSEFULLADD = b'fulladd' | |
2652 |
|
2652 | |||
2653 | DELTAREUSEALL = {b'always', b'samerevs', b'never', b'fulladd'} |
|
2653 | DELTAREUSEALL = {b'always', b'samerevs', b'never', b'fulladd'} | |
2654 |
|
2654 | |||
2655 | def clone( |
|
2655 | def clone( | |
2656 | self, |
|
2656 | self, | |
2657 | tr, |
|
2657 | tr, | |
2658 | destrevlog, |
|
2658 | destrevlog, | |
2659 | addrevisioncb=None, |
|
2659 | addrevisioncb=None, | |
2660 | deltareuse=DELTAREUSESAMEREVS, |
|
2660 | deltareuse=DELTAREUSESAMEREVS, | |
2661 | forcedeltabothparents=None, |
|
2661 | forcedeltabothparents=None, | |
2662 | sidedatacompanion=None, |
|
2662 | sidedatacompanion=None, | |
2663 | ): |
|
2663 | ): | |
2664 | """Copy this revlog to another, possibly with format changes. |
|
2664 | """Copy this revlog to another, possibly with format changes. | |
2665 |
|
2665 | |||
2666 | The destination revlog will contain the same revisions and nodes. |
|
2666 | The destination revlog will contain the same revisions and nodes. | |
2667 | However, it may not be bit-for-bit identical due to e.g. delta encoding |
|
2667 | However, it may not be bit-for-bit identical due to e.g. delta encoding | |
2668 | differences. |
|
2668 | differences. | |
2669 |
|
2669 | |||
2670 | The ``deltareuse`` argument control how deltas from the existing revlog |
|
2670 | The ``deltareuse`` argument control how deltas from the existing revlog | |
2671 | are preserved in the destination revlog. The argument can have the |
|
2671 | are preserved in the destination revlog. The argument can have the | |
2672 | following values: |
|
2672 | following values: | |
2673 |
|
2673 | |||
2674 | DELTAREUSEALWAYS |
|
2674 | DELTAREUSEALWAYS | |
2675 | Deltas will always be reused (if possible), even if the destination |
|
2675 | Deltas will always be reused (if possible), even if the destination | |
2676 | revlog would not select the same revisions for the delta. This is the |
|
2676 | revlog would not select the same revisions for the delta. This is the | |
2677 | fastest mode of operation. |
|
2677 | fastest mode of operation. | |
2678 | DELTAREUSESAMEREVS |
|
2678 | DELTAREUSESAMEREVS | |
2679 | Deltas will be reused if the destination revlog would pick the same |
|
2679 | Deltas will be reused if the destination revlog would pick the same | |
2680 | revisions for the delta. This mode strikes a balance between speed |
|
2680 | revisions for the delta. This mode strikes a balance between speed | |
2681 | and optimization. |
|
2681 | and optimization. | |
2682 | DELTAREUSENEVER |
|
2682 | DELTAREUSENEVER | |
2683 | Deltas will never be reused. This is the slowest mode of execution. |
|
2683 | Deltas will never be reused. This is the slowest mode of execution. | |
2684 | This mode can be used to recompute deltas (e.g. if the diff/delta |
|
2684 | This mode can be used to recompute deltas (e.g. if the diff/delta | |
2685 | algorithm changes). |
|
2685 | algorithm changes). | |
2686 | DELTAREUSEFULLADD |
|
2686 | DELTAREUSEFULLADD | |
2687 | Revision will be re-added as if their were new content. This is |
|
2687 | Revision will be re-added as if their were new content. This is | |
2688 | slower than DELTAREUSEALWAYS but allow more mechanism to kicks in. |
|
2688 | slower than DELTAREUSEALWAYS but allow more mechanism to kicks in. | |
2689 | eg: large file detection and handling. |
|
2689 | eg: large file detection and handling. | |
2690 |
|
2690 | |||
2691 | Delta computation can be slow, so the choice of delta reuse policy can |
|
2691 | Delta computation can be slow, so the choice of delta reuse policy can | |
2692 | significantly affect run time. |
|
2692 | significantly affect run time. | |
2693 |
|
2693 | |||
2694 | The default policy (``DELTAREUSESAMEREVS``) strikes a balance between |
|
2694 | The default policy (``DELTAREUSESAMEREVS``) strikes a balance between | |
2695 | two extremes. Deltas will be reused if they are appropriate. But if the |
|
2695 | two extremes. Deltas will be reused if they are appropriate. But if the | |
2696 | delta could choose a better revision, it will do so. This means if you |
|
2696 | delta could choose a better revision, it will do so. This means if you | |
2697 | are converting a non-generaldelta revlog to a generaldelta revlog, |
|
2697 | are converting a non-generaldelta revlog to a generaldelta revlog, | |
2698 | deltas will be recomputed if the delta's parent isn't a parent of the |
|
2698 | deltas will be recomputed if the delta's parent isn't a parent of the | |
2699 | revision. |
|
2699 | revision. | |
2700 |
|
2700 | |||
2701 | In addition to the delta policy, the ``forcedeltabothparents`` |
|
2701 | In addition to the delta policy, the ``forcedeltabothparents`` | |
2702 | argument controls whether to force compute deltas against both parents |
|
2702 | argument controls whether to force compute deltas against both parents | |
2703 | for merges. By default, the current default is used. |
|
2703 | for merges. By default, the current default is used. | |
2704 |
|
2704 | |||
2705 | If not None, the `sidedatacompanion` is callable that accept two |
|
2705 | If not None, the `sidedatacompanion` is callable that accept two | |
2706 | arguments: |
|
2706 | arguments: | |
2707 |
|
2707 | |||
2708 | (srcrevlog, rev) |
|
2708 | (srcrevlog, rev) | |
2709 |
|
2709 | |||
2710 | and return a quintet that control changes to sidedata content from the |
|
2710 | and return a quintet that control changes to sidedata content from the | |
2711 | old revision to the new clone result: |
|
2711 | old revision to the new clone result: | |
2712 |
|
2712 | |||
2713 | (dropall, filterout, update, new_flags, dropped_flags) |
|
2713 | (dropall, filterout, update, new_flags, dropped_flags) | |
2714 |
|
2714 | |||
2715 | * if `dropall` is True, all sidedata should be dropped |
|
2715 | * if `dropall` is True, all sidedata should be dropped | |
2716 | * `filterout` is a set of sidedata keys that should be dropped |
|
2716 | * `filterout` is a set of sidedata keys that should be dropped | |
2717 | * `update` is a mapping of additionnal/new key -> value |
|
2717 | * `update` is a mapping of additionnal/new key -> value | |
2718 | * new_flags is a bitfields of new flags that the revision should get |
|
2718 | * new_flags is a bitfields of new flags that the revision should get | |
2719 | * dropped_flags is a bitfields of new flags that the revision shoudl not longer have |
|
2719 | * dropped_flags is a bitfields of new flags that the revision shoudl not longer have | |
2720 | """ |
|
2720 | """ | |
2721 | if deltareuse not in self.DELTAREUSEALL: |
|
2721 | if deltareuse not in self.DELTAREUSEALL: | |
2722 | raise ValueError( |
|
2722 | raise ValueError( | |
2723 | _(b'value for deltareuse invalid: %s') % deltareuse |
|
2723 | _(b'value for deltareuse invalid: %s') % deltareuse | |
2724 | ) |
|
2724 | ) | |
2725 |
|
2725 | |||
2726 | if len(destrevlog): |
|
2726 | if len(destrevlog): | |
2727 | raise ValueError(_(b'destination revlog is not empty')) |
|
2727 | raise ValueError(_(b'destination revlog is not empty')) | |
2728 |
|
2728 | |||
2729 | if getattr(self, 'filteredrevs', None): |
|
2729 | if getattr(self, 'filteredrevs', None): | |
2730 | raise ValueError(_(b'source revlog has filtered revisions')) |
|
2730 | raise ValueError(_(b'source revlog has filtered revisions')) | |
2731 | if getattr(destrevlog, 'filteredrevs', None): |
|
2731 | if getattr(destrevlog, 'filteredrevs', None): | |
2732 | raise ValueError(_(b'destination revlog has filtered revisions')) |
|
2732 | raise ValueError(_(b'destination revlog has filtered revisions')) | |
2733 |
|
2733 | |||
2734 | # lazydelta and lazydeltabase controls whether to reuse a cached delta, |
|
2734 | # lazydelta and lazydeltabase controls whether to reuse a cached delta, | |
2735 | # if possible. |
|
2735 | # if possible. | |
2736 | oldlazydelta = destrevlog._lazydelta |
|
2736 | oldlazydelta = destrevlog._lazydelta | |
2737 | oldlazydeltabase = destrevlog._lazydeltabase |
|
2737 | oldlazydeltabase = destrevlog._lazydeltabase | |
2738 | oldamd = destrevlog._deltabothparents |
|
2738 | oldamd = destrevlog._deltabothparents | |
2739 |
|
2739 | |||
2740 | try: |
|
2740 | try: | |
2741 | if deltareuse == self.DELTAREUSEALWAYS: |
|
2741 | if deltareuse == self.DELTAREUSEALWAYS: | |
2742 | destrevlog._lazydeltabase = True |
|
2742 | destrevlog._lazydeltabase = True | |
2743 | destrevlog._lazydelta = True |
|
2743 | destrevlog._lazydelta = True | |
2744 | elif deltareuse == self.DELTAREUSESAMEREVS: |
|
2744 | elif deltareuse == self.DELTAREUSESAMEREVS: | |
2745 | destrevlog._lazydeltabase = False |
|
2745 | destrevlog._lazydeltabase = False | |
2746 | destrevlog._lazydelta = True |
|
2746 | destrevlog._lazydelta = True | |
2747 | elif deltareuse == self.DELTAREUSENEVER: |
|
2747 | elif deltareuse == self.DELTAREUSENEVER: | |
2748 | destrevlog._lazydeltabase = False |
|
2748 | destrevlog._lazydeltabase = False | |
2749 | destrevlog._lazydelta = False |
|
2749 | destrevlog._lazydelta = False | |
2750 |
|
2750 | |||
2751 | destrevlog._deltabothparents = forcedeltabothparents or oldamd |
|
2751 | destrevlog._deltabothparents = forcedeltabothparents or oldamd | |
2752 |
|
2752 | |||
2753 | self._clone( |
|
2753 | self._clone( | |
2754 | tr, |
|
2754 | tr, | |
2755 | destrevlog, |
|
2755 | destrevlog, | |
2756 | addrevisioncb, |
|
2756 | addrevisioncb, | |
2757 | deltareuse, |
|
2757 | deltareuse, | |
2758 | forcedeltabothparents, |
|
2758 | forcedeltabothparents, | |
2759 | sidedatacompanion, |
|
2759 | sidedatacompanion, | |
2760 | ) |
|
2760 | ) | |
2761 |
|
2761 | |||
2762 | finally: |
|
2762 | finally: | |
2763 | destrevlog._lazydelta = oldlazydelta |
|
2763 | destrevlog._lazydelta = oldlazydelta | |
2764 | destrevlog._lazydeltabase = oldlazydeltabase |
|
2764 | destrevlog._lazydeltabase = oldlazydeltabase | |
2765 | destrevlog._deltabothparents = oldamd |
|
2765 | destrevlog._deltabothparents = oldamd | |
2766 |
|
2766 | |||
2767 | def _clone( |
|
2767 | def _clone( | |
2768 | self, |
|
2768 | self, | |
2769 | tr, |
|
2769 | tr, | |
2770 | destrevlog, |
|
2770 | destrevlog, | |
2771 | addrevisioncb, |
|
2771 | addrevisioncb, | |
2772 | deltareuse, |
|
2772 | deltareuse, | |
2773 | forcedeltabothparents, |
|
2773 | forcedeltabothparents, | |
2774 | sidedatacompanion, |
|
2774 | sidedatacompanion, | |
2775 | ): |
|
2775 | ): | |
2776 | """perform the core duty of `revlog.clone` after parameter processing""" |
|
2776 | """perform the core duty of `revlog.clone` after parameter processing""" | |
2777 | deltacomputer = deltautil.deltacomputer(destrevlog) |
|
2777 | deltacomputer = deltautil.deltacomputer(destrevlog) | |
2778 | index = self.index |
|
2778 | index = self.index | |
2779 | for rev in self: |
|
2779 | for rev in self: | |
2780 | entry = index[rev] |
|
2780 | entry = index[rev] | |
2781 |
|
2781 | |||
2782 | # Some classes override linkrev to take filtered revs into |
|
2782 | # Some classes override linkrev to take filtered revs into | |
2783 | # account. Use raw entry from index. |
|
2783 | # account. Use raw entry from index. | |
2784 | flags = entry[0] & 0xFFFF |
|
2784 | flags = entry[0] & 0xFFFF | |
2785 | linkrev = entry[4] |
|
2785 | linkrev = entry[4] | |
2786 | p1 = index[entry[5]][7] |
|
2786 | p1 = index[entry[5]][7] | |
2787 | p2 = index[entry[6]][7] |
|
2787 | p2 = index[entry[6]][7] | |
2788 | node = entry[7] |
|
2788 | node = entry[7] | |
2789 |
|
2789 | |||
2790 | sidedataactions = (False, [], {}, 0, 0) |
|
2790 | sidedataactions = (False, [], {}, 0, 0) | |
2791 | if sidedatacompanion is not None: |
|
2791 | if sidedatacompanion is not None: | |
2792 | sidedataactions = sidedatacompanion(self, rev) |
|
2792 | sidedataactions = sidedatacompanion(self, rev) | |
2793 |
|
2793 | |||
2794 | # (Possibly) reuse the delta from the revlog if allowed and |
|
2794 | # (Possibly) reuse the delta from the revlog if allowed and | |
2795 | # the revlog chunk is a delta. |
|
2795 | # the revlog chunk is a delta. | |
2796 | cachedelta = None |
|
2796 | cachedelta = None | |
2797 | rawtext = None |
|
2797 | rawtext = None | |
2798 | if any(sidedataactions) or deltareuse == self.DELTAREUSEFULLADD: |
|
2798 | if any(sidedataactions) or deltareuse == self.DELTAREUSEFULLADD: | |
2799 | dropall = sidedataactions[0] |
|
2799 | dropall = sidedataactions[0] | |
2800 | filterout = sidedataactions[1] |
|
2800 | filterout = sidedataactions[1] | |
2801 | update = sidedataactions[2] |
|
2801 | update = sidedataactions[2] | |
2802 | new_flags = sidedataactions[3] |
|
2802 | new_flags = sidedataactions[3] | |
2803 | dropped_flags = sidedataactions[4] |
|
2803 | dropped_flags = sidedataactions[4] | |
2804 | text, sidedata = self._revisiondata(rev) |
|
2804 | text, sidedata = self._revisiondata(rev) | |
2805 | if dropall: |
|
2805 | if dropall: | |
2806 | sidedata = {} |
|
2806 | sidedata = {} | |
2807 | for key in filterout: |
|
2807 | for key in filterout: | |
2808 | sidedata.pop(key, None) |
|
2808 | sidedata.pop(key, None) | |
2809 | sidedata.update(update) |
|
2809 | sidedata.update(update) | |
2810 | if not sidedata: |
|
2810 | if not sidedata: | |
2811 | sidedata = None |
|
2811 | sidedata = None | |
2812 |
|
2812 | |||
2813 | flags |= new_flags |
|
2813 | flags |= new_flags | |
2814 | flags &= ~dropped_flags |
|
2814 | flags &= ~dropped_flags | |
2815 |
|
2815 | |||
2816 | destrevlog.addrevision( |
|
2816 | destrevlog.addrevision( | |
2817 | text, |
|
2817 | text, | |
2818 | tr, |
|
2818 | tr, | |
2819 | linkrev, |
|
2819 | linkrev, | |
2820 | p1, |
|
2820 | p1, | |
2821 | p2, |
|
2821 | p2, | |
2822 | cachedelta=cachedelta, |
|
2822 | cachedelta=cachedelta, | |
2823 | node=node, |
|
2823 | node=node, | |
2824 | flags=flags, |
|
2824 | flags=flags, | |
2825 | deltacomputer=deltacomputer, |
|
2825 | deltacomputer=deltacomputer, | |
2826 | sidedata=sidedata, |
|
2826 | sidedata=sidedata, | |
2827 | ) |
|
2827 | ) | |
2828 | else: |
|
2828 | else: | |
2829 | if destrevlog._lazydelta: |
|
2829 | if destrevlog._lazydelta: | |
2830 | dp = self.deltaparent(rev) |
|
2830 | dp = self.deltaparent(rev) | |
2831 | if dp != nullrev: |
|
2831 | if dp != nullrev: | |
2832 | cachedelta = (dp, bytes(self._chunk(rev))) |
|
2832 | cachedelta = (dp, bytes(self._chunk(rev))) | |
2833 |
|
2833 | |||
2834 | if not cachedelta: |
|
2834 | if not cachedelta: | |
2835 | rawtext = self.rawdata(rev) |
|
2835 | rawtext = self.rawdata(rev) | |
2836 |
|
2836 | |||
2837 | ifh = destrevlog.opener( |
|
2837 | ifh = destrevlog.opener( | |
2838 | destrevlog.indexfile, b'a+', checkambig=False |
|
2838 | destrevlog.indexfile, b'a+', checkambig=False | |
2839 | ) |
|
2839 | ) | |
2840 | dfh = None |
|
2840 | dfh = None | |
2841 | if not destrevlog._inline: |
|
2841 | if not destrevlog._inline: | |
2842 | dfh = destrevlog.opener(destrevlog.datafile, b'a+') |
|
2842 | dfh = destrevlog.opener(destrevlog.datafile, b'a+') | |
2843 | try: |
|
2843 | try: | |
2844 | destrevlog._addrevision( |
|
2844 | destrevlog._addrevision( | |
2845 | node, |
|
2845 | node, | |
2846 | rawtext, |
|
2846 | rawtext, | |
2847 | tr, |
|
2847 | tr, | |
2848 | linkrev, |
|
2848 | linkrev, | |
2849 | p1, |
|
2849 | p1, | |
2850 | p2, |
|
2850 | p2, | |
2851 | flags, |
|
2851 | flags, | |
2852 | cachedelta, |
|
2852 | cachedelta, | |
2853 | ifh, |
|
2853 | ifh, | |
2854 | dfh, |
|
2854 | dfh, | |
2855 | deltacomputer=deltacomputer, |
|
2855 | deltacomputer=deltacomputer, | |
2856 | ) |
|
2856 | ) | |
2857 | finally: |
|
2857 | finally: | |
2858 | if dfh: |
|
2858 | if dfh: | |
2859 | dfh.close() |
|
2859 | dfh.close() | |
2860 | ifh.close() |
|
2860 | ifh.close() | |
2861 |
|
2861 | |||
2862 | if addrevisioncb: |
|
2862 | if addrevisioncb: | |
2863 | addrevisioncb(self, rev, node) |
|
2863 | addrevisioncb(self, rev, node) | |
2864 |
|
2864 | |||
2865 | def censorrevision(self, tr, censornode, tombstone=b''): |
|
2865 | def censorrevision(self, tr, censornode, tombstone=b''): | |
2866 | if (self.version & 0xFFFF) == REVLOGV0: |
|
2866 | if (self.version & 0xFFFF) == REVLOGV0: | |
2867 | raise error.RevlogError( |
|
2867 | raise error.RevlogError( | |
2868 | _(b'cannot censor with version %d revlogs') % self.version |
|
2868 | _(b'cannot censor with version %d revlogs') % self.version | |
2869 | ) |
|
2869 | ) | |
2870 |
|
2870 | |||
2871 | censorrev = self.rev(censornode) |
|
2871 | censorrev = self.rev(censornode) | |
2872 | tombstone = storageutil.packmeta({b'censored': tombstone}, b'') |
|
2872 | tombstone = storageutil.packmeta({b'censored': tombstone}, b'') | |
2873 |
|
2873 | |||
2874 | if len(tombstone) > self.rawsize(censorrev): |
|
2874 | if len(tombstone) > self.rawsize(censorrev): | |
2875 | raise error.Abort( |
|
2875 | raise error.Abort( | |
2876 | _(b'censor tombstone must be no longer than censored data') |
|
2876 | _(b'censor tombstone must be no longer than censored data') | |
2877 | ) |
|
2877 | ) | |
2878 |
|
2878 | |||
2879 | # Rewriting the revlog in place is hard. Our strategy for censoring is |
|
2879 | # Rewriting the revlog in place is hard. Our strategy for censoring is | |
2880 | # to create a new revlog, copy all revisions to it, then replace the |
|
2880 | # to create a new revlog, copy all revisions to it, then replace the | |
2881 | # revlogs on transaction close. |
|
2881 | # revlogs on transaction close. | |
2882 |
|
2882 | |||
2883 | newindexfile = self.indexfile + b'.tmpcensored' |
|
2883 | newindexfile = self.indexfile + b'.tmpcensored' | |
2884 | newdatafile = self.datafile + b'.tmpcensored' |
|
2884 | newdatafile = self.datafile + b'.tmpcensored' | |
2885 |
|
2885 | |||
2886 | # This is a bit dangerous. We could easily have a mismatch of state. |
|
2886 | # This is a bit dangerous. We could easily have a mismatch of state. | |
2887 | newrl = revlog( |
|
2887 | newrl = revlog( | |
2888 | self.opener, |
|
2888 | self.opener, | |
2889 | target=self.target, |
|
2889 | target=self.target, | |
2890 | indexfile=newindexfile, |
|
2890 | indexfile=newindexfile, | |
2891 | datafile=newdatafile, |
|
2891 | datafile=newdatafile, | |
2892 | censorable=True, |
|
2892 | censorable=True, | |
2893 | ) |
|
2893 | ) | |
2894 | newrl.version = self.version |
|
2894 | newrl.version = self.version | |
2895 | newrl._generaldelta = self._generaldelta |
|
2895 | newrl._generaldelta = self._generaldelta | |
2896 | newrl._parse_index = self._parse_index |
|
2896 | newrl._parse_index = self._parse_index | |
2897 |
|
2897 | |||
2898 | for rev in self.revs(): |
|
2898 | for rev in self.revs(): | |
2899 | node = self.node(rev) |
|
2899 | node = self.node(rev) | |
2900 | p1, p2 = self.parents(node) |
|
2900 | p1, p2 = self.parents(node) | |
2901 |
|
2901 | |||
2902 | if rev == censorrev: |
|
2902 | if rev == censorrev: | |
2903 | newrl.addrawrevision( |
|
2903 | newrl.addrawrevision( | |
2904 | tombstone, |
|
2904 | tombstone, | |
2905 | tr, |
|
2905 | tr, | |
2906 | self.linkrev(censorrev), |
|
2906 | self.linkrev(censorrev), | |
2907 | p1, |
|
2907 | p1, | |
2908 | p2, |
|
2908 | p2, | |
2909 | censornode, |
|
2909 | censornode, | |
2910 | REVIDX_ISCENSORED, |
|
2910 | REVIDX_ISCENSORED, | |
2911 | ) |
|
2911 | ) | |
2912 |
|
2912 | |||
2913 | if newrl.deltaparent(rev) != nullrev: |
|
2913 | if newrl.deltaparent(rev) != nullrev: | |
2914 | raise error.Abort( |
|
2914 | raise error.Abort( | |
2915 | _( |
|
2915 | _( | |
2916 | b'censored revision stored as delta; ' |
|
2916 | b'censored revision stored as delta; ' | |
2917 | b'cannot censor' |
|
2917 | b'cannot censor' | |
2918 | ), |
|
2918 | ), | |
2919 | hint=_( |
|
2919 | hint=_( | |
2920 | b'censoring of revlogs is not ' |
|
2920 | b'censoring of revlogs is not ' | |
2921 | b'fully implemented; please report ' |
|
2921 | b'fully implemented; please report ' | |
2922 | b'this bug' |
|
2922 | b'this bug' | |
2923 | ), |
|
2923 | ), | |
2924 | ) |
|
2924 | ) | |
2925 | continue |
|
2925 | continue | |
2926 |
|
2926 | |||
2927 | if self.iscensored(rev): |
|
2927 | if self.iscensored(rev): | |
2928 | if self.deltaparent(rev) != nullrev: |
|
2928 | if self.deltaparent(rev) != nullrev: | |
2929 | raise error.Abort( |
|
2929 | raise error.Abort( | |
2930 | _( |
|
2930 | _( | |
2931 | b'cannot censor due to censored ' |
|
2931 | b'cannot censor due to censored ' | |
2932 | b'revision having delta stored' |
|
2932 | b'revision having delta stored' | |
2933 | ) |
|
2933 | ) | |
2934 | ) |
|
2934 | ) | |
2935 | rawtext = self._chunk(rev) |
|
2935 | rawtext = self._chunk(rev) | |
2936 | else: |
|
2936 | else: | |
2937 | rawtext = self.rawdata(rev) |
|
2937 | rawtext = self.rawdata(rev) | |
2938 |
|
2938 | |||
2939 | newrl.addrawrevision( |
|
2939 | newrl.addrawrevision( | |
2940 | rawtext, tr, self.linkrev(rev), p1, p2, node, self.flags(rev) |
|
2940 | rawtext, tr, self.linkrev(rev), p1, p2, node, self.flags(rev) | |
2941 | ) |
|
2941 | ) | |
2942 |
|
2942 | |||
2943 | tr.addbackup(self.indexfile, location=b'store') |
|
2943 | tr.addbackup(self.indexfile, location=b'store') | |
2944 | if not self._inline: |
|
2944 | if not self._inline: | |
2945 | tr.addbackup(self.datafile, location=b'store') |
|
2945 | tr.addbackup(self.datafile, location=b'store') | |
2946 |
|
2946 | |||
2947 | self.opener.rename(newrl.indexfile, self.indexfile) |
|
2947 | self.opener.rename(newrl.indexfile, self.indexfile) | |
2948 | if not self._inline: |
|
2948 | if not self._inline: | |
2949 | self.opener.rename(newrl.datafile, self.datafile) |
|
2949 | self.opener.rename(newrl.datafile, self.datafile) | |
2950 |
|
2950 | |||
2951 | self.clearcaches() |
|
2951 | self.clearcaches() | |
2952 | self._loadindex() |
|
2952 | self._loadindex() | |
2953 |
|
2953 | |||
2954 | def verifyintegrity(self, state): |
|
2954 | def verifyintegrity(self, state): | |
2955 | """Verifies the integrity of the revlog. |
|
2955 | """Verifies the integrity of the revlog. | |
2956 |
|
2956 | |||
2957 | Yields ``revlogproblem`` instances describing problems that are |
|
2957 | Yields ``revlogproblem`` instances describing problems that are | |
2958 | found. |
|
2958 | found. | |
2959 | """ |
|
2959 | """ | |
2960 | dd, di = self.checksize() |
|
2960 | dd, di = self.checksize() | |
2961 | if dd: |
|
2961 | if dd: | |
2962 | yield revlogproblem(error=_(b'data length off by %d bytes') % dd) |
|
2962 | yield revlogproblem(error=_(b'data length off by %d bytes') % dd) | |
2963 | if di: |
|
2963 | if di: | |
2964 | yield revlogproblem(error=_(b'index contains %d extra bytes') % di) |
|
2964 | yield revlogproblem(error=_(b'index contains %d extra bytes') % di) | |
2965 |
|
2965 | |||
2966 | version = self.version & 0xFFFF |
|
2966 | version = self.version & 0xFFFF | |
2967 |
|
2967 | |||
2968 | # The verifier tells us what version revlog we should be. |
|
2968 | # The verifier tells us what version revlog we should be. | |
2969 | if version != state[b'expectedversion']: |
|
2969 | if version != state[b'expectedversion']: | |
2970 | yield revlogproblem( |
|
2970 | yield revlogproblem( | |
2971 | warning=_(b"warning: '%s' uses revlog format %d; expected %d") |
|
2971 | warning=_(b"warning: '%s' uses revlog format %d; expected %d") | |
2972 | % (self.indexfile, version, state[b'expectedversion']) |
|
2972 | % (self.indexfile, version, state[b'expectedversion']) | |
2973 | ) |
|
2973 | ) | |
2974 |
|
2974 | |||
2975 | state[b'skipread'] = set() |
|
2975 | state[b'skipread'] = set() | |
2976 | state[b'safe_renamed'] = set() |
|
2976 | state[b'safe_renamed'] = set() | |
2977 |
|
2977 | |||
2978 | for rev in self: |
|
2978 | for rev in self: | |
2979 | node = self.node(rev) |
|
2979 | node = self.node(rev) | |
2980 |
|
2980 | |||
2981 | # Verify contents. 4 cases to care about: |
|
2981 | # Verify contents. 4 cases to care about: | |
2982 | # |
|
2982 | # | |
2983 | # common: the most common case |
|
2983 | # common: the most common case | |
2984 | # rename: with a rename |
|
2984 | # rename: with a rename | |
2985 | # meta: file content starts with b'\1\n', the metadata |
|
2985 | # meta: file content starts with b'\1\n', the metadata | |
2986 | # header defined in filelog.py, but without a rename |
|
2986 | # header defined in filelog.py, but without a rename | |
2987 | # ext: content stored externally |
|
2987 | # ext: content stored externally | |
2988 | # |
|
2988 | # | |
2989 | # More formally, their differences are shown below: |
|
2989 | # More formally, their differences are shown below: | |
2990 | # |
|
2990 | # | |
2991 | # | common | rename | meta | ext |
|
2991 | # | common | rename | meta | ext | |
2992 | # ------------------------------------------------------- |
|
2992 | # ------------------------------------------------------- | |
2993 | # flags() | 0 | 0 | 0 | not 0 |
|
2993 | # flags() | 0 | 0 | 0 | not 0 | |
2994 | # renamed() | False | True | False | ? |
|
2994 | # renamed() | False | True | False | ? | |
2995 | # rawtext[0:2]=='\1\n'| False | True | True | ? |
|
2995 | # rawtext[0:2]=='\1\n'| False | True | True | ? | |
2996 | # |
|
2996 | # | |
2997 | # "rawtext" means the raw text stored in revlog data, which |
|
2997 | # "rawtext" means the raw text stored in revlog data, which | |
2998 | # could be retrieved by "rawdata(rev)". "text" |
|
2998 | # could be retrieved by "rawdata(rev)". "text" | |
2999 | # mentioned below is "revision(rev)". |
|
2999 | # mentioned below is "revision(rev)". | |
3000 | # |
|
3000 | # | |
3001 | # There are 3 different lengths stored physically: |
|
3001 | # There are 3 different lengths stored physically: | |
3002 | # 1. L1: rawsize, stored in revlog index |
|
3002 | # 1. L1: rawsize, stored in revlog index | |
3003 | # 2. L2: len(rawtext), stored in revlog data |
|
3003 | # 2. L2: len(rawtext), stored in revlog data | |
3004 | # 3. L3: len(text), stored in revlog data if flags==0, or |
|
3004 | # 3. L3: len(text), stored in revlog data if flags==0, or | |
3005 | # possibly somewhere else if flags!=0 |
|
3005 | # possibly somewhere else if flags!=0 | |
3006 | # |
|
3006 | # | |
3007 | # L1 should be equal to L2. L3 could be different from them. |
|
3007 | # L1 should be equal to L2. L3 could be different from them. | |
3008 | # "text" may or may not affect commit hash depending on flag |
|
3008 | # "text" may or may not affect commit hash depending on flag | |
3009 | # processors (see flagutil.addflagprocessor). |
|
3009 | # processors (see flagutil.addflagprocessor). | |
3010 | # |
|
3010 | # | |
3011 | # | common | rename | meta | ext |
|
3011 | # | common | rename | meta | ext | |
3012 | # ------------------------------------------------- |
|
3012 | # ------------------------------------------------- | |
3013 | # rawsize() | L1 | L1 | L1 | L1 |
|
3013 | # rawsize() | L1 | L1 | L1 | L1 | |
3014 | # size() | L1 | L2-LM | L1(*) | L1 (?) |
|
3014 | # size() | L1 | L2-LM | L1(*) | L1 (?) | |
3015 | # len(rawtext) | L2 | L2 | L2 | L2 |
|
3015 | # len(rawtext) | L2 | L2 | L2 | L2 | |
3016 | # len(text) | L2 | L2 | L2 | L3 |
|
3016 | # len(text) | L2 | L2 | L2 | L3 | |
3017 | # len(read()) | L2 | L2-LM | L2-LM | L3 (?) |
|
3017 | # len(read()) | L2 | L2-LM | L2-LM | L3 (?) | |
3018 | # |
|
3018 | # | |
3019 | # LM: length of metadata, depending on rawtext |
|
3019 | # LM: length of metadata, depending on rawtext | |
3020 | # (*): not ideal, see comment in filelog.size |
|
3020 | # (*): not ideal, see comment in filelog.size | |
3021 | # (?): could be "- len(meta)" if the resolved content has |
|
3021 | # (?): could be "- len(meta)" if the resolved content has | |
3022 | # rename metadata |
|
3022 | # rename metadata | |
3023 | # |
|
3023 | # | |
3024 | # Checks needed to be done: |
|
3024 | # Checks needed to be done: | |
3025 | # 1. length check: L1 == L2, in all cases. |
|
3025 | # 1. length check: L1 == L2, in all cases. | |
3026 | # 2. hash check: depending on flag processor, we may need to |
|
3026 | # 2. hash check: depending on flag processor, we may need to | |
3027 | # use either "text" (external), or "rawtext" (in revlog). |
|
3027 | # use either "text" (external), or "rawtext" (in revlog). | |
3028 |
|
3028 | |||
3029 | try: |
|
3029 | try: | |
3030 | skipflags = state.get(b'skipflags', 0) |
|
3030 | skipflags = state.get(b'skipflags', 0) | |
3031 | if skipflags: |
|
3031 | if skipflags: | |
3032 | skipflags &= self.flags(rev) |
|
3032 | skipflags &= self.flags(rev) | |
3033 |
|
3033 | |||
3034 | _verify_revision(self, skipflags, state, node) |
|
3034 | _verify_revision(self, skipflags, state, node) | |
3035 |
|
3035 | |||
3036 | l1 = self.rawsize(rev) |
|
3036 | l1 = self.rawsize(rev) | |
3037 | l2 = len(self.rawdata(node)) |
|
3037 | l2 = len(self.rawdata(node)) | |
3038 |
|
3038 | |||
3039 | if l1 != l2: |
|
3039 | if l1 != l2: | |
3040 | yield revlogproblem( |
|
3040 | yield revlogproblem( | |
3041 | error=_(b'unpacked size is %d, %d expected') % (l2, l1), |
|
3041 | error=_(b'unpacked size is %d, %d expected') % (l2, l1), | |
3042 | node=node, |
|
3042 | node=node, | |
3043 | ) |
|
3043 | ) | |
3044 |
|
3044 | |||
3045 | except error.CensoredNodeError: |
|
3045 | except error.CensoredNodeError: | |
3046 | if state[b'erroroncensored']: |
|
3046 | if state[b'erroroncensored']: | |
3047 | yield revlogproblem( |
|
3047 | yield revlogproblem( | |
3048 | error=_(b'censored file data'), node=node |
|
3048 | error=_(b'censored file data'), node=node | |
3049 | ) |
|
3049 | ) | |
3050 | state[b'skipread'].add(node) |
|
3050 | state[b'skipread'].add(node) | |
3051 | except Exception as e: |
|
3051 | except Exception as e: | |
3052 | yield revlogproblem( |
|
3052 | yield revlogproblem( | |
3053 | error=_(b'unpacking %s: %s') |
|
3053 | error=_(b'unpacking %s: %s') | |
3054 | % (short(node), stringutil.forcebytestr(e)), |
|
3054 | % (short(node), stringutil.forcebytestr(e)), | |
3055 | node=node, |
|
3055 | node=node, | |
3056 | ) |
|
3056 | ) | |
3057 | state[b'skipread'].add(node) |
|
3057 | state[b'skipread'].add(node) | |
3058 |
|
3058 | |||
3059 | def storageinfo( |
|
3059 | def storageinfo( | |
3060 | self, |
|
3060 | self, | |
3061 | exclusivefiles=False, |
|
3061 | exclusivefiles=False, | |
3062 | sharedfiles=False, |
|
3062 | sharedfiles=False, | |
3063 | revisionscount=False, |
|
3063 | revisionscount=False, | |
3064 | trackedsize=False, |
|
3064 | trackedsize=False, | |
3065 | storedsize=False, |
|
3065 | storedsize=False, | |
3066 | ): |
|
3066 | ): | |
3067 | d = {} |
|
3067 | d = {} | |
3068 |
|
3068 | |||
3069 | if exclusivefiles: |
|
3069 | if exclusivefiles: | |
3070 | d[b'exclusivefiles'] = [(self.opener, self.indexfile)] |
|
3070 | d[b'exclusivefiles'] = [(self.opener, self.indexfile)] | |
3071 | if not self._inline: |
|
3071 | if not self._inline: | |
3072 | d[b'exclusivefiles'].append((self.opener, self.datafile)) |
|
3072 | d[b'exclusivefiles'].append((self.opener, self.datafile)) | |
3073 |
|
3073 | |||
3074 | if sharedfiles: |
|
3074 | if sharedfiles: | |
3075 | d[b'sharedfiles'] = [] |
|
3075 | d[b'sharedfiles'] = [] | |
3076 |
|
3076 | |||
3077 | if revisionscount: |
|
3077 | if revisionscount: | |
3078 | d[b'revisionscount'] = len(self) |
|
3078 | d[b'revisionscount'] = len(self) | |
3079 |
|
3079 | |||
3080 | if trackedsize: |
|
3080 | if trackedsize: | |
3081 | d[b'trackedsize'] = sum(map(self.rawsize, iter(self))) |
|
3081 | d[b'trackedsize'] = sum(map(self.rawsize, iter(self))) | |
3082 |
|
3082 | |||
3083 | if storedsize: |
|
3083 | if storedsize: | |
3084 | d[b'storedsize'] = sum( |
|
3084 | d[b'storedsize'] = sum( | |
3085 | self.opener.stat(path).st_size for path in self.files() |
|
3085 | self.opener.stat(path).st_size for path in self.files() | |
3086 | ) |
|
3086 | ) | |
3087 |
|
3087 | |||
3088 | return d |
|
3088 | return d | |
3089 |
|
3089 | |||
3090 | def rewrite_sidedata(self, helpers, startrev, endrev): |
|
3090 | def rewrite_sidedata(self, helpers, startrev, endrev): | |
3091 | if self.version & 0xFFFF != REVLOGV2: |
|
3091 | if self.version & 0xFFFF != REVLOGV2: | |
3092 | return |
|
3092 | return | |
3093 | # inline are not yet supported because they suffer from an issue when |
|
3093 | # inline are not yet supported because they suffer from an issue when | |
3094 | # rewriting them (since it's not an append-only operation). |
|
3094 | # rewriting them (since it's not an append-only operation). | |
3095 | # See issue6485. |
|
3095 | # See issue6485. | |
3096 | assert not self._inline |
|
3096 | assert not self._inline | |
3097 | if not helpers[1] and not helpers[2]: |
|
3097 | if not helpers[1] and not helpers[2]: | |
3098 | # Nothing to generate or remove |
|
3098 | # Nothing to generate or remove | |
3099 | return |
|
3099 | return | |
3100 |
|
3100 | |||
3101 | new_entries = [] |
|
3101 | new_entries = [] | |
3102 | # append the new sidedata |
|
3102 | # append the new sidedata | |
3103 | with self._datafp(b'a+') as fp: |
|
3103 | with self._datafp(b'a+') as fp: | |
3104 | # Maybe this bug still exists, see revlog._writeentry |
|
3104 | # Maybe this bug still exists, see revlog._writeentry | |
3105 | fp.seek(0, os.SEEK_END) |
|
3105 | fp.seek(0, os.SEEK_END) | |
3106 | current_offset = fp.tell() |
|
3106 | current_offset = fp.tell() | |
3107 | for rev in range(startrev, endrev + 1): |
|
3107 | for rev in range(startrev, endrev + 1): | |
3108 | entry = self.index[rev] |
|
3108 | entry = self.index[rev] | |
3109 | new_sidedata = storageutil.run_sidedata_helpers( |
|
3109 | new_sidedata = storageutil.run_sidedata_helpers( | |
3110 | store=self, |
|
3110 | store=self, | |
3111 | sidedata_helpers=helpers, |
|
3111 | sidedata_helpers=helpers, | |
3112 | sidedata={}, |
|
3112 | sidedata={}, | |
3113 | rev=rev, |
|
3113 | rev=rev, | |
3114 | ) |
|
3114 | ) | |
3115 |
|
3115 | |||
3116 | serialized_sidedata = sidedatautil.serialize_sidedata( |
|
3116 | serialized_sidedata = sidedatautil.serialize_sidedata( | |
3117 | new_sidedata |
|
3117 | new_sidedata | |
3118 | ) |
|
3118 | ) | |
3119 | if entry[8] != 0 or entry[9] != 0: |
|
3119 | if entry[8] != 0 or entry[9] != 0: | |
3120 | # rewriting entries that already have sidedata is not |
|
3120 | # rewriting entries that already have sidedata is not | |
3121 | # supported yet, because it introduces garbage data in the |
|
3121 | # supported yet, because it introduces garbage data in the | |
3122 | # revlog. |
|
3122 | # revlog. | |
3123 | msg = b"Rewriting existing sidedata is not supported yet" |
|
3123 | msg = b"Rewriting existing sidedata is not supported yet" | |
3124 | raise error.Abort(msg) |
|
3124 | raise error.Abort(msg) | |
3125 | entry = entry[:8] |
|
3125 | entry = entry[:8] | |
3126 | entry += (current_offset, len(serialized_sidedata)) |
|
3126 | entry += (current_offset, len(serialized_sidedata)) | |
3127 |
|
3127 | |||
3128 | fp.write(serialized_sidedata) |
|
3128 | fp.write(serialized_sidedata) | |
3129 | new_entries.append(entry) |
|
3129 | new_entries.append(entry) | |
3130 | current_offset += len(serialized_sidedata) |
|
3130 | current_offset += len(serialized_sidedata) | |
3131 |
|
3131 | |||
3132 | # rewrite the new index entries |
|
3132 | # rewrite the new index entries | |
3133 | with self._indexfp(b'w+') as fp: |
|
3133 | with self._indexfp(b'w+') as fp: | |
3134 | fp.seek(startrev * self.index.entry_size) |
|
3134 | fp.seek(startrev * self.index.entry_size) | |
3135 | for i, entry in enumerate(new_entries): |
|
3135 | for i, entry in enumerate(new_entries): | |
3136 | rev = startrev + i |
|
3136 | rev = startrev + i | |
3137 | self.index.replace_sidedata_info(rev, entry[8], entry[9]) |
|
3137 | self.index.replace_sidedata_info(rev, entry[8], entry[9]) | |
3138 | packed = self.index.entry_binary(rev) |
|
3138 | packed = self.index.entry_binary(rev) | |
3139 | if rev == 0: |
|
3139 | if rev == 0: | |
3140 | header = self.index.pack_header(self.version) |
|
3140 | header = self.index.pack_header(self.version) | |
3141 | packed = header + packed |
|
3141 | packed = header + packed | |
3142 | fp.write(packed) |
|
3142 | fp.write(packed) |
General Comments 0
You need to be logged in to leave comments.
Login now