/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/diff.py

  • Committer: Aaron Bentley
  • Date: 2007-03-03 17:17:53 UTC
  • mfrom: (2309 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2316.
  • Revision ID: aaron.bentley@utoronto.ca-20070303171753-o0s1yrxx5sn12p2k
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
96
96
 
97
97
 
98
98
def _set_lang_C():
99
 
    """Set the env var LANG=C"""
 
99
    """Set the env vars LANG=C and LC_ALL=C."""
100
100
    osutils.set_or_unset_env('LANG', 'C')
101
 
    osutils.set_or_unset_env('LC_ALL', None)
 
101
    osutils.set_or_unset_env('LC_ALL', 'C')
102
102
    osutils.set_or_unset_env('LC_CTYPE', None)
103
103
    osutils.set_or_unset_env('LANGUAGE', None)
104
104
 
107
107
    """Spawn the externall diff process, and return the child handle.
108
108
 
109
109
    :param diffcmd: The command list to spawn
110
 
    :param capture_errors: Capture stderr as well as setting LANG=C.
111
 
        This lets us read and understand the output of diff, and respond 
112
 
        to any errors.
 
110
    :param capture_errors: Capture stderr as well as setting LANG=C
 
111
        and LC_ALL=C. This lets us read and understand the output of diff,
 
112
        and respond to any errors.
113
113
    :return: A Popen object.
114
114
    """
115
115
    if capture_errors:
116
116
        if sys.platform == 'win32':
117
117
            # Win32 doesn't support preexec_fn, but that is
118
 
            # okay, because it doesn't support LANG either.
 
118
            # okay, because it doesn't support LANG and LC_ALL either.
119
119
            preexec_fn = None
120
120
        else:
121
121
            preexec_fn = _set_lang_C
219
219
            if pipe.returncode != 2:
220
220
                raise errors.BzrError(
221
221
                               'external diff failed with exit code 2'
222
 
                               ' when run with LANG=C, but not when run'
223
 
                               ' natively: %r' % (diffcmd,))
 
222
                               ' when run with LANG=C and LC_ALL=C,'
 
223
                               ' but not when run natively: %r' % (diffcmd,))
224
224
 
225
225
            first_line = lang_c_out.split('\n', 1)[0]
226
226
            # Starting with diffutils 2.8.4 the word "binary" was dropped.
306
306
 
307
307
def diff_cmd_helper(tree, specific_files, external_diff_options, 
308
308
                    old_revision_spec=None, new_revision_spec=None,
 
309
                    revision_specs=None,
309
310
                    old_label='a/', new_label='b/'):
310
311
    """Helper for cmd_diff.
311
312
 
312
 
   tree 
 
313
    :param tree:
313
314
        A WorkingTree
314
315
 
315
 
    specific_files
 
316
    :param specific_files:
316
317
        The specific files to compare, or None
317
318
 
318
 
    external_diff_options
 
319
    :param external_diff_options:
319
320
        If non-None, run an external diff, and pass it these options
320
321
 
321
 
    old_revision_spec
 
322
    :param old_revision_spec:
322
323
        If None, use basis tree as old revision, otherwise use the tree for
323
324
        the specified revision. 
324
325
 
325
 
    new_revision_spec
 
326
    :param new_revision_spec:
326
327
        If None, use working tree as new revision, otherwise use the tree for
327
328
        the specified revision.
328
329
    
 
330
    :param revision_specs: 
 
331
        Zero, one or two RevisionSpecs from the command line, saying what revisions 
 
332
        to compare.  This can be passed as an alternative to the old_revision_spec 
 
333
        and new_revision_spec parameters.
 
334
 
329
335
    The more general form is show_diff_trees(), where the caller
330
336
    supplies any two trees.
331
337
    """
 
338
 
 
339
    # TODO: perhaps remove the old parameters old_revision_spec and
 
340
    # new_revision_spec, since this is only really for use from cmd_diff and
 
341
    # it now always passes through a sequence of revision_specs -- mbp
 
342
    # 20061221
 
343
 
332
344
    def spec_tree(spec):
333
345
        if tree:
334
346
            revision = spec.in_store(tree.branch)
337
349
        revision_id = revision.rev_id
338
350
        branch = revision.branch
339
351
        return branch.repository.revision_tree(revision_id)
 
352
 
 
353
    if revision_specs is not None:
 
354
        assert (old_revision_spec is None
 
355
                and new_revision_spec is None)
 
356
        if len(revision_specs) > 0:
 
357
            old_revision_spec = revision_specs[0]
 
358
        if len(revision_specs) > 1:
 
359
            new_revision_spec = revision_specs[1]
 
360
 
340
361
    if old_revision_spec is None:
341
362
        old_tree = tree.basis_tree()
342
363
    else:
343
364
        old_tree = spec_tree(old_revision_spec)
344
365
 
345
 
    if new_revision_spec is None:
 
366
    if (new_revision_spec is None
 
367
        or new_revision_spec.spec is None):
346
368
        new_tree = tree
347
369
    else:
348
370
        new_tree = spec_tree(new_revision_spec)
 
371
 
349
372
    if new_tree is not tree:
350
373
        extra_trees = (tree,)
351
374
    else: