~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-03-01 07:30:00 UTC
  • mfrom: (2220.2.49 tags)
  • Revision ID: pqm@pqm.ubuntu.com-20070301073000-0bfe1394fee5e712
(mbp) tags in branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
549
549
    def run(self, location=None, remember=False, overwrite=False,
550
550
            revision=None, verbose=False,
551
551
            directory=None):
 
552
        from bzrlib.tag import _merge_tags_if_possible
552
553
        # FIXME: too much stuff is in the command class
553
554
        if directory is None:
554
555
            directory = u'.'
597
598
 
598
599
        old_rh = branch_to.revision_history()
599
600
        if tree_to is not None:
600
 
            count = tree_to.pull(branch_from, overwrite, rev_id,
 
601
            result = tree_to.pull(branch_from, overwrite, rev_id,
601
602
                delta.ChangeReporter(tree_to.inventory))
602
603
        else:
603
 
            count = branch_to.pull(branch_from, overwrite, rev_id)
604
 
        note('%d revision(s) pulled.' % (count,))
 
604
            result = branch_to.pull(branch_from, overwrite, rev_id)
605
605
 
 
606
        result.report(self.outf)
606
607
        if verbose:
 
608
            from bzrlib.log import show_changed_revisions
607
609
            new_rh = branch_to.revision_history()
608
 
            if old_rh != new_rh:
609
 
                # Something changed
610
 
                from bzrlib.log import show_changed_revisions
611
 
                show_changed_revisions(branch_to, old_rh, new_rh,
612
 
                                       to_file=self.outf)
 
610
            show_changed_revisions(branch_to, old_rh, new_rh, to_file=self.outf)
613
611
 
614
612
 
615
613
class cmd_push(Command):
679
677
        to_transport = transport.get_transport(location)
680
678
        location_url = to_transport.base
681
679
 
682
 
        old_rh = []
683
 
        count = 0
684
 
 
685
680
        br_to = repository_to = dir_to = None
686
681
        try:
687
682
            dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
701
696
            else:
702
697
                # Found a branch, so we must have found a repository
703
698
                repository_to = br_to.repository
704
 
 
 
699
        push_result = None
705
700
        old_rh = []
706
701
        if dir_to is None:
 
702
            # The destination doesn't exist; create it.
707
703
            # XXX: Refactor the create_prefix/no_create_prefix code into a
708
704
            #      common helper function
709
705
            try:
750
746
            dir_to = br_from.bzrdir.clone(location_url,
751
747
                revision_id=br_from.last_revision())
752
748
            br_to = dir_to.open_branch()
753
 
            count = br_to.last_revision_info()[0]
 
749
            # TODO: Some more useful message about what was copied
 
750
            note('Created new branch.')
754
751
            # We successfully created the target, remember it
755
752
            if br_from.get_push_location() is None or remember:
756
753
                br_from.set_push_location(br_to.base)
769
766
            repository_to.fetch(br_from.repository,
770
767
                                revision_id=last_revision_id)
771
768
            br_to = br_from.clone(dir_to, revision_id=last_revision_id)
772
 
            count = len(br_to.revision_history())
 
769
            note('Created new branch.')
773
770
            if br_from.get_push_location() is None or remember:
774
771
                br_from.set_push_location(br_to.base)
775
772
        else: # We have a valid to branch
784
781
                except errors.NotLocalUrl:
785
782
                    warning('This transport does not update the working '
786
783
                            'tree of: %s' % (br_to.base,))
787
 
                    count = br_from.push(br_to, overwrite)
 
784
                    push_result = br_from.push(br_to, overwrite)
788
785
                except errors.NoWorkingTree:
789
 
                    count = br_from.push(br_to, overwrite)
 
786
                    push_result = br_from.push(br_to, overwrite)
790
787
                else:
791
788
                    tree_to.lock_write()
792
789
                    try:
793
 
                        count = br_from.push(tree_to.branch, overwrite)
 
790
                        push_result = br_from.push(tree_to.branch, overwrite)
794
791
                        tree_to.update()
795
792
                    finally:
796
793
                        tree_to.unlock()
797
794
            except errors.DivergedBranches:
798
795
                raise errors.BzrCommandError('These branches have diverged.'
799
796
                                        '  Try using "merge" and then "push".')
800
 
        note('%d revision(s) pushed.' % (count,))
801
 
 
802
 
        if verbose:
 
797
        if push_result is not None:
 
798
            push_result.report(self.outf)
 
799
        elif verbose:
803
800
            new_rh = br_to.revision_history()
804
801
            if old_rh != new_rh:
805
802
                # Something changed
806
803
                from bzrlib.log import show_changed_revisions
807
804
                show_changed_revisions(br_to, old_rh, new_rh,
808
805
                                       to_file=self.outf)
 
806
        else:
 
807
            # we probably did a clone rather than a push, so a message was
 
808
            # emitted above
 
809
            pass
809
810
 
810
811
 
811
812
class cmd_branch(Command):
826
827
    aliases = ['get', 'clone']
827
828
 
828
829
    def run(self, from_location, to_location=None, revision=None, basis=None):
 
830
        from bzrlib.tag import _merge_tags_if_possible
829
831
        if revision is None:
830
832
            revision = [None]
831
833
        elif len(revision) > 1:
876
878
                raise errors.BzrCommandError(msg)
877
879
            if name:
878
880
                branch.control_files.put_utf8('branch-name', name)
 
881
            _merge_tags_if_possible(br_from, branch)
879
882
            note('Branched %d revision(s).' % branch.revno())
880
883
        finally:
881
884
            br_from.unlock()
2416
2419
                ' source rather than merging. When this happens,'
2417
2420
                ' you do not need to commit the result.'),
2418
2421
        Option('directory',
2419
 
            help='branch to merge into, '
 
2422
            help='Branch to merge into, '
2420
2423
                 'rather than the one containing the working directory',
2421
2424
            short_name='d',
2422
2425
            type=unicode,
2428
2431
            uncommitted=False, pull=False,
2429
2432
            directory=None,
2430
2433
            ):
 
2434
        from bzrlib.tag import _merge_tags_if_possible
2431
2435
        if merge_type is None:
2432
2436
            merge_type = _mod_merge.Merge3Merger
2433
2437
 
2488
2492
        if tree.branch.get_parent() is None or remember:
2489
2493
            tree.branch.set_parent(other_branch.base)
2490
2494
 
 
2495
        # pull tags now... it's a bit inconsistent to do it ahead of copying
 
2496
        # the history but that's done inside the merge code
 
2497
        _merge_tags_if_possible(other_branch, tree.branch)
 
2498
 
2491
2499
        if path != "":
2492
2500
            interesting_files = [path]
2493
2501
        else:
3168
3176
        server.serve()
3169
3177
 
3170
3178
 
 
3179
class cmd_tag(Command):
 
3180
    """Create a tag naming a revision.
 
3181
    
 
3182
    Tags give human-meaningful names to revisions.  Commands that take a -r
 
3183
    (--revision) option can be given -rtag:X, where X is any previously
 
3184
    created tag.
 
3185
 
 
3186
    Tags are stored in the branch.  Tags are copied from one branch to another
 
3187
    along when you branch, push, pull or merge.
 
3188
 
 
3189
    It is an error to give a tag name that already exists unless you pass 
 
3190
    --force, in which case the tag is moved to point to the new revision.
 
3191
    """
 
3192
 
 
3193
    takes_args = ['tag_name']
 
3194
    takes_options = [
 
3195
        Option('delete',
 
3196
            help='Delete this tag rather than placing it.',
 
3197
            ),
 
3198
        Option('directory',
 
3199
            help='Branch in which to place the tag.',
 
3200
            short_name='d',
 
3201
            type=unicode,
 
3202
            ),
 
3203
        Option('force',
 
3204
            help='Replace existing tags',
 
3205
            ),
 
3206
        'revision',
 
3207
        ]
 
3208
 
 
3209
    def run(self, tag_name,
 
3210
            delete=None,
 
3211
            directory='.',
 
3212
            force=None,
 
3213
            revision=None,
 
3214
            ):
 
3215
        branch, relpath = Branch.open_containing(directory)
 
3216
        branch.lock_write()
 
3217
        try:
 
3218
            if delete:
 
3219
                branch.tags.delete_tag(tag_name)
 
3220
                self.outf.write('Deleted tag %s.\n' % tag_name)
 
3221
            else:
 
3222
                if revision:
 
3223
                    if len(revision) != 1:
 
3224
                        raise errors.BzrCommandError(
 
3225
                            "Tags can only be placed on a single revision, "
 
3226
                            "not on a range")
 
3227
                    revision_id = revision[0].in_history(branch).rev_id
 
3228
                else:
 
3229
                    revision_id = branch.last_revision()
 
3230
                if (not force) and branch.tags.has_tag(tag_name):
 
3231
                    raise errors.TagAlreadyExists(tag_name)
 
3232
                branch.tags.set_tag(tag_name, revision_id)
 
3233
                self.outf.write('Created tag %s.\n' % tag_name)
 
3234
        finally:
 
3235
            branch.unlock()
 
3236
 
 
3237
 
 
3238
class cmd_tags(Command):
 
3239
    """List tags.
 
3240
 
 
3241
    This tag shows a table of tag names and the revisions they reference.
 
3242
    """
 
3243
 
 
3244
    takes_options = [
 
3245
        Option('directory',
 
3246
            help='Branch whose tags should be displayed',
 
3247
            short_name='d',
 
3248
            type=unicode,
 
3249
            ),
 
3250
    ]
 
3251
 
 
3252
    @display_command
 
3253
    def run(self,
 
3254
            directory='.',
 
3255
            ):
 
3256
        branch, relpath = Branch.open_containing(directory)
 
3257
        for tag_name, target in sorted(branch.tags.get_tag_dict().items()):
 
3258
            self.outf.write('%-20s %s\n' % (tag_name, target))
 
3259
 
 
3260
 
3171
3261
# command-line interpretation helper for merge-related commands
3172
3262
def _merge_helper(other_revision, base_revision,
3173
3263
                  check_clean=True, ignore_zero=False,
3232
3322
            return 0
3233
3323
        if file_list is None:
3234
3324
            if pull and merger.base_rev_id == merger.this_rev_id:
3235
 
                count = merger.this_tree.pull(merger.this_branch,
 
3325
                # FIXME: deduplicate with pull
 
3326
                result = merger.this_tree.pull(merger.this_branch,
3236
3327
                        False, merger.other_rev_id)
3237
 
                note('%d revision(s) pulled.' % (count,))
 
3328
                if result.old_revid == result.new_revid:
 
3329
                    note('No revisions to pull.')
 
3330
                else:
 
3331
                    note('Now on revision %d.' % result.new_revno)
3238
3332
                return 0
3239
3333
        merger.backup_files = backup_files
3240
3334
        merger.merge_type = merge_type