/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/commands.py

  • Committer: Martin Pool
  • Date: 2005-08-18 04:25:42 UTC
  • Revision ID: mbp@sourcefrog.net-20050818042542-6af9da978f695195
- check for email address in BRANCH_ROOT/.bzr/email, so you can 
  easily use different per-project personas

Show diffs side-by-side

added added

removed removed

Lines of Context:
141
141
        raise BzrCommandError(msg)
142
142
    
143
143
 
 
144
def get_merge_type(typestring):
 
145
    """Attempt to find the merge class/factory associated with a string."""
 
146
    from merge import merge_types
 
147
    try:
 
148
        return merge_types[typestring][0]
 
149
    except KeyError:
 
150
        templ = '%s%%7s: %%s' % (' '*12)
 
151
        lines = [templ % (f[0], f[1][1]) for f in merge_types.iteritems()]
 
152
        type_list = '\n'.join(lines)
 
153
        msg = "No known merge type %s. Supported types are:\n%s" %\
 
154
            (typestring, type_list)
 
155
        raise BzrCommandError(msg)
 
156
    
 
157
 
144
158
 
145
159
def _get_cmd_dict(plugins_override=True):
146
160
    d = {}
837
851
    If files are listed, only the changes in those files are listed.
838
852
    Otherwise, all changes for the tree are listed.
839
853
 
840
 
    TODO: Given two revision arguments, show the difference between them.
841
 
 
842
854
    TODO: Allow diff across branches.
843
855
 
844
856
    TODO: Option to use external diff command; could be GNU diff, wdiff,
853
865
          deleted files.
854
866
 
855
867
    TODO: This probably handles non-Unix newlines poorly.
 
868
 
 
869
    examples:
 
870
        bzr diff
 
871
        bzr diff -r1
 
872
        bzr diff -r1:2
856
873
    """
857
874
    
858
875
    takes_args = ['file*']
871
888
        else:
872
889
            b = find_branch('.')
873
890
 
874
 
        # TODO: Make show_diff support taking 2 arguments
875
 
        base_rev = None
876
891
        if revision is not None:
877
 
            if len(revision) != 1:
878
 
                raise BzrCommandError('bzr diff --revision takes exactly one revision identifier')
879
 
            base_rev = revision[0]
880
 
    
881
 
        show_diff(b, base_rev, specific_files=file_list,
882
 
                  external_diff_options=diff_options)
883
 
 
 
892
            if len(revision) == 1:
 
893
                show_diff(b, revision[0], specific_files=file_list,
 
894
                          external_diff_options=diff_options)
 
895
            elif len(revision) == 2:
 
896
                show_diff(b, revision[0], specific_files=file_list,
 
897
                          external_diff_options=diff_options,
 
898
                          revision2=revision[1])
 
899
            else:
 
900
                raise BzrCommandError('bzr diff --revision takes exactly one or two revision identifiers')
 
901
        else:
 
902
            show_diff(b, None, specific_files=file_list,
 
903
                      external_diff_options=diff_options)
884
904
 
885
905
        
886
906
 
967
987
    """
968
988
 
969
989
    takes_args = ['filename?']
970
 
    takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision','long', 'message']
 
990
    takes_options = ['forward', 'timezone', 'verbose', 'show-ids', 'revision',
 
991
                     'long', 'message', 'short',]
971
992
    
972
993
    def run(self, filename=None, timezone='original',
973
994
            verbose=False,
975
996
            forward=False,
976
997
            revision=None,
977
998
            message=None,
978
 
            long=False):
 
999
            long=False,
 
1000
            short=False):
979
1001
        from bzrlib.branch import find_branch
980
1002
        from bzrlib.log import log_formatter, show_log
981
1003
        import codecs
1015
1037
        # in e.g. the default C locale.
1016
1038
        outf = codecs.getwriter(bzrlib.user_encoding)(sys.stdout, errors='replace')
1017
1039
 
1018
 
        if long:
 
1040
        if not short:
1019
1041
            log_format = 'long'
1020
1042
        else:
1021
1043
            log_format = 'short'
1359
1381
    takes_options = ['email']
1360
1382
    
1361
1383
    def run(self, email=False):
 
1384
        try:
 
1385
            b = bzrlib.branch.find_branch('.')
 
1386
        except:
 
1387
            b = None
 
1388
        
1362
1389
        if email:
1363
 
            print bzrlib.osutils.user_email()
 
1390
            print bzrlib.osutils.user_email(b)
1364
1391
        else:
1365
 
            print bzrlib.osutils.username()
 
1392
            print bzrlib.osutils.username(b)
1366
1393
 
1367
1394
 
1368
1395
class cmd_selftest(Command):
1433
1460
 
1434
1461
 
1435
1462
class cmd_merge(Command):
1436
 
    """Perform a three-way merge of trees.
1437
 
    
1438
 
    The SPEC parameters are working tree or revision specifiers.  Working trees
1439
 
    are specified using standard paths or urls.  No component of a directory
1440
 
    path may begin with '@'.
1441
 
    
1442
 
    Working tree examples: '.', '..', 'foo@', but NOT 'foo/@bar'
1443
 
 
1444
 
    Revisions are specified using a dirname/@revno pair, where dirname is the
1445
 
    branch directory and revno is the revision within that branch.  If no revno
1446
 
    is specified, the latest revision is used.
1447
 
 
1448
 
    Revision examples: './@127', 'foo/@', '../@1'
1449
 
 
1450
 
    The OTHER_SPEC parameter is required.  If the BASE_SPEC parameter is
1451
 
    not supplied, the common ancestor of OTHER_SPEC the current branch is used
1452
 
    as the BASE.
1453
 
 
 
1463
    """Perform a three-way merge.
 
1464
    
 
1465
    The branch is the branch you will merge from.  By default, it will merge
 
1466
    the latest revision.  If you specify a revision, that revision will be
 
1467
    merged.  If you specify two revisions, the first will be used as a BASE, 
 
1468
    and the second one as OTHER.  Revision numbers are always relative to the
 
1469
    specified branch.
 
1470
    
 
1471
    Examples:
 
1472
 
 
1473
    To merge the latest revision from bzr.dev
 
1474
    bzr merge ../bzr.dev
 
1475
 
 
1476
    To merge changes up to and including revision 82 from bzr.dev
 
1477
    bzr merge -r 82 ../bzr.dev
 
1478
 
 
1479
    To merge the changes introduced by 82, without previous changes:
 
1480
    bzr merge -r 81..82 ../bzr.dev
 
1481
    
1454
1482
    merge refuses to run if there are any uncommitted changes, unless
1455
1483
    --force is given.
1456
1484
    """
1457
 
    takes_args = ['other_spec', 'base_spec?']
1458
 
    takes_options = ['force', 'merge-type']
 
1485
    takes_args = ['branch?']
 
1486
    takes_options = ['revision', 'force', 'merge-type']
1459
1487
 
1460
 
    def run(self, other_spec, base_spec=None, force=False, merge_type=None):
 
1488
    def run(self, branch='.', revision=None, force=False, 
 
1489
            merge_type=None):
1461
1490
        from bzrlib.merge import merge
1462
1491
        from bzrlib.merge_core import ApplyMerge3
1463
1492
        if merge_type is None:
1464
1493
            merge_type = ApplyMerge3
1465
 
        merge(parse_spec(other_spec), parse_spec(base_spec),
1466
 
              check_clean=(not force), merge_type=merge_type)
 
1494
 
 
1495
        if revision is None or len(revision) < 1:
 
1496
            base = (None, None)
 
1497
            other = (branch, -1)
 
1498
        else:
 
1499
            if len(revision) == 1:
 
1500
                other = (branch, revision[0])
 
1501
                base = (None, None)
 
1502
            else:
 
1503
                assert len(revision) == 2
 
1504
                if None in revision:
 
1505
                    raise BzrCommandError(
 
1506
                        "Merge doesn't permit that revision specifier.")
 
1507
                base = (branch, revision[0])
 
1508
                other = (branch, revision[1])
 
1509
            
 
1510
        merge(other, base, check_clean=(not force), merge_type=merge_type)
1467
1511
 
1468
1512
 
1469
1513
class cmd_revert(Command):
1514
1558
 
1515
1559
 
1516
1560
 
 
1561
class cmd_missing(Command):
 
1562
    """What is missing in this branch relative to other branch.
 
1563
    """
 
1564
    takes_args = ['remote?']
 
1565
    aliases = ['mis', 'miss']
 
1566
    # We don't have to add quiet to the list, because 
 
1567
    # unknown options are parsed as booleans
 
1568
    takes_options = ['verbose', 'quiet']
 
1569
 
 
1570
    def run(self, remote=None, verbose=False, quiet=False):
 
1571
        from bzrlib.branch import find_branch, DivergedBranches
 
1572
        from bzrlib.errors import BzrCommandError
 
1573
        from bzrlib.missing import get_parent, show_missing
 
1574
 
 
1575
        if verbose and quiet:
 
1576
            raise BzrCommandError('Cannot pass both quiet and verbose')
 
1577
 
 
1578
        b = find_branch('.')
 
1579
        parent = get_parent(b)
 
1580
        if remote is None:
 
1581
            if parent is None:
 
1582
                raise BzrCommandError("No missing location known or specified.")
 
1583
            else:
 
1584
                if not quiet:
 
1585
                    print "Using last location: %s" % parent
 
1586
                remote = parent
 
1587
        elif parent is None:
 
1588
            # We only update x-pull if it did not exist, missing should not change the parent
 
1589
            b.controlfile('x-pull', 'wb').write(remote + '\n')
 
1590
        br_remote = find_branch(remote)
 
1591
 
 
1592
        return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
 
1593
 
 
1594
 
1517
1595
class cmd_plugins(Command):
1518
1596
    """List plugins"""
1519
1597
    hidden = True
1546
1624
    'no-recurse':             None,
1547
1625
    'profile':                None,
1548
1626
    'revision':               _parse_revision_str,
 
1627
    'short':                  None,
1549
1628
    'show-ids':               None,
1550
1629
    'timezone':               str,
1551
1630
    'verbose':                None,