~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-13 18:38:58 UTC
  • mfrom: (1863 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1869.
  • Revision ID: john@arbash-meinel.com-20060713183858-ebf4aa1f9ef8bb6e
[merge] bzr.dev 1863

Show diffs side-by-side

added added

removed removed

Lines of Context:
256
256
    The more general form is show_diff_trees(), where the caller
257
257
    supplies any two trees.
258
258
    """
259
 
    output = sys.stdout
260
259
    def spec_tree(spec):
261
 
        revision_id = spec.in_store(tree.branch).rev_id
262
 
        return tree.branch.repository.revision_tree(revision_id)
 
260
        if tree:
 
261
            revision = spec.in_store(tree.branch)
 
262
        else:
 
263
            revision = spec.in_store(None)
 
264
        revision_id = revision.rev_id
 
265
        branch = revision.branch
 
266
        return branch.repository.revision_tree(revision_id)
263
267
    if old_revision_spec is None:
264
268
        old_tree = tree.basis_tree()
265
269
    else:
269
273
        new_tree = tree
270
274
    else:
271
275
        new_tree = spec_tree(new_revision_spec)
 
276
    if new_tree is not tree:
 
277
        extra_trees = (tree,)
 
278
    else:
 
279
        extra_trees = None
272
280
 
273
281
    return show_diff_trees(old_tree, new_tree, sys.stdout, specific_files,
274
282
                           external_diff_options,
275
 
                           old_label=old_label, new_label=new_label)
 
283
                           old_label=old_label, new_label=new_label,
 
284
                           extra_trees=extra_trees)
276
285
 
277
286
 
278
287
def show_diff_trees(old_tree, new_tree, to_file, specific_files=None,
279
288
                    external_diff_options=None,
280
 
                    old_label='a/', new_label='b/'):
 
289
                    old_label='a/', new_label='b/',
 
290
                    extra_trees=None):
281
291
    """Show in text form the changes from one tree to another.
282
292
 
283
293
    to_files
285
295
 
286
296
    external_diff_options
287
297
        If set, use an external GNU diff and pass these options.
 
298
 
 
299
    extra_trees
 
300
        If set, more Trees to use for looking up file ids
288
301
    """
289
302
    old_tree.lock_read()
290
303
    try:
292
305
        try:
293
306
            return _show_diff_trees(old_tree, new_tree, to_file,
294
307
                                    specific_files, external_diff_options,
295
 
                                    old_label=old_label, new_label=new_label)
 
308
                                    old_label=old_label, new_label=new_label,
 
309
                                    extra_trees=extra_trees)
296
310
        finally:
297
311
            new_tree.unlock()
298
312
    finally:
301
315
 
302
316
def _show_diff_trees(old_tree, new_tree, to_file,
303
317
                     specific_files, external_diff_options, 
304
 
                     old_label='a/', new_label='b/' ):
 
318
                     old_label='a/', new_label='b/', extra_trees=None):
305
319
 
306
320
    # GNU Patch uses the epoch date to detect files that are being added
307
321
    # or removed in a diff.
310
324
    # TODO: Generation of pseudo-diffs for added/deleted files could
311
325
    # be usefully made into a much faster special case.
312
326
 
313
 
    _raise_if_doubly_unversioned(specific_files, old_tree, new_tree)
314
 
 
315
327
    if external_diff_options:
316
328
        assert isinstance(external_diff_options, basestring)
317
329
        opts = external_diff_options.split()
321
333
        diff_file = internal_diff
322
334
    
323
335
    delta = compare_trees(old_tree, new_tree, want_unchanged=False,
324
 
                          specific_files=specific_files)
 
336
                          specific_files=specific_files, 
 
337
                          extra_trees=extra_trees, require_versioned=True)
325
338
 
326
339
    has_changes = 0
327
340
    for path, file_id, kind in delta.removed:
379
392
    return time.strftime('%Y-%m-%d %H:%M:%S +0000', tm)
380
393
 
381
394
 
382
 
def _raise_if_doubly_unversioned(specific_files, old_tree, new_tree):
383
 
    """Complain if paths are not versioned in either tree."""
384
 
    if not specific_files:
385
 
        return
386
 
    old_unversioned = old_tree.filter_unversioned_files(specific_files)
387
 
    new_unversioned = new_tree.filter_unversioned_files(specific_files)
388
 
    unversioned = old_unversioned.intersection(new_unversioned)
389
 
    if unversioned:
390
 
        raise errors.PathsNotVersionedError(sorted(unversioned))
391
 
    
392
 
 
393
395
def _raise_if_nonexistent(paths, old_tree, new_tree):
394
396
    """Complain if paths are not in either inventory or tree.
395
397