~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Robert Collins
  • Date: 2010-04-08 04:34:03 UTC
  • mfrom: (5138 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5139.
  • Revision ID: robertc@robertcollins.net-20100408043403-56z0d07vdqrx7f3t
Update bugfix for 528114 to trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
from bzrlib import (
32
32
    branch as _mod_branch,
33
33
    bzrdir,
34
 
    commands,
 
34
    cmdline,
35
35
    errors,
36
36
    osutils,
37
37
    patiencediff,
43
43
from bzrlib.workingtree import WorkingTree
44
44
""")
45
45
 
 
46
from bzrlib.registry import (
 
47
    Registry,
 
48
    )
46
49
from bzrlib.symbol_versioning import (
47
50
    deprecated_function,
48
51
    )
411
414
                    old_label='a/', new_label='b/',
412
415
                    extra_trees=None,
413
416
                    path_encoding='utf8',
414
 
                    using=None):
 
417
                    using=None,
 
418
                    format_cls=None):
415
419
    """Show in text form the changes from one tree to another.
416
420
 
417
 
    to_file
418
 
        The output stream.
419
 
 
420
 
    specific_files
421
 
        Include only changes to these files - None for all changes.
422
 
 
423
 
    external_diff_options
424
 
        If set, use an external GNU diff and pass these options.
425
 
 
426
 
    extra_trees
427
 
        If set, more Trees to use for looking up file ids
428
 
 
429
 
    path_encoding
430
 
        If set, the path will be encoded as specified, otherwise is supposed
431
 
        to be utf8
 
421
    :param to_file: The output stream.
 
422
    :param specific_files:Include only changes to these files - None for all
 
423
        changes.
 
424
    :param external_diff_options: If set, use an external GNU diff and pass 
 
425
        these options.
 
426
    :param extra_trees: If set, more Trees to use for looking up file ids
 
427
    :param path_encoding: If set, the path will be encoded as specified, 
 
428
        otherwise is supposed to be utf8
 
429
    :param format_cls: Formatter class (DiffTree subclass)
432
430
    """
 
431
    if format_cls is None:
 
432
        format_cls = DiffTree
433
433
    old_tree.lock_read()
434
434
    try:
435
435
        if extra_trees is not None:
437
437
                tree.lock_read()
438
438
        new_tree.lock_read()
439
439
        try:
440
 
            differ = DiffTree.from_trees_options(old_tree, new_tree, to_file,
441
 
                                                 path_encoding,
442
 
                                                 external_diff_options,
443
 
                                                 old_label, new_label, using)
 
440
            differ = format_cls.from_trees_options(old_tree, new_tree, to_file,
 
441
                                                   path_encoding,
 
442
                                                   external_diff_options,
 
443
                                                   old_label, new_label, using)
444
444
            return differ.show_diff(specific_files, extra_trees)
445
445
        finally:
446
446
            new_tree.unlock()
683
683
    @classmethod
684
684
    def from_string(klass, command_string, old_tree, new_tree, to_file,
685
685
                    path_encoding='utf-8'):
686
 
        command_template = commands.shlex_split_unicode(command_string)
 
686
        command_template = cmdline.split(command_string)
687
687
        if '@' not in command_string:
688
688
            command_template.extend(['@old_path', '@new_path'])
689
689
        return klass(command_template, old_tree, new_tree, to_file,
882
882
    def show_diff(self, specific_files, extra_trees=None):
883
883
        """Write tree diff to self.to_file
884
884
 
885
 
        :param sepecific_files: the specific files to compare (recursive)
 
885
        :param specific_files: the specific files to compare (recursive)
886
886
        :param extra_trees: extra trees to use for mapping paths to file_ids
887
887
        """
888
888
        try:
978
978
            if error_path is None:
979
979
                error_path = old_path
980
980
            raise errors.NoDiffFound(error_path)
 
981
 
 
982
 
 
983
format_registry = Registry()
 
984
format_registry.register('default', DiffTree)