3 # NetHack Git Hook Module
13 my $tracefile = "/tmp/nhgitt.$$";
16 my $DS = quotemeta('/');
19 $DS = quotemeta('\\');
27 @saved_input = <STDIN
>;
30 print TRACE
"STDIN:\n";
31 print TRACE
$saved_input;
32 print TRACE
"ENDSTDIN\n";
35 tie
*STDIN
, 'NHIO::STDIN', @saved_input;
38 # XXX this needs a re-write (don't tie and untie, just set NEXT=0)
39 # (the sensitive thing is @foo = <STDIN> )
45 tie
*STDIN
, 'NHIO::STDIN', $data;
50 # open STDIN, "<", \$saved_input or die "reopen STDIN: $!";
51 # @ARGV = @saved_argv;
67 $hname =~ s!^((.*$DS)|())(.*)!$1$p-$4!;
69 print TRACE
"START $p: $hname\n" if($trace);
71 open TOHOOK
, "|-", $hname or die "open $hname: $!";
73 close TOHOOK
or die "close $hname: $! $?";
75 print TRACE
"END $p\n" if($trace);
80 return unless($trace);
82 open TRACE
, ">>", $tracefile;
83 print TRACE
"START CLIENT PID:$$ ARGV:\n";
84 print TRACE
"CWD: " . cwd
() . "\n";
85 print TRACE
"[0] $0\n";
87 for(my $x=0;$x<scalar @ARGV;$x++){
89 print TRACE
"[$x1] $ARGV[$x]\n";
92 foreach my $k (sort keys %ENV){
93 next unless ($k =~ m/(^GIT_)|(^NH)/);
94 print TRACE
" $k => $ENV{$k}\n";
105 ### ugly mess so we can re-read STDIN
118 return bless \
%fh, $class;
123 return undef if($self->{EOF
});
125 my $lim = $#{$self->{DATA}};
126 my @ary = @
{$self->{DATA
}}[$self->{NEXT}..$lim];
127 my @rv = @ary[$self->{NEXT}..$#ary];
131 my $rv = $self->{DATA
}[$self->{NEXT}];
152 NHgithook - common code for NetHack git hooks (and other git bits)
157 my $DS = quotemeta('/');
159 if ($^O eq "MSWin32")
161 $DS = quotemeta('\\');
165 push(@INC, $ENV{GIT_DIR}.$PDS."hooks"); # for most hooks
166 push(@INC, ($0 =~ m!^(.*)$DS!)[0]); # when the above doesn't work
168 $gitdir = `git rev-parse --git-dir`; # and when the above really doesn't work
169 $gitdir =~ s/[\r\n]*$/;
170 push(@INC, $gitdir.$PDS."hooks");
174 &NHgithook::saveSTDIN;
181 Buffers call information so multiple independent actions may be coded for
182 Git hooks and similar Git callouts.
186 Changing the C<$trace> and C<$tracefile> variables requires editing the
187 module source. Setting C<$trace> enables tracing, logs basic information,
188 and leaves the C<TRACE> filehandle open for additional output; output to this
189 filehandle must be guarded by C<$NHgithook::trace>. Setting
190 C<$tracefile> specifies the file used for trace output. Note that C<$$>
191 may be useful since multiple processes may be live at the same time.
195 NHgithook::saveSTDIN reads STDIN until EOF and saves it
196 NHgithook::PRE runs the PRE hook, if it exists
197 NHgithook::POST runs the POST hook, if it exists
201 Some features not well tested, especially under Windows.
205 Kenneth Lorber (keni@his.com)