25
25
from bzrlib import (
26
conflicts as _mod_conflicts,
28
29
revision as _mod_revision,
29
conflicts as _mod_conflicts,
32
33
from bzrlib.decorators import needs_read_lock
176
177
def iter_entries_by_dir(self, specific_file_ids=None):
177
178
"""Walk the tree in 'by_dir' order.
179
This will yield each entry in the tree as a (path, entry) tuple. The
180
order that they are yielded is: the contents of a directory are
181
preceeded by the parent of a directory, and all the contents of a
182
directory are grouped together.
180
This will yield each entry in the tree as a (path, entry) tuple.
181
The order that they are yielded is:
183
Directories are walked in a depth-first lexicographical order,
184
however, whenever a directory is reached, all of its direct child
185
nodes are yielded in lexicographical order before yielding the
188
For example, in the tree::
198
The yield order (ignoring root) would be::
199
a, f, a/b, a/d, a/b/c, a/d/e, f/g
184
201
return self.inventory.iter_entries_by_dir(
185
202
specific_file_ids=specific_file_ids)
357
374
return vf.plan_lca_merge(last_revision_a, last_revision_b,
358
375
last_revision_base)
377
def _iter_parent_trees(self):
378
"""Iterate through parent trees, defaulting to Tree.revision_tree."""
379
for revision_id in self.get_parent_ids():
381
yield self.revision_tree(revision_id)
382
except errors.NoSuchRevisionInTree:
383
yield self.repository.revision_tree(revision_id)
386
def _file_revision(revision_tree, file_id):
387
"""Determine the revision associated with a file in a given tree."""
388
revision_tree.lock_read()
390
return revision_tree.inventory[file_id].revision
392
revision_tree.unlock()
360
394
def _get_file_revision(self, file_id, vf, tree_revision):
361
395
"""Ensure that file_id, tree_revision is in vf to plan the merge."""
362
def file_revision(revision_tree):
363
revision_tree.lock_read()
365
return revision_tree.inventory[file_id].revision
367
revision_tree.unlock()
369
def iter_parent_trees():
370
for revision_id in self.get_parent_ids():
372
yield self.revision_tree(revision_id)
374
yield self.repository.revision_tree(revision_id)
376
397
if getattr(self, '_repository', None) is None:
377
398
last_revision = tree_revision
378
parent_keys = [(file_id, file_revision(t)) for t in
399
parent_keys = [(file_id, self._file_revision(t, file_id)) for t in
400
self._iter_parent_trees()]
380
401
vf.add_lines((file_id, last_revision), parent_keys,
381
402
self.get_file(file_id).readlines())
382
403
repo = self.branch.repository
383
404
base_vf = repo.texts
385
last_revision = file_revision(self)
406
last_revision = self._file_revision(self, file_id)
386
407
base_vf = self._repository.texts
387
408
if base_vf not in vf.fallback_versionedfiles:
388
409
vf.fallback_versionedfiles.append(base_vf)
513
534
raise NotImplementedError(self.walkdirs)
536
def iter_search_rules(self, path_names, pref_names=None,
537
_default_searcher=rules._per_user_searcher):
538
"""Find the preferences for filenames in a tree.
540
:param path_names: an iterable of paths to find attributes for.
541
Paths are given relative to the root of the tree.
542
:param pref_names: the list of preferences to lookup - None for all
543
:param _default_searcher: private parameter to assist testing - don't use
544
:return: an iterator of tuple sequences, one per path-name.
545
See _RulesSearcher.get_items for details on the tuple sequence.
547
searcher = self._get_rules_searcher(_default_searcher)
548
if searcher is not None:
549
if pref_names is not None:
550
for path in path_names:
551
yield searcher.get_selected_items(path, pref_names)
553
for path in path_names:
554
yield searcher.get_items(path)
557
def _get_rules_searcher(self, default_searcher):
558
"""Get the RulesSearcher for this tree given the default one."""
559
searcher = default_searcher
560
file_id = self.path2id(rules.RULES_TREE_FILENAME)
561
if file_id is not None:
562
ini_file = self.get_file(file_id)
563
searcher = rules._StackedRulesSearcher(
564
[rules._IniBasedRulesSearcher(ini_file), default_searcher])
516
568
class EmptyTree(Tree):