~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hashcache.py

  • Committer: Robert Collins
  • Date: 2005-10-06 22:15:52 UTC
  • mfrom: (1185.13.2)
  • mto: This revision was merged to the branch mainline in revision 1420.
  • Revision ID: robertc@robertcollins.net-20051006221552-9b15c96fa504e0ad
mergeĀ fromĀ upstream

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