Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
29396:d0ae5b8f80dc | 29397:844f72885fb9 |
---|---|
1403 self._first = False | 1403 self._first = False |
1404 else: | 1404 else: |
1405 self.ui.write(",\n {") | 1405 self.ui.write(",\n {") |
1406 | 1406 |
1407 if self.ui.quiet: | 1407 if self.ui.quiet: |
1408 self.ui.write('\n "rev": %s' % jrev) | 1408 self.ui.write(('\n "rev": %s') % jrev) |
1409 self.ui.write(',\n "node": %s' % jnode) | 1409 self.ui.write((',\n "node": %s') % jnode) |
1410 self.ui.write('\n }') | 1410 self.ui.write('\n }') |
1411 return | 1411 return |
1412 | 1412 |
1413 self.ui.write('\n "rev": %s' % jrev) | 1413 self.ui.write(('\n "rev": %s') % jrev) |
1414 self.ui.write(',\n "node": %s' % jnode) | 1414 self.ui.write((',\n "node": %s') % jnode) |
1415 self.ui.write(',\n "branch": "%s"' % j(ctx.branch())) | 1415 self.ui.write((',\n "branch": "%s"') % j(ctx.branch())) |
1416 self.ui.write(',\n "phase": "%s"' % ctx.phasestr()) | 1416 self.ui.write((',\n "phase": "%s"') % ctx.phasestr()) |
1417 self.ui.write(',\n "user": "%s"' % j(ctx.user())) | 1417 self.ui.write((',\n "user": "%s"') % j(ctx.user())) |
1418 self.ui.write(',\n "date": [%d, %d]' % ctx.date()) | 1418 self.ui.write((',\n "date": [%d, %d]') % ctx.date()) |
1419 self.ui.write(',\n "desc": "%s"' % j(ctx.description())) | 1419 self.ui.write((',\n "desc": "%s"') % j(ctx.description())) |
1420 | 1420 |
1421 self.ui.write(',\n "bookmarks": [%s]' % | 1421 self.ui.write((',\n "bookmarks": [%s]') % |
1422 ", ".join('"%s"' % j(b) for b in ctx.bookmarks())) | 1422 ", ".join('"%s"' % j(b) for b in ctx.bookmarks())) |
1423 self.ui.write(',\n "tags": [%s]' % | 1423 self.ui.write((',\n "tags": [%s]') % |
1424 ", ".join('"%s"' % j(t) for t in ctx.tags())) | 1424 ", ".join('"%s"' % j(t) for t in ctx.tags())) |
1425 self.ui.write(',\n "parents": [%s]' % | 1425 self.ui.write((',\n "parents": [%s]') % |
1426 ", ".join('"%s"' % c.hex() for c in ctx.parents())) | 1426 ", ".join('"%s"' % c.hex() for c in ctx.parents())) |
1427 | 1427 |
1428 if self.ui.debugflag: | 1428 if self.ui.debugflag: |
1429 if rev is None: | 1429 if rev is None: |
1430 jmanifestnode = 'null' | 1430 jmanifestnode = 'null' |
1431 else: | 1431 else: |
1432 jmanifestnode = '"%s"' % hex(ctx.manifestnode()) | 1432 jmanifestnode = '"%s"' % hex(ctx.manifestnode()) |
1433 self.ui.write(',\n "manifest": %s' % jmanifestnode) | 1433 self.ui.write((',\n "manifest": %s') % jmanifestnode) |
1434 | 1434 |
1435 self.ui.write(',\n "extra": {%s}' % | 1435 self.ui.write((',\n "extra": {%s}') % |
1436 ", ".join('"%s": "%s"' % (j(k), j(v)) | 1436 ", ".join('"%s": "%s"' % (j(k), j(v)) |
1437 for k, v in ctx.extra().items())) | 1437 for k, v in ctx.extra().items())) |
1438 | 1438 |
1439 files = ctx.p1().status(ctx) | 1439 files = ctx.p1().status(ctx) |
1440 self.ui.write(',\n "modified": [%s]' % | 1440 self.ui.write((',\n "modified": [%s]') % |
1441 ", ".join('"%s"' % j(f) for f in files[0])) | 1441 ", ".join('"%s"' % j(f) for f in files[0])) |
1442 self.ui.write(',\n "added": [%s]' % | 1442 self.ui.write((',\n "added": [%s]') % |
1443 ", ".join('"%s"' % j(f) for f in files[1])) | 1443 ", ".join('"%s"' % j(f) for f in files[1])) |
1444 self.ui.write(',\n "removed": [%s]' % | 1444 self.ui.write((',\n "removed": [%s]') % |
1445 ", ".join('"%s"' % j(f) for f in files[2])) | 1445 ", ".join('"%s"' % j(f) for f in files[2])) |
1446 | 1446 |
1447 elif self.ui.verbose: | 1447 elif self.ui.verbose: |
1448 self.ui.write(',\n "files": [%s]' % | 1448 self.ui.write((',\n "files": [%s]') % |
1449 ", ".join('"%s"' % j(f) for f in ctx.files())) | 1449 ", ".join('"%s"' % j(f) for f in ctx.files())) |
1450 | 1450 |
1451 if copies: | 1451 if copies: |
1452 self.ui.write(',\n "copies": {%s}' % | 1452 self.ui.write((',\n "copies": {%s}') % |
1453 ", ".join('"%s": "%s"' % (j(k), j(v)) | 1453 ", ".join('"%s": "%s"' % (j(k), j(v)) |
1454 for k, v in copies)) | 1454 for k, v in copies)) |
1455 | 1455 |
1456 matchfn = self.matchfn | 1456 matchfn = self.matchfn |
1457 if matchfn: | 1457 if matchfn: |
1461 node, prev = ctx.node(), ctx.p1().node() | 1461 node, prev = ctx.node(), ctx.p1().node() |
1462 if stat: | 1462 if stat: |
1463 self.ui.pushbuffer() | 1463 self.ui.pushbuffer() |
1464 diffordiffstat(self.ui, self.repo, diffopts, prev, node, | 1464 diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
1465 match=matchfn, stat=True) | 1465 match=matchfn, stat=True) |
1466 self.ui.write(',\n "diffstat": "%s"' % j(self.ui.popbuffer())) | 1466 self.ui.write((',\n "diffstat": "%s"') |
1467 % j(self.ui.popbuffer())) | |
1467 if diff: | 1468 if diff: |
1468 self.ui.pushbuffer() | 1469 self.ui.pushbuffer() |
1469 diffordiffstat(self.ui, self.repo, diffopts, prev, node, | 1470 diffordiffstat(self.ui, self.repo, diffopts, prev, node, |
1470 match=matchfn, stat=False) | 1471 match=matchfn, stat=False) |
1471 self.ui.write(',\n "diff": "%s"' % j(self.ui.popbuffer())) | 1472 self.ui.write((',\n "diff": "%s"') % j(self.ui.popbuffer())) |
1472 | 1473 |
1473 self.ui.write("\n }") | 1474 self.ui.write("\n }") |
1474 | 1475 |
1475 class changeset_templater(changeset_printer): | 1476 class changeset_templater(changeset_printer): |
1476 '''format changeset information.''' | 1477 '''format changeset information.''' |