Mercurial > hg-stable
diff mercurial/cmdutil.py @ 29397:844f72885fb9
check-code: detect "missing _() in ui message" more exactly
Before this patch, "missing _() in ui message" rule overlooks
translatable message, which starts with other than alphabet.
To detect "missing _() in ui message" more exactly, this patch
improves the regexp with assumptions below.
- sequence consisting of below might precede "translatable message"
in same string token
- formatting string, which starts with '%'
- escaped character, which starts with 'b' (as replacement of '\\'), or
- characters other than '%', 'b' and 'x' (as replacement of alphabet)
- any string tokens might precede a string token, which contains
"translatable message"
This patch builds an input file, which is used to examine "missing _()
in ui message" detection, before '"$check_code" stringjoin.py' in
test-contrib-check-code.t, because this reduces amount of change churn
in subsequent patch.
This patch also applies "()" instead of "_()" on messages below to
hide false-positives:
- messages for ui.debug() or debug commands/tools
- contrib/debugshell.py
- hgext/win32mbcs.py (ui.write() is used, though)
- mercurial/commands.py
- _debugchangegroup
- debugindex
- debuglocks
- debugrevlog
- debugrevspec
- debugtemplate
- untranslatable messages
- doc/gendoc.py (ReST specific text)
- hgext/hgk.py (permission string)
- hgext/keyword.py (text written into configuration file)
- mercurial/cmdutil.py (formatting strings for JSON)
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Tue, 21 Jun 2016 00:50:39 +0900 |
parents | 38e0c83c7ee4 |
children | 33a6b750b5b9 |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Wed Jun 22 21:30:49 2016 +0100 +++ b/mercurial/cmdutil.py Tue Jun 21 00:50:39 2016 +0900 @@ -1405,24 +1405,24 @@ self.ui.write(",\n {") if self.ui.quiet: - self.ui.write('\n "rev": %s' % jrev) - self.ui.write(',\n "node": %s' % jnode) + self.ui.write(('\n "rev": %s') % jrev) + self.ui.write((',\n "node": %s') % jnode) self.ui.write('\n }') return - self.ui.write('\n "rev": %s' % jrev) - self.ui.write(',\n "node": %s' % jnode) - self.ui.write(',\n "branch": "%s"' % j(ctx.branch())) - self.ui.write(',\n "phase": "%s"' % ctx.phasestr()) - self.ui.write(',\n "user": "%s"' % j(ctx.user())) - self.ui.write(',\n "date": [%d, %d]' % ctx.date()) - self.ui.write(',\n "desc": "%s"' % j(ctx.description())) - - self.ui.write(',\n "bookmarks": [%s]' % + self.ui.write(('\n "rev": %s') % jrev) + self.ui.write((',\n "node": %s') % jnode) + self.ui.write((',\n "branch": "%s"') % j(ctx.branch())) + self.ui.write((',\n "phase": "%s"') % ctx.phasestr()) + self.ui.write((',\n "user": "%s"') % j(ctx.user())) + self.ui.write((',\n "date": [%d, %d]') % ctx.date()) + self.ui.write((',\n "desc": "%s"') % j(ctx.description())) + + self.ui.write((',\n "bookmarks": [%s]') % ", ".join('"%s"' % j(b) for b in ctx.bookmarks())) - self.ui.write(',\n "tags": [%s]' % + self.ui.write((',\n "tags": [%s]') % ", ".join('"%s"' % j(t) for t in ctx.tags())) - self.ui.write(',\n "parents": [%s]' % + self.ui.write((',\n "parents": [%s]') % ", ".join('"%s"' % c.hex() for c in ctx.parents())) if self.ui.debugflag: @@ -1430,26 +1430,26 @@ jmanifestnode = 'null' else: jmanifestnode = '"%s"' % hex(ctx.manifestnode()) - self.ui.write(',\n "manifest": %s' % jmanifestnode) - - self.ui.write(',\n "extra": {%s}' % + self.ui.write((',\n "manifest": %s') % jmanifestnode) + + self.ui.write((',\n "extra": {%s}') % ", ".join('"%s": "%s"' % (j(k), j(v)) for k, v in ctx.extra().items())) files = ctx.p1().status(ctx) - self.ui.write(',\n "modified": [%s]' % + self.ui.write((',\n "modified": [%s]') % ", ".join('"%s"' % j(f) for f in files[0])) - self.ui.write(',\n "added": [%s]' % + self.ui.write((',\n "added": [%s]') % ", ".join('"%s"' % j(f) for f in files[1])) - self.ui.write(',\n "removed": [%s]' % + self.ui.write((',\n "removed": [%s]') % ", ".join('"%s"' % j(f) for f in files[2])) elif self.ui.verbose: - self.ui.write(',\n "files": [%s]' % + self.ui.write((',\n "files": [%s]') % ", ".join('"%s"' % j(f) for f in ctx.files())) if copies: - self.ui.write(',\n "copies": {%s}' % + self.ui.write((',\n "copies": {%s}') % ", ".join('"%s": "%s"' % (j(k), j(v)) for k, v in copies)) @@ -1463,12 +1463,13 @@ self.ui.pushbuffer() diffordiffstat(self.ui, self.repo, diffopts, prev, node, match=matchfn, stat=True) - self.ui.write(',\n "diffstat": "%s"' % j(self.ui.popbuffer())) + self.ui.write((',\n "diffstat": "%s"') + % j(self.ui.popbuffer())) if diff: self.ui.pushbuffer() diffordiffstat(self.ui, self.repo, diffopts, prev, node, match=matchfn, stat=False) - self.ui.write(',\n "diff": "%s"' % j(self.ui.popbuffer())) + self.ui.write((',\n "diff": "%s"') % j(self.ui.popbuffer())) self.ui.write("\n }")