~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to patches/ndiff.patch

  • Committer: Robert Collins
  • Date: 2005-10-06 12:14:01 UTC
  • mfrom: (1393.1.67)
  • Revision ID: robertc@robertcollins.net-20051006121401-ce87bcb93909bbdf
merge martins latest

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
*** modified file 'bzrlib/commands.py'
 
2
--- bzrlib/commands.py 
 
3
+++ bzrlib/commands.py 
 
4
@@ -721,10 +721,11 @@
 
5
     """
 
6
     
 
7
     takes_args = ['file*']
 
8
-    takes_options = ['revision', 'diff-options']
 
9
+    takes_options = ['revision', 'diff-options', 'ndiff']
 
10
     aliases = ['di', 'dif']
 
11
 
 
12
-    def run(self, revision=None, file_list=None, diff_options=None):
 
13
+    def run(self, revision=None, file_list=None, diff_options=None,
 
14
+            ndiff=None):
 
15
         from bzrlib.diff import show_diff
 
16
 
 
17
         if file_list:
 
18
@@ -735,9 +736,15 @@
 
19
                 file_list = None
 
20
         else:
 
21
             b = find_branch('.')
 
22
-    
 
23
+
 
24
+        if ndiff:
 
25
+            format = 'ndiff'
 
26
+        else:
 
27
+            format = None
 
28
+
 
29
         show_diff(b, revision, specific_files=file_list,
 
30
-                  external_diff_options=diff_options)
 
31
+                  external_diff_options=diff_options,
 
32
+                  format=format)
 
33
 
 
34
 
 
35
         
 
36
@@ -1344,6 +1351,7 @@
 
37
     'format':                 unicode,
 
38
     'forward':                None,
 
39
     'message':                unicode,
 
40
+    'ndiff':                  None,
 
41
     'no-recurse':             None,
 
42
     'profile':                None,
 
43
     'revision':               _parse_revision_str,
 
44
 
 
45
*** modified file 'bzrlib/diff.py'
 
46
--- bzrlib/diff.py 
 
47
+++ bzrlib/diff.py 
 
48
@@ -70,6 +70,13 @@
 
49
     print >>to_file
 
50
 
 
51
 
 
52
+
 
53
+def internal_ndiff(old_label, oldlines,
 
54
+                   new_label, newlines,
 
55
+                   to_file):
 
56
+    """Show diff in python-specific ndiff format."""
 
57
+    from difflib import ndiff
 
58
+    to_file.writelines(ndiff(oldlines, newlines))
 
59
 
 
60
 
 
61
 def external_diff(old_label, oldlines, new_label, newlines, to_file,
 
62
@@ -152,7 +159,8 @@
 
63
     
 
64
 
 
65
 
 
66
-def show_diff(b, revision, specific_files, external_diff_options=None):
 
67
+def show_diff(b, revision, specific_files, external_diff_options=None,
 
68
+              format=None):
 
69
     """Shortcut for showing the diff to the working tree.
 
70
 
 
71
     b
 
72
@@ -160,6 +168,9 @@
 
73
 
 
74
     revision
 
75
         None for each, or otherwise the old revision to compare against.
 
76
+
 
77
+    format
 
78
+        'unified', 'context', 'ndiff', 'external'
 
79
     
 
80
     The more general form is show_diff_trees(), where the caller
 
81
     supplies any two trees.
 
82
@@ -174,12 +185,13 @@
 
83
     new_tree = b.working_tree()
 
84
 
 
85
     show_diff_trees(old_tree, new_tree, sys.stdout, specific_files,
 
86
-                    external_diff_options)
 
87
+                    external_diff_options, format)
 
88
 
 
89
 
 
90
 
 
91
 def show_diff_trees(old_tree, new_tree, to_file, specific_files=None,
 
92
-                    external_diff_options=None):
 
93
+                    external_diff_options=None,
 
94
+                    format=None):
 
95
     """Show in text form the changes from one tree to another.
 
96
 
 
97
     to_files
 
98
@@ -204,10 +216,12 @@
 
99
     if external_diff_options:
 
100
         assert isinstance(external_diff_options, basestring)
 
101
         opts = external_diff_options.split()
 
102
-        def diff_file(olab, olines, nlab, nlines, to_file):
 
103
+        def diff_fn(olab, olines, nlab, nlines, to_file):
 
104
             external_diff(olab, olines, nlab, nlines, to_file, opts)
 
105
+    elif format == 'ndiff':
 
106
+        diff_fn = internal_ndiff
 
107
     else:
 
108
-        diff_file = internal_diff
 
109
+        diff_fn = internal_diff
 
110
     
 
111
 
 
112
     delta = compare_trees(old_tree, new_tree, want_unchanged=False,
 
113
@@ -216,7 +230,7 @@
 
114
     for path, file_id, kind in delta.removed:
 
115
         print >>to_file, '*** removed %s %r' % (kind, path)
 
116
         if kind == 'file':
 
117
-            diff_file(old_label + path,
 
118
+            diff_fn(old_label + path,
 
119
                       old_tree.get_file(file_id).readlines(),
 
120
                       DEVNULL, 
 
121
                       [],
 
122
@@ -225,7 +239,7 @@
 
123
     for path, file_id, kind in delta.added:
 
124
         print >>to_file, '*** added %s %r' % (kind, path)
 
125
         if kind == 'file':
 
126
-            diff_file(DEVNULL,
 
127
+            diff_fn(DEVNULL,
 
128
                       [],
 
129
                       new_label + path,
 
130
                       new_tree.get_file(file_id).readlines(),
 
131
@@ -234,7 +248,7 @@
 
132
     for old_path, new_path, file_id, kind, text_modified in delta.renamed:
 
133
         print >>to_file, '*** renamed %s %r => %r' % (kind, old_path, new_path)
 
134
         if text_modified:
 
135
-            diff_file(old_label + old_path,
 
136
+            diff_fn(old_label + old_path,
 
137
                       old_tree.get_file(file_id).readlines(),
 
138
                       new_label + new_path,
 
139
                       new_tree.get_file(file_id).readlines(),
 
140
@@ -243,7 +257,7 @@
 
141
     for path, file_id, kind in delta.modified:
 
142
         print >>to_file, '*** modified %s %r' % (kind, path)
 
143
         if kind == 'file':
 
144
-            diff_file(old_label + path,
 
145
+            diff_fn(old_label + path,
 
146
                       old_tree.get_file(file_id).readlines(),
 
147
                       new_label + path,
 
148
                       new_tree.get_file(file_id).readlines(),
 
149