[Lunar-commits] <moonbase> mercurial: Added the download-hg plugin for mercurial repos
Terry Chan
tchan at lunar-linux.org
Mon Oct 27 16:45:53 CET 2008
commit 077deef772579533cbd91ea35bd109055cd9bd36
Author: Terry Chan <tchan at lunar-linux.org>
Date: Mon Oct 27 10:45:53 2008 -0500
mercurial: Added the download-hg plugin for mercurial repos
---
devel/mercurial/plugin.d/download-hg.plugin | 121 +++++++++++++++++++++++++++
1 files changed, 121 insertions(+), 0 deletions(-)
diff --git a/devel/mercurial/plugin.d/download-hg.plugin b/devel/mercurial/plugin.d/download-hg.plugin
new file mode 100644
index 0000000..7c5e052
--- /dev/null
+++ b/devel/mercurial/plugin.d/download-hg.plugin
@@ -0,0 +1,121 @@
+#!/bin/bash
+############################################################
+# #
+# download-hg.plugin - download Mercurial (hg) urls #
+# #
+############################################################
+# #
+# Copyright 2005 by Auke Kok under GPLv2 #
+# #
+# Parts Copyright 2008 by Terry Chan under GPLv2 #
+# #
+############################################################
+
+# valid hg urls are:
+# hg+http:// (will be transformed to http://)
+# hg+https:// (will be transformed to https://)
+# hg+ssh:// (will be transformed to ssh://)
+
+plugin_source_download_hg() {
+ # check if we can handle this URL format
+ if [ "${1:0:10}" != "hg+http://" -a "${1:0:11}" != "hg+https://" -a "${1:0:9}" != "hg+ssh://" ] ; then
+ return 2
+ fi
+ debug_msg "plugin_source_needrefresh_hg($@)"
+
+ if [ ! -x `which hg` ] ; then
+ # full stop: we need to make sure the user sees this error:
+ message "${PROBLEM_COLOR}! Cannot fetch hg sources without \"mercurial\" installed${DEFAULT_COLOR}"
+ exit 1
+ fi
+
+ HG_URL=$(echo $1 | cut -d: -f1-2)
+ # translate hg+http(s) urls:
+ if [ "${HG_URL:0:7}" == "hg+http" ]; then
+ HG_URL="${HG_URL:3}"
+ fi
+
+ message "${MESSAGE_COLOR}Downloading HG module for module ${MODULE_COLOR}${MODULE}${DEFAULT_COLOR}"
+
+ SBASE=$(source_basename $2)
+ mk_source_dir $TMPDIR/$MODULE-$VERSION
+ cd $TMPDIR/$MODULE-$VERSION
+ if [ -f "$3/$2" ] ; then
+ verbose_msg "Extracting local HG copy"
+ # unpacking
+ CD=$(pwd -P)
+ cd $CD
+ if ! unpack $2 ; then
+ message "${PROBLEM_COLOR}Warning: bad local HG copy, checking out fresh HG copy${DEFAULT_COLOR}"
+ rm_source_dir $TMPDIR/$MODULE-$VERSION
+ mk_source_dir $TMPDIR/$MODULE-$VERSION
+ fi
+ fi
+
+ NUM_RETRY=${NUM_RETRY:-5}
+ if [ "$NUM_RETRY" -eq 0 ]; then
+ NUM_RETRY=1000
+ fi
+
+ for (( TRY=1 ; $TRY<$NUM_RETRY+1 ; TRY++ )) ; do
+ if [ -d "$SBASE/.hg" ] ; then
+ cd $SBASE
+ verbose_msg "[${TRY}] hg pull"
+ hg pull && hg update && GOT_HG="yes"
+ cd ${CD}
+ else
+ verbose_msg "[${TRY}] hg clone $HG_URL"
+ hg clone $HG_URL $SBASE && GOT_HG="yes"
+ fi
+
+ if [ "$?" == "0" ] ; then
+ break
+ fi
+
+ sleep 2
+ done
+
+ if [ "$GOT_HG" == "yes" ] ; then
+ message "${MESSAGE_COLOR}Creating ${FILE_COLOR}$2${DEFAULT_COLOR}"
+ # pack
+ tar cjf $3/$2 $SBASE
+ else
+ activity_log "lget" "$MODULE" "$VERSION" "failed" "Could not fetch \"$1\""
+ fi
+
+ cd $TMPDIR
+ rm_source_dir $TMPDIR/$MODULE-$VERSION
+
+}
+
+
+plugin_source_needrefresh_hg() {
+ # check if we can handle this URL format
+ if [ "${1:0:10}" != "hg+http://" -a "${1:0:11}" != "hg+https://" -a "${1:0:9}" != "hg+ssh://" ] ; then
+ return 2
+ fi
+ debug_msg "plugin_source_needrefresh_hg($@)"
+
+ if [ ! -f $3/$2 ]; then
+ return 0
+ fi
+
+ REPOSITORY_THRESHOLD=${REPOSITORY_THRESHOLD:-10}
+ if (( "REPOSITORY_THRESHOLD" > 0 )) ; then
+ if [ "$(find $3/$2 -amin +$REPOSITORY_THRESHOLD)" == "$3/$2" ] ; then
+ # it is older:
+ return 0
+ else
+ message "${MESSAGE_COLOR}HG update not required for \"${FILE_COLOR}$(basename $2)${DEFAULT_COLOR}${CYAN}\" (less than $REPOSITORY_THRESHOLD minutes old)${DEFAULT_COLOR}"
+ # now we can send a FAIL so the next plugins are skipped:
+ return 1
+ fi
+ else
+ # always return true if threshold is zero
+ return 0
+ fi
+}
+
+
+plugin_register SOURCE_DOWNLOAD plugin_source_download_hg
+plugin_register SOURCE_NEEDREFRESH plugin_source_needrefresh_hg
More information about the Lunar-commits
mailing list