Mercurial > hg-stable
view doc/docchecker @ 31996:e6e1884df298
track-tags: write all tag changes to a file
The tag changes information we compute is now written to disk. This gives
hooks full access to that data.
The format picked for that file uses a 2 characters prefix for the action:
-R: tag removed
+A: tag added
-M: tag moved (old value)
+M: tag moved (new value)
This format allows hooks to easily select the line that matters to them without
having to post process the file too much. Here is a couple of examples:
* to select all newly tagged changeset, match "^+",
* to detect tag move, match "^.M",
* to detect tag deletion, match "-R".
Once again we rely on the fact the tag tests run through all possible
situations to test this change.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Tue, 28 Mar 2017 10:15:02 +0200 |
parents | c9ab5a0bc7c5 |
children | 9bfbb9fc5871 |
line wrap: on
line source
#!/usr/bin/env python # # docchecker - look for problematic markup # # Copyright 2016 timeless <timeless@mozdev.org> and others # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. from __future__ import absolute_import, print_function import re import sys leadingline = re.compile(r'(^\s*)(\S.*)$') checks = [ (r""":hg:`[^`]*'[^`]*`""", """warning: please avoid nesting ' in :hg:`...`"""), (r'\w:hg:`', 'warning: please have a space before :hg:'), (r"""(?:[^a-z][^'.])hg ([^,;"`]*'(?!hg)){2}""", '''warning: please use " instead of ' for hg ... "..."'''), ] def check(line): messages = [] for match, msg in checks: if re.search(match, line): messages.append(msg) if messages: print(line) for msg in messages: print(msg) def work(file): (llead, lline) = ('', '') for line in file: # this section unwraps lines match = leadingline.match(line) if not match: check(lline) (llead, lline) = ('', '') continue lead, line = match.group(1), match.group(2) if (lead == llead): if (lline != ''): lline += ' ' + line else: lline = line else: check(lline) (llead, lline) = (lead, line) check(lline) def main(): for f in sys.argv[1:]: try: with open(f) as file: work(file) except BaseException as e: print("failed to process %s: %s" % (f, e)) main()