Re: mtimes of working files

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Eric Wong
Date: Wednesday, July 11, 2007 - 11:26 pm

Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:

I'll have to admit that most of my git usage is via git-svn, so I
mostly deal with linear history and some branching, but no real merges
in a git sense.

This is what I whipped up the other night:

http://yhbt.net/git-set-file-times

-----------------------------------8<-----------------------------------------
#!/usr/bin/perl -w
use strict;

# sets mtime and atime of files to the latest commit time in git
#
# This is useful for serving static content (managed by git)
# from a cluster of identically configured HTTP servers.  HTTP
# clients and content delivery networks can get consistent
# Last-Modified headers no matter which HTTP server in the
# cluster they hit.  This should improve caching behavior.
#
# This does not take into account merges, but if you're updating
# every machine in the cluster from the same commit (A) to the
# same commit (B), the mtimes will be _consistent_ across all
# machines if not necesarily accurate.
#
# THIS IS NOT INTENDED TO OPTIMIZE BUILD SYSTEMS SUCH AS 'make'
# YOU HAVE BEEN WARNED!

my %ls = ();
my $commit_time;

$/ = "\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 (/^committer .*? (\d+) (?:[\-\+]\d+)$/) {
		$commit_time = $1;
	} elsif (s/\0\0commit [a-f0-9]{40}$//) {
		my @files = delete @ls{split(/\0/, $_)};
		@files = grep { defined $_ } @files;
		next unless @files;
		utime $commit_time, $commit_time, @files;
	}
	last unless %ls;

}
close FH;
-----------------------------------8<-----------------------------------------

-- 
Eric Wong
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
mtimes of working files, Yakov Lerner, (Wed Jul 11, 8:08 am)
Re: mtimes of working files, Johannes Schindelin, (Wed Jul 11, 11:05 am)
Re: mtimes of working files, Yakov Lerner, (Wed Jul 11, 11:36 am)
Re: mtimes of working files, Johannes Schindelin, (Wed Jul 11, 11:42 am)
Re: mtimes of working files, Jan Hudec, (Wed Jul 11, 1:26 pm)
Re: mtimes of working files, Eric Wong, (Wed Jul 11, 11:26 pm)
Re: mtimes of working files, Andy Parkins, (Thu Jul 12, 12:57 am)
Re: mtimes of working files, Randal L. Schwartz, (Thu Jul 12, 6:05 am)
Re: mtimes of working files, David Woodhouse, (Thu Jul 12, 10:27 am)
Re: mtimes of working files, Eric Wong, (Thu Jul 12, 11:25 am)
Re: mtimes of working files, Theodore Tso, (Thu Jul 12, 5:37 pm)
Re: mtimes of working files, David Woodhouse, (Fri Jul 13, 4:00 pm)
Re: mtimes of working files, Linus Torvalds, (Fri Jul 13, 4:18 pm)
Re: mtimes of working files, David Woodhouse, (Fri Jul 13, 4:46 pm)
Re: mtimes of working files, Linus Torvalds, (Fri Jul 13, 5:10 pm)
Re: mtimes of working files, David Woodhouse, (Fri Jul 13, 5:36 pm)
Re: mtimes of working files, J. Bruce Fields, (Fri Jul 13, 5:44 pm)
Re: mtimes of working files, David Woodhouse, (Fri Jul 13, 5:49 pm)
Re: mtimes of working files, Julian Phillips, (Sat Jul 14, 6:09 am)
Re: mtimes of working files, Robin Rosenberg, (Sat Jul 14, 6:23 am)
Re: mtimes of working files, Jan Hudec, (Sat Jul 14, 3:22 pm)
Re: mtimes of working files, Julian Phillips, (Sat Jul 14, 3:36 pm)
Re: mtimes of working files, Daniel Barkalow, (Sat Jul 14, 6:46 pm)