##// END OF EJS Templates
rev-branch-cache: properly ignores unaligned trailing data...
marmoute -
r52868:76416b6e default
parent child Browse files
Show More
@@ -56,23 +56,28 class rbcrevs:
56 self._prefix = revs
56 self._prefix = revs
57 self._rest = bytearray()
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 def __len__(self):
64 def __len__(self):
60 return len(self._prefix) + len(self._rest)
65 return self.len_prefix + len(self._rest)
61
66
62 def unpack_record(self, rbcrevidx):
67 def unpack_record(self, rbcrevidx):
63 if rbcrevidx < len(self._prefix):
68 if rbcrevidx < self.len_prefix:
64 return unpack_from(_rbcrecfmt, util.buffer(self._prefix), rbcrevidx)
69 return unpack_from(_rbcrecfmt, util.buffer(self._prefix), rbcrevidx)
65 else:
70 else:
66 return unpack_from(
71 return unpack_from(
67 _rbcrecfmt,
72 _rbcrecfmt,
68 util.buffer(self._rest),
73 util.buffer(self._rest),
69 rbcrevidx - len(self._prefix),
74 rbcrevidx - self.len_prefix,
70 )
75 )
71
76
72 def make_mutable(self):
77 def make_mutable(self):
73 if len(self._prefix) > 0:
78 if self.len_prefix > 0:
74 entirety = bytearray()
79 entirety = bytearray()
75 entirety[:] = self._prefix
80 entirety[:] = self._prefix[: self.len_prefix]
76 entirety.extend(self._rest)
81 entirety.extend(self._rest)
77 self._rest = entirety
82 self._rest = entirety
78 self._prefix = bytearray()
83 self._prefix = bytearray()
@@ -82,10 +87,10 class rbcrevs:
82 del self._rest[pos:]
87 del self._rest[pos:]
83
88
84 def pack_into(self, rbcrevidx, node, branchidx):
89 def pack_into(self, rbcrevidx, node, branchidx):
85 if rbcrevidx < len(self._prefix):
90 if rbcrevidx < self.len_prefix:
86 self.make_mutable()
91 self.make_mutable()
87 buf = self._rest
92 buf = self._rest
88 start_offset = rbcrevidx - len(self._prefix)
93 start_offset = rbcrevidx - self.len_prefix
89 end_offset = start_offset + _rbcrecsize
94 end_offset = start_offset + _rbcrecsize
90
95
91 if len(self._rest) < end_offset:
96 if len(self._rest) < end_offset:
@@ -107,14 +112,14 class rbcrevs:
107 return self._rest.extend(extension)
112 return self._rest.extend(extension)
108
113
109 def slice(self, begin, end):
114 def slice(self, begin, end):
110 if begin < len(self._prefix):
115 if begin < self.len_prefix:
111 acc = bytearray()
116 acc = bytearray()
112 acc[:] = self._prefix[begin:end]
117 acc[:] = self._prefix[begin : min(end, self.len_prefix)]
113 acc.extend(
118 acc.extend(
114 self._rest[begin - len(self._prefix) : end - len(self._prefix)]
119 self._rest[begin - self.len_prefix : end - self.len_prefix]
115 )
120 )
116 return acc
121 return acc
117 return self._rest[begin - len(self._prefix) : end - len(self._prefix)]
122 return self._rest[begin - self.len_prefix : end - self.len_prefix]
118
123
119
124
120 class revbranchcache:
125 class revbranchcache:
@@ -388,6 +393,9 class revbranchcache:
388 if self._force_overwrite:
393 if self._force_overwrite:
389 start = 0
394 start = 0
390
395
396 # align start on entry boundary
397 start = _rbcrecsize * (start // _rbcrecsize)
398
391 with repo.cachevfs.open(_rbcrevs, b'a+b') as f:
399 with repo.cachevfs.open(_rbcrevs, b'a+b') as f:
392 pass # this make sure the file exist…
400 pass # this make sure the file exist…
393 with repo.cachevfs.open(_rbcrevs, b'r+b') as f:
401 with repo.cachevfs.open(_rbcrevs, b'r+b') as f:
@@ -831,15 +831,30 no errors when wlock cannot be acquired
831 $ mv .hg/cache/rbc-revs-v2_ .hg/cache/rbc-revs-v2
831 $ mv .hg/cache/rbc-revs-v2_ .hg/cache/rbc-revs-v2
832 #endif
832 #endif
833
833
834 recovery from invalid cache revs file with trailing data
834 dealing with valid cache revs file but for extra trailing data
835 $ echo >> .hg/cache/rbc-revs-v2
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 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug
841 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug
837 5
842 5
838 cache/rbc-revs-v2 contains 2 unknown trailing bytes
839 $ f --size .hg/cache/rbc-revs*
843 $ f --size .hg/cache/rbc-revs*
840 .hg/cache/rbc-revs-v2: size=162
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 recovery from invalid cache file with partial last record
856 recovery from invalid cache file with partial last record
857 ---------------------------------------------------------
843 $ mv .hg/cache/rbc-revs-v2 .
858 $ mv .hg/cache/rbc-revs-v2 .
844 $ f -qDB 119 rbc-revs-v2 > .hg/cache/rbc-revs-v2
859 $ f -qDB 119 rbc-revs-v2 > .hg/cache/rbc-revs-v2
845 $ f --size .hg/cache/rbc-revs*
860 $ f --size .hg/cache/rbc-revs*
General Comments 0
You need to be logged in to leave comments. Login now