Show More
@@ -56,23 +56,28 class rbcrevs: | |||
|
56 | 56 | self._prefix = revs |
|
57 | 57 | self._rest = bytearray() |
|
58 | 58 | |
|
59 | @property | |
|
60 | def len_prefix(self): | |
|
61 | size = len(self._prefix) | |
|
62 | return size - (size % _rbcrecsize) | |
|
63 | ||
|
59 | 64 | def __len__(self): |
|
60 |
return |
|
|
65 | return self.len_prefix + len(self._rest) | |
|
61 | 66 | |
|
62 | 67 | def unpack_record(self, rbcrevidx): |
|
63 |
if rbcrevidx < |
|
|
68 | if rbcrevidx < self.len_prefix: | |
|
64 | 69 | return unpack_from(_rbcrecfmt, util.buffer(self._prefix), rbcrevidx) |
|
65 | 70 | else: |
|
66 | 71 | return unpack_from( |
|
67 | 72 | _rbcrecfmt, |
|
68 | 73 | util.buffer(self._rest), |
|
69 |
rbcrevidx - |
|
|
74 | rbcrevidx - self.len_prefix, | |
|
70 | 75 | ) |
|
71 | 76 | |
|
72 | 77 | def make_mutable(self): |
|
73 |
if |
|
|
78 | if self.len_prefix > 0: | |
|
74 | 79 | entirety = bytearray() |
|
75 | entirety[:] = self._prefix | |
|
80 | entirety[:] = self._prefix[: self.len_prefix] | |
|
76 | 81 | entirety.extend(self._rest) |
|
77 | 82 | self._rest = entirety |
|
78 | 83 | self._prefix = bytearray() |
@@ -82,10 +87,10 class rbcrevs: | |||
|
82 | 87 | del self._rest[pos:] |
|
83 | 88 | |
|
84 | 89 | def pack_into(self, rbcrevidx, node, branchidx): |
|
85 |
if rbcrevidx < |
|
|
90 | if rbcrevidx < self.len_prefix: | |
|
86 | 91 | self.make_mutable() |
|
87 | 92 | buf = self._rest |
|
88 |
start_offset = rbcrevidx - |
|
|
93 | start_offset = rbcrevidx - self.len_prefix | |
|
89 | 94 | end_offset = start_offset + _rbcrecsize |
|
90 | 95 | |
|
91 | 96 | if len(self._rest) < end_offset: |
@@ -107,14 +112,14 class rbcrevs: | |||
|
107 | 112 | return self._rest.extend(extension) |
|
108 | 113 | |
|
109 | 114 | def slice(self, begin, end): |
|
110 |
if begin < |
|
|
115 | if begin < self.len_prefix: | |
|
111 | 116 | acc = bytearray() |
|
112 | acc[:] = self._prefix[begin:end] | |
|
117 | acc[:] = self._prefix[begin : min(end, self.len_prefix)] | |
|
113 | 118 | acc.extend( |
|
114 |
self._rest[begin - |
|
|
119 | self._rest[begin - self.len_prefix : end - self.len_prefix] | |
|
115 | 120 | ) |
|
116 | 121 | return acc |
|
117 |
return self._rest[begin - |
|
|
122 | return self._rest[begin - self.len_prefix : end - self.len_prefix] | |
|
118 | 123 | |
|
119 | 124 | |
|
120 | 125 | class revbranchcache: |
@@ -388,6 +393,9 class revbranchcache: | |||
|
388 | 393 | if self._force_overwrite: |
|
389 | 394 | start = 0 |
|
390 | 395 | |
|
396 | # align start on entry boundary | |
|
397 | start = _rbcrecsize * (start // _rbcrecsize) | |
|
398 | ||
|
391 | 399 | with repo.cachevfs.open(_rbcrevs, b'a+b') as f: |
|
392 | 400 | pass # this make sure the file exist… |
|
393 | 401 | with repo.cachevfs.open(_rbcrevs, b'r+b') as f: |
@@ -831,15 +831,30 no errors when wlock cannot be acquired | |||
|
831 | 831 | $ mv .hg/cache/rbc-revs-v2_ .hg/cache/rbc-revs-v2 |
|
832 | 832 | #endif |
|
833 | 833 | |
|
834 |
|
|
|
835 | $ echo >> .hg/cache/rbc-revs-v2 | |
|
834 | dealing with valid cache revs file but for extra trailing data | |
|
835 | -------------------------------------------------------------- | |
|
836 | ||
|
837 | When the trailing data are smaller than a record, they are practically | |
|
838 | invisible to the cache and ignored. No warning is issued about them. | |
|
839 | ||
|
840 | $ echo '42' >> .hg/cache/rbc-revs-v2 | |
|
836 | 841 | $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug |
|
837 | 842 | 5 |
|
838 | cache/rbc-revs-v2 contains 2 unknown trailing bytes | |
|
839 | 843 | $ f --size .hg/cache/rbc-revs* |
|
840 |
.hg/cache/rbc-revs-v2: size=16 |
|
|
844 | .hg/cache/rbc-revs-v2: size=164 | |
|
845 | ||
|
846 | When the trailing data are larger than a record, they are seens as extra | |
|
847 | (probably invalid) data. We warn about them when writing. | |
|
848 | ||
|
849 | $ echo 'abracadabra!' >> .hg/cache/rbc-revs-v2 | |
|
850 | $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug | |
|
851 | 5 | |
|
852 | cache/rbc-revs-v2 contains 17 unknown trailing bytes | |
|
853 | $ f --size .hg/cache/rbc-revs* | |
|
854 | .hg/cache/rbc-revs-v2: size=177 | |
|
841 | 855 | |
|
842 | 856 | recovery from invalid cache file with partial last record |
|
857 | --------------------------------------------------------- | |
|
843 | 858 | $ mv .hg/cache/rbc-revs-v2 . |
|
844 | 859 | $ f -qDB 119 rbc-revs-v2 > .hg/cache/rbc-revs-v2 |
|
845 | 860 | $ f --size .hg/cache/rbc-revs* |
General Comments 0
You need to be logged in to leave comments.
Login now