summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2012-10-24 21:06:07 (GMT)
committerGerrit Code Review <gerrit@localhost.localdomain>2012-10-26 12:11:15 (GMT)
commite1fc03a2454767e5d8f9abe8ca7746b1e3dcfbf9 (patch)
treeefa2a5b960d8f51713c4750430c2d97354374db4 /BuildTools
parent698d56b68533760931ea6e1509fea73cdcf35b67 (diff)
downloadswift-e1fc03a2454767e5d8f9abe8ca7746b1e3dcfbf9.zip
swift-e1fc03a2454767e5d8f9abe8ca7746b1e3dcfbf9.tar.bz2
Only check tabs & copyright of committed files.
Change-Id: Iba37ecbf03bab9e23a1ee9c72b39ee4266ec4032
Diffstat (limited to 'BuildTools')
-rwxr-xr-xBuildTools/CheckTabs.py60
-rwxr-xr-xBuildTools/Copyrighter.py23
-rwxr-xr-xBuildTools/Git/Hooks/pre-commit23
3 files changed, 42 insertions, 64 deletions
diff --git a/BuildTools/CheckTabs.py b/BuildTools/CheckTabs.py
index c685fc4..e007a68 100755
--- a/BuildTools/CheckTabs.py
+++ b/BuildTools/CheckTabs.py
@@ -4,38 +4,28 @@ import os, sys
foundExpandedTabs = False
-for (path, dirs, files) in os.walk(".") :
- if not "3rdParty" in path and not ".sconf" in path and not ".framework" in path and not path.startswith("build") :
- for filename in [os.path.join(path, file) for file in files if (file.endswith(".cpp") or file.endswith(".h")) and not "ui_" in file and not "moc_" in file and not "qrc_" in file] :
- file = open(filename, "r")
- contents = []
- contentsChanged = False
- for line in file.readlines() :
- newline = ""
- previousChar = None
- pastInitialSpace = False
- for char in line :
- if not pastInitialSpace :
- if char == ' ' and previousChar == ' ' :
- contentsChanged = True
- previousChar = '\t'
- continue
- pastInitialSpace = (char != ' ')
- if previousChar :
- newline += previousChar
- previousChar = char
- if previousChar :
- newline += previousChar
- contents.append(newline)
- file.close()
- if contentsChanged :
- if len(sys.argv) > 1 and sys.argv[1] == "--fix" :
- print("Fixing tabs in " + filename)
- file = open(filename, "w")
- file.write(''.join(contents))
- file.close()
- else :
- foundExpandedTabs = True
- print(filename + " contains expanded tabs")
-
-sys.exit(foundExpandedTabs)
+filename = sys.argv[1]
+if (filename.endswith(".cpp") or filename.endswith(".h")) and not "3rdParty" in filename :
+ file = open(filename, "r")
+ contents = []
+ contentsChanged = False
+ for line in file.readlines() :
+ newline = ""
+ previousChar = None
+ pastInitialSpace = False
+ for char in line :
+ if not pastInitialSpace :
+ if char == ' ' and previousChar == ' ' :
+ contentsChanged = True
+ previousChar = '\t'
+ continue
+ pastInitialSpace = (char != ' ')
+ if previousChar :
+ newline += previousChar
+ previousChar = char
+ if previousChar :
+ newline += previousChar
+ contents.append(newline)
+ file.close()
+ if contentsChanged :
+ sys.exit(-1)
diff --git a/BuildTools/Copyrighter.py b/BuildTools/Copyrighter.py
index 248873b..ccb2019 100755
--- a/BuildTools/Copyrighter.py
+++ b/BuildTools/Copyrighter.py
@@ -129,29 +129,14 @@ def set_copyright(filename, copyright) :
file.close()
if sys.argv[1] == "check-copyright" :
- if not check_copyright(sys.argv[2]) :
- sys.exit(-1)
-elif sys.argv[1] == "check-all-copyrights" :
- ok = True
- for (path, dirs, files) in os.walk(".") :
- if "3rdParty" in path or ".sconf" in path or "Swift.app" in path or path.startswith("build") or "xmppbench" in path :
- continue
- for filename in [os.path.join(path, file) for file in files if (file.endswith(".cpp") or file.endswith(".h")) and not "ui_" in file and not "moc_" in file and not "qrc_" in file and not "BuildVersion.h" in file and not "Swiften.h" in file and not "Version.h" in file and not "swiften-config.h" in file and not "linit.cpp" in file ] :
- ok &= check_copyright(filename)
- if not ok :
- sys.exit(-1)
+ file = sys.argv[2]
+ if (file.endswith(".cpp") or file.endswith(".h")) and not "3rdParty" in file :
+ if not check_copyright(file) :
+ sys.exit(-1)
elif sys.argv[1] == "set-copyright" :
(username, email) = get_userinfo()
copyright = get_copyright(username, email)
set_copyright(sys.argv[2], copyright)
-elif sys.argv[1] == "set-all-copyrights" :
- (username, email) = get_userinfo()
- copyright = get_copyright(username, email)
- for (path, dirs, files) in os.walk(".") :
- if "3rdParty" in path or ".sconf" in path or "Swift.app" in path :
- continue
- for filename in [os.path.join(path, file) for file in files if (file.endswith(".cpp") or file.endswith(".h")) and not "ui_" in file and not "moc_" in file and not "qrc_" in file and not "BuildVersion.h" in file and not "swiften-config.h" in file] :
- set_copyright(filename, copyright)
else :
print "Unknown command: " + sys.argv[1]
sys.exit(-1)
diff --git a/BuildTools/Git/Hooks/pre-commit b/BuildTools/Git/Hooks/pre-commit
index 8130ad6..28bebfc 100755
--- a/BuildTools/Git/Hooks/pre-commit
+++ b/BuildTools/Git/Hooks/pre-commit
@@ -1,13 +1,16 @@
#!/bin/sh
-echo "Checking tabs ..."
-if ! BuildTools/CheckTabs.py; then
- echo "Expanded tabs found. Aborting commit."
- exit -1
-fi
+IFS='
+'
-echo "Checking copyrights ..."
-if ! BuildTools/Copyrighter.py check-all-copyrights; then
- echo "Copyright error found. Aborting commit."
- exit -1
-fi
+echo "Checking tabs & copyrights ..."
+for file in $(git diff --cached --name-only); do
+ if ! BuildTools/CheckTabs.py $file; then
+ echo "ERROR: '$file' contains expanded tabs. Aborting commit."
+ exit -1
+ fi
+ if ! BuildTools/Copyrighter.py check-copyright $file; then
+ echo "ERROR: '$file' has a copyright error. Aborting commit."
+ exit -1
+ fi
+done