~bzr-pqm/bzr/bzr.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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(),