subversion


Recently I had to face a limitation of subversion – you can set files and patterns for ignoring files (using svn:ignore) but you can not specify certain files or patterns for files to be included. In my situation, I wanted to build an Ivy repository and put only the ivy files under the version control cause all other artifacts could be rebuild using SCM.

So I came up with a simple bash script, which is run just before commit and is actually called from an ant script in a build environment:

#!/bin/bash
#
# adds only certain files to repository, adds
# all intermediate directories on their paths,
# it also works with empty space in path (except newline)
#
# @todo Add some bells and whistles!
 
REPO_NAME=<some_repo>
echo "Running $0 on" `date` "with $REPO_NAME"
 
# this file will help to limit the search, if it's modified on commit
# for example the log file of last commit, the idea here is to run 
# this script always before commit
REF_TIME_FILE=<some_file>
REP_PATH=/some/path/to/your/copies/root
 
FILE_PATTERN='ivy.xml*'
DIR=`pwd`
 
cd $REP_PATH
IFS_ORIG=$IFS
# this allows paths with whitespace, but not with newline
IFS=$'\n'
#IFS="$(echo)" another way to get newline
for ivy in `find ./ -newer $REF_TIME_FILE  -type f  -name "$FILE_PATTERN"  -print`
do
	echo "found fresh file $ivy"
	p=$ivy
	while [ $p != "." ]
	do 
			all_paths=${all_paths}${del}${p}
			p=${p%/*}	
			del=:
	done
done
 
IFS=$IFS_ORIG
#echo $all_paths | tr ':' '\n' | sort | uniq |  tr '\n' '\0' | xargs -0 -i echo {}
echo $all_paths | tr ':' '\n' | sort | uniq |  tr '\n' '\0' | xargs -0  svn add --non-recursive  2>&1 | grep "^A"
 
 
cd $DIR
echo "Finish $0 on" `date` "with $REPO_NAME"

It’s not a big deal but might help you to spare some time. There might be better ways to do it and I wonder if same can be done using “plain ant”.

Subversion clients store authentication data in ./subversion/auth for each realm.

To remove cached data go to “.subversion/auth/svn.simple” folder and delete the particular file.
There will be key (K)-value (V) pairs. “username” and “svn:realmstring” together can identify the user.
So use for example:

grep servername ./*

to find the right file.

Disable caching by opening “config” file in “.subversion” folder and setting the values of “store-passwords” and “store-auth-creds” to “no” or use –no-auth-cache as command line argument.

Since Version 1.1 subversion can deal with symlinks (see Does Subversion support symlinks?). There are only a few remarks in the manual Versioned Properties – svn:special and ’svn add’ command.

Actually all handling of the symbolic link is up to the client. Cause in creation of symlinks the used paths do matter and subversion stores the link target in simple text file with the appropriate relative or absolute path you should choose the way you create your symlinks with care.

Example – Creating a symlink in your working copy:

$ mkdir A
$ ln -s A link
$ svn add --force .
A A
A link
$ svn commit -m "link there"

the contents of the link file in svn:
link A

Example – change symlink target
$ svn del --force link
$ svn commit -m "no link"
$ mkdir B
$ ln -s B link
$ svn add --force .
$ svn commit -m "link changed to B"

the contents of the link file in svn:
link B

To exclude certain files and directories from subversion’s version control you can set the ’svn:ignore’ property as described in Ignoring Unversioned Items.
That works fine but nevertheless you might run into problems if you are using
svn add *
or similiar on linux systems. This is due to the shell expansion of wildcards. The above command is expanded to explicit files names svn add filename and seems to have the same effect as svn add --no-ignore filename.
Tip: Use svn add --force . instead!

Command line utilities are great for one-pointed tasks or for batch processing, but sometimes you just want to browse around and quickly play with the options. For that purpose I prefer to use GUI-tools.

In ubuntu you can use the svn-workbench as an GUI-Client written in python to subversion repositories. I am using KDE, so installing kdesvn (also see kde-apps.org) gives me a repository access and management functions right in my Konqueror file browser by using addresses like: ksvn+https://rcs.somehost.de/rep1. In this way you can work in repositories without explicit checkout. The only draw back appears in case you want to copy directories. Due to Konquerors way of copying/moving with KIO you will be asked for log messages for each single subdir or file recursively. To avoid being asked for log messages every time start kdesvn, go to Main Menu Settings – Configure Kdesvn – KIO/Commandline – check KIO operations use standard logmessage .

Kdesvn adds extra functions in Konqueror’s context menu : RightClick – Actions – Subversion . Kate and QuantaPlus Integration is also provided by kdesvn.

BTW: Subclipse is a good svn GUI client implementation as well, but requires an Eclipse installation.