~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hashcache.py

  • Committer: Martin Pool
  • Date: 2005-10-04 02:27:27 UTC
  • mfrom: (1399)
  • mto: (1185.13.3)
  • mto: This revision was merged to the branch mainline in revision 1400.
  • Revision ID: mbp@sourcefrog.net-20051004022727-aee7064c62e039a7
[merge] merge robertc's format5 integration

 - test status on specific files
 - track x bit
 - baz2bzr fixes
 - remotebranch fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
CACHE_HEADER = "### bzr hashcache v5\n"
31
31
 
32
32
import os, stat, time
 
33
import sha
33
34
 
34
35
from bzrlib.osutils import sha_file
35
36
from bzrlib.trace import mutter, warning
36
37
from bzrlib.atomicfile import AtomicFile
37
38
 
38
39
 
39
 
 
 
40
FP_MODE_COLUMN = 5
40
41
 
41
42
def _fingerprint(abspath):
42
43
    try:
51
52
    # we discard any high precision because it's not reliable; perhaps we
52
53
    # could do better on some systems?
53
54
    return (fs.st_size, long(fs.st_mtime),
54
 
            long(fs.st_ctime), fs.st_ino, fs.st_dev)
 
55
            long(fs.st_ctime), fs.st_ino, fs.st_dev, fs.st_mode)
55
56
 
56
57
 
57
58
class HashCache(object):
164
165
            return cache_sha1
165
166
        
166
167
        self.miss_count += 1
167
 
        digest = sha_file(file(abspath, 'rb', buffering=65000))
 
168
 
 
169
 
 
170
        mode = file_fp[FP_MODE_COLUMN]
 
171
        if stat.S_ISREG(mode):
 
172
            digest = sha_file(file(abspath, 'rb', buffering=65000))
 
173
        elif stat.S_ISLNK(mode):
 
174
            link_target = os.readlink(abspath)
 
175
            digest = sha.new(os.readlink(abspath)).hexdigest()
 
176
        else:
 
177
            raise BzrError("file %r: unknown file stat mode: %o"%(abspath,mode))
168
178
 
169
179
        now = int(time.time())
170
180
        if file_fp[1] >= now or file_fp[2] >= now:
180
190
            self.update_count += 1
181
191
            self.needs_write = True
182
192
            self._cache[path] = (digest, file_fp)
183
 
        
184
193
        return digest
185
194
        
186
 
 
187
 
 
188
 
 
189
195
    def write(self):
190
196
        """Write contents of cache to file."""
191
197
        outf = AtomicFile(self.cache_file_name(), 'wb')
244
250
 
245
251
            pos += 3
246
252
            fields = l[pos:].split(' ')
247
 
            if len(fields) != 6:
 
253
            if len(fields) != 7:
248
254
                warning("bad line in hashcache: %r" % l)
249
255
                continue
250
256