Change NHtext to double the speed of "git checkout"

This commit is contained in:
keni
2015-02-28 17:52:19 -05:00
committed by Pasi Kallinen
parent 56279a9950
commit 5b4000a2e9

View File

@@ -5,30 +5,32 @@
# clean/smudge filter for handling substitutions
use strict;
my $debug = 0; # save trace to file
my $debug2 = 0; # annotate output when running from command line
#my $debug = 0; # save trace to file
#my $debug2 = 0; # annotate output when running from command line
my $sink = ($^O eq "MSWin32")? "NUL" :"/dev/null";
my $dbgfile = ($^O eq "MSWin32") ? "$ENV{TEMP}.$$" : "/tmp/trace.$$";
open TRACE, ">>", ($debug==0)? $sink : $dbgfile;
print TRACE "START CLIENT ARGV:\n";
print TRACE "[0] $0\n";
my $x1;
for(my $x=0;$x<scalar @ARGV;$x++){
$x1 = $x+1;
print TRACE "[$x1] $ARGV[$x]\n";
}
print TRACE "ENV:\n";
foreach my $k (sort keys %ENV){
next unless ($k =~ m/^(GIT_|NH)/);
print TRACE " $k => $ENV{$k}\n";
}
print TRACE "CWD: " . `pwd`;
print TRACE "END\n";
#my $sink = ($^O eq "MSWin32")? "NUL" :"/dev/null";
#my $dbgfile = ($^O eq "MSWin32") ? "$ENV{TEMP}.$$" : "/tmp/trace.$$";
#open TRACE, ">>", ($debug==0)? $sink : $dbgfile;
# pick up the prefix for substitutions in this repo
my $PREFIX = `git config --local --get nethack.substprefix`;
chomp($PREFIX);
#my $PREFIX = `git config --local --get nethack.substprefix`;
#chomp($PREFIX);
sub git_config {
my($section, $var) = @_;
local($_);
open(CONFIG, "<", "$ENV{GIT_DIR}/config") or die "Missing .git/config: $!";
while(<CONFIG>){
m/^\[$section]/ && do {
while(<CONFIG>){
m/^\s+$var\s+=\s+(.*)/ && do {
return $1;
};
}
};
}
die "Missing config var: [$section] $var\n";
}
my $PREFIX = &git_config('nethack','substprefix');
my $submode = 0; # ok to make non-cleaning changes to file
my $mode;
@@ -37,7 +39,7 @@ if($ARGV[0] eq "--clean"){
$mode = "c";
if(0 == 0+$ENV{NHMODE}){
$submode = 1; # do NOT add extra changes to the file
print TRACE "SKIPPING\n";
# print TRACE "SKIPPING\n";
}
} elsif($ARGV[0] eq "--smudge"){
$mode = "s";
@@ -51,27 +53,30 @@ if($ARGV[0] eq "--clean"){
#XXX
#git check-attr -a $ARGV[1]
# process stdin to stdout
# Process stdin to stdout.
# For speed we read in the entire file then do the substitutions.
while(<STDIN>){
print TRACE "IN: $_";
# $1 - var and value (including trailing space but not $)
# $2 - var
# $4 - value or undef
# s/\$$PREFIX-(([A-Za-z][A-Za-z0-9_]*)(: ([^\N{DOLLAR SIGN}]+))?)\$/&handlevar($2,$4)/eg;
s/\$$PREFIX-(([A-Za-z][A-Za-z0-9_]*)(: ([^\x24]+))?)\$/&handlevar($2,$4)/eg;
if($debug2){
chomp;
print "XX: |$_|\n";
} else {
print;
}
print TRACE "OT: X${_}X\n";
local($_) = '';
my $len;
while(1){
# On at least some systems we only get 64K.
my $len = sysread(STDIN, $_, 999999, length($_));
last if($len == 0);
die "read failed: $!" unless defined($len);
}
# $1 - var and value (including trailing space but not $)
# $2 - var
# $4 - value or undef
# s/\$$PREFIX-(([A-Za-z][A-Za-z0-9_]*)(: ([^\N{DOLLAR SIGN}]+))?)\$/&handlevar($2,$4)/eg;
s/\$$PREFIX-(([A-Za-z][A-Za-z0-9_]*)(: ([^\x24]+))?)\$/&handlevar($2,$4)/ego;
die "write failed: $!" unless defined syswrite(STDOUT, $_);
exit 0;
sub handlevar {
my($var, $val) = @_;
print "HIT '$var' '$val'\n" if($debug2);
# print "HIT '$var' '$val'\n" if($debug2);
my $subname = "PREFIX::$var";
if(defined &$subname){
@@ -147,4 +152,3 @@ sub Revision {
return $val;
}
__END__