Change NHtext to double the speed of "git checkout"
This commit is contained in:
+43
-39
@@ -5,30 +5,32 @@
|
|||||||
# clean/smudge filter for handling substitutions
|
# clean/smudge filter for handling substitutions
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
my $debug = 0; # save trace to file
|
#my $debug = 0; # save trace to file
|
||||||
my $debug2 = 0; # annotate output when running from command line
|
#my $debug2 = 0; # annotate output when running from command line
|
||||||
|
|
||||||
my $sink = ($^O eq "MSWin32")? "NUL" :"/dev/null";
|
#my $sink = ($^O eq "MSWin32")? "NUL" :"/dev/null";
|
||||||
my $dbgfile = ($^O eq "MSWin32") ? "$ENV{TEMP}.$$" : "/tmp/trace.$$";
|
#my $dbgfile = ($^O eq "MSWin32") ? "$ENV{TEMP}.$$" : "/tmp/trace.$$";
|
||||||
open TRACE, ">>", ($debug==0)? $sink : $dbgfile;
|
#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";
|
|
||||||
|
|
||||||
# pick up the prefix for substitutions in this repo
|
# pick up the prefix for substitutions in this repo
|
||||||
my $PREFIX = `git config --local --get nethack.substprefix`;
|
#my $PREFIX = `git config --local --get nethack.substprefix`;
|
||||||
chomp($PREFIX);
|
#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 $submode = 0; # ok to make non-cleaning changes to file
|
||||||
my $mode;
|
my $mode;
|
||||||
@@ -37,7 +39,7 @@ if($ARGV[0] eq "--clean"){
|
|||||||
$mode = "c";
|
$mode = "c";
|
||||||
if(0 == 0+$ENV{NHMODE}){
|
if(0 == 0+$ENV{NHMODE}){
|
||||||
$submode = 1; # do NOT add extra changes to the file
|
$submode = 1; # do NOT add extra changes to the file
|
||||||
print TRACE "SKIPPING\n";
|
# print TRACE "SKIPPING\n";
|
||||||
}
|
}
|
||||||
} elsif($ARGV[0] eq "--smudge"){
|
} elsif($ARGV[0] eq "--smudge"){
|
||||||
$mode = "s";
|
$mode = "s";
|
||||||
@@ -51,27 +53,30 @@ if($ARGV[0] eq "--clean"){
|
|||||||
#XXX
|
#XXX
|
||||||
#git check-attr -a $ARGV[1]
|
#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>){
|
local($_) = '';
|
||||||
print TRACE "IN: $_";
|
my $len;
|
||||||
# $1 - var and value (including trailing space but not $)
|
while(1){
|
||||||
# $2 - var
|
# On at least some systems we only get 64K.
|
||||||
# $4 - value or undef
|
my $len = sysread(STDIN, $_, 999999, length($_));
|
||||||
# s/\$$PREFIX-(([A-Za-z][A-Za-z0-9_]*)(: ([^\N{DOLLAR SIGN}]+))?)\$/&handlevar($2,$4)/eg;
|
last if($len == 0);
|
||||||
s/\$$PREFIX-(([A-Za-z][A-Za-z0-9_]*)(: ([^\x24]+))?)\$/&handlevar($2,$4)/eg;
|
die "read failed: $!" unless defined($len);
|
||||||
if($debug2){
|
|
||||||
chomp;
|
|
||||||
print "XX: |$_|\n";
|
|
||||||
} else {
|
|
||||||
print;
|
|
||||||
}
|
|
||||||
print TRACE "OT: X${_}X\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# $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 {
|
sub handlevar {
|
||||||
my($var, $val) = @_;
|
my($var, $val) = @_;
|
||||||
print "HIT '$var' '$val'\n" if($debug2);
|
# print "HIT '$var' '$val'\n" if($debug2);
|
||||||
|
|
||||||
my $subname = "PREFIX::$var";
|
my $subname = "PREFIX::$var";
|
||||||
if(defined &$subname){
|
if(defined &$subname){
|
||||||
@@ -147,4 +152,3 @@ sub Revision {
|
|||||||
return $val;
|
return $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
__END__
|
|
||||||
|
|||||||
Reference in New Issue
Block a user