Mercurial > hg > check_whitespace
comparison check_whitespace.py @ 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 |
comparison
equal
deleted
inserted
replaced
10:bd1ca3d502d6 | 11:ff07accd0692 |
---|---|
116 break | 116 break |
117 else: | 117 else: |
118 # no descendants for this revision, check diff with saved parents | 118 # no descendants for this revision, check diff with saved parents |
119 for p in branches[branch]: | 119 for p in branches[branch]: |
120 for filename, linenum, msg in trailing_whitespace(repo[rev].diff(p)): | 120 for filename, linenum, msg in trailing_whitespace(repo[rev].diff(p)): |
121 print >> sys.stderr, ('%s, line %d: %s added' % | 121 ui.write('%s, line %d: %s added\n' % (filename, linenum, msg)) |
122 (filename, linenum, msg)) | |
123 added = True | 122 added = True |
124 if added: | 123 if added: |
125 # save the commit message so we don't need to retype it | 124 # save the commit message so we don't need to retype it |
126 if source != 'serve': | 125 if source != 'serve': |
127 cmtsv = os.path.join('.hg','commit.save') | 126 cmtsv = os.path.join('.hg','commit.save') |
128 subprocess.call(['hg', 'tip', '--template', '{desc}'], | 127 subprocess.call(['hg', 'tip', '--template', '{desc}'], |
129 stdout=open(cmtsv, 'w')) | 128 stdout=open(cmtsv, 'w')) |
130 print >> sys.stderr, 'commit message saved to %s' % cmtsv | 129 ui.write('commit message saved to %s\n' % cmtsv) |
131 return 1 | 130 return 1 |
132 | 131 |
133 if __name__ == '__main__': | 132 if __name__ == '__main__': |
134 if hook(None, None, None, None): | 133 import sys |
135 sys.exit(1) | 134 sys.stderr.write('call this hook using the Python interface.\n' |
135 'In your .hgrc file you shoud have:\n' | |
136 'pretxncommit.whitespace = python:<path-to-check_whitespace-directory>/check_whitespace.py:hook\n') | |
137 | |
138 sys.exit(1) |