[Lunar-commits] <moonbase> Subject: git:
Auke Kok
sofar at foo-projects.org
Thu Dec 3 22:29:48 CET 2009
commit dd556958ff4544b0682571283d9583dea55d4499
Author: Christian Riggenbach <criggenbach at magahugu.net>
Date: Thu Dec 3 22:29:48 2009 +0100
Subject: git:
---
devel/git/plugin.d/download-git.plugin | 18 ++++
devel/git/plugin.d/download-git.plugin2 | 135 +++++++++++++++++++++++++++++++
2 files changed, 153 insertions(+), 0 deletions(-)
diff --git a/devel/git/plugin.d/download-git.plugin b/devel/git/plugin.d/download-git.plugin
index 1b28551..a8aef27 100644
--- a/devel/git/plugin.d/download-git.plugin
+++ b/devel/git/plugin.d/download-git.plugin
@@ -30,6 +30,8 @@ plugin_source_download_git() {
fi
GIT_URL=$(echo $1 | cut -d: -f1-2)
+ GIT_BRANCH=$(echo $1 | cut -s -d: -f3)
+
# translate git+http(s) urls:
if [ "${GIT_URL:0:8}" == "git+http" ]; then
GIT_URL="${GIT_URL:4}"
@@ -64,10 +66,26 @@ plugin_source_download_git() {
cd $SBASE
verbose_msg "[${TRY}] git pull"
git pull && git gc && GOT_GIT="yes"
+ message "${MESSAGE_COLOR}Init and update the submodules${DEFAULT_COLOR}"
+ git submodule init
+ git submodule update
+ if [ -n "$GIT_BRANCH" ] ; then
+ message "${MESSAGE_COLOR}Checking out branch ${FILE_COLOR}$GIT_BRANCH${DEFAULT_COLOR}"
+ git checkout $GIT_BRANCH || activity_log "lget" "$MODULE" "$VERSION" "failed" "Could not checkout branch $GIT_BRANCH of \"$1\""
+ fi
cd ${CD}
else
verbose_msg "[${TRY}] git clone $GIT_URL"
git clone $GIT_URL $SBASE && GOT_GIT="yes"
+ cd $SBASE
+ message "${MESSAGE_COLOR}Init and update the submodules${DEFAULT_COLOR}"
+ git submodule init
+ git submodule update
+ if [ -n "$GIT_BRANCH" ] ; then
+ message "${MESSAGE_COLOR}Checking out branch ${FILE_COLOR}$GIT_BRANCH${DEFAULT_COLOR}"
+ git checkout $GIT_BRANCH || activity_log "lget" "$MODULE" "$VERSION" "failed" "Could not checkout branch $GIT_BRANCH of \"$1\""
+ fi
+ cd $TMPDIR/$MODULE-$VERSION
fi
if [ "$?" == "0" ] ; then
diff --git a/devel/git/plugin.d/download-git.plugin2 b/devel/git/plugin.d/download-git.plugin2
new file mode 100644
index 0000000..008206b
--- /dev/null
+++ b/devel/git/plugin.d/download-git.plugin2
@@ -0,0 +1,135 @@
+#!/bin/bash
+############################################################
+# #
+# download-git.plugin - download GIT urls #
+# #
+############################################################
+# #
+# Copyright 2005 by Auke Kok under GPLv2 #
+# #
+############################################################
+
+# valid git urls are:
+# git://
+# git+http:// (will be transformed to http://)
+# git+https:// (will be transformed to https://)
+# git+rsync:// (will be transformed to rsync://)
+# git+ssh:// (will be transformed to ssh://)
+#
+# additional, behind a ":" can be a branch to use
+
+plugin_source_download_git() {
+ # check if we can handle this URL format
+ if [ "${1:0:6}" != "git://" -a "${1:0:11}" != "git+http://" -a "${1:0:12}" != "git+https://" -a "${1:0:12}" != "git+rsync://" -a "${1:0:10}" != "git+ssh://" ] ; then
+ return 2
+ fi
+ debug_msg "plugin_source_needrefresh_git($@)"
+
+ if [ ! -x `which git` ] ; then
+ # full stop: we need to make sure the user sees this error:
+ message "${PROBLEM_COLOR}! Cannot fetch git sources without \"git\" installed${DEFAULT_COLOR}"
+ exit 1
+ fi
+
+ GIT_URL=$(echo $1 | cut -d: -f1-2)
+ GIT_BRANCH=$(echo $1 | cut -s -d: -f3)
+
+ # translate git+http(s) urls:
+ if [ "${GIT_URL:0:8}" == "git+http" ]; then
+ GIT_URL="${GIT_URL:4}"
+ elif [ "${GIT_URL:0:9}" == "git+rsync" ]; then
+ GIT_URL="${GIT_URL:4}"
+ fi
+
+ message "${MESSAGE_COLOR}Downloading GIT 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 GIT copy"
+ # unpacking
+ CD=$(pwd -P)
+ cd $CD
+ if ! unpack $2 ; then
+ message "${PROBLEM_COLOR}Warning: bad local GIT copy, checking out fresh GIT 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/.git" ] ; then
+ cd $SBASE
+ verbose_msg "[${TRY}] git pull"
+ git pull && git gc && GOT_GIT="yes"
+ else
+ verbose_msg "[${TRY}] git clone $GIT_URL"
+ pwd
+ git clone $GIT_URL $SBASE && GOT_GIT="yes"
+ fi
+
+ echo "Hallo ${CD}"
+ cd $CD
+
+ if [ "$?" == "0" ] ; then
+ break
+ fi
+
+ sleep 2
+ done
+
+ if [ "$GOT_GIT" == "yes" ] ; then
+ if [ -n "$GIT_BRANCH" ] ; then
+ message "${MESSAGE_COLOR}Checking out branch ${FILE_COLOR}$GIT_BRANCH${DEFAULT_COLOR}"
+ git checkout $GIT_BRANCH || activity_log "lget" "$MODULE" "$VERSION" "failed" "Could not checkout branch $GIT_BRANCH of \"$1\""
+ fi
+
+ 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_git() {
+ # check if we can handle this URL format
+ if [ "${1:0:6}" != "git://" -a "${1:0:11}" != "git+http://" -a "${1:0:12}" != "git+https://" -a "${1:0:12}" != "git+rsync://" -a "${1:0:10}" != "git+ssh://" ] ; then
+ return 2
+ fi
+ debug_msg "plugin_source_needrefresh_git($@)"
+
+ 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}GIT 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 threshhold is zero
+ return 0
+ fi
+}
+
+
+plugin_register SOURCE_DOWNLOAD plugin_source_download_git
+plugin_register SOURCE_NEEDREFRESH plugin_source_needrefresh_git
More information about the Lunar-commits
mailing list