~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-12-21 04:13:14 UTC
  • mfrom: (2197.2.2 diff-refactoring)
  • Revision ID: pqm@pqm.ubuntu.com-20061221041314-2991e63a023efcf1
(mbp) initial cleanups of cmd_diff (r=john)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1213
1213
    #       deleted files.
1214
1214
 
1215
1215
    # TODO: This probably handles non-Unix newlines poorly.
1216
 
    
 
1216
 
1217
1217
    takes_args = ['file*']
1218
1218
    takes_options = ['revision', 'diff-options',
1219
1219
        Option('prefix', type=str,
1236
1236
        elif prefix == '1':
1237
1237
            old_label = 'old/'
1238
1238
            new_label = 'new/'
1239
 
        else:
1240
 
            if not ':' in prefix:
1241
 
                 raise BzrCommandError(
1242
 
                     "--prefix expects two values separated by a colon")
 
1239
        elif ':' in prefix:
1243
1240
            old_label, new_label = prefix.split(":")
 
1241
        else:
 
1242
            raise BzrCommandError(
 
1243
                "--prefix expects two values separated by a colon")
 
1244
 
 
1245
        if revision and len(revision) > 2:
 
1246
            raise errors.BzrCommandError('bzr diff --revision takes exactly'
 
1247
                                         ' one or two revision specifiers')
1244
1248
        
1245
1249
        try:
1246
1250
            tree1, file_list = internal_tree_files(file_list)
1266
1270
                tree1, tree2 = None, None
1267
1271
            else:
1268
1272
                raise
1269
 
        if revision is not None:
1270
 
            if tree2 is not None:
1271
 
                raise errors.BzrCommandError("Can't specify -r with two branches")
1272
 
            if (len(revision) == 1) or (revision[1].spec is None):
1273
 
                return diff_cmd_helper(tree1, file_list, diff_options,
1274
 
                                       revision[0], 
1275
 
                                       old_label=old_label, new_label=new_label)
1276
 
            elif len(revision) == 2:
1277
 
                return diff_cmd_helper(tree1, file_list, diff_options,
1278
 
                                       revision[0], revision[1],
1279
 
                                       old_label=old_label, new_label=new_label)
1280
 
            else:
1281
 
                raise errors.BzrCommandError('bzr diff --revision takes exactly'
1282
 
                                             ' one or two revision identifiers')
1283
 
        else:
1284
 
            if tree2 is not None:
1285
 
                return show_diff_trees(tree1, tree2, sys.stdout, 
1286
 
                                       specific_files=file_list,
1287
 
                                       external_diff_options=diff_options,
1288
 
                                       old_label=old_label, new_label=new_label)
1289
 
            else:
1290
 
                return diff_cmd_helper(tree1, file_list, diff_options,
1291
 
                                       old_label=old_label, new_label=new_label)
 
1273
 
 
1274
        if tree2 is not None:
 
1275
            if revision is not None:
 
1276
                # FIXME: but there should be a clean way to diff between
 
1277
                # non-default versions of two trees, it's not hard to do
 
1278
                # internally...
 
1279
                raise errors.BzrCommandError(
 
1280
                        "Sorry, diffing arbitrary revisions across branches "
 
1281
                        "is not implemented yet")
 
1282
            return show_diff_trees(tree1, tree2, sys.stdout, 
 
1283
                                   specific_files=file_list,
 
1284
                                   external_diff_options=diff_options,
 
1285
                                   old_label=old_label, new_label=new_label)
 
1286
 
 
1287
        return diff_cmd_helper(tree1, file_list, diff_options,
 
1288
                               revision_specs=revision,
 
1289
                               old_label=old_label, new_label=new_label)
1292
1290
 
1293
1291
 
1294
1292
class cmd_deleted(Command):