/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: Aaron Bentley
  • Date: 2007-06-12 14:57:07 UTC
  • mfrom: (2523 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2527.
  • Revision ID: abentley@panoramicfeedback.com-20070612145707-6ul10rmeln23my4f
Merge bzr.dev

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,
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
 
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
848
832
 
849
833
    If the TO_LOCATION is omitted, the last component of the FROM_LOCATION will
850
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.
851
839
 
852
840
    To retrieve the branch as of a particular revision, supply the --revision
853
841
    parameter, as in "branch foo/bar -r 5".
877
865
                # RBC 20060209
878
866
                revision_id = br_from.last_revision()
879
867
            if to_location is None:
880
 
                to_location = os.path.basename(from_location.rstrip("/\\"))
 
868
                to_location = urlutils.derive_to_location(from_location)
881
869
                name = None
882
870
            else:
883
871
                name = os.path.basename(to_location) + '\n'
917
905
    
918
906
    If the TO_LOCATION is omitted, the last component of the BRANCH_LOCATION will
919
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.
920
912
 
921
913
    To retrieve the branch as of a particular revision, supply the --revision
922
914
    parameter, as in "checkout foo/bar -r 5". Note that this will be immediately
953
945
        else:
954
946
            revision_id = None
955
947
        if to_location is None:
956
 
            to_location = os.path.basename(branch_location.rstrip("/\\"))
 
948
            to_location = urlutils.derive_to_location(branch_location)
957
949
        # if the source and to_location are the same, 
958
950
        # and there is no working tree,
959
951
        # then reconstitute a branch
1258
1250
    _see_also = ['init-repo', 'branch', 'checkout']
1259
1251
    takes_args = ['location?']
1260
1252
    takes_options = [
 
1253
        Option('create-prefix',
 
1254
               help='Create the path leading up to the branch '
 
1255
                    'if it does not already exist'),
1261
1256
         RegistryOption('format',
1262
1257
                help='Specify a format for this branch. '
1263
1258
                'See "help formats".',
1270
1265
                help='Never change revnos or the existing log.'
1271
1266
                '  Append revisions to it only.')
1272
1267
         ]
1273
 
    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):
1274
1270
        if format is None:
1275
1271
            format = bzrdir.format_registry.make_bzrdir('default')
1276
1272
        if location is None:
1283
1279
        # Just using os.mkdir, since I don't
1284
1280
        # believe that we want to create a bunch of
1285
1281
        # locations if the user supplies an extended path
1286
 
        # TODO: create-prefix
1287
 
        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)
1288
1292
 
1289
1293
        try:
1290
1294
            existing_bzrdir = bzrdir.BzrDir.open(location)
1563
1567
        self.outf.write(tree.basedir + '\n')
1564
1568
 
1565
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
 
1566
1578
class cmd_log(Command):
1567
1579
    """Show log of a branch, file, or directory.
1568
1580
 
1593
1605
                            short_name='m',
1594
1606
                            help='show revisions whose message matches this regexp',
1595
1607
                            type=str),
 
1608
                     Option('limit', 
 
1609
                            help='limit the output to the first N revisions',
 
1610
                            type=_parse_limit),
1596
1611
                     ]
1597
1612
    encoding_type = 'replace'
1598
1613
 
1603
1618
            forward=False,
1604
1619
            revision=None,
1605
1620
            log_format=None,
1606
 
            message=None):
 
1621
            message=None,
 
1622
            limit=None):
1607
1623
        from bzrlib.log import show_log
1608
1624
        assert message is None or isinstance(message, basestring), \
1609
1625
            "invalid message argument %r" % message
1684
1700
                     direction=direction,
1685
1701
                     start_revision=rev1,
1686
1702
                     end_revision=rev2,
1687
 
                     search=message)
 
1703
                     search=message,
 
1704
                     limit=limit)
1688
1705
        finally:
1689
1706
            b.unlock()
1690
1707
 
3749
3766
    return conflicts
3750
3767
 
3751
3768
 
 
3769
def _create_prefix(cur_transport):
 
3770
    needed = [cur_transport]
 
3771
    # Recurse upwards until we can create a directory successfully
 
3772
    while True:
 
3773
        new_transport = cur_transport.clone('..')
 
3774
        if new_transport.base == cur_transport.base:
 
3775
            raise errors.BzrCommandError("Failed to create path"
 
3776
                                         " prefix for %s."
 
3777
                                         % location)
 
3778
        try:
 
3779
            new_transport.mkdir('.')
 
3780
        except errors.NoSuchFile:
 
3781
            needed.append(new_transport)
 
3782
            cur_transport = new_transport
 
3783
        else:
 
3784
            break
 
3785
 
 
3786
    # Now we only need to create child directories
 
3787
    while needed:
 
3788
        cur_transport = needed.pop()
 
3789
        cur_transport.ensure_base()
 
3790
 
3752
3791
# Compatibility
3753
3792
merge = _merge_helper
3754
3793