~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

Merge up bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
from bzrlib.symbol_versioning import (
43
43
        deprecated_function,
44
 
        one_zero,
45
44
        one_three
46
45
        )
47
46
from bzrlib.trace import mutter, warning
276
275
                        new_abspath, e)
277
276
 
278
277
 
279
 
@deprecated_function(one_zero)
280
 
def diff_cmd_helper(tree, specific_files, external_diff_options, 
281
 
                    old_revision_spec=None, new_revision_spec=None,
282
 
                    revision_specs=None,
283
 
                    old_label='a/', new_label='b/'):
284
 
    """Helper for cmd_diff.
285
 
 
286
 
    :param tree:
287
 
        A WorkingTree
288
 
 
289
 
    :param specific_files:
290
 
        The specific files to compare, or None
291
 
 
292
 
    :param external_diff_options:
293
 
        If non-None, run an external diff, and pass it these options
294
 
 
295
 
    :param old_revision_spec:
296
 
        If None, use basis tree as old revision, otherwise use the tree for
297
 
        the specified revision. 
298
 
 
299
 
    :param new_revision_spec:
300
 
        If None, use working tree as new revision, otherwise use the tree for
301
 
        the specified revision.
302
 
    
303
 
    :param revision_specs: 
304
 
        Zero, one or two RevisionSpecs from the command line, saying what revisions 
305
 
        to compare.  This can be passed as an alternative to the old_revision_spec 
306
 
        and new_revision_spec parameters.
307
 
 
308
 
    The more general form is show_diff_trees(), where the caller
309
 
    supplies any two trees.
310
 
    """
311
 
 
312
 
    # TODO: perhaps remove the old parameters old_revision_spec and
313
 
    # new_revision_spec, since this is only really for use from cmd_diff and
314
 
    # it now always passes through a sequence of revision_specs -- mbp
315
 
    # 20061221
316
 
 
317
 
    def spec_tree(spec):
318
 
        if tree:
319
 
            revision = spec.in_store(tree.branch)
320
 
        else:
321
 
            revision = spec.in_store(None)
322
 
        revision_id = revision.rev_id
323
 
        branch = revision.branch
324
 
        return branch.repository.revision_tree(revision_id)
325
 
 
326
 
    if revision_specs is not None:
327
 
        assert (old_revision_spec is None
328
 
                and new_revision_spec is None)
329
 
        if len(revision_specs) > 0:
330
 
            old_revision_spec = revision_specs[0]
331
 
        if len(revision_specs) > 1:
332
 
            new_revision_spec = revision_specs[1]
333
 
 
334
 
    if old_revision_spec is None:
335
 
        old_tree = tree.basis_tree()
336
 
    else:
337
 
        old_tree = spec_tree(old_revision_spec)
338
 
 
339
 
    if (new_revision_spec is None
340
 
        or new_revision_spec.spec is None):
341
 
        new_tree = tree
342
 
    else:
343
 
        new_tree = spec_tree(new_revision_spec)
344
 
 
345
 
    if new_tree is not tree:
346
 
        extra_trees = (tree,)
347
 
    else:
348
 
        extra_trees = None
349
 
 
350
 
    return show_diff_trees(old_tree, new_tree, sys.stdout, specific_files,
351
 
                           external_diff_options,
352
 
                           old_label=old_label, new_label=new_label,
353
 
                           extra_trees=extra_trees)
354
 
 
355
 
 
356
278
def _get_trees_to_diff(path_list, revision_specs, old_url, new_url):
357
279
    """Get the trees and specific files to diff given a list of paths.
358
280
 
517
439
def _patch_header_date(tree, file_id, path):
518
440
    """Returns a timestamp suitable for use in a patch header."""
519
441
    mtime = tree.get_file_mtime(file_id, path)
520
 
    assert mtime is not None, \
521
 
        "got an mtime of None for file-id %s, path %s in tree %s" % (
522
 
                file_id, path, tree)
523
442
    return timestamp.format_patch_date(mtime)
524
443
 
525
444
 
914
833
        else:
915
834
            extra_factories = []
916
835
        if external_diff_options:
917
 
            assert isinstance(external_diff_options, basestring)
918
836
            opts = external_diff_options.split()
919
837
            def diff_file(olab, olines, nlab, nlines, to_file):
920
838
                external_diff(olab, olines, nlab, nlines, to_file, opts)