Mercurial > hg > check_whitespace
changeset 5:32c51a111990
Fix checking for errors in merge changeset.
author | Sjoerd Mullender <sjoerd@acm.org> |
---|---|
date | Wed, 11 Sep 2013 18:56:09 +0200 (2013-09-11) |
parents | 8884ce4b78d4 |
children | 95e8189b5fb4 |
files | check_whitespace.py |
diffstat | 1 files changed, 35 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/check_whitespace.py Tue May 14 12:29:18 2013 +0200 +++ b/check_whitespace.py Wed Sep 11 18:56:09 2013 +0200 @@ -28,51 +28,48 @@ tbre = re.compile(r'\+.*\t') resre = re.compile(r'\+(<<<<<<<|>>>>>>>)') - for line in difflines: - if header: - # remember the name of the file that this diff affects - m = fnre.match(line) - if m is not None and m.group('filename') != '/dev/null': - filename = m.group('filename').split('/', 1)[-1] - if line.startswith('+++ '): - header = False - continue - if line.startswith('diff '): - header = True - continue - # hunk header - save the line number - m = lnre.match(line) - if m is not None: - linenum = int(m.group('lineno')) - continue - if header or not filename: - continue - # hunk body - check for an added line with bad whitespace - if filename[-3:] == '.py' or filename[-5:] == '.py.in': - m = tbre.match(line) + for chunk in difflines: + for line in chunk.split('\n'): + if header: + # remember the name of the file that this diff affects + m = fnre.match(line) + if m is not None and m.group('filename') != '/dev/null': + filename = m.group('filename').split('/', 1)[-1] + if line.startswith('+++ '): + header = False + continue + if line.startswith('diff '): + header = True + continue + # hunk header - save the line number + m = lnre.match(line) if m is not None: - yield filename, linenum, 'TABs' - # trailing whitespace, for now only in Python source - m = wsre.match(line) - if m is not None: + linenum = int(m.group('lineno')) + continue + if header or not filename: + continue + # hunk body - check for an added line with bad whitespace if filename[-3:] == '.py' or filename[-5:] == '.py.in': - yield filename, linenum, 'trailing whitespace' - # conflict markers - m = resre.match(line) - if m is not None: - yield filename, linenum, 'conflict marker' - if line and line[0] in ' +': - linenum += 1 + m = tbre.match(line) + if m is not None: + yield filename, linenum, 'TABs' + # trailing whitespace, for now only in Python source + m = wsre.match(line) + if m is not None: + if filename[-3:] == '.py' or filename[-5:] == '.py.in': + yield filename, linenum, 'trailing whitespace' + # conflict markers + m = resre.match(line) + if m is not None: + yield filename, linenum, 'conflict marker' + if line and line[0] in ' +': + linenum += 1 def hook(ui, repo, hooktype, node, **kwargs): import os, sys, subprocess added = 0 - cmd = ['hg', 'export'] - if repo: - cmd.extend(['--cwd', repo.root]) - cmd.append('tip') - for filename, linenum, msg in trailing_whitespace(subprocess.Popen(cmd, stdout=subprocess.PIPE).stdout): + for filename, linenum, msg in trailing_whitespace(repo[node].diff()): print >> sys.stderr, ('%s, line %d: %s added' % (filename, linenum, msg)) added += 1