Skip to content

Commit 64be309

Browse files
committed
Don't complain about \r when core.autocrlf is on in Git... and work in Python 2.4, 2.6, and 3.x.
1 parent 1d10582 commit 64be309

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/etc/tidy.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python2.5
22

3-
import sys, fileinput
3+
import sys, fileinput, subprocess
44

55
err=0
66
cols=78
77

8+
# Be careful to support Python 2.4, 2.6, and 3.x here!
9+
config_proc=subprocess.Popen([ "git", "config", "core.autocrlf" ],
10+
stdout=subprocess.PIPE)
11+
result=config_proc.communicate()[0]
12+
13+
true="true".encode('utf8')
14+
autocrlf=result.strip() == true if result is not None else False
15+
816
def report_err(s):
917
global err
1018
print("%s:%d: %s" % (fileinput.filename(), fileinput.filelineno(), s))
@@ -14,10 +22,11 @@ def report_err(s):
1422
if line.find('\t') != -1 and fileinput.filename().find("Makefile") == -1:
1523
report_err("tab character")
1624

17-
if line.find('\r') != -1:
25+
if not autocrlf and line.find('\r') != -1:
1826
report_err("CR character")
1927

20-
if len(line)-1 > cols:
28+
line_len = len(line)-2 if autocrlf else len(line)-1
29+
if line_len > cols:
2130
report_err("line longer than %d chars" % cols)
2231

2332

0 commit comments

Comments
 (0)