blob: 85d854e883988a699ddfef2c833bec00b1dce470 [file] [log] [blame]
Dmitry V. Levin81dfcfb2009-10-09 23:07:12 +00001#!/usr/bin/perl -w
2use 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
9my %ls;
10my $commit_time;
11my $prefix = @ARGV && $ARGV[0] =~ s/^--prefix=// ? shift : '';
12
13$/ = "\0";
14open FH, 'git ls-files -z|' or die $!;
15while (<FH>) {
16 chomp;
17 $ls{$_} = $_;
18}
19close FH;
20
21$/ = "\n";
22open FH, "git log -r --name-only --no-color --pretty=raw -z @ARGV |" or die $!;
23while (<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}
36close FH;