diff options
author | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2016-01-24 03:47:32 +0100 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2016-01-24 03:47:32 +0100 |
commit | c803493e75a1964c6463286e9d37a5e76c1fc8a9 (patch) | |
tree | 8f65184933dbb3d35df6a17d778146d77831f79e | |
parent | 942698cabd574a232a39301b471dc7da38dd11c7 (diff) |
Bin old commit analyzer in favour of mr
-rwxr-xr-x | analyse_commits | 265 |
1 files changed, 0 insertions, 265 deletions
diff --git a/analyse_commits b/analyse_commits deleted file mode 100755 index 286a5d57..00000000 --- a/analyse_commits +++ /dev/null @@ -1,265 +0,0 @@ -#!/usr/bin/perl -w - -use strict; - -my $app_path; -my $cwd; -my $git_dir; -my $reuse_log = 0; -my $dump_numstat = 0; -my $show_note_tags = 0; -my $apache_svn_git_repo = 0; -my ($config_dir, $gitdm_path, $output_dir); - - -my $dump_numstat_cmd = "git --no-pager log --numstat --pretty='%H,%ae,%ai,%ce,%f'"; - -sub usage() -{ - print "build-stats [options...] <path to 'core' git checkout>\n"; - print "generates stats on a libreoffice checkout using gitdm, with auto-detection\n"; - print "of repository type and completeness if you pass a single directory path\n"; - print " -n, --show-tags show legacy (note) tags extracted from notes and exit\n"; - print " -c, --config-dir <dir> (optional) path to the config for gitdm and this script\n"; - print " -d, --dump-numstat dump numstat log on stdout in a given format\n"; - print " -r, --reuse-log <log> re-use an existing intermediate commit log file\n"; - print " -g, --gitdm-path <path> path to the gitdm binary to use\n"; - print " -o, --output-dir <dir> path to an output directory to drop data into\n"; - print " -w, --weekly generate statistic on a weekly basis\n"; - print " -h, --help prints this\n"; - print "build-stats - generates statistics on a libreoffice checkout using gitdm\n"; - - exit (1); -} - -sub infer_optional_variables() -{ - if (!defined $config_dir) { - $config_dir = $app_path; - print "config:\t$config_dir\n"; - } - - $config_dir =~ m/^\// || die "need absolute config path '$config_dir'"; - - if (!defined $gitdm_path) { - chomp ($gitdm_path = `which gitdm 2>/dev/null`); - my $try = "$config_dir/../gitdm/gitdm"; - - if ($gitdm_path ne "" && -x $gitdm_path) { - print "gitdm:\t$gitdm_path\n"; - } else { - $gitdm_path = ''; - if (-x $try) { - print "gitdm:\t$try\n"; - $gitdm_path = $try; - } - } - } - - if ($gitdm_path eq '') { - print "\nError: gitdm not found - use -g to specify its path\n\n"; - usage(); - } - -x $gitdm_path || die "\nError: $gitdm_path not executable\n\n"; - - my ($weekno, $year); - chomp ($weekno=`date +%W`); - chomp ($year=`date +%Y`); - if (!defined $output_dir) { - $output_dir = "$cwd/stats-" . $year . "-" . $weekno; - print "output:\t$output_dir\n"; - } -} - -sub is_git_repo($) -{ - my $repo = shift; - return -f "$repo/.git/config"; -} - -sub sanity_check_git_dir($) -{ - my $core = shift; - print "checking git dir at: $core\n"; - is_git_repo ($core) || die "$core is not a valid git repo"; - -d "$core/clone" || die "expected directory $core/clone for sub-repositories"; - - my $error = 0; - my @required = ( 'online' ); - for my $expect (@required) { - my $dir = "$core/clone/$expect"; - if (!is_git_repo ($dir)) { - print "\n" if (!$error); - print "Error: missing git repo '$expect' in: $core/clone.\n"; - $error = 1; - } - print " found: $dir\n"; - } - $error && die "please checkout missing git repositories before continuing"; -} - -# build a list of hashes for all the revisions - -my %check_queries; -sub read_rev_list($$$) -{ - my ($git_dir, $descr, $query) = @_; - my $outputh; - my @revs; - - print "\tquery: $descr ($query), against $git_dir\n"; - - chdir ($git_dir); - open ($outputh, "git rev-list --timestamp $query |") || die "can't open git rev-list"; - while (<$outputh>) { - my %commit; - /^(\d+)\s+(.*)$/ || die "invalid git rev-list output: $_ on repo $git_dir with query $query\n"; - my ($t, $hash) = ($1, $2); - $commit{'t'} = $t; - $commit{'hash'} = $hash; - $commit{'repo'} = $git_dir; - push @revs, \%commit; - if (defined $check_queries{$hash}) { - die "Duplicate hash $hash between query $query and " . $check_queries{$hash} . "\n"; - } - $check_queries{$hash} = $query; - } - close ($outputh); - return @revs; -} - - -# Extraction and merging of git logs ... -sub merge_logs ($$@) -{ - my $log = shift; - my $git_dir = shift; - my $just_core_numstat = shift; - - # quick & easy for apache git-svn integration - if ($apache_svn_git_repo) { - chdir ($git_dir); - system ("git --no-pager log -u > $log") && die "failed to generate apache git log"; - return; - } - - my @revisions; - - print STDERR "reading revisions\n"; - # recent work on core ... - if (defined ($just_core_numstat)) { - system("cd $git_dir ; $dump_numstat_cmd MELD_LIBREOFFICE_REPOS.."); - exit (0); - } else { - push @revisions, read_rev_list ("$git_dir/clone/online", "online", "d106b7cb3a962ef33fb28c9fb49b4858beafc817.."); - # magic from: git log --since 2013-01-01 | grep 'commit ' | tail -n 1 - push @revisions, read_rev_list ($git_dir, "core", "ffaf6adba6da2af0bd9ceb7f94b4e4eff055ae20.."); - } - - my $revcount = @revisions; - print "sorting $revcount revisions\n"; - @revisions = sort {$a->{'t'} <=> $b->{'t'}} @revisions; - - print "extracting patches one by one...\n"; - my $count = 0; - my $percent_divs = ($revcount + 9) / 10; - for my $rev (@revisions) { - $count++; - print "\t" . int($count/$revcount * 100) . "%\n" if ($count % $percent_divs == 0); - chdir ($rev->{'repo'}); - system ("git --no-pager log -1 -p " . $rev->{'hash'} . " >> $log") && die "failed to extract git hash: " . $rev->{'hash'} . "\n"; - } -} - -# main - starts ... - -while (my $arg = shift @ARGV) { - if ($arg =~ /--reuse-log/ || $arg eq "-r") { - $reuse_log = shift @ARGV; - } elsif ($arg =~ /--show-tags/ || $arg eq "-n") { - $show_note_tags = 1; - } elsif ($arg =~ /--config-dir/ || $arg eq '-c') { - $config_dir = shift @ARGV; - } elsif ($arg =~ /--gitdm-path/ || $arg eq '-g') { - $gitdm_path = shift @ARGV; - } elsif ($arg =~ /--output-dir/ || $arg eq '-o') { - $output_dir = shift @ARGV; - } elsif ($arg =~ /--dump-numstat/ || $arg eq '-d') { - $dump_numstat = 1; - } elsif ($arg =~ /--help/ || $arg eq '-h') { - usage(); - } elsif (!defined ($git_dir)) { - $git_dir = $arg; - } else { - usage(); - } -} - -if (! defined $git_dir) { - print "\nError: a git directory is required\n\n"; - usage(); -} - -if ($dump_numstat) { - merge_logs ("/dev/stdout", $git_dir, 'core numstat'); - exit; -} - -chomp ($cwd = `pwd`); -$app_path = $0; -$app_path =~ s/\/[^\/]*$//; -$app_path = "$cwd/$app_path" if ($app_path =~ /^[^\/]/); -print "app path $app_path\n"; - -infer_optional_variables(); - -if (-f "$git_dir/rat-excludes") { # it is Apache - $apache_svn_git_repo = 1; - $output_dir = $output_dir . "-apache"; -} else { - sanity_check_git_dir ($git_dir); -} - -system ("git --version") && die "Can't find git executable in path: $!"; - --d $output_dir || mkdir $output_dir || die "Can't create output dir: $!"; - -# extract the right commit logs -my $log; -if (!$reuse_log) { - $log = "$output_dir/all-lo.log"; - unlink ($log); - - merge_logs ($log, $git_dir); -} else { - $log = $reuse_log; -} -unlink ("$output_dir/hackers.csv"); -unlink ("$output_dir/hackers.csv.bak"); -unlink ("$output_dir/git-hackers-data.csv"); -unlink ("$output_dir/git-hackers-reports.txt"); -unlink ("$output_dir/git-hackers-data.csv.bak"); - --f $log || die "Failed to generate commit log: $log\n"; - -# Analyze the commit logs -print "analyse output using gitdm\n"; -my $gitdmfh; -chdir ($config_dir); -my $cmd = "cat $log | $gitdm_path -u -X '\.(sdf|po|dic)\$'" . - " -b $config_dir" . - " -x $output_dir/git-hackers-data.csv" . - " -o $output_dir/git-hackers-reports.txt" . - " -H $output_dir/hackers.csv"; -open ($gitdmfh, "$cmd |") || die "Can't spawn $cmd: $!"; -while (<$gitdmfh>) { - print $_; # log output -} -close ($gitdmfh) || die "$cmd: command failed"; - -for my $f ("$output_dir/git-hackers-data.csv", "$output_dir/hackers.csv") { - print "final sed csv output '$f'\n"; - system ("sed -i.bak 's/(Unknown)/Assigned/' $f") && die "failed to sed: $!"; -} -print "done.\n"; - |