lo-commit-stat: allow to filer cherry-picked commits

Add --cherry option that filters commits using the "git cherry" command.

Note that you need to pass git arguments for "git cherry". It means
"old-branch-or-tag" "new-branch-or-tag".

Change-Id: Iea67d0ead205c66112791cb0444fa183c7fa6e9b
This commit is contained in:
Petr Mladek 2012-11-29 11:14:13 +01:00
parent fead8bc949
commit 3e0e88f675

View file

@ -6,6 +6,7 @@
use strict;
use LWP::UserAgent;
use utf8;
use File::Temp;
my %module_dirname = (
"core" => "",
@ -92,11 +93,53 @@ sub standardize_summary($)
return $line;
}
sub load_git_log($$$$$)
sub generate_git_cherry_ids_log($$$$$)
{
my ($pdata, $repo_dir, $module, $branch_name, $git_command) = @_;
my ($pdata, $repo_dir, $module, $branch_name, $git_args) = @_;
my $commit_ids_log;
my $commit_ids_log_fh;
$commit_ids_log_fh = File::Temp->new(TEMPLATE => 'lo-commit-stat-ids-XXXXXX',
DIR => '/tmp',
UNLINK => 0);
$commit_ids_log = $commit_ids_log_fh->filename;
print STDERR "Filtering cherry-picked commits in the git repo: $module...\n";
my $cmd = "cd $repo_dir; git cherry $git_args";
open (GIT, "$cmd 2>&1|") || die "Can't run $cmd: $!";
while (my $line = <GIT>) {
# skip cherry-picked commits
next if ( $line =~ m/^\-/ );
if ( $line =~ m/^\+ / ) {
$line =~ s/^\+ //;
print $commit_ids_log_fh $line;
}
}
close GIT;
close $commit_ids_log_fh;
return $commit_ids_log;
}
sub load_git_log($$$$$$$)
{
my ($pdata, $repo_dir, $module, $branch_name, $git_command, $git_cherry, $git_args) = @_;
my $cmd = "cd $repo_dir;";
my $commit_ids_log;
if ($git_cherry) {
$commit_ids_log = generate_git_cherry_ids_log($pdata, $repo_dir, $module, $branch_name, $git_args);
$cmd .= " cat $commit_ids_log | xargs -n 1 $git_command -1";
} else {
$cmd .= " $git_command $git_args";
}
my $cmd = "cd $repo_dir; $git_command";
my $commit_id;
my $summary;
@ -155,6 +198,7 @@ sub load_git_log($$$$$)
}
close GIT;
unlink $commit_ids_log if ($git_cherry);
}
sub get_repo_name($)
@ -176,12 +220,12 @@ sub get_repo_name($)
die "Error: can't find repo name in \"$$repo_dir/.git/config\"\n";
}
sub load_data($$$$$)
sub load_data($$$$$$$)
{
my ($pdata, $top_dir, $p_module_dirname, $branch_name, $git_command) = @_;
my ($pdata, $top_dir, $p_module_dirname, $branch_name, $git_command, $git_cherry, $git_args) = @_;
foreach my $module (keys %{$p_module_dirname}) {
load_git_log($pdata, "$top_dir/$p_module_dirname->{$module}", $module, $branch_name, $git_command);
foreach my $module (sort { $a cmp $b } keys %{$p_module_dirname}) {
load_git_log($pdata, "$top_dir/$p_module_dirname->{$module}", $module, $branch_name, $git_command, $git_cherry, $git_args);
}
}
@ -416,12 +460,16 @@ sub usage()
" --bugs-numbers generate log with bugzilla numbers\n" .
" --rev-list use \"git rev-list\" instead of \"git log\"; useful to check\n" .
" differences between branches\n" .
" --cherry use \"git cherry\" instead of \"git log\"; detects cherry-picked\n" .
" commits between branches\n" .
" topdir directory with the libreoffice/core clone\n" .
" git_arg extra parameters passed to the git command to define\n" .
" the area of interest; The default command is \"git log\" and\n" .
" parameters might be, for example, --after=\"2010-09-27\" or\n" .
" TAG..HEAD; with the option --rev-list, useful might be, for\n" .
" example origin/master ^origin/libreoffice-3-3\n";
" example origin/master ^origin/libreoffice-3-3; with the option\n" .
" --rev-list, useful might be, for example libreoffice-3.6.3.2\n" .
" libreoffice-3.6.4.1\n";
}
@ -441,8 +489,9 @@ my $log_suffix;
my $log;
my $branch_name;
my $git_command = "git log";
my $git_cherry;
my $git_args = "";
my $branch_name;
my @git_args;
my %data;
my $print_mode = "normal";
@ -477,11 +526,14 @@ foreach my $arg (@ARGV) {
$generate_log{"bugs-numbers"} = 1;
} elsif ($arg eq '--rev-list') {
$git_command = "git rev-list --pretty=medium"
} elsif ($arg eq '--cherry') {
$git_command = "git log";
$git_cherry = 1;
} else {
if (! defined $top_dir) {
$top_dir=$arg;
} else {
push @git_args, $arg;
$git_args .= " $arg";
}
}
}
@ -498,8 +550,6 @@ if ($module) {
$module_dirname{$module} = $name;
}
$git_command .= " " . join ' ', @git_args if (@git_args);
(defined $top_dir) || die "Error: top directory is not defined\n";
(-d "$top_dir") || die "Error: not a directory: $top_dir\n";
(-f "$top_dir/.git/config") || die "Error: can't find $top_dir/.git/config\n";
@ -510,7 +560,7 @@ $git_command .= " " . join ' ', @git_args if (@git_args);
$branch_name = get_branch_name($top_dir);
load_data(\%data, $top_dir, \%module_dirname, $branch_name, $git_command);
load_data(\%data, $top_dir, \%module_dirname, $branch_name, $git_command, $git_cherry, $git_args);
generate_log(\%data, \&print_commits, $log_dir, "commits", $log_suffix, $top_dir, $branch_name, 0) if (defined $generate_log{"commits"});
generate_log(\%data, \&print_bugs, $log_dir, "bugs", $log_suffix, $top_dir, $branch_name, 0) if (defined $generate_log{"bugs"});