~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Robert Collins
  • Date: 2007-03-05 03:43:56 UTC
  • mfrom: (2312 +trunk)
  • mto: (2255.11.6 dirstate)
  • mto: This revision was merged to the branch mainline in revision 2322.
  • Revision ID: robertc@robertcollins.net-20070305034356-og43j35eg62m952f
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
559
559
    def run(self, location=None, remember=False, overwrite=False,
560
560
            revision=None, verbose=False,
561
561
            directory=None):
 
562
        from bzrlib.tag import _merge_tags_if_possible
562
563
        # FIXME: too much stuff is in the command class
563
564
        if directory is None:
564
565
            directory = u'.'
607
608
 
608
609
        old_rh = branch_to.revision_history()
609
610
        if tree_to is not None:
610
 
            count = tree_to.pull(branch_from, overwrite, rev_id,
611
 
                delta.ChangeReporter())
 
611
            result = tree_to.pull(branch_from, overwrite, rev_id,
 
612
                delta.ChangeReporter(unversioned_filter=tree_to.is_ignored))
612
613
        else:
613
 
            count = branch_to.pull(branch_from, overwrite, rev_id)
614
 
        note('%d revision(s) pulled.' % (count,))
 
614
            result = branch_to.pull(branch_from, overwrite, rev_id)
615
615
 
 
616
        result.report(self.outf)
616
617
        if verbose:
 
618
            from bzrlib.log import show_changed_revisions
617
619
            new_rh = branch_to.revision_history()
618
 
            if old_rh != new_rh:
619
 
                # Something changed
620
 
                from bzrlib.log import show_changed_revisions
621
 
                show_changed_revisions(branch_to, old_rh, new_rh,
622
 
                                       to_file=self.outf)
 
620
            show_changed_revisions(branch_to, old_rh, new_rh, to_file=self.outf)
623
621
 
624
622
 
625
623
class cmd_push(Command):
689
687
        to_transport = transport.get_transport(location)
690
688
        location_url = to_transport.base
691
689
 
692
 
        old_rh = []
693
 
        count = 0
694
 
 
695
690
        br_to = repository_to = dir_to = None
696
691
        try:
697
692
            dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
711
706
            else:
712
707
                # Found a branch, so we must have found a repository
713
708
                repository_to = br_to.repository
714
 
 
 
709
        push_result = None
715
710
        old_rh = []
716
711
        if dir_to is None:
 
712
            # The destination doesn't exist; create it.
717
713
            # XXX: Refactor the create_prefix/no_create_prefix code into a
718
714
            #      common helper function
719
715
            try:
760
756
            dir_to = br_from.bzrdir.clone(location_url,
761
757
                revision_id=br_from.last_revision())
762
758
            br_to = dir_to.open_branch()
763
 
            count = br_to.last_revision_info()[0]
 
759
            # TODO: Some more useful message about what was copied
 
760
            note('Created new branch.')
764
761
            # We successfully created the target, remember it
765
762
            if br_from.get_push_location() is None or remember:
766
763
                br_from.set_push_location(br_to.base)
779
776
            repository_to.fetch(br_from.repository,
780
777
                                revision_id=last_revision_id)
781
778
            br_to = br_from.clone(dir_to, revision_id=last_revision_id)
782
 
            count = len(br_to.revision_history())
 
779
            note('Created new branch.')
783
780
            if br_from.get_push_location() is None or remember:
784
781
                br_from.set_push_location(br_to.base)
785
782
        else: # We have a valid to branch
794
791
                except errors.NotLocalUrl:
795
792
                    warning('This transport does not update the working '
796
793
                            'tree of: %s' % (br_to.base,))
797
 
                    count = br_from.push(br_to, overwrite)
 
794
                    push_result = br_from.push(br_to, overwrite)
798
795
                except errors.NoWorkingTree:
799
 
                    count = br_from.push(br_to, overwrite)
 
796
                    push_result = br_from.push(br_to, overwrite)
800
797
                else:
801
798
                    tree_to.lock_write()
802
799
                    try:
803
 
                        count = br_from.push(tree_to.branch, overwrite)
 
800
                        push_result = br_from.push(tree_to.branch, overwrite)
804
801
                        tree_to.update()
805
802
                    finally:
806
803
                        tree_to.unlock()
807
804
            except errors.DivergedBranches:
808
805
                raise errors.BzrCommandError('These branches have diverged.'
809
806
                                        '  Try using "merge" and then "push".')
810
 
        note('%d revision(s) pushed.' % (count,))
811
 
 
812
 
        if verbose:
 
807
        if push_result is not None:
 
808
            push_result.report(self.outf)
 
809
        elif verbose:
813
810
            new_rh = br_to.revision_history()
814
811
            if old_rh != new_rh:
815
812
                # Something changed
816
813
                from bzrlib.log import show_changed_revisions
817
814
                show_changed_revisions(br_to, old_rh, new_rh,
818
815
                                       to_file=self.outf)
 
816
        else:
 
817
            # we probably did a clone rather than a push, so a message was
 
818
            # emitted above
 
819
            pass
819
820
 
820
821
 
821
822
class cmd_branch(Command):
836
837
    aliases = ['get', 'clone']
837
838
 
838
839
    def run(self, from_location, to_location=None, revision=None, basis=None):
 
840
        from bzrlib.tag import _merge_tags_if_possible
839
841
        if revision is None:
840
842
            revision = [None]
841
843
        elif len(revision) > 1:
886
888
                raise errors.BzrCommandError(msg)
887
889
            if name:
888
890
                branch.control_files.put_utf8('branch-name', name)
 
891
            _merge_tags_if_possible(br_from, branch)
889
892
            note('Branched %d revision(s).' % branch.revno())
890
893
        finally:
891
894
            br_from.unlock()
1253
1256
            existing_bzrdir = bzrdir.BzrDir.open(location)
1254
1257
        except errors.NotBranchError:
1255
1258
            # really a NotBzrDir error...
1256
 
            branch = bzrdir.BzrDir.create_branch_convenience(location,
 
1259
            branch = bzrdir.BzrDir.create_branch_convenience(to_transport.base,
1257
1260
                                                             format=format)
1258
1261
        else:
1259
1262
            from bzrlib.transport.local import LocalTransport
1964
1967
 
1965
1968
        tree = None
1966
1969
        try:
1967
 
            tree, relpath = WorkingTree.open_containing(filename)
1968
 
            b = tree.branch
1969
 
        except (errors.NotBranchError, errors.NotLocalUrl):
 
1970
            tree, b, relpath = \
 
1971
                    bzrdir.BzrDir.open_containing_tree_or_branch(filename)
 
1972
        except errors.NotBranchError:
1970
1973
            pass
1971
1974
 
1972
1975
        if revision is not None and revision[0].get_branch() is not None:
1973
1976
            b = Branch.open(revision[0].get_branch())
1974
1977
        if tree is None:
1975
 
            b, relpath = Branch.open_containing(filename)
1976
1978
            tree = b.basis_tree()
1977
1979
        if revision is None:
1978
1980
            revision_id = b.last_revision()
2371
2373
 
2372
2374
    @display_command
2373
2375
    def run(self):
2374
 
        print "it sure does!"
 
2376
        print "It sure does!"
2375
2377
 
2376
2378
 
2377
2379
class cmd_find_merge_base(Command):
2455
2457
                ' source rather than merging. When this happens,'
2456
2458
                ' you do not need to commit the result.'),
2457
2459
        Option('directory',
2458
 
            help='branch to merge into, '
 
2460
            help='Branch to merge into, '
2459
2461
                 'rather than the one containing the working directory',
2460
2462
            short_name='d',
2461
2463
            type=unicode,
2467
2469
            uncommitted=False, pull=False,
2468
2470
            directory=None,
2469
2471
            ):
 
2472
        from bzrlib.tag import _merge_tags_if_possible
2470
2473
        if merge_type is None:
2471
2474
            merge_type = _mod_merge.Merge3Merger
2472
2475
 
2479
2482
        #      Either the merge helper code should be updated to take a tree,
2480
2483
        #      (What about tree.merge_from_branch?)
2481
2484
        tree = WorkingTree.open_containing(directory)[0]
2482
 
        change_reporter = delta.ChangeReporter()
 
2485
        change_reporter = delta.ChangeReporter(
 
2486
            unversioned_filter=tree.is_ignored)
2483
2487
 
2484
2488
        if branch is not None:
2485
2489
            try:
2534
2538
        if tree.branch.get_parent() is None or remember:
2535
2539
            tree.branch.set_parent(other_branch.base)
2536
2540
 
 
2541
        # pull tags now... it's a bit inconsistent to do it ahead of copying
 
2542
        # the history but that's done inside the merge code
 
2543
        _merge_tags_if_possible(other_branch, tree.branch)
 
2544
 
2537
2545
        if path != "":
2538
2546
            interesting_files = [path]
2539
2547
        else:
3174
3182
        Option('port',
3175
3183
               help='listen for connections on nominated port of the form '
3176
3184
                    '[hostname:]portnumber. Passing 0 as the port number will '
3177
 
                    'result in a dynamically allocated port.',
 
3185
                    'result in a dynamically allocated port. Default port is '
 
3186
                    '4155.',
3178
3187
               type=str),
3179
3188
        Option('directory',
3180
3189
               help='serve contents of directory',
3197
3206
        t = get_transport(url)
3198
3207
        if inet:
3199
3208
            server = smart.SmartServerPipeStreamMedium(sys.stdin, sys.stdout, t)
3200
 
        elif port is not None:
3201
 
            if ':' in port:
3202
 
                host, port = port.split(':')
3203
 
            else:
 
3209
        else:
 
3210
            if port is None:
 
3211
                port = smart.BZR_DEFAULT_PORT
3204
3212
                host = '127.0.0.1'
3205
 
            server = smart.SmartTCPServer(t, host=host, port=int(port))
 
3213
            else:
 
3214
                if ':' in port:
 
3215
                    host, port = port.split(':')
 
3216
                else:
 
3217
                    host = '127.0.0.1'
 
3218
                port = int(port)
 
3219
            server = smart.SmartTCPServer(t, host=host, port=port)
3206
3220
            print 'listening on port: ', server.port
3207
3221
            sys.stdout.flush()
3208
 
        else:
3209
 
            raise errors.BzrCommandError("bzr serve requires one of --inet or --port")
3210
3222
        server.serve()
3211
3223
 
3212
3224
 
 
3225
class cmd_tag(Command):
 
3226
    """Create a tag naming a revision.
 
3227
    
 
3228
    Tags give human-meaningful names to revisions.  Commands that take a -r
 
3229
    (--revision) option can be given -rtag:X, where X is any previously
 
3230
    created tag.
 
3231
 
 
3232
    Tags are stored in the branch.  Tags are copied from one branch to another
 
3233
    along when you branch, push, pull or merge.
 
3234
 
 
3235
    It is an error to give a tag name that already exists unless you pass 
 
3236
    --force, in which case the tag is moved to point to the new revision.
 
3237
    """
 
3238
 
 
3239
    takes_args = ['tag_name']
 
3240
    takes_options = [
 
3241
        Option('delete',
 
3242
            help='Delete this tag rather than placing it.',
 
3243
            ),
 
3244
        Option('directory',
 
3245
            help='Branch in which to place the tag.',
 
3246
            short_name='d',
 
3247
            type=unicode,
 
3248
            ),
 
3249
        Option('force',
 
3250
            help='Replace existing tags',
 
3251
            ),
 
3252
        'revision',
 
3253
        ]
 
3254
 
 
3255
    def run(self, tag_name,
 
3256
            delete=None,
 
3257
            directory='.',
 
3258
            force=None,
 
3259
            revision=None,
 
3260
            ):
 
3261
        branch, relpath = Branch.open_containing(directory)
 
3262
        branch.lock_write()
 
3263
        try:
 
3264
            if delete:
 
3265
                branch.tags.delete_tag(tag_name)
 
3266
                self.outf.write('Deleted tag %s.\n' % tag_name)
 
3267
            else:
 
3268
                if revision:
 
3269
                    if len(revision) != 1:
 
3270
                        raise errors.BzrCommandError(
 
3271
                            "Tags can only be placed on a single revision, "
 
3272
                            "not on a range")
 
3273
                    revision_id = revision[0].in_history(branch).rev_id
 
3274
                else:
 
3275
                    revision_id = branch.last_revision()
 
3276
                if (not force) and branch.tags.has_tag(tag_name):
 
3277
                    raise errors.TagAlreadyExists(tag_name)
 
3278
                branch.tags.set_tag(tag_name, revision_id)
 
3279
                self.outf.write('Created tag %s.\n' % tag_name)
 
3280
        finally:
 
3281
            branch.unlock()
 
3282
 
 
3283
 
 
3284
class cmd_tags(Command):
 
3285
    """List tags.
 
3286
 
 
3287
    This tag shows a table of tag names and the revisions they reference.
 
3288
    """
 
3289
 
 
3290
    takes_options = [
 
3291
        Option('directory',
 
3292
            help='Branch whose tags should be displayed',
 
3293
            short_name='d',
 
3294
            type=unicode,
 
3295
            ),
 
3296
    ]
 
3297
 
 
3298
    @display_command
 
3299
    def run(self,
 
3300
            directory='.',
 
3301
            ):
 
3302
        branch, relpath = Branch.open_containing(directory)
 
3303
        for tag_name, target in sorted(branch.tags.get_tag_dict().items()):
 
3304
            self.outf.write('%-20s %s\n' % (tag_name, target))
 
3305
 
 
3306
 
3213
3307
# command-line interpretation helper for merge-related commands
3214
3308
def _merge_helper(other_revision, base_revision,
3215
3309
                  check_clean=True, ignore_zero=False,
3282
3376
            return 0
3283
3377
        if file_list is None:
3284
3378
            if pull and merger.base_rev_id == merger.this_rev_id:
3285
 
                count = merger.this_tree.pull(merger.this_branch,
 
3379
                # FIXME: deduplicate with pull
 
3380
                result = merger.this_tree.pull(merger.this_branch,
3286
3381
                        False, merger.other_rev_id)
3287
 
                note('%d revision(s) pulled.' % (count,))
 
3382
                if result.old_revid == result.new_revid:
 
3383
                    note('No revisions to pull.')
 
3384
                else:
 
3385
                    note('Now on revision %d.' % result.new_revno)
3288
3386
                return 0
3289
3387
        merger.backup_files = backup_files
3290
3388
        merger.merge_type = merge_type