hgbook
annotate en/examples/data/check_whitespace.py @ 47:6f37e6a7d8cd
Get Emacs to figure out what syntax highlighting to use for examples.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Sun Jul 23 23:38:41 2006 -0700 (2006-07-23) |
parents | |
children | 18210d46491f |
rev | line source |
---|---|
bos@44 | 1 #!/usr/bin/python |
bos@44 | 2 |
bos@44 | 3 import os, re, sys |
bos@44 | 4 |
bos@44 | 5 count = 0 |
bos@44 | 6 |
bos@44 | 7 for line in os.popen('hg export tip'): |
bos@44 | 8 # remember the name of the file that this diff affects |
bos@44 | 9 m = re.match(r'^--- [^/]/([^\t])', line) |
bos@44 | 10 if m: |
bos@44 | 11 filename = m.group(1) |
bos@44 | 12 continue |
bos@44 | 13 # remember the line number |
bos@44 | 14 m = re.match(r'^@@ -(\d+),') |
bos@44 | 15 if m: |
bos@44 | 16 linenum = m.group(1) |
bos@44 | 17 continue |
bos@44 | 18 linenum += 1 |
bos@44 | 19 # check for an added line with trailing whitespace |
bos@44 | 20 m = re.match(r'^\+.*\s$', line) |
bos@44 | 21 if m: |
bos@44 | 22 print >> sys.stderr, ('%s:%d: trailing whitespace introduced' % |
bos@44 | 23 (filename, linenum)) |
bos@44 | 24 count += 1 |
bos@44 | 25 |
bos@44 | 26 if count: |
bos@44 | 27 # save the commit message so we don't need to retype it |
bos@44 | 28 os.system('hg tip --template "{desc}" > .hg/commit.save') |
bos@44 | 29 print >> sys.stderr, 'commit message saved to .hg/commit.save' |
bos@44 | 30 |
bos@44 | 31 sys.exit(count) |