~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/knit.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-09-24 04:28:07 UTC
  • mfrom: (2850.1.1 knits)
  • Revision ID: pqm@pqm.ubuntu.com-20070924042807-nfjwj1voh6a8zddf
(robertc) Increase efficiency of shaing during adding of knit records. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
from bzrlib.osutils import (
105
105
    contains_whitespace,
106
106
    contains_linebreaks,
 
107
    sha_string,
107
108
    sha_strings,
108
109
    )
109
110
from bzrlib.symbol_versioning import DEPRECATED_PARAMETER, deprecated_passed
854
855
 
855
856
        Any versions not present will be converted into ghosts.
856
857
        """
857
 
        #  461    0   6546.0390     43.9100   bzrlib.knit:489(_add)
858
 
        # +400    0    889.4890    418.9790   +bzrlib.knit:192(lower_fulltext)
859
 
        # +461    0   1364.8070    108.8030   +bzrlib.knit:996(add_record)
860
 
        # +461    0    193.3940     41.5720   +bzrlib.knit:898(add_version)
861
 
        # +461    0    134.0590     18.3810   +bzrlib.osutils:361(sha_strings)
862
 
        # +461    0     36.3420     15.4540   +bzrlib.knit:146(make)
863
 
        # +1383   0      8.0370      8.0370   +<len>
864
 
        # +61     0     13.5770      7.9190   +bzrlib.knit:199(lower_line_delta)
865
 
        # +61     0    963.3470      7.8740   +bzrlib.knit:427(_get_content)
866
 
        # +61     0    973.9950      5.2950   +bzrlib.knit:136(line_delta)
867
 
        # +61     0   1918.1800      5.2640   +bzrlib.knit:359(_merge_annotations)
 
858
        # first thing, if the content is something we don't need to store, find
 
859
        # that out.
 
860
        line_bytes = ''.join(lines)
 
861
        digest = sha_string(line_bytes)
 
862
        if nostore_sha == digest:
 
863
            raise errors.ExistingContent
868
864
 
869
865
        present_parents = []
870
866
        if parent_texts is None:
879
875
             present_parents[0] != parents[0])):
880
876
            delta = False
881
877
 
882
 
        digest = sha_strings(lines)
883
 
        if nostore_sha == digest:
884
 
            raise errors.ExistingContent
885
 
        text_length = sum(map(len, lines))
 
878
        text_length = len(line_bytes)
886
879
        options = []
887
880
        if lines:
888
881
            if lines[-1][-1] != '\n':
908
901
        if delta:
909
902
            options.append('line-delta')
910
903
            store_lines = self.factory.lower_line_delta(delta_hunks)
 
904
            size, bytes = self._data._record_to_data(version_id, digest,
 
905
                store_lines)
911
906
        else:
912
907
            options.append('fulltext')
 
908
            # get mixed annotation + content and feed it into the
 
909
            # serialiser.
913
910
            store_lines = self.factory.lower_fulltext(content)
 
911
            size, bytes = self._data._record_to_data(version_id, digest,
 
912
                store_lines)
914
913
 
915
 
        access_memo = self._data.add_record(version_id, digest, store_lines)
 
914
        access_memo = self._data.add_raw_records([size], bytes)[0]
916
915
        self._index.add_versions(
917
 
            ((version_id, options, access_memo, parents),), random_id=random_id)
 
916
            ((version_id, options, access_memo, parents),),
 
917
            random_id=random_id)
918
918
        return digest, text_length, content
919
919
 
920
920
    def check(self, progress_bar=None):
2005
2005
        """
2006
2006
        return self._access.add_raw_records(sizes, raw_data)
2007
2007
        
2008
 
    def add_record(self, version_id, digest, lines):
2009
 
        """Write new text record to disk. 
2010
 
        
2011
 
        Returns index data for retrieving it later, as per add_raw_records.
2012
 
        """
2013
 
        size, bytes = self._record_to_data(version_id, digest, lines)
2014
 
        result = self.add_raw_records([size], bytes)
2015
 
        if self._do_cache:
2016
 
            self._cache[version_id] = bytes
2017
 
        return result[0]
2018
 
 
2019
2008
    def _parse_record_header(self, version_id, raw_data):
2020
2009
        """Parse a record header for consistency.
2021
2010