Skip to content

Commit c707a81

Browse files
JoePerchestorvalds
authored andcommitted
checkpatch: make the CamelCase cache work for non-git trees too
Might as well check include timestamps and cache the include file CamelCase uses for the non-git case too. The camelcase cache file is now named: for git: .checkpatch-camelcase.git.<commit_id> for non-git: .checkpatch-camelcase.date.<YYYYMMDDhhmm> All .checkpatch-camelcase* files are deleted if not current. Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent dcb6b45 commit c707a81

1 file changed

Lines changed: 35 additions & 19 deletions

File tree

scripts/checkpatch.pl

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# Licensed under the terms of the GNU GPL License version 2
77

88
use strict;
9+
use POSIX;
910

1011
my $P = $0;
1112
$P =~ s@.*/@@g;
@@ -399,37 +400,52 @@ sub seed_camelcase_includes {
399400
return if ($camelcase_seeded);
400401

401402
my $files;
402-
my $camelcase_git_file = "";
403+
my $camelcase_cache = "";
404+
my @include_files = ();
405+
406+
$camelcase_seeded = 1;
403407

404408
if (-d ".git") {
405409
my $git_last_include_commit = `git log --no-merges --pretty=format:"%h%n" -1 -- include`;
406410
chomp $git_last_include_commit;
407-
$camelcase_git_file = ".checkpatch-camelcase.$git_last_include_commit";
408-
if (-f $camelcase_git_file) {
409-
open(my $camelcase_file, '<', "$camelcase_git_file")
410-
or warn "$P: Can't read '$camelcase_git_file' $!\n";
411-
while (<$camelcase_file>) {
412-
chomp;
413-
$camelcase{$_} = 1;
414-
}
415-
close($camelcase_file);
416-
417-
return;
418-
}
419-
$files = `git ls-files include`;
411+
$camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit";
420412
} else {
413+
my $last_mod_date = 0;
421414
$files = `find $root/include -name "*.h"`;
415+
@include_files = split('\n', $files);
416+
foreach my $file (@include_files) {
417+
my $date = POSIX::strftime("%Y%m%d%H%M",
418+
localtime((stat $file)[9]));
419+
$last_mod_date = $date if ($last_mod_date < $date);
420+
}
421+
$camelcase_cache = ".checkpatch-camelcase.date.$last_mod_date";
422+
}
423+
424+
if ($camelcase_cache ne "" && -f $camelcase_cache) {
425+
open(my $camelcase_file, '<', "$camelcase_cache")
426+
or warn "$P: Can't read '$camelcase_cache' $!\n";
427+
while (<$camelcase_file>) {
428+
chomp;
429+
$camelcase{$_} = 1;
430+
}
431+
close($camelcase_file);
432+
433+
return;
434+
}
435+
436+
if (-d ".git") {
437+
$files = `git ls-files "include/*.h"`;
438+
@include_files = split('\n', $files);
422439
}
423-
my @include_files = split('\n', $files);
440+
424441
foreach my $file (@include_files) {
425442
seed_camelcase_file($file);
426443
}
427-
$camelcase_seeded = 1;
428444

429-
if ($camelcase_git_file ne "") {
445+
if ($camelcase_cache ne "") {
430446
unlink glob ".checkpatch-camelcase.*";
431-
open(my $camelcase_file, '>', "$camelcase_git_file")
432-
or warn "$P: Can't write '$camelcase_git_file' $!\n";
447+
open(my $camelcase_file, '>', "$camelcase_cache")
448+
or warn "$P: Can't write '$camelcase_cache' $!\n";
433449
foreach (sort { lc($a) cmp lc($b) } keys(%camelcase)) {
434450
print $camelcase_file ("$_\n");
435451
}

0 commit comments

Comments
 (0)