Skip to content

Commit

Permalink
FROMLIST: checkpatch: Enable GIT_DIR environment use to set git repos…
Browse files Browse the repository at this point in the history
…itory location

If set, use the environment variable GIT_DIR to change the
default .git location of the kernel git tree.

If GIT_DIR is unset, keep using the current ".git" default.

Link: https://lore.kernel.org/lkml/[email protected]/
Tested-by: Geert Uytterhoeven <[email protected]>
Signed-off-by: Joe Perches <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Change-Id: Iada84c273affd12000f4df3b98da2d3d44b1a26c
  • Loading branch information
JoePerches authored and gregkh committed Oct 27, 2020
1 parent 92f919a commit f886255
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
my $fix = 0;
my $fix_inplace = 0;
my $root;
my $gitroot = $ENV{'GIT_DIR'};
$gitroot = ".git" if !defined($gitroot);
my %debug;
my %camelcase = ();
my %use_type = ();
Expand Down Expand Up @@ -908,7 +910,7 @@ sub is_maintained_obsolete {
sub is_SPDX_License_valid {
my ($license) = @_;

return 1 if (!$tree || which("python") eq "" || !(-e "$root/scripts/spdxcheck.py") || !(-e "$root/.git"));
return 1 if (!$tree || which("python") eq "" || !(-e "$root/scripts/spdxcheck.py") || !(-e "$gitroot"));

my $root_path = abs_path($root);
my $status = `cd "$root_path"; echo "$license" | python scripts/spdxcheck.py -`;
Expand All @@ -926,7 +928,7 @@ sub seed_camelcase_includes {

$camelcase_seeded = 1;

if (-e ".git") {
if (-e "$gitroot") {
my $git_last_include_commit = `${git_command} log --no-merges --pretty=format:"%h%n" -1 -- include`;
chomp $git_last_include_commit;
$camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit";
Expand Down Expand Up @@ -954,7 +956,7 @@ sub seed_camelcase_includes {
return;
}

if (-e ".git") {
if (-e "$gitroot") {
$files = `${git_command} ls-files "include/*.h"`;
@include_files = split('\n', $files);
}
Expand Down Expand Up @@ -987,7 +989,7 @@ sub git_is_single_file {
sub git_commit_info {
my ($commit, $id, $desc) = @_;

return ($id, $desc) if ((which("git") eq "") || !(-e ".git"));
return ($id, $desc) if ((which("git") eq "") || !(-e "$gitroot"));

my $output = `${git_command} log --no-color --format='%H %s' -1 $commit 2>&1`;
$output =~ s/^\s*//gm;
Expand Down Expand Up @@ -1026,7 +1028,7 @@ sub git_commit_info {

# If input is git commits, extract all commits from the commit expressions.
# For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'.
die "$P: No git repository found\n" if ($git && !-e ".git");
die "$P: No git repository found\n" if ($git && !-e "$gitroot");

if ($git) {
my @commits = ();
Expand Down

0 comments on commit f886255

Please sign in to comment.