~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: 2010-07-19 14:26:11 UTC
  • mfrom: (5346.4.6 cleanup)
  • Revision ID: pqm@pqm.ubuntu.com-20100719142611-fbhst4ivcngc32d5
(mbp) tree_files and internal_tree files moved to WorkingTree (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
from bzrlib.trace import mutter, note, warning, is_quiet, get_verbosity_level
76
76
 
77
77
 
 
78
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
78
79
def tree_files(file_list, default_branch=u'.', canonicalize=True,
79
80
    apply_view=True):
80
81
    return internal_tree_files(file_list, default_branch, canonicalize,
148
149
 
149
150
# XXX: Bad function name; should possibly also be a class method of
150
151
# WorkingTree rather than a function.
 
152
@symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
151
153
def internal_tree_files(file_list, default_branch=u'.', canonicalize=True,
152
154
    apply_view=True):
153
155
    """Convert command-line paths to a WorkingTree and relative paths.
154
156
 
 
157
    Deprecated: use WorkingTree.open_containing_paths instead.
 
158
 
155
159
    This is typically used for command-line processors that take one or
156
160
    more filenames, and infer the workingtree that contains them.
157
161
 
167
171
 
168
172
    :return: workingtree, [relative_paths]
169
173
    """
170
 
    if file_list is None or len(file_list) == 0:
171
 
        tree = WorkingTree.open_containing(default_branch)[0]
172
 
        if tree.supports_views() and apply_view:
173
 
            view_files = tree.views.lookup_view()
174
 
            if view_files:
175
 
                file_list = view_files
176
 
                view_str = views.view_display_str(view_files)
177
 
                note("Ignoring files outside view. View is %s" % view_str)
178
 
        return tree, file_list
179
 
    tree = WorkingTree.open_containing(osutils.realpath(file_list[0]))[0]
180
 
    return tree, safe_relpath_files(tree, file_list, canonicalize,
181
 
        apply_view=apply_view)
182
 
 
183
 
 
184
 
def safe_relpath_files(tree, file_list, canonicalize=True, apply_view=True):
185
 
    """Convert file_list into a list of relpaths in tree.
186
 
 
187
 
    :param tree: A tree to operate on.
188
 
    :param file_list: A list of user provided paths or None.
189
 
    :param apply_view: if True and a view is set, apply it or check that
190
 
        specified files are within it
191
 
    :return: A list of relative paths.
192
 
    :raises errors.PathNotChild: When a provided path is in a different tree
193
 
        than tree.
194
 
    """
195
 
    if file_list is None:
196
 
        return None
197
 
    if tree.supports_views() and apply_view:
198
 
        view_files = tree.views.lookup_view()
199
 
    else:
200
 
        view_files = []
201
 
    new_list = []
202
 
    # tree.relpath exists as a "thunk" to osutils, but canonical_relpath
203
 
    # doesn't - fix that up here before we enter the loop.
204
 
    if canonicalize:
205
 
        fixer = lambda p: osutils.canonical_relpath(tree.basedir, p)
206
 
    else:
207
 
        fixer = tree.relpath
208
 
    for filename in file_list:
209
 
        relpath = fixer(osutils.dereference_path(filename))
210
 
        if  view_files and not osutils.is_inside_any(view_files, relpath):
211
 
            raise errors.FileOutsideView(filename, view_files)
212
 
        new_list.append(relpath)
213
 
    return new_list
 
174
    return WorkingTree.open_containing_paths(
 
175
        file_list, default_directory='.',
 
176
        canonicalize=True,
 
177
        apply_view=True)
214
178
 
215
179
 
216
180
def _get_view_info_for_change_reporter(tree):
316
280
            raise errors.BzrCommandError('bzr status --revision takes exactly'
317
281
                                         ' one or two revision specifiers')
318
282
 
319
 
        tree, relfile_list = tree_files(file_list)
 
283
        tree, relfile_list = WorkingTree.open_containing_paths(file_list)
320
284
        # Avoid asking for specific files when that is not needed.
321
285
        if relfile_list == ['']:
322
286
            relfile_list = None
754
718
            raise errors.BzrCommandError('invalid kind %r specified' % (kind,))
755
719
 
756
720
        revision = _get_one_revision('inventory', revision)
757
 
        work_tree, file_list = tree_files(file_list)
 
721
        work_tree, file_list = WorkingTree.open_containing_paths(file_list)
758
722
        self.add_cleanup(work_tree.lock_read().unlock)
759
723
        if revision is not None:
760
724
            tree = revision.as_tree(work_tree.branch)
825
789
            names_list = []
826
790
        if len(names_list) < 2:
827
791
            raise errors.BzrCommandError("missing file argument")
828
 
        tree, rel_names = tree_files(names_list, canonicalize=False)
 
792
        tree, rel_names = WorkingTree.open_containing_paths(names_list, canonicalize=False)
829
793
        self.add_cleanup(tree.lock_tree_write().unlock)
830
794
        self._run(tree, names_list, rel_names, after)
831
795
 
836
800
        if after:
837
801
            raise errors.BzrCommandError('--after cannot be specified with'
838
802
                                         ' --auto.')
839
 
        work_tree, file_list = tree_files(names_list, default_branch='.')
 
803
        work_tree, file_list = WorkingTree.open_containing_paths(
 
804
            names_list, default_directory='.')
840
805
        self.add_cleanup(work_tree.lock_tree_write().unlock)
841
806
        rename_map.RenameMap.guess_renames(work_tree, dry_run)
842
807
 
1519
1484
 
1520
1485
    def run(self, file_list, verbose=False, new=False,
1521
1486
        file_deletion_strategy='safe'):
1522
 
        tree, file_list = tree_files(file_list)
 
1487
        tree, file_list = WorkingTree.open_containing_paths(file_list)
1523
1488
 
1524
1489
        if file_list is not None:
1525
1490
            file_list = [f for f in file_list]
3102
3067
 
3103
3068
        properties = {}
3104
3069
 
3105
 
        tree, selected_list = tree_files(selected_list)
 
3070
        tree, selected_list = WorkingTree.open_containing_paths(selected_list)
3106
3071
        if selected_list == ['']:
3107
3072
            # workaround - commit of root of tree should be exactly the same
3108
3073
            # as just default commit in that tree, and succeed even though
3182
3147
                        reporter=None, verbose=verbose, revprops=properties,
3183
3148
                        authors=author, timestamp=commit_stamp,
3184
3149
                        timezone=offset,
3185
 
                        exclude=safe_relpath_files(tree, exclude))
 
3150
                        exclude=tree.safe_relpath_files(exclude))
3186
3151
        except PointlessCommit:
3187
3152
            raise errors.BzrCommandError("No changes to commit."
3188
3153
                              " Use --unchanged to commit anyhow.")
4084
4049
        from bzrlib.conflicts import restore
4085
4050
        if merge_type is None:
4086
4051
            merge_type = _mod_merge.Merge3Merger
4087
 
        tree, file_list = tree_files(file_list)
 
4052
        tree, file_list = WorkingTree.open_containing_paths(file_list)
4088
4053
        self.add_cleanup(tree.lock_write().unlock)
4089
4054
        parents = tree.get_parent_ids()
4090
4055
        if len(parents) != 2:
4200
4165
 
4201
4166
    def run(self, revision=None, no_backup=False, file_list=None,
4202
4167
            forget_merges=None):
4203
 
        tree, file_list = tree_files(file_list)
 
4168
        tree, file_list = WorkingTree.open_containing_paths(file_list)
4204
4169
        self.add_cleanup(tree.lock_tree_write().unlock)
4205
4170
        if forget_merges:
4206
4171
            tree.set_parent_ids(tree.get_parent_ids()[:1])
5702
5667
            name=None,
5703
5668
            switch=None,
5704
5669
            ):
5705
 
        tree, file_list = tree_files(file_list, apply_view=False)
 
5670
        tree, file_list = WorkingTree.open_containing_paths(file_list,
 
5671
            apply_view=False)
5706
5672
        current_view, view_dict = tree.views.get_view_info()
5707
5673
        if name is None:
5708
5674
            name = current_view