Mercurial > hg
annotate mercurial/utils/storageutil.py @ 40321:6994a8be3663
storageutil: convert fileid to bytes to avoid cast to %s
test-storage.py manages to trigger this on Python 3.
Differential Revision: https://phab.mercurial-scm.org/D5117
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 16 Oct 2018 17:45:39 +0200 |
parents | f5d819d84461 |
children | b0fbd1792e2d |
rev | line source |
---|---|
39877
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 # storageutil.py - Storage functionality agnostic of backend implementation. |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 # |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2018 Gregory Szorc <gregory.szorc@gmail.com> |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 # |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 from __future__ import absolute_import |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
10 import hashlib |
39878
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
11 import re |
39877
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
12 |
40002
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
13 from ..i18n import _ |
39877
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
14 from ..node import ( |
40002
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
15 bin, |
39877
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
16 nullid, |
40004
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
17 nullrev, |
39877
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
18 ) |
39881
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
19 from .. import ( |
40010
f5d819d84461
storageutil: pass nodes into emitrevisions()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40009
diff
changeset
|
20 dagop, |
40002
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
21 error, |
40009
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
22 mdiff, |
39881
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
23 pycompat, |
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
24 ) |
39877
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 _nullhash = hashlib.sha1(nullid) |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 def hashrevisionsha1(text, p1, p2): |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 """Compute the SHA-1 for revision data and its parents. |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
30 |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 This hash combines both the current file contents and its history |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 in a manner that makes it easy to distinguish nodes with the same |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 content in the revision graph. |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 """ |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 # As of now, if one of the parent node is null, p2 is null |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
36 if p2 == nullid: |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 # deep copy of a hash is faster than creating one |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 s = _nullhash.copy() |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 s.update(p1) |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 else: |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
41 # none of the parent nodes are nullid |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
42 if p1 < p2: |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
43 a = p1 |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 b = p2 |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 else: |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 a = p2 |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 b = p1 |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 s = hashlib.sha1(a) |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 s.update(b) |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 s.update(text) |
f8eb71f9e3bd
storageutil: new module for storage primitives (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 return s.digest() |
39878
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
52 |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
53 METADATA_RE = re.compile(b'\x01\n') |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
54 |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
55 def parsemeta(text): |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
56 """Parse metadata header from revision data. |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
57 |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
58 Returns a 2-tuple of (metadata, offset), where both can be None if there |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
59 is no metadata. |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
60 """ |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
61 # text can be buffer, so we can't use .startswith or .index |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
62 if text[:2] != b'\x01\n': |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
63 return None, None |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
64 s = METADATA_RE.search(text, 2).start() |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
65 mtext = text[2:s] |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
66 meta = {} |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
67 for l in mtext.splitlines(): |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
68 k, v = l.split(b': ', 1) |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
69 meta[k] = v |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
70 return meta, s + 2 |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
71 |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
72 def packmeta(meta, text): |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
73 """Add metadata to fulltext to produce revision text.""" |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
74 keys = sorted(meta) |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
75 metatext = b''.join(b'%s: %s\n' % (k, meta[k]) for k in keys) |
3e896b51aa5d
storageutil: move metadata parsing and packing from revlog (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39877
diff
changeset
|
76 return b'\x01\n%s\x01\n%s' % (metatext, text) |
39879
d269ddbf54f0
storageutil: move _censoredtext() from revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39878
diff
changeset
|
77 |
d269ddbf54f0
storageutil: move _censoredtext() from revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39878
diff
changeset
|
78 def iscensoredtext(text): |
d269ddbf54f0
storageutil: move _censoredtext() from revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39878
diff
changeset
|
79 meta = parsemeta(text)[0] |
d269ddbf54f0
storageutil: move _censoredtext() from revlog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39878
diff
changeset
|
80 return meta and b'censored' in meta |
39880
1b65fb4d43d6
storageutil: new function for extracting metadata-less content from text
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39879
diff
changeset
|
81 |
1b65fb4d43d6
storageutil: new function for extracting metadata-less content from text
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39879
diff
changeset
|
82 def filtermetadata(text): |
1b65fb4d43d6
storageutil: new function for extracting metadata-less content from text
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39879
diff
changeset
|
83 """Extract just the revision data from source text. |
1b65fb4d43d6
storageutil: new function for extracting metadata-less content from text
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39879
diff
changeset
|
84 |
1b65fb4d43d6
storageutil: new function for extracting metadata-less content from text
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39879
diff
changeset
|
85 Returns ``text`` unless it has a metadata header, in which case we return |
1b65fb4d43d6
storageutil: new function for extracting metadata-less content from text
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39879
diff
changeset
|
86 a new buffer without hte metadata. |
1b65fb4d43d6
storageutil: new function for extracting metadata-less content from text
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39879
diff
changeset
|
87 """ |
1b65fb4d43d6
storageutil: new function for extracting metadata-less content from text
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39879
diff
changeset
|
88 if not text.startswith(b'\x01\n'): |
1b65fb4d43d6
storageutil: new function for extracting metadata-less content from text
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39879
diff
changeset
|
89 return text |
1b65fb4d43d6
storageutil: new function for extracting metadata-less content from text
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39879
diff
changeset
|
90 |
1b65fb4d43d6
storageutil: new function for extracting metadata-less content from text
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39879
diff
changeset
|
91 offset = text.index(b'\x01\n', 2) |
1b65fb4d43d6
storageutil: new function for extracting metadata-less content from text
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39879
diff
changeset
|
92 return text[offset + 2:] |
39881
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
93 |
40005
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
94 def filerevisioncopied(store, node): |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
95 """Resolve file revision copy metadata. |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
96 |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
97 Returns ``False`` if the file has no copy metadata. Otherwise a |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
98 2-tuple of the source filename and node. |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
99 """ |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
100 if store.parents(node)[0] != nullid: |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
101 return False |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
102 |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
103 meta = parsemeta(store.revision(node))[0] |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
104 |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
105 # copy and copyrev occur in pairs. In rare cases due to old bugs, |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
106 # one can occur without the other. So ensure both are present to flag |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
107 # as a copy. |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
108 if meta and b'copy' in meta and b'copyrev' in meta: |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
109 return meta[b'copy'], bin(meta[b'copyrev']) |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
110 |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
111 return False |
1d97a332c6d9
storageutil: extract copy metadata retrieval out of filelog
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40004
diff
changeset
|
112 |
40007
1470183068b8
storageutil: invert logic of file data comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40006
diff
changeset
|
113 def filedataequivalent(store, node, filedata): |
1470183068b8
storageutil: invert logic of file data comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40006
diff
changeset
|
114 """Determines whether file data is equivalent to a stored node. |
1470183068b8
storageutil: invert logic of file data comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40006
diff
changeset
|
115 |
1470183068b8
storageutil: invert logic of file data comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40006
diff
changeset
|
116 Returns True if the passed file data would hash to the same value |
1470183068b8
storageutil: invert logic of file data comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40006
diff
changeset
|
117 as a stored revision and False otherwise. |
1470183068b8
storageutil: invert logic of file data comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40006
diff
changeset
|
118 |
1470183068b8
storageutil: invert logic of file data comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40006
diff
changeset
|
119 When a stored revision is censored, filedata must be empty to have |
1470183068b8
storageutil: invert logic of file data comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40006
diff
changeset
|
120 equivalence. |
1470183068b8
storageutil: invert logic of file data comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40006
diff
changeset
|
121 |
1470183068b8
storageutil: invert logic of file data comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40006
diff
changeset
|
122 When a stored revision has copy metadata, it is ignored as part |
1470183068b8
storageutil: invert logic of file data comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40006
diff
changeset
|
123 of the compare. |
1470183068b8
storageutil: invert logic of file data comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40006
diff
changeset
|
124 """ |
40006
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
125 |
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
126 if filedata.startswith(b'\x01\n'): |
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
127 revisiontext = b'\x01\n\x01\n' + filedata |
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
128 else: |
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
129 revisiontext = filedata |
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
130 |
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
131 p1, p2 = store.parents(node) |
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
132 |
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
133 computednode = hashrevisionsha1(revisiontext, p1, p2) |
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
134 |
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
135 if computednode == node: |
40007
1470183068b8
storageutil: invert logic of file data comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40006
diff
changeset
|
136 return True |
40006
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
137 |
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
138 # Censored files compare against the empty file. |
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
139 if store.iscensored(store.rev(node)): |
40007
1470183068b8
storageutil: invert logic of file data comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40006
diff
changeset
|
140 return filedata == b'' |
40006
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
141 |
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
142 # Renaming a file produces a different hash, even if the data |
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
143 # remains unchanged. Check if that's the case. |
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
144 if store.renamed(node): |
40007
1470183068b8
storageutil: invert logic of file data comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40006
diff
changeset
|
145 return store.read(node) == filedata |
40006
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
146 |
40007
1470183068b8
storageutil: invert logic of file data comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40006
diff
changeset
|
147 return False |
40006
422beffd71ba
storageutil: extract filelog.cmp() to a standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40005
diff
changeset
|
148 |
39881
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
149 def iterrevs(storelen, start=0, stop=None): |
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
150 """Iterate over revision numbers in a store.""" |
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
151 step = 1 |
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
152 |
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
153 if stop is not None: |
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
154 if start > stop: |
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
155 step = -1 |
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
156 stop += step |
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
157 if stop > storelen: |
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
158 stop = storelen |
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
159 else: |
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
160 stop = storelen |
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
161 |
d63153611ed5
storageutil: extract revision number iteration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39880
diff
changeset
|
162 return pycompat.xrange(start, stop, step) |
40002
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
163 |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
164 def fileidlookup(store, fileid, identifier): |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
165 """Resolve the file node for a value. |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
166 |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
167 ``store`` is an object implementing the ``ifileindex`` interface. |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
168 |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
169 ``fileid`` can be: |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
170 |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
171 * A 20 byte binary node. |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
172 * An integer revision number |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
173 * A 40 byte hex node. |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
174 * A bytes that can be parsed as an integer representing a revision number. |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
175 |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
176 ``identifier`` is used to populate ``error.LookupError`` with an identifier |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
177 for the store. |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
178 |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
179 Raises ``error.LookupError`` on failure. |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
180 """ |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
181 if isinstance(fileid, int): |
40003
ad8389ecd3f5
storageutil: consistently raise LookupError (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40002
diff
changeset
|
182 try: |
ad8389ecd3f5
storageutil: consistently raise LookupError (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40002
diff
changeset
|
183 return store.node(fileid) |
ad8389ecd3f5
storageutil: consistently raise LookupError (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40002
diff
changeset
|
184 except IndexError: |
40321
6994a8be3663
storageutil: convert fileid to bytes to avoid cast to %s
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40010
diff
changeset
|
185 raise error.LookupError('%d' % fileid, identifier, |
6994a8be3663
storageutil: convert fileid to bytes to avoid cast to %s
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40010
diff
changeset
|
186 _('no match found')) |
40002
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
187 |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
188 if len(fileid) == 20: |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
189 try: |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
190 store.rev(fileid) |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
191 return fileid |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
192 except error.LookupError: |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
193 pass |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
194 |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
195 if len(fileid) == 40: |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
196 try: |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
197 rawnode = bin(fileid) |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
198 store.rev(rawnode) |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
199 return rawnode |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
200 except TypeError: |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
201 pass |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
202 |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
203 try: |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
204 rev = int(fileid) |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
205 |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
206 if b'%d' % rev != fileid: |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
207 raise ValueError |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
208 |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
209 try: |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
210 return store.node(rev) |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
211 except (IndexError, TypeError): |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
212 pass |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
213 except (ValueError, OverflowError): |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
214 pass |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
215 |
0e8836be9541
storageutil: implement file identifier resolution method (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39881
diff
changeset
|
216 raise error.LookupError(fileid, identifier, _('no match found')) |
40004
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
217 |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
218 def resolvestripinfo(minlinkrev, tiprev, headrevs, linkrevfn, parentrevsfn): |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
219 """Resolve information needed to strip revisions. |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
220 |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
221 Finds the minimum revision number that must be stripped in order to |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
222 strip ``minlinkrev``. |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
223 |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
224 Returns a 2-tuple of the minimum revision number to do that and a set |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
225 of all revision numbers that have linkrevs that would be broken |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
226 by that strip. |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
227 |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
228 ``tiprev`` is the current tip-most revision. It is ``len(store) - 1``. |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
229 ``headrevs`` is an iterable of head revisions. |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
230 ``linkrevfn`` is a callable that receives a revision and returns a linked |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
231 revision. |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
232 ``parentrevsfn`` is a callable that receives a revision number and returns |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
233 an iterable of its parent revision numbers. |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
234 """ |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
235 brokenrevs = set() |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
236 strippoint = tiprev + 1 |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
237 |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
238 heads = {} |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
239 futurelargelinkrevs = set() |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
240 for head in headrevs: |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
241 headlinkrev = linkrevfn(head) |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
242 heads[head] = headlinkrev |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
243 if headlinkrev >= minlinkrev: |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
244 futurelargelinkrevs.add(headlinkrev) |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
245 |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
246 # This algorithm involves walking down the rev graph, starting at the |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
247 # heads. Since the revs are topologically sorted according to linkrev, |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
248 # once all head linkrevs are below the minlink, we know there are |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
249 # no more revs that could have a linkrev greater than minlink. |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
250 # So we can stop walking. |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
251 while futurelargelinkrevs: |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
252 strippoint -= 1 |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
253 linkrev = heads.pop(strippoint) |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
254 |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
255 if linkrev < minlinkrev: |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
256 brokenrevs.add(strippoint) |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
257 else: |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
258 futurelargelinkrevs.remove(linkrev) |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
259 |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
260 for p in parentrevsfn(strippoint): |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
261 if p != nullrev: |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
262 plinkrev = linkrevfn(p) |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
263 heads[p] = plinkrev |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
264 if plinkrev >= minlinkrev: |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
265 futurelargelinkrevs.add(plinkrev) |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
266 |
fa3dc85a747e
storageutil: extract functionality for resolving strip revisions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40003
diff
changeset
|
267 return strippoint, brokenrevs |
40008
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
268 |
40010
f5d819d84461
storageutil: pass nodes into emitrevisions()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40009
diff
changeset
|
269 def emitrevisions(store, nodes, nodesorder, resultcls, deltaparentfn=None, |
f5d819d84461
storageutil: pass nodes into emitrevisions()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40009
diff
changeset
|
270 candeltafn=None, rawsizefn=None, revdifffn=None, flagsfn=None, |
40009
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
271 sendfulltext=False, |
40008
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
272 revisiondata=False, assumehaveparentrevisions=False, |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
273 deltaprevious=False): |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
274 """Generic implementation of ifiledata.emitrevisions(). |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
275 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
276 Emitting revision data is subtly complex. This function attempts to |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
277 encapsulate all the logic for doing so in a backend-agnostic way. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
278 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
279 ``store`` |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
280 Object conforming to ``ifilestorage`` interface. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
281 |
40010
f5d819d84461
storageutil: pass nodes into emitrevisions()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40009
diff
changeset
|
282 ``nodes`` |
f5d819d84461
storageutil: pass nodes into emitrevisions()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40009
diff
changeset
|
283 List of revision nodes whose data to emit. |
40008
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
284 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
285 ``resultcls`` |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
286 A type implementing the ``irevisiondelta`` interface that will be |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
287 constructed and returned. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
288 |
40009
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
289 ``deltaparentfn`` (optional) |
40008
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
290 Callable receiving a revision number and returning the revision number |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
291 of a revision that the internal delta is stored against. This delta |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
292 will be preferred over computing a new arbitrary delta. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
293 |
40009
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
294 If not defined, a delta will always be computed from raw revision |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
295 data. |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
296 |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
297 ``candeltafn`` (optional) |
40008
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
298 Callable receiving a pair of revision numbers that returns a bool |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
299 indicating whether a delta between them can be produced. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
300 |
40009
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
301 If not defined, it is assumed that any two revisions can delta with |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
302 each other. |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
303 |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
304 ``rawsizefn`` (optional) |
40008
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
305 Callable receiving a revision number and returning the length of the |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
306 ``store.revision(rev, raw=True)``. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
307 |
40009
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
308 If not defined, ``len(store.revision(rev, raw=True))`` will be called. |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
309 |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
310 ``revdifffn`` (optional) |
40008
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
311 Callable receiving a pair of revision numbers that returns a delta |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
312 between them. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
313 |
40009
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
314 If not defined, a delta will be computed by invoking mdiff code |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
315 on ``store.revision()`` results. |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
316 |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
317 Defining this function allows a precomputed or stored delta to be |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
318 used without having to compute on. |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
319 |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
320 ``flagsfn`` (optional) |
40008
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
321 Callable receiving a revision number and returns the integer flags |
40009
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
322 value for it. If not defined, flags value will be 0. |
40008
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
323 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
324 ``sendfulltext`` |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
325 Whether to send fulltext revisions instead of deltas, if allowed. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
326 |
40010
f5d819d84461
storageutil: pass nodes into emitrevisions()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40009
diff
changeset
|
327 ``nodesorder`` |
40008
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
328 ``revisiondata`` |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
329 ``assumehaveparentrevisions`` |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
330 ``deltaprevious`` |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
331 See ``ifiledata.emitrevisions()`` interface documentation. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
332 """ |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
333 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
334 fnode = store.node |
40010
f5d819d84461
storageutil: pass nodes into emitrevisions()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40009
diff
changeset
|
335 frev = store.rev |
f5d819d84461
storageutil: pass nodes into emitrevisions()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40009
diff
changeset
|
336 |
f5d819d84461
storageutil: pass nodes into emitrevisions()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40009
diff
changeset
|
337 if nodesorder == 'nodes': |
f5d819d84461
storageutil: pass nodes into emitrevisions()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40009
diff
changeset
|
338 revs = [frev(n) for n in nodes] |
f5d819d84461
storageutil: pass nodes into emitrevisions()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40009
diff
changeset
|
339 elif nodesorder == 'storage': |
f5d819d84461
storageutil: pass nodes into emitrevisions()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40009
diff
changeset
|
340 revs = sorted(frev(n) for n in nodes) |
f5d819d84461
storageutil: pass nodes into emitrevisions()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40009
diff
changeset
|
341 else: |
f5d819d84461
storageutil: pass nodes into emitrevisions()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40009
diff
changeset
|
342 revs = set(frev(n) for n in nodes) |
f5d819d84461
storageutil: pass nodes into emitrevisions()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40009
diff
changeset
|
343 revs = dagop.linearize(revs, store.parentrevs) |
40008
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
344 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
345 prevrev = None |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
346 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
347 if deltaprevious or assumehaveparentrevisions: |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
348 prevrev = store.parentrevs(revs[0])[0] |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
349 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
350 # Set of revs available to delta against. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
351 available = set() |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
352 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
353 for rev in revs: |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
354 if rev == nullrev: |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
355 continue |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
356 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
357 node = fnode(rev) |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
358 p1rev, p2rev = store.parentrevs(rev) |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
359 |
40009
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
360 if deltaparentfn: |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
361 deltaparentrev = deltaparentfn(rev) |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
362 else: |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
363 deltaparentrev = nullrev |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
364 |
40008
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
365 # Forced delta against previous mode. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
366 if deltaprevious: |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
367 baserev = prevrev |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
368 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
369 # We're instructed to send fulltext. Honor that. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
370 elif sendfulltext: |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
371 baserev = nullrev |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
372 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
373 # There is a delta in storage. We try to use that because it |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
374 # amounts to effectively copying data from storage and is |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
375 # therefore the fastest. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
376 elif deltaparentrev != nullrev: |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
377 # Base revision was already emitted in this group. We can |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
378 # always safely use the delta. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
379 if deltaparentrev in available: |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
380 baserev = deltaparentrev |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
381 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
382 # Base revision is a parent that hasn't been emitted already. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
383 # Use it if we can assume the receiver has the parent revision. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
384 elif (assumehaveparentrevisions |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
385 and deltaparentrev in (p1rev, p2rev)): |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
386 baserev = deltaparentrev |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
387 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
388 # No guarantee the receiver has the delta parent. Send delta |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
389 # against last revision (if possible), which in the common case |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
390 # should be similar enough to this revision that the delta is |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
391 # reasonable. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
392 elif prevrev is not None: |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
393 baserev = prevrev |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
394 else: |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
395 baserev = nullrev |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
396 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
397 # Storage has a fulltext revision. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
398 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
399 # Let's use the previous revision, which is as good a guess as any. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
400 # There is definitely room to improve this logic. |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
401 elif prevrev is not None: |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
402 baserev = prevrev |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
403 else: |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
404 baserev = nullrev |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
405 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
406 # But we can't actually use our chosen delta base for whatever |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
407 # reason. Reset to fulltext. |
40009
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
408 if baserev != nullrev and (candeltafn and not candeltafn(baserev, rev)): |
40008
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
409 baserev = nullrev |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
410 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
411 revision = None |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
412 delta = None |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
413 baserevisionsize = None |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
414 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
415 if revisiondata: |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
416 if store.iscensored(baserev) or store.iscensored(rev): |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
417 try: |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
418 revision = store.revision(node, raw=True) |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
419 except error.CensoredNodeError as e: |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
420 revision = e.tombstone |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
421 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
422 if baserev != nullrev: |
40009
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
423 if rawsizefn: |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
424 baserevisionsize = rawsizefn(baserev) |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
425 else: |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
426 baserevisionsize = len(store.revision(baserev, |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
427 raw=True)) |
40008
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
428 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
429 elif baserev == nullrev and not deltaprevious: |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
430 revision = store.revision(node, raw=True) |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
431 available.add(rev) |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
432 else: |
40009
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
433 if revdifffn: |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
434 delta = revdifffn(baserev, rev) |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
435 else: |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
436 delta = mdiff.textdiff(store.revision(baserev, raw=True), |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
437 store.revision(rev, raw=True)) |
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
438 |
40008
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
439 available.add(rev) |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
440 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
441 yield resultcls( |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
442 node=node, |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
443 p1node=fnode(p1rev), |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
444 p2node=fnode(p2rev), |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
445 basenode=fnode(baserev), |
40009
631c6f5058b9
storageutil: make all callables optional
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40008
diff
changeset
|
446 flags=flagsfn(rev) if flagsfn else 0, |
40008
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
447 baserevisionsize=baserevisionsize, |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
448 revision=revision, |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
449 delta=delta) |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
450 |
842ffcf1d42f
storageutil: extract most of emitrevisions() to standalone function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40007
diff
changeset
|
451 prevrev = rev |