[PATCH 1 of 1] revlog: fix partial read error introduced in 57a41c08feab (issue1672)
Matt Mackall
mpm at selenic.com
Sat May 23 11:03:37 CDT 2009
On Sat, 2009-05-23 at 09:50 +0000, Henrik Stuart wrote:
> # HG changeset patch
> # User Henrik Stuart <hg at hstuart.dk>
> # Date 1243071825 -7200
> # Node ID 8ac77e18bdbe3c93f56ee5230bc99290a0995af3
> # Parent 9f85da26050895c67a162d0d2097255402618017
> revlog: fix partial read error introduced in 57a41c08feab (issue1672)
>
> If an inline revlog is larger than _prereadsize, the remainder of the
> revlog is never read, or if util.openhardlinks() evaluates to False,
> e.g. on Windows.
>
> diff -r 9f85da260508 -r 8ac77e18bdbe mercurial/revlog.py
> --- a/mercurial/revlog.py Sat May 23 00:24:00 2009 +0200
> +++ b/mercurial/revlog.py Sat May 23 11:43:45 2009 +0200
> @@ -380,6 +380,8 @@
> index[0] = e
> return index, nodemap, None
>
> + if size > _prereadsize:
> + data += fp.read()
> # call the C implementation to parse the index data
> index, nodemap, cache = parsers.parse_index(data, inline)
> return index, nodemap, cache
I came up with exactly this fix this morning. I've since changed it to:
diff -r 9f85da260508 mercurial/revlog.py
--- a/mercurial/revlog.py Sat May 23 00:24:00 2009 +0200
+++ b/mercurial/revlog.py Sat May 23 10:59:01 2009 -0500
@@ -322,7 +322,7 @@
index = []
nodemap = {nullid: nullrev}
n = off = 0
- if len(data) < _prereadsize:
+ if len(data) == _prereadsize:
data += fp.read() # read the rest
l = len(data)
while off + s <= l:
@@ -362,23 +362,19 @@
self.size = struct.calcsize(indexformatng)
def parseindex(self, fp, data, inline):
- try:
- size = len(data)
- if size == _prereadsize:
- size = util.fstat(fp).st_size
- except AttributeError:
- size = 0
-
- if util.openhardlinks() and not inline and size > _prereadsize:
- # big index, let's parse it on demand
- parser = lazyparser(fp, size)
- index = lazyindex(parser)
- nodemap = lazymap(parser)
- e = list(index[0])
- type = gettype(e[0])
- e[0] = offset_type(0, type)
- index[0] = e
- return index, nodemap, None
+ if len(data) == _prereadsize:
+ if util.openhardlinks() and not inline:
+ # big index, let's parse it on demand
+ parser = lazyparser(fp, size)
+ index = lazyindex(parser)
+ nodemap = lazymap(parser)
+ e = list(index[0])
+ type = gettype(e[0])
+ e[0] = offset_type(0, type)
+ index[0] = e
+ return index, nodemap, None
+ else:
+ data += fp.read()
# call the C implementation to parse the index data
index, nodemap, cache = parsers.parse_index(data, inline)
--
http://selenic.com : development and support for Mercurial and Linux
More information about the Mercurial-devel
mailing list