/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: Martin Pool
  • Date: 2011-04-19 01:53:52 UTC
  • mto: This revision was merged to the branch mainline in revision 5802.
  • Revision ID: mbp@sourcefrog.net-20110419015352-s1vdqlhuv49482gj
Reinstate checkin alias for commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
"""
19
19
 
20
20
import os
21
 
from collections import deque
22
 
 
23
 
import bzrlib
 
21
 
 
22
from bzrlib.lazy_import import lazy_import
 
23
lazy_import(globals(), """
 
24
import collections
 
25
 
24
26
from bzrlib import (
25
27
    conflicts as _mod_conflicts,
26
28
    debug,
27
29
    delta,
 
30
    errors,
28
31
    filters,
 
32
    inventory,
29
33
    osutils,
30
34
    revision as _mod_revision,
31
35
    rules,
 
36
    trace,
32
37
    )
 
38
""")
 
39
 
33
40
from bzrlib.decorators import needs_read_lock
34
 
from bzrlib.errors import BzrError, NoSuchId
35
 
from bzrlib import errors
36
 
from bzrlib.inventory import InventoryFile
37
41
from bzrlib.inter import InterObject
38
 
from bzrlib.osutils import fingerprint_file
39
 
from bzrlib.symbol_versioning import deprecated_function, deprecated_in
40
 
from bzrlib.trace import note
41
42
 
42
43
 
43
44
class Tree(object):
157
158
        """
158
159
        return self.inventory.id2path(file_id)
159
160
 
160
 
    def is_control_filename(self, filename):
161
 
        """True if filename is the name of a control file in this tree.
162
 
 
163
 
        :param filename: A filename within the tree. This is a relative path
164
 
        from the root of this tree.
165
 
 
166
 
        This is true IF and ONLY IF the filename is part of the meta data
167
 
        that bzr controls in this tree. I.E. a random .bzr directory placed
168
 
        on disk will not be a control file for this tree.
169
 
        """
170
 
        return self.bzrdir.is_control_filename(filename)
171
 
 
172
161
    @needs_read_lock
173
162
    def iter_entries_by_dir(self, specific_file_ids=None, yield_parents=False):
174
163
        """Walk the tree in 'by_dir' order.
427
416
                        elif child_base.lower() == lelt:
428
417
                            cur_id = child
429
418
                            new_path = osutils.pathjoin(cur_path, child_base)
430
 
                    except NoSuchId:
 
419
                    except errors.NoSuchId:
431
420
                        # before a change is committed we can see this error...
432
421
                        continue
433
422
                if new_path:
520
509
            parent_keys = [(file_id, self._file_revision(t, file_id)) for t in
521
510
                self._iter_parent_trees()]
522
511
            vf.add_lines((file_id, last_revision), parent_keys,
523
 
                         self.get_file(file_id).readlines())
 
512
                         self.get_file_lines(file_id))
524
513
            repo = self.branch.repository
525
514
            base_vf = repo.texts
526
515
        else:
536
525
    def _check_retrieved(self, ie, f):
537
526
        if not __debug__:
538
527
            return
539
 
        fp = fingerprint_file(f)
 
528
        fp = osutils.fingerprint_file(f)
540
529
        f.seek(0)
541
530
 
542
531
        if ie.text_size is not None:
543
532
            if ie.text_size != fp['size']:
544
 
                raise BzrError("mismatched size for file %r in %r" % (ie.file_id, self._store),
 
533
                raise errors.BzrError(
 
534
                        "mismatched size for file %r in %r" %
 
535
                        (ie.file_id, self._store),
545
536
                        ["inventory expects %d bytes" % ie.text_size,
546
537
                         "file is actually %d bytes" % fp['size'],
547
538
                         "store is probably damaged/corrupt"])
548
539
 
549
540
        if ie.text_sha1 != fp['sha1']:
550
 
            raise BzrError("wrong SHA-1 for file %r in %r" % (ie.file_id, self._store),
 
541
            raise errors.BzrError("wrong SHA-1 for file %r in %r" %
 
542
                    (ie.file_id, self._store),
551
543
                    ["inventory expects %s" % ie.text_sha1,
552
544
                     "file is actually %s" % fp['sha1'],
553
545
                     "store is probably damaged/corrupt"])
582
574
            yield child.file_id
583
575
 
584
576
    def lock_read(self):
 
577
        """Lock this tree for multiple read only operations.
 
578
        
 
579
        :return: A bzrlib.lock.LogicalLockResult.
 
580
        """
585
581
        pass
586
582
 
587
583
    def revision_tree(self, revision_id):
676
672
        prefs = self.iter_search_rules([path], filter_pref_names).next()
677
673
        stk = filters._get_filter_stack_for(prefs)
678
674
        if 'filters' in debug.debug_flags:
679
 
            note("*** %s content-filter: %s => %r" % (path,prefs,stk))
 
675
            trace.note("*** %s content-filter: %s => %r" % (path,prefs,stk))
680
676
        return stk
681
677
 
682
678
    def _content_filter_stack_provider(self):
774
770
    return 'wtf?'
775
771
 
776
772
 
777
 
@deprecated_function(deprecated_in((1, 9, 0)))
778
 
def find_renames(old_inv, new_inv):
779
 
    for file_id in old_inv:
780
 
        if file_id not in new_inv:
781
 
            continue
782
 
        old_name = old_inv.id2path(file_id)
783
 
        new_name = new_inv.id2path(file_id)
784
 
        if old_name != new_name:
785
 
            yield (old_name, new_name)
786
 
 
787
 
 
788
773
def find_ids_across_trees(filenames, trees, require_versioned=True):
789
774
    """Find the ids corresponding to specified filenames.
790
775
 
987
972
            # All files are unversioned, so just return an empty delta
988
973
            # _compare_trees would think we want a complete delta
989
974
            result = delta.TreeDelta()
990
 
            fake_entry = InventoryFile('unused', 'unused', 'unused')
 
975
            fake_entry = inventory.InventoryFile('unused', 'unused', 'unused')
991
976
            result.unversioned = [(path, None,
992
977
                self.target._comparison_data(fake_entry, path)[0]) for path in
993
978
                specific_files]
1058
1043
                                     self.target.extras()
1059
1044
                if specific_files is None or
1060
1045
                    osutils.is_inside_any(specific_files, p)])
1061
 
            all_unversioned = deque(all_unversioned)
 
1046
            all_unversioned = collections.deque(all_unversioned)
1062
1047
        else:
1063
 
            all_unversioned = deque()
 
1048
            all_unversioned = collections.deque()
1064
1049
        to_paths = {}
1065
1050
        from_entries_by_dir = list(self.source.iter_entries_by_dir(
1066
1051
            specific_file_ids=specific_file_ids))
1072
1057
        # the unversioned path lookup only occurs on real trees - where there
1073
1058
        # can be extras. So the fake_entry is solely used to look up
1074
1059
        # executable it values when execute is not supported.
1075
 
        fake_entry = InventoryFile('unused', 'unused', 'unused')
 
1060
        fake_entry = inventory.InventoryFile('unused', 'unused', 'unused')
1076
1061
        for target_path, target_entry in to_entries_by_dir:
1077
1062
            while (all_unversioned and
1078
1063
                all_unversioned[0][0] < target_path.split('/')):
1126
1111
            if file_id in to_paths:
1127
1112
                # already returned
1128
1113
                continue
1129
 
            if file_id not in self.target.all_file_ids():
 
1114
            if not self.target.has_id(file_id):
1130
1115
                # common case - paths we have not emitted are not present in
1131
1116
                # target.
1132
1117
                to_path = None