File: git-blame-stats

package info (click to toggle)
hxtools 20221119-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,760 kB
  • sloc: ansic: 5,114; perl: 3,612; cpp: 2,727; sh: 1,622; makefile: 156
file content (42 lines) | stat: -rwxr-xr-x 1,078 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl
# SPDX-License-Identifier: MIT
#
#	git-blame based authoring statistics
#	written by Jan Engelhardt, 2009

use Getopt::Long;
use POSIX qw(ceil);
use strict;
Getopt::Long::Configure(qw(bundling));
my %authors;
my $total;
my $files;
my $rev = shift(@ARGV) || "HEAD";
my $zargs = join(" ", @ARGV);

foreach my $file (`git ls-tree --name-only -r $rev $zargs`) {
	chomp($file);
	print STDERR "Processing $file\n";
	foreach my $line (`git blame -M -w $rev -- "$file"`) {
		chomp($line);
		if (substr($line, 0, 1) eq "^") {
			++$authors{"*initial checkin"};
		} else {
			$line =~ s[^.*?\((.*?)\s*\d{4}-\d{2}-\d{2}.*][$1];
			++$authors{$line};
		}
		++$total;
	}
}

print "Total lines: $total\n";
my $i = 0;
my $author_ind = ceil(log(scalar(keys %authors)) / log(10));
my $lines_ind  = ceil(log($total) / log(10));
foreach my $author (sort { $authors{$b} <=> $authors{$a} } keys %authors) {
	printf "%${author_ind}s  %${lines_ind}u  %5.2f%%  %s\n",
	       sprintf("#%u", ++$i),
	       $authors{$author},
	       $authors{$author} * 100 / $total,
	       $author;
}