]> granicus.if.org Git - strace/blob - git-set-file-times
tests: add ioctl_evdev-success* test binaries to .gitignore
[strace] / git-set-file-times
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
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 my $top_dir = `git rev-parse --show-toplevel`;
15 exit 1 unless $top_dir;
16 chomp($top_dir);
17
18 chdir $top_dir or die "Failed to chdir to $top_dir\: $!\n";
19
20 $/ = "\0";
21 open FH, '-|', qw( git ls-files -z ) or die "Failed to fork: $!";
22 while (<FH>) {
23     chomp;
24     $ls{$_} = $_;
25 }
26 close FH;
27
28 $/ = "\n";
29 open FH, '-|', qw( git log -r --name-only --no-color --pretty=raw -z ), @ARGV or die "Failed to fork: $!";
30 while (<FH>) {
31     chomp;
32     if (/^committer .*? (\d+) (?:[\-\+]\d+)$/) {
33         $commit_time = $1;
34     } elsif (s/\0\0commit [a-f0-9]{40}$// || s/\0$//) {
35         my @files = delete @ls{split(/\0/, $_)};
36         @files = grep { defined $_ } @files;
37         next unless @files;
38         map { s/^/$prefix/ } @files;
39         utime $commit_time, $commit_time, @files;
40     }
41     last unless %ls;
42 }
43 close FH;