~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: 2009-02-10 02:22:43 UTC
  • mfrom: (3993.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090210022243-eobdt6wezitsxs65
helper function when only one revision required (Daniel Watkins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
                                     (e.path, file_list[0]))
74
74
 
75
75
 
 
76
def _get_one_revision(command_name, revisions):
 
77
    if revisions is None:
 
78
        return None
 
79
    if len(revisions) != 1:
 
80
        raise errors.BzrCommandError(
 
81
            'bzr %s --revision takes exactly one revision identifier' % (
 
82
                command_name,))
 
83
    return revisions[0]
 
84
 
 
85
 
76
86
def _get_one_revision_tree(command_name, revisions, branch=None, tree=None):
77
87
    if branch is None:
78
88
        branch = tree.branch
82
92
        else:
83
93
            rev_tree = branch.basis_tree()
84
94
    else:
85
 
        if len(revisions) != 1:
86
 
            raise errors.BzrCommandError(
87
 
                'bzr %s --revision takes exactly one revision identifier' % (
88
 
                    command_name,))
89
 
        rev_tree = revisions[0].as_tree(branch)
 
95
        revision = _get_one_revision(command_name, revisions)
 
96
        rev_tree = revision.as_tree(branch)
90
97
    return rev_tree
91
98
 
92
99
 
600
607
        if kind and kind not in ['file', 'directory', 'symlink']:
601
608
            raise errors.BzrCommandError('invalid kind %r specified' % (kind,))
602
609
 
 
610
        revision = _get_one_revision('inventory', revision)
603
611
        work_tree, file_list = tree_files(file_list)
604
612
        work_tree.lock_read()
605
613
        try:
606
614
            if revision is not None:
607
 
                if len(revision) > 1:
608
 
                    raise errors.BzrCommandError(
609
 
                        'bzr inventory --revision takes exactly one revision'
610
 
                        ' identifier')
611
 
                tree = revision[0].as_tree(work_tree.branch)
 
615
                tree = revision.as_tree(work_tree.branch)
612
616
 
613
617
                extra_trees = [work_tree]
614
618
                tree.lock_read()
833
837
                    self.outf.write("Using saved parent location: %s\n" % display_url)
834
838
                location = stored_loc
835
839
 
 
840
        revision = _get_one_revision('pull', revision)
836
841
        if mergeable is not None:
837
842
            if revision is not None:
838
843
                raise errors.BzrCommandError(
849
854
                branch_to.set_parent(branch_from.base)
850
855
 
851
856
        if revision is not None:
852
 
            if len(revision) == 1:
853
 
                revision_id = revision[0].as_revision_id(branch_from)
854
 
            else:
855
 
                raise errors.BzrCommandError(
856
 
                    'bzr pull --revision takes one value.')
 
857
            revision_id = revision.as_revision_id(branch_from)
857
858
 
858
859
        branch_to.lock_write()
859
860
        try:
938
939
        if directory is None:
939
940
            directory = '.'
940
941
        br_from = Branch.open_containing(directory)[0]
 
942
        revision = _get_one_revision('push', revision)
941
943
        if revision is not None:
942
 
            if len(revision) == 1:
943
 
                revision_id = revision[0].in_history(br_from).rev_id
944
 
            else:
945
 
                raise errors.BzrCommandError(
946
 
                    'bzr push --revision takes one value.')
 
944
            revision_id = revision.in_history(br_from).rev_id
947
945
        else:
948
946
            revision_id = br_from.last_revision()
949
947
 
1013
1011
    def run(self, from_location, to_location=None, revision=None,
1014
1012
            hardlink=False, stacked=False, standalone=False):
1015
1013
        from bzrlib.tag import _merge_tags_if_possible
1016
 
        if revision is None:
1017
 
            revision = [None]
1018
 
        elif len(revision) > 1:
1019
 
            raise errors.BzrCommandError(
1020
 
                'bzr branch --revision takes exactly 1 revision value')
1021
1014
 
1022
1015
        accelerator_tree, br_from = bzrdir.BzrDir.open_tree_or_branch(
1023
1016
            from_location)
 
1017
        revision = _get_one_revision('branch', revision)
1024
1018
        br_from.lock_read()
1025
1019
        try:
1026
 
            if len(revision) == 1 and revision[0] is not None:
1027
 
                revision_id = revision[0].as_revision_id(br_from)
 
1020
            if revision is not None:
 
1021
                revision_id = revision.as_revision_id(br_from)
1028
1022
            else:
1029
1023
                # FIXME - wt.last_revision, fallback to branch, fall back to
1030
1024
                # None or perhaps NULL_REVISION to mean copy nothing
1053
1047
            except errors.NoSuchRevision:
1054
1048
                to_transport.delete_tree('.')
1055
1049
                msg = "The branch %s has no revision %s." % (from_location,
1056
 
                    revision[0])
 
1050
                    revision)
1057
1051
                raise errors.BzrCommandError(msg)
1058
1052
            _merge_tags_if_possible(br_from, branch)
1059
1053
            # If the source branch is stacked, the new branch may
1110
1104
 
1111
1105
    def run(self, branch_location=None, to_location=None, revision=None,
1112
1106
            lightweight=False, files_from=None, hardlink=False):
1113
 
        if revision is None:
1114
 
            revision = [None]
1115
 
        elif len(revision) > 1:
1116
 
            raise errors.BzrCommandError(
1117
 
                'bzr checkout --revision takes exactly 1 revision value')
1118
1107
        if branch_location is None:
1119
1108
            branch_location = osutils.getcwd()
1120
1109
            to_location = branch_location
1121
1110
        accelerator_tree, source = bzrdir.BzrDir.open_tree_or_branch(
1122
1111
            branch_location)
 
1112
        revision = _get_one_revision('checkout', revision)
1123
1113
        if files_from is not None:
1124
1114
            accelerator_tree = WorkingTree.open(files_from)
1125
 
        if len(revision) == 1 and revision[0] is not None:
1126
 
            revision_id = revision[0].as_revision_id(source)
 
1115
        if revision is not None:
 
1116
            revision_id = revision.as_revision_id(source)
1127
1117
        else:
1128
1118
            revision_id = None
1129
1119
        if to_location is None: