aboutsummaryrefslogtreecommitdiff
path: root/time-getter.pl
blob: a42be3364ed9c28235c743c074574379fbae5aad (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
#!/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/) {
            print $filename . "\t" . $prevtimestamp . " \n";
            delete ($list{$filename});
            delete ($all_file{$filename});
        }
    }

    foreach my $filename (keys(%remained)) {
        print $filename . "\t" . $prevtimestamp . " \n";
        delete ($list{$filename});
        delete ($all_file{$filename});
    }

    $prevtimestamp = $timestamp;

    close (BLOBS);
}

close (COMMITS);