 ___              _                   
 |   \ _____ _____| |___ _ __  ___ _ _ 
 | |) / -_) V / -_) / _ \ '_ \/ -_) '_|
 |___/\___|\_/\___|_\___/ .__/\___|_|  
                        |_|            

$NHDT-Date: 1447180052 2015/11/10 18:27:32 $

Welcome to the NetHack Infrastructure Developer's Guide.

This is the info you need if you are developing code for NetHack.
(This information is from DevTeam.  If you are working with a variant please
check for additional documentation for that variant.)

For information on building NetHack, see README in the top level directory.
For information on playing NetHack, see the Guidebook in the doc directory.

DANGER!  WORK IN PROGRESS!  Known issues marked XXX.

CONTENTS
1. email
2. git repositories
3. bug reporting
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
while.  Please do not send save files, binary screen grabs, or other large
things.
------------------------------------------------------------------------------
2. git repositories
The public NetHack git repository is available (read-only) on SourceForge at:
  git://git.code.sf.net/p/nethack/NHsource

XXX need to discuss what branches are available
------------------------------------------------------------------------------
3. bug reporting
Please use the form at http://www.nethack.org/common/contact.html (or send
us an email if that's more appropriate).
------------------------------------------------------------------------------
4. git configuration

NOTE: These instructions assume you are on the default branch ("master");
      this _is_ where you want to be for setting things up.  This may or may
      not be the branch you want to use for your changes; see the appropriate
      project private documentation for more information (if you are working
      alone we suggest using branch names starting with "LOCAL-").

A. If you have never set up git on this machine before:
   (This assumes you will only be using git for NetHack.  If you are going to
   use it for other projects as well, think before you type.)
	Tell git what name (or nicname) and email address to use for you:
		git config --global user.name "MY NAME"
		git config --global user.email USER@EXAMPLE.COM
   You probably want to set up a credential cache.
	Mac OS X:
		git config --global credential.helper osxkeychain
	Windows:
		git config --global credential.helper store
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.
   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:
		~/nethack/GITADDDIR/DOTGIT/PRE
	Put this in it (if your OS is not Unix-like you may need to change
	the first line):
		#!/bin/sh
		git config nethack.substprefix MINE
	Now make it executable:
		chmod +x ~/nethack/GITADDDIR/DOTGIT/PRE
C. Configure the repository:
	- cd to the top level of the repository
	- tell the repository about the directory you created above:
		git config nethack.gitadddir FULL_PATH_TO_GITADDDIR
	   so for the example above:
		git config nethack.gitadddir ~/nethack/GITADDDIR
	- do the automated setup:
		perl DEVEL/nhgitset.pl
	  If it complains, fix what it complains about.  nhgitset.pl accepts
	  the following options:
		-v verbose
		-n dry run
   You can re-run nhgitset.pl as often as needed; occasionally we will
   update it and ask you to run it again.
D. aliases
   Two aliases are installed by nhgitset.pl:
	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 nothing terrible will happen if you do not use the nh* versions
   of the commands.

   Supported substitutions:
	MINE-Date	the commit time and date
   Experimental substitutions:
	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.

1) to run your own hooks in addition to ours:
	name your hook
		WHEN-HOOKNAME
	where WHEN is
		PRE	(run your code before the NetHack hook)
		POST	(run your code after the NetHack hook)
	and HOOKNAME is the normal git name of the hook.
   Make sure the hooks are executable (chmod +x ...).
   Be sure to test carefully since the composition of two bits of code may or
   may not do what you want.
2) to install other bits on setup:
	Put additional files in the GITADDDIR tree.  Use "DOTGIT" instead of
	".git".  If a file called PRE, POST, or INSTEAD exists in a
	subdirectory of GITADDDIR, it is run before the copy, after the copy,
	or instead of the copy.  No copy operation is attempted in the DOTGIT
	directory; use a script and standard git commands to change the
	contents as needed.
3) NB: In all namespaces, anything that matches m/^nh/i or m/^nethack/i is
   reserved.
------------------------------------------------------------------------------
5. variable expansion
A. Introduction
   We have implemented an RCS/CVS/SVN style variable expansion mechanism.
   References of either of the formats:
	$PREFIX-VARNAME$
	$PREFIX-VARNAME: VALUE $
   will be handled (if enabled).

   The PREFIX is the value in the git config variable nethack.substprefix.
   VARNAME is one of:
	Date
	Branch (experimental)
	Revision (experimental)
   other names will give a warning.

B. Enabling variable expansion
   Variable expansion is controlled by the .gitattributes file.

   To enable variable expansion:
        pattern NHSUBST
   To disable variable expansion:
	pattern -NHSUBST

   More information: "git help gitattributes"

C. Oddities
   To trigger variable expansion, you _must_ use "git nhadd" or "git nhcommit"
   instead of "git add" or "git commit."  Nothing terrible will happen if you
   use the wrong one, but the values will not be updated.

   Variable expansion modifies the files in the work tree - your editor or
   IDE may or may not be happy with this.

D. Using your own hooks
   You can use your own hooks - put them in .git/hooks as usual BUT name them
   as follows:
	WHEN-HOOKNAME
   where WHEN is:
	PRE	(execute the code before the NetHack hook)
	POST	(execute the code after the NetHack hook)
   and HOOKNAME is the normal git name for the hook.

   Test carefully - interactions between hooks can be nasty.
------------------------------------------------------------------------------
6. reserved names
   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".
   
------------------------------------------------------------------------------
