/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: John Arbash Meinel
  • Date: 2010-08-05 16:27:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5374.
  • Revision ID: john@arbash-meinel.com-20100805162735-172opvx34sr5gpbl
Find a case where we are wasting a bit of memory.

Specifically the 'build_details' tuple contains a lot of wasted references,
and we hold on to one of these for each record we are fetching.
And for something like 'bzr pack', that is all keys.

For just loading all text build details on my bzr+ repository, With:
locations = b.repository.texts._index.get_build_details(b.repository.texts.keys())
This drops the memory consumption from:
WorkingSize   77604KiB
 to
WorkingSize   64640KiB

Or around 10.6MB. I worked it out to a savings of about 80 bytes/record
on data that can have hundreds of thousands of records (in 32-bit).

Show diffs side-by-side

added added

removed removed

Lines of Context:
99
99
    if sequence_matcher is None:
100
100
        sequence_matcher = patiencediff.PatienceSequenceMatcher
101
101
    ud = patiencediff.unified_diff(oldlines, newlines,
102
 
                      fromfile=old_filename.encode(path_encoding),
103
 
                      tofile=new_filename.encode(path_encoding),
 
102
                      fromfile=old_filename.encode(path_encoding, 'replace'),
 
103
                      tofile=new_filename.encode(path_encoding, 'replace'),
104
104
                      sequencematcher=sequence_matcher)
105
105
 
106
106
    ud = list(ud)
420
420
 
421
421
    # Get the specific files (all files is None, no files is [])
422
422
    if make_paths_wt_relative and working_tree is not None:
423
 
        try:
424
 
            from bzrlib.builtins import safe_relpath_files
425
 
            other_paths = safe_relpath_files(working_tree, other_paths,
 
423
        other_paths = working_tree.safe_relpath_files(
 
424
            other_paths,
426
425
            apply_view=apply_view)
427
 
        except errors.FileInWrongBranch:
428
 
            raise errors.BzrCommandError("Files are in different branches")
429
426
    specific_files.extend(other_paths)
430
427
    if len(specific_files) == 0:
431
428
        specific_files = None
706
703
        """
707
704
        def _get_text(tree, file_id, path):
708
705
            if file_id is not None:
709
 
                return tree.get_file(file_id, path).readlines()
 
706
                return tree.get_file_lines(file_id, path)
710
707
            else:
711
708
                return []
712
709
        try:
713
710
            from_text = _get_text(self.old_tree, from_file_id, from_path)
714
711
            to_text = _get_text(self.new_tree, to_file_id, to_path)
715
712
            self.text_differ(from_label, from_text, to_label, to_text,
716
 
                             self.to_file)
 
713
                             self.to_file, path_encoding=self.path_encoding)
717
714
        except errors.BinaryFile:
718
715
            self.to_file.write(
719
716
                  ("Binary files %s and %s differ\n" %
720
 
                  (from_label, to_label)).encode(self.path_encoding))
 
717
                  (from_label, to_label)).encode(self.path_encoding,'replace'))
721
718
        return self.CHANGED
722
719
 
723
720
 
920
917
            extra_factories = []
921
918
        if external_diff_options:
922
919
            opts = external_diff_options.split()
923
 
            def diff_file(olab, olines, nlab, nlines, to_file):
 
920
            def diff_file(olab, olines, nlab, nlines, to_file, path_encoding=None):
 
921
                """:param path_encoding: not used but required
 
922
                        to match the signature of internal_diff.
 
923
                """
924
924
                external_diff(olab, olines, nlab, nlines, to_file, opts)
925
925
        else:
926
926
            diff_file = internal_diff