Script for adding all new files in a SVN repository
When working with revision controlled stuff you sometimes add loads of new files to an already existing repository. Then when you are about to check in the next revision you have forgotten where all the new files are and you probably don’t feel like writing svn add thefile too many times. This is of course no problem if you’r using a decent SVN client – like Tortoise SVN on Windows – but I prefer the command line so the solution was writing a script that adds all new files in a directory structure to the SVN repository.
There are “one liners” for this but I wanted a bit more flexibility and ease of use so I wrote the a script that also lets you define regexp patterns for files you don’t want to add even if they exist in the directory structure.
This is how to use it:
- # Add all new files
- svnadd path/to/repository/
- # Add all new files except those matching the regexp
- svnadd -s ".*.txt|tmp/.*" path/to/repository/
- # Add all new files except those matching the regexp in
- # the file defined by the "-f" flag
- svnadd -f regexp.txt path/to/repository/
Quite easy! If you don’t feel like remembering the pattern for files to skip, put the regexp in a file and use the svn add thefile flag.
- #!/bin/bash
- ##########################################################################
- #
- # Script for adding all new files in a directory structure to an SVN
- # repository.
- #
- # copyright © 2007 Pontus Östlund <spam@poppa.se>
- #
- # The svnadd script is free software; you can redistribute it and/or
- # modify it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or (at your
- # option) any later version.
- #
- # The svnadd script is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
- # Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software Foundation,
- # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- #
- ##########################################################################
- while getopts "s:f:h" opts
- do
- case $opts in
- s) skip="$OPTARG";;
- f) if [ -f "$OPTARG" ]; then
- skip=$(head -n 1 $OPTARG)
- else
- echo "$OPTARG doesn't exist!"
- fi
- ;;
- h) help=1;;
- esac
- done
- shift $(($OPTIND - 1))
- if [ -z $1 ] || [ "$help" ]; then
- echo "About: svnadd enables you to add all new files in [dir] to a "
- "subversion repository"
- echo "Usage: svnadd [flags] [dir]"
- echo
- echo " -s <pattern> Regexp pattern for files to skip"
- echo " -f <path> Path to file containing regexp for files to skip"
- echo " The regexp should be placed in line one!"
- echo " [dir] The path to the repository"
- echo
- echo "Example: svnadd svnsrc/"
- echo "Example: svnadd -s 'tmp/.*.xml' svnsrc/"
- echo "Example: svnadd -f regexp.txt svnsrc/"
- echo
- exit 0
- fi
- dir=$1
- if [ ! -d "$dir" ]; then
- echo "$dir is not a directory"
- exit 1
- fi
- while read status file; do
- if [ "$status" = "?" ]; then
- res=$( echo "$file" | egrep -o "$skip" )
- if [ -z "$res" ]; then
- svn add "$file"
- fi
- fi
- done<<EOF
- $( svn st "$dir" )
- EOF
- exit 0
Download
PHP documentation browser
Even though I have my vacation right now I need to hack some ![]()
What I have done is a PHP documentation browser, I simply call it PHPDoc Browser, for GNU/Linux to read the PHP documentation locally on the computer (it’s a little bit like CHM for Windows). This little app isn’t that necessary but I thought it was a great thing for learning new stuff: The application is written in Mono/C# and uses SQLite for storing the search index.
Difference from CHM
Although there’s a CHM equivalent, XCHM, for Unix like systems I decided that my application serves a purpose: What I like about the PHP manual is that you can hit www.php.net/the_function in you browser and you will get the documentation for “the_function”. Of course I implemented the same functionality in PHPDoc Browser. You can also do a wild card search like “array_*” and you will get a list of all “array_*” functions.
I also implemented a free text search but that’s not “a real” FTS at the moment. FTS in SQLite in a little bit harder than in MySQL so while awaiting the next SQLite version the FTS is a bit of a hack. But you can quote the search to narrow it down
What’s learned?
Most of the unnecessary stuff I do I do to learn and the PHPDoc Browser is no exception. I learned how to use SQLite in Mono/C# and I also wrote a self contained installer in Bash, and Bash I havn’t really touch although I’ve been using GNU/Linux for 6-7 years! I found it quite fun writing the installer
Howto
If you would like to try it out:
- Download the install script
- Un-tar it (`tar zxvf phpdocbrowser-installer.tgz`)
- Make sure the script is executable (`chmod +x phpdocbrowser-installer`)
- Open a console and run the installer:
./phpdocbrowser-installer - Answer the questions and you’r ready to go.
The script will create a directory, ./phpdocbrowser-installer, in your home directory in wich you will find ./phpdocbrowser-installer, ./phpdocbrowser-installer and a directory, ./phpdocbrowser-installer, with the PHP documentation. A “run script” will also be installed either in ./phpdocbrowser-installer or in your home directory depending on how you answered the questions and if you agreed to create a desktop shortcut one will hopefully appear on your desktop (havn’t tested this on KDE but it should work fine in Gnome).
To run the application hit the desktop shortcut, if one was created, or invoke ./phpdocbrowser-installer from a console.
If you wish to remove the PHPDoc Browser run the following from a console:
./phpdocbrowser-installer.
And that’s that!
Download
PHPDoc Browser 17:31, Sat 17 October 2009 :: 8.9 MB





