Mercurial > hg > check_whitespace
changeset 10:bd1ca3d502d6
Do not check intermediate changesets for errors, only final result.
author | Sjoerd Mullender <sjoerd@acm.org> |
---|---|
date | Fri, 20 Mar 2015 14:43:48 +0100 (2015-03-20) |
parents | 1ba95b6130d4 |
children | ff07accd0692 |
files | check_whitespace.py |
diffstat | 1 files changed, 27 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/check_whitespace.py Fri Mar 06 14:41:19 2015 +0100 +++ b/check_whitespace.py Fri Mar 20 14:43:48 2015 +0100 @@ -99,21 +99,36 @@ if line and line[0] in ' +': linenum += 1 -def hook(ui, repo, hooktype, node, **kwargs): +def hook(ui, repo, hooktype, node=None, source=None, **kwargs): import os, sys, subprocess - - added = 0 - for filename, linenum, msg in trailing_whitespace(repo[node].diff()): - print >> sys.stderr, ('%s, line %d: %s added' % - (filename, linenum, msg)) - added += 1 + if hooktype not in ['pretxnchangegroup', 'pretxncommit']: + ui.write('Hook should be pretxncommit/pretxnchangegroup not "%s".' % hooktype) + return 1 + added = False + branches = {} + for rev in xrange(repo[node], len(repo)): + branch = repo[rev].branch() + if not branches.has_key(branch): + # first time we see this branch, remember parents to diff against + branches[branch] = repo[rev].parents() + desc = 0 + for d in repo[rev].descendants(): + break + else: + # 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)) + added = True if added: # save the commit message so we don't need to retype it - 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 - return True + if source != 'serve': + 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 + return 1 if __name__ == '__main__': if hook(None, None, None, None):