File: git-revert-stats

package info (click to toggle)
hxtools 20201116-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,696 kB
  • sloc: ansic: 5,074; perl: 3,589; cpp: 2,152; sh: 1,610; asm: 173; makefile: 153
file content (122 lines) | stat: -rwxr-xr-x 2,539 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/perl
#
#	git-revert statistics
#	written by Jan Engelhardt, 2008
#
#	This program is free software; you can redistribute it and/or
#	modify it under the terms of the WTF Public License version 2 or
#	(at your option) any later version.
#
#	git log --pretty="format:<%an>%s" v2.6.25..HEAD | ./git-revert-stats
#
#	-n NUM    limit output to NUM developers
#	-o        omit developers with only one revert/commit
#	-v        debug debug debug output
#

use Getopt::Long;
use Git;
use strict;
no strict "subs";
use warnings;

my $stats_limit = 100;
my $verbose = 0;
my $omit_one = 0;
&Getopt::Long::Configure(qw(bundling));
&GetOptions(
	"n=i" => \$stats_limit,
	"v+"  => \$verbose,
	"o"   => \$omit_one,
);
&main();

sub main ()
{
	my $repo = Git->repository();
	my @note;
	my(%praise, %blame);

	foreach (<>) {
		my($name, $message) = ($_ =~ /^<(.*?)>(.*)/);

		if ($message =~ /^\s*revert\s*:?\s*(\"?)(.*)\1/i) {
			push(@note, [$name, $2]);
			++$praise{$name};
			if ($verbose >= 1) {
				print "\e[31m", "$name: $message", "\e[0m\n";
			}
			next;
		}

		my $idx;
		if ($idx = &array_substr_ifind(\@note, $message)) {
			++$blame{$name};
			if ($verbose >= 1) {
				print "\e[32m", "$name: $message", "\e[0m\n";
			}
			next;
		}

		if ($verbose >= 2) {
			print "\e[34m", "$name: $message", "\e[0m\n";
		}
	}

	&stats(\%praise, \%blame);
}

sub stats ()
{
	my($reverands, $developers) = @_; # pun
	my $omits;
	my $i;

	print " P#  COMM#  NAME --- Top people doing the revert:\n";
	$omits = 0;
	$i = 0;
	foreach my $name (sort { $reverands->{$b} <=> $reverands->{$a} } keys %$reverands) {
		if ($omit_one && $reverands->{$name} == 1) {
			++$omits;
			next;
		}
		if ($i > $stats_limit) {
			last;
		}
		printf "%3u  %5u  %s\n", ++$i, $reverands->{$name}, $name;
	}
	if ($omit_one && $omits > 0) {
		printf "  *  %5u developers with only one revert are omitted\n", $omits;
	}

	print "\n";
	print " P#  COMM#  NAME --- Top developers with reverted commits:\n";
	$omits = 0;
	$i = 0;
	foreach my $name (sort { $developers->{$b} <=> $developers->{$a} } keys %$developers) {
		if ($omit_one && $developers->{$name} == 1) {
			++$omits;
			next;
		}
		if ($i > $stats_limit) {
			last;
		}
		printf "%3u  %5u  %s\n", ++$i, $developers->{$name}, $name;
	}
	if ($omit_one && $omits > 0) {
		printf "  *  %5u developers with only one revert are omitted\n", $omits;
	}
}

sub array_substr_ifind ()
{
	my($note, $msg) = @_;

	foreach my $note_entry (@$note) {
		if ($msg =~ /\Q$note_entry->[1]\E/i) {
			return 1;
		}
	}

	return 0;
}