/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: Vincent Ladeuil
  • Date: 2011-04-11 09:38:59 UTC
  • mfrom: (5609.33.1 2.3)
  • mto: This revision was merged to the branch mainline in revision 5783.
  • Revision ID: v.ladeuil+lp@free.fr-20110411093859-0gyunr0tkvnoskrm
Merge 2.3 to trunk

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.
305
294
        """
306
295
        return osutils.split_lines(self.get_file_text(file_id, path))
307
296
 
 
297
    def get_file_sha1(self, file_id, path=None):
 
298
        """Return the SHA1 file for a file.
 
299
 
 
300
        :param file_id: The handle for this file.
 
301
        :param path: The path that this file can be found at.
 
302
            These must point to the same object.
 
303
        """
 
304
        raise NotImplementedError(self.get_file_sha1)
 
305
 
308
306
    def get_file_mtime(self, file_id, path=None):
309
307
        """Return the modification time for a file.
310
308
 
326
324
    def get_file_by_path(self, path):
327
325
        return self.get_file(self._inventory.path2id(path), path)
328
326
 
 
327
    def is_executable(self, file_id, path=None):
 
328
        """Check if a file is executable.
 
329
 
 
330
        :param file_id: The handle for this file.
 
331
        :param path: The path that this file can be found at.
 
332
            These must point to the same object.
 
333
        """
 
334
        raise NotImplementedError(self.is_executable)
 
335
 
329
336
    def iter_files_bytes(self, desired_files):
330
337
        """Iterate through file contents.
331
338
 
427
434
                        elif child_base.lower() == lelt:
428
435
                            cur_id = child
429
436
                            new_path = osutils.pathjoin(cur_path, child_base)
430
 
                    except NoSuchId:
 
437
                    except errors.NoSuchId:
431
438
                        # before a change is committed we can see this error...
432
439
                        continue
433
440
                if new_path:
520
527
            parent_keys = [(file_id, self._file_revision(t, file_id)) for t in
521
528
                self._iter_parent_trees()]
522
529
            vf.add_lines((file_id, last_revision), parent_keys,
523
 
                         self.get_file(file_id).readlines())
 
530
                         self.get_file_lines(file_id))
524
531
            repo = self.branch.repository
525
532
            base_vf = repo.texts
526
533
        else:
536
543
    def _check_retrieved(self, ie, f):
537
544
        if not __debug__:
538
545
            return
539
 
        fp = fingerprint_file(f)
 
546
        fp = osutils.fingerprint_file(f)
540
547
        f.seek(0)
541
548
 
542
549
        if ie.text_size is not None:
543
550
            if ie.text_size != fp['size']:
544
 
                raise BzrError("mismatched size for file %r in %r" % (ie.file_id, self._store),
 
551
                raise errors.BzrError(
 
552
                        "mismatched size for file %r in %r" %
 
553
                        (ie.file_id, self._store),
545
554
                        ["inventory expects %d bytes" % ie.text_size,
546
555
                         "file is actually %d bytes" % fp['size'],
547
556
                         "store is probably damaged/corrupt"])
548
557
 
549
558
        if ie.text_sha1 != fp['sha1']:
550
 
            raise BzrError("wrong SHA-1 for file %r in %r" % (ie.file_id, self._store),
 
559
            raise errors.BzrError("wrong SHA-1 for file %r in %r" %
 
560
                    (ie.file_id, self._store),
551
561
                    ["inventory expects %s" % ie.text_sha1,
552
562
                     "file is actually %s" % fp['sha1'],
553
563
                     "store is probably damaged/corrupt"])
582
592
            yield child.file_id
583
593
 
584
594
    def lock_read(self):
 
595
        """Lock this tree for multiple read only operations.
 
596
        
 
597
        :return: A bzrlib.lock.LogicalLockResult.
 
598
        """
585
599
        pass
586
600
 
587
601
    def revision_tree(self, revision_id):
676
690
        prefs = self.iter_search_rules([path], filter_pref_names).next()
677
691
        stk = filters._get_filter_stack_for(prefs)
678
692
        if 'filters' in debug.debug_flags:
679
 
            note("*** %s content-filter: %s => %r" % (path,prefs,stk))
 
693
            trace.note("*** %s content-filter: %s => %r" % (path,prefs,stk))
680
694
        return stk
681
695
 
682
696
    def _content_filter_stack_provider(self):
774
788
    return 'wtf?'
775
789
 
776
790
 
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
791
def find_ids_across_trees(filenames, trees, require_versioned=True):
789
792
    """Find the ids corresponding to specified filenames.
790
793
 
987
990
            # All files are unversioned, so just return an empty delta
988
991
            # _compare_trees would think we want a complete delta
989
992
            result = delta.TreeDelta()
990
 
            fake_entry = InventoryFile('unused', 'unused', 'unused')
 
993
            fake_entry = inventory.InventoryFile('unused', 'unused', 'unused')
991
994
            result.unversioned = [(path, None,
992
995
                self.target._comparison_data(fake_entry, path)[0]) for path in
993
996
                specific_files]
1058
1061
                                     self.target.extras()
1059
1062
                if specific_files is None or
1060
1063
                    osutils.is_inside_any(specific_files, p)])
1061
 
            all_unversioned = deque(all_unversioned)
 
1064
            all_unversioned = collections.deque(all_unversioned)
1062
1065
        else:
1063
 
            all_unversioned = deque()
 
1066
            all_unversioned = collections.deque()
1064
1067
        to_paths = {}
1065
1068
        from_entries_by_dir = list(self.source.iter_entries_by_dir(
1066
1069
            specific_file_ids=specific_file_ids))
1072
1075
        # the unversioned path lookup only occurs on real trees - where there
1073
1076
        # can be extras. So the fake_entry is solely used to look up
1074
1077
        # executable it values when execute is not supported.
1075
 
        fake_entry = InventoryFile('unused', 'unused', 'unused')
 
1078
        fake_entry = inventory.InventoryFile('unused', 'unused', 'unused')
1076
1079
        for target_path, target_entry in to_entries_by_dir:
1077
1080
            while (all_unversioned and
1078
1081
                all_unversioned[0][0] < target_path.split('/')):
1126
1129
            if file_id in to_paths:
1127
1130
                # already returned
1128
1131
                continue
1129
 
            if file_id not in self.target.all_file_ids():
 
1132
            if not self.target.has_id(file_id):
1130
1133
                # common case - paths we have not emitted are not present in
1131
1134
                # target.
1132
1135
                to_path = None