Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

git-set-file-times 1.1KB

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