# (Be in -*- python -*- mode.) # # ==================================================================== # Copyright (c) 2000-2006 CollabNet. All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms # are also available at http://subversion.tigris.org/license-1.html. # If newer versions of this license are posted there, you may use a # newer version instead, at your option. # # This software consists of voluntary contributions made by many # individuals. For exact contribution history, see the revision # history and logs, available at http://cvs2svn.tigris.org/. # ==================================================================== """This module contains a database that can store arbitrary CVSItems.""" from __future__ import generators import struct import cPickle from cvs2svn_lib.boolean import * from cvs2svn_lib.common import FatalError from cvs2svn_lib.cvs_item import CVSRevision from cvs2svn_lib.cvs_item import CVSBranch from cvs2svn_lib.cvs_item import CVSTag from cvs2svn_lib.primed_pickle import get_memos from cvs2svn_lib.primed_pickle import PrimedPickler from cvs2svn_lib.primed_pickle import PrimedUnpickler from cvs2svn_lib.record_table import NewRecordTable from cvs2svn_lib.record_table import OldRecordTable class NewCVSItemStore: """A file of sequential CVSItems, grouped by CVSFile. The file consists of a sequence of pickles. The zeroth one is an 'unpickler_memo' as described in the primed_pickle module. Subsequent ones are pickled lists of CVSItems, each list containing all of the CVSItems for a single file. We don't use a single pickler for all items because the memo would grow too large.""" def __init__(self, filename): """Initialize an instance, creating the file and writing the primer.""" self.f = open(filename, 'wb') primer = (CVSRevision, CVSBranch, CVSTag,) (pickler_memo, unpickler_memo,) = get_memos(primer) self.pickler = PrimedPickler(pickler_memo) cPickle.dump(unpickler_memo, self.f, -1) self.current_file_id = None self.current_file_items = [] def _flush(self): """Write the current items to disk.""" if self.current_file_items: self.pickler.dumpf(self.f, self.current_file_items) self.current_file_id = None self.current_file_items = [] def add(self, cvs_item): """Write cvs_item into the database.""" if cvs_item.cvs_file.id != self.current_file_id: self._flush() self.current_file_id = cvs_item.cvs_file.id self.current_file_items.append(cvs_item) def close(self): self._flush() self.f.close() # Convert file offsets to 8-bit little-endian unsigned longs... INDEX_FORMAT = '