blob: 7a29ba5cfa449560fdcdc3176c17f7861e626c7d (
plain)
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
|
#!/usr/bin/env perl
use strict;
open (F, 'git ls-tree -r HEAD|');
my %list;
my %all_file;
# 辞書作る
while (<F>) {
my @info = split /\s+/;
my $filename = $info[-1];
my $hash = $info[-2];
$list{$filename} = $hash;
$all_file{$filename} = 1;
}
close(F);
$? and die;
open (COMMITS, 'git rev-list HEAD |');
# timestamp 取りつつ tree を get
my $prevtimestamp;
my $timestamp;
while (<COMMITS>) {
my $commit = $_;
(keys %list) or last;
open (TMP, 'git cat-file -p ' . $commit . '|');
my $tree;
while (<TMP>) {
if (/tree/) {
my @tmp = split /\s+/;
$tree = $tmp[1];
next
}
if (/committer/) {
my @tmp = split /\s+/;
$timestamp = $tmp[-2];
last;
}
}
close(TMP);
open (BLOBS, "git ls-tree -r $tree |");
my %remained = %all_file;
while (<BLOBS>) {
my @tmp = split(/\s+/);
my $filename = $tmp[-1];
my $blobhash = $tmp[-2];
if ($remained{$filename}) {
delete $remained{$filename};
}
if (!$list{$filename}) {
next;
}
if ($list{$filename} !~ /$blobhash/) {
do_print($filename, $prevtimestamp);
}
}
foreach my $filename (keys(%remained)) {
do_print($filename, $prevtimestamp);
}
$prevtimestamp = $timestamp;
close (BLOBS);
}
# For files that never changed from the root commit.
foreach my $filename (keys(%all_file)) {
do_print($filename, $prevtimestamp);
}
sub do_print() {
my ($filename, $timestamp) = @_;
print $filename . "\t" . $timestamp . " \n";
delete ($list{$filename});
delete ($all_file{$filename});
}
close (COMMITS);
|