Adding a support script that can be used to make the checked-out
[rsync.git] / support / git-set-file-times
blob9ddef25f82579466f959ec9d311bb6b0178913bc
1 #!/usr/bin/perl -w
2 use strict;
4 # Sets mtime and atime of files to the latest commit time in git.
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".
9 my %ls;
10 my $commit_time;
12 $/ = "\0";
13 open FH, 'git ls-files -z|' or die $!;
14 while (<FH>) {
15 chomp;
16 $ls{$_} = $_;
18 close FH;
20 $/ = "\n";
21 open FH, "git log -r --name-only --no-color --pretty=raw -z @ARGV |" or die $!;
22 while (<FH>) {
23 chomp;
24 if (/^committer .*? (\d+) (?:[\-\+]\d+)$/) {
25 $commit_time = $1;
26 } elsif (s/\0\0commit [a-f0-9]{40}$// or s/\0$//) {
27 my @files = delete @ls{split(/\0/, $_)};
28 @files = grep { defined $_ } @files;
29 next unless @files;
30 utime $commit_time, $commit_time, @files;
32 last unless %ls;
34 close FH;