2484.1.12
by John Arbash Meinel
Switch the layout to use a matching _knit_load_data_py.py and _knit_load_data_c.pyx |
1 |
# Copyright (C) 2007 Canonical Ltd
|
2 |
#
|
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
16 |
||
17 |
||
18 |
from bzrlib import errors |
|
19 |
||
20 |
||
21 |
def _load_data_py(kndx, fp): |
|
22 |
"""Read in a knit index."""
|
|
23 |
cache = kndx._cache |
|
24 |
history = kndx._history |
|
25 |
||
26 |
kndx.check_header(fp) |
|
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
|
|
31 |
# readlines once.
|
|
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(): |
|
37 |
rec = line.split() |
|
38 |
if len(rec) < 5 or rec[-1] != ':': |
|
39 |
# corrupt line.
|
|
40 |
# FIXME: in the future we should determine if its a
|
|
2484.1.24
by John Arbash Meinel
Add direct tests of how we handle incomplete/'broken' lines |
41 |
# short write - and ignore it
|
2484.1.12
by John Arbash Meinel
Switch the layout to use a matching _knit_load_data_py.py and _knit_load_data_c.pyx |
42 |
# or a different failure, and raise. RBC 20060407
|
43 |
continue
|
|
44 |
||
45 |
try: |
|
46 |
parents = [] |
|
47 |
for value in rec[4:-1]: |
|
48 |
if value[0] == '.': |
|
49 |
# uncompressed reference
|
|
50 |
parent_id = value[1:] |
|
51 |
else: |
|
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
|
|
62 |
# one, so we error.
|
|
2484.1.13
by John Arbash Meinel
Add a test that KnitCorrupt is raised when parent strings are invalid. |
63 |
raise errors.KnitCorrupt(kndx._filename, "line %r: %s" % (rec, e)) |
2484.1.12
by John Arbash Meinel
Switch the layout to use a matching _knit_load_data_py.py and _knit_load_data_c.pyx |
64 |
|
65 |
version_id, options, pos, size = rec[:4] |
|
66 |
version_id = version_id |
|
2484.1.18
by John Arbash Meinel
Test that we properly verify the size and position strings. |
67 |
try: |
68 |
pos = int(pos) |
|
69 |
except ValueError, e: |
|
70 |
raise errors.KnitCorrupt(kndx._filename, |
|
71 |
"invalid position on line %r: %s" |
|
72 |
% (rec, e)) |
|
73 |
try: |
|
74 |
size = int(size) |
|
75 |
except ValueError, e: |
|
76 |
raise errors.KnitCorrupt(kndx._filename, |
|
77 |
"invalid size on line %r: %s" |
|
78 |
% (rec, e)) |
|
2484.1.12
by John Arbash Meinel
Switch the layout to use a matching _knit_load_data_py.py and _knit_load_data_c.pyx |
79 |
|
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: |
|
84 |
history_top += 1 |
|
85 |
index = history_top |
|
86 |
history.append(version_id) |
|
87 |
else: |
|
88 |
index = cache[version_id][5] |
|
89 |
cache[version_id] = (version_id, |
|
90 |
options.split(','), |
|
2484.1.18
by John Arbash Meinel
Test that we properly verify the size and position strings. |
91 |
pos, |
92 |
size, |
|
3287.5.5
by Robert Collins
Refactor internals of knit implementations to implement get_parents_with_ghosts in terms of get_parent_map. |
93 |
tuple(parents), |
2484.1.12
by John Arbash Meinel
Switch the layout to use a matching _knit_load_data_py.py and _knit_load_data_c.pyx |
94 |
index) |
95 |
# end kndx._cache_version
|