25
25
from bzrlib import (
26
conflicts as _mod_conflicts,
29
30
revision as _mod_revision,
30
conflicts as _mod_conflicts,
33
34
from bzrlib.decorators import needs_read_lock
177
178
def iter_entries_by_dir(self, specific_file_ids=None):
178
179
"""Walk the tree in 'by_dir' order.
180
This will yield each entry in the tree as a (path, entry) tuple. The
181
order that they are yielded is: the contents of a directory are
182
preceeded by the parent of a directory, and all the contents of a
183
directory are grouped together.
181
This will yield each entry in the tree as a (path, entry) tuple.
182
The order that they are yielded is:
184
Directories are walked in a depth-first lexicographical order,
185
however, whenever a directory is reached, all of its direct child
186
nodes are yielded in lexicographical order before yielding the
189
For example, in the tree::
199
The yield order (ignoring root) would be::
200
a, f, a/b, a/d, a/b/c, a/d/e, f/g
185
202
return self.inventory.iter_entries_by_dir(
186
203
specific_file_ids=specific_file_ids)
359
376
last_revision_base)
361
378
def _get_file_revision(self, file_id, vf, tree_revision):
379
"""Ensure that file_id, tree_revision is in vf to plan the merge."""
362
380
def file_revision(revision_tree):
363
381
revision_tree.lock_read()
374
392
yield self.repository.revision_tree(revision_id)
376
if getattr(self, '_get_weave', None) is None:
394
if getattr(self, '_repository', None) is None:
377
395
last_revision = tree_revision
378
parent_revisions = [file_revision(t) for t in iter_parent_trees()]
379
vf.add_lines(last_revision, parent_revisions,
396
parent_keys = [(file_id, file_revision(t)) for t in
398
vf.add_lines((file_id, last_revision), parent_keys,
380
399
self.get_file(file_id).readlines())
381
400
repo = self.branch.repository
382
transaction = repo.get_transaction()
383
base_vf = repo.weave_store.get_weave(file_id, transaction)
385
403
last_revision = file_revision(self)
386
base_vf = self._get_weave(file_id)
387
vf.fallback_versionedfiles.append(base_vf)
404
base_vf = self._repository.texts
405
if base_vf not in vf.fallback_versionedfiles:
406
vf.fallback_versionedfiles.append(base_vf)
388
407
return last_revision
390
409
inventory = property(_get_inventory,
434
453
return find_ids_across_trees(paths, [self] + list(trees), require_versioned)
455
@symbol_versioning.deprecated_method(symbol_versioning.one_six)
436
456
def print_file(self, file_id):
437
457
"""Print file with id `file_id` to stdout."""
529
549
path = self.id2path(file_id)
531
# TODO: Replace the line above with the line below
532
# (when the rule-based preferences branch is merged)
533
#prefs = rules.iter_search_rules(self.branch, [path],
534
# filter_pref_names).next()
550
prefs = rules.iter_search_rules(self.branch, [path],
551
filter_pref_names).next()
535
552
return filters._get_filter_stack_for(prefs)
554
def iter_search_rules(self, path_names, pref_names=None,
555
_default_searcher=rules._per_user_searcher):
556
"""Find the preferences for filenames in a tree.
558
:param path_names: an iterable of paths to find attributes for.
559
Paths are given relative to the root of the tree.
560
:param pref_names: the list of preferences to lookup - None for all
561
:param _default_searcher: private parameter to assist testing - don't use
562
:return: an iterator of tuple sequences, one per path-name.
563
See _RulesSearcher.get_items for details on the tuple sequence.
565
searcher = self._get_rules_searcher(_default_searcher)
566
if searcher is not None:
567
if pref_names is not None:
568
for path in path_names:
569
yield searcher.get_selected_items(path, pref_names)
571
for path in path_names:
572
yield searcher.get_items(path)
575
def _get_rules_searcher(self, default_searcher):
576
"""Get the RulesSearcher for this tree given the default one."""
577
searcher = default_searcher
578
file_id = self.path2id(rules.RULES_TREE_FILENAME)
579
if file_id is not None:
580
ini_file = self.get_file(file_id)
581
searcher = rules._StackedRulesSearcher(
582
[rules._IniBasedRulesSearcher(ini_file), default_searcher])
538
586
class EmptyTree(Tree):