Dmitry V. Levin | 6363074 | 2015-01-21 20:50:32 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl |
Dmitry V. Levin | 81dfcfb | 2009-10-09 23:07:12 +0000 | [diff] [blame] | 2 | use strict; |
Dmitry V. Levin | 6363074 | 2015-01-21 20:50:32 +0000 | [diff] [blame] | 3 | use warnings; |
Dmitry V. Levin | 81dfcfb | 2009-10-09 23:07:12 +0000 | [diff] [blame] | 4 | |
| 5 | # Sets mtime and atime of files to the latest commit time in git. |
| 6 | # |
| 7 | # This is useful after the first clone of the rsync repository BEFORE you |
| 8 | # do any building. It is also safe if you have done a "make distclean". |
| 9 | |
| 10 | my %ls; |
| 11 | my $commit_time; |
| 12 | my $prefix = @ARGV && $ARGV[0] =~ s/^--prefix=// ? shift : ''; |
| 13 | |
| 14 | $/ = "\0"; |
| 15 | open FH, 'git ls-files -z|' or die $!; |
| 16 | while (<FH>) { |
| 17 | chomp; |
| 18 | $ls{$_} = $_; |
| 19 | } |
| 20 | close FH; |
| 21 | |
| 22 | $/ = "\n"; |
| 23 | open FH, "git log -r --name-only --no-color --pretty=raw -z @ARGV |" or die $!; |
| 24 | while (<FH>) { |
| 25 | chomp; |
| 26 | if (/^committer .*? (\d+) (?:[\-\+]\d+)$/) { |
| 27 | $commit_time = $1; |
| 28 | } elsif (s/\0\0commit [a-f0-9]{40}$// or s/\0$//) { |
| 29 | my @files = delete @ls{split(/\0/, $_)}; |
| 30 | @files = grep { defined $_ } @files; |
| 31 | next unless @files; |
| 32 | map { s/^/$prefix/ } @files; |
| 33 | utime $commit_time, $commit_time, @files; |
| 34 | } |
| 35 | last unless %ls; |
| 36 | } |
| 37 | close FH; |