Last active
September 4, 2021 00:39
-
-
Save hrkokw/c618790419e025ca1c6ce7f45d3891db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
# Based on git-set-file-times in Git SCM Wiki | |
# https://git.wiki.kernel.org/index.php/ExampleScripts | |
# | |
# Sets mtime and atime of files to the latest author time in git. | |
# | |
# This is useful after the first clone of the rsync repository BEFORE you | |
# do any building. It is also safe if you have done a "make distclean". | |
my %ls; | |
my $author_time; | |
my $prefix = @ARGV && $ARGV[0] =~ s/^--prefix=// ? shift : ''; | |
$/ = "\0"; | |
open FH, 'git ls-files -z|' or die $!; | |
while (<FH>) { | |
chomp; | |
$ls{$_} = $_; | |
} | |
close FH; | |
$/ = "\n"; | |
open FH, "git log -r --name-only --no-color --pretty=raw -z @ARGV |" or die $!; | |
while (<FH>) { | |
chomp; | |
if (/^author .*? (\d+) (?:[\-\+]\d+)$/) { | |
$author_time = $1; | |
} elsif (s/\0\0commit [a-f0-9]{40}$// or s/\0$//) { | |
my @files = delete @ls{split(/\0/, $_)}; | |
@files = grep { defined $_ } @files; | |
next unless @files; | |
map { s/^/$prefix/ } @files; | |
utime $author_time, $author_time, @files; | |
} | |
last unless %ls; | |
} | |
close FH; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment