Skip to content

Commit cef4870

Browse files
tautschnigDaniel Kroening
authored and
Daniel Kroening
committed
Make the pre-commit hook report non-temporary path names (#477)
This also fixes the problem of failing to deduce the correct include guards.
1 parent 2e56672 commit cef4870

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

.githooks/pre-commit

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ cleanup()
2424
trap cleanup EXIT
2525

2626
tmpStaging=$(mktemp -d)
27+
touch $tmpStaging/.git
2728

2829
# Copy contents of staged version of files to temporary staging area
2930
# because we only want the staged version that will be commited and not

scripts/cpplint.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -1220,8 +1220,10 @@ def Error(filename, linenum, category, confidence, message):
12201220
sys.stderr.write('%s:%s: warning: %s [%s] [%d]\n' % (
12211221
filename, linenum, message, category, confidence))
12221222
else:
1223+
fileinfo = FileInfo(filename)
1224+
path_from_root = fileinfo.RepositoryName()
12231225
sys.stderr.write('%s:%s: %s [%s] [%d]\n' % (
1224-
filename, linenum, message, category, confidence))
1226+
path_from_root, linenum, message, category, confidence))
12251227

12261228

12271229
# Matches standard C++ escape sequences per 2.13.2.3 of the C++ standard.
@@ -6469,13 +6471,18 @@ def ProcessFile(filename, vlevel, extra_check_functions=[]):
64696471
return
64706472

64716473
# Note, if no dot is found, this will give the entire filename as the ext.
6472-
file_extension = filename[filename.rfind('.') + 1:]
6474+
fileinfo = FileInfo(filename)
6475+
path_from_root = fileinfo.RepositoryName()
6476+
file_extension = fileinfo.Extension()
6477+
if not file_extension:
6478+
file_extension = filename[filename.rfind('.')]
6479+
file_extension = file_extension[1:]
64736480

64746481
# When reading from stdin, the extension is unknown, so no cpplint tests
64756482
# should rely on the extension.
64766483
if filename != '-' and file_extension not in _valid_extensions:
64776484
sys.stderr.write('Ignoring %s; not a valid file name '
6478-
'(%s)\n' % (filename, ', '.join(_valid_extensions)))
6485+
'(%s)\n' % (path_from_root, ', '.join(_valid_extensions)))
64796486
else:
64806487
ProcessFileData(filename, file_extension, lines, Error,
64816488
extra_check_functions)
@@ -6498,7 +6505,7 @@ def ProcessFile(filename, vlevel, extra_check_functions=[]):
64986505
Error(filename, linenum, 'whitespace/newline', 1,
64996506
'Unexpected \\r (^M) found; better to use only \\n')
65006507

6501-
sys.stdout.write('Done processing %s\n' % filename)
6508+
sys.stdout.write('Done processing %s\n' % path_from_root)
65026509
_RestoreFilters()
65036510

65046511

0 commit comments

Comments
 (0)