1
# Copyright (C) 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from bzrlib import errors
21
def _load_data_py(kndx, fp):
22
"""Read in a knit index."""
24
history = kndx._history
27
# readlines reads the whole file at once:
28
# bad for transports like http, good for local disk
29
# we save 60 ms doing this one change (
30
# from calling readline each time to calling
32
# probably what we want for nice behaviour on
33
# http is a incremental readlines that yields, or
34
# a check for local vs non local indexes,
35
history_top = len(history) - 1
36
for line in fp.readlines():
38
if len(rec) < 5 or rec[-1] != ':':
40
# FIXME: in the future we should determine if its a
41
# short write - and ignore it
42
# or a different failure, and raise. RBC 20060407
47
for value in rec[4:-1]:
49
# uncompressed reference
52
parent_id = history[int(value)]
53
parents.append(parent_id)
54
except (IndexError, ValueError), e:
55
# The parent could not be decoded to get its parent row. This
56
# at a minimum will cause this row to have wrong parents, or
57
# even to apply a delta to the wrong base and decode
58
# incorrectly. its therefore not usable, and because we have
59
# encountered a situation where a new knit index had this
60
# corrupt we can't asssume that no other rows referring to the
61
# index of this record actually mean the subsequent uncorrupt
63
raise errors.KnitCorrupt(kndx._filename, "line %r: %s" % (rec, e))
65
version_id, options, pos, size = rec[:4]
66
version_id = version_id
70
raise errors.KnitCorrupt(kndx._filename,
71
"invalid position on line %r: %s"
76
raise errors.KnitCorrupt(kndx._filename,
77
"invalid size on line %r: %s"
80
# See kndx._cache_version
81
# only want the _history index to reference the 1st
82
# index entry for version_id
83
if version_id not in cache:
86
history.append(version_id)
88
index = cache[version_id][5]
89
cache[version_id] = (version_id,
95
# end kndx._cache_version