nhgitset version 4
To update, run "perl DEVEL/nhgitset.pl"
Fixes:
- "nhcommit -a" has been fixed
- NHDT was hardwired in places
- no longer complain about a missing dat directory outside of the
NetHack source tree
- make update of gitinfo atomic
- Replace some hardwired directory separators with OS-dependent constructs
Backwards Incompatibilities:
- NH_DATESUB's DATE() is now Date() to match the other variables
- MSYS2 requires an additional Perl package - the MSYS2 docs have
been updated
New Help System:
- git nhhelp
This command mirrors "git help" for nh* commands.
- See git nhhelp nhsub for general help on substitution variables
New Substitution Variables:
-Brev()
An aBREViation of $PREFIX-Branch$:$PREFIX-Revision$ - this
may help get line length under control in file headers.
-Assert(TYPE=VALUE)
If TYPE does not match VALUE, do not substitute on this line.
TYPE P checks VALUE against nethack.substprefix
-Project(arg)
Returns nethack.projectname if there is no arg and an uppercase
version if arg is uc.
Other New Features:
- Add nethack.projectname
- Documentation updates - see "git nhhelp nhsub"
- On checkout or merge of a branch, check for nhgitset version updates
and provide an optional message to the user.
- Move NH_DATESUB substitutions here from cron job to keep dates in sync
- PREFIX-* keywords now available in NH_DATESUB templates
- Support use of nhgitset.pl from a different repo; note that update
checks will be dependent on keeping the original source repo up-to-date
and in the same location.
This commit is contained in:
@@ -12,11 +12,32 @@ die "Bad subcommand '$ARGV[0]'" unless $ok{$ARGV[0]};
|
||||
# we won't fail on a failure, so just system()
|
||||
$rv = system('.git/hooks/nhsub',"--$ARGV[0]",@ARGV[1..$#ARGV]);
|
||||
if($rv){
|
||||
print "warning: nhsub failed: $rv $!\n";
|
||||
print "warning: nhsub failed: $rv $!\n";
|
||||
}
|
||||
|
||||
if(length $ENV{GIT_PREFIX}){
|
||||
chdir($ENV{GIT_PREFIX}) or die "Can't chdir $ENV{GIT_PREFIX}: $!";
|
||||
chdir($ENV{GIT_PREFIX}) or die "Can't chdir $ENV{GIT_PREFIX}: $!";
|
||||
}
|
||||
|
||||
exec "git", @ARGV or die "Can't exec git: $!";
|
||||
|
||||
__END__
|
||||
=for nhgitset nhadd Add file contents to the index with NetHack additions
|
||||
=for nhgitset nhcommit Record changes to the repository with NetHack additions
|
||||
|
||||
=head1 NAME
|
||||
|
||||
C<NHadd> - NetHack internal common code for nhadd and nhcommit
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
C<git nhadd E<lt>git add optionsE<gt>>
|
||||
|
||||
C<git nhcommit E<lt>git add optionsE<gt>>
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Run nhsub with the given arguments, then run C<git add> or C<git commit>
|
||||
with the given arguments. Note that only basic arguments for those commands
|
||||
are understood; more complex situations may be handled by running C<git nhsub>
|
||||
manually before running C<git add> or C<git commit>.
|
||||
|
||||
@@ -16,9 +16,11 @@ my $tracefile = "/tmp/nhgitt.$$";
|
||||
|
||||
# OS hackery
|
||||
my $DS = quotemeta('/');
|
||||
my $PDS = '/';
|
||||
if ($^O eq "MSWin32")
|
||||
{
|
||||
$DS = quotemeta('\\');
|
||||
$PDS = '\\';
|
||||
}
|
||||
|
||||
our %saved_env;
|
||||
@@ -26,25 +28,23 @@ our @saved_argv;
|
||||
our $saved_input;
|
||||
|
||||
sub saveSTDIN {
|
||||
@saved_input = <STDIN>;
|
||||
@saved_input = <STDIN>;
|
||||
|
||||
if($trace){
|
||||
print TRACE "STDIN:\n";
|
||||
print TRACE $saved_input;
|
||||
print TRACE "ENDSTDIN\n";
|
||||
}
|
||||
if($trace){
|
||||
print TRACE "STDIN:\n";
|
||||
print TRACE $saved_input;
|
||||
print TRACE "ENDSTDIN\n";
|
||||
}
|
||||
|
||||
tie *STDIN, 'NHIO::STDIN', @saved_input;
|
||||
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;
|
||||
my $x = tied(*STDIN);
|
||||
my %x = %$x;
|
||||
my $data = @$x{DATA};
|
||||
untie *STDIN;
|
||||
tie *STDIN, 'NHIO::STDIN', $data;
|
||||
}
|
||||
|
||||
# don't need this now
|
||||
@@ -55,21 +55,142 @@ sub resetSTDIN{
|
||||
#}
|
||||
|
||||
sub PRE {
|
||||
&do_hook("PRE");
|
||||
&do_hook("PRE");
|
||||
}
|
||||
|
||||
sub POST {
|
||||
&do_hook("POST");
|
||||
&do_hook("POST");
|
||||
}
|
||||
|
||||
###
|
||||
### versioning for nhgitset and friends
|
||||
###
|
||||
|
||||
# values of nethack.setupversion and DEVEL/VERSION:
|
||||
# 1 is reserved for repos checked out before versioning was added
|
||||
# 2 used clean/smudge filter, poorly
|
||||
# 3 was first production version
|
||||
# 4 added the version file and version checking; nhhelp, NH_DATESUB support, etc.
|
||||
|
||||
sub version_in_devel {
|
||||
# (1) check for a non-null nethack.setuppath - this handles
|
||||
# any repo that has already been set up (but NOT checking
|
||||
# out <v4 over >=v4 since nethack.setuppath will exist but
|
||||
# DEVEL/VERSION will not).
|
||||
# XXX if the source repo has been removed, we'll fall back to
|
||||
# the third case - hopefully that's ok.
|
||||
# XXX there's no way to recover from a missing source repo
|
||||
# without editing .git/config.
|
||||
my $path = `git config --local nethack.setuppath`;
|
||||
chomp $path;
|
||||
$path =~ s/DEVEL$//; # NOP if config not set
|
||||
|
||||
# (2) else check the local directory; that will be correct for NHsource.
|
||||
if(0 == length $path){
|
||||
$path = `git rev-parse --show-toplevel`;
|
||||
chomp $path;
|
||||
$path = '' unless(-d "$path${PDS}DEVEL");
|
||||
}
|
||||
# (3) If that doesn't exist, check using the invocation path; that will be
|
||||
# correct for other repos during nhgitset (but will also fail for
|
||||
# checking out 3 over 4).
|
||||
if(0 == length $path){
|
||||
# strip out "DEVEL"
|
||||
$path = ($0 =~ m!^(.*)${PDS}DEVEL${PDS}.*?(*nla:DEVEL)!)[0];
|
||||
}
|
||||
# Uh oh?
|
||||
if(0==length($path) or (! -d "$path${PDS}DEVEL")){
|
||||
die "Can't locate DEVEL directory in '$path'.";
|
||||
}
|
||||
|
||||
# Handle checking out version <4 over version >=4. If
|
||||
# this seems to be the situation, don't revert the code.
|
||||
return 0 if(! -f "$path${PDS}DEVEL${PDS}VERSION");
|
||||
|
||||
my $version;
|
||||
my $verfile = "$path${PDS}DEVEL${PDS}VERSION";
|
||||
open VERFH,"<",$verfile or die "xCan't open $verfile: $!";
|
||||
$version = 0+<VERFH>;
|
||||
my $message = join('',<VERFH>);
|
||||
close VERFH;
|
||||
die "Valid version not found in $verfile" unless($version >= 4);
|
||||
return ($version,$message) if($version > 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub version_in_git {
|
||||
my $vtemp = `git config --local --get nethack.setupversion`;
|
||||
chomp($vtemp);
|
||||
return $vtemp if($vtemp > 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub version_set_git {
|
||||
my $version_new = $_[0];
|
||||
|
||||
system("git config nethack.setupversion $version_new");
|
||||
if($?){
|
||||
die "Can't set nethack.setupversion $version_new: $?,$!\n";
|
||||
}
|
||||
}
|
||||
|
||||
###
|
||||
### store githash and gitbranch in dat/gitinfo.txt
|
||||
###
|
||||
# CAUTION! This is run not just from git hooks, but also from
|
||||
# sys/unix/gitinfo.sh
|
||||
|
||||
sub nhversioning {
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
# See if we're (probably) in a "git pull", in which case we need to
|
||||
# check for upgrades.
|
||||
my $check_upgrade = 1 if($_[0]);
|
||||
|
||||
# Check for pre-v4 source repo.
|
||||
my $is_sourcerepo;
|
||||
{
|
||||
chomp($is_sourcerepo = `git config --type=int --get nethack.is-sourcerepo`);
|
||||
if(0 == length $is_sourcerepo){ # not set - assume old repo
|
||||
$is_sourcerepo = 1;
|
||||
}elsif($is_sourcerepo==1){
|
||||
;
|
||||
}elsif($is_sourcerepo==0){
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
# Skip the skipping tests if we're being called directly.
|
||||
# NB: post-commit has no args, but that will be caught by
|
||||
# the next test for non-source repos.
|
||||
if($#ARGV != -1){
|
||||
# Skip this if we didn't change branches, but see if we need to warn.
|
||||
if(defined($ARGV[2]) and ($ARGV[2] == 0)){
|
||||
# Because we can create an out of sync state, possibly warn.
|
||||
my $ref = $ARGV[1];
|
||||
if($is_sourcerepo and (0 != 0+`git diff --name-only $ref $ref^ |grep ^DEVEL|wc -l`)){
|
||||
warn "WARNING: DEVEL directory changed. Versioning may be inconsistent\n";
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if($check_upgrade){
|
||||
my $current_version = version_in_git();
|
||||
my($new_version,$message) = version_in_devel();
|
||||
if($new_version > $current_version){
|
||||
warn "nhgitset.pl and/or related programs have changed.\n";
|
||||
warn "Please re-run nhgitset.pl to update from version $current_version to $new_version.\n";
|
||||
if(length $message){
|
||||
warn "Additional information\n$message\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Skip versioning if we aren't in a source repo.
|
||||
return if(0==$is_sourcerepo);
|
||||
|
||||
my $git_sha = `git rev-parse HEAD`;
|
||||
$git_sha =~ s/\s+//g;
|
||||
my $git_branch = `git rev-parse --abbrev-ref HEAD`;
|
||||
@@ -77,7 +198,14 @@ sub nhversioning {
|
||||
die "git rev-parse failed" unless(length $git_sha and length $git_branch);
|
||||
my $exists = 0;
|
||||
|
||||
if (open my $fh, '<', 'dat/gitinfo.txt') {
|
||||
no strict 'refs';
|
||||
no strict 'subs';
|
||||
my $file_gitinfo = "dat${PDS}gitinfo.txt";
|
||||
my $file_gittemp = "dat${PDS}TMPgitinfo.txt";
|
||||
use strict 'subs';
|
||||
use strict 'refs';
|
||||
|
||||
if (open my $fh, '<', $file_gitinfo) {
|
||||
$exists = 1;
|
||||
my $hashok = 0;
|
||||
my $branchok = 0;
|
||||
@@ -91,61 +219,71 @@ sub nhversioning {
|
||||
}
|
||||
close $fh;
|
||||
if ($hashok && $branchok) {
|
||||
print "dat/gitinfo.txt unchanged, githash=".$git_sha."\n";
|
||||
print "$file_gitinfo unchanged, githash=".$git_sha."\n";
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
print "WARNING: Can't find dat directory\n" unless(-d "dat");
|
||||
warn "WARNING: Can't find dat directory\n" unless(-d "dat");
|
||||
return;
|
||||
}
|
||||
if (open my $fh, '>', 'dat/gitinfo.txt') {
|
||||
if (open my $fh, '>', $file_gittemp) {
|
||||
my $how = ($exists ? "updated" : "created");
|
||||
print $fh 'githash='.$git_sha."\n";
|
||||
print $fh 'gitbranch='.$git_branch."\n";
|
||||
print "dat/gitinfo.txt ".$how.", githash=".$git_sha."\n";
|
||||
print "$file_gitinfo ".$how.", githash=".$git_sha."\n";
|
||||
if(close($fh)){
|
||||
if(rename($file_gittemp, $file_gitinfo)){
|
||||
; # all ok
|
||||
} else {
|
||||
warn "WARNING: Can't rename $file_gittemp -> $file_gitinfo";
|
||||
}
|
||||
} else {
|
||||
warn "WARNING: Can't close temp file: $!";
|
||||
}
|
||||
} else {
|
||||
print "WARNING: Unable to open dat/gitinfo.txt: $!\n";
|
||||
warn "WARNING: Unable to open $file_gitinfo: $!\n";
|
||||
}
|
||||
}
|
||||
|
||||
# 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);
|
||||
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: $! $?";
|
||||
open TOHOOK, "|-", $hname or die "open $hname: $!";
|
||||
print TOHOOK <STDIN>;
|
||||
close TOHOOK or die "close $hname: $! $?";
|
||||
|
||||
print TRACE "END $p\n" if($trace);
|
||||
}
|
||||
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";
|
||||
}
|
||||
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;
|
||||
%saved_env = %ENV;
|
||||
@saved_argv = @ARGV;
|
||||
&trace_start;
|
||||
}
|
||||
|
||||
###
|
||||
@@ -153,42 +291,41 @@ BEGIN {
|
||||
###
|
||||
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;
|
||||
my $class = shift;
|
||||
my %fh;
|
||||
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;
|
||||
}
|
||||
}
|
||||
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};
|
||||
$self = shift;
|
||||
return $self->{EOF};
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -223,11 +360,20 @@ NHgithook - common code for NetHack git hooks (and other git bits)
|
||||
(core hook code)
|
||||
&NHgithook::POST;
|
||||
|
||||
__END__
|
||||
=for nhgitset NHgithook Infrastructure for NetHack git hooks.
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Perl module for infrastructure of NetHack Git hooks.
|
||||
|
||||
Buffers call information so multiple independent actions may be coded for
|
||||
Git hooks and similar Git callouts.
|
||||
|
||||
Maintains C<dat/gitinfo.txt>.
|
||||
|
||||
Common routines for dealing with nethack.setupversion git config variable.
|
||||
|
||||
=head1 SETUP
|
||||
|
||||
Changing the C<$trace> and C<$tracefile> variables requires editing the
|
||||
@@ -247,6 +393,9 @@ may be useful since multiple processes may be live at the same time.
|
||||
|
||||
Some features not well tested, especially under Windows.
|
||||
|
||||
Not well documented, but almost no one needs to change (or even call)
|
||||
this code.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Kenneth Lorber (keni@his.com)
|
||||
|
||||
@@ -17,24 +17,24 @@ my $dbgfile = ($^O eq "MSWin32") ? "$ENV{TEMP}.$$" : "/tmp/trace.$$";
|
||||
open TRACE, ">>", $rawin?"/dev/tty":(($debug==0)? $sink : $dbgfile);
|
||||
print TRACE "TEST TRACE\n";
|
||||
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";
|
||||
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];
|
||||
@@ -47,37 +47,37 @@ my $mark_end = '>' x $mark_len;
|
||||
my $PREFIX;
|
||||
# pick up the prefix for substitutions in this repo
|
||||
if($rawin){
|
||||
$PREFIX = "TEST";
|
||||
$PREFIX = "TEST";
|
||||
} else {
|
||||
$PREFIX = `git config --local --get nethack.substprefix`;
|
||||
chomp($PREFIX);
|
||||
$PREFIX = `git config --local --get nethack.substprefix`;
|
||||
chomp($PREFIX);
|
||||
}
|
||||
|
||||
my @out;
|
||||
my $cntout;
|
||||
if($rawin){
|
||||
@out = <STDIN>;
|
||||
@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]`;
|
||||
#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";
|
||||
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;
|
||||
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;
|
||||
# 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 "WRITING START ($ARGV[1])\n".join("",@out)."WRITING END\n";
|
||||
&dumpfile($ARGV[1], "READBACK");
|
||||
}
|
||||
print TRACE "COUNT: $cntout\n";
|
||||
|
||||
@@ -95,37 +95,37 @@ exit( ($cntout>0) ? 1 : 0);
|
||||
# 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";
|
||||
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;
|
||||
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, $_);
|
||||
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);
|
||||
}
|
||||
print TRACE "RETURN count=$::count\n";
|
||||
return($::count, @out);
|
||||
}
|
||||
|
||||
sub edit_conflict {
|
||||
@@ -305,41 +305,41 @@ print TRACE "MVM: -$varname-$oursval-$theirval-\n";
|
||||
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);
|
||||
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) .' $';
|
||||
return "\$$PREFIX-$varname: " . (($m>$t)?$mine:$theirs) .' $';
|
||||
}
|
||||
|
||||
#sub Header {
|
||||
#sub Author {
|
||||
|
||||
sub Branch {
|
||||
my($PREFIX, $varname, $mine, $theirs) = @_;
|
||||
$mine =~ s/^\s+//; $mine =~ s/\s+$//;
|
||||
$theirs =~ s/^\s+//; $theirs =~ s/\s+$//;
|
||||
return "\$$PREFIX-$varname: $mine \$" if(length $mine);
|
||||
return "\$$PREFIX-$varname: $theirs \$" if(length $theirs);
|
||||
return "\$$PREFIX-$varname\$" if(length $theirs);
|
||||
my($PREFIX, $varname, $mine, $theirs) = @_;
|
||||
$mine =~ s/^\s+//; $mine =~ s/\s+$//;
|
||||
$theirs =~ s/^\s+//; $theirs =~ s/\s+$//;
|
||||
return "\$$PREFIX-$varname: $mine \$" if(length $mine);
|
||||
return "\$$PREFIX-$varname: $theirs \$" if(length $theirs);
|
||||
return "\$$PREFIX-$varname\$" if(length $theirs);
|
||||
}
|
||||
|
||||
sub Revision {
|
||||
my($PREFIX, $varname, $mine, $theirs) = @_;
|
||||
my($m) = ($mine =~ m/1.(\d+)/);
|
||||
my($t) = ($theirs =~ m/1.(\d+)/);
|
||||
if($m > 0 && $t > 0){
|
||||
my $q = ($m > $t) ? $m : $t;
|
||||
return "\$$PREFIX-$varname: 1.$q \$";
|
||||
}
|
||||
if($m > 0){
|
||||
return "\$$PREFIX-$varname: 1.$m \$";
|
||||
}
|
||||
if($t > 0){
|
||||
return "\$$PREFIX-$varname: 1.$t \$";
|
||||
}
|
||||
return "\$$PREFIX-$varname\$";
|
||||
my($PREFIX, $varname, $mine, $theirs) = @_;
|
||||
my($m) = ($mine =~ m/1.(\d+)/);
|
||||
my($t) = ($theirs =~ m/1.(\d+)/);
|
||||
if($m > 0 && $t > 0){
|
||||
my $q = ($m > $t) ? $m : $t;
|
||||
return "\$$PREFIX-$varname: 1.$q \$";
|
||||
}
|
||||
if($m > 0){
|
||||
return "\$$PREFIX-$varname: 1.$m \$";
|
||||
}
|
||||
if($t > 0){
|
||||
return "\$$PREFIX-$varname: 1.$t \$";
|
||||
}
|
||||
return "\$$PREFIX-$varname\$";
|
||||
}
|
||||
__END__
|
||||
|
||||
@@ -396,3 +396,17 @@ TEST 8:
|
||||
===
|
||||
/* NetHack 3.7 objnam.c $TEST-Date: 1426977394 2015/03/21 22:36:34 $ $TEST-Branch: master $:$TEST-Revision: 1.108 $ */
|
||||
>>> d3
|
||||
|
||||
=for nhgitset NHsubst NetHack merge driver
|
||||
|
||||
=head1 NAME
|
||||
|
||||
C<NHsubst> - NetHack merge driver
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
(called from C<git>, do not invoke directly)
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This is invoked by git through .git/config.
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
# Copyright (c) 2015 by Kenneth Lorber, Kensington, Maryland
|
||||
# NetHack may be freely redistributed. See license for details.
|
||||
|
||||
# Not in use as of v3, but could come back in the future.
|
||||
|
||||
# clean/smudge filter for handling substitutions
|
||||
use strict;
|
||||
|
||||
@@ -54,9 +56,9 @@ if($ARGV[0] eq "--clean"){
|
||||
exit 1;
|
||||
}
|
||||
|
||||
# XXX for now, there isn't any - if we get called, we subst. No options for now.
|
||||
# XX for now, there isn't any - if we get called, we subst. No options for now.
|
||||
# get relevant config info
|
||||
#XXX
|
||||
#XX
|
||||
#git check-attr -a $ARGV[1]
|
||||
|
||||
# Process stdin to stdout.
|
||||
@@ -109,7 +111,7 @@ sub Date {
|
||||
my($val, $mode, $submode) = @_;
|
||||
if($mode eq "c"){
|
||||
if($submode==0){
|
||||
# we add this to make merge easier for now XXX
|
||||
# we add this to make merge easier for now XX
|
||||
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));
|
||||
|
||||
79
DEVEL/hooksdir/nhhelp
Normal file
79
DEVEL/hooksdir/nhhelp
Normal file
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/perl
|
||||
# $NHDT-Date: 1730238507 2024/10/29 21:48:27 $ $NHDT-Brev: keni-gitset:1.0 $
|
||||
# Copyright (c) 2024 by Kenneth Lorber, Kensington, Maryland
|
||||
# NetHack may be freely redistributed. See license for details.
|
||||
|
||||
# This deals with a git problem: there is no way to do:
|
||||
# git help alias-name
|
||||
# (yes, that will show the definition of the alias, but not show an actual
|
||||
# help document).
|
||||
#
|
||||
# So we implement this:
|
||||
# nhhelp
|
||||
# With no arguments, run perldoc on this file.
|
||||
# nhhelp FOO
|
||||
# Run perldoc on .git/hooks/FOO (if it exists).
|
||||
|
||||
if($#ARGV == -1){
|
||||
system("perldoc $0")==0 or die "perldoc error: $!\n";
|
||||
exit 0;
|
||||
}
|
||||
if($#ARGV == 0){
|
||||
if($ARGV[0] eq "-a"){
|
||||
&listhelp;
|
||||
exit 0;
|
||||
}
|
||||
|
||||
chomp(my $target = `git config nethack.aliashelp.$ARGV[0]`);
|
||||
my $file = ".git/hooks/$target";
|
||||
if(-f $file){
|
||||
system("perldoc $file")==0 or die "perldoc error: $!\n";
|
||||
} else {
|
||||
print "Unknown name '$ARGV[0]'\n";
|
||||
&usage;
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
&usage;
|
||||
exit 0;
|
||||
|
||||
sub usage {
|
||||
print <<E_O_M;
|
||||
usage: git nhhelp [<nhcmd>|-a]
|
||||
E_O_M
|
||||
}
|
||||
|
||||
sub listhelp {
|
||||
print "nhhelp is available for:\n";
|
||||
my @namelist = `git config --name-only --get-regexp 'nethack.aliashelp.*'`;
|
||||
print "NAMELIST $?\n" if($?);
|
||||
@namelist = map {
|
||||
if(m/^nethack.aliashelp.(.*)/){
|
||||
chomp(my $x = `git config 'nethack.aliasdesc.$1'`);
|
||||
sprintf("%-12s %s",$1,$x);
|
||||
}
|
||||
} sort @namelist;
|
||||
print " " . join("\n ", @namelist)."\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
__END__
|
||||
=for nhgitset nhhelp Help on NetHack git commands
|
||||
|
||||
=head1 NAME
|
||||
|
||||
C<nhhelp> - NetHack git command for help on NetHack git commands
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
C<git nhhelp [nhcmd|-a]>
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
With no arguments, print this message.
|
||||
|
||||
With one argument matching a NetHack git command, print the
|
||||
documentation for that command.
|
||||
|
||||
With the argument C<-a>, show all available nhhelp topics with one line
|
||||
summaries.
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/perl
|
||||
# $NHDT-Date: 1524689631 2018/04/25 20:53:51 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.1 $
|
||||
# NetHack 3.7 post-applypatch $NHDT-Date: 1524689631 2018/04/25 20:53:51 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1 $
|
||||
# Copyright (c) 2015 by Kenneth Lorber, Kensington, Maryland
|
||||
# NetHack may be freely redistributed. See license for details.
|
||||
|
||||
@@ -24,7 +24,11 @@ BEGIN {
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
eval {use NHgithook;};
|
||||
if($@){
|
||||
warn "loading NHgithook failed: $@";
|
||||
$nogithook = 1;
|
||||
}
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
|
||||
@@ -24,10 +24,15 @@ BEGIN {
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
eval {use NHgithook;};
|
||||
if($@){
|
||||
warn "loading NHgithook failed: $@";
|
||||
$nogithook = 1;
|
||||
}
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
&NHgithook::nhversioning;
|
||||
eval { &NHgithook::nhversioning unless($nogithook) };
|
||||
warn "nhversioning failed: $@" if($@);
|
||||
&NHgithook::POST;
|
||||
exit 0;
|
||||
|
||||
@@ -24,10 +24,17 @@ BEGIN {
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
eval {use NHgithook;};
|
||||
if($@){
|
||||
warn "loading NHgithook failed: $@";
|
||||
$nogithook = 1;
|
||||
}
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
&NHgithook::nhversioning;
|
||||
eval { &NHgithook::nhversioning unless($nogithook) };
|
||||
warn "nhversioning failed: $@" if($@);
|
||||
&NHgithook::POST;
|
||||
exit 0;
|
||||
|
||||
|
||||
|
||||
@@ -25,10 +25,15 @@ BEGIN {
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
|
||||
use NHgithook;
|
||||
eval {use NHgithook;};
|
||||
if($@){
|
||||
warn "loading NHgithook failed: $@";
|
||||
$nogithook = 1;
|
||||
}
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
&NHgithook::nhversioning;
|
||||
eval { &NHgithook::nhversioning(1) unless($nogithook) };
|
||||
warn "nhversioning failed: $@" if($@);
|
||||
&NHgithook::POST;
|
||||
exit 0;
|
||||
|
||||
@@ -24,7 +24,11 @@ BEGIN {
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
eval {use NHgithook;};
|
||||
if($@){
|
||||
warn "loading NHgithook failed: $@";
|
||||
$nogithook = 1;
|
||||
}
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::saveSTDIN;
|
||||
|
||||
@@ -24,7 +24,11 @@ BEGIN {
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
eval {use NHgithook;};
|
||||
if($@){
|
||||
warn "loading NHgithook failed: $@";
|
||||
$nogithook = 1;
|
||||
}
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
|
||||
@@ -24,7 +24,11 @@ BEGIN {
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
eval {use NHgithook;};
|
||||
if($@){
|
||||
warn "loading NHgithook failed: $@";
|
||||
$nogithook = 1;
|
||||
}
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
|
||||
@@ -24,7 +24,11 @@ BEGIN {
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
eval {use NHgithook;};
|
||||
if($@){
|
||||
warn "loading NHgithook failed: $@";
|
||||
$nogithook = 1;
|
||||
}
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
|
||||
@@ -24,7 +24,11 @@ BEGIN {
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
eval {use NHgithook;};
|
||||
if($@){
|
||||
warn "loading NHgithook failed: $@";
|
||||
$nogithook = 1;
|
||||
}
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::saveSTDIN;
|
||||
|
||||
@@ -24,7 +24,11 @@ BEGIN {
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
eval {use NHgithook;};
|
||||
if($@){
|
||||
warn "loading NHgithook failed: $@";
|
||||
$nogithook = 1;
|
||||
}
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/perl
|
||||
# $NHDT-Date: 1524689633 2018/04/25 20:53:53 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.1 $
|
||||
# NetHack 3.7 prepare-commit-msg $NHDT-Date: 1524689633 2018/04/25 20:53:53 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.1 $
|
||||
# Copyright (c) 2015 by Kenneth Lorber, Kensington, Maryland
|
||||
# NetHack may be freely redistributed. See license for details.
|
||||
|
||||
@@ -24,7 +24,11 @@ BEGIN {
|
||||
chomp $gitdir;
|
||||
push(@INC, $gitdir.$PDS."hooks");
|
||||
}
|
||||
use NHgithook;
|
||||
eval {use NHgithook;};
|
||||
if($@){
|
||||
warn "loading NHgithook failed: $@";
|
||||
$nogithook = 1;
|
||||
}
|
||||
#STARTUP-END
|
||||
|
||||
&NHgithook::PRE;
|
||||
|
||||
Reference in New Issue
Block a user