1 # $Hg: pretxnkw.py,v$ |
1 # $Hg: hgkw/pretxnkw.py,v$ |
2 |
2 |
3 from mercurial.i18n import gettext as _ |
3 from mercurial.i18n import gettext as _ |
4 from mercurial.demandload import demandload |
4 from mercurial.demandload import demandload |
5 demandload(globals(), 'hgkw:kwutil mercurial:util os.path re') |
5 demandload(globals(), 'hgkw:kwutil mercurial:util re') |
6 |
6 |
7 kwencodefilter = 'hgkwencode' |
7 kwencodefilter = 'hgkwencode' |
8 |
8 |
9 def pretxnkw(ui=None, repo=None, hooktype='', **args): |
9 def pretxnkw(ui=None, repo=None, hooktype='', **args): |
10 '''Important: returns False on success, True on failure.''' |
10 '''Important: returns False on success, True on failure.''' |
35 re_kwcheck = re.compile(r'[$]Hg: (.*?),v.*?\$') |
35 re_kwcheck = re.compile(r'[$]Hg: (.*?),v.*?\$') |
36 |
36 |
37 for filename in files: |
37 for filename in files: |
38 |
38 |
39 data = repo.wfile(filename).read() |
39 data = repo.wfile(filename).read() |
40 bn = os.path.basename(filename) |
|
41 |
40 |
42 # check for keywords with incorrect basename |
41 # check for keywords with incorrect filename |
43 # eg. if you forgot to update basename manually after "hg mv" |
42 # eg. if you forgot to update filename manually after "hg mv" |
44 failures = [m for m in map(str, re_kwcheck.findall(data)) if m != bn] |
43 invalids = [m for m in map(str, re_kwcheck.findall(data)) |
45 if failures: |
44 if m != filename] |
46 failures = ['%sHg: %s,v$' % ('$', nobn) for nobn in failures] |
45 if invalids: |
47 ui.warn(_('%d incorrect basenames in file %s:\n' |
46 invalids = ['%sHg: %s,v$' % ('$', i) for i in invalids] |
|
47 ui.warn(_('%d invalid keyword filenames in file %s:\n' |
48 '%s\nplease correct to %sHg: %s,v$\n' |
48 '%s\nplease correct to %sHg: %s,v$\n' |
49 % (len(failures), filename, ', '.join(failures), '$', bn))) |
49 % (len(invalids), filename, ', '.join(invalids), '$', filename) |
|
50 )) |
50 return True |
51 return True |
51 |
52 |
52 # substitute <Dollar>(Hg|Id): <basename>,v.*<Dollar> |
53 # substitute <Dollar>(Hg|Id): <basename>,v.*<Dollar> |
53 data, kwct = re_kw.subn(kword, data) |
54 data, kwct = re_kw.subn(kword, data) |
54 |
55 |