Show More
@@ -1,378 +1,378 b'' | |||||
1 | # debugcommands.py - debug logic for remotefilelog |
|
1 | # debugcommands.py - debug logic for remotefilelog | |
2 | # |
|
2 | # | |
3 | # Copyright 2013 Facebook, Inc. |
|
3 | # Copyright 2013 Facebook, Inc. | |
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 | from __future__ import absolute_import |
|
7 | from __future__ import absolute_import | |
8 |
|
8 | |||
9 | import hashlib |
|
9 | import hashlib | |
10 | import os |
|
10 | import os | |
11 | import zlib |
|
11 | import zlib | |
12 |
|
12 | |||
13 | from mercurial.node import bin, hex, nullid, short |
|
13 | from mercurial.node import bin, hex, nullid, short | |
14 | from mercurial.i18n import _ |
|
14 | from mercurial.i18n import _ | |
15 | from mercurial import ( |
|
15 | from mercurial import ( | |
16 | error, |
|
16 | error, | |
17 | filelog, |
|
17 | filelog, | |
18 | node as nodemod, |
|
18 | node as nodemod, | |
19 | revlog, |
|
19 | revlog, | |
20 | ) |
|
20 | ) | |
21 | from . import ( |
|
21 | from . import ( | |
22 | constants, |
|
22 | constants, | |
23 | datapack, |
|
23 | datapack, | |
24 | extutil, |
|
24 | extutil, | |
25 | fileserverclient, |
|
25 | fileserverclient, | |
26 | historypack, |
|
26 | historypack, | |
27 | repack, |
|
27 | repack, | |
28 | shallowutil, |
|
28 | shallowutil, | |
29 | ) |
|
29 | ) | |
30 |
|
30 | |||
31 | def debugremotefilelog(ui, path, **opts): |
|
31 | def debugremotefilelog(ui, path, **opts): | |
32 | decompress = opts.get(r'decompress') |
|
32 | decompress = opts.get(r'decompress') | |
33 |
|
33 | |||
34 | size, firstnode, mapping = parsefileblob(path, decompress) |
|
34 | size, firstnode, mapping = parsefileblob(path, decompress) | |
35 |
|
35 | |||
36 |
ui.status(_("size: % |
|
36 | ui.status(_("size: %d bytes\n") % (size)) | |
37 | ui.status(_("path: %s \n") % (path)) |
|
37 | ui.status(_("path: %s \n") % (path)) | |
38 | ui.status(_("key: %s \n") % (short(firstnode))) |
|
38 | ui.status(_("key: %s \n") % (short(firstnode))) | |
39 | ui.status(_("\n")) |
|
39 | ui.status(_("\n")) | |
40 | ui.status(_("%12s => %12s %13s %13s %12s\n") % |
|
40 | ui.status(_("%12s => %12s %13s %13s %12s\n") % | |
41 | ("node", "p1", "p2", "linknode", "copyfrom")) |
|
41 | ("node", "p1", "p2", "linknode", "copyfrom")) | |
42 |
|
42 | |||
43 | queue = [firstnode] |
|
43 | queue = [firstnode] | |
44 | while queue: |
|
44 | while queue: | |
45 | node = queue.pop(0) |
|
45 | node = queue.pop(0) | |
46 | p1, p2, linknode, copyfrom = mapping[node] |
|
46 | p1, p2, linknode, copyfrom = mapping[node] | |
47 | ui.status(_("%s => %s %s %s %s\n") % |
|
47 | ui.status(_("%s => %s %s %s %s\n") % | |
48 | (short(node), short(p1), short(p2), short(linknode), copyfrom)) |
|
48 | (short(node), short(p1), short(p2), short(linknode), copyfrom)) | |
49 | if p1 != nullid: |
|
49 | if p1 != nullid: | |
50 | queue.append(p1) |
|
50 | queue.append(p1) | |
51 | if p2 != nullid: |
|
51 | if p2 != nullid: | |
52 | queue.append(p2) |
|
52 | queue.append(p2) | |
53 |
|
53 | |||
54 | def buildtemprevlog(repo, file): |
|
54 | def buildtemprevlog(repo, file): | |
55 | # get filename key |
|
55 | # get filename key | |
56 | filekey = nodemod.hex(hashlib.sha1(file).digest()) |
|
56 | filekey = nodemod.hex(hashlib.sha1(file).digest()) | |
57 | filedir = os.path.join(repo.path, 'store/data', filekey) |
|
57 | filedir = os.path.join(repo.path, 'store/data', filekey) | |
58 |
|
58 | |||
59 | # sort all entries based on linkrev |
|
59 | # sort all entries based on linkrev | |
60 | fctxs = [] |
|
60 | fctxs = [] | |
61 | for filenode in os.listdir(filedir): |
|
61 | for filenode in os.listdir(filedir): | |
62 | if '_old' not in filenode: |
|
62 | if '_old' not in filenode: | |
63 | fctxs.append(repo.filectx(file, fileid=bin(filenode))) |
|
63 | fctxs.append(repo.filectx(file, fileid=bin(filenode))) | |
64 |
|
64 | |||
65 | fctxs = sorted(fctxs, key=lambda x: x.linkrev()) |
|
65 | fctxs = sorted(fctxs, key=lambda x: x.linkrev()) | |
66 |
|
66 | |||
67 | # add to revlog |
|
67 | # add to revlog | |
68 | temppath = repo.sjoin('data/temprevlog.i') |
|
68 | temppath = repo.sjoin('data/temprevlog.i') | |
69 | if os.path.exists(temppath): |
|
69 | if os.path.exists(temppath): | |
70 | os.remove(temppath) |
|
70 | os.remove(temppath) | |
71 | r = filelog.filelog(repo.svfs, 'temprevlog') |
|
71 | r = filelog.filelog(repo.svfs, 'temprevlog') | |
72 |
|
72 | |||
73 | class faket(object): |
|
73 | class faket(object): | |
74 | def add(self, a, b, c): |
|
74 | def add(self, a, b, c): | |
75 | pass |
|
75 | pass | |
76 | t = faket() |
|
76 | t = faket() | |
77 | for fctx in fctxs: |
|
77 | for fctx in fctxs: | |
78 | if fctx.node() not in repo: |
|
78 | if fctx.node() not in repo: | |
79 | continue |
|
79 | continue | |
80 |
|
80 | |||
81 | p = fctx.filelog().parents(fctx.filenode()) |
|
81 | p = fctx.filelog().parents(fctx.filenode()) | |
82 | meta = {} |
|
82 | meta = {} | |
83 | if fctx.renamed(): |
|
83 | if fctx.renamed(): | |
84 | meta['copy'] = fctx.renamed()[0] |
|
84 | meta['copy'] = fctx.renamed()[0] | |
85 | meta['copyrev'] = hex(fctx.renamed()[1]) |
|
85 | meta['copyrev'] = hex(fctx.renamed()[1]) | |
86 |
|
86 | |||
87 | r.add(fctx.data(), meta, t, fctx.linkrev(), p[0], p[1]) |
|
87 | r.add(fctx.data(), meta, t, fctx.linkrev(), p[0], p[1]) | |
88 |
|
88 | |||
89 | return r |
|
89 | return r | |
90 |
|
90 | |||
91 | def debugindex(orig, ui, repo, file_=None, **opts): |
|
91 | def debugindex(orig, ui, repo, file_=None, **opts): | |
92 | """dump the contents of an index file""" |
|
92 | """dump the contents of an index file""" | |
93 | if (opts.get(r'changelog') or |
|
93 | if (opts.get(r'changelog') or | |
94 | opts.get(r'manifest') or |
|
94 | opts.get(r'manifest') or | |
95 | opts.get(r'dir') or |
|
95 | opts.get(r'dir') or | |
96 | not shallowutil.isenabled(repo) or |
|
96 | not shallowutil.isenabled(repo) or | |
97 | not repo.shallowmatch(file_)): |
|
97 | not repo.shallowmatch(file_)): | |
98 | return orig(ui, repo, file_, **opts) |
|
98 | return orig(ui, repo, file_, **opts) | |
99 |
|
99 | |||
100 | r = buildtemprevlog(repo, file_) |
|
100 | r = buildtemprevlog(repo, file_) | |
101 |
|
101 | |||
102 | # debugindex like normal |
|
102 | # debugindex like normal | |
103 | format = opts.get('format', 0) |
|
103 | format = opts.get('format', 0) | |
104 | if format not in (0, 1): |
|
104 | if format not in (0, 1): | |
105 | raise error.Abort(_("unknown format %d") % format) |
|
105 | raise error.Abort(_("unknown format %d") % format) | |
106 |
|
106 | |||
107 | generaldelta = r.version & revlog.FLAG_GENERALDELTA |
|
107 | generaldelta = r.version & revlog.FLAG_GENERALDELTA | |
108 | if generaldelta: |
|
108 | if generaldelta: | |
109 | basehdr = ' delta' |
|
109 | basehdr = ' delta' | |
110 | else: |
|
110 | else: | |
111 | basehdr = ' base' |
|
111 | basehdr = ' base' | |
112 |
|
112 | |||
113 | if format == 0: |
|
113 | if format == 0: | |
114 | ui.write((" rev offset length " + basehdr + " linkrev" |
|
114 | ui.write((" rev offset length " + basehdr + " linkrev" | |
115 | " nodeid p1 p2\n")) |
|
115 | " nodeid p1 p2\n")) | |
116 | elif format == 1: |
|
116 | elif format == 1: | |
117 | ui.write((" rev flag offset length" |
|
117 | ui.write((" rev flag offset length" | |
118 | " size " + basehdr + " link p1 p2" |
|
118 | " size " + basehdr + " link p1 p2" | |
119 | " nodeid\n")) |
|
119 | " nodeid\n")) | |
120 |
|
120 | |||
121 | for i in r: |
|
121 | for i in r: | |
122 | node = r.node(i) |
|
122 | node = r.node(i) | |
123 | if generaldelta: |
|
123 | if generaldelta: | |
124 | base = r.deltaparent(i) |
|
124 | base = r.deltaparent(i) | |
125 | else: |
|
125 | else: | |
126 | base = r.chainbase(i) |
|
126 | base = r.chainbase(i) | |
127 | if format == 0: |
|
127 | if format == 0: | |
128 | try: |
|
128 | try: | |
129 | pp = r.parents(node) |
|
129 | pp = r.parents(node) | |
130 | except Exception: |
|
130 | except Exception: | |
131 | pp = [nullid, nullid] |
|
131 | pp = [nullid, nullid] | |
132 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( |
|
132 | ui.write("% 6d % 9d % 7d % 6d % 7d %s %s %s\n" % ( | |
133 | i, r.start(i), r.length(i), base, r.linkrev(i), |
|
133 | i, r.start(i), r.length(i), base, r.linkrev(i), | |
134 | short(node), short(pp[0]), short(pp[1]))) |
|
134 | short(node), short(pp[0]), short(pp[1]))) | |
135 | elif format == 1: |
|
135 | elif format == 1: | |
136 | pr = r.parentrevs(i) |
|
136 | pr = r.parentrevs(i) | |
137 | ui.write("% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d % 6d %s\n" % ( |
|
137 | ui.write("% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d % 6d %s\n" % ( | |
138 | i, r.flags(i), r.start(i), r.length(i), r.rawsize(i), |
|
138 | i, r.flags(i), r.start(i), r.length(i), r.rawsize(i), | |
139 | base, r.linkrev(i), pr[0], pr[1], short(node))) |
|
139 | base, r.linkrev(i), pr[0], pr[1], short(node))) | |
140 |
|
140 | |||
141 | def debugindexdot(orig, ui, repo, file_): |
|
141 | def debugindexdot(orig, ui, repo, file_): | |
142 | """dump an index DAG as a graphviz dot file""" |
|
142 | """dump an index DAG as a graphviz dot file""" | |
143 | if not shallowutil.isenabled(repo): |
|
143 | if not shallowutil.isenabled(repo): | |
144 | return orig(ui, repo, file_) |
|
144 | return orig(ui, repo, file_) | |
145 |
|
145 | |||
146 | r = buildtemprevlog(repo, os.path.basename(file_)[:-2]) |
|
146 | r = buildtemprevlog(repo, os.path.basename(file_)[:-2]) | |
147 |
|
147 | |||
148 | ui.write(("digraph G {\n")) |
|
148 | ui.write(("digraph G {\n")) | |
149 | for i in r: |
|
149 | for i in r: | |
150 | node = r.node(i) |
|
150 | node = r.node(i) | |
151 | pp = r.parents(node) |
|
151 | pp = r.parents(node) | |
152 | ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) |
|
152 | ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i)) | |
153 | if pp[1] != nullid: |
|
153 | if pp[1] != nullid: | |
154 | ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) |
|
154 | ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i)) | |
155 | ui.write("}\n") |
|
155 | ui.write("}\n") | |
156 |
|
156 | |||
157 | def verifyremotefilelog(ui, path, **opts): |
|
157 | def verifyremotefilelog(ui, path, **opts): | |
158 | decompress = opts.get(r'decompress') |
|
158 | decompress = opts.get(r'decompress') | |
159 |
|
159 | |||
160 | for root, dirs, files in os.walk(path): |
|
160 | for root, dirs, files in os.walk(path): | |
161 | for file in files: |
|
161 | for file in files: | |
162 | if file == "repos": |
|
162 | if file == "repos": | |
163 | continue |
|
163 | continue | |
164 | filepath = os.path.join(root, file) |
|
164 | filepath = os.path.join(root, file) | |
165 | size, firstnode, mapping = parsefileblob(filepath, decompress) |
|
165 | size, firstnode, mapping = parsefileblob(filepath, decompress) | |
166 | for p1, p2, linknode, copyfrom in mapping.itervalues(): |
|
166 | for p1, p2, linknode, copyfrom in mapping.itervalues(): | |
167 | if linknode == nullid: |
|
167 | if linknode == nullid: | |
168 | actualpath = os.path.relpath(root, path) |
|
168 | actualpath = os.path.relpath(root, path) | |
169 | key = fileserverclient.getcachekey("reponame", actualpath, |
|
169 | key = fileserverclient.getcachekey("reponame", actualpath, | |
170 | file) |
|
170 | file) | |
171 | ui.status("%s %s\n" % (key, os.path.relpath(filepath, |
|
171 | ui.status("%s %s\n" % (key, os.path.relpath(filepath, | |
172 | path))) |
|
172 | path))) | |
173 |
|
173 | |||
174 | def _decompressblob(raw): |
|
174 | def _decompressblob(raw): | |
175 | return zlib.decompress(raw) |
|
175 | return zlib.decompress(raw) | |
176 |
|
176 | |||
177 | def parsefileblob(path, decompress): |
|
177 | def parsefileblob(path, decompress): | |
178 | raw = None |
|
178 | raw = None | |
179 | f = open(path, "rb") |
|
179 | f = open(path, "rb") | |
180 | try: |
|
180 | try: | |
181 | raw = f.read() |
|
181 | raw = f.read() | |
182 | finally: |
|
182 | finally: | |
183 | f.close() |
|
183 | f.close() | |
184 |
|
184 | |||
185 | if decompress: |
|
185 | if decompress: | |
186 | raw = _decompressblob(raw) |
|
186 | raw = _decompressblob(raw) | |
187 |
|
187 | |||
188 | offset, size, flags = shallowutil.parsesizeflags(raw) |
|
188 | offset, size, flags = shallowutil.parsesizeflags(raw) | |
189 | start = offset + size |
|
189 | start = offset + size | |
190 |
|
190 | |||
191 | firstnode = None |
|
191 | firstnode = None | |
192 |
|
192 | |||
193 | mapping = {} |
|
193 | mapping = {} | |
194 | while start < len(raw): |
|
194 | while start < len(raw): | |
195 | divider = raw.index('\0', start + 80) |
|
195 | divider = raw.index('\0', start + 80) | |
196 |
|
196 | |||
197 | currentnode = raw[start:(start + 20)] |
|
197 | currentnode = raw[start:(start + 20)] | |
198 | if not firstnode: |
|
198 | if not firstnode: | |
199 | firstnode = currentnode |
|
199 | firstnode = currentnode | |
200 |
|
200 | |||
201 | p1 = raw[(start + 20):(start + 40)] |
|
201 | p1 = raw[(start + 20):(start + 40)] | |
202 | p2 = raw[(start + 40):(start + 60)] |
|
202 | p2 = raw[(start + 40):(start + 60)] | |
203 | linknode = raw[(start + 60):(start + 80)] |
|
203 | linknode = raw[(start + 60):(start + 80)] | |
204 | copyfrom = raw[(start + 80):divider] |
|
204 | copyfrom = raw[(start + 80):divider] | |
205 |
|
205 | |||
206 | mapping[currentnode] = (p1, p2, linknode, copyfrom) |
|
206 | mapping[currentnode] = (p1, p2, linknode, copyfrom) | |
207 | start = divider + 1 |
|
207 | start = divider + 1 | |
208 |
|
208 | |||
209 | return size, firstnode, mapping |
|
209 | return size, firstnode, mapping | |
210 |
|
210 | |||
211 | def debugdatapack(ui, *paths, **opts): |
|
211 | def debugdatapack(ui, *paths, **opts): | |
212 | for path in paths: |
|
212 | for path in paths: | |
213 | if '.data' in path: |
|
213 | if '.data' in path: | |
214 | path = path[:path.index('.data')] |
|
214 | path = path[:path.index('.data')] | |
215 | ui.write("%s:\n" % path) |
|
215 | ui.write("%s:\n" % path) | |
216 | dpack = datapack.datapack(path) |
|
216 | dpack = datapack.datapack(path) | |
217 | node = opts.get(r'node') |
|
217 | node = opts.get(r'node') | |
218 | if node: |
|
218 | if node: | |
219 | deltachain = dpack.getdeltachain('', bin(node)) |
|
219 | deltachain = dpack.getdeltachain('', bin(node)) | |
220 | dumpdeltachain(ui, deltachain, **opts) |
|
220 | dumpdeltachain(ui, deltachain, **opts) | |
221 | return |
|
221 | return | |
222 |
|
222 | |||
223 | if opts.get(r'long'): |
|
223 | if opts.get(r'long'): | |
224 | hashformatter = hex |
|
224 | hashformatter = hex | |
225 | hashlen = 42 |
|
225 | hashlen = 42 | |
226 | else: |
|
226 | else: | |
227 | hashformatter = short |
|
227 | hashformatter = short | |
228 | hashlen = 14 |
|
228 | hashlen = 14 | |
229 |
|
229 | |||
230 | lastfilename = None |
|
230 | lastfilename = None | |
231 | totaldeltasize = 0 |
|
231 | totaldeltasize = 0 | |
232 | totalblobsize = 0 |
|
232 | totalblobsize = 0 | |
233 | def printtotals(): |
|
233 | def printtotals(): | |
234 | if lastfilename is not None: |
|
234 | if lastfilename is not None: | |
235 | ui.write("\n") |
|
235 | ui.write("\n") | |
236 | if not totaldeltasize or not totalblobsize: |
|
236 | if not totaldeltasize or not totalblobsize: | |
237 | return |
|
237 | return | |
238 | difference = totalblobsize - totaldeltasize |
|
238 | difference = totalblobsize - totaldeltasize | |
239 | deltastr = "%0.1f%% %s" % ( |
|
239 | deltastr = "%0.1f%% %s" % ( | |
240 | (100.0 * abs(difference) / totalblobsize), |
|
240 | (100.0 * abs(difference) / totalblobsize), | |
241 | ("smaller" if difference > 0 else "bigger")) |
|
241 | ("smaller" if difference > 0 else "bigger")) | |
242 |
|
242 | |||
243 | ui.write(("Total:%s%s %s (%s)\n") % ( |
|
243 | ui.write(("Total:%s%s %s (%s)\n") % ( | |
244 | "".ljust(2 * hashlen - len("Total:")), |
|
244 | "".ljust(2 * hashlen - len("Total:")), | |
245 | str(totaldeltasize).ljust(12), |
|
245 | str(totaldeltasize).ljust(12), | |
246 | str(totalblobsize).ljust(9), |
|
246 | str(totalblobsize).ljust(9), | |
247 | deltastr |
|
247 | deltastr | |
248 | )) |
|
248 | )) | |
249 |
|
249 | |||
250 | bases = {} |
|
250 | bases = {} | |
251 | nodes = set() |
|
251 | nodes = set() | |
252 | failures = 0 |
|
252 | failures = 0 | |
253 | for filename, node, deltabase, deltalen in dpack.iterentries(): |
|
253 | for filename, node, deltabase, deltalen in dpack.iterentries(): | |
254 | bases[node] = deltabase |
|
254 | bases[node] = deltabase | |
255 | if node in nodes: |
|
255 | if node in nodes: | |
256 | ui.write(("Bad entry: %s appears twice\n" % short(node))) |
|
256 | ui.write(("Bad entry: %s appears twice\n" % short(node))) | |
257 | failures += 1 |
|
257 | failures += 1 | |
258 | nodes.add(node) |
|
258 | nodes.add(node) | |
259 | if filename != lastfilename: |
|
259 | if filename != lastfilename: | |
260 | printtotals() |
|
260 | printtotals() | |
261 | name = '(empty name)' if filename == '' else filename |
|
261 | name = '(empty name)' if filename == '' else filename | |
262 | ui.write("%s:\n" % name) |
|
262 | ui.write("%s:\n" % name) | |
263 | ui.write("%s%s%s%s\n" % ( |
|
263 | ui.write("%s%s%s%s\n" % ( | |
264 | "Node".ljust(hashlen), |
|
264 | "Node".ljust(hashlen), | |
265 | "Delta Base".ljust(hashlen), |
|
265 | "Delta Base".ljust(hashlen), | |
266 | "Delta Length".ljust(14), |
|
266 | "Delta Length".ljust(14), | |
267 | "Blob Size".ljust(9))) |
|
267 | "Blob Size".ljust(9))) | |
268 | lastfilename = filename |
|
268 | lastfilename = filename | |
269 | totalblobsize = 0 |
|
269 | totalblobsize = 0 | |
270 | totaldeltasize = 0 |
|
270 | totaldeltasize = 0 | |
271 |
|
271 | |||
272 | # Metadata could be missing, in which case it will be an empty dict. |
|
272 | # Metadata could be missing, in which case it will be an empty dict. | |
273 | meta = dpack.getmeta(filename, node) |
|
273 | meta = dpack.getmeta(filename, node) | |
274 | if constants.METAKEYSIZE in meta: |
|
274 | if constants.METAKEYSIZE in meta: | |
275 | blobsize = meta[constants.METAKEYSIZE] |
|
275 | blobsize = meta[constants.METAKEYSIZE] | |
276 | totaldeltasize += deltalen |
|
276 | totaldeltasize += deltalen | |
277 | totalblobsize += blobsize |
|
277 | totalblobsize += blobsize | |
278 | else: |
|
278 | else: | |
279 | blobsize = "(missing)" |
|
279 | blobsize = "(missing)" | |
280 | ui.write("%s %s %s%s\n" % ( |
|
280 | ui.write("%s %s %s%s\n" % ( | |
281 | hashformatter(node), |
|
281 | hashformatter(node), | |
282 | hashformatter(deltabase), |
|
282 | hashformatter(deltabase), | |
283 | str(deltalen).ljust(14), |
|
283 | str(deltalen).ljust(14), | |
284 | blobsize)) |
|
284 | blobsize)) | |
285 |
|
285 | |||
286 | if filename is not None: |
|
286 | if filename is not None: | |
287 | printtotals() |
|
287 | printtotals() | |
288 |
|
288 | |||
289 | failures += _sanitycheck(ui, set(nodes), bases) |
|
289 | failures += _sanitycheck(ui, set(nodes), bases) | |
290 | if failures > 1: |
|
290 | if failures > 1: | |
291 | ui.warn(("%d failures\n" % failures)) |
|
291 | ui.warn(("%d failures\n" % failures)) | |
292 | return 1 |
|
292 | return 1 | |
293 |
|
293 | |||
294 | def _sanitycheck(ui, nodes, bases): |
|
294 | def _sanitycheck(ui, nodes, bases): | |
295 | """ |
|
295 | """ | |
296 | Does some basic sanity checking on a packfiles with ``nodes`` ``bases`` (a |
|
296 | Does some basic sanity checking on a packfiles with ``nodes`` ``bases`` (a | |
297 | mapping of node->base): |
|
297 | mapping of node->base): | |
298 |
|
298 | |||
299 | - Each deltabase must itself be a node elsewhere in the pack |
|
299 | - Each deltabase must itself be a node elsewhere in the pack | |
300 | - There must be no cycles |
|
300 | - There must be no cycles | |
301 | """ |
|
301 | """ | |
302 | failures = 0 |
|
302 | failures = 0 | |
303 | for node in nodes: |
|
303 | for node in nodes: | |
304 | seen = set() |
|
304 | seen = set() | |
305 | current = node |
|
305 | current = node | |
306 | deltabase = bases[current] |
|
306 | deltabase = bases[current] | |
307 |
|
307 | |||
308 | while deltabase != nullid: |
|
308 | while deltabase != nullid: | |
309 | if deltabase not in nodes: |
|
309 | if deltabase not in nodes: | |
310 | ui.warn(("Bad entry: %s has an unknown deltabase (%s)\n" % |
|
310 | ui.warn(("Bad entry: %s has an unknown deltabase (%s)\n" % | |
311 | (short(node), short(deltabase)))) |
|
311 | (short(node), short(deltabase)))) | |
312 | failures += 1 |
|
312 | failures += 1 | |
313 | break |
|
313 | break | |
314 |
|
314 | |||
315 | if deltabase in seen: |
|
315 | if deltabase in seen: | |
316 | ui.warn(("Bad entry: %s has a cycle (at %s)\n" % |
|
316 | ui.warn(("Bad entry: %s has a cycle (at %s)\n" % | |
317 | (short(node), short(deltabase)))) |
|
317 | (short(node), short(deltabase)))) | |
318 | failures += 1 |
|
318 | failures += 1 | |
319 | break |
|
319 | break | |
320 |
|
320 | |||
321 | current = deltabase |
|
321 | current = deltabase | |
322 | seen.add(current) |
|
322 | seen.add(current) | |
323 | deltabase = bases[current] |
|
323 | deltabase = bases[current] | |
324 | # Since ``node`` begins a valid chain, reset/memoize its base to nullid |
|
324 | # Since ``node`` begins a valid chain, reset/memoize its base to nullid | |
325 | # so we don't traverse it again. |
|
325 | # so we don't traverse it again. | |
326 | bases[node] = nullid |
|
326 | bases[node] = nullid | |
327 | return failures |
|
327 | return failures | |
328 |
|
328 | |||
329 | def dumpdeltachain(ui, deltachain, **opts): |
|
329 | def dumpdeltachain(ui, deltachain, **opts): | |
330 | hashformatter = hex |
|
330 | hashformatter = hex | |
331 | hashlen = 40 |
|
331 | hashlen = 40 | |
332 |
|
332 | |||
333 | lastfilename = None |
|
333 | lastfilename = None | |
334 | for filename, node, filename, deltabasenode, delta in deltachain: |
|
334 | for filename, node, filename, deltabasenode, delta in deltachain: | |
335 | if filename != lastfilename: |
|
335 | if filename != lastfilename: | |
336 | ui.write("\n%s\n" % filename) |
|
336 | ui.write("\n%s\n" % filename) | |
337 | lastfilename = filename |
|
337 | lastfilename = filename | |
338 | ui.write("%s %s %s %s\n" % ( |
|
338 | ui.write("%s %s %s %s\n" % ( | |
339 | "Node".ljust(hashlen), |
|
339 | "Node".ljust(hashlen), | |
340 | "Delta Base".ljust(hashlen), |
|
340 | "Delta Base".ljust(hashlen), | |
341 | "Delta SHA1".ljust(hashlen), |
|
341 | "Delta SHA1".ljust(hashlen), | |
342 | "Delta Length".ljust(6), |
|
342 | "Delta Length".ljust(6), | |
343 | )) |
|
343 | )) | |
344 |
|
344 | |||
345 | ui.write("%s %s %s %s\n" % ( |
|
345 | ui.write("%s %s %s %s\n" % ( | |
346 | hashformatter(node), |
|
346 | hashformatter(node), | |
347 | hashformatter(deltabasenode), |
|
347 | hashformatter(deltabasenode), | |
348 | nodemod.hex(hashlib.sha1(delta).digest()), |
|
348 | nodemod.hex(hashlib.sha1(delta).digest()), | |
349 | len(delta))) |
|
349 | len(delta))) | |
350 |
|
350 | |||
351 | def debughistorypack(ui, path): |
|
351 | def debughistorypack(ui, path): | |
352 | if '.hist' in path: |
|
352 | if '.hist' in path: | |
353 | path = path[:path.index('.hist')] |
|
353 | path = path[:path.index('.hist')] | |
354 | hpack = historypack.historypack(path) |
|
354 | hpack = historypack.historypack(path) | |
355 |
|
355 | |||
356 | lastfilename = None |
|
356 | lastfilename = None | |
357 | for entry in hpack.iterentries(): |
|
357 | for entry in hpack.iterentries(): | |
358 | filename, node, p1node, p2node, linknode, copyfrom = entry |
|
358 | filename, node, p1node, p2node, linknode, copyfrom = entry | |
359 | if filename != lastfilename: |
|
359 | if filename != lastfilename: | |
360 | ui.write("\n%s\n" % filename) |
|
360 | ui.write("\n%s\n" % filename) | |
361 | ui.write("%s%s%s%s%s\n" % ( |
|
361 | ui.write("%s%s%s%s%s\n" % ( | |
362 | "Node".ljust(14), |
|
362 | "Node".ljust(14), | |
363 | "P1 Node".ljust(14), |
|
363 | "P1 Node".ljust(14), | |
364 | "P2 Node".ljust(14), |
|
364 | "P2 Node".ljust(14), | |
365 | "Link Node".ljust(14), |
|
365 | "Link Node".ljust(14), | |
366 | "Copy From")) |
|
366 | "Copy From")) | |
367 | lastfilename = filename |
|
367 | lastfilename = filename | |
368 | ui.write("%s %s %s %s %s\n" % (short(node), short(p1node), |
|
368 | ui.write("%s %s %s %s %s\n" % (short(node), short(p1node), | |
369 | short(p2node), short(linknode), copyfrom)) |
|
369 | short(p2node), short(linknode), copyfrom)) | |
370 |
|
370 | |||
371 | def debugwaitonrepack(repo): |
|
371 | def debugwaitonrepack(repo): | |
372 | with extutil.flock(repack.repacklockvfs(repo).join('repacklock'), ''): |
|
372 | with extutil.flock(repack.repacklockvfs(repo).join('repacklock'), ''): | |
373 | return |
|
373 | return | |
374 |
|
374 | |||
375 | def debugwaitonprefetch(repo): |
|
375 | def debugwaitonprefetch(repo): | |
376 | with repo._lock(repo.svfs, "prefetchlock", True, None, |
|
376 | with repo._lock(repo.svfs, "prefetchlock", True, None, | |
377 | None, _('prefetching in %s') % repo.origroot): |
|
377 | None, _('prefetching in %s') % repo.origroot): | |
378 | pass |
|
378 | pass |
General Comments 0
You need to be logged in to leave comments.
Login now