May 23 2007

Cleaning up the Subversion

Subversion … A really wonderful tool for managing the the Software development for highly distributed programmers and tester. We can easily perform the Change Management (Source Code Management) using this tool.

A subversion cheat sheat is available at http://www.yolinux.com/TUTORIALS/Subversion.html . It’s really helpful for those who wants to know more about subversion.

It can be a messy tool if some of your team mates use it in the wrong way. You will need to remove those .o, .ko or .swp files from the subversion repository just because they have done the compilation from the local copy and forgot to run make clean and then committed that. Specially when you are a Configuration Controller (Unfortunately I am one of them and an programmer too..) . So here is the script to clean up your very own repository .

 

#!/bin/bash
# Usage: ./tidysvn.sh
# This script will clean the checked out copy of source code by removing the unnecessary files like .o , .ko and .cmd, etc
# Hacked by Maxin B. John from a shell script to generate the .m3u list

IFS=$’n’ # Input Field Separator
# Normally this internal bash variable includes
# any type of whitespace, but we want to avoid
# splitting up file names with spaces.

# Fuction to cleanup the unnecessary files.
cleanupDir ()
{
FileList=”" # initialize empty variable FileList
for FileTypes in “o” “cmd” “ko” “swp” “swo” # loop over file types.
# the user can add file types here.
# FileTypes is a variable that cycles

# inside the for loop.
do # the next line of a for loop is do

FindFiles=$(find $(pwd) -type f -iname “*.$FileTypes” | sort)
# $(command) is equivalent to `command` (another way to do command substitution)
# This is mainly useful because you can have nested command substitutions using $(),
# which does not work with backquotes.
FileList=$FileList$FindFiles
# After exiting the loop, you have a single list of files for all extensions.
# The find command above puts a n (new line) after each file, so you are
# building up a list of files with one file per line.
done # end the loop with done

if [ "${#FileList}" != "0" ] # do not remove the files if the file list is empty
then
# get the current directory
CurrDir=$(pwd)
# cleanup the *.o files from the current directory
svn rm *.o 2&> /dev/null
# cleanup the *.cmd files from the current directory
svn rm .*.cmd 2&> /dev/null
# cleanup the *.ko files from the current directory
svn rm *.ko 2&> /dev/null
# cleanup the *.swp files from the current directory
svn rm .*.swp 2&> /dev/null
# cleanup the *.swo files from the current directory
svn rm .*.swo 2&> /dev/null
fi
}

# This is the body of the script
AllDirs=$(find $(pwd) -type d | sort) # Get a complete list of full paths to subdirectories,
# including the top level directory. This list
for Directory in $AllDirs # loop over the top level directory and all subdirectories
# This didn’t have to be recursive because the find command does the work.
do
cd “$Directory” # cd to each directory
cleanupDir # The function cleanupDir is called
done

exit 0 # success !

Hmm. .. It works for me.

 


Get Adobe Flash playerPlugin by wpburn.com wordpress themes