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


#---------------------------------------------------------------------
##=item dl_bzr_get <url>
##
## Fetch the specified bzr url.
##
## This handler only supports tree downloads.
##
#---------------------------------------------------------------------
dl_bzr_get() {
  dl_command_check bzr || 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 BZR_ROOT BZR_DIRECTORY BZR_BRANCH
    url_crack "$url" "$hints"
    if [[ -z $BZR_DIRECTORY ]]
    then
      BZR_DIRECTORY=${target}
    fi
    eval "$dl_target=\"$BZR_DIRECTORY\""
    if [ -d "$BZR_DIRECTORY" ]; then
      message "${MESSAGE_COLOR}Updating...${DEFAULT_COLOR}"
      bzr update "$BZR_DIRECTORY"
    else
      message "${MESSAGE_COLOR}Doing a lightweight checkout...${DEFAULT_COLOR}"
      bzr checkout --lightweight "$BZR_ROOT" "$BZR_DIRECTORY"
    fi
    ((rc = $?)) || 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
##
#---------------------------------------------------------------------
