-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimediff
executable file
·37 lines (33 loc) · 1.05 KB
/
timediff
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
#!/usr/bin/perl -w
# Read the whole time log
my %timelog;
open TIMELOG, "< .timelog";
while (<TIMELOG>) {
next unless /(.*?):(.*?) (.*?) (.*?) (.*?)/;
$timelog{$1}{$2} = $3 + $4;
}
close TIMELOG;
# Use git rev-parse to analyse the command line
sub rev_parse ($) {
my ($rev, $plus) = ($_[0] =~ /^(.*?)(\+?)$/);
$rev = `git rev-parse --short $rev`;
$rev or die "Usage: ./timediff [<before-rev> [<after-rev>]]";
chomp $rev;
return $rev . $plus;
}
# Obtain the revisions of interest
my $pending = `git status --porcelain --untracked=no` ? 1 : 0;
my $bspec = defined($ARGV[0]) ? $ARGV[0] : $pending ? "HEAD" : "HEAD^";
my $aspec = defined($ARGV[1]) ? $ARGV[1] : $pending ? "HEAD+" : "HEAD";
# Print the differences
my $bef = rev_parse($bspec);
my $aft = rev_parse($aspec);
my $total = 0;
print STDERR "Showing differences between $bef..$aft\n";
foreach (sort keys(%{$timelog{$bef}})) {
next unless exists $timelog{$aft}{$_};
my $diff = $timelog{$aft}{$_} - $timelog{$bef}{$_};
printf "%s: %+.2f\n", $_, $diff;
$total += $diff;
}
printf "total: %+.2f\n", $total;