Skip to content

Commit 4fd4a9c

Browse files
committed
Codechange: fix indentation
1 parent eeb3791 commit 4fd4a9c

File tree

3 files changed

+79
-74
lines changed

3 files changed

+79
-74
lines changed

hooks/check-diff.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
PAT_TAB = re.compile("#?\t*[^\t]*$")
66

77
def checkascii(l):
8-
return any((ord(c) < 32 or ord(c) > 127) and c != '\t' for c in l)
8+
return any((ord(c) < 32 or ord(c) > 127) and c != '\t' for c in l)
99

1010
status = 0
1111
filename = None
@@ -14,47 +14,47 @@ def checkascii(l):
1414
lastline = None
1515

1616
for l in open(sys.argv[1], encoding="utf-8"):
17-
l = l.rstrip("\n")
17+
l = l.rstrip("\n")
1818

19-
if l.startswith("+++"):
20-
line = 1
21-
lastline = None
22-
filename = l[4:].strip()
23-
if checkascii(filename):
24-
sys.stderr.write("*** Filename is non-ASCII: '{}'\n".format(filename))
25-
status = 1
26-
is_source = (filename.find("3rdparty") < 0) and filename.endswith((".cpp", ".c", ".hpp", ".h", ".mm"))
27-
elif l.startswith("@@"):
28-
line = int(l.split()[2].split(",")[0])
29-
lastline = None
30-
elif l.startswith("+"):
31-
l = l[1:]
32-
lastline = "+"
33-
if is_source and checkascii(l):
34-
sys.stderr.write("*** {}:{}: Non-ASCII found: '{}'\n".format(filename, line, l))
35-
status = 1
36-
if l != l.rstrip():
37-
sys.stderr.write("*** {}:{}: Trailing whitespace: '{}'\n".format(filename, line, l))
38-
status = 1
39-
if is_source and not PAT_TAB.match(l):
40-
sys.stderr.write("*** {}:{}: Invalid tab usage: '{}'\n".format(filename, line, l))
41-
status = 1
42-
if is_source and (l.find("\t#") >= 0):
43-
sys.stderr.write("*** {}:{}: Preprocessor hash is put into the first column, before the tab indentation: '{}'\n".format(filename, line, l))
44-
status = 1
45-
if is_source and l.startswith(" "):
46-
sys.stderr.write("*** {}:{}: Use tabs for indentation: '{}'\n".format(filename, line, l))
47-
status = 1
48-
line += 1
49-
elif l.startswith(" "):
50-
line += 1
51-
lastline = " "
52-
elif l.startswith("-"):
53-
# do not increment line
54-
lastline = "-"
55-
elif l == "\\ No newline at end of file" and lastline != "-":
56-
sys.stderr.write("*** {}: No newline at end of file\n".format(filename))
57-
if lastline == " ": sys.stderr.write("Please fix the existing newline problem in the file.\n")
58-
status = 1
19+
if l.startswith("+++"):
20+
line = 1
21+
lastline = None
22+
filename = l[4:].strip()
23+
if checkascii(filename):
24+
sys.stderr.write("*** Filename is non-ASCII: '{}'\n".format(filename))
25+
status = 1
26+
is_source = (filename.find("3rdparty") < 0) and filename.endswith((".cpp", ".c", ".hpp", ".h", ".mm"))
27+
elif l.startswith("@@"):
28+
line = int(l.split()[2].split(",")[0])
29+
lastline = None
30+
elif l.startswith("+"):
31+
l = l[1:]
32+
lastline = "+"
33+
if is_source and checkascii(l):
34+
sys.stderr.write("*** {}:{}: Non-ASCII found: '{}'\n".format(filename, line, l))
35+
status = 1
36+
if l != l.rstrip():
37+
sys.stderr.write("*** {}:{}: Trailing whitespace: '{}'\n".format(filename, line, l))
38+
status = 1
39+
if is_source and not PAT_TAB.match(l):
40+
sys.stderr.write("*** {}:{}: Invalid tab usage: '{}'\n".format(filename, line, l))
41+
status = 1
42+
if is_source and (l.find("\t#") >= 0):
43+
sys.stderr.write("*** {}:{}: Preprocessor hash is put into the first column, before the tab indentation: '{}'\n".format(filename, line, l))
44+
status = 1
45+
if is_source and l.startswith(" "):
46+
sys.stderr.write("*** {}:{}: Use tabs for indentation: '{}'\n".format(filename, line, l))
47+
status = 1
48+
line += 1
49+
elif l.startswith(" "):
50+
line += 1
51+
lastline = " "
52+
elif l.startswith("-"):
53+
# do not increment line
54+
lastline = "-"
55+
elif l == "\\ No newline at end of file" and lastline != "-":
56+
sys.stderr.write("*** {}: No newline at end of file\n".format(filename))
57+
if lastline == " ": sys.stderr.write("Please fix the existing newline problem in the file.\n")
58+
status = 1
5959

6060
sys.exit(status)

hooks/check-message.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,41 @@
2727

2828
first_line = True
2929
for l in open(sys.argv[1], encoding="utf-8"):
30-
l = l.rstrip("\n")
30+
l = l.rstrip("\n")
3131

32-
# Skip comments on client side:
33-
# There are various ways how parts of the commit message can be ignored.
34-
# One method is by using some comment character (# by default).
35-
# Another is by using scissor lines.
36-
# We cannot tell which method is active, so we make a convenient assumption.
37-
# On server side we always check the whole message, since there are no longer any comments.
38-
if is_client and l.startswith("#"):
39-
continue
32+
# Skip comments on client side:
33+
# There are various ways how parts of the commit message can be ignored.
34+
# One method is by using some comment character (# by default).
35+
# Another is by using scissor lines.
36+
# We cannot tell which method is active, so we make a convenient assumption.
37+
# On server side we always check the whole message, since there are no longer any comments.
38+
if is_client and l.startswith("#"):
39+
continue
4040

41-
# Check trailing whitespace
42-
if l != l.rstrip():
43-
sys.stderr.write("*** Message contains trailing whitespace: {!a}\n".format(l))
44-
sys.exit(1)
41+
# Check trailing whitespace
42+
if l != l.rstrip():
43+
sys.stderr.write("*** Message contains trailing whitespace: {!a}\n".format(l))
44+
sys.exit(1)
4545

46-
# Check ASCII, and no control chars
47-
if any(ord(c) < 32 or ord(c) > 127 for c in l):
48-
sys.stderr.write("*** Message contains non-ASCII characters or tabs: {!a}\n".format(l))
49-
sys.exit(1)
46+
# Check ASCII, and no control chars
47+
if any(ord(c) < 32 or ord(c) > 127 for c in l):
48+
sys.stderr.write("*** Message contains non-ASCII characters or tabs: {!a}\n".format(l))
49+
sys.exit(1)
5050

51-
# Check first line
52-
if first_line:
53-
first_line = False
51+
# Check first line
52+
if first_line:
53+
first_line = False
5454

55-
parts = l.split(": ", 1)
56-
if len(parts) != 2:
57-
sys.stderr.write(ERROR)
58-
sys.exit(1)
55+
parts = l.split(": ", 1)
56+
if len(parts) != 2:
57+
sys.stderr.write(ERROR)
58+
sys.exit(1)
5959

60-
prefixes = parts[0].split(", ")
61-
first_prefix = True
62-
for p in prefixes:
63-
if (len(prefixes) == 1 and MSG_PAT1.match(p)) or MSG_PAT2.match(p) or MSG_PAT3.match(p) or (not first_prefix and MSG_PAT4.match(p)):
64-
first_prefix = False
65-
else:
66-
sys.stderr.write(ERROR)
67-
sys.exit(1)
60+
prefixes = parts[0].split(", ")
61+
first_prefix = True
62+
for p in prefixes:
63+
if (len(prefixes) == 1 and MSG_PAT1.match(p)) or MSG_PAT2.match(p) or MSG_PAT3.match(p) or (not first_prefix and MSG_PAT4.match(p)):
64+
first_prefix = False
65+
else:
66+
sys.stderr.write(ERROR)
67+
sys.exit(1)

test/test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ rm -rf main main.git goodguy badguy
3636
# setup main
3737
git_good init main
3838
cd main
39+
git_good config --local user.email [email protected]
3940
git_good config --local core.autocrlf input
4041
git_good config --local core.whitespace trailing-space,space-before-tab,indent-with-non-tab
4142
echo "init" > readme
@@ -59,6 +60,7 @@ cd ../..
5960
echo "goodguy"
6061
git_good clone main.git goodguy
6162
cd goodguy
63+
git_good config --local user.email [email protected]
6264
git_good config --local core.autocrlf input
6365
git_good config --local core.whitespace trailing-space,space-before-tab,indent-with-non-tab
6466
cd .git/hooks
@@ -170,6 +172,7 @@ cd ..
170172
echo "badguy"
171173
git_good clone main.git badguy
172174
cd badguy
175+
git_good config --local user.email [email protected]
173176

174177
cp case1.cpp case19.cpp
175178
git_good add case19.cpp
@@ -182,3 +185,5 @@ git_good commit --amend -m "Fix: Message"
182185
git_bad push
183186

184187
cd ..
188+
189+
echo "All tests passed successfully"

0 commit comments

Comments
 (0)