# HG changeset patch # User Sjoerd Mullender <sjoerd@acm.org> # Date 1426861570 -3600 # Node ID ff07accd0692e8d4055aa63e7516c41c509c2d8a # Parent bd1ca3d502d6e7cec9f12be3a6543e31bb36655f Don't use print; complain when used as program instead of python hook. diff -r bd1ca3d502d6 -r ff07accd0692 check_whitespace.py --- 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)