Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0dea9f1e authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds
Browse files

checkpatch: reduce number of `git log` calls with --git

checkpatch currently calls git log multiple times to first get the
<revision range> sha1 values and again to get the subject for each
individual sha1 commit.

Always get the sha1 and subject at the same time instead.  Store the
subject in a sha1 hash to avoid the second git log exec.

Link: http://lkml.kernel.org/r/274efab2332ad2308ab5de85a95d255f6e2de5f3.1462711962.git.joe@perches.com


Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 4a593c34
Loading
Loading
Loading
Loading
+13 −10
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ my $terse = 0;
my $showfile = 0;
my $showfile = 0;
my $file = 0;
my $file = 0;
my $git = 0;
my $git = 0;
my %git_commits = ();
my $check = 0;
my $check = 0;
my $check_orig = 0;
my $check_orig = 0;
my $summary = 1;
my $summary = 1;
@@ -806,23 +807,25 @@ die "$P: No git repository found\n" if ($git && !-e ".git");


if ($git) {
if ($git) {
	my @commits = ();
	my @commits = ();
	for my $commit_expr (@ARGV) {
	foreach my $commit_expr (@ARGV) {
		my $git_range;
		my $git_range;
		if ($commit_expr =~ m/-/) {
		if ($commit_expr =~ m/-/) {
			my @tmp = split(/-/, $commit_expr);
			my @tmp = split(/-/, $commit_expr);
			die "$P: incorrect git commits expression $commit_expr$!\n"
			die "$P: incorrect git commit expression '$commit_expr' $!\n"
			    if (@tmp != 2);
			    if (@tmp != 2);
			$git_range = "-$tmp[1] $tmp[0]";
			$git_range = "-$tmp[1] $tmp[0]";
		} elsif ($commit_expr =~ m/\.\./) {
		} elsif ($commit_expr =~ m/\.\./) {
			$git_range = "$commit_expr";
			$git_range = "$commit_expr";
		} else {
			$git_range = "-1 $commit_expr";
		}
		}
		if (defined $git_range) {
		my $lines = `git log --no-color --no-merges --pretty=format:'%H %s' $git_range`;
			my $lines = `git log --no-merges --pretty=format:'%H' $git_range`;
		foreach my $line (split(/\n/, $lines)) {
		foreach my $line (split(/\n/, $lines)) {
				unshift(@commits, $line);
			$line =~ /(^\w+) (.*)/;
			}
			my $sha1 = $1;
		} else {
			my $subject = $2;
			unshift(@commits, $commit_expr);
			unshift(@commits, $sha1);
			$git_commits{$sha1} = $subject;
		}
		}
	}
	}
	die "$P: no git commits after extraction!\n" if (@commits == 0);
	die "$P: no git commits after extraction!\n" if (@commits == 0);
@@ -847,7 +850,7 @@ for my $filename (@ARGV) {
	if ($filename eq '-') {
	if ($filename eq '-') {
		$vname = 'Your patch';
		$vname = 'Your patch';
	} elsif ($git) {
	} elsif ($git) {
		$vname = "Commit " . substr($filename, 0, 12) . `git log -1 --pretty=format:' ("%s")' $filename`;
		$vname = "Commit " . substr($filename, 0, 12) . ' ("' . $git_commits{$filename} . '")';
	} else {
	} else {
		$vname = $filename;
		$vname = $filename;
	}
	}