[3.12] GH-109408: Move the C file whitespace check from patchcheck to pre-commit (GH-109890) (#110636)

(cherry picked from commit f5edb56328)
This commit is contained in:
Adam Turner 2023-10-10 16:00:00 +01:00 committed by GitHub
parent 948576574f
commit c9157feeec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 90 deletions

View file

@ -21,8 +21,7 @@ def main():
if optname == '-t':
tabsize = int(optvalue)
for filename in args:
process(filename, tabsize)
return max(process(filename, tabsize) for filename in args)
def process(filename, tabsize, verbose=True):
@ -32,10 +31,10 @@ def process(filename, tabsize, verbose=True):
encoding = f.encoding
except IOError as msg:
print("%r: I/O error: %s" % (filename, msg))
return
return 2
newtext = text.expandtabs(tabsize)
if newtext == text:
return
return 0
backup = filename + "~"
try:
os.unlink(backup)
@ -49,7 +48,8 @@ def process(filename, tabsize, verbose=True):
f.write(newtext)
if verbose:
print(filename)
return 1
if __name__ == '__main__':
main()
raise SystemExit(main())