From dfbd94458efbe5ae949da6f79b23049decaf8295 Mon Sep 17 00:00:00 2001 From: Davide Madrisan Date: Mon, 29 Oct 2012 22:55:49 +0100 Subject: [PATCH] libnetwork.lib: new helper function: 'git.download' Signed-off-by: Davide Madrisan --- ChangeLog | 4 +++ lib/libnetwork.lib.in | 67 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/ChangeLog b/ChangeLog index b2a4ba2..1bae68f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -52,6 +52,10 @@ Changes in version 1.12.6 Update some requirements of the autospec subpackages in order to always use the real package names instead of their aliases ('Provides' tag). ++ update + * lib/libnetwork.lib - Davide Madrisan: + New helper function: 'git.download()'. + ------------------------------------------------------------------------------- Changes in version 1.12.5 diff --git a/lib/libnetwork.lib.in b/lib/libnetwork.lib.in index d8f1471..2083c05 100644 --- a/lib/libnetwork.lib.in +++ b/lib/libnetwork.lib.in @@ -842,6 +842,73 @@ curl $options --user \"***:***\" --quote \"DELE $deletefile\" $1" [[ "$retval" != "0" && "$exitonerror" = 1 ]] && exit 1 } +# function git.download +# helper for creating a tarball from a git repository +# args: +# -d, --destdir : target directory +# -p, --proxy : proxy server +# -u, --proxy-user : proxy user +# $@ : git repository +# +# return value: +# 0 + +function git.download() { + local ARGS + ARGS=`LC_ALL=C getopt \ + -o d:p:u: \ + --long destdir:,proxy:,proxy-user: \ + -n "$FUNCNAME" -- "$@"` + [ $? = 0 ] || notify.error $"(bug)"" -- $FUNCNAME: "$"\`getopt' error" + + local destdir + local proxy proxy_user + + eval set -- "$ARGS" + while :; do + case "$1" in + -d|--destdir) + destdir="$2"; shift + notify.debug "$FUNCNAME: destdir = \"$destdir\"" + ;; + -p|--proxy) + proxy="$2"; shift + notify.debug "$FUNCNAME: proxy = \"$proxy\"" + ;; + -u|--proxy-user) + proxy_user="$2"; shift + notify.debug "$FUNCNAME: proxy_user = \"$proxy_user\"" + ;; + --) shift; break;; + *) notify.error $"\ +(bug)"" -- $FUNCNAME: "$"\`getopt' error: bad command \`$1'" ;; + esac + shift + done + + local giturl_and_branch="$1" + + notify.debug "$FUNCNAME: giturl_and_branch = \"$giturl_and_branch\"" + [ "$giturl_and_branch" ] || notify.error $"\ +(bug)"" -- $FUNCNAME: "$"missing mandatory arg"" (#1)" + + [ "$destdir" ] || notify.error $"\ +(bug)"" -- $FUNCNAME: "$"missing mandatory arg"" (--destdir)" + + local token_dirname="${giturl_and_branch%/*}" + local token_basename="${giturl_and_branch##*/}" + notify.debug "$FUNCNAME: token_dirname = \"$token_dirname\"" + notify.debug "$FUNCNAME: token_basename = \"$token_basename\"" + + local git_branch="${token_dirname##*/}" + notify.debug "$FUNCNAME: git_branch = \"$git_branch\"" + + git.create_tarball \ + --destdir "$destdir" \ + --preserve-dot-git "0" --git-branch "$git_branch" \ + "${token_dirname%/*}" +} + # function git.create_tarball # clone a git repository and convert is into a tarball file #