-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp4-blame
executable file
·71 lines (56 loc) · 1.75 KB
/
p4-blame
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
#!/usr/bin/env perl
# p4-blame --- extended p4 annotate
# Author: Noah Friedman <[email protected]>
# Created: 2013-02-26
# Public domain
# $Id: p4-blame,v 1.6 2017/07/07 01:21:30 friedman Exp $
# Commentary:
# Code:
use strict;
use warnings qw(all);
use POSIX qw(strftime);
use FindBin;
use lib "$FindBin::Bin/../lib/perl";
use lib "$ENV{HOME}/lib/perl";
use NF::P4cmd qw(:direct);
sub log10 { log ($_[0]) / log (10) }
sub uniq { my %x = map { $_ => undef } @_; keys %x }
sub main
{
my @data = p4 (qw(annotate -c -db -dw -dl), @_);
my @cmd = map { "change -o $_" } uniq (map { $_->{lower} || () } @data);
my %change = map { $_->{Date} = substr ($_->{Date}, 0, 10);
$_->{Change} => $_
} p4 (\@cmd, "-b", scalar @cmd, "run");
undef @cmd; # gc
my $nfiles = grep { exists $_->{depotFile} } @data;
my $fcount = 0;
my $line = 1;
my $linewidth = 1 + int (log10 (scalar @data));
my $fmt = sprintf ("%%7d %%s %%-9s %%%dd: %%s", $linewidth);
for my $elt (@data)
{
$elt->{data} .= "\n"
if (defined $elt->{data} && substr ($elt->{data}, -1, 1) ne "\n");
if ($elt->{code} eq 'error')
{
print STDERR $elt->{data};
next;
}
elsif (exists $elt->{depotFile}) # new file
{
$line = 1;
print "\n" if $fcount++ > 0;
printf("%s#%s - %s %s (%s) %s\n",
@{$elt}{qw(depotFile rev action change type)},
strftime ("%Y-%m-%d %H:%M:%S", localtime ($elt->{time})))
if $nfiles > 1;
next;
}
my $changeno = $elt->{lower};
my $info = $change{$changeno};
printf($fmt, $changeno, $info->{Date}, $info->{User}, $line++, $elt->{data});
}
}
main (@ARGV);
# eof