/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: John Arbash Meinel
  • Date: 2007-06-28 23:18:09 UTC
  • mfrom: (2562 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2566.
  • Revision ID: john@arbash-meinel.com-20070628231809-pqbt7puoqj8bl07b
[merge] bzr.dev 2562

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
lazy_import(globals(), """
24
24
import codecs
25
25
import errno
26
 
import smtplib
27
26
import sys
28
27
import tempfile
29
28
import time
45
44
    osutils,
46
45
    registry,
47
46
    repository,
 
47
    revisionspec,
48
48
    symbol_versioning,
49
49
    transport,
50
50
    tree as _mod_tree,
54
54
from bzrlib.branch import Branch
55
55
from bzrlib.bundle.apply_bundle import install_bundle, merge_bundle
56
56
from bzrlib.conflicts import ConflictList
57
 
from bzrlib.revision import common_ancestor
58
57
from bzrlib.revisionspec import RevisionSpec
 
58
from bzrlib.smtp_connection import SMTPConnection
59
59
from bzrlib.workingtree import WorkingTree
60
60
""")
61
61
 
249
249
 
250
250
    To re-create the working tree, use "bzr checkout".
251
251
    """
252
 
    _see_also = ['checkout']
 
252
    _see_also = ['checkout', 'working-trees']
253
253
 
254
254
    takes_args = ['location?']
255
255
 
304
304
        if revision_info_list is not None:
305
305
            for rev in revision_info_list:
306
306
                revs.append(RevisionSpec.from_string(rev))
 
307
 
 
308
        b = Branch.open_containing(u'.')[0]
 
309
 
307
310
        if len(revs) == 0:
308
 
            raise errors.BzrCommandError('You must supply a revision identifier')
309
 
 
310
 
        b = WorkingTree.open_containing(u'.')[0].branch
 
311
            revs.append(RevisionSpec.from_string('-1'))
311
312
 
312
313
        for rev in revs:
313
314
            revinfo = rev.in_history(b)
314
315
            if revinfo.revno is None:
315
 
                print '     %s' % revinfo.rev_id
 
316
                dotted_map = b.get_revision_id_to_revno_map()
 
317
                revno = '.'.join(str(i) for i in dotted_map[revinfo.rev_id])
 
318
                print '%s %s' % (revno, revinfo.rev_id)
316
319
            else:
317
320
                print '%4d %s' % (revinfo.revno, revinfo.rev_id)
318
321
 
669
672
    location can be accessed.
670
673
    """
671
674
 
672
 
    _see_also = ['pull', 'update']
 
675
    _see_also = ['pull', 'update', 'working-trees']
673
676
    takes_options = ['remember', 'overwrite', 'verbose',
674
677
        Option('create-prefix',
675
678
               help='Create the path leading up to the branch '
709
712
                location = stored_loc
710
713
 
711
714
        to_transport = transport.get_transport(location)
712
 
        location_url = to_transport.base
713
715
 
714
716
        br_to = repository_to = dir_to = None
715
717
        try:
752
754
                        " leading parent directories."
753
755
                        % location)
754
756
 
755
 
                cur_transport = to_transport
756
 
                needed = [cur_transport]
757
 
                # Recurse upwards until we can create a directory successfully
758
 
                while True:
759
 
                    new_transport = cur_transport.clone('..')
760
 
                    if new_transport.base == cur_transport.base:
761
 
                        raise errors.BzrCommandError("Failed to create path"
762
 
                                                     " prefix for %s."
763
 
                                                     % location)
764
 
                    try:
765
 
                        new_transport.mkdir('.')
766
 
                    except errors.NoSuchFile:
767
 
                        needed.append(new_transport)
768
 
                        cur_transport = new_transport
769
 
                    else:
770
 
                        break
 
757
                _create_prefix(to_transport)
771
758
 
772
 
                # Now we only need to create child directories
773
 
                while needed:
774
 
                    cur_transport = needed.pop()
775
 
                    cur_transport.mkdir('.')
776
 
            
777
759
            # Now the target directory exists, but doesn't have a .bzr
778
760
            # directory. So we need to create it, along with any work to create
779
761
            # all of the dependent branches, etc.
780
 
            dir_to = br_from.bzrdir.clone(location_url,
 
762
            dir_to = br_from.bzrdir.clone_on_transport(to_transport,
781
763
                revision_id=br_from.last_revision())
782
764
            br_to = dir_to.open_branch()
783
765
            # TODO: Some more useful message about what was copied
813
795
                try:
814
796
                    tree_to = dir_to.open_workingtree()
815
797
                except errors.NotLocalUrl:
816
 
                    warning('This transport does not update the working '
817
 
                            'tree of: %s' % (br_to.base,))
 
798
                    warning("This transport does not update the working " 
 
799
                            "tree of: %s. See 'bzr help working-trees' for "
 
800
                            "more information." % br_to.base)
818
801
                    push_result = br_from.push(br_to, overwrite)
819
802
                except errors.NoWorkingTree:
820
803
                    push_result = br_from.push(br_to, overwrite)
848
831
 
849
832
    If the TO_LOCATION is omitted, the last component of the FROM_LOCATION will
850
833
    be used.  In other words, "branch ../foo/bar" will attempt to create ./bar.
 
834
    If the FROM_LOCATION has no / or path separator embedded, the TO_LOCATION
 
835
    is derived from the FROM_LOCATION by stripping a leading scheme or drive
 
836
    identifier, if any. For example, "branch lp:foo-bar" will attempt to
 
837
    create ./foo-bar.
851
838
 
852
839
    To retrieve the branch as of a particular revision, supply the --revision
853
840
    parameter, as in "branch foo/bar -r 5".
877
864
                # RBC 20060209
878
865
                revision_id = br_from.last_revision()
879
866
            if to_location is None:
880
 
                to_location = os.path.basename(from_location.rstrip("/\\"))
 
867
                to_location = urlutils.derive_to_location(from_location)
881
868
                name = None
882
869
            else:
883
870
                name = os.path.basename(to_location) + '\n'
917
904
    
918
905
    If the TO_LOCATION is omitted, the last component of the BRANCH_LOCATION will
919
906
    be used.  In other words, "checkout ../foo/bar" will attempt to create ./bar.
 
907
    If the BRANCH_LOCATION has no / or path separator embedded, the TO_LOCATION
 
908
    is derived from the BRANCH_LOCATION by stripping a leading scheme or drive
 
909
    identifier, if any. For example, "checkout lp:foo-bar" will attempt to
 
910
    create ./foo-bar.
920
911
 
921
912
    To retrieve the branch as of a particular revision, supply the --revision
922
913
    parameter, as in "checkout foo/bar -r 5". Note that this will be immediately
953
944
        else:
954
945
            revision_id = None
955
946
        if to_location is None:
956
 
            to_location = os.path.basename(branch_location.rstrip("/\\"))
 
947
            to_location = urlutils.derive_to_location(branch_location)
957
948
        # if the source and to_location are the same, 
958
949
        # and there is no working tree,
959
950
        # then reconstitute a branch
1018
1009
    'bzr revert' instead of 'bzr commit' after the update.
1019
1010
    """
1020
1011
 
1021
 
    _see_also = ['pull']
 
1012
    _see_also = ['pull', 'working-trees']
1022
1013
    takes_args = ['dir?']
1023
1014
    aliases = ['up']
1024
1015
 
1062
1053
 
1063
1054
    Branches and working trees will also report any missing revisions.
1064
1055
    """
1065
 
    _see_also = ['revno']
 
1056
    _see_also = ['revno', 'working-trees', 'repositories']
1066
1057
    takes_args = ['location?']
1067
1058
    takes_options = ['verbose']
1068
1059
 
1069
1060
    @display_command
1070
 
    def run(self, location=None, verbose=False):
 
1061
    def run(self, location=None, verbose=0):
1071
1062
        from bzrlib.info import show_bzrdir_info
1072
1063
        show_bzrdir_info(bzrdir.BzrDir.open_containing(location)[0],
1073
1064
                         verbose=verbose)
1258
1249
    _see_also = ['init-repo', 'branch', 'checkout']
1259
1250
    takes_args = ['location?']
1260
1251
    takes_options = [
 
1252
        Option('create-prefix',
 
1253
               help='Create the path leading up to the branch '
 
1254
                    'if it does not already exist'),
1261
1255
         RegistryOption('format',
1262
1256
                help='Specify a format for this branch. '
1263
1257
                'See "help formats".',
1270
1264
                help='Never change revnos or the existing log.'
1271
1265
                '  Append revisions to it only.')
1272
1266
         ]
1273
 
    def run(self, location=None, format=None, append_revisions_only=False):
 
1267
    def run(self, location=None, format=None, append_revisions_only=False,
 
1268
            create_prefix=False):
1274
1269
        if format is None:
1275
1270
            format = bzrdir.format_registry.make_bzrdir('default')
1276
1271
        if location is None:
1283
1278
        # Just using os.mkdir, since I don't
1284
1279
        # believe that we want to create a bunch of
1285
1280
        # locations if the user supplies an extended path
1286
 
        # TODO: create-prefix
1287
1281
        try:
1288
 
            to_transport.mkdir('.')
1289
 
        except errors.FileExists:
1290
 
            pass
1291
 
                    
 
1282
            to_transport.ensure_base()
 
1283
        except errors.NoSuchFile:
 
1284
            if not create_prefix:
 
1285
                raise errors.BzrCommandError("Parent directory of %s"
 
1286
                    " does not exist."
 
1287
                    "\nYou may supply --create-prefix to create all"
 
1288
                    " leading parent directories."
 
1289
                    % location)
 
1290
            _create_prefix(to_transport)
 
1291
 
1292
1292
        try:
1293
1293
            existing_bzrdir = bzrdir.BzrDir.open(location)
1294
1294
        except errors.NotBranchError:
1316
1316
class cmd_init_repository(Command):
1317
1317
    """Create a shared repository to hold branches.
1318
1318
 
1319
 
    New branches created under the repository directory will store their revisions
1320
 
    in the repository, not in the branch directory.
 
1319
    New branches created under the repository directory will store their
 
1320
    revisions in the repository, not in the branch directory.
 
1321
 
 
1322
    If the --no-trees option is used then the branches in the repository
 
1323
    will not have working trees by default.
1321
1324
 
1322
1325
    example:
1323
1326
        bzr init-repo --no-trees repo
1325
1328
        bzr checkout --lightweight repo/trunk trunk-checkout
1326
1329
        cd trunk-checkout
1327
1330
        (add files here)
 
1331
 
 
1332
    See 'bzr help repositories' for more information.
1328
1333
    """
1329
1334
 
1330
1335
    _see_also = ['init', 'branch', 'checkout']
1349
1354
            location = '.'
1350
1355
 
1351
1356
        to_transport = transport.get_transport(location)
1352
 
        try:
1353
 
            to_transport.mkdir('.')
1354
 
        except errors.FileExists:
1355
 
            pass
 
1357
        to_transport.ensure_base()
1356
1358
 
1357
1359
        newdir = format.initialize_on_transport(to_transport)
1358
1360
        repo = newdir.create_repository(shared=True)
1564
1566
        self.outf.write(tree.basedir + '\n')
1565
1567
 
1566
1568
 
 
1569
def _parse_limit(limitstring):
 
1570
    try:
 
1571
        return int(limitstring)
 
1572
    except ValueError:
 
1573
        msg = "The limit argument must be an integer."
 
1574
        raise errors.BzrCommandError(msg)
 
1575
 
 
1576
 
1567
1577
class cmd_log(Command):
1568
1578
    """Show log of a branch, file, or directory.
1569
1579
 
1594
1604
                            short_name='m',
1595
1605
                            help='show revisions whose message matches this regexp',
1596
1606
                            type=str),
 
1607
                     Option('limit', 
 
1608
                            help='limit the output to the first N revisions',
 
1609
                            type=_parse_limit),
1597
1610
                     ]
1598
1611
    encoding_type = 'replace'
1599
1612
 
1604
1617
            forward=False,
1605
1618
            revision=None,
1606
1619
            log_format=None,
1607
 
            message=None):
 
1620
            message=None,
 
1621
            limit=None):
1608
1622
        from bzrlib.log import show_log
1609
1623
        assert message is None or isinstance(message, basestring), \
1610
1624
            "invalid message argument %r" % message
1685
1699
                     direction=direction,
1686
1700
                     start_revision=rev1,
1687
1701
                     end_revision=rev2,
1688
 
                     search=message)
 
1702
                     search=message,
 
1703
                     limit=limit)
1689
1704
        finally:
1690
1705
            b.unlock()
1691
1706
 
2343
2358
class cmd_selftest(Command):
2344
2359
    """Run internal test suite.
2345
2360
    
2346
 
    This creates temporary test directories in the working directory, but no
2347
 
    existing data is affected.  These directories are deleted if the tests
2348
 
    pass, or left behind to help in debugging if they fail and --keep-output
2349
 
    is specified.
2350
 
    
2351
2361
    If arguments are given, they are regular expressions that say which tests
2352
2362
    should run.  Tests matching any expression are run, and other tests are
2353
2363
    not run.
2461
2471
            from bzrlib.tests import clean_selftest_output
2462
2472
            clean_selftest_output()
2463
2473
            return 0
 
2474
        if keep_output:
 
2475
            warning("notice: selftest --keep-output "
 
2476
                    "is no longer supported; "
 
2477
                    "test output is always removed")
2464
2478
 
2465
2479
        if numbered_dirs is None and sys.platform == 'win32':
2466
2480
            numbered_dirs = True
2489
2503
            result = selftest(verbose=verbose, 
2490
2504
                              pattern=pattern,
2491
2505
                              stop_on_failure=one, 
2492
 
                              keep_output=keep_output,
2493
2506
                              transport=transport,
2494
2507
                              test_suite_factory=test_suite_factory,
2495
2508
                              lsprof_timed=lsprof_timed,
2538
2551
    
2539
2552
    @display_command
2540
2553
    def run(self, branch, other):
2541
 
        from bzrlib.revision import MultipleRevisionSources
 
2554
        from bzrlib.revision import ensure_null, MultipleRevisionSources
2542
2555
        
2543
2556
        branch1 = Branch.open_containing(branch)[0]
2544
2557
        branch2 = Branch.open_containing(other)[0]
2545
2558
 
2546
 
        last1 = branch1.last_revision()
2547
 
        last2 = branch2.last_revision()
 
2559
        last1 = ensure_null(branch1.last_revision())
 
2560
        last2 = ensure_null(branch2.last_revision())
2548
2561
 
2549
 
        source = MultipleRevisionSources(branch1.repository, 
2550
 
                                         branch2.repository)
2551
 
        
2552
 
        base_rev_id = common_ancestor(last1, last2, source)
 
2562
        graph = branch1.repository.get_graph(branch2.repository)
 
2563
        base_rev_id = graph.find_unique_lca(last1, last2)
2553
2564
 
2554
2565
        print 'merge base is revision %s' % base_rev_id
2555
2566
 
2793
2804
                                             " merges.  Not cherrypicking or"
2794
2805
                                             " multi-merges.")
2795
2806
            repository = tree.branch.repository
2796
 
            base_revision = common_ancestor(parents[0],
2797
 
                                            parents[1], repository)
 
2807
            graph = repository.get_graph()
 
2808
            base_revision = graph.find_unique_lca(parents[0], parents[1])
2798
2809
            base_tree = repository.revision_tree(base_revision)
2799
2810
            other_tree = repository.revision_tree(parents[1])
2800
2811
            interesting_ids = None
2951
2962
 
2952
2963
class cmd_missing(Command):
2953
2964
    """Show unmerged/unpulled revisions between two branches.
2954
 
 
 
2965
    
2955
2966
    OTHER_BRANCH may be local or remote.
2956
2967
    """
2957
2968
 
2960
2971
    takes_options = [Option('reverse', 'Reverse the order of revisions'),
2961
2972
                     Option('mine-only', 
2962
2973
                            'Display changes in the local branch only'),
 
2974
                     Option('this' , 'same as --mine-only'),
2963
2975
                     Option('theirs-only', 
2964
 
                            'Display changes in the remote branch only'), 
 
2976
                            'Display changes in the remote branch only'),
 
2977
                     Option('other', 'same as --theirs-only'),
2965
2978
                     'log-format',
2966
2979
                     'show-ids',
2967
2980
                     'verbose'
2971
2984
    @display_command
2972
2985
    def run(self, other_branch=None, reverse=False, mine_only=False,
2973
2986
            theirs_only=False, log_format=None, long=False, short=False, line=False, 
2974
 
            show_ids=False, verbose=False):
2975
 
        from bzrlib.missing import find_unmerged, iter_log_data
 
2987
            show_ids=False, verbose=False, this=False, other=False):
 
2988
        from bzrlib.missing import find_unmerged, iter_log_revisions
2976
2989
        from bzrlib.log import log_formatter
 
2990
 
 
2991
        if this:
 
2992
          mine_only = this
 
2993
        if other:
 
2994
          theirs_only = other
 
2995
 
2977
2996
        local_branch = Branch.open_containing(u".")[0]
2978
2997
        parent = local_branch.get_parent()
2979
2998
        if other_branch is None:
3003
3022
                    remote_extra.reverse()
3004
3023
                if local_extra and not theirs_only:
3005
3024
                    print "You have %d extra revision(s):" % len(local_extra)
3006
 
                    for data in iter_log_data(local_extra, local_branch.repository,
3007
 
                                              verbose):
3008
 
                        lf.show(*data)
 
3025
                    for revision in iter_log_revisions(local_extra, 
 
3026
                                        local_branch.repository,
 
3027
                                        verbose):
 
3028
                        lf.log_revision(revision)
3009
3029
                    printed_local = True
3010
3030
                else:
3011
3031
                    printed_local = False
3013
3033
                    if printed_local is True:
3014
3034
                        print "\n\n"
3015
3035
                    print "You are missing %d revision(s):" % len(remote_extra)
3016
 
                    for data in iter_log_data(remote_extra, remote_branch.repository, 
3017
 
                                              verbose):
3018
 
                        lf.show(*data)
 
3036
                    for revision in iter_log_revisions(remote_extra, 
 
3037
                                        remote_branch.repository, 
 
3038
                                        verbose):
 
3039
                        lf.log_revision(revision)
3019
3040
                if not remote_extra and not local_extra:
3020
3041
                    status_code = 0
3021
3042
                    print "Branches are up to date."
3515
3536
            help='Message to use when committing this merge')
3516
3537
        ]
3517
3538
 
 
3539
    encoding_type = 'exact'
 
3540
 
3518
3541
    def run(self, submit_branch=None, public_branch=None, patch_type='bundle',
3519
3542
            sign=False, revision=None, mail_to=None, message=None):
 
3543
        from bzrlib.revision import ensure_null, NULL_REVISION
3520
3544
        if patch_type == 'plain':
3521
3545
            patch_type = None
3522
3546
        branch = Branch.open('.')
3547
3571
                revision_id = revision[0].in_history(branch).rev_id
3548
3572
        else:
3549
3573
            revision_id = branch.last_revision()
 
3574
        revision_id = ensure_null(revision_id)
 
3575
        if revision_id == NULL_REVISION:
 
3576
            raise errors.BzrCommandError('No revisions to bundle.')
3550
3577
        directive = merge_directive.MergeDirective.from_objects(
3551
3578
            branch.repository, revision_id, time.time(),
3552
3579
            osutils.local_time_offset(), submit_branch,
3559
3586
                self.outf.writelines(directive.to_lines())
3560
3587
        else:
3561
3588
            message = directive.to_email(mail_to, branch, sign)
3562
 
            s = smtplib.SMTP()
3563
 
            server = branch.get_config().get_user_option('smtp_server')
3564
 
            if not server:
3565
 
                server = 'localhost'
3566
 
            s.connect(server)
3567
 
            s.sendmail(message['From'], message['To'], message.as_string())
 
3589
            s = SMTPConnection(branch.get_config())
 
3590
            s.send_email(message)
3568
3591
 
3569
3592
 
3570
3593
class cmd_tag(Command):
3748
3771
    return conflicts
3749
3772
 
3750
3773
 
 
3774
def _create_prefix(cur_transport):
 
3775
    needed = [cur_transport]
 
3776
    # Recurse upwards until we can create a directory successfully
 
3777
    while True:
 
3778
        new_transport = cur_transport.clone('..')
 
3779
        if new_transport.base == cur_transport.base:
 
3780
            raise errors.BzrCommandError("Failed to create path"
 
3781
                                         " prefix for %s."
 
3782
                                         % location)
 
3783
        try:
 
3784
            new_transport.mkdir('.')
 
3785
        except errors.NoSuchFile:
 
3786
            needed.append(new_transport)
 
3787
            cur_transport = new_transport
 
3788
        else:
 
3789
            break
 
3790
 
 
3791
    # Now we only need to create child directories
 
3792
    while needed:
 
3793
        cur_transport = needed.pop()
 
3794
        cur_transport.ensure_base()
 
3795
 
3751
3796
# Compatibility
3752
3797
merge = _merge_helper
3753
3798
 
3761
3806
from bzrlib.conflicts import cmd_resolve, cmd_conflicts, restore
3762
3807
from bzrlib.bundle.commands import cmd_bundle_revisions
3763
3808
from bzrlib.sign_my_commits import cmd_sign_my_commits
3764
 
from bzrlib.weave_commands import cmd_weave_list, cmd_weave_join, \
 
3809
from bzrlib.weave_commands import cmd_versionedfile_list, cmd_weave_join, \
3765
3810
        cmd_weave_plan_merge, cmd_weave_merge_text