/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/hashcache.py

Test the disk layout of format3 working trees.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
import os, stat, time
33
33
import sha
34
34
 
35
 
from bzrlib.osutils import sha_file, pathjoin
 
35
from bzrlib.osutils import sha_file, pathjoin, safe_unicode
36
36
from bzrlib.trace import mutter, warning
37
37
from bzrlib.atomicfile import AtomicFile
38
38
from bzrlib.errors import BzrError
94
94
    """
95
95
    needs_write = False
96
96
 
97
 
    def __init__(self, basedir, mode=None):
 
97
    def __init__(self, root, cache_file_name, mode=None):
98
98
        """Create a hash cache in base dir, and set the file mode to mode."""
99
 
        self.basedir = basedir
 
99
        self.root = safe_unicode(root)
100
100
        self.hit_count = 0
101
101
        self.miss_count = 0
102
102
        self.stat_count = 0
105
105
        self.update_count = 0
106
106
        self._cache = {}
107
107
        self._mode = mode
 
108
        self._cache_file_name = safe_unicode(cache_file_name)
108
109
 
109
110
    def cache_file_name(self):
110
 
        # FIXME: duplicate path logic here, this should be 
111
 
        # something like 'branch.controlfile'.
112
 
        return pathjoin(self.basedir, '.bzr', 'stat-cache')
 
111
        return self._cache_file_name
113
112
 
114
113
    def clear(self):
115
114
        """Discard all cached information.
119
118
            self.needs_write = True
120
119
            self._cache = {}
121
120
 
122
 
 
123
121
    def scan(self):
124
122
        """Scan all files and remove entries where the cache entry is obsolete.
125
123
        
132
130
        prep.sort()
133
131
        
134
132
        for inum, path, cache_entry in prep:
135
 
            abspath = pathjoin(self.basedir, path)
 
133
            abspath = pathjoin(self.root, path)
136
134
            fp = _fingerprint(abspath)
137
135
            self.stat_count += 1
138
136
            
148
146
    def get_sha1(self, path):
149
147
        """Return the sha1 of a file.
150
148
        """
151
 
        abspath = pathjoin(self.basedir, path)
 
149
        abspath = pathjoin(self.root, path)
152
150
        self.stat_count += 1
153
151
        file_fp = _fingerprint(abspath)
154
152