~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Aaron Bentley
  • Date: 2007-07-17 13:27:14 UTC
  • mfrom: (2624 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2631.
  • Revision ID: abentley@panoramicfeedback.com-20070717132714-tmzx9khmg9501k51
Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
1187
1187
            try:
1188
1188
                # _load_data may raise NoSuchFile if the target knit is
1189
1189
                # completely empty.
1190
 
                self._load_data(fp)
 
1190
                _load_data(self, fp)
1191
1191
            finally:
1192
1192
                fp.close()
1193
1193
        except NoSuchFile:
1199
1199
                self._transport.put_bytes_non_atomic(
1200
1200
                    self._filename, self.HEADER, mode=self._file_mode)
1201
1201
 
1202
 
    def _load_data(self, fp):
1203
 
        cache = self._cache
1204
 
        history = self._history
1205
 
 
1206
 
        self.check_header(fp)
1207
 
        # readlines reads the whole file at once:
1208
 
        # bad for transports like http, good for local disk
1209
 
        # we save 60 ms doing this one change (
1210
 
        # from calling readline each time to calling
1211
 
        # readlines once.
1212
 
        # probably what we want for nice behaviour on
1213
 
        # http is a incremental readlines that yields, or
1214
 
        # a check for local vs non local indexes,
1215
 
        history_top = len(history) - 1
1216
 
        for line in fp.readlines():
1217
 
            rec = line.split()
1218
 
            if len(rec) < 5 or rec[-1] != ':':
1219
 
                # corrupt line.
1220
 
                # FIXME: in the future we should determine if its a
1221
 
                # short write - and ignore it 
1222
 
                # or a different failure, and raise. RBC 20060407
1223
 
                continue
1224
 
 
1225
 
            try:
1226
 
                parents = []
1227
 
                for value in rec[4:-1]:
1228
 
                    if value[0] == '.':
1229
 
                        # uncompressed reference
1230
 
                        parent_id = value[1:]
1231
 
                    else:
1232
 
                        parent_id = history[int(value)]
1233
 
                    parents.append(parent_id)
1234
 
            except (IndexError, ValueError), e:
1235
 
                # The parent could not be decoded to get its parent row. This
1236
 
                # at a minimum will cause this row to have wrong parents, or
1237
 
                # even to apply a delta to the wrong base and decode
1238
 
                # incorrectly. its therefore not usable, and because we have
1239
 
                # encountered a situation where a new knit index had this
1240
 
                # corrupt we can't asssume that no other rows referring to the
1241
 
                # index of this record actually mean the subsequent uncorrupt
1242
 
                # one, so we error.
1243
 
                raise errors.KnitCorrupt(self._filename,
1244
 
                    "line %r: %s" % (rec, e))
1245
 
 
1246
 
            version_id, options, pos, size = rec[:4]
1247
 
            version_id = version_id
1248
 
 
1249
 
            # See self._cache_version
1250
 
            # only want the _history index to reference the 1st 
1251
 
            # index entry for version_id
1252
 
            if version_id not in cache:
1253
 
                history_top += 1
1254
 
                index = history_top
1255
 
                history.append(version_id)
1256
 
            else:
1257
 
                index = cache[version_id][5]
1258
 
            cache[version_id] = (version_id,
1259
 
                                 options.split(','),
1260
 
                                 int(pos),
1261
 
                                 int(size),
1262
 
                                 parents,
1263
 
                                 index)
1264
 
            # end self._cache_version 
1265
 
 
1266
1202
    def get_graph(self):
1267
1203
        return [(vid, idx[4]) for vid, idx in self._cache.iteritems()]
1268
1204
 
1998
1934
            bestsize = bestsize + 1
1999
1935
 
2000
1936
        return besti, bestj, bestsize
 
1937
 
 
1938
 
 
1939
try:
 
1940
    from bzrlib._knit_load_data_c import _load_data_c as _load_data
 
1941
except ImportError:
 
1942
    from bzrlib._knit_load_data_py import _load_data_py as _load_data