/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-08 14:55:19 UTC
  • mfrom: (3530 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3532.
  • Revision ID: john@arbash-meinel.com-20080708145519-paqg4kjwbpgs2xmq
Merge bzr.dev 3530

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
import bzrlib
25
25
from bzrlib import (
 
26
    conflicts as _mod_conflicts,
26
27
    delta,
27
28
    osutils,
28
29
    revision as _mod_revision,
29
 
    conflicts as _mod_conflicts,
 
30
    rules,
30
31
    symbol_versioning,
31
32
    )
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.
178
179
 
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:
 
182
 
 
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
 
186
        grandchildren.
 
187
 
 
188
        For example, in the tree::
 
189
 
 
190
           a/
 
191
             b/
 
192
               c
 
193
             d/
 
194
               e
 
195
           f/
 
196
             g
 
197
 
 
198
        The yield order (ignoring root) would be::
 
199
          a, f, a/b, a/d, a/b/c, a/d/e, f/g
183
200
        """
184
201
        return self.inventory.iter_entries_by_dir(
185
202
            specific_file_ids=specific_file_ids)
254
271
        """
255
272
        raise NotImplementedError(self.get_file_mtime)
256
273
 
 
274
    def get_file_size(self, file_id):
 
275
        """Return the size of a file in bytes.
 
276
 
 
277
        This applies only to regular files.  If invoked on directories or
 
278
        symlinks, it will return None.
 
279
        :param file_id: The file-id of the file
 
280
        """
 
281
        raise NotImplementedError(self.get_file_size)
 
282
 
257
283
    def get_file_by_path(self, path):
258
284
        return self.get_file(self._inventory.path2id(path), path)
259
285
 
349
375
                                 last_revision_base)
350
376
 
351
377
    def _get_file_revision(self, file_id, vf, tree_revision):
 
378
        """Ensure that file_id, tree_revision is in vf to plan the merge."""
352
379
        def file_revision(revision_tree):
353
380
            revision_tree.lock_read()
354
381
            try:
363
390
                except:
364
391
                    yield self.repository.revision_tree(revision_id)
365
392
 
366
 
        if getattr(self, '_get_weave', None) is None:
 
393
        if getattr(self, '_repository', None) is None:
367
394
            last_revision = tree_revision
368
 
            parent_revisions = [file_revision(t) for t in iter_parent_trees()]
369
 
            vf.add_lines(last_revision, parent_revisions,
 
395
            parent_keys = [(file_id, file_revision(t)) for t in
 
396
                iter_parent_trees()]
 
397
            vf.add_lines((file_id, last_revision), parent_keys,
370
398
                         self.get_file(file_id).readlines())
371
399
            repo = self.branch.repository
372
 
            transaction = repo.get_transaction()
373
 
            base_vf = repo.weave_store.get_weave(file_id, transaction)
 
400
            base_vf = repo.texts
374
401
        else:
375
402
            last_revision = file_revision(self)
376
 
            base_vf = self._get_weave(file_id)
377
 
        vf.fallback_versionedfiles.append(base_vf)
 
403
            base_vf = self._repository.texts
 
404
        if base_vf not in vf.fallback_versionedfiles:
 
405
            vf.fallback_versionedfiles.append(base_vf)
378
406
        return last_revision
379
407
 
380
408
    inventory = property(_get_inventory,
423
451
        """
424
452
        return find_ids_across_trees(paths, [self] + list(trees), require_versioned)
425
453
 
 
454
    @symbol_versioning.deprecated_method(symbol_versioning.one_six)
426
455
    def print_file(self, file_id):
427
456
        """Print file with id `file_id` to stdout."""
428
457
        import sys
500
529
        """
501
530
        raise NotImplementedError(self.walkdirs)
502
531
 
 
532
    def iter_search_rules(self, path_names, pref_names=None,
 
533
        _default_searcher=rules._per_user_searcher):
 
534
        """Find the preferences for filenames in a tree.
 
535
 
 
536
        :param path_names: an iterable of paths to find attributes for.
 
537
          Paths are given relative to the root of the tree.
 
538
        :param pref_names: the list of preferences to lookup - None for all
 
539
        :param _default_searcher: private parameter to assist testing - don't use
 
540
        :return: an iterator of tuple sequences, one per path-name.
 
541
          See _RulesSearcher.get_items for details on the tuple sequence.
 
542
        """
 
543
        searcher = self._get_rules_searcher(_default_searcher)
 
544
        if searcher is not None:
 
545
            if pref_names is not None:
 
546
                for path in path_names:
 
547
                    yield searcher.get_selected_items(path, pref_names)
 
548
            else:
 
549
                for path in path_names:
 
550
                    yield searcher.get_items(path)
 
551
 
 
552
    @needs_read_lock
 
553
    def _get_rules_searcher(self, default_searcher):
 
554
        """Get the RulesSearcher for this tree given the default one."""
 
555
        searcher = default_searcher
 
556
        file_id = self.path2id(rules.RULES_TREE_FILENAME)
 
557
        if file_id is not None:
 
558
            ini_file = self.get_file(file_id)
 
559
            searcher = rules._StackedRulesSearcher(
 
560
                [rules._IniBasedRulesSearcher(ini_file), default_searcher])
 
561
        return searcher
 
562
 
503
563
 
504
564
class EmptyTree(Tree):
505
565
 
519
579
        return False
520
580
 
521
581
    def kind(self, file_id):
522
 
        assert self._inventory[file_id].kind == "directory"
523
582
        return "directory"
524
583
 
525
584
    def list_files(self, include_root=False):
568
627
        # what happened to the file that used to have
569
628
        # this name.  There are two possibilities: either it was
570
629
        # deleted entirely, or renamed.
571
 
        assert old_id
572
630
        if new_inv.has_id(old_id):
573
631
            return 'X', old_inv.id2path(old_id), new_inv.id2path(old_id)
574
632
        else:
895
953
            # the parent's path is necessarily known at this point.
896
954
            yield(file_id, (path, to_path), changed_content, versioned, parent,
897
955
                  name, kind, executable)
898
 
 
899
 
 
900
 
# This was deprecated before 0.12, but did not have an official warning
901
 
@symbol_versioning.deprecated_function(symbol_versioning.zero_twelve)
902
 
def RevisionTree(*args, **kwargs):
903
 
    """RevisionTree has moved to bzrlib.revisiontree.RevisionTree()
904
 
 
905
 
    Accessing it as bzrlib.tree.RevisionTree has been deprecated as of
906
 
    bzr 0.12.
907
 
    """
908
 
    from bzrlib.revisiontree import RevisionTree as _RevisionTree
909
 
    return _RevisionTree(*args, **kwargs)
910
 
 
911