aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNao Ueda <nao.uedder@gmail.com>2021-02-05 21:32:49 +0900
committerNao Ueda <nao.uedder@gmail.com>2021-02-06 11:01:07 +0900
commitcfdc7552882c0c3a55d1af3ac29938f7324a95a2 (patch)
tree647886fce1a5085cf5fb8bad644f9cd903c2c196
downloadgit-file-changed-time-getter-cfdc7552882c0c3a55d1af3ac29938f7324a95a2.tar.gz
git-file-changed-time-getter-cfdc7552882c0c3a55d1af3ac29938f7324a95a2.tar.bz2
git-file-changed-time-getter-cfdc7552882c0c3a55d1af3ac29938f7324a95a2.zip
initial commit
-rw-r--r--time-getter.pl69
1 files changed, 69 insertions, 0 deletions
diff --git a/time-getter.pl b/time-getter.pl
new file mode 100644
index 0000000..5335fbd
--- /dev/null
+++ b/time-getter.pl
@@ -0,0 +1,69 @@
+#!/usr/bin/env perl
+
+use strict;
+
+open (F, 'git ls-tree -r HEAD|');
+
+my %list;
+
+# 辞書作る
+while (<F>) {
+ my @info = split /\s+/;
+
+ my $filename = $info[-1];
+ my $hash = $info[-2];
+
+ $list{$filename} = $hash;
+}
+
+close(F);
+
+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 |");
+
+ while (<BLOBS>) {
+ my @tmp = split(/\s+/);
+ my $filename = $tmp[-1];
+ my $blobhash = $tmp[-2];
+
+ if (!$list{$filename}) {
+ next;
+ }
+
+ if ($list{$filename} !~ /$blobhash/) {
+ print $filename . ": " . $prevtimestamp . " \n";
+ delete ($list{$filename});
+ }
+ }
+
+ $prevtimestamp = $timestamp;
+
+ close (BLOBS);
+}
+
+close (COMMITS);