/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

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
552
552
    def run(self, location=None, remember=False, overwrite=False,
553
553
            revision=None, verbose=False,
554
554
            directory=None):
 
555
        from bzrlib.tag import _merge_tags_if_possible
555
556
        # FIXME: too much stuff is in the command class
556
557
        if directory is None:
557
558
            directory = u'.'
600
601
 
601
602
        old_rh = branch_to.revision_history()
602
603
        if tree_to is not None:
603
 
            count = tree_to.pull(branch_from, overwrite, rev_id,
 
604
            result = tree_to.pull(branch_from, overwrite, rev_id,
604
605
                delta.ChangeReporter(tree_to.inventory))
605
606
        else:
606
 
            count = branch_to.pull(branch_from, overwrite, rev_id)
607
 
        note('%d revision(s) pulled.' % (count,))
 
607
            result = branch_to.pull(branch_from, overwrite, rev_id)
608
608
 
 
609
        result.report(self.outf)
609
610
        if verbose:
 
611
            from bzrlib.log import show_changed_revisions
610
612
            new_rh = branch_to.revision_history()
611
 
            if old_rh != new_rh:
612
 
                # Something changed
613
 
                from bzrlib.log import show_changed_revisions
614
 
                show_changed_revisions(branch_to, old_rh, new_rh,
615
 
                                       to_file=self.outf)
 
613
            show_changed_revisions(branch_to, old_rh, new_rh, to_file=self.outf)
616
614
 
617
615
 
618
616
class cmd_push(Command):
682
680
        to_transport = transport.get_transport(location)
683
681
        location_url = to_transport.base
684
682
 
685
 
        old_rh = []
686
 
        count = 0
687
 
 
688
683
        br_to = repository_to = dir_to = None
689
684
        try:
690
685
            dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
704
699
            else:
705
700
                # Found a branch, so we must have found a repository
706
701
                repository_to = br_to.repository
707
 
 
 
702
        push_result = None
708
703
        old_rh = []
709
704
        if dir_to is None:
 
705
            # The destination doesn't exist; create it.
710
706
            # XXX: Refactor the create_prefix/no_create_prefix code into a
711
707
            #      common helper function
712
708
            try:
753
749
            dir_to = br_from.bzrdir.clone(location_url,
754
750
                revision_id=br_from.last_revision())
755
751
            br_to = dir_to.open_branch()
756
 
            count = br_to.last_revision_info()[0]
 
752
            # TODO: Some more useful message about what was copied
 
753
            note('Created new branch.')
757
754
            # We successfully created the target, remember it
758
755
            if br_from.get_push_location() is None or remember:
759
756
                br_from.set_push_location(br_to.base)
772
769
            repository_to.fetch(br_from.repository,
773
770
                                revision_id=last_revision_id)
774
771
            br_to = br_from.clone(dir_to, revision_id=last_revision_id)
775
 
            count = len(br_to.revision_history())
 
772
            note('Created new branch.')
776
773
            if br_from.get_push_location() is None or remember:
777
774
                br_from.set_push_location(br_to.base)
778
775
        else: # We have a valid to branch
787
784
                except errors.NotLocalUrl:
788
785
                    warning('This transport does not update the working '
789
786
                            'tree of: %s' % (br_to.base,))
790
 
                    count = br_from.push(br_to, overwrite)
 
787
                    push_result = br_from.push(br_to, overwrite)
791
788
                except errors.NoWorkingTree:
792
 
                    count = br_from.push(br_to, overwrite)
 
789
                    push_result = br_from.push(br_to, overwrite)
793
790
                else:
794
791
                    tree_to.lock_write()
795
792
                    try:
796
 
                        count = br_from.push(tree_to.branch, overwrite)
 
793
                        push_result = br_from.push(tree_to.branch, overwrite)
797
794
                        tree_to.update()
798
795
                    finally:
799
796
                        tree_to.unlock()
800
797
            except errors.DivergedBranches:
801
798
                raise errors.BzrCommandError('These branches have diverged.'
802
799
                                        '  Try using "merge" and then "push".')
803
 
        note('%d revision(s) pushed.' % (count,))
804
 
 
805
 
        if verbose:
 
800
        if push_result is not None:
 
801
            push_result.report(self.outf)
 
802
        elif verbose:
806
803
            new_rh = br_to.revision_history()
807
804
            if old_rh != new_rh:
808
805
                # Something changed
809
806
                from bzrlib.log import show_changed_revisions
810
807
                show_changed_revisions(br_to, old_rh, new_rh,
811
808
                                       to_file=self.outf)
 
809
        else:
 
810
            # we probably did a clone rather than a push, so a message was
 
811
            # emitted above
 
812
            pass
812
813
 
813
814
 
814
815
class cmd_branch(Command):
829
830
    aliases = ['get', 'clone']
830
831
 
831
832
    def run(self, from_location, to_location=None, revision=None, basis=None):
 
833
        from bzrlib.tag import _merge_tags_if_possible
832
834
        if revision is None:
833
835
            revision = [None]
834
836
        elif len(revision) > 1:
879
881
                raise errors.BzrCommandError(msg)
880
882
            if name:
881
883
                branch.control_files.put_utf8('branch-name', name)
 
884
            _merge_tags_if_possible(br_from, branch)
882
885
            note('Branched %d revision(s).' % branch.revno())
883
886
        finally:
884
887
            br_from.unlock()
1236
1239
            existing_bzrdir = bzrdir.BzrDir.open(location)
1237
1240
        except errors.NotBranchError:
1238
1241
            # really a NotBzrDir error...
1239
 
            branch = bzrdir.BzrDir.create_branch_convenience(location,
 
1242
            branch = bzrdir.BzrDir.create_branch_convenience(to_transport.base,
1240
1243
                                                             format=format)
1241
1244
        else:
1242
1245
            from bzrlib.transport.local import LocalTransport
1928
1931
 
1929
1932
        tree = None
1930
1933
        try:
1931
 
            tree, relpath = WorkingTree.open_containing(filename)
1932
 
            b = tree.branch
1933
 
        except (errors.NotBranchError, errors.NotLocalUrl):
 
1934
            tree, b, relpath = \
 
1935
                    bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
1936
        except errors.NotBranchError:
1934
1937
            pass
1935
1938
 
1936
1939
        if revision is not None and revision[0].get_branch() is not None:
1937
1940
            b = Branch.open(revision[0].get_branch())
1938
1941
        if tree is None:
1939
 
            b, relpath = Branch.open_containing(filename)
1940
1942
            tree = b.basis_tree()
1941
1943
        if revision is None:
1942
1944
            revision_id = b.last_revision()
2335
2337
 
2336
2338
    @display_command
2337
2339
    def run(self):
2338
 
        print "it sure does!"
 
2340
        print "It sure does!"
2339
2341
 
2340
2342
 
2341
2343
class cmd_find_merge_base(Command):
2419
2421
                ' source rather than merging. When this happens,'
2420
2422
                ' you do not need to commit the result.'),
2421
2423
        Option('directory',
2422
 
            help='branch to merge into, '
 
2424
            help='Branch to merge into, '
2423
2425
                 'rather than the one containing the working directory',
2424
2426
            short_name='d',
2425
2427
            type=unicode,
2431
2433
            uncommitted=False, pull=False,
2432
2434
            directory=None,
2433
2435
            ):
 
2436
        from bzrlib.tag import _merge_tags_if_possible
2434
2437
        if merge_type is None:
2435
2438
            merge_type = _mod_merge.Merge3Merger
2436
2439
 
2491
2494
        if tree.branch.get_parent() is None or remember:
2492
2495
            tree.branch.set_parent(other_branch.base)
2493
2496
 
 
2497
        # pull tags now... it's a bit inconsistent to do it ahead of copying
 
2498
        # the history but that's done inside the merge code
 
2499
        _merge_tags_if_possible(other_branch, tree.branch)
 
2500
 
2494
2501
        if path != "":
2495
2502
            interesting_files = [path]
2496
2503
        else:
3131
3138
        Option('port',
3132
3139
               help='listen for connections on nominated port of the form '
3133
3140
                    '[hostname:]portnumber. Passing 0 as the port number will '
3134
 
                    'result in a dynamically allocated port.',
 
3141
                    'result in a dynamically allocated port. Default port is '
 
3142
                    '4155.',
3135
3143
               type=str),
3136
3144
        Option('directory',
3137
3145
               help='serve contents of directory',
3154
3162
        t = get_transport(url)
3155
3163
        if inet:
3156
3164
            server = smart.SmartServerPipeStreamMedium(sys.stdin, sys.stdout, t)
3157
 
        elif port is not None:
3158
 
            if ':' in port:
3159
 
                host, port = port.split(':')
3160
 
            else:
 
3165
        else:
 
3166
            if port is None:
 
3167
                port = smart.BZR_DEFAULT_PORT
3161
3168
                host = '127.0.0.1'
3162
 
            server = smart.SmartTCPServer(t, host=host, port=int(port))
 
3169
            else:
 
3170
                if ':' in port:
 
3171
                    host, port = port.split(':')
 
3172
                else:
 
3173
                    host = '127.0.0.1'
 
3174
                port = int(port)
 
3175
            server = smart.SmartTCPServer(t, host=host, port=port)
3163
3176
            print 'listening on port: ', server.port
3164
3177
            sys.stdout.flush()
3165
 
        else:
3166
 
            raise errors.BzrCommandError("bzr serve requires one of --inet or --port")
3167
3178
        server.serve()
3168
3179
 
3169
3180
 
3229
3240
            self.outf.writelines(directive.to_lines())
3230
3241
 
3231
3242
 
 
3243
class cmd_tag(Command):
 
3244
    """Create a tag naming a revision.
 
3245
    
 
3246
    Tags give human-meaningful names to revisions.  Commands that take a -r
 
3247
    (--revision) option can be given -rtag:X, where X is any previously
 
3248
    created tag.
 
3249
 
 
3250
    Tags are stored in the branch.  Tags are copied from one branch to another
 
3251
    along when you branch, push, pull or merge.
 
3252
 
 
3253
    It is an error to give a tag name that already exists unless you pass 
 
3254
    --force, in which case the tag is moved to point to the new revision.
 
3255
    """
 
3256
 
 
3257
    takes_args = ['tag_name']
 
3258
    takes_options = [
 
3259
        Option('delete',
 
3260
            help='Delete this tag rather than placing it.',
 
3261
            ),
 
3262
        Option('directory',
 
3263
            help='Branch in which to place the tag.',
 
3264
            short_name='d',
 
3265
            type=unicode,
 
3266
            ),
 
3267
        Option('force',
 
3268
            help='Replace existing tags',
 
3269
            ),
 
3270
        'revision',
 
3271
        ]
 
3272
 
 
3273
    def run(self, tag_name,
 
3274
            delete=None,
 
3275
            directory='.',
 
3276
            force=None,
 
3277
            revision=None,
 
3278
            ):
 
3279
        branch, relpath = Branch.open_containing(directory)
 
3280
        branch.lock_write()
 
3281
        try:
 
3282
            if delete:
 
3283
                branch.tags.delete_tag(tag_name)
 
3284
                self.outf.write('Deleted tag %s.\n' % tag_name)
 
3285
            else:
 
3286
                if revision:
 
3287
                    if len(revision) != 1:
 
3288
                        raise errors.BzrCommandError(
 
3289
                            "Tags can only be placed on a single revision, "
 
3290
                            "not on a range")
 
3291
                    revision_id = revision[0].in_history(branch).rev_id
 
3292
                else:
 
3293
                    revision_id = branch.last_revision()
 
3294
                if (not force) and branch.tags.has_tag(tag_name):
 
3295
                    raise errors.TagAlreadyExists(tag_name)
 
3296
                branch.tags.set_tag(tag_name, revision_id)
 
3297
                self.outf.write('Created tag %s.\n' % tag_name)
 
3298
        finally:
 
3299
            branch.unlock()
 
3300
 
 
3301
 
 
3302
class cmd_tags(Command):
 
3303
    """List tags.
 
3304
 
 
3305
    This tag shows a table of tag names and the revisions they reference.
 
3306
    """
 
3307
 
 
3308
    takes_options = [
 
3309
        Option('directory',
 
3310
            help='Branch whose tags should be displayed',
 
3311
            short_name='d',
 
3312
            type=unicode,
 
3313
            ),
 
3314
    ]
 
3315
 
 
3316
    @display_command
 
3317
    def run(self,
 
3318
            directory='.',
 
3319
            ):
 
3320
        branch, relpath = Branch.open_containing(directory)
 
3321
        for tag_name, target in sorted(branch.tags.get_tag_dict().items()):
 
3322
            self.outf.write('%-20s %s\n' % (tag_name, target))
 
3323
 
 
3324
 
3232
3325
# command-line interpretation helper for merge-related commands
3233
3326
def _merge_helper(other_revision, base_revision,
3234
3327
                  check_clean=True, ignore_zero=False,
3293
3386
            return 0
3294
3387
        if file_list is None:
3295
3388
            if pull and merger.base_rev_id == merger.this_rev_id:
3296
 
                count = merger.this_tree.pull(merger.this_branch,
 
3389
                # FIXME: deduplicate with pull
 
3390
                result = merger.this_tree.pull(merger.this_branch,
3297
3391
                        False, merger.other_rev_id)
3298
 
                note('%d revision(s) pulled.' % (count,))
 
3392
                if result.old_revid == result.new_revid:
 
3393
                    note('No revisions to pull.')
 
3394
                else:
 
3395
                    note('Now on revision %d.' % result.new_revno)
3299
3396
                return 0
3300
3397
        merger.backup_files = backup_files
3301
3398
        merger.merge_type = merge_type