diff options
author | Nao Ueda <nao.uedder@gmail.com> | 2021-02-06 09:20:58 +0900 |
---|---|---|
committer | Nao Ueda <nao.uedder@gmail.com> | 2021-02-06 11:01:12 +0900 |
commit | 5d9a4e18c8d5fe7f80e302a5f2439f219d50a39d (patch) | |
tree | d14907a7241ede35ef5659b045b95bcea9cbf04e | |
parent | 8e6a3c1c7269786cb43688cba0e016cd1c68e6cd (diff) | |
download | git-file-changed-time-getter-5d9a4e18c8d5fe7f80e302a5f2439f219d50a39d.tar.gz git-file-changed-time-getter-5d9a4e18c8d5fe7f80e302a5f2439f219d50a39d.tar.bz2 git-file-changed-time-getter-5d9a4e18c8d5fe7f80e302a5f2439f219d50a39d.zip |
refactoring
-rw-r--r-- | time-getter.pl | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/time-getter.pl b/time-getter.pl index 7a29ba5..7daafa0 100644 --- a/time-getter.pl +++ b/time-getter.pl @@ -2,39 +2,38 @@ use strict; -open (F, 'git ls-tree -r HEAD|'); +open (TREES, 'git ls-tree -r HEAD|'); -my %list; -my %all_file; +my %blob_hash; +my %files_should_print; -# 辞書作る -while (<F>) { +# make the HEAD tree info +while (<TREES>) { my @info = split /\s+/; my $filename = $info[-1]; my $hash = $info[-2]; - $list{$filename} = $hash; - $all_file{$filename} = 1; + $blob_hash{$filename} = $hash; + $files_should_print{$filename} = 1; } -close(F); +close(TREES); $? and die; open (COMMITS, 'git rev-list HEAD |'); -# timestamp 取りつつ tree を get -my $prevtimestamp; -my $timestamp; +my $prev_timestamp; while (<COMMITS>) { - my $commit = $_; + (keys %files_should_print) or last; - (keys %list) or last; + my $commit = $_; - open (TMP, 'git cat-file -p ' . $commit . '|'); + open (COMMIT_CONTENT, 'git cat-file -p ' . $commit . '|'); my $tree; - while (<TMP>) { + my $timestamp; + while (<COMMIT_CONTENT>) { if (/tree/) { my @tmp = split /\s+/; $tree = $tmp[1]; @@ -46,11 +45,11 @@ while (<COMMITS>) { last; } } - close(TMP); + close(COMMIT_CONTENT); open (BLOBS, "git ls-tree -r $tree |"); - my %remained = %all_file; + my %remained = %files_should_print; while (<BLOBS>) { my @tmp = split(/\s+/); my $filename = $tmp[-1]; @@ -60,36 +59,35 @@ while (<COMMITS>) { delete $remained{$filename}; } - if (!$list{$filename}) { + if (!$files_should_print{$filename}) { next; } - if ($list{$filename} !~ /$blobhash/) { - do_print($filename, $prevtimestamp); + if ($blob_hash{$filename} !~ /$blobhash/) { + do_print($filename, $prev_timestamp); } } foreach my $filename (keys(%remained)) { - do_print($filename, $prevtimestamp); + do_print($filename, $prev_timestamp); } - $prevtimestamp = $timestamp; + $prev_timestamp = $timestamp; close (BLOBS); } # For files that never changed from the root commit. -foreach my $filename (keys(%all_file)) { - do_print($filename, $prevtimestamp); +foreach my $filename (keys(%files_should_print)) { + do_print($filename, $prev_timestamp); } sub do_print() { my ($filename, $timestamp) = @_; print $filename . "\t" . $timestamp . " \n"; - delete ($list{$filename}); - delete ($all_file{$filename}); + delete ($files_should_print{$filename}); } close (COMMITS); |