Mercurial > hg > check_whitespace
changeset 11:ff07accd0692
Don't use print; complain when used as program instead of python hook.
author | Sjoerd Mullender <sjoerd@acm.org> |
---|---|
date | Fri, 20 Mar 2015 15:26:10 +0100 (2015-03-20) |
parents | bd1ca3d502d6 |
children | 915cf73f6afa |
files | check_whitespace.py |
diffstat | 1 files changed, 8 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/check_whitespace.py Fri Mar 20 14:43:48 2015 +0100 +++ b/check_whitespace.py Fri Mar 20 15:26:10 2015 +0100 @@ -118,8 +118,7 @@ # no descendants for this revision, check diff with saved parents for p in branches[branch]: for filename, linenum, msg in trailing_whitespace(repo[rev].diff(p)): - print >> sys.stderr, ('%s, line %d: %s added' % - (filename, linenum, msg)) + ui.write('%s, line %d: %s added\n' % (filename, linenum, msg)) added = True if added: # save the commit message so we don't need to retype it @@ -127,9 +126,13 @@ cmtsv = os.path.join('.hg','commit.save') subprocess.call(['hg', 'tip', '--template', '{desc}'], stdout=open(cmtsv, 'w')) - print >> sys.stderr, 'commit message saved to %s' % cmtsv + ui.write('commit message saved to %s\n' % cmtsv) return 1 if __name__ == '__main__': - if hook(None, None, None, None): - sys.exit(1) + import sys + sys.stderr.write('call this hook using the Python interface.\n' + 'In your .hgrc file you shoud have:\n' + 'pretxncommit.whitespace = python:<path-to-check_whitespace-directory>/check_whitespace.py:hook\n') + + sys.exit(1)