~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hashcache.py

  • Committer: Robert Collins
  • Date: 2006-01-05 22:30:59 UTC
  • mto: (1534.1.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1536.
  • Revision ID: robertc@robertcollins.net-20060105223059-a8b64f7b47cf12fb
 * bzrlib.osutils.safe_unicode now exists to provide parameter coercion
   for functions that need unicode strings. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
from bzrlib.osutils import sha_file
36
36
from bzrlib.trace import mutter, warning
37
37
from bzrlib.atomicfile import AtomicFile
 
38
from bzrlib.osutils import pathjoin
38
39
 
39
40
 
40
41
FP_MODE_COLUMN = 5
101
102
        self.update_count = 0
102
103
        self._cache = {}
103
104
 
104
 
 
105
105
    def cache_file_name(self):
106
 
        return os.sep.join([self.basedir, '.bzr', 'stat-cache'])
107
 
 
108
 
 
109
 
 
 
106
        # FIXME: duplicate path logic here, this should be 
 
107
        # something like 'branch.controlfile'.
 
108
        return pathjoin(self.basedir, '.bzr', 'stat-cache')
110
109
 
111
110
    def clear(self):
112
111
        """Discard all cached information.
127
126
        prep.sort()
128
127
        
129
128
        for inum, path, cache_entry in prep:
130
 
            abspath = os.sep.join([self.basedir, path])
 
129
            abspath = pathjoin(self.basedir, path)
131
130
            fp = _fingerprint(abspath)
132
131
            self.stat_count += 1
133
132
            
143
142
    def get_sha1(self, path):
144
143
        """Return the sha1 of a file.
145
144
        """
146
 
        abspath = os.sep.join([self.basedir, path])
 
145
        abspath = pathjoin(self.basedir, path)
147
146
        self.stat_count += 1
148
147
        file_fp = _fingerprint(abspath)
149
148
        
212
211
        finally:
213
212
            if not outf.closed:
214
213
                outf.abort()
215
 
        
216
 
 
217
214
 
218
215
    def read(self):
219
216
        """Reinstate cache from file.
228
225
        try:
229
226
            inf = file(fn, 'rb', buffering=65000)
230
227
        except IOError, e:
231
 
            mutter("failed to open %s: %s" % (fn, e))
 
228
            mutter("failed to open %s: %s", fn, e)
232
229
            # better write it now so it is valid
233
230
            self.needs_write = True
234
231
            return
236
233
 
237
234
        hdr = inf.readline()
238
235
        if hdr != CACHE_HEADER:
239
 
            mutter('cache header marker not found at top of %s; discarding cache'
240
 
                   % fn)
 
236
            mutter('cache header marker not found at top of %s;'
 
237
                   ' discarding cache', fn)
241
238
            self.needs_write = True
242
239
            return
243
240