#!/bin/bash
#---------------------------------------------------------------------
##
##=head1 COPYRIGHT
##
## Copyright 2004 by the Source Mage Team
##
##=head1 FUNCTIONS
##
##=over 4
##
#---------------------------------------------------------------------


#---------------------------------------------------------------------
##=item dl_get_svn <url>
## 
## Fetch the specified svn url.
##
## This handler only supports tree downloads.
##
#---------------------------------------------------------------------
function dl_svn_get () { 
  dl_command_check svn || return 254

  local target=$1
  local url_list=$2
  local hints=$3
  local dl_target=$4
  local dl_type=$5
  local url rc=0

  [[ $target ]] &&
  dl_connect || return 255

  for url in $url_list; do
    local URL SVN_ROOT SVN_MODULE SVN_TAG
    url_svn_crack $url

    if test -d $target; then
      message "${MESSAGE_COLOR}Running svn update...${DEFAULT_COLOR}"
      svn update -q --non-interactive -r $SVN_TAG $target
      rc=$?
      eval "$dl_target=\"$target\""
    else
      message "${MESSAGE_COLOR}Running svn checkout...${DEFAULT_COLOR}"
      # hard-coded http :-(
      svn checkout -r $SVN_TAG http://$SVN_ROOT $SVN_MODULE
      rc=$?
      eval "$dl_target=\"$SVN_MODULE\""
    fi
    [[ $rc == 0 ]] && break
  done
  dl_disconnect

  eval "$dl_type=\"tree\""
  return $rc
}

#---------------------------------------------------------------------
##=back
##
##=head1 LICENSE
##
## This software 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.
##
## This software 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 software; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
##
#---------------------------------------------------------------------
