/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-17 08:32:56 UTC
  • Revision ID: mbp@sourcefrog.net-20050817083255-894936d5aebf7a95
- merge merge improvements from aaron

  revisions to merge are now specified by the -r parameter; the 
  /@ syntax is no longer needed

  abentley@panoramicfeedback.com-20050811205739-dc1988c004f9503e

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'
1433
1455
 
1434
1456
 
1435
1457
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
 
 
 
1458
    """Perform a three-way merge.
 
1459
    
 
1460
    The branch is the branch you will merge from.  By default, it will merge
 
1461
    the latest revision.  If you specify a revision, that revision will be
 
1462
    merged.  If you specify two revisions, the first will be used as a BASE, 
 
1463
    and the second one as OTHER.  Revision numbers are always relative to the
 
1464
    specified branch.
 
1465
    
 
1466
    Examples:
 
1467
 
 
1468
    To merge the latest revision from bzr.dev
 
1469
    bzr merge ../bzr.dev
 
1470
 
 
1471
    To merge changes up to and including revision 82 from bzr.dev
 
1472
    bzr merge -r 82 ../bzr.dev
 
1473
 
 
1474
    To merge the changes introduced by 82, without previous changes:
 
1475
    bzr merge -r 81..82 ../bzr.dev
 
1476
    
1454
1477
    merge refuses to run if there are any uncommitted changes, unless
1455
1478
    --force is given.
1456
1479
    """
1457
 
    takes_args = ['other_spec', 'base_spec?']
1458
 
    takes_options = ['force', 'merge-type']
 
1480
    takes_args = ['branch?']
 
1481
    takes_options = ['revision', 'force', 'merge-type']
1459
1482
 
1460
 
    def run(self, other_spec, base_spec=None, force=False, merge_type=None):
 
1483
    def run(self, branch='.', revision=None, force=False, 
 
1484
            merge_type=None):
1461
1485
        from bzrlib.merge import merge
1462
1486
        from bzrlib.merge_core import ApplyMerge3
1463
1487
        if merge_type is None:
1464
1488
            merge_type = ApplyMerge3
1465
 
        merge(parse_spec(other_spec), parse_spec(base_spec),
1466
 
              check_clean=(not force), merge_type=merge_type)
 
1489
 
 
1490
        if revision is None or len(revision) < 1:
 
1491
            base = (None, None)
 
1492
            other = (branch, -1)
 
1493
        else:
 
1494
            if len(revision) == 1:
 
1495
                other = (branch, revision[0])
 
1496
                base = (None, None)
 
1497
            else:
 
1498
                assert len(revision) == 2
 
1499
                if None in revision:
 
1500
                    raise BzrCommandError(
 
1501
                        "Merge doesn't permit that revision specifier.")
 
1502
                base = (branch, revision[0])
 
1503
                other = (branch, revision[1])
 
1504
            
 
1505
        merge(other, base, check_clean=(not force), merge_type=merge_type)
1467
1506
 
1468
1507
 
1469
1508
class cmd_revert(Command):
1514
1553
 
1515
1554
 
1516
1555
 
 
1556
class cmd_missing(Command):
 
1557
    """What is missing in this branch relative to other branch.
 
1558
    """
 
1559
    takes_args = ['remote?']
 
1560
    aliases = ['mis', 'miss']
 
1561
    # We don't have to add quiet to the list, because 
 
1562
    # unknown options are parsed as booleans
 
1563
    takes_options = ['verbose', 'quiet']
 
1564
 
 
1565
    def run(self, remote=None, verbose=False, quiet=False):
 
1566
        from bzrlib.branch import find_branch, DivergedBranches
 
1567
        from bzrlib.errors import BzrCommandError
 
1568
        from bzrlib.missing import get_parent, show_missing
 
1569
 
 
1570
        if verbose and quiet:
 
1571
            raise BzrCommandError('Cannot pass both quiet and verbose')
 
1572
 
 
1573
        b = find_branch('.')
 
1574
        parent = get_parent(b)
 
1575
        if remote is None:
 
1576
            if parent is None:
 
1577
                raise BzrCommandError("No missing location known or specified.")
 
1578
            else:
 
1579
                if not quiet:
 
1580
                    print "Using last location: %s" % parent
 
1581
                remote = parent
 
1582
        elif parent is None:
 
1583
            # We only update x-pull if it did not exist, missing should not change the parent
 
1584
            b.controlfile('x-pull', 'wb').write(remote + '\n')
 
1585
        br_remote = find_branch(remote)
 
1586
 
 
1587
        return show_missing(b, br_remote, verbose=verbose, quiet=quiet)
 
1588
 
 
1589
 
1517
1590
class cmd_plugins(Command):
1518
1591
    """List plugins"""
1519
1592
    hidden = True
1546
1619
    'no-recurse':             None,
1547
1620
    'profile':                None,
1548
1621
    'revision':               _parse_revision_str,
 
1622
    'short':                  None,
1549
1623
    'show-ids':               None,
1550
1624
    'timezone':               str,
1551
1625
    'verbose':                None,