~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.py

  • Committer: Martin Pool
  • Date: 2010-07-16 13:29:07 UTC
  • mto: This revision was merged to the branch mainline in revision 5351.
  • Revision ID: mbp@canonical.com-20100716132907-0iffip1m4qt5vvif
Move internal_tree_files and safe_relpath_files onto WorkingTree

Show diffs side-by-side

added added

removed removed

Lines of Context:
152
152
 
153
153
# XXX: Bad function name; should possibly also be a class method of
154
154
# WorkingTree rather than a function.
 
155
# @symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
155
156
def internal_tree_files(file_list, default_branch=u'.', canonicalize=True,
156
157
    apply_view=True):
157
158
    """Convert command-line paths to a WorkingTree and relative paths.
158
159
 
 
160
    Deprecated: use WorkingTree.open_containing_paths instead.
 
161
 
159
162
    This is typically used for command-line processors that take one or
160
163
    more filenames, and infer the workingtree that contains them.
161
164
 
171
174
 
172
175
    :return: workingtree, [relative_paths]
173
176
    """
174
 
    if file_list is None or len(file_list) == 0:
175
 
        tree = WorkingTree.open_containing(default_branch)[0]
176
 
        if tree.supports_views() and apply_view:
177
 
            view_files = tree.views.lookup_view()
178
 
            if view_files:
179
 
                file_list = view_files
180
 
                view_str = views.view_display_str(view_files)
181
 
                note("Ignoring files outside view. View is %s" % view_str)
182
 
        return tree, file_list
183
 
    tree = WorkingTree.open_containing(file_list[0])[0]
184
 
    return tree, safe_relpath_files(tree, file_list, canonicalize,
185
 
        apply_view=apply_view)
186
 
 
187
 
 
188
 
def safe_relpath_files(tree, file_list, canonicalize=True, apply_view=True):
189
 
    """Convert file_list into a list of relpaths in tree.
190
 
 
191
 
    :param tree: A tree to operate on.
192
 
    :param file_list: A list of user provided paths or None.
193
 
    :param apply_view: if True and a view is set, apply it or check that
194
 
        specified files are within it
195
 
    :return: A list of relative paths.
196
 
    :raises errors.PathNotChild: When a provided path is in a different tree
197
 
        than tree.
198
 
    """
199
 
    if file_list is None:
200
 
        return None
201
 
    if tree.supports_views() and apply_view:
202
 
        view_files = tree.views.lookup_view()
203
 
    else:
204
 
        view_files = []
205
 
    new_list = []
206
 
    # tree.relpath exists as a "thunk" to osutils, but canonical_relpath
207
 
    # doesn't - fix that up here before we enter the loop.
208
 
    if canonicalize:
209
 
        fixer = lambda p: osutils.canonical_relpath(tree.basedir, p)
210
 
    else:
211
 
        fixer = tree.relpath
212
 
    for filename in file_list:
213
 
        try:
214
 
            relpath = fixer(osutils.dereference_path(filename))
215
 
            if  view_files and not osutils.is_inside_any(view_files, relpath):
216
 
                raise errors.FileOutsideView(filename, view_files)
217
 
            new_list.append(relpath)
218
 
        except errors.PathNotChild:
219
 
            raise errors.FileInWrongBranch(tree.branch, filename)
220
 
    return new_list
 
177
    return WorkingTree.open_containing_paths(
 
178
        file_list, default_directory='.',
 
179
        canonicalize=True,
 
180
        apply_view=True)
221
181
 
222
182
 
223
183
def _get_view_info_for_change_reporter(tree):
3189
3149
                        reporter=None, verbose=verbose, revprops=properties,
3190
3150
                        authors=author, timestamp=commit_stamp,
3191
3151
                        timezone=offset,
3192
 
                        exclude=safe_relpath_files(tree, exclude))
 
3152
                        exclude=tree.safe_relpath_files(exclude))
3193
3153
        except PointlessCommit:
3194
3154
            raise errors.BzrCommandError("No changes to commit."
3195
3155
                              " Use --unchanged to commit anyhow.")