/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

1st cut merge of bzr.dev r3907

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
from bzrlib.inter import InterObject
40
40
from bzrlib.osutils import fingerprint_file
41
41
import bzrlib.revision
42
 
from bzrlib.trace import note
 
42
from bzrlib.symbol_versioning import deprecated_function, deprecated_in
 
43
from bzrlib.trace import mutter, note
43
44
 
44
45
 
45
46
class Tree(object):
134
135
    def has_id(self, file_id):
135
136
        return self.inventory.has_id(file_id)
136
137
 
137
 
    __contains__ = has_id
 
138
    def __contains__(self, file_id):
 
139
        return self.has_id(file_id)
138
140
 
139
141
    def has_or_had_id(self, file_id):
140
142
        if file_id == self.inventory.root.file_id:
264
266
        """
265
267
        raise NotImplementedError(self.get_file)
266
268
 
 
269
    def get_file_text(self, file_id, path=None):
 
270
        """Return the byte content of a file.
 
271
 
 
272
        :param file_id: The file_id of the file.
 
273
        :param path: The path of the file.
 
274
        If both file_id and path are supplied, an implementation may use
 
275
        either one.
 
276
        """
 
277
        my_file = self.get_file(file_id, path)
 
278
        try:
 
279
            return my_file.read()
 
280
        finally:
 
281
            my_file.close()
 
282
 
 
283
    def get_file_lines(self, file_id, path=None):
 
284
        """Return the content of a file, as lines.
 
285
 
 
286
        :param file_id: The file_id of the file.
 
287
        :param path: The path of the file.
 
288
        If both file_id and path are supplied, an implementation may use
 
289
        either one.
 
290
        """
 
291
        return osutils.split_lines(self.get_file_text(file_id, path))
 
292
 
267
293
    def get_file_mtime(self, file_id, path=None):
268
294
        """Return the modification time for a file.
269
295
 
470
496
        """
471
497
        return find_ids_across_trees(paths, [self] + list(trees), require_versioned)
472
498
 
 
499
    def iter_children(self, file_id):
 
500
        entry = self.iter_entries_by_dir([file_id]).next()[1]
 
501
        for child in getattr(entry, 'children', {}).itervalues():
 
502
            yield child.file_id
 
503
 
473
504
    @symbol_versioning.deprecated_method(symbol_versioning.one_six)
474
505
    def print_file(self, file_id):
475
506
        """Print file with id `file_id` to stdout."""
595
626
    def _get_rules_searcher(self, default_searcher):
596
627
        """Get the RulesSearcher for this tree given the default one."""
597
628
        searcher = default_searcher
598
 
        ini_file = self.get_special_file("rules")
599
 
        if ini_file is not None:
600
 
            searcher = rules._StackedRulesSearcher(
601
 
                [rules._IniBasedRulesSearcher(ini_file), default_searcher])
602
629
        return searcher
603
630
 
604
631
 
685
712
    return 'wtf?'
686
713
 
687
714
    
688
 
 
 
715
@deprecated_function(deprecated_in((1, 9, 0)))
689
716
def find_renames(old_inv, new_inv):
690
717
    for file_id in old_inv:
691
718
        if file_id not in new_inv:
694
721
        new_name = new_inv.id2path(file_id)
695
722
        if old_name != new_name:
696
723
            yield (old_name, new_name)
697
 
            
 
724
 
698
725
 
699
726
def find_ids_across_trees(filenames, trees, require_versioned=True):
700
727
    """Find the ids corresponding to specified filenames.
761
788
            for tree in trees:
762
789
                if not tree.has_id(file_id):
763
790
                    continue
764
 
                entry = tree.inventory[file_id]
765
 
                for child in getattr(entry, 'children', {}).itervalues():
766
 
                    if child.file_id not in interesting_ids:
767
 
                        new_pending.add(child.file_id)
 
791
                for child_id in tree.iter_children(file_id):
 
792
                    if child_id not in interesting_ids:
 
793
                        new_pending.add(child_id)
768
794
        interesting_ids.update(new_pending)
769
795
        pending = new_pending
770
796
    return interesting_ids
873
899
        else:
874
900
            all_unversioned = deque()
875
901
        to_paths = {}
876
 
        from_entries_by_dir = list(self.source.inventory.iter_entries_by_dir(
 
902
        from_entries_by_dir = list(self.source.iter_entries_by_dir(
877
903
            specific_file_ids=specific_file_ids))
878
904
        from_data = dict((e.file_id, (p, e)) for p, e in from_entries_by_dir)
879
 
        to_entries_by_dir = list(self.target.inventory.iter_entries_by_dir(
 
905
        to_entries_by_dir = list(self.target.iter_entries_by_dir(
880
906
            specific_file_ids=specific_file_ids))
881
907
        num_entries = len(from_entries_by_dir) + len(to_entries_by_dir)
882
908
        entry_count = 0
970
996
            if file_id in to_paths:
971
997
                # already returned
972
998
                continue
973
 
            if not file_id in self.target.inventory:
 
999
            if not file_id in self.target.all_file_ids():
974
1000
                # common case - paths we have not emitted are not present in
975
1001
                # target.
976
1002
                to_path = None
986
1012
                self.source._comparison_data(from_entry, path)
987
1013
            kind = (from_kind, None)
988
1014
            executable = (from_executable, None)
989
 
            changed_content = True
 
1015
            changed_content = from_kind is not None
990
1016
            # the parent's path is necessarily known at this point.
991
1017
            yield(file_id, (path, to_path), changed_content, versioned, parent,
992
1018
                  name, kind, executable)