g2p / git-fs

A filesystem interface to git repositories
GNU General Public License v2.0
234 stars 19 forks source link

[Feature Request] file's last-modified time based on its last commit #4

Closed timgreen closed 13 years ago

timgreen commented 13 years ago

For now, the last modified time has been set to the time user mount git-fs. I'd like to see file's last-modified time based on its last commit. Which will be more useful (then my webserver can return correct last-modified header).

Thank you.


FYI Here is a script from rsync can modify the time locally git://git.samba.org/rsync.git

#!/usr/bin/perl
use strict;
use warnings;

# Sets mtime and atime of files to the latest commit 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 $commit_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 (/^committer .*? (\d+) (?:[\-\+]\d+)$/) {
    $commit_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 $commit_time, $commit_time, @files;
    }
    last unless %ls;
}
close FH;
g2p commented 13 years ago

That does not fit the git data model. Blobs don't depend on commits, and walking an open-ended commit graph to find the oldest commit referencing a blob would be fragile and slow.

HTTP provides etags, they are a much better solution to cache these files. The real path (after symlink resolution) of a blob contains a hash of the blob contents and can be used as a cache key.

timgreen commented 13 years ago

Cool, you are right. thanks g2p. Please close this