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

  • Committer: Martin Pool
  • Date: 2007-06-15 07:01:24 UTC
  • mfrom: (2528 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2530.
  • Revision ID: mbp@sourcefrog.net-20070615070124-clpwqh5gxc4wbf9l
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
    osutils,
46
46
    registry,
47
47
    repository,
 
48
    revisionspec,
48
49
    symbol_versioning,
49
50
    transport,
50
51
    tree as _mod_tree,
249
250
 
250
251
    To re-create the working tree, use "bzr checkout".
251
252
    """
252
 
    _see_also = ['checkout']
 
253
    _see_also = ['checkout', 'working-trees']
253
254
 
254
255
    takes_args = ['location?']
255
256
 
304
305
        if revision_info_list is not None:
305
306
            for rev in revision_info_list:
306
307
                revs.append(RevisionSpec.from_string(rev))
 
308
 
 
309
        b = Branch.open_containing(u'.')[0]
 
310
 
307
311
        if len(revs) == 0:
308
 
            raise errors.BzrCommandError('You must supply a revision identifier')
309
 
 
310
 
        b = WorkingTree.open_containing(u'.')[0].branch
 
312
            revs.append(RevisionSpec.from_string('-1'))
311
313
 
312
314
        for rev in revs:
313
315
            revinfo = rev.in_history(b)
314
316
            if revinfo.revno is None:
315
 
                print '     %s' % revinfo.rev_id
 
317
                dotted_map = b.get_revision_id_to_revno_map()
 
318
                revno = '.'.join(str(i) for i in dotted_map[revinfo.rev_id])
 
319
                print '%s %s' % (revno, revinfo.rev_id)
316
320
            else:
317
321
                print '%4d %s' % (revinfo.revno, revinfo.rev_id)
318
322
 
669
673
    location can be accessed.
670
674
    """
671
675
 
672
 
    _see_also = ['pull', 'update']
 
676
    _see_also = ['pull', 'update', 'working-trees']
673
677
    takes_options = ['remember', 'overwrite', 'verbose',
674
678
        Option('create-prefix',
675
679
               help='Create the path leading up to the branch '
751
755
                        " leading parent directories."
752
756
                        % location)
753
757
 
754
 
                cur_transport = to_transport
755
 
                needed = [cur_transport]
756
 
                # Recurse upwards until we can create a directory successfully
757
 
                while True:
758
 
                    new_transport = cur_transport.clone('..')
759
 
                    if new_transport.base == cur_transport.base:
760
 
                        raise errors.BzrCommandError("Failed to create path"
761
 
                                                     " prefix for %s."
762
 
                                                     % location)
763
 
                    try:
764
 
                        new_transport.mkdir('.')
765
 
                    except errors.NoSuchFile:
766
 
                        needed.append(new_transport)
767
 
                        cur_transport = new_transport
768
 
                    else:
769
 
                        break
770
 
 
771
 
                # Now we only need to create child directories
772
 
                while needed:
773
 
                    cur_transport = needed.pop()
774
 
                    cur_transport.ensure_base()
 
758
                _create_prefix(to_transport)
775
759
 
776
760
            # Now the target directory exists, but doesn't have a .bzr
777
761
            # directory. So we need to create it, along with any work to create
812
796
                try:
813
797
                    tree_to = dir_to.open_workingtree()
814
798
                except errors.NotLocalUrl:
815
 
                    warning('This transport does not update the working '
816
 
                            'tree of: %s' % (br_to.base,))
 
799
                    warning("This transport does not update the working " 
 
800
                            "tree of: %s. See 'bzr help working-trees' for "
 
801
                            "more information." % br_to.base)
817
802
                    push_result = br_from.push(br_to, overwrite)
818
803
                except errors.NoWorkingTree:
819
804
                    push_result = br_from.push(br_to, overwrite)
847
832
 
848
833
    If the TO_LOCATION is omitted, the last component of the FROM_LOCATION will
849
834
    be used.  In other words, "branch ../foo/bar" will attempt to create ./bar.
 
835
    If the FROM_LOCATION has no / or path separator embedded, the TO_LOCATION
 
836
    is derived from the FROM_LOCATION by stripping a leading scheme or drive
 
837
    identifier, if any. For example, "branch lp:foo-bar" will attempt to
 
838
    create ./foo-bar.
850
839
 
851
840
    To retrieve the branch as of a particular revision, supply the --revision
852
841
    parameter, as in "branch foo/bar -r 5".
876
865
                # RBC 20060209
877
866
                revision_id = br_from.last_revision()
878
867
            if to_location is None:
879
 
                to_location = os.path.basename(from_location.rstrip("/\\"))
 
868
                to_location = urlutils.derive_to_location(from_location)
880
869
                name = None
881
870
            else:
882
871
                name = os.path.basename(to_location) + '\n'
916
905
    
917
906
    If the TO_LOCATION is omitted, the last component of the BRANCH_LOCATION will
918
907
    be used.  In other words, "checkout ../foo/bar" will attempt to create ./bar.
 
908
    If the BRANCH_LOCATION has no / or path separator embedded, the TO_LOCATION
 
909
    is derived from the BRANCH_LOCATION by stripping a leading scheme or drive
 
910
    identifier, if any. For example, "checkout lp:foo-bar" will attempt to
 
911
    create ./foo-bar.
919
912
 
920
913
    To retrieve the branch as of a particular revision, supply the --revision
921
914
    parameter, as in "checkout foo/bar -r 5". Note that this will be immediately
952
945
        else:
953
946
            revision_id = None
954
947
        if to_location is None:
955
 
            to_location = os.path.basename(branch_location.rstrip("/\\"))
 
948
            to_location = urlutils.derive_to_location(branch_location)
956
949
        # if the source and to_location are the same, 
957
950
        # and there is no working tree,
958
951
        # then reconstitute a branch
1017
1010
    'bzr revert' instead of 'bzr commit' after the update.
1018
1011
    """
1019
1012
 
1020
 
    _see_also = ['pull']
 
1013
    _see_also = ['pull', 'working-trees']
1021
1014
    takes_args = ['dir?']
1022
1015
    aliases = ['up']
1023
1016
 
1061
1054
 
1062
1055
    Branches and working trees will also report any missing revisions.
1063
1056
    """
1064
 
    _see_also = ['revno']
 
1057
    _see_also = ['revno', 'working-trees', 'repositories']
1065
1058
    takes_args = ['location?']
1066
1059
    takes_options = ['verbose']
1067
1060
 
1068
1061
    @display_command
1069
 
    def run(self, location=None, verbose=False):
 
1062
    def run(self, location=None, verbose=0):
1070
1063
        from bzrlib.info import show_bzrdir_info
1071
1064
        show_bzrdir_info(bzrdir.BzrDir.open_containing(location)[0],
1072
1065
                         verbose=verbose)
1257
1250
    _see_also = ['init-repo', 'branch', 'checkout']
1258
1251
    takes_args = ['location?']
1259
1252
    takes_options = [
 
1253
        Option('create-prefix',
 
1254
               help='Create the path leading up to the branch '
 
1255
                    'if it does not already exist'),
1260
1256
         RegistryOption('format',
1261
1257
                help='Specify a format for this branch. '
1262
1258
                'See "help formats".',
1269
1265
                help='Never change revnos or the existing log.'
1270
1266
                '  Append revisions to it only.')
1271
1267
         ]
1272
 
    def run(self, location=None, format=None, append_revisions_only=False):
 
1268
    def run(self, location=None, format=None, append_revisions_only=False,
 
1269
            create_prefix=False):
1273
1270
        if format is None:
1274
1271
            format = bzrdir.format_registry.make_bzrdir('default')
1275
1272
        if location is None:
1282
1279
        # Just using os.mkdir, since I don't
1283
1280
        # believe that we want to create a bunch of
1284
1281
        # locations if the user supplies an extended path
1285
 
        # TODO: create-prefix
1286
 
        to_transport.ensure_base()
 
1282
        try:
 
1283
            to_transport.ensure_base()
 
1284
        except errors.NoSuchFile:
 
1285
            if not create_prefix:
 
1286
                raise errors.BzrCommandError("Parent directory of %s"
 
1287
                    " does not exist."
 
1288
                    "\nYou may supply --create-prefix to create all"
 
1289
                    " leading parent directories."
 
1290
                    % location)
 
1291
            _create_prefix(to_transport)
1287
1292
 
1288
1293
        try:
1289
1294
            existing_bzrdir = bzrdir.BzrDir.open(location)
1312
1317
class cmd_init_repository(Command):
1313
1318
    """Create a shared repository to hold branches.
1314
1319
 
1315
 
    New branches created under the repository directory will store their revisions
1316
 
    in the repository, not in the branch directory.
 
1320
    New branches created under the repository directory will store their
 
1321
    revisions in the repository, not in the branch directory.
 
1322
 
 
1323
    If the --no-trees option is used then the branches in the repository
 
1324
    will not have working trees by default.
1317
1325
 
1318
1326
    example:
1319
1327
        bzr init-repo --no-trees repo
1321
1329
        bzr checkout --lightweight repo/trunk trunk-checkout
1322
1330
        cd trunk-checkout
1323
1331
        (add files here)
 
1332
 
 
1333
    See 'bzr help repositories' for more information.
1324
1334
    """
1325
1335
 
1326
1336
    _see_also = ['init', 'branch', 'checkout']
1557
1567
        self.outf.write(tree.basedir + '\n')
1558
1568
 
1559
1569
 
 
1570
def _parse_limit(limitstring):
 
1571
    try:
 
1572
        return int(limitstring)
 
1573
    except ValueError:
 
1574
        msg = "The limit argument must be an integer."
 
1575
        raise errors.BzrCommandError(msg)
 
1576
 
 
1577
 
1560
1578
class cmd_log(Command):
1561
1579
    """Show log of a branch, file, or directory.
1562
1580
 
1587
1605
                            short_name='m',
1588
1606
                            help='show revisions whose message matches this regexp',
1589
1607
                            type=str),
 
1608
                     Option('limit', 
 
1609
                            help='limit the output to the first N revisions',
 
1610
                            type=_parse_limit),
1590
1611
                     ]
1591
1612
    encoding_type = 'replace'
1592
1613
 
1597
1618
            forward=False,
1598
1619
            revision=None,
1599
1620
            log_format=None,
1600
 
            message=None):
 
1621
            message=None,
 
1622
            limit=None):
1601
1623
        from bzrlib.log import show_log
1602
1624
        assert message is None or isinstance(message, basestring), \
1603
1625
            "invalid message argument %r" % message
1678
1700
                     direction=direction,
1679
1701
                     start_revision=rev1,
1680
1702
                     end_revision=rev2,
1681
 
                     search=message)
 
1703
                     search=message,
 
1704
                     limit=limit)
1682
1705
        finally:
1683
1706
            b.unlock()
1684
1707
 
2963
2986
    def run(self, other_branch=None, reverse=False, mine_only=False,
2964
2987
            theirs_only=False, log_format=None, long=False, short=False, line=False, 
2965
2988
            show_ids=False, verbose=False):
2966
 
        from bzrlib.missing import find_unmerged, iter_log_data
 
2989
        from bzrlib.missing import find_unmerged, iter_log_revisions
2967
2990
        from bzrlib.log import log_formatter
2968
2991
        local_branch = Branch.open_containing(u".")[0]
2969
2992
        parent = local_branch.get_parent()
2994
3017
                    remote_extra.reverse()
2995
3018
                if local_extra and not theirs_only:
2996
3019
                    print "You have %d extra revision(s):" % len(local_extra)
2997
 
                    for data in iter_log_data(local_extra, local_branch.repository,
2998
 
                                              verbose):
2999
 
                        lf.show(*data)
 
3020
                    for revision in iter_log_revisions(local_extra, 
 
3021
                                        local_branch.repository,
 
3022
                                        verbose):
 
3023
                        lf.log_revision(revision)
3000
3024
                    printed_local = True
3001
3025
                else:
3002
3026
                    printed_local = False
3004
3028
                    if printed_local is True:
3005
3029
                        print "\n\n"
3006
3030
                    print "You are missing %d revision(s):" % len(remote_extra)
3007
 
                    for data in iter_log_data(remote_extra, remote_branch.repository, 
3008
 
                                              verbose):
3009
 
                        lf.show(*data)
 
3031
                    for revision in iter_log_revisions(remote_extra, 
 
3032
                                        remote_branch.repository, 
 
3033
                                        verbose):
 
3034
                        lf.log_revision(revision)
3010
3035
                if not remote_extra and not local_extra:
3011
3036
                    status_code = 0
3012
3037
                    print "Branches are up to date."
3739
3764
    return conflicts
3740
3765
 
3741
3766
 
 
3767
def _create_prefix(cur_transport):
 
3768
    needed = [cur_transport]
 
3769
    # Recurse upwards until we can create a directory successfully
 
3770
    while True:
 
3771
        new_transport = cur_transport.clone('..')
 
3772
        if new_transport.base == cur_transport.base:
 
3773
            raise errors.BzrCommandError("Failed to create path"
 
3774
                                         " prefix for %s."
 
3775
                                         % location)
 
3776
        try:
 
3777
            new_transport.mkdir('.')
 
3778
        except errors.NoSuchFile:
 
3779
            needed.append(new_transport)
 
3780
            cur_transport = new_transport
 
3781
        else:
 
3782
            break
 
3783
 
 
3784
    # Now we only need to create child directories
 
3785
    while needed:
 
3786
        cur_transport = needed.pop()
 
3787
        cur_transport.ensure_base()
 
3788
 
3742
3789
# Compatibility
3743
3790
merge = _merge_helper
3744
3791