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

  • Committer: Martin Pool
  • Date: 2005-05-17 09:05:11 UTC
  • Revision ID: mbp@sourcefrog.net-20050517090511-b026ebbb9060034c
- file-ids are stored as quoted-printable in the stat cache,
  so as to better handle any wierd values that may be present.
- more sanity checks on records read from stat cache

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
 
67
67
The SHA-1 is stored in memory as a hexdigest.
68
68
 
69
 
File names are written out as the quoted-printable encoding of their
70
 
UTF-8 representation.
 
69
File names and file-ids are written out as the quoted-printable
 
70
encoding of their UTF-8 representation.  (file-ids shouldn't contain
 
71
wierd characters, but it might happen.)
71
72
"""
72
73
 
73
74
# order of fields returned by fingerprint()
119
120
            
120
121
            if entry[SC_FILE_ID] in dangerfiles:
121
122
                continue                # changed too recently
122
 
            outf.write(entry[0])        # file id
 
123
            outf.write(b2a_qp(entry[0].encode('utf-8'))) # file id
123
124
            outf.write(' ')
124
125
            outf.write(entry[1])        # hex sha1
125
126
            outf.write(' ')
136
137
        
137
138
def load_cache(basedir):
138
139
    from sets import Set
 
140
    import re
139
141
    cache = {}
140
142
    seen_paths = Set()
141
143
 
 
144
    sha_re = re.compile(r'[a-f0-9]{40}')
 
145
 
142
146
    try:
143
147
        cachefn = os.path.join(basedir, '.bzr', 'stat-cache')
144
148
        cachefile = open(cachefn, 'rb')
153
157
    for l in cachefile:
154
158
        f = l.split(' ')
155
159
 
156
 
        file_id = f[0]
 
160
        file_id = a2b_qp(f[0]).decode('utf-8')
157
161
        if file_id in cache:
158
 
            raise BzrError("duplicated file_id in cache: {%s}" % file_id)
 
162
            raise BzrCheckError("duplicated file_id in cache: {%s}" % file_id)
 
163
 
 
164
        text_sha = f[1]
 
165
        if len(text_sha) != 40 or not sha_re.match(text_sha):
 
166
            raise BzrCheckError("invalid file SHA-1 in cache: %r" % text_sha)
159
167
        
160
168
        path = a2b_qp(f[2]).decode('utf-8')
161
169
        if path in seen_paths:
162
170
            raise BzrCheckError("duplicated path in cache: %r" % path)
163
171
        seen_paths.add(path)
164
172
        
165
 
        entry = (file_id, f[1], path) + tuple([long(x) for x in f[3:]])
 
173
        entry = (file_id, text_sha, path) + tuple([long(x) for x in f[3:]])
166
174
        if len(entry) != 8:
167
175
            raise ValueError("invalid statcache entry tuple %r" % entry)
168
176