nhsub docs and fixes
This commit is contained in:
@@ -24,6 +24,7 @@ CONTENTS
|
||||
4. git configuration
|
||||
5. variable expansion
|
||||
6. reserved names
|
||||
7. nhadd/nhcommit
|
||||
------------------------------------------------------------------------------
|
||||
1. email
|
||||
Email to devteam@nethack.org will usually get a response, but it may take a
|
||||
@@ -52,7 +53,9 @@ XXX windows
|
||||
XXX linux
|
||||
B. Specify the prefix for variable substitution:
|
||||
(This assumes you are not a member of DevTeam or any variant's development
|
||||
team. If you are, this may be wrong. Look for more specific documentation.)
|
||||
team. If you are, this may be wrong. Look for more specific documentation.
|
||||
For example, this file uses "MINE" for the substitution prefix - this will
|
||||
almost always be wrong if you are working with someone else.)
|
||||
Decide where you want to put this info; it should NOT be inside the
|
||||
tree you cloned from git. I use ~/nethack/GITADDDIR; for that base,
|
||||
create the needed directories and edit the file:
|
||||
@@ -82,8 +85,7 @@ D. aliases
|
||||
nhadd
|
||||
nhcommit
|
||||
These two commands take the same options as the normal git add and commit
|
||||
commands but perform RCS/CVS-style variable substitution. Note that the
|
||||
substitutions do not show up in the working directory.
|
||||
commands but perform RCS/CVS-style variable substitution.
|
||||
|
||||
Note that nothing terrible will happen if you do not use the nh* versions
|
||||
of the commands.
|
||||
@@ -94,6 +96,12 @@ D. aliases
|
||||
MINE-Revision CVS style revision number
|
||||
MINE-Branch the current git branch
|
||||
|
||||
For direct access to the substitution mechanism, use:
|
||||
nhsub
|
||||
|
||||
See the section "nhadd/nhcommit" for details on those aliases.
|
||||
Run "perldoc DEVEL/hooksdir/nhsub" for details on nhsub.
|
||||
|
||||
That's it. If you need to do something more when setting up your repository,
|
||||
keep reading. Otherwise, you are done with this section.
|
||||
|
||||
@@ -165,3 +173,26 @@ D. Using your own hooks
|
||||
Anything that matches m/^nh/i or m/^nethack/i is reserved in all
|
||||
namespaces (environment, file names, git config, etc).
|
||||
------------------------------------------------------------------------------
|
||||
7. nhadd/nhcommit
|
||||
nhadd is essentially "git nhsub $*; git add $*"
|
||||
nhcommit is essentially "git nhsub $*; git commit $*"
|
||||
|
||||
As "git add" and "git commit" have complex arguments, nhsub attempts to
|
||||
do the right thing - or at least something reasonable - for most arguments.
|
||||
If nhadd/nhcommit don't do what you need, run "git nhsub" on its own then
|
||||
add/commit.
|
||||
|
||||
So when do I need to use what?
|
||||
The object is to get nhsub run right before git takes a snapshot of each
|
||||
file. So for example:
|
||||
- use "git nhcommit <filespec>" instead of "git commit <filespec>"
|
||||
- use "git nhadd <filespec>" instead of "git add <filespec>"
|
||||
- use either "git commit" or "git nhcommit" (because the snapshot was
|
||||
already taken)
|
||||
- if you use "git nhsub <filespec>" then you can "git add <filespec>" or
|
||||
"git commit <filespec>"
|
||||
|
||||
For more complex situations, "git nhsub" takes -v and -n flags - see
|
||||
"perldoc DEVEL/hooksdir/nhsub".
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
@@ -99,11 +99,46 @@ if ($^O eq "MSWin32")
|
||||
$PDS = '\\';
|
||||
}
|
||||
|
||||
my @rawlist = &cmdparse(@ARGV);
|
||||
# various command line options to consider and what the code actually does:
|
||||
#DONE nhcommit with no files should exit(0)
|
||||
#DONE nhadd with no files should exit(0)
|
||||
#DONE commit -a?
|
||||
# add root dir
|
||||
#DONE commit -a + files -> exit(0)
|
||||
#nothing: commit --interactive/--patch
|
||||
#nothing: add -i/--interactive --patch/-p?
|
||||
#nothing: add -u/--update?????? -A/--all/--no-ignore-removal???
|
||||
#nothing (not quite right): add --no-all --ignore-removal???
|
||||
#DONE add --refresh
|
||||
#nothing: add -N/--intent-to-add
|
||||
#DONE add -n - exit(0)
|
||||
#DONE add --dry-run - exit 0
|
||||
#DONE commit --dry-run - exit 0
|
||||
#DONE?: add foo/\*/x (letting git expand the filenames)
|
||||
|
||||
my @rawlist0 = &cmdparse(@ARGV);
|
||||
|
||||
# Use git ls-files to expand command line filepaths with wildcards.
|
||||
# Let's try this for all commands.
|
||||
my @rawlist;
|
||||
foreach my $e (@rawlist0){
|
||||
if($e =~ m/[?*[\\]/){
|
||||
my @rv = &lsfiles(undef, $e);
|
||||
push(@rawlist, @rv) if(@rv);
|
||||
if($opt{f}){
|
||||
my @rv = &lsfiles('-i', $e);
|
||||
push(@rawlist, @rv) if(@rv);
|
||||
}
|
||||
} else {
|
||||
push(@rawlist, $e);
|
||||
}
|
||||
}
|
||||
|
||||
push(@rawlist,'.') if($#rawlist == -1);
|
||||
|
||||
# pick up the prefix for substitutions in this repo
|
||||
my $PREFIX = &git_config('nethack','substprefix');
|
||||
#TEST my $PREFIX = &git_config('nethack','substprefix');
|
||||
my $PREFIX = "NHDT";
|
||||
print "PREFIX: '$PREFIX'\n" if($opt{v});
|
||||
|
||||
while(@rawlist){
|
||||
@@ -256,8 +291,14 @@ sub cmdparse {
|
||||
last;
|
||||
}
|
||||
if(m/^--/){
|
||||
if($opt{cmd} eq 'add' && $_ eq '--dry-run'){
|
||||
exit 0;
|
||||
}
|
||||
if($opt{cmd} eq 'commit' && $_ eq '--dry-run'){
|
||||
$opt{'n'} = 1;
|
||||
exit 0;
|
||||
}
|
||||
if($opt{cmd} eq 'add' && $_ eq '--refresh'){
|
||||
exit 0;
|
||||
}
|
||||
shift @in;
|
||||
next;
|
||||
@@ -270,6 +311,10 @@ sub cmdparse {
|
||||
} elsif($opt{cmd} eq 'date'){
|
||||
$opt{$single}++;
|
||||
}
|
||||
|
||||
if($opt{cmd} eq 'add' && $single eq 'n'){
|
||||
exit 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
shift @in;
|
||||
@@ -279,6 +324,20 @@ sub cmdparse {
|
||||
$mode = 'f' if($opt{cmd} eq 'date' && ($opt{f}||$opt{F}));
|
||||
$mode = 'f' if($opt{cmd} eq 'add' && $opt{f});
|
||||
|
||||
if($opt{cmd} eq 'add' && $#in == -1){
|
||||
exit 0;
|
||||
}
|
||||
if($opt{cmd} eq 'commit' && $#in == -1){
|
||||
exit 0;
|
||||
}
|
||||
if($opt{cmd} eq 'add' && $opt{a} && $#in != -1){
|
||||
exit 0;
|
||||
}
|
||||
if($opt{cmd} eq 'add' && $opt{a}){
|
||||
my $x = `git rev-parse --show-toplevel`;
|
||||
$x =~ s/[\n\r]+$//;
|
||||
push(@in, $x);
|
||||
}
|
||||
return @in; # this is our file list
|
||||
}
|
||||
|
||||
@@ -312,6 +371,19 @@ sub handlevar {
|
||||
}
|
||||
}
|
||||
|
||||
sub lsfiles {
|
||||
my ($flags, $ps) = @_;
|
||||
open RV, "-|", "git ls-files $flags '$ps'" or die "Can't ls-files";
|
||||
my @rv = <RV>;
|
||||
map { s/[\r\n]+$// } @rv;
|
||||
if(!close RV){
|
||||
return undef if($! == 0);
|
||||
die "close ls-files failed: $!";
|
||||
}
|
||||
return undef if($#rv == -1);
|
||||
return @rv;
|
||||
}
|
||||
|
||||
package PREFIX;
|
||||
use POSIX qw(strftime);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user