Fixed a problem with --fake-super not getting the fully tweaked new_mode
[rsync/rsync.git] / support / git-set-file-times
CommitLineData
90c98cdc
WD
1#!/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;
11
12$/ = "\0";
13open FH, 'git ls-files -z|' or die $!;
14while (<FH>) {
15 chomp;
16 $ls{$_} = $_;
17}
18close FH;
19
20$/ = "\n";
21open FH, "git log -r --name-only --no-color --pretty=raw -z @ARGV |" or die $!;
22while (<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;
31 }
32 last unless %ls;
33}
34close FH;