comparison mercurial/branchmap.py @ 25660:328739ea70c3

global: mass rewrite to use modern exception syntax Python 2.6 introduced the "except type as instance" syntax, replacing the "except type, instance" syntax that came before. Python 3 dropped support for the latter syntax. Since we no longer support Python 2.4 or 2.5, we have no need to continue supporting the "except type, instance". This patch mass rewrites the exception syntax to be Python 2.6+ and Python 3 compatible. This patch was produced by running `2to3 -f except -w -n .`.
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 23 Jun 2015 22:20:08 -0700
parents 38117278f295
children 47f36e050c2e
comparison
equal deleted inserted replaced
25659:d60678a567a9 25660:328739ea70c3
53 partial.setdefault(label, []).append(node) 53 partial.setdefault(label, []).append(node)
54 if state == 'c': 54 if state == 'c':
55 partial._closednodes.add(node) 55 partial._closednodes.add(node)
56 except KeyboardInterrupt: 56 except KeyboardInterrupt:
57 raise 57 raise
58 except Exception, inst: 58 except Exception as inst:
59 if repo.ui.debugflag: 59 if repo.ui.debugflag:
60 msg = 'invalid branchheads cache' 60 msg = 'invalid branchheads cache'
61 if repo.filtername is not None: 61 if repo.filtername is not None:
62 msg += ' (%s)' % repo.filtername 62 msg += ' (%s)' % repo.filtername
63 msg += ': %s\n' 63 msg += ': %s\n'
201 encoding.fromlocal(label))) 201 encoding.fromlocal(label)))
202 f.close() 202 f.close()
203 repo.ui.log('branchcache', 203 repo.ui.log('branchcache',
204 'wrote %s branch cache with %d labels and %d nodes\n', 204 'wrote %s branch cache with %d labels and %d nodes\n',
205 repo.filtername, len(self), nodecount) 205 repo.filtername, len(self), nodecount)
206 except (IOError, OSError, util.Abort), inst: 206 except (IOError, OSError, util.Abort) as inst:
207 repo.ui.debug("couldn't write branch cache: %s\n" % inst) 207 repo.ui.debug("couldn't write branch cache: %s\n" % inst)
208 # Abort may be raise by read only opener 208 # Abort may be raise by read only opener
209 pass 209 pass
210 210
211 def update(self, repo, revgen): 211 def update(self, repo, revgen):
313 self._rbcsnameslen = 0 313 self._rbcsnameslen = 0
314 try: 314 try:
315 bndata = repo.vfs.read(_rbcnames) 315 bndata = repo.vfs.read(_rbcnames)
316 self._rbcsnameslen = len(bndata) # for verification before writing 316 self._rbcsnameslen = len(bndata) # for verification before writing
317 self._names = [encoding.tolocal(bn) for bn in bndata.split('\0')] 317 self._names = [encoding.tolocal(bn) for bn in bndata.split('\0')]
318 except (IOError, OSError), inst: 318 except (IOError, OSError) as inst:
319 if readonly: 319 if readonly:
320 # don't try to use cache - fall back to the slow path 320 # don't try to use cache - fall back to the slow path
321 self.branchinfo = self._branchinfo 321 self.branchinfo = self._branchinfo
322 322
323 if self._names: 323 if self._names:
324 try: 324 try:
325 data = repo.vfs.read(_rbcrevs) 325 data = repo.vfs.read(_rbcrevs)
326 self._rbcrevs.fromstring(data) 326 self._rbcrevs.fromstring(data)
327 except (IOError, OSError), inst: 327 except (IOError, OSError) as inst:
328 repo.ui.debug("couldn't read revision branch cache: %s\n" % 328 repo.ui.debug("couldn't read revision branch cache: %s\n" %
329 inst) 329 inst)
330 # remember number of good records on disk 330 # remember number of good records on disk
331 self._rbcrevslen = min(len(self._rbcrevs) // _rbcrecsize, 331 self._rbcrevslen = min(len(self._rbcrevs) // _rbcrecsize,
332 len(repo.changelog)) 332 len(repo.changelog))
416 f = repo.vfs.open(_rbcnames, 'wb') 416 f = repo.vfs.open(_rbcnames, 'wb')
417 f.write('\0'.join(encoding.fromlocal(b) 417 f.write('\0'.join(encoding.fromlocal(b)
418 for b in self._names[self._rbcnamescount:])) 418 for b in self._names[self._rbcnamescount:]))
419 self._rbcsnameslen = f.tell() 419 self._rbcsnameslen = f.tell()
420 f.close() 420 f.close()
421 except (IOError, OSError, util.Abort), inst: 421 except (IOError, OSError, util.Abort) as inst:
422 repo.ui.debug("couldn't write revision branch cache names: " 422 repo.ui.debug("couldn't write revision branch cache names: "
423 "%s\n" % inst) 423 "%s\n" % inst)
424 return 424 return
425 self._rbcnamescount = len(self._names) 425 self._rbcnamescount = len(self._names)
426 426
434 f.seek(start) 434 f.seek(start)
435 f.truncate() 435 f.truncate()
436 end = revs * _rbcrecsize 436 end = revs * _rbcrecsize
437 f.write(self._rbcrevs[start:end]) 437 f.write(self._rbcrevs[start:end])
438 f.close() 438 f.close()
439 except (IOError, OSError, util.Abort), inst: 439 except (IOError, OSError, util.Abort) as inst:
440 repo.ui.debug("couldn't write revision branch cache: %s\n" % 440 repo.ui.debug("couldn't write revision branch cache: %s\n" %
441 inst) 441 inst)
442 return 442 return
443 self._rbcrevslen = revs 443 self._rbcrevslen = revs