Home | History | Annotate | Download | only in strace
      1 #!/usr/bin/perl -w
      2 use strict;
      3 
      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 
      9 my %ls;
     10 my $commit_time;
     11 my $prefix = @ARGV && $ARGV[0] =~ s/^--prefix=// ? shift : '';
     12 
     13 $/ = "\0";
     14 open FH, 'git ls-files -z|' or die $!;
     15 while (<FH>) {
     16     chomp;
     17     $ls{$_} = $_;
     18 }
     19 close FH;
     20 
     21 $/ = "\n";
     22 open FH, "git log -r --name-only --no-color --pretty=raw -z @ARGV |" or die $!;
     23 while (<FH>) {
     24     chomp;
     25     if (/^committer .*? (\d+) (?:[\-\+]\d+)$/) {
     26 	$commit_time = $1;
     27     } elsif (s/\0\0commit [a-f0-9]{40}$// or s/\0$//) {
     28 	my @files = delete @ls{split(/\0/, $_)};
     29 	@files = grep { defined $_ } @files;
     30 	next unless @files;
     31 	map { s/^/$prefix/ } @files;
     32 	utime $commit_time, $commit_time, @files;
     33     }
     34     last unless %ls;
     35 }
     36 close FH;
     37