Re: [PATCH 1/2] check-headers: add header usage checks for .c files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Junio C Hamano <gitster@xxxxxxxxx> writes:

> David Aguilar <davvid@xxxxxxxxx> writes:
>
>> Teach check-header.sh to ensure that the first included header in .c
>> files is either git-compat-util.h, builtin.h, or cache.h.
>>
>> Ensure that common-cmds.h is only included by help.c.
>>
>> Move the logic into functions so that we can skip parts of the check.
>>
>> Signed-off-by: David Aguilar <davvid@xxxxxxxxx>
>> ---
>> This depends on my previous patch that adds check-header.sh.
>> ...
>> +check_headers () {
>> +	for header in *.h ewah/*.h vcs-svn/*.h xdiff/*.h
>> +	do
>> +		check_header "$header"
>
> Hmmmm, doesn't check_header run "$@" as a command?

Taking the previous two together, perhaps

 check-headers.sh | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/check-headers.sh b/check-headers.sh
index 7f25e7a..526381e 100755
--- a/check-headers.sh
+++ b/check-headers.sh
@@ -20,6 +20,7 @@ maybe_exit () {
 
 check_header () {
 	header="$1"
+	shift
 	case "$header" in
 	common-cmds.h)
 		# should only be included by help.c, not checked
@@ -38,15 +39,17 @@ check_header () {
 check_headers () {
 	for header in *.h ewah/*.h vcs-svn/*.h xdiff/*.h
 	do
-		check_header "$header"
+		check_header "$header" "$@"
 	done
 }
 
 check_header_usage () {
-	first=$(grep '^#include' "$1" |
-		head -n1 |
-		sed -e 's,#include ",,' -e 's,"$,,')
-
+	first=$( 
+		sed -n -e '/^#include/{
+			s/#include ["<]\(.*\)".*/\1/p
+			q
+		}' "$1"
+	)
 	case "$first" in
 	cache.h|builtin.h|git-compat-util.h)
 		# happy
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]