~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Lukáš Lalinský
  • Date: 2008-08-28 13:41:15 UTC
  • mto: (3732.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3733.
  • Revision ID: lalinsky@gmail.com-20080828134115-265uyumclq5qvetg
Fix `bzr st -rbranch:PATH_TO_BRANCH`

* Add RevisionSpec.as_tree which returns a tree representation of the revision specifier. This might return a remote revision tree.
* Make status use this new method and not require RevisionSpec.as_revision_id, which for RevisionSpec_branch fetches data to the local repository.
* Refactor common code for getting either a revision tree or a tree/branch's basis tree into a private function _get_revision_tree and make it use RevisionSpec.as_tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
                                     (e.path, file_list[0]))
68
68
 
69
69
 
 
70
def _get_revision_tree(command_name, revision, branch=None, tree=None):
 
71
    if branch is None:
 
72
        branch = tree.branch
 
73
    if revision is None:
 
74
        if tree is not None:
 
75
            rev_tree = tree.basis_tree()
 
76
        else:
 
77
            rev_tree = branch.basis_tree()
 
78
    else:
 
79
        if len(revision) != 1:
 
80
            raise errors.BzrCommandError(
 
81
                'bzr %s --revision takes exactly one revision identifier' % (
 
82
                    command_name,))
 
83
        rev_tree = revision[0].as_tree(branch)
 
84
    return rev_tree
 
85
 
 
86
 
70
87
# XXX: Bad function name; should possibly also be a class method of
71
88
# WorkingTree rather than a function.
72
89
def internal_tree_files(file_list, default_branch=u'.'):
477
494
                    raise errors.BzrCommandError(
478
495
                        'bzr inventory --revision takes exactly one revision'
479
496
                        ' identifier')
480
 
                revision_id = revision[0].as_revision_id(work_tree.branch)
481
 
                tree = work_tree.branch.repository.revision_tree(revision_id)
 
497
                tree = revision[0].as_tree(work_tree.branch)
482
498
 
483
499
                extra_trees = [work_tree]
484
500
                tree.lock_read()
1836
1852
            relpath = u''
1837
1853
        elif relpath:
1838
1854
            relpath += '/'
1839
 
        if revision is not None:
1840
 
            tree = branch.repository.revision_tree(
1841
 
                revision[0].as_revision_id(branch))
1842
 
        elif tree is None:
1843
 
            tree = branch.basis_tree()
 
1855
        if revision is not None or tree is None:
 
1856
            tree = _get_revision_tree('ls', revision, branch=branch)
1844
1857
 
1845
1858
        tree.lock_read()
1846
1859
        try:
2064
2077
            subdir = None
2065
2078
        else:
2066
2079
            b, subdir = Branch.open_containing(branch_or_subdir)
2067
 
            
2068
 
        if revision is None:
2069
 
            # should be tree.last_revision  FIXME
2070
 
            rev_id = b.last_revision()
2071
 
        else:
2072
 
            if len(revision) != 1:
2073
 
                raise errors.BzrCommandError('bzr export --revision takes exactly 1 argument')
2074
 
            rev_id = revision[0].as_revision_id(b)
2075
 
        t = b.repository.revision_tree(rev_id)
 
2080
            tree = None
 
2081
 
 
2082
        rev_tree = _get_revision_tree('export', revision, branch=b, tree=tree)
2076
2083
        try:
2077
 
            export(t, dest, format, root, subdir)
 
2084
            export(rev_tree, dest, format, root, subdir)
2078
2085
        except errors.NoSuchExportFormat, e:
2079
2086
            raise errors.BzrCommandError('Unsupported export format: %s' % e.format)
2080
2087
 
2113
2120
    def _run(self, tree, b, relpath, filename, revision, name_from_revision):
2114
2121
        if tree is None:
2115
2122
            tree = b.basis_tree()
2116
 
        if revision is None:
2117
 
            revision_id = b.last_revision()
2118
 
        else:
2119
 
            revision_id = revision[0].as_revision_id(b)
 
2123
        rev_tree = _get_revision_tree('cat', revision, branch=b)
2120
2124
 
2121
2125
        cur_file_id = tree.path2id(relpath)
2122
 
        rev_tree = b.repository.revision_tree(revision_id)
2123
2126
        old_file_id = rev_tree.path2id(relpath)
2124
 
        
 
2127
 
2125
2128
        if name_from_revision:
2126
2129
            if old_file_id is None:
2127
 
                raise errors.BzrCommandError("%r is not present in revision %s"
2128
 
                                                % (filename, revision_id))
 
2130
                raise errors.BzrCommandError(
 
2131
                    "%r is not present in revision %s" % (
 
2132
                        filename, rev_tree.get_revision_id()))
2129
2133
            else:
2130
2134
                content = rev_tree.get_file_text(old_file_id)
2131
2135
        elif cur_file_id is not None:
2133
2137
        elif old_file_id is not None:
2134
2138
            content = rev_tree.get_file_text(old_file_id)
2135
2139
        else:
2136
 
            raise errors.BzrCommandError("%r is not present in revision %s" %
2137
 
                                         (filename, revision_id))
 
2140
            raise errors.BzrCommandError(
 
2141
                "%r is not present in revision %s" % (
 
2142
                    filename, rev_tree.get_revision_id()))
2138
2143
        self.outf.write(content)
2139
2144
 
2140
2145
 
3235
3240
 
3236
3241
    @staticmethod
3237
3242
    def _revert_tree_to_revision(tree, revision, file_list, no_backup):
3238
 
        if revision is None:
3239
 
            rev_id = tree.last_revision()
3240
 
        elif len(revision) != 1:
3241
 
            raise errors.BzrCommandError('bzr revert --revision takes exactly 1 argument')
3242
 
        else:
3243
 
            rev_id = revision[0].as_revision_id(tree.branch)
 
3243
        rev_tree = _get_revision_tree('revert', revision, tree=tree)
3244
3244
        pb = ui.ui_factory.nested_progress_bar()
3245
3245
        try:
3246
 
            tree.revert(file_list,
3247
 
                        tree.branch.repository.revision_tree(rev_id),
3248
 
                        not no_backup, pb, report_changes=True)
 
3246
            tree.revert(file_list, rev_tree, not no_backup, pb,
 
3247
                report_changes=True)
3249
3248
        finally:
3250
3249
            pb.finished()
3251
3250
 
3546
3545
        else:
3547
3546
            branch.lock_read()
3548
3547
        try:
3549
 
            if revision is None:
3550
 
                revision_id = branch.last_revision()
3551
 
            elif len(revision) != 1:
3552
 
                raise errors.BzrCommandError('bzr annotate --revision takes exactly 1 argument')
3553
 
            else:
3554
 
                revision_id = revision[0].as_revision_id(branch)
3555
 
            tree = branch.repository.revision_tree(revision_id)
 
3548
            tree = _get_revision_tree('annotate', revision, branch=branch)
3556
3549
            if wt is not None:
3557
3550
                file_id = wt.path2id(relpath)
3558
3551
            else: