Mercurial > hgsubversion
comparison hgsubversion/maps.py @ 826:8794302f3614
maps: s/hash/ha/ and s/map/m/ to avoid hiding Python builtins
Also rename unused sbuf -> _sbuf.
author | Yonggang Luo <luoyonggang@gmail.com> |
---|---|
date | Sat, 01 Oct 2011 00:50:10 +0800 |
parents | 033b86e0f56d |
children | 5061640fe5bc |
comparison
equal
deleted
inserted
replaced
825:c3450512237d | 826:8794302f3614 |
---|---|
134 return | 134 return |
135 elif ver != self.VERSION: | 135 elif ver != self.VERSION: |
136 print 'tagmap too new -- please upgrade' | 136 print 'tagmap too new -- please upgrade' |
137 raise NotImplementedError | 137 raise NotImplementedError |
138 for l in f: | 138 for l in f: |
139 hash, revision, tag = l.split(' ', 2) | 139 ha, revision, tag = l.split(' ', 2) |
140 revision = int(revision) | 140 revision = int(revision) |
141 tag = tag[:-1] | 141 tag = tag[:-1] |
142 if self.endrev is not None and revision > self.endrev: | 142 if self.endrev is not None and revision > self.endrev: |
143 break | 143 break |
144 if not tag: | 144 if not tag: |
145 continue | 145 continue |
146 dict.__setitem__(self, tag, node.bin(hash)) | 146 dict.__setitem__(self, tag, node.bin(ha)) |
147 f.close() | 147 f.close() |
148 | 148 |
149 def _write(self): | 149 def _write(self): |
150 assert self.endrev is None | 150 assert self.endrev is None |
151 f = open(self.path, 'w') | 151 f = open(self.path, 'w') |
166 raise KeyError() | 166 raise KeyError() |
167 | 167 |
168 def __setitem__(self, tag, info): | 168 def __setitem__(self, tag, info): |
169 if not tag: | 169 if not tag: |
170 raise hgutil.Abort('tag cannot be empty') | 170 raise hgutil.Abort('tag cannot be empty') |
171 hash, revision = info | 171 ha, revision = info |
172 f = open(self.path, 'a') | 172 f = open(self.path, 'a') |
173 f.write('%s %s %s\n' % (node.hex(hash), revision, tag)) | 173 f.write('%s %s %s\n' % (node.hex(ha), revision, tag)) |
174 f.close() | 174 f.close() |
175 dict.__setitem__(self, tag, hash) | 175 dict.__setitem__(self, tag, ha) |
176 | 176 |
177 | 177 |
178 class RevMap(dict): | 178 class RevMap(dict): |
179 | 179 |
180 VERSION = 1 | 180 VERSION = 1 |
219 ver = int(f.readline()) | 219 ver = int(f.readline()) |
220 if ver != self.VERSION: | 220 if ver != self.VERSION: |
221 print 'revmap too new -- please upgrade' | 221 print 'revmap too new -- please upgrade' |
222 raise NotImplementedError | 222 raise NotImplementedError |
223 for l in f: | 223 for l in f: |
224 revnum, hash, branch = l.split(' ', 2) | 224 revnum, ha, branch = l.split(' ', 2) |
225 if branch == '\n': | 225 if branch == '\n': |
226 branch = None | 226 branch = None |
227 else: | 227 else: |
228 branch = branch[:-1] | 228 branch = branch[:-1] |
229 revnum = int(revnum) | 229 revnum = int(revnum) |
230 if revnum > self.youngest or not self.youngest: | 230 if revnum > self.youngest or not self.youngest: |
231 self.youngest = revnum | 231 self.youngest = revnum |
232 if revnum < self.oldest or not self.oldest: | 232 if revnum < self.oldest or not self.oldest: |
233 self.oldest = revnum | 233 self.oldest = revnum |
234 dict.__setitem__(self, (revnum, branch), node.bin(hash)) | 234 dict.__setitem__(self, (revnum, branch), node.bin(ha)) |
235 f.close() | 235 f.close() |
236 | 236 |
237 def _write(self): | 237 def _write(self): |
238 f = open(self.path, 'w') | 238 f = open(self.path, 'w') |
239 f.write('%s\n' % self.VERSION) | 239 f.write('%s\n' % self.VERSION) |
240 f.close() | 240 f.close() |
241 | 241 |
242 def __setitem__(self, key, hash): | 242 def __setitem__(self, key, ha): |
243 revnum, branch = key | 243 revnum, branch = key |
244 f = open(self.path, 'a') | 244 f = open(self.path, 'a') |
245 b = branch or '' | 245 b = branch or '' |
246 f.write(str(revnum) + ' ' + node.hex(hash) + ' ' + b + '\n') | 246 f.write(str(revnum) + ' ' + node.hex(ha) + ' ' + b + '\n') |
247 f.close() | 247 f.close() |
248 if revnum > self.youngest or not self.youngest: | 248 if revnum > self.youngest or not self.youngest: |
249 self.youngest = revnum | 249 self.youngest = revnum |
250 if revnum < self.oldest or not self.oldest: | 250 if revnum < self.oldest or not self.oldest: |
251 self.oldest = revnum | 251 self.oldest = revnum |
252 dict.__setitem__(self, (revnum, branch), hash) | 252 dict.__setitem__(self, (revnum, branch), ha) |
253 | 253 |
254 | 254 |
255 class FileMap(object): | 255 class FileMap(object): |
256 | 256 |
257 def __init__(self, repo): | 257 def __init__(self, repo): |
267 e = len(name) | 267 e = len(name) |
268 while e != -1: | 268 while e != -1: |
269 yield name[:e], name[e+1:] | 269 yield name[:e], name[e+1:] |
270 e = name.rfind('/', 0, e) | 270 e = name.rfind('/', 0, e) |
271 | 271 |
272 def check(self, map, path): | 272 def check(self, m, path): |
273 map = getattr(self, map) | 273 m = getattr(self, m) |
274 for pre, suf in self._rpairs(path): | 274 for pre, _suf in self._rpairs(path): |
275 if pre not in map: | 275 if pre not in m: |
276 continue | 276 continue |
277 return map[pre] | 277 return m[pre] |
278 return None | 278 return None |
279 | 279 |
280 def __contains__(self, path): | 280 def __contains__(self, path): |
281 if len(self.include) and len(path): | 281 if len(self.include) and len(path): |
282 inc = self.check('include', path) | 282 inc = self.check('include', path) |
292 | 292 |
293 # Needed so empty filemaps are false | 293 # Needed so empty filemaps are false |
294 def __len__(self): | 294 def __len__(self): |
295 return len(self.include) + len(self.exclude) | 295 return len(self.include) + len(self.exclude) |
296 | 296 |
297 def add(self, fn, map, path): | 297 def add(self, fn, m, path): |
298 mapping = getattr(self, map) | 298 mapping = getattr(self, m) |
299 if path in mapping: | 299 if path in mapping: |
300 msg = 'duplicate %s entry in %s: "%s"\n' | 300 msg = 'duplicate %s entry in %s: "%s"\n' |
301 self.ui.status(msg % (map, fn, path)) | 301 self.ui.status(msg % (m, fn, path)) |
302 return | 302 return |
303 bits = map.strip('e'), path | 303 bits = m.strip('e'), path |
304 self.ui.debug('%sing %s\n' % bits) | 304 self.ui.debug('%sing %s\n' % bits) |
305 mapping[path] = path | 305 mapping[path] = path |
306 | 306 |
307 def load(self, fn): | 307 def load(self, fn): |
308 self.ui.note('reading file map from %s\n' % fn) | 308 self.ui.note('reading file map from %s\n' % fn) |