Skip to content

Commit

Permalink
checkpatch: cache last camelcase hash as .checkpatch-camelcase.<commit>
Browse files Browse the repository at this point in the history
Add a file to cache the CamelCase variables found by <commit> to reduce
the time it takes to scan the include/ directory.

Filename is '.checkpatch-camelcase.<commit>' and it is created only only
if a .git directory exists.

<commit> is determined by the last non-merge commit id in the
include/ path.

Reduces checkpatch run time by ~12 cpu seconds on my little netbook.

Signed-off-by: Joe Perches <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
JoePerches authored and torvalds committed Jul 3, 2013
1 parent 7d0b659 commit 351b2a1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,23 @@ sub seed_camelcase_includes {
return if ($camelcase_seeded);

my $files;
my $camelcase_git_file = "";

if (-d ".git") {
my $git_last_include_commit = `git log --no-merges --pretty=format:"%h%n" -1 -- include`;
chomp $git_last_include_commit;
$camelcase_git_file = ".checkpatch-camelcase.$git_last_include_commit";
if (-f $camelcase_git_file) {
open(my $camelcase_file, '<', "$camelcase_git_file")
or warn "$P: Can't read '$camelcase_git_file' $!\n";
while (<$camelcase_file>) {
chomp;
$camelcase{$_} = 1;
}
close($camelcase_file);

return;
}
$files = `git ls-files include`;
} else {
$files = `find $root/include -name "*.h"`;
Expand All @@ -409,6 +425,16 @@ sub seed_camelcase_includes {
seed_camelcase_file($file);
}
$camelcase_seeded = 1;

if ($camelcase_git_file ne "") {
unlink glob ".checkpatch-camelcase.*";
open(my $camelcase_file, '>', "$camelcase_git_file")
or warn "$P: Can't write '$camelcase_git_file' $!\n";
foreach (sort { lc($a) cmp lc($b) } keys(%camelcase)) {
print $camelcase_file ("$_\n");
}
close($camelcase_file);
}
}

$chk_signoff = 0 if ($file);
Expand Down

0 comments on commit 351b2a1

Please sign in to comment.