git-set-file-times 899 B

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