Skip to content

Commit b4f9277

Browse files
committed
Don't complain about \r when core.autocrlf is on in Git (now working with Python 2.6).
1 parent 724d723 commit b4f9277

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/etc/tidy.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
#!/usr/bin/python
22

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

55
err=0
66
cols=78
77

8+
config_proc=subprocess.Popen([ "git", "config", "core.autocrlf" ],
9+
stdout=subprocess.PIPE)
10+
result=config_proc.communicate()[0]
11+
autocrlf=result.strip() == b"true" if result is not None else False
12+
813
def report_err(s):
914
global err
1015
print("%s:%d: %s" % (fileinput.filename(), fileinput.filelineno(), s))
@@ -14,10 +19,11 @@ def report_err(s):
1419
if line.find('\t') != -1 and fileinput.filename().find("Makefile") == -1:
1520
report_err("tab character")
1621

17-
if line.find('\r') != -1:
22+
if not autocrlf and line.find('\r') != -1:
1823
report_err("CR character")
1924

20-
if len(line)-1 > cols:
25+
line_len = len(line)-2 if autocrlf else len(line)-1
26+
if line_len > cols:
2127
report_err("line longer than %d chars" % cols)
2228

2329

0 commit comments

Comments
 (0)