summaryrefslogtreecommitdiffstats
path: root/scripts/libmakepkg/source/hg.sh.in
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2015-05-17 16:02:17 +0200
committerAllan McRae <allan@archlinux.org>2015-05-19 15:43:00 +0200
commit3d4529335c598e79b5a483fedc4c9d5c12ef10f1 (patch)
treef965489bcea98a5461f064584fffb16d559e7e84 /scripts/libmakepkg/source/hg.sh.in
parent1a17249159d2425dfd5103b8699673f72394a385 (diff)
downloadpacman-3d4529335c598e79b5a483fedc4c9d5c12ef10f1.tar.gz
pacman-3d4529335c598e79b5a483fedc4c9d5c12ef10f1.tar.xz
libmakepkg: extract functions for source download and extraction
Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'scripts/libmakepkg/source/hg.sh.in')
-rw-r--r--scripts/libmakepkg/source/hg.sh.in104
1 files changed, 104 insertions, 0 deletions
diff --git a/scripts/libmakepkg/source/hg.sh.in b/scripts/libmakepkg/source/hg.sh.in
new file mode 100644
index 00000000..6b21dad2
--- /dev/null
+++ b/scripts/libmakepkg/source/hg.sh.in
@@ -0,0 +1,104 @@
+#!/bin/bash
+#
+# hg.sh - function for handling the download and "extraction" of Mercurial sources
+#
+# Copyright (c) 2015 Pacman Development Team <pacman-dev@archlinux.org>
+#
+# This program 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 program 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 program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+[[ -n "$LIBMAKEPKG_SOURCE_HG_SH" ]] && return
+LIBMAKEPKG_SOURCE_HG_SH=1
+
+
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+source "$LIBRARY/util/message.sh"
+source "$LIBRARY/util/pkgbuild.sh"
+
+
+download_hg() {
+ local netfile=$1
+
+ local dir=$(get_filepath "$netfile")
+ [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
+
+ local repo=$(get_filename "$netfile")
+
+ local url=$(get_url "$netfile")
+ url=${url#hg+}
+ url=${url%%#*}
+
+ if [[ ! -d "$dir" ]] || dir_is_empty "$dir" ; then
+ msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "hg"
+ if ! hg clone -U "$url" "$dir"; then
+ error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "hg"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+ elif (( ! HOLDVER )); then
+ msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "hg"
+ cd_safe "$dir"
+ if ! hg pull; then
+ # only warn on failure to allow offline builds
+ warning "$(gettext "Failure while updating %s %s repo")" "${repo}" "hg"
+ fi
+ fi
+}
+
+extract_hg() {
+ local netfile=$1
+
+ local fragment=${netfile#*#}
+ if [[ $fragment = "$netfile" ]]; then
+ unset fragment
+ fi
+
+ local dir=$(get_filepath "$netfile")
+ [[ -z "$dir" ]] && dir="$SRCDEST/$(get_filename "$netfile")"
+
+ local repo=${netfile##*/}
+ repo=${repo%%#*}
+
+ msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "hg"
+ pushd "$srcdir" &>/dev/null
+
+ local ref=tip
+ if [[ -n $fragment ]]; then
+ case ${fragment%%=*} in
+ branch|revision|tag)
+ ref="${fragment##*=}"
+ ;;
+ *)
+ error "$(gettext "Unrecognized reference: %s")" "${fragment}"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ esac
+ fi
+
+ if [[ -d "${dir##*/}" ]]; then
+ cd_safe "${dir##*/}"
+ if ! (hg pull && hg update -C -r "$ref"); then
+ error "$(gettext "Failure while updating working copy of %s %s repo")" "${repo}" "hg"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+ elif ! hg clone -u "$ref" "$dir" "${dir##*/}"; then
+ error "$(gettext "Failure while creating working copy of %s %s repo")" "${repo}" "hg"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+
+ popd &>/dev/null
+}