diff --git a/contrib/check-code.py b/contrib/check-code.py --- a/contrib/check-code.py +++ b/contrib/check-code.py @@ -203,10 +203,10 @@ pypats = [ (r'(?i)descendent', "the proper spelling is descendAnt"), (r'\.debug\(\_', "don't mark debug messages for translation"), (r'\.strip\(\)\.split\(\)', "no need to strip before splitting"), + (r'^\s*except\s*:', "warning: naked except clause", r'#.*re-raises'), ], # warnings [ - (r'^\s*except\s*:', "warning: naked except clause"), (r'ui\.(status|progress|write|note|warn)\([\'\"]x', "warning: unwrapped ui message"), ] @@ -355,7 +355,13 @@ def checkfile(f, logfunc=_defaultlogger. prelines = None errors = [] - for p, msg in pats: + for pat in pats: + if len(pat) == 3: + p, msg, ignore = pat + else: + p, msg = pat + ignore = None + # fix-up regexes for multiline searches po = p # \s doesn't match \n @@ -386,6 +392,8 @@ def checkfile(f, logfunc=_defaultlogger. print "Skipping %s for %s:%s (check-code -ignore)" % ( name, f, n) continue + elif ignore and re.search(ignore, l, re.MULTILINE): + continue bd = "" if blame: bd = 'working directory' diff --git a/contrib/shrink-revlog.py b/contrib/shrink-revlog.py --- a/contrib/shrink-revlog.py +++ b/contrib/shrink-revlog.py @@ -240,7 +240,7 @@ def shrink(ui, repo, **opts): writerevs(ui, r1, r2, order, tr) report(ui, r1, r2) tr.close() - except: + except: # re-raises # Abort transaction first, so we truncate the files before # deleting them. tr.abort() diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -712,7 +712,7 @@ class queue(object): tr.close() self.savedirty() return 2, repo.dirstate.p1() - except: + except: # re-raises try: tr.abort() finally: @@ -1077,7 +1077,7 @@ class queue(object): r = self.qrepo() if r: r[None].add([patchfn]) - except: + except: # re-raises repo.rollback() raise except Exception: @@ -1303,7 +1303,7 @@ class queue(object): else: ret = self.apply(repo, s, list, all_files=all_files, tobackup=tobackup, check=check) - except: + except: # re-raises self.ui.warn(_('cleaning up working directory...')) node = repo.dirstate.p1() hg.revert(repo, node, None) @@ -1629,7 +1629,7 @@ class queue(object): self.applieddirty = True self.strip(repo, [top], update=False, backup='strip') - except: + except: # re-raises repo.dirstate.invalidate() raise @@ -1643,7 +1643,7 @@ class queue(object): # only write patch after a successful commit patchf.close() self.applied.append(statusentry(n, patchfn)) - except: + except: # re-raises ctx = repo[cparents[0]] repo.dirstate.rebuild(ctx.node(), ctx.manifest()) self.savedirty() diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -3775,7 +3775,7 @@ def import_(ui, repo, patch1=None, *patc tr.close() if msgs: repo.savecommitmessage('\n* * *\n'.join(msgs)) - except: + except: # re-raises # wlock.release() indirectly calls dirstate.write(): since # we're crashing, we do not want to change the working dir # parent after all, so make sure it writes nothing diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -88,7 +88,7 @@ def _runcatch(req): return _dispatch(req) finally: ui.flush() - except: + except: # re-raises # enter the debugger when we hit an exception if '--debugger' in req.args: traceback.print_exc() @@ -204,7 +204,7 @@ def _runcatch(req): return inst.code except socket.error, inst: ui.warn(_("abort: %s\n") % inst.args[-1]) - except: + except: # re-raises ui.warn(_("** unknown exception encountered," " please report by visiting\n")) ui.warn(_("** http://mercurial.selenic.com/wiki/BugTracker\n")) diff --git a/mercurial/hg.py b/mercurial/hg.py --- a/mercurial/hg.py +++ b/mercurial/hg.py @@ -203,7 +203,7 @@ def copystore(ui, srcrepo, destpath): else: ui.debug("copied %d files\n" % num) return destlock - except: + except: # re-raises release(destlock) raise diff --git a/mercurial/keepalive.py b/mercurial/keepalive.py --- a/mercurial/keepalive.py +++ b/mercurial/keepalive.py @@ -290,7 +290,7 @@ class KeepAliveHandler(object): # worked. We'll check the version below, too. except (socket.error, httplib.HTTPException): r = None - except: + except: # re-raises # adding this block just in case we've missed # something we will still raise the exception, but # lets try and close the connection and remove it diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1180,7 +1180,7 @@ class localrepository(repo.repository): self.hook("precommit", throw=True, parent1=hookp1, parent2=hookp2) ret = self.commitctx(cctx, True) - except: + except: # re-raises if edited: self.ui.write( _('note: commit message saved in %s\n') % msgfn) diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -245,7 +245,7 @@ def extract(ui, fileobj): tmpfp.write('\n') elif not diffs_seen and message and content_type == 'text/plain': message += '\n' + payload - except: + except: # re-raises tmpfp.close() os.unlink(tmpname) raise diff --git a/mercurial/repair.py b/mercurial/repair.py --- a/mercurial/repair.py +++ b/mercurial/repair.py @@ -131,7 +131,7 @@ def strip(ui, repo, nodelist, backup="al file, troffset, ignore = tr.entries[i] repo.sopener(file, 'a').truncate(troffset) tr.close() - except: + except: # re-raises tr.abort() raise @@ -160,7 +160,7 @@ def strip(ui, repo, nodelist, backup="al for m in updatebm: bm[m] = repo['.'].node() bookmarks.write(repo) - except: + except: # re-raises if backupfile: ui.warn(_("strip failed, full bundle stored in '%s'\n") % backupfile) diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -760,7 +760,7 @@ def mktempcopy(name, emptyok=False, crea ofp.write(chunk) ifp.close() ofp.close() - except: + except: # re-raises try: os.unlink(temp) except OSError: pass raise diff --git a/tests/test-check-code-hg.t b/tests/test-check-code-hg.t --- a/tests/test-check-code-hg.t +++ b/tests/test-check-code-hg.t @@ -8,9 +8,6 @@ $ hg manifest | xargs "$check_code" || echo 'FAILURE IS NOT AN OPTION!!!' $ hg manifest | xargs "$check_code" --warnings --nolineno --per-file=0 || true - contrib/shrink-revlog.py:0: - > except: - warning: naked except clause hgext/convert/cvsps.py:0: > ui.write('Ancestors: %s\n' % (','.join(r))) warning: unwrapped ui message @@ -69,15 +66,6 @@ > ui.note("hg ci -m '%s'\n" % msg) warning: unwrapped ui message hgext/mq.py:0: - > except: - warning: naked except clause - hgext/mq.py:0: - > except: - warning: naked except clause - warning: naked except clause - warning: naked except clause - warning: naked except clause - hgext/mq.py:0: > ui.write("mq: %s\n" % ', '.join(m)) warning: unwrapped ui message hgext/patchbomb.py:0: @@ -117,9 +105,6 @@ > ui.write('deltas against p2 : ' + fmt % pcfmt(nump2, numdeltas)) warning: unwrapped ui message mercurial/commands.py:0: - > except: - warning: naked except clause - mercurial/commands.py:0: > ui.write("common heads: %s\n" % " ".join([short(n) for n in common])) warning: unwrapped ui message mercurial/commands.py:0: @@ -177,33 +162,6 @@ mercurial/commands.py:0: > ui.write('symlink: %s\n' % (util.checklink(path) and 'yes' or 'no')) warning: unwrapped ui message - mercurial/dispatch.py:0: - > except: - warning: naked except clause - mercurial/dispatch.py:0: - > except: - warning: naked except clause - mercurial/hg.py:0: - > except: - warning: naked except clause - mercurial/keepalive.py:0: - > except: - warning: naked except clause - mercurial/localrepo.py:0: - > except: - warning: naked except clause - mercurial/patch.py:0: - > except: - warning: naked except clause - mercurial/repair.py:0: - > except: - warning: naked except clause - mercurial/repair.py:0: - > except: - warning: naked except clause - mercurial/util.py:0: - > except: - warning: naked except clause tests/autodiff.py:0: > ui.write('data lost for: %s\n' % fn) warning: unwrapped ui message