~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Martin Pool
  • Date: 2005-08-01 23:14:12 UTC
  • mfrom: (974.1.11)
  • Revision ID: mbp@sourcefrog.net-20050801231412-6a6278d24a7cbb0a
- merge aaron's revert and merge improvements

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    ud = difflib.unified_diff(oldlines, newlines,
46
46
                              fromfile=old_label, tofile=new_label)
47
47
 
48
 
    ud = list(ud)
49
48
    # work-around for difflib being too smart for its own good
50
49
    # if /dev/null is "1,0", patch won't recognize it as /dev/null
51
50
    if not oldlines:
 
51
        ud = list(ud)
52
52
        ud[2] = ud[2].replace('-1,0', '-0,0')
53
53
    elif not newlines:
 
54
        ud = list(ud)
54
55
        ud[2] = ud[2].replace('+1,0', '+0,0')
55
 
    # work around for difflib emitting random spaces after the label
56
 
    ud[0] = ud[0][:-2] + '\n'
57
 
    ud[1] = ud[1][:-2] + '\n'
58
56
 
59
57
    for line in ud:
60
58
        to_file.write(line)
145
143
    
146
144
 
147
145
 
148
 
def show_diff(b, revision, specific_files, external_diff_options=None,
149
 
              revision2=None, output=None):
 
146
def show_diff(b, revision, specific_files, external_diff_options=None):
150
147
    """Shortcut for showing the diff to the working tree.
151
148
 
152
149
    b
158
155
    The more general form is show_diff_trees(), where the caller
159
156
    supplies any two trees.
160
157
    """
161
 
    if output is None:
162
 
        import sys
163
 
        output = sys.stdout
 
158
    import sys
164
159
 
165
160
    if revision == None:
166
161
        old_tree = b.basis_tree()
167
162
    else:
168
163
        old_tree = b.revision_tree(b.lookup_revision(revision))
169
 
 
170
 
    if revision2 == None:
171
 
        new_tree = b.working_tree()
172
 
    else:
173
 
        new_tree = b.revision_tree(b.lookup_revision(revision2))
174
 
 
175
 
    show_diff_trees(old_tree, new_tree, output, specific_files,
 
164
        
 
165
    new_tree = b.working_tree()
 
166
 
 
167
    show_diff_trees(old_tree, new_tree, sys.stdout, specific_files,
176
168
                    external_diff_options)
177
169
 
178
170
 
213
205
                          specific_files=specific_files)
214
206
 
215
207
    for path, file_id, kind in delta.removed:
216
 
        print >>to_file, '=== removed %s %r' % (kind, path)
 
208
        print >>to_file, '*** removed %s %r' % (kind, path)
217
209
        if kind == 'file':
218
210
            diff_file(old_label + path,
219
211
                      old_tree.get_file(file_id).readlines(),
222
214
                      to_file)
223
215
 
224
216
    for path, file_id, kind in delta.added:
225
 
        print >>to_file, '=== added %s %r' % (kind, path)
 
217
        print >>to_file, '*** added %s %r' % (kind, path)
226
218
        if kind == 'file':
227
219
            diff_file(DEVNULL,
228
220
                      [],
231
223
                      to_file)
232
224
 
233
225
    for old_path, new_path, file_id, kind, text_modified in delta.renamed:
234
 
        print >>to_file, '=== renamed %s %r => %r' % (kind, old_path, new_path)
 
226
        print >>to_file, '*** renamed %s %r => %r' % (kind, old_path, new_path)
235
227
        if text_modified:
236
228
            diff_file(old_label + old_path,
237
229
                      old_tree.get_file(file_id).readlines(),
240
232
                      to_file)
241
233
 
242
234
    for path, file_id, kind in delta.modified:
243
 
        print >>to_file, '=== modified %s %r' % (kind, path)
 
235
        print >>to_file, '*** modified %s %r' % (kind, path)
244
236
        if kind == 'file':
245
237
            diff_file(old_label + path,
246
238
                      old_tree.get_file(file_id).readlines(),