~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Robert Collins
  • Date: 2005-09-13 09:39:26 UTC
  • mto: This revision was merged to the branch mainline in revision 1397.
  • Revision ID: robertc@robertcollins.net-20050913093926-7edba69aff28352d
bugfix symlink support - read the link from the abspath not relative path

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
    print >>to_file
62
62
 
63
63
 
64
 
 
65
 
 
66
64
def external_diff(old_label, oldlines, new_label, newlines, to_file,
67
65
                  diff_opts):
68
66
    """Display a diff by calling out to the external diff program."""
140
138
    finally:
141
139
        oldtmpf.close()                 # and delete
142
140
        newtmpf.close()
143
 
    
144
 
 
145
141
 
146
142
def show_diff(b, revision, specific_files, external_diff_options=None,
147
 
              revision2=None):
 
143
              revision2=None, output=None):
148
144
    """Shortcut for showing the diff to the working tree.
149
145
 
150
146
    b
156
152
    The more general form is show_diff_trees(), where the caller
157
153
    supplies any two trees.
158
154
    """
159
 
    import sys
 
155
    if output is None:
 
156
        import sys
 
157
        output = sys.stdout
160
158
 
161
159
    if revision == None:
162
160
        old_tree = b.basis_tree()
168
166
    else:
169
167
        new_tree = b.revision_tree(b.lookup_revision(revision2))
170
168
 
171
 
    show_diff_trees(old_tree, new_tree, sys.stdout, specific_files,
 
169
    show_diff_trees(old_tree, new_tree, output, specific_files,
172
170
                    external_diff_options)
173
171
 
174
172
 
228
226
 
229
227
    for old_path, new_path, file_id, kind, text_modified in delta.renamed:
230
228
        print >>to_file, '*** renamed %s %r => %r' % (kind, old_path, new_path)
231
 
        if text_modified:
 
229
        _maybe_diff_file_or_symlink(old_label, old_path, old_tree, file_id,
 
230
                                    new_label, new_path, new_tree,
 
231
                                    text_modified, kind, to_file, diff_file)
 
232
 
 
233
    for path, file_id, kind in delta.modified:
 
234
        print >>to_file, '*** modified %s %r' % (kind, path)
 
235
        _maybe_diff_file_or_symlink(old_label, path, old_tree, file_id,
 
236
                                    new_label, path, new_tree,
 
237
                                    True, kind, to_file, diff_file)
 
238
 
 
239
def _maybe_diff_file_or_symlink(old_label, old_path, old_tree, file_id,
 
240
                                new_label, new_path, new_tree, text_modified,
 
241
                                kind, to_file, diff_file):
 
242
    if text_modified:
 
243
        if kind == 'file':
232
244
            diff_file(old_label + old_path,
233
245
                      old_tree.get_file(file_id).readlines(),
234
246
                      new_label + new_path,
235
247
                      new_tree.get_file(file_id).readlines(),
236
248
                      to_file)
237
 
 
238
 
    for path, file_id, kind in delta.modified:
239
 
        print >>to_file, '*** modified %s %r' % (kind, path)
240
 
        if kind == 'file':
241
 
            diff_file(old_label + path,
242
 
                      old_tree.get_file(file_id).readlines(),
243
 
                      new_label + path,
244
 
                      new_tree.get_file(file_id).readlines(),
245
 
                      to_file)
246
 
 
247
 
 
248
 
 
249
 
 
250
 
 
 
249
        elif kind == 'symlink':
 
250
            _diff_symlink(old_tree, new_tree, file_id, to_file)
 
251
            
 
252
def _diff_symlink(old_tree, new_tree, file_id, to_file):
 
253
    t1 = old_tree.get_symlink_target(file_id)
 
254
    t2 = new_tree.get_symlink_target(file_id)
 
255
    print >>to_file, '*** *** target changed %r => %r' % (t1, t2)
 
256