~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Ian Clatworthy
  • Date: 2008-09-24 06:52:03 UTC
  • mfrom: (3655.3.1 revspec_as_tree)
  • mto: This revision was merged to the branch mainline in revision 3733.
  • Revision ID: ian.clatworthy@canonical.com-20080924065203-69aq3cbypyyo30zs
fix bzr st -rbranch:path-to-branch (Lukas Lalinsky)

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_one_revision_tree(command_name, revisions, branch=None, tree=None):
 
71
    if branch is None:
 
72
        branch = tree.branch
 
73
    if revisions 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(revisions) != 1:
 
80
            raise errors.BzrCommandError(
 
81
                'bzr %s --revision takes exactly one revision identifier' % (
 
82
                    command_name,))
 
83
        rev_tree = revisions[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'.'):
490
507
                    raise errors.BzrCommandError(
491
508
                        'bzr inventory --revision takes exactly one revision'
492
509
                        ' identifier')
493
 
                revision_id = revision[0].as_revision_id(work_tree.branch)
494
 
                tree = work_tree.branch.repository.revision_tree(revision_id)
 
510
                tree = revision[0].as_tree(work_tree.branch)
495
511
 
496
512
                extra_trees = [work_tree]
497
513
                tree.lock_read()
1850
1866
            relpath = u''
1851
1867
        elif relpath:
1852
1868
            relpath += '/'
1853
 
        if revision is not None:
1854
 
            tree = branch.repository.revision_tree(
1855
 
                revision[0].as_revision_id(branch))
1856
 
        elif tree is None:
1857
 
            tree = branch.basis_tree()
 
1869
        if revision is not None or tree is None:
 
1870
            tree = _get_one_revision_tree('ls', revision, branch=branch)
1858
1871
 
1859
1872
        tree.lock_read()
1860
1873
        try:
2078
2091
            subdir = None
2079
2092
        else:
2080
2093
            b, subdir = Branch.open_containing(branch_or_subdir)
2081
 
            
2082
 
        if revision is None:
2083
 
            # should be tree.last_revision  FIXME
2084
 
            rev_id = b.last_revision()
2085
 
        else:
2086
 
            if len(revision) != 1:
2087
 
                raise errors.BzrCommandError('bzr export --revision takes exactly 1 argument')
2088
 
            rev_id = revision[0].as_revision_id(b)
2089
 
        t = b.repository.revision_tree(rev_id)
 
2094
            tree = None
 
2095
 
 
2096
        rev_tree = _get_one_revision_tree('export', revision, branch=b, tree=tree)
2090
2097
        try:
2091
 
            export(t, dest, format, root, subdir)
 
2098
            export(rev_tree, dest, format, root, subdir)
2092
2099
        except errors.NoSuchExportFormat, e:
2093
2100
            raise errors.BzrCommandError('Unsupported export format: %s' % e.format)
2094
2101
 
2127
2134
    def _run(self, tree, b, relpath, filename, revision, name_from_revision):
2128
2135
        if tree is None:
2129
2136
            tree = b.basis_tree()
2130
 
        if revision is None:
2131
 
            revision_id = b.last_revision()
2132
 
        else:
2133
 
            revision_id = revision[0].as_revision_id(b)
 
2137
        rev_tree = _get_one_revision_tree('cat', revision, branch=b)
2134
2138
 
2135
2139
        cur_file_id = tree.path2id(relpath)
2136
 
        rev_tree = b.repository.revision_tree(revision_id)
2137
2140
        old_file_id = rev_tree.path2id(relpath)
2138
 
        
 
2141
 
2139
2142
        if name_from_revision:
2140
2143
            if old_file_id is None:
2141
 
                raise errors.BzrCommandError("%r is not present in revision %s"
2142
 
                                                % (filename, revision_id))
 
2144
                raise errors.BzrCommandError(
 
2145
                    "%r is not present in revision %s" % (
 
2146
                        filename, rev_tree.get_revision_id()))
2143
2147
            else:
2144
2148
                content = rev_tree.get_file_text(old_file_id)
2145
2149
        elif cur_file_id is not None:
2147
2151
        elif old_file_id is not None:
2148
2152
            content = rev_tree.get_file_text(old_file_id)
2149
2153
        else:
2150
 
            raise errors.BzrCommandError("%r is not present in revision %s" %
2151
 
                                         (filename, revision_id))
 
2154
            raise errors.BzrCommandError(
 
2155
                "%r is not present in revision %s" % (
 
2156
                    filename, rev_tree.get_revision_id()))
2152
2157
        self.outf.write(content)
2153
2158
 
2154
2159
 
3250
3255
 
3251
3256
    @staticmethod
3252
3257
    def _revert_tree_to_revision(tree, revision, file_list, no_backup):
3253
 
        if revision is None:
3254
 
            rev_id = tree.last_revision()
3255
 
        elif len(revision) != 1:
3256
 
            raise errors.BzrCommandError('bzr revert --revision takes exactly 1 argument')
3257
 
        else:
3258
 
            rev_id = revision[0].as_revision_id(tree.branch)
 
3258
        rev_tree = _get_one_revision_tree('revert', revision, tree=tree)
3259
3259
        pb = ui.ui_factory.nested_progress_bar()
3260
3260
        try:
3261
 
            tree.revert(file_list,
3262
 
                        tree.branch.repository.revision_tree(rev_id),
3263
 
                        not no_backup, pb, report_changes=True)
 
3261
            tree.revert(file_list, rev_tree, not no_backup, pb,
 
3262
                report_changes=True)
3264
3263
        finally:
3265
3264
            pb.finished()
3266
3265
 
3561
3560
        else:
3562
3561
            branch.lock_read()
3563
3562
        try:
3564
 
            if revision is None:
3565
 
                revision_id = branch.last_revision()
3566
 
            elif len(revision) != 1:
3567
 
                raise errors.BzrCommandError('bzr annotate --revision takes exactly 1 argument')
3568
 
            else:
3569
 
                revision_id = revision[0].as_revision_id(branch)
3570
 
            tree = branch.repository.revision_tree(revision_id)
 
3563
            tree = _get_one_revision_tree('annotate', revision, branch=branch)
3571
3564
            if wt is not None:
3572
3565
                file_id = wt.path2id(relpath)
3573
3566
            else: