initial git setup
This commit is contained in:
BIN
DEVEL/hooksdir/.NHgithook.pm.swp
Normal file
BIN
DEVEL/hooksdir/.NHgithook.pm.swp
Normal file
Binary file not shown.
14
DEVEL/hooksdir/NHadd
Executable file
14
DEVEL/hooksdir/NHadd
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/perl
|
||||
# wrapper for nhadd and nhcommit aliases
|
||||
# $NHDT-Date$
|
||||
|
||||
%ok = map { $_ => 1 } ('add', 'commit');
|
||||
|
||||
die "Bad subcommand '$ARGV[0]'" unless $ok{$ARGV[0]};
|
||||
|
||||
if(length $ENV{GIT_PREFIX}){
|
||||
chdir($ENV{GIT_PREFIX}) or die "Can't chdir $ENV{GIT_PREFIX}: $!";
|
||||
}
|
||||
|
||||
$ENV{NHMODE} = 1;
|
||||
exec "git", @ARGV or die "Can't exec git: $!";
|
||||
205
DEVEL/hooksdir/NHgithook.pm
Normal file
205
DEVEL/hooksdir/NHgithook.pm
Normal file
@@ -0,0 +1,205 @@
|
||||
#
|
||||
# NHgithook.pm
|
||||
# NetHack Git Hook Module
|
||||
# $NHDT-Date$
|
||||
|
||||
package NHgithook;
|
||||
use Cwd;
|
||||
|
||||
###
|
||||
### CONFIG
|
||||
###
|
||||
my $trace = 0;
|
||||
my $tracefile = "/tmp/nhgitt.$$";
|
||||
|
||||
# OS hackery
|
||||
my $DS = quotemeta('/');
|
||||
if ($^O eq "MSWin32")
|
||||
{
|
||||
$DS = quotemeta('\\');
|
||||
}
|
||||
|
||||
our %saved_env;
|
||||
our @saved_argv;
|
||||
our $saved_input;
|
||||
|
||||
sub saveSTDIN {
|
||||
@saved_input = <STDIN>;
|
||||
|
||||
if($trace){
|
||||
print TRACE "STDIN:\n";
|
||||
print TRACE $saved_input;
|
||||
print TRACE "ENDSTDIN\n";
|
||||
}
|
||||
|
||||
tie *STDIN, 'NHIO::STDIN', @saved_input;
|
||||
}
|
||||
|
||||
# XXX this needs a re-write (don't tie and untie, just set NEXT=0)
|
||||
# (the sensitive thing is @foo = <STDIN> )
|
||||
sub resetSTDIN{
|
||||
my $x = tied(*STDIN);
|
||||
my %x = %$x;
|
||||
my $data = @$x{DATA};
|
||||
untie *STDIN;
|
||||
tie *STDIN, 'NHIO::STDIN', $data;
|
||||
}
|
||||
|
||||
# don't need this now
|
||||
#sub restore {
|
||||
# open STDIN, "<", \$saved_input or die "reopen STDIN: $!";
|
||||
# @ARGV = @saved_argv;
|
||||
# %ENV = %saved_env;
|
||||
#}
|
||||
|
||||
sub PRE {
|
||||
&do_hook("PRE");
|
||||
}
|
||||
|
||||
sub POST {
|
||||
&do_hook("POST");
|
||||
}
|
||||
|
||||
# PRIVATE
|
||||
sub do_hook {
|
||||
my($p) = @_;
|
||||
my $hname = $0;
|
||||
$hname =~ s!^((.*$DS)|())(.*)!$1$p-$4!;
|
||||
if(-x $hname){
|
||||
print TRACE "START $p: $hname\n" if($trace);
|
||||
|
||||
open TOHOOK, "|-", $hname or die "open $hname: $!";
|
||||
print TOHOOK <STDIN>;
|
||||
close TOHOOK or die "close $hname: $! $?";
|
||||
|
||||
print TRACE "END $p\n" if($trace);
|
||||
}
|
||||
}
|
||||
|
||||
sub trace_start {
|
||||
return unless($trace);
|
||||
my $self = shift;
|
||||
open TRACE, ">>", $tracefile;
|
||||
print TRACE "START CLIENT PID:$$ ARGV:\n";
|
||||
print TRACE "CWD: " . cwd() . "\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";
|
||||
}
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
%saved_env = %ENV;
|
||||
@saved_argv = @ARGV;
|
||||
&trace_start;
|
||||
}
|
||||
|
||||
###
|
||||
### ugly mess so we can re-read STDIN
|
||||
###
|
||||
package NHIO::STDIN;
|
||||
sub TIEHANDLE {
|
||||
my $class = shift;
|
||||
my %fh;
|
||||
# XXX yuck
|
||||
if(ref @_[0]){
|
||||
$fh{DATA} = @_[0];
|
||||
} else {
|
||||
$fh{DATA} = \@_;
|
||||
}
|
||||
$fh{NEXT} = 0;
|
||||
return bless \%fh, $class;
|
||||
}
|
||||
|
||||
sub READLINE {
|
||||
my $self = shift;
|
||||
return undef if($self->{EOF});
|
||||
if(wantarray){
|
||||
my $lim = $#{$self->{DATA}};
|
||||
my @ary = @{$self->{DATA}}[$self->{NEXT}..$lim];
|
||||
my @rv = @ary[$self->{NEXT}..$#ary];
|
||||
$self->{EOF} = 1;
|
||||
return @rv;
|
||||
} else{
|
||||
my $rv = $self->{DATA}[$self->{NEXT}];
|
||||
if(length $rv){
|
||||
$self->{NEXT}++;
|
||||
return $rv;
|
||||
} else {
|
||||
$self->{EOF} = 1;
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sub EOF {
|
||||
$self = shift;
|
||||
return $self->{EOF};
|
||||
}
|
||||
|
||||
1;
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
NHgithook - common code for NetHack git hooks (and other git bits)
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
BEGIN {
|
||||
my $DS = quotemeta('/');
|
||||
my $PDS = '/';
|
||||
if ($^O eq "MSWin32")
|
||||
{
|
||||
$DS = quotemeta('\\');
|
||||
$PDS = '\\';
|
||||
}
|
||||
|
||||
push(@INC, $ENV{GIT_DIR}.$PDS."hooks"); # for most hooks
|
||||
push(@INC, ($0 =~ m!^(.*)$DS!)[0]); # when the above doesn't work
|
||||
|
||||
$gitdir = `git rev-parse --git-dir`; # and when the above really doesn't work
|
||||
$gitdir =~ s/[\r\n]*$/;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
|
||||
&NHgithook::saveSTDIN;
|
||||
&NHgithook::PRE;
|
||||
(core hook code)
|
||||
&NHgithook::POST;
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Buffers call information so multiple independent actions may be coded for
|
||||
Git hooks and similar Git callouts.
|
||||
|
||||
=head1 SETUP
|
||||
|
||||
Changing the C<$trace> and C<$tracefile> variables requires editing the
|
||||
module source. Setting C<$trace> enables tracing, logs basic information,
|
||||
and leaves the C<TRACE> filehandle open for additional output; output to this
|
||||
filehandle must be guarded by C<$NHgithook::trace>. Setting
|
||||
C<$tracefile> specifies the file used for trace output. Note that C<$$>
|
||||
may be useful since multiple processes may be live at the same time.
|
||||
|
||||
=head1 FUNCTIONS
|
||||
|
||||
NHgithook::saveSTDIN reads STDIN until EOF and saves it
|
||||
NHgithook::PRE runs the PRE hook, if it exists
|
||||
NHgithook::POST runs the POST hook, if it exists
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
Some features not well tested, especially under Windows.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Kenneth Lorber (keni@his.com)
|
||||
366
DEVEL/hooksdir/NHsubst
Executable file
366
DEVEL/hooksdir/NHsubst
Executable file
@@ -0,0 +1,366 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# NHsubst
|
||||
# $NHDT-Date$
|
||||
# git merge driver for substitutions (like RCS/CVS)
|
||||
# driver line: .... %O %A %B %L
|
||||
use strict;
|
||||
|
||||
my $debug = 0;
|
||||
my $rawin = 0; # feed diff to stdin for testing (do NOT set $debug=1)
|
||||
|
||||
# We want TRACE open so we don't need to test $debug everywhere, but we skip
|
||||
# this first block because it's expensive and dumpfile() hangs with $rawin.
|
||||
my $sink = ($^O eq "MSWin32") ? "NUL" : "/dev/null";
|
||||
my $dbgfile = ($^O eq "MSWin32") ? "$ENV{TEMP}.$$" : "/tmp/trace.$$";
|
||||
open TRACE, ">>", ($debug==0)? $sink : $dbgfile;
|
||||
if($debug){
|
||||
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_/);
|
||||
print TRACE " $k => $ENV{$k}\n";
|
||||
}
|
||||
print TRACE "CWD: " . `pwd`;
|
||||
&dumpfile($ARGV[0], "[0O]");
|
||||
&dumpfile($ARGV[1], "[1A]");
|
||||
&dumpfile($ARGV[2], "[2B]");
|
||||
print TRACE "L=$ARGV[3]\n";
|
||||
print TRACE "END\n";
|
||||
}
|
||||
|
||||
my $mark_len = $ARGV[3];
|
||||
$mark_len = 3 if($mark_len==0 && $rawin);
|
||||
|
||||
my $mark_start = '<' x $mark_len;
|
||||
my $mark_middle = '=' x $mark_len;
|
||||
my $mark_end = '>' x $mark_len;
|
||||
|
||||
my $PREFIX;
|
||||
# pick up the prefix for substitutions in this repo
|
||||
if($rawin){
|
||||
$PREFIX = "TEST";
|
||||
} else {
|
||||
$PREFIX = `git config --local --get nethack.substprefix`;
|
||||
chomp($PREFIX);
|
||||
}
|
||||
|
||||
my @out;
|
||||
my $cntout;
|
||||
if($rawin){
|
||||
@out = <STDIN>;
|
||||
} else {
|
||||
#system "git merge-file -p .... > temp
|
||||
my $tags = "-L CURRENT -L ANCESTOR -L OTHER"; # XXX should "CURRENT" be "MINE"?
|
||||
@out = `git merge-file -p $tags $ARGV[1] $ARGV[0] $ARGV[2]`;
|
||||
#NB: we don't check the exit value because it's useless
|
||||
print TRACE "MERGE-FILE START\n".join("",@out)."MERGE-FILE END\n";
|
||||
}
|
||||
|
||||
($cntout,@out) = &edit_merge(@out);
|
||||
|
||||
if($rawin){
|
||||
print "COUNT: $cntout\n";
|
||||
print @out;
|
||||
} else {
|
||||
# spit @out to $ARGV[1] (careful: what about EOL character?)
|
||||
open OUT, ">$ARGV[1]" or die "Can't open $ARGV[1]";
|
||||
print OUT @out;
|
||||
close OUT;
|
||||
|
||||
print TRACE "WRITING START ($ARGV[1])\n".join("",@out)."WRITING END\n";
|
||||
&dumpfile($ARGV[1], "READBACK");
|
||||
}
|
||||
print TRACE "COUNT: $cntout\n";
|
||||
|
||||
exit( ($cntout>0) ? 1 : 0);
|
||||
|
||||
#git merge-file [-L <current-name> [-L <base-name> [-L <other-name>]]]
|
||||
# [--ours|--theirs|--union] [-p|--stdout] [-q|--quiet] [--marker-size=<n>]
|
||||
# [--[no-]diff3] <current-file> <base-file> <other-file>
|
||||
#The `merge.*.driver` variable's value is used to construct a command to run to merge ancestor's
|
||||
# version (%O), current version (%A) and the other branches' version (%B). These three tokens are
|
||||
# replaced with the names of temporary files that hold the contents of these versions when the
|
||||
# command line is built. Additionally, %L will be replaced with the conflict marker size (see
|
||||
# below).
|
||||
|
||||
# keep failing so we don't need to keep changing the setup while building this script
|
||||
|
||||
sub dumpfile {
|
||||
my($file, $tag) = @_;
|
||||
print TRACE "FILE $tag START\n";
|
||||
print TRACE `hexdump -C $file`;
|
||||
print TRACE "FILE END\n";
|
||||
}
|
||||
|
||||
sub edit_merge {
|
||||
my(@input) = @_;
|
||||
# $::count is a bit ugly XXX
|
||||
local $::count = 0; # we need the number of conflicts for exit()
|
||||
my @out;
|
||||
|
||||
local $_;
|
||||
while($_ = shift @input){
|
||||
if(m/^$mark_start /){
|
||||
print TRACE "FOUND A CONFLICT\n";
|
||||
my @conflict;
|
||||
push(@conflict, $_);
|
||||
while($_ = shift @input){
|
||||
push(@conflict, $_);
|
||||
if(m/^$mark_end /){
|
||||
last;
|
||||
}
|
||||
}
|
||||
push(@out, &edit_conflict(@conflict));
|
||||
} else {
|
||||
push(@out, $_);
|
||||
}
|
||||
}
|
||||
print TRACE "RETURN count=$::count\n";
|
||||
return($::count, @out);
|
||||
}
|
||||
|
||||
sub edit_conflict {
|
||||
my(@in) = @_;
|
||||
|
||||
print TRACE "EDIT START: " . scalar(@in)."\n";
|
||||
if($debug){
|
||||
foreach my $x (@in){ my $xx = $x; chomp($xx); print TRACE "-$xx-\n"; }
|
||||
}
|
||||
print TRACE "EDIT END INPUT\n";
|
||||
|
||||
# one-line change - use as base case to develop the code
|
||||
# ours ARGV[1] top-of-diff
|
||||
# theirs ARGV[2] bottom-of-diff
|
||||
# simple conflict:
|
||||
# [0] <<<<<<< d1
|
||||
# [1] $$PREFIX-Date: 1 ...
|
||||
# [2] =======
|
||||
# [3] $$PREFIX-Date: 3 ...
|
||||
# [4] >>>>>>> d3
|
||||
if(scalar(@in) == 5 && $in[2] =~ m/^$mark_middle/){
|
||||
my $back = &merge_one_line_maybe($in[1],$in[3]); # (ours, theirs)
|
||||
if(!defined $back){
|
||||
$::count++; # leave the conflict
|
||||
return @in;
|
||||
} else {
|
||||
return ($back);
|
||||
}
|
||||
# NOTREACHED
|
||||
} else {
|
||||
# XXX LATER
|
||||
# Start at the top of both sections and work downwards. As long as the lines can be merged,
|
||||
# push them out and keep going. If there are lines left, we will still have a conflict but
|
||||
# we can try to make it smaller. Push out the start-conflict marker. Start at the
|
||||
# bottom of both section and work upwards. As long as the lines can be merged, reverse push out
|
||||
# the merged line and keep going. (We know there will be lines left at some point.) Push out
|
||||
# remaining (middle) lines from OURS. Push out mark_middle. Push out remaining middle lines
|
||||
# from THEIRS. Push out end-conflict marker. $::count++; return (@a,$b,@c,$d,@e,$f,@g)
|
||||
# @a
|
||||
# $b = <<<
|
||||
# @c
|
||||
# $d = ===
|
||||
# @e
|
||||
# $f = >>>
|
||||
# @g
|
||||
}
|
||||
# not matched - return the unchanged conflict
|
||||
$::count++;
|
||||
return @in;
|
||||
}
|
||||
|
||||
# XXX This is expensive. Add a quick check for "anything that looks like a subst var" and just
|
||||
# declare the lines unmergeable if it fails.
|
||||
sub merge_one_line_maybe {
|
||||
my($ours, $theirs) = @_;
|
||||
|
||||
my $more = 1;
|
||||
my $fail = 0;
|
||||
my $out = '';
|
||||
# TYPES:
|
||||
# 0 no match
|
||||
# 1 unexpanded var
|
||||
# 2 expanded var
|
||||
# 3 non-var text
|
||||
my($ourstype, $theirtype);
|
||||
my($oursvar, $theirvar);
|
||||
my($oursval, $theirval);
|
||||
|
||||
while($more){
|
||||
($ourstype, $theirtype) = (0,0);
|
||||
($oursvar, $theirvar) = (undef, undef);
|
||||
($oursvar, $theirvar) = (undef, undef);
|
||||
# unexpanded var
|
||||
if($ours =~ m/\G\$$PREFIX-([A-Z][a-z]+)\$/gc){
|
||||
$ourstype = 1;
|
||||
$oursvar = $1;
|
||||
}
|
||||
if($theirs =~ m/\G\$$PREFIX-([A-Z][a-z]+)\$/gc){
|
||||
$theirtype = 1;
|
||||
$theirvar = $1;
|
||||
}
|
||||
# expanded var
|
||||
unless($ourstype){
|
||||
if($ours =~ m/\G\$$PREFIX-([A-Za-z]+):\s+(.*?)\s\$/gc){
|
||||
$ourstype = 2;
|
||||
$oursvar = $1;
|
||||
$oursval = $2;
|
||||
}
|
||||
}
|
||||
unless($theirtype){
|
||||
if($theirs =~ m/\G\$$PREFIX-([A-Za-z]+):\s+(.*?)\s\$/gc){
|
||||
$theirtype = 2;
|
||||
$theirvar = $1;
|
||||
$theirval = $2;
|
||||
}
|
||||
}
|
||||
# non-var text
|
||||
unless($ourstype){
|
||||
if($ours =~ m/\G(\$?[^\x24]*)/gc){
|
||||
$ourstype = 3;
|
||||
$oursval = $1;
|
||||
}
|
||||
}
|
||||
unless($theirtype){
|
||||
if($theirs =~ m/\G(\$?[^\x24]*)/gc){
|
||||
$theirtype = 3;
|
||||
$theirval = $1;
|
||||
}
|
||||
}
|
||||
|
||||
# are we done?
|
||||
if(pos($ours)==length $ours && pos($theirs) == length $theirs){
|
||||
$more = 0;
|
||||
}
|
||||
if($ourstype == 0 && $theirtype == 0){
|
||||
die "NHsubst MERGE FAILED - aborted infinite loop\n";
|
||||
}
|
||||
|
||||
# now see if ours and their match or can be resolved
|
||||
# text
|
||||
if($ourstype == 3 && $theirtype == 3){
|
||||
if($oursval eq $theirval){
|
||||
$out .= $oursval;
|
||||
next;
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
if($ourstype == 3 || $theirtype == 3){
|
||||
return undef;
|
||||
}
|
||||
# XXX we could do better: on failure of one field, return 2 lines with the fields we _can_ fix
|
||||
# substituted into those lines, leaving only the fail-to-match bits for the user to
|
||||
# deal with. Later.
|
||||
# vars (all 4 cases)
|
||||
if($oursvar ne $theirvar){
|
||||
return undef;
|
||||
}
|
||||
my $m = merge_one_var_maybe($oursvar, $oursval, $theirval);
|
||||
if(! defined $m){
|
||||
return undef;
|
||||
}
|
||||
$out .= $m;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
# return undef if we can't merge the values; $NAME: VALUE $ or $NAME$ (as appropriate) if we can.
|
||||
sub merge_one_var_maybe {
|
||||
my($varname, $oursval, $theirval) = @_;
|
||||
my $resolvedas;
|
||||
{
|
||||
no strict;
|
||||
my $fn = "PREFIX::$varname";
|
||||
if(defined &$fn){
|
||||
$resolvedas = &$fn($PREFIX,$varname,$oursval, $theirval);
|
||||
} else {
|
||||
$resolvedas = undef; # can't resolve
|
||||
}
|
||||
}
|
||||
|
||||
if(!defined $resolvedas){
|
||||
$::count++; # we have an externally visible conflict
|
||||
return undef;
|
||||
} else {
|
||||
return $resolvedas;
|
||||
}
|
||||
# NOTREACHED
|
||||
}
|
||||
|
||||
package PREFIX;
|
||||
# Resolve the conflict of a single var's 2 values. Return undef to leave the conflict.
|
||||
sub Date {
|
||||
my($PREFIX, $varname, $mine, $theirs) = @_;
|
||||
my $m = ($mine =~ m/(\d+)/)[0];
|
||||
my $t = ($theirs =~ m/(\d+)/)[0];
|
||||
return undef unless ($m>0) && ($t>0);
|
||||
|
||||
return "\$$PREFIX-$varname: " . (($m>$t)?$mine:$theirs) .' $';
|
||||
}
|
||||
|
||||
#sub Header {
|
||||
#sub Author {
|
||||
|
||||
sub Branch {
|
||||
my($PREFIX, $varname, $mine, $theirs) = @_;
|
||||
return "\$$PREFIX-$varname: $mine \$";
|
||||
}
|
||||
|
||||
sub Revision {
|
||||
my($PREFIX, $varname, $mine, $theirs) = @_;
|
||||
return "\$$PREFIX-$varname: $mine \$";
|
||||
}
|
||||
__END__
|
||||
|
||||
TEST 1:
|
||||
<<< d1
|
||||
$TEST-Date: 1 $
|
||||
===
|
||||
$TEST-Date: 3 $
|
||||
>>> d3
|
||||
|
||||
TEST 2:
|
||||
nothing
|
||||
at all
|
||||
|
||||
TEST 3:
|
||||
<<< d1
|
||||
a line
|
||||
===
|
||||
one line
|
||||
two lines
|
||||
>>> d3
|
||||
|
||||
TEST 4:
|
||||
<<< d1
|
||||
$TEST-Date: 1 $ yes
|
||||
===
|
||||
$TEST-Date: 1 $ no
|
||||
>>> d3
|
||||
|
||||
TEST 5:
|
||||
<<< d1
|
||||
$TEST-Date: 3 $ yes
|
||||
===
|
||||
$TEST-Date: 1 $ yes
|
||||
>>> d3
|
||||
|
||||
TEST 6:
|
||||
<<< d1
|
||||
$TEST-Date: 3 $ yes$TEST-Date: 4 $
|
||||
===
|
||||
$TEST-Date: 1 $ yes$TEST-Date: 5 $
|
||||
>>> d3
|
||||
|
||||
TEST 7:
|
||||
<<< d1
|
||||
$TEST-Branch: mine $
|
||||
===
|
||||
$TEST-Branch: theirs $
|
||||
>>> d3
|
||||
145
DEVEL/hooksdir/NHtext
Executable file
145
DEVEL/hooksdir/NHtext
Executable file
@@ -0,0 +1,145 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# NHtext
|
||||
# $NHDT-Date$
|
||||
# clean/smudge filter for handling substitutions
|
||||
use strict;
|
||||
|
||||
my $debug = 0;
|
||||
|
||||
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";
|
||||
|
||||
# pick up the prefix for substitutions in this repo
|
||||
my $PREFIX = `git config --local --get nethack.substprefix`;
|
||||
chomp($PREFIX);
|
||||
|
||||
my $submode = 0; # ok to make non-cleaning changes to file
|
||||
my $mode;
|
||||
|
||||
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";
|
||||
}
|
||||
} elsif($ARGV[0] eq "--smudge"){
|
||||
$mode = "s";
|
||||
} else {
|
||||
warn "Unknown mode '$ARGV[0]'\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# XXX for now, there isn't any - if we get called, we subst. No options for now.
|
||||
# get relevent config info
|
||||
#XXX
|
||||
#git check-attr -a $ARGV[1]
|
||||
|
||||
# process stdin to stdout
|
||||
|
||||
while(<STDIN>){
|
||||
print TRACE "IN: $_";
|
||||
# $1 - var and value (not including trailing $)
|
||||
# $2 - var
|
||||
# $4 - value or undef
|
||||
# s/\$$PREFIX-(([A-Za-z][A-Za-z0-9_]*)(: ([^\N{DOLLAR SIGN}]+))?)\s*\$/&handlevar($2,$4)/eg;
|
||||
s/\$$PREFIX-(([A-Za-z][A-Za-z0-9_]*)(: ([^\x24]+))?)\s*\$/&handlevar($2,$4)/eg;
|
||||
print;
|
||||
print TRACE "OT: $_";
|
||||
}
|
||||
|
||||
sub handlevar {
|
||||
my($var, $val) = @_;
|
||||
|
||||
my $subname = "PREFIX::$var";
|
||||
if(defined &$subname){
|
||||
no strict;
|
||||
$val = &$subname($val,$mode,$submode);
|
||||
} else {
|
||||
warn "No handler for \$$PREFIX-$var\n";
|
||||
}
|
||||
|
||||
if(length $val){
|
||||
return "\$$PREFIX-$var: $val \$";
|
||||
} else {
|
||||
return "\$$PREFIX-$var\$";
|
||||
}
|
||||
}
|
||||
|
||||
package PREFIX;
|
||||
use POSIX qw(strftime);
|
||||
|
||||
# On push, put in the current date because we changed the file.
|
||||
# On pull, keep the current value so we can see the last change date.
|
||||
sub Date {
|
||||
my($val, $mode, $submode) = @_;
|
||||
if($mode eq "c"){
|
||||
if($submode==0){
|
||||
# we add this to make merge easier for now XXX
|
||||
my $now = time; # not %s below - may not be portable
|
||||
# YYYY/MM/DD HH:MM:SS
|
||||
$val = "$now " . strftime("%Y/%m/%d %H:%M:%S", gmtime($now));
|
||||
}
|
||||
}
|
||||
if($mode eq "s"){
|
||||
$val =~ s/\s*$//; # XXX why do I need this?
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
#sub Header {
|
||||
#}
|
||||
#sub Author {
|
||||
#}
|
||||
|
||||
# NB: the standard-ish Revision line isn't enough - you need Branch/Revision -
|
||||
# but we split it into 2 so we can use the standard processing code on Revision
|
||||
# and just slip Branch in.
|
||||
sub Branch {
|
||||
my($val, $mode, $submode) = @_;
|
||||
if($mode eq "c"){
|
||||
if($submode==0){
|
||||
$val = `git branch --no-color --contains`;
|
||||
chomp($val); #XXX
|
||||
$val =~ s/^\*\s*//;
|
||||
}
|
||||
}
|
||||
if($mode eq "s"){
|
||||
#XXX do we need this now?
|
||||
$val =~ s/\s*$//; # XXX why do I need this?
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
sub Revision {
|
||||
my($val, $mode, $submode) = @_;
|
||||
if($mode eq "c"){
|
||||
if($submode==0){
|
||||
my $file = $ARGV[1];
|
||||
my @val = `git log --follow --oneline $file`;
|
||||
$val = sprintf("1.%d",0+$#val);
|
||||
}
|
||||
}
|
||||
if($mode eq "s"){
|
||||
#XXX do we need this here?
|
||||
$val =~ s/\s*$//; # XXX why do I need this?
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
__END__
|
||||
1
DEVEL/hooksdir/TARGET
Normal file
1
DEVEL/hooksdir/TARGET
Normal file
@@ -0,0 +1 @@
|
||||
.git/hooks
|
||||
30
DEVEL/hooksdir/applypatch-msg
Executable file
30
DEVEL/hooksdir/applypatch-msg
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/perl
|
||||
# $NHDT-Date$
|
||||
|
||||
#STARTUP-START
|
||||
BEGIN {
|
||||
# OS hackery has to be duplicated in each of the hooks :/
|
||||
# first the directory separator
|
||||
my $DS = quotemeta('/');
|
||||
my $PDS = '/';
|
||||
# msys: POSIXish over a Windows filesystem (so / not \ but \r\n not \n).
|
||||
# temporarily removed because inconsistent behavior
|
||||
# if ($^O eq "msys")
|
||||
# {
|
||||
# $/ = "\r\n";
|
||||
# $\ = "\r\n";
|
||||
# }
|
||||
if($^O eq "MSWin32"){
|
||||
$DS = quotemeta('\\');
|
||||
$PDS = '\\';
|
||||
}
|
||||
$gitdir = `git rev-parse --git-dir`;
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
&NHgithook::POST;
|
||||
exit 0;
|
||||
30
DEVEL/hooksdir/commit-msg
Executable file
30
DEVEL/hooksdir/commit-msg
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/perl
|
||||
# $NHDT-Date$
|
||||
|
||||
#STARTUP-START
|
||||
BEGIN {
|
||||
# OS hackery has to be duplicated in each of the hooks :/
|
||||
# first the directory separator
|
||||
my $DS = quotemeta('/');
|
||||
my $PDS = '/';
|
||||
# msys: POSIXish over a Windows filesystem (so / not \ but \r\n not \n).
|
||||
# temporarily removed because inconsistent behavior
|
||||
# if ($^O eq "msys")
|
||||
# {
|
||||
# $/ = "\r\n";
|
||||
# $\ = "\r\n";
|
||||
# }
|
||||
if($^O eq "MSWin32"){
|
||||
$DS = quotemeta('\\');
|
||||
$PDS = '\\';
|
||||
}
|
||||
$gitdir = `git rev-parse --git-dir`;
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
&NHgithook::POST;
|
||||
exit 0;
|
||||
30
DEVEL/hooksdir/post-applypatch
Executable file
30
DEVEL/hooksdir/post-applypatch
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/perl
|
||||
# $NHDT-Date$
|
||||
|
||||
#STARTUP-START
|
||||
BEGIN {
|
||||
# OS hackery has to be duplicated in each of the hooks :/
|
||||
# first the directory separator
|
||||
my $DS = quotemeta('/');
|
||||
my $PDS = '/';
|
||||
# msys: POSIXish over a Windows filesystem (so / not \ but \r\n not \n).
|
||||
# temporarily removed because inconsistent behavior
|
||||
# if ($^O eq "msys")
|
||||
# {
|
||||
# $/ = "\r\n";
|
||||
# $\ = "\r\n";
|
||||
# }
|
||||
if($^O eq "MSWin32"){
|
||||
$DS = quotemeta('\\');
|
||||
$PDS = '\\';
|
||||
}
|
||||
$gitdir = `git rev-parse --git-dir`;
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
&NHgithook::POST;
|
||||
exit 0;
|
||||
30
DEVEL/hooksdir/post-checkout
Executable file
30
DEVEL/hooksdir/post-checkout
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/perl
|
||||
# $NHDT-Date$
|
||||
|
||||
#STARTUP-START
|
||||
BEGIN {
|
||||
# OS hackery has to be duplicated in each of the hooks :/
|
||||
# first the directory separator
|
||||
my $DS = quotemeta('/');
|
||||
my $PDS = '/';
|
||||
# msys: POSIXish over a Windows filesystem (so / not \ but \r\n not \n).
|
||||
# temporarily removed because inconsistent behavior
|
||||
# if ($^O eq "msys")
|
||||
# {
|
||||
# $/ = "\r\n";
|
||||
# $\ = "\r\n";
|
||||
# }
|
||||
if($^O eq "MSWin32"){
|
||||
$DS = quotemeta('\\');
|
||||
$PDS = '\\';
|
||||
}
|
||||
$gitdir = `git rev-parse --git-dir`;
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
&NHgithook::POST;
|
||||
exit 0;
|
||||
30
DEVEL/hooksdir/post-commit
Executable file
30
DEVEL/hooksdir/post-commit
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/perl
|
||||
# $NHDT-Date$
|
||||
|
||||
#STARTUP-START
|
||||
BEGIN {
|
||||
# OS hackery has to be duplicated in each of the hooks :/
|
||||
# first the directory separator
|
||||
my $DS = quotemeta('/');
|
||||
my $PDS = '/';
|
||||
# msys: POSIXish over a Windows filesystem (so / not \ but \r\n not \n).
|
||||
# temporarily removed because inconsistent behavior
|
||||
# if ($^O eq "msys")
|
||||
# {
|
||||
# $/ = "\r\n";
|
||||
# $\ = "\r\n";
|
||||
# }
|
||||
if($^O eq "MSWin32"){
|
||||
$DS = quotemeta('\\');
|
||||
$PDS = '\\';
|
||||
}
|
||||
$gitdir = `git rev-parse --git-dir`;
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
&NHgithook::POST;
|
||||
exit 0;
|
||||
30
DEVEL/hooksdir/post-merge
Executable file
30
DEVEL/hooksdir/post-merge
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/perl
|
||||
# $NHDT-Date$
|
||||
|
||||
#STARTUP-START
|
||||
BEGIN {
|
||||
# OS hackery has to be duplicated in each of the hooks :/
|
||||
# first the directory separator
|
||||
my $DS = quotemeta('/');
|
||||
my $PDS = '/';
|
||||
# msys: POSIXish over a Windows filesystem (so / not \ but \r\n not \n).
|
||||
# temporarily removed because inconsistent behavior
|
||||
# if ($^O eq "msys")
|
||||
# {
|
||||
# $/ = "\r\n";
|
||||
# $\ = "\r\n";
|
||||
# }
|
||||
if($^O eq "MSWin32"){
|
||||
$DS = quotemeta('\\');
|
||||
$PDS = '\\';
|
||||
}
|
||||
$gitdir = `git rev-parse --git-dir`;
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
&NHgithook::POST;
|
||||
exit 0;
|
||||
32
DEVEL/hooksdir/post-rewrite
Executable file
32
DEVEL/hooksdir/post-rewrite
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/perl
|
||||
# $NHDT-Date$
|
||||
|
||||
#STARTUP-START
|
||||
BEGIN {
|
||||
# OS hackery has to be duplicated in each of the hooks :/
|
||||
# first the directory separator
|
||||
my $DS = quotemeta('/');
|
||||
my $PDS = '/';
|
||||
# msys: POSIXish over a Windows filesystem (so / not \ but \r\n not \n).
|
||||
# temporarily removed because inconsistent behavior
|
||||
# if ($^O eq "msys")
|
||||
# {
|
||||
# $/ = "\r\n";
|
||||
# $\ = "\r\n";
|
||||
# }
|
||||
if($^O eq "MSWin32"){
|
||||
$DS = quotemeta('\\');
|
||||
$PDS = '\\';
|
||||
}
|
||||
$gitdir = `git rev-parse --git-dir`;
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::saveSTDIN;
|
||||
&NHgithook::PRE;
|
||||
&NHgithook::resetSTDIN;
|
||||
&NHgithook::POST;
|
||||
exit 0;
|
||||
30
DEVEL/hooksdir/pre-applypatch
Executable file
30
DEVEL/hooksdir/pre-applypatch
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/perl
|
||||
# $NHDT-Date$
|
||||
|
||||
#STARTUP-START
|
||||
BEGIN {
|
||||
# OS hackery has to be duplicated in each of the hooks :/
|
||||
# first the directory separator
|
||||
my $DS = quotemeta('/');
|
||||
my $PDS = '/';
|
||||
# msys: POSIXish over a Windows filesystem (so / not \ but \r\n not \n).
|
||||
# temporarily removed because inconsistent behavior
|
||||
# if ($^O eq "msys")
|
||||
# {
|
||||
# $/ = "\r\n";
|
||||
# $\ = "\r\n";
|
||||
# }
|
||||
if($^O eq "MSWin32"){
|
||||
$DS = quotemeta('\\');
|
||||
$PDS = '\\';
|
||||
}
|
||||
$gitdir = `git rev-parse --git-dir`;
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
&NHgithook::POST;
|
||||
exit 0;
|
||||
30
DEVEL/hooksdir/pre-auto-gc
Executable file
30
DEVEL/hooksdir/pre-auto-gc
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/perl
|
||||
# $NHDT-Date$
|
||||
|
||||
#STARTUP-START
|
||||
BEGIN {
|
||||
# OS hackery has to be duplicated in each of the hooks :/
|
||||
# first the directory separator
|
||||
my $DS = quotemeta('/');
|
||||
my $PDS = '/';
|
||||
# msys: POSIXish over a Windows filesystem (so / not \ but \r\n not \n).
|
||||
# temporarily removed because inconsistent behavior
|
||||
# if ($^O eq "msys")
|
||||
# {
|
||||
# $/ = "\r\n";
|
||||
# $\ = "\r\n";
|
||||
# }
|
||||
if($^O eq "MSWin32"){
|
||||
$DS = quotemeta('\\');
|
||||
$PDS = '\\';
|
||||
}
|
||||
$gitdir = `git rev-parse --git-dir`;
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
&NHgithook::POST;
|
||||
exit 0;
|
||||
30
DEVEL/hooksdir/pre-commit
Executable file
30
DEVEL/hooksdir/pre-commit
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/perl
|
||||
# $NHDT-Date$
|
||||
|
||||
#STARTUP-START
|
||||
BEGIN {
|
||||
# OS hackery has to be duplicated in each of the hooks :/
|
||||
# first the directory separator
|
||||
my $DS = quotemeta('/');
|
||||
my $PDS = '/';
|
||||
# msys: POSIXish over a Windows filesystem (so / not \ but \r\n not \n).
|
||||
# temporarily removed because inconsistent behavior
|
||||
# if ($^O eq "msys")
|
||||
# {
|
||||
# $/ = "\r\n";
|
||||
# $\ = "\r\n";
|
||||
# }
|
||||
if($^O eq "MSWin32"){
|
||||
$DS = quotemeta('\\');
|
||||
$PDS = '\\';
|
||||
}
|
||||
$gitdir = `git rev-parse --git-dir`;
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
&NHgithook::POST;
|
||||
exit 0;
|
||||
32
DEVEL/hooksdir/pre-push
Executable file
32
DEVEL/hooksdir/pre-push
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/perl
|
||||
# $NHDT-Date$
|
||||
|
||||
#STARTUP-START
|
||||
BEGIN {
|
||||
# OS hackery has to be duplicated in each of the hooks :/
|
||||
# first the directory separator
|
||||
my $DS = quotemeta('/');
|
||||
my $PDS = '/';
|
||||
# msys: POSIXish over a Windows filesystem (so / not \ but \r\n not \n).
|
||||
# temporarily removed because inconsistent behavior
|
||||
# if ($^O eq "msys")
|
||||
# {
|
||||
# $/ = "\r\n";
|
||||
# $\ = "\r\n";
|
||||
# }
|
||||
if($^O eq "MSWin32"){
|
||||
$DS = quotemeta('\\');
|
||||
$PDS = '\\';
|
||||
}
|
||||
$gitdir = `git rev-parse --git-dir`;
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::saveSTDIN;
|
||||
&NHgithook::PRE;
|
||||
&NHgithook::resetSTDIN;
|
||||
&NHgithook::POST;
|
||||
exit 0;
|
||||
30
DEVEL/hooksdir/pre-rebase
Executable file
30
DEVEL/hooksdir/pre-rebase
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/perl
|
||||
# $NHDT-Date$
|
||||
|
||||
#STARTUP-START
|
||||
BEGIN {
|
||||
# OS hackery has to be duplicated in each of the hooks :/
|
||||
# first the directory separator
|
||||
my $DS = quotemeta('/');
|
||||
my $PDS = '/';
|
||||
# msys: POSIXish over a Windows filesystem (so / not \ but \r\n not \n).
|
||||
# temporarily removed because inconsistent behavior
|
||||
# if ($^O eq "msys")
|
||||
# {
|
||||
# $/ = "\r\n";
|
||||
# $\ = "\r\n";
|
||||
# }
|
||||
if($^O eq "MSWin32"){
|
||||
$DS = quotemeta('\\');
|
||||
$PDS = '\\';
|
||||
}
|
||||
$gitdir = `git rev-parse --git-dir`;
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
&NHgithook::POST;
|
||||
exit 0;
|
||||
30
DEVEL/hooksdir/prepare-commit-msg
Executable file
30
DEVEL/hooksdir/prepare-commit-msg
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/perl
|
||||
# $NHDT-Date$
|
||||
|
||||
#STARTUP-START
|
||||
BEGIN {
|
||||
# OS hackery has to be duplicated in each of the hooks :/
|
||||
# first the directory separator
|
||||
my $DS = quotemeta('/');
|
||||
my $PDS = '/';
|
||||
# msys: POSIXish over a Windows filesystem (so / not \ but \r\n not \n).
|
||||
# temporarily removed because inconsistent behavior
|
||||
# if ($^O eq "msys")
|
||||
# {
|
||||
# $/ = "\r\n";
|
||||
# $\ = "\r\n";
|
||||
# }
|
||||
if($^O eq "MSWin32"){
|
||||
$DS = quotemeta('\\');
|
||||
$PDS = '\\';
|
||||
}
|
||||
$gitdir = `git rev-parse --git-dir`;
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
&NHgithook::POST;
|
||||
exit 0;
|
||||
Reference in New Issue
Block a user