~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Robert Collins
  • Date: 2007-08-22 01:41:24 UTC
  • mfrom: (2740 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2741.
  • Revision ID: robertc@robertcollins.net-20070822014124-wiinlne4nin2f2tm
Merge bzr.dev to resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
import difflib
17
18
import os
18
19
import re
19
20
import sys
34
35
    )
35
36
""")
36
37
 
37
 
# compatability - plugins import compare_trees from diff!!!
38
 
# deprecated as of 0.10
39
 
from bzrlib.delta import compare_trees
40
38
from bzrlib.symbol_versioning import (
41
39
        deprecated_function,
42
 
        zero_eight,
43
40
        )
44
41
from bzrlib.trace import mutter, warning
45
42
 
48
45
# invoke callbacks on an object.  That object can either accumulate a
49
46
# list, write them out directly, etc etc.
50
47
 
 
48
 
 
49
class _PrematchedMatcher(difflib.SequenceMatcher):
 
50
    """Allow SequenceMatcher operations to use predetermined blocks"""
 
51
 
 
52
    def __init__(self, matching_blocks):
 
53
        difflib.SequenceMatcher(self, None, None)
 
54
        self.matching_blocks = matching_blocks
 
55
        self.opcodes = None
 
56
 
 
57
 
51
58
def internal_diff(old_filename, oldlines, new_filename, newlines, to_file,
52
59
                  allow_binary=False, sequence_matcher=None,
53
60
                  path_encoding='utf8'):
261
268
                        new_abspath, e)
262
269
 
263
270
 
264
 
@deprecated_function(zero_eight)
265
 
def show_diff(b, from_spec, specific_files, external_diff_options=None,
266
 
              revision2=None, output=None, b2=None):
267
 
    """Shortcut for showing the diff to the working tree.
268
 
 
269
 
    Please use show_diff_trees instead.
270
 
 
271
 
    b
272
 
        Branch.
273
 
 
274
 
    revision
275
 
        None for 'basis tree', or otherwise the old revision to compare against.
276
 
    
277
 
    The more general form is show_diff_trees(), where the caller
278
 
    supplies any two trees.
279
 
    """
280
 
    if output is None:
281
 
        output = sys.stdout
282
 
 
283
 
    if from_spec is None:
284
 
        old_tree = b.bzrdir.open_workingtree()
285
 
        if b2 is None:
286
 
            old_tree = old_tree = old_tree.basis_tree()
287
 
    else:
288
 
        old_tree = b.repository.revision_tree(from_spec.in_history(b).rev_id)
289
 
 
290
 
    if revision2 is None:
291
 
        if b2 is None:
292
 
            new_tree = b.bzrdir.open_workingtree()
293
 
        else:
294
 
            new_tree = b2.bzrdir.open_workingtree()
295
 
    else:
296
 
        new_tree = b.repository.revision_tree(revision2.in_history(b).rev_id)
297
 
 
298
 
    return show_diff_trees(old_tree, new_tree, output, specific_files,
299
 
                           external_diff_options)
300
 
 
301
 
 
302
271
def diff_cmd_helper(tree, specific_files, external_diff_options, 
303
272
                    old_revision_spec=None, new_revision_spec=None,
304
273
                    revision_specs=None,
455
424
         text_modified, meta_modified) in delta.renamed:
456
425
        has_changes = 1
457
426
        prop_str = get_prop_change(meta_modified)
458
 
        print >>to_file, "=== renamed %s '%s' => %r%s" % (
 
427
        print >>to_file, "=== renamed %s '%s' => '%s'%s" % (
459
428
                    kind, old_path.encode('utf8'),
460
429
                    new_path.encode('utf8'), prop_str)
461
430
        old_name = '%s%s\t%s' % (old_label, old_path,