Re: Git on Windows, CRLF issues

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jeff King
Date: Monday, April 21, 2008 - 7:39 pm

On Mon, Apr 21, 2008 at 05:53:34PM -0400, Avery Pennarun wrote:


Yes, a tree filter would probably be quite slow due to checking out, and
then munging all of the files.

You could maybe do an index filter that gets the blob SHA1 of each file
that is new, and just munges those. But I think it is even simpler to
just keep a cache of original blob hashes mapping to munged blob hashes.

Something like:

  git filter-branch --index-filter '
    git ls-files --stage |
    perl /path/to/caching-munger |
    git update-index --index-info
  '

where your caching munger looks something like:

-- >8 --
#!/usr/bin/perl

use strict;
use DB_File;
use Fcntl;
tie my %cache, 'DB_File', "$ENV{HOME}/filter-cache", O_RDWR|O_CREAT, 0666
  or die "unable to open db: $!";

while(<>) {
  my ($mode, $hash, $path) = /^(\d+) ([0-9a-f]{40}) \d\t(.*)/
    or die "bad ls-files line: $_";
  $cache{$hash} = munge($hash)
    unless exists $cache{$hash};
  print "$mode $cache{$hash}\t$path\n";
}

sub munge {
  my $h = shift;
  my $r = scalar `git show $h | sed 's/\$/\\r/' | git hash-object -w --stdin`;
  chomp $r;
  return $r;
}
-- 8< --

so we keep a dbm of the hash mapping, and do no work if we have already
seen this blob. If we don't, then we actually do the expensive 'show |
munge | hash-object'. And here our munge adds a CR, but you should be
able to do an arbitrary transformation.

-Peff
--
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:
Git on Windows, CRLF issues, Peter Karlsson, (Mon Apr 21, 12:48 pm)
Re: Git on Windows, CRLF issues, Johannes Schindelin, (Mon Apr 21, 1:07 pm)
Re: Git on Windows, CRLF issues, Jakub Narebski, (Mon Apr 21, 2:51 pm)
Re: Git on Windows, CRLF issues, Avery Pennarun, (Mon Apr 21, 2:53 pm)
Re: Git on Windows, CRLF issues, Jeff King, (Mon Apr 21, 7:39 pm)
Re: Git on Windows, CRLF issues, Johannes Sixt, (Mon Apr 21, 11:31 pm)
Re: Git on Windows, CRLF issues, Johannes Sixt, (Mon Apr 21, 11:41 pm)
Re: Git on Windows, CRLF issues, Peter Karlsson, (Mon Apr 21, 11:52 pm)
Re: Git on Windows, CRLF issues, Peter Karlsson, (Tue Apr 22, 1:42 am)
Re: Git on Windows, CRLF issues, Johannes Sixt, (Tue Apr 22, 2:04 am)
Re: Git on Windows, CRLF issues, Avery Pennarun, (Tue Apr 22, 9:51 am)
Re: Git on Windows, CRLF issues, Peter Karlsson, (Wed Apr 23, 12:11 am)
Re: Git on Windows, CRLF issues, Jeff King, (Wed Apr 23, 1:08 am)
Re: Git on Windows, CRLF issues, Jeff King, (Wed Apr 23, 1:10 am)
Re: Git on Windows, CRLF issues, Johannes Schindelin, (Wed Apr 23, 3:13 am)
Re: Git on Windows, CRLF issues, Jeff King, (Wed Apr 23, 3:58 am)
Re: Git on Windows, CRLF issues, Johannes Sixt, (Wed Apr 23, 3:58 am)
Re: Git on Windows, CRLF issues, Jeff King, (Wed Apr 23, 4:04 am)
Re: Git on Windows, CRLF issues, Johannes Sixt, (Wed Apr 23, 4:46 am)
Re: Git on Windows, CRLF issues, Peter Karlsson, (Wed Apr 23, 6:47 am)
Re: Git on Windows, CRLF issues, Johan Herland, (Wed Apr 23, 7:24 am)
Re: Git on Windows, CRLF issues, Johannes Sixt, (Wed Apr 23, 8:12 am)
Re: Git on Windows, CRLF issues, Avery Pennarun, (Wed Apr 23, 1:02 pm)
Re: Git on Windows, CRLF issues, Jeff King, (Wed Apr 23, 2:47 pm)
Re: Git on Windows, CRLF issues, Junio C Hamano, (Wed Apr 23, 4:01 pm)
Re: Git on Windows, CRLF issues, Avery Pennarun, (Wed Apr 23, 4:04 pm)
Re: Git on Windows, CRLF issues, Jeff King, (Wed Apr 23, 6:37 pm)
Re: Git on Windows, CRLF issues, Johannes Sixt, (Wed Apr 23, 11:25 pm)
Re: Git on Windows, CRLF issues, Johannes Schindelin, (Thu Apr 24, 1:11 am)
Re: Git on Windows, CRLF issues, Avery Pennarun, (Thu Apr 24, 9:56 am)