From: keni Date: Sat, 28 Feb 2015 22:52:19 +0000 (-0500) Subject: Change NHtext to double the speed of "git checkout" X-Git-Tag: NetHack-3.6.0_RC01~651 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=91b96e2331ae480e566cbcdc84b3e2b3a12743c0;p=nethack Change NHtext to double the speed of "git checkout" --- diff --git a/DEVEL/hooksdir/NHtext b/DEVEL/hooksdir/NHtext index e9ee8c28c..03550e513 100755 --- a/DEVEL/hooksdir/NHtext +++ b/DEVEL/hooksdir/NHtext @@ -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 $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 $ENV{$k}\n"; -} -print TRACE "CWD: " . `pwd`; -print TRACE "END\n"; +#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; # 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(){ + m/^\[$section]/ && do { + while(){ + 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(){ - 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__