I am building a quickie script to deal with CVS commit email notifications. According to the CVSNT docco, you just set up a line in your loginfo like this:
DEFAULT cmd
where DEFAULT means the default action and cmd is the command you are sending. Dirt easy, right? You could replace DEFAULT with mymodule/subdir/subsub... to only send emails to a particular module, or ALL to send emails for EVERY module, along with any other loginfo action. See the CVSNT docs for details.
PHP is my scripting language of choice, (although there is a vast cornucopia of languages that would work nicely as well). So I just make cmd be "C:\path\to\php.exe c:\path\to\script.php %{sVv}"
The {%sVv} tells CVSNT to replace it with the current module name (i.e. mymodule/subdir/subsub) the files committed, and their previous and current versions in a format something like this:
myModule/sandbox/CommitLogTests README.txt,1.4,1.5 test.txt,1.2,1.3
So with some regex and/or explosion magick, one can easily tear that apart, using PHP's builtin $argv[] variable.
CVSNT also sends a bunch of information to stdin, its format looks something like this:
Update of H:/Full/Path/Tp/CVSRepository/cvs/myModule/sandbox/CommitLogTests
In directory computername:H:\\CVSTemp\\cvs-serv223a\\sandbox\\CommitLogTests
Modified Files:
README.txt test.txt
Log Message:
Test of a commit
It is a simple case of grabbing the STDIN filehandle, and read bytes till feof() is hit. After that, 'splosion and regex magick again work well. I just 'sploded and searched for "Log Message:" in the array myself.
A few pointers:
- Do: run your script through php lint (php(.exe) -l [script])
- Do: test your script by calling it directly, and redirecting a text file that has contents similar to above.
- Do NOT: blindly hook it into your live CVSNT server without giving it a good testing. You might hose things badly enough to require a service shutdown, and manual lockfile removal in your repository.
(this post probably also applies to regular CVS as well)