Subversion client filtering

Last Updated on Vendredi, 24 juillet 2009 06:23 Written by Henri Gomez Vendredi, 24 juillet 2009 06:23

Even in its latest version 1.6.3, Subversion does not define type regex filtering on files to be recovered through checkout.

It is possible to use directory traversal reduced, Sparse Directories, but nothing to exclude some branches, tags or file types.

So I used the svn ls command and a little of sed to have a filter at the checkout.

In my case I wanted to keep the trunks of our different projects that host Subversion repository.

PROGDIR=/var/opengrok
SOURCESDIR=${PROGDIR}/sources
BINDIR=${PROGDIR}/bin
REPOBASEURL=http://svn.mycorp.com/

if [ $# -lt 1 ]; then
  echo "Usage: $0 repo1 repo2... "
  exit
fi

cd ${SOURCESDIR}

ALL_REPOS="$@"

for REPO in ${ALL_REPOS}; do

  echo "fetching trunk directories from ${REPO} at `date`"

  svn ls -R ${REPOBASEURL}${REPO} | grep -v branches | grep -v tags | grep /trunk/ | grep pom.xml | sed "s|\(^.*/trunk/\)\(.*$\)|\1|"  | sort | uniq > REPS_${REPO}

  PROJECTS=`cat REPS_${REPO} | xargs echo`

  mkdir -p ${REPO}
  pushd ${REPO}

  for PRJ in ${PROJECTS}; do

    PRJC=`echo ${PRJ} | sed "s|/trunk/||g"`
    mkdir -p ./${PRJC}
    pushd ./${PRJC}

    echo "cleanup local copy of project ${PRJC} from ${REPO} at `date`"
    svn cleanup

    echo "checkout ${REPOBASEURL}${REPO}/${PRJ} in ${PRJC}"
    svn co ${REPOBASEURL}${REPO}/${PRJ}

    popd

  done

  popd

done

Simple and effective, devilishly useful in conjunction with OpenGrok, which will be another ticket.

In my example I excluded the tags and branches, but you can use other patterns to exclude individuals from SVN checkout to have, locally, the sources really necessary for your use.

Learn More
Designed by RocketTheme
WordPress is Free Software released under the GNU/GPL License.