#!/usr/bin/perl # parses git-whatchanged output and then # sets the mtime for all the files # copyleft GPL use strict; use HTTP::Date; # my $string = time2str($time); # Format as GMT ASCII time # my $now = str2time($string); # convert ASCII date to machine time my $oldest = localtime(); my %allfiles; my $time; # make a hash of all the files foreach my $file ( split "\n", `git-ls-files` ) { chomp $file; $allfiles{ $file } = 0; } # get the newest mtime for each one foreach my $line ( `git-whatchanged` ) { chomp $line; my @parts = split " ", $line; if( $parts[0] eq "Date:" ) { shift @parts; pop @parts; $time = str2time( join " ", @parts ); next; } if( $line =~ /^:/ ) { my $name = pop @parts; if( $allfiles{ $name } lt $time ) { # print "$name was $allfiles{ $name } now: $time\n"; $allfiles{ $name } = $time; } if( $time lt $oldest ) { $oldest = $time; } } } # set the mtime for each one foreach my $name ( sort keys %allfiles ) { if ( $allfiles{$name} eq 0 ) { # print "$name mtime $allfiles{$name}\n"; utime $oldest, $oldest, $name; } else { # print "$name mtime $allfiles{$name}\n"; utime $allfiles{$name}, $allfiles{$name}, $name; } }