~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Aaron Bentley
  • Date: 2005-10-04 04:32:32 UTC
  • mfrom: (1185.12.6)
  • mto: (1185.12.13)
  • mto: This revision was merged to the branch mainline in revision 1419.
  • Revision ID: aaron.bentley@utoronto.ca-20051004043231-40302a149769263b
merged my own changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
140
140
        oldtmpf.close()                 # and delete
141
141
        newtmpf.close()
142
142
 
143
 
def show_diff(b, from_spec, specific_files, external_diff_options=None,
 
143
def show_diff(b, revision, specific_files, external_diff_options=None,
144
144
              revision2=None, output=None):
145
145
    """Shortcut for showing the diff to the working tree.
146
146
 
148
148
        Branch.
149
149
 
150
150
    revision
151
 
        None for 'basis tree', or otherwise the old revision to compare against.
 
151
        None for each, or otherwise the old revision to compare against.
152
152
    
153
153
    The more general form is show_diff_trees(), where the caller
154
154
    supplies any two trees.
157
157
        import sys
158
158
        output = sys.stdout
159
159
 
160
 
    if from_spec is None:
 
160
    if revision is None:
161
161
        old_tree = b.basis_tree()
162
162
    else:
163
 
        old_tree = b.revision_tree(from_spec.in_history(b).rev_id)
 
163
        old_tree = b.revision_tree(revision.in_history(b).rev_id)
164
164
 
165
165
    if revision2 is None:
166
166
        new_tree = b.working_tree()
167
167
    else:
168
168
        new_tree = b.revision_tree(revision2.in_history(b).rev_id)
169
169
 
170
 
    return show_diff_trees(old_tree, new_tree, output, specific_files,
171
 
                           external_diff_options)
 
170
    show_diff_trees(old_tree, new_tree, output, specific_files,
 
171
                    external_diff_options)
172
172
 
173
173
 
174
174
 
207
207
    delta = compare_trees(old_tree, new_tree, want_unchanged=False,
208
208
                          specific_files=specific_files)
209
209
 
210
 
    has_changes = 0
211
210
    for path, file_id, kind in delta.removed:
212
 
        has_changes = 1
213
211
        print >>to_file, '=== removed %s %r' % (kind, path)
214
 
        old_tree.inventory[file_id].diff(diff_file, old_label + path, old_tree,
215
 
                                         DEVNULL, None, None, to_file)
 
212
        if kind == 'file':
 
213
            diff_file(old_label + path,
 
214
                      old_tree.get_file(file_id).readlines(),
 
215
                      DEVNULL, 
 
216
                      [],
 
217
                      to_file)
216
218
    for path, file_id, kind in delta.added:
217
 
        has_changes = 1
218
219
        print >>to_file, '=== added %s %r' % (kind, path)
219
 
        new_tree.inventory[file_id].diff(diff_file, new_label + path, new_tree,
220
 
                                         DEVNULL, None, None, to_file, 
221
 
                                         reverse=True)
 
220
        if kind == 'file':
 
221
            diff_file(DEVNULL,
 
222
                      [],
 
223
                      new_label + path,
 
224
                      new_tree.get_file(file_id).readlines(),
 
225
                      to_file)
222
226
    for (old_path, new_path, file_id, kind,
223
227
         text_modified, meta_modified) in delta.renamed:
224
 
        has_changes = 1
225
228
        prop_str = get_prop_change(meta_modified)
226
229
        print >>to_file, '=== renamed %s %r => %r%s' % (
227
230
                          kind, old_path, new_path, prop_str)
229
232
                                    new_label, new_path, new_tree,
230
233
                                    text_modified, kind, to_file, diff_file)
231
234
    for path, file_id, kind, text_modified, meta_modified in delta.modified:
232
 
        has_changes = 1
233
235
        prop_str = get_prop_change(meta_modified)
234
236
        print >>to_file, '=== modified %s %r%s' % (kind, path, prop_str)
235
237
        if text_modified:
236
238
            _maybe_diff_file_or_symlink(old_label, path, old_tree, file_id,
237
239
                                        new_label, path, new_tree,
238
240
                                        True, kind, to_file, diff_file)
239
 
    return has_changes
240
241
    
241
242
 
242
243
def get_prop_change(meta_modified):
250
251
                                new_label, new_path, new_tree, text_modified,
251
252
                                kind, to_file, diff_file):
252
253
    if text_modified:
253
 
        new_entry = new_tree.inventory[file_id]
254
 
        old_tree.inventory[file_id].diff(diff_file,
255
 
                                         old_label + old_path, old_tree,
256
 
                                         new_label + new_path, new_entry, 
257
 
                                         new_tree, to_file)
 
254
        if kind == 'file':
 
255
            diff_file(old_label + old_path,
 
256
                      old_tree.get_file(file_id).readlines(),
 
257
                      new_label + new_path,
 
258
                      new_tree.get_file(file_id).readlines(),
 
259
                      to_file)
 
260
        elif kind == 'symlink':
 
261
            _diff_symlink(old_tree, new_tree, file_id, to_file)
 
262
            
 
263
def _diff_symlink(old_tree, new_tree, file_id, to_file):
 
264
    t1 = old_tree.get_symlink_target(file_id)
 
265
    t2 = new_tree.get_symlink_target(file_id)
 
266
    print >>to_file, '=== target changed %r => %r' % (t1, t2)