[Pkg-bazaar-commits] ./bzr/unstable r817: - Deferred patch that uses Python ndiff format.

Martin Pool mbp at sourcefrog.net
Fri Apr 10 08:13:41 UTC 2009


------------------------------------------------------------
revno: 817
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Mon 2005-07-04 22:11:40 +1000
message:
  - Deferred patch that uses Python ndiff format.
  
    This highlights the changes within a line, which is rather nice.  But it also
    outputs the entire file, which is less good.
added:
  patches/ndiff.patch
-------------- next part --------------
=== added file 'patches/ndiff.patch'
--- a/patches/ndiff.patch	1970-01-01 00:00:00 +0000
+++ b/patches/ndiff.patch	2005-07-04 12:11:40 +0000
@@ -0,0 +1,149 @@
+*** modified file 'bzrlib/commands.py'
+--- bzrlib/commands.py 
++++ bzrlib/commands.py 
+@@ -721,10 +721,11 @@
+     """
+     
+     takes_args = ['file*']
+-    takes_options = ['revision', 'diff-options']
++    takes_options = ['revision', 'diff-options', 'ndiff']
+     aliases = ['di', 'dif']
+ 
+-    def run(self, revision=None, file_list=None, diff_options=None):
++    def run(self, revision=None, file_list=None, diff_options=None,
++            ndiff=None):
+         from bzrlib.diff import show_diff
+ 
+         if file_list:
+@@ -735,9 +736,15 @@
+                 file_list = None
+         else:
+             b = find_branch('.')
+-    
++
++        if ndiff:
++            format = 'ndiff'
++        else:
++            format = None
++
+         show_diff(b, revision, specific_files=file_list,
+-                  external_diff_options=diff_options)
++                  external_diff_options=diff_options,
++                  format=format)
+ 
+ 
+         
+@@ -1344,6 +1351,7 @@
+     'format':                 unicode,
+     'forward':                None,
+     'message':                unicode,
++    'ndiff':                  None,
+     'no-recurse':             None,
+     'profile':                None,
+     'revision':               _parse_revision_str,
+
+*** modified file 'bzrlib/diff.py'
+--- bzrlib/diff.py 
++++ bzrlib/diff.py 
+@@ -70,6 +70,13 @@
+     print >>to_file
+ 
+ 
++
++def internal_ndiff(old_label, oldlines,
++                   new_label, newlines,
++                   to_file):
++    """Show diff in python-specific ndiff format."""
++    from difflib import ndiff
++    to_file.writelines(ndiff(oldlines, newlines))
+ 
+ 
+ def external_diff(old_label, oldlines, new_label, newlines, to_file,
+@@ -152,7 +159,8 @@
+     
+ 
+ 
+-def show_diff(b, revision, specific_files, external_diff_options=None):
++def show_diff(b, revision, specific_files, external_diff_options=None,
++              format=None):
+     """Shortcut for showing the diff to the working tree.
+ 
+     b
+@@ -160,6 +168,9 @@
+ 
+     revision
+         None for each, or otherwise the old revision to compare against.
++
++    format
++        'unified', 'context', 'ndiff', 'external'
+     
+     The more general form is show_diff_trees(), where the caller
+     supplies any two trees.
+@@ -174,12 +185,13 @@
+     new_tree = b.working_tree()
+ 
+     show_diff_trees(old_tree, new_tree, sys.stdout, specific_files,
+-                    external_diff_options)
++                    external_diff_options, format)
+ 
+ 
+ 
+ def show_diff_trees(old_tree, new_tree, to_file, specific_files=None,
+-                    external_diff_options=None):
++                    external_diff_options=None,
++                    format=None):
+     """Show in text form the changes from one tree to another.
+ 
+     to_files
+@@ -204,10 +216,12 @@
+     if external_diff_options:
+         assert isinstance(external_diff_options, basestring)
+         opts = external_diff_options.split()
+-        def diff_file(olab, olines, nlab, nlines, to_file):
++        def diff_fn(olab, olines, nlab, nlines, to_file):
+             external_diff(olab, olines, nlab, nlines, to_file, opts)
++    elif format == 'ndiff':
++        diff_fn = internal_ndiff
+     else:
+-        diff_file = internal_diff
++        diff_fn = internal_diff
+     
+ 
+     delta = compare_trees(old_tree, new_tree, want_unchanged=False,
+@@ -216,7 +230,7 @@
+     for path, file_id, kind in delta.removed:
+         print >>to_file, '*** removed %s %r' % (kind, path)
+         if kind == 'file':
+-            diff_file(old_label + path,
++            diff_fn(old_label + path,
+                       old_tree.get_file(file_id).readlines(),
+                       DEVNULL, 
+                       [],
+@@ -225,7 +239,7 @@
+     for path, file_id, kind in delta.added:
+         print >>to_file, '*** added %s %r' % (kind, path)
+         if kind == 'file':
+-            diff_file(DEVNULL,
++            diff_fn(DEVNULL,
+                       [],
+                       new_label + path,
+                       new_tree.get_file(file_id).readlines(),
+@@ -234,7 +248,7 @@
+     for old_path, new_path, file_id, kind, text_modified in delta.renamed:
+         print >>to_file, '*** renamed %s %r => %r' % (kind, old_path, new_path)
+         if text_modified:
+-            diff_file(old_label + old_path,
++            diff_fn(old_label + old_path,
+                       old_tree.get_file(file_id).readlines(),
+                       new_label + new_path,
+                       new_tree.get_file(file_id).readlines(),
+@@ -243,7 +257,7 @@
+     for path, file_id, kind in delta.modified:
+         print >>to_file, '*** modified %s %r' % (kind, path)
+         if kind == 'file':
+-            diff_file(old_label + path,
++            diff_fn(old_label + path,
+                       old_tree.get_file(file_id).readlines(),
+                       new_label + path,
+                       new_tree.get_file(file_id).readlines(),
+



More information about the Pkg-bazaar-commits mailing list