~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Robert Collins
  • Date: 2005-09-28 05:37:53 UTC
  • mfrom: (1092.3.4)
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050928053753-68e6e4c0642eccea
merge from symlink branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/env python
2
1
# -*- coding: UTF-8 -*-
3
2
 
4
3
# This program is free software; you can redistribute it and/or modify
45
44
    ud = difflib.unified_diff(oldlines, newlines,
46
45
                              fromfile=old_label, tofile=new_label)
47
46
 
 
47
    ud = list(ud)
48
48
    # work-around for difflib being too smart for its own good
49
49
    # if /dev/null is "1,0", patch won't recognize it as /dev/null
50
50
    if not oldlines:
51
 
        ud = list(ud)
52
51
        ud[2] = ud[2].replace('-1,0', '-0,0')
53
52
    elif not newlines:
54
 
        ud = list(ud)
55
53
        ud[2] = ud[2].replace('+1,0', '+0,0')
 
54
    # work around for difflib emitting random spaces after the label
 
55
    ud[0] = ud[0][:-2] + '\n'
 
56
    ud[1] = ud[1][:-2] + '\n'
56
57
 
57
58
    for line in ud:
58
59
        to_file.write(line)
156
157
        import sys
157
158
        output = sys.stdout
158
159
 
159
 
    if revision == None:
 
160
    if revision is None:
160
161
        old_tree = b.basis_tree()
161
162
    else:
162
 
        old_tree = b.revision_tree(b.lookup_revision(revision))
 
163
        old_tree = b.revision_tree(revision.in_history(b).rev_id)
163
164
 
164
 
    if revision2 == None:
 
165
    if revision2 is None:
165
166
        new_tree = b.working_tree()
166
167
    else:
167
 
        new_tree = b.revision_tree(b.lookup_revision(revision2))
 
168
        new_tree = b.revision_tree(revision2.in_history(b).rev_id)
168
169
 
169
170
    show_diff_trees(old_tree, new_tree, output, specific_files,
170
171
                    external_diff_options)
207
208
                          specific_files=specific_files)
208
209
 
209
210
    for path, file_id, kind in delta.removed:
210
 
        print >>to_file, '*** removed %s %r' % (kind, path)
 
211
        print >>to_file, '=== removed %s %r' % (kind, path)
211
212
        if kind == 'file':
212
213
            diff_file(old_label + path,
213
214
                      old_tree.get_file(file_id).readlines(),
214
215
                      DEVNULL, 
215
216
                      [],
216
217
                      to_file)
217
 
 
218
218
    for path, file_id, kind in delta.added:
219
 
        print >>to_file, '*** added %s %r' % (kind, path)
 
219
        print >>to_file, '=== added %s %r' % (kind, path)
220
220
        if kind == 'file':
221
221
            diff_file(DEVNULL,
222
222
                      [],
223
223
                      new_label + path,
224
224
                      new_tree.get_file(file_id).readlines(),
225
225
                      to_file)
226
 
 
227
226
    for old_path, new_path, file_id, kind, text_modified in delta.renamed:
228
 
        print >>to_file, '*** renamed %s %r => %r' % (kind, old_path, new_path)
 
227
        print >>to_file, '=== renamed %s %r => %r' % (kind, old_path, new_path)
229
228
        _maybe_diff_file_or_symlink(old_label, old_path, old_tree, file_id,
230
229
                                    new_label, new_path, new_tree,
231
230
                                    text_modified, kind, to_file, diff_file)
232
 
 
233
231
    for path, file_id, kind in delta.modified:
234
 
        print >>to_file, '*** modified %s %r' % (kind, path)
 
232
        print >>to_file, '=== modified %s %r' % (kind, path)
235
233
        _maybe_diff_file_or_symlink(old_label, path, old_tree, file_id,
236
234
                                    new_label, path, new_tree,
237
235
                                    True, kind, to_file, diff_file)
 
236
    
238
237
 
239
238
def _maybe_diff_file_or_symlink(old_label, old_path, old_tree, file_id,
240
239
                                new_label, new_path, new_tree, text_modified,
252
251
def _diff_symlink(old_tree, new_tree, file_id, to_file):
253
252
    t1 = old_tree.get_symlink_target(file_id)
254
253
    t2 = new_tree.get_symlink_target(file_id)
255
 
    print >>to_file, '*** *** target changed %r => %r' % (t1, t2)
256
 
    
 
254
    print >>to_file, '=== target changed %r => %r' % (t1, t2)