|
Revision 559:352e5cce339c, 1.3 kB
(checked in by David Anderson <dave@…>, 7 months ago)
|
|
Add a top-level scripts directory for general development helpers.
The main helper right now is configure-repos.py, which sets up
a .hg/hgrc with useful paths and hook scripts to perform basic
sanity checking.
|
|
|
| Line | |
|---|
| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | # |
|---|
| 4 | # Copyright (c) 2008 the NxOS developers |
|---|
| 5 | # |
|---|
| 6 | # See AUTHORS for a full list of the developers. |
|---|
| 7 | # |
|---|
| 8 | # Redistribution of this file is permitted under |
|---|
| 9 | # the terms of the GNU Public License (GPL) version 2. |
|---|
| 10 | # |
|---|
| 11 | # Receives a unified diff on standard input. Looks for adds that |
|---|
| 12 | # insert trailing whitespace, and reports them along with |
|---|
| 13 | # file/line/function info. If any added trailing whitespace is found, |
|---|
| 14 | # exits in error. Also reports win32 EOLs. |
|---|
| 15 | |
|---|
| 16 | import os |
|---|
| 17 | import sys |
|---|
| 18 | |
|---|
| 19 | file = '<file unknown>' |
|---|
| 20 | function = '<function unknown>' |
|---|
| 21 | ok = True |
|---|
| 22 | |
|---|
| 23 | for line in sys.stdin: |
|---|
| 24 | if line.startswith('+++'): |
|---|
| 25 | file = line.split()[1][2:] |
|---|
| 26 | function = '<function unknown>' |
|---|
| 27 | continue |
|---|
| 28 | elif line.startswith('@@'): |
|---|
| 29 | function = line.split('@@')[2].strip() or '<function unknown>' |
|---|
| 30 | continue |
|---|
| 31 | elif line.startswith('+'): |
|---|
| 32 | line = line.rstrip('\n') |
|---|
| 33 | if line.endswith(' ') or line.endswith('\t'): |
|---|
| 34 | print 'Trailing whitespace at %s in %s:' % (file, function) |
|---|
| 35 | print line |
|---|
| 36 | ok = False |
|---|
| 37 | if line.endswith('\r'): |
|---|
| 38 | print 'Windows-style EOL at %s in %s:' % (file, function) |
|---|
| 39 | print line |
|---|
| 40 | ok = False |
|---|
| 41 | |
|---|
| 42 | if ok: |
|---|
| 43 | sys.exit(0) |
|---|
| 44 | else: |
|---|
| 45 | os.system('hg tip --template {desc} >commit.msg') |
|---|
| 46 | print 'Commit message saved in commit.msg' |
|---|
| 47 | sys.exit(1) |
|---|