/var/lib/sorcery/modules/dl_handlers/dl_hg

     1	#!/bin/bash
     2	#---------------------------------------------------------------------
     3	##
     4	##=head1 COPYRIGHT
     5	##
     6	## Copyright 2008 by the Source Mage Team
     7	##
     8	##=head1 FUNCTIONS
     9	##
    10	##=over 4
    11	##
    12	#---------------------------------------------------------------------
    13	
    14	#---------------------------------------------------------------------
    15	##=item dl_get_hg <url>
    16	##
    17	## Fetch the specified mercurial url.
    18	##
    19	## This handler only supports tree downloads.
    20	##
    21	#---------------------------------------------------------------------
    22	function dl_hg_get() {
    23	  dl_command_check hg || return 254
    24	
    25	  local target=$1
    26	  local url_list=$2
    27	  local hints=$3
    28	  local dl_target=$4
    29	  local dl_type=$5
    30	  local url rc=0
    31	
    32	  [[ $target ]] &&
    33	  dl_connect || return 255
    34	
    35	  for url in $url_list; do
    36	    local URL HG_ROOT HG_DIRECTORY HG_TAG
    37	    url_crack "$url" "$hints"
    38	    if [[ -z $HG_DIRECTORY ]]
    39	    then
    40	      HG_DIRECTORY=${target/.hg/}
    41	    fi
    42	    if [[ -d $HG_DIRECTORY ]]; then
    43	      message "${MESSAGE_COLOR}Running hg pull...${DEFAULT_COLOR}"
    44	      ( cd $HG_DIRECTORY &&
    45	      echo hg pull $HG_ROOT &&
    46	      hg pull $HG_ROOT &&
    47	      echo hg update $HG_TAG &&
    48	      hg update $HG_TAG )
    49	      rc=$?
    50	      eval "$dl_target=\"$HG_DIRECTORY\""
    51	    else
    52	      message "${MESSAGE_COLOR}Running hg clone...${DEFAULT_COLOR}"
    53	      echo hg clone $HG_ROOT $HG_DIRECTORY
    54	      hg clone $HG_ROOT $HG_DIRECTORY &&
    55	      ( cd $HG_DIRECTORY &&
    56	      echo hg update $HG_TAG &&
    57	      hg update $HG_TAG )
    58	      rc=$?
    59	      eval "$dl_target=\"$HG_DIRECTORY\""
    60	    fi
    61	    [[ $rc == 0 ]] && break
    62	  done
    63	  dl_disconnect
    64	
    65	  eval "$dl_type=\"tree\""
    66	  return $rc
    67	}
    68	
    69	#---------------------------------------------------------------------
    70	##=back
    71	##
    72	##=head1 LICENSE
    73	##
    74	## This software is free software; you can redistribute it and/or modify
    75	## it under the terms of the GNU General Public License as published by
    76	## the Free Software Foundation; either version 2 of the License, or
    77	## (at your option) any later version.
    78	##
    79	## This software is distributed in the hope that it will be useful,
    80	## but WITHOUT ANY WARRANTY; without even the implied warranty of
    81	## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    82	## GNU General Public License for more details.
    83	##
    84	## You should have received a copy of the GNU General Public License
    85	## along with this software; if not, write to the Free Software
    86	## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    87	##
    88	#---------------------------------------------------------------------