Fix Bug 9951: 'git commit hook isn't calling checkAPIs.pl with arguments for the...
authorHadriel Kaplan <hadrielk@yahoo.com>
Thu, 3 Apr 2014 21:42:54 +0000 (17:42 -0400)
committerMichael Mann <mmann78@netscape.net>
Mon, 14 Apr 2014 00:10:20 +0000 (00:10 +0000)
I recently made a change to packet-rtp.c and inappropriately included
g_error() in it, which the builbots caught during their run of checkAPIs.pl.
But checkAPIs.pl is supposed to catch such things for us before we submit, by
being invoked in the git pre-commit hook.

Apparently though, buildbots call checkAPIs.pl with extra arguments for
different cases... and for packet dissectors it calls it with a '-g abort'
argument, which is how it caught the g_error.

So the "bug" is that the pre-commit hook should invoke checAPIs.pl with that
argument too, for epan/dissectors/packet-*.c files.

Change-Id: Ie8f9dcc55f2248918208dea85a04f67e6bf9829a
Reviewed-on: https://code.wireshark.org/review/953
Reviewed-by: Hadriel Kaplan <hadrielk@yahoo.com>
Reviewed-by: Evan Huus <eapache@gmail.com>
Reviewed-by: Michael Mann <mmann78@netscape.net>
tools/checkAPIs.pl
tools/pre-commit

index 1335bdd69c15d61515a1174ab4220986ffc2df50..17750194d86d6123e119618397eebe6358a45102 100755 (executable)
@@ -1860,6 +1860,7 @@ sub print_usage
         print "                    [--nocheck-addtext] [--nocheck-hf] [--debug] file1 file2 ...\n";
         print "\n";
         print "       -M: Generate output for -g in 'machine-readable' format\n";
+        print "       -p: used by the git pre-commit hook\n";
         print "       -h: help, print usage message\n";
         print "       -g <group>:  Check input files for use of APIs in <group>\n";
         print "                    (in addition to the default groups)\n";
@@ -2000,6 +2001,7 @@ my $check_addtext = 1;                                  # default: enabled
 my $debug_flag = 0;                                     # default: disabled
 my $buildbot_flag = 0;
 my $help_flag = 0;
+my $pre_commit = 0;
 
 my $result = GetOptions(
                         'group=s' => \@apiGroups,
@@ -2010,6 +2012,7 @@ my $result = GetOptions(
                         'check-addtext!' => \$check_addtext,
                         'build' => \$buildbot_flag,
                         'debug' => \$debug_flag,
+                        'pre-commit' => \$pre_commit,
                         'help' => \$help_flag
                         );
 if (!$result || $help_flag) {
@@ -2017,6 +2020,17 @@ if (!$result || $help_flag) {
         exit(1);
 }
 
+# the pre-commit hook only calls checkAPIs one file at a time, so this
+# is safe to do globally (and easier)
+if ($pre_commit) {
+    my $filename = $ARGV[0];
+    # if the filename is packet-*.c or packet-*.h, then we set the abort and termoutput groups.
+    if ($filename =~ /\bpacket-\w+\.[ch]$/) {
+        push @apiGroups, "abort";
+        push @apiGroups, "termoutput";
+    }
+}
+
 # Add a 'function_count' anonymous hash to each of the 'apiGroup' entries in the %APIs hash.
 for my $apiGroup (keys %APIs) {
         my @functions = @{$APIs{$apiGroup}{functions}};
index 89afabc3e9a836220c28198cffd2347e65a4942b..55b9c9c96db9a7ee55af67911d331ee623213514 100755 (executable)
@@ -21,7 +21,7 @@ for FILE in `git diff-index --cached --name-only HEAD | grep "\.[ch]$"` ; do
     ./tools/checkhf.pl $FILE
 
     #Check if checkAPIs is good
-    ./tools/checkAPIs.pl $FILE
+    ./tools/checkAPIs.pl -p $FILE
 
     #Check if fix-encoding-args is good
     ./tools/fix-encoding-args.pl $FILE