diff options
| author | Tomas Chvatal <scarabeus@gentoo.org> | 2011-02-11 23:44:34 +0100 |
|---|---|---|
| committer | Tomas Chvatal <scarabeus@gentoo.org> | 2011-02-11 23:51:52 +0100 |
| commit | 8f6cdc751ccc36348dd3402662e257f29419795b (patch) | |
| tree | cde120cc8dd9d54ae755292ad6b3a8f805a6f980 /eclass | |
| parent | 86b6e54716f127efbebc9a88b44a03ce472a839c (diff) | |
| download | kde-8f6cdc751ccc36348dd3402662e257f29419795b.tar.gz kde-8f6cdc751ccc36348dd3402662e257f29419795b.tar.bz2 kde-8f6cdc751ccc36348dd3402662e257f29419795b.zip | |
Update git-2 eclass based on comments from -dev ml.
Diffstat (limited to 'eclass')
| -rw-r--r-- | eclass/git-2.eclass | 212 |
1 files changed, 99 insertions, 113 deletions
diff --git a/eclass/git-2.eclass b/eclass/git-2.eclass index 3e48770dc1e..936fc3cbcce 100644 --- a/eclass/git-2.eclass +++ b/eclass/git-2.eclass @@ -7,7 +7,7 @@ # Tomas Chvatal <scarabeus@gentoo.org> # @BLURB: This eclass provides functions for fetch and unpack git repositories # @DESCRIPTION: -# Eclass for easing maitenance of live ebuilds using git as remote repositories. +# Eclass for easing maitenance of live ebuilds using git as remote repository. # Eclass support working with git submodules and branching. # This eclass support all EAPIs @@ -27,42 +27,38 @@ EGIT_SOURCEDIR="${WORKDIR}/${P}" git-2_init_variables() { debug-print-function ${FUNCNAME} "$@" - # @ECLASS-VARIABLE: ESCM_STORE_DIR + # @ECLASS-VARIABLE: EGIT_STORE_DIR # @DESCRIPTION: # Storage directory for git sources. - : ${ESCM_STORE_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/egit-src"} + : ${EGIT_STORE_DIR:="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/egit-src"} # @ECLASS-VARIABLE: EGIT_HAS_SUBMODULES # @DESCRIPTION: - # Set this to non-empty value to enable submodule support (slower). + # Set this to non-empty value to enable submodule support. : ${EGIT_HAS_SUBMODULES:=} - # @ECLASS-VARIABLE: ESCM_FETCH_CMD + # @ECLASS-VARIABLE: EGIT_FETCH_CMD # @DESCRIPTION: # Command for cloning the repository. - : ${ESCM_FETCH_CMD:="git clone"} + : ${EGIT_FETCH_CMD:="git clone"} - # @ECLASS-VARIABLE: ESCM_UPDATE_CMD + # @ECLASS-VARIABLE: EGIT_UPDATE_CMD # @DESCRIPTION: # Git fetch command. - if [[ -n ${EGIT_HAS_SUBMODULES} ]]; then - ESCM_UPDATE_CMD="git pull -f -u" - else - ESCM_UPDATE_CMD="git fetch -t -f -u" - fi + : ${EGIT_UPDATE_CMD:="git pull -f -u"} - # @ECLASS-VARIABLE: ESCM_OPTIONS + # @ECLASS-VARIABLE: EGIT_OPTIONS # @DESCRIPTION: # This variable value is passed to clone and fetch. - : ${ESCM_OPTIONS:=} + : ${EGIT_OPTIONS:=} - # @ECLASS-VARIABLE: ESCM_MASTER + # @ECLASS-VARIABLE: EGIT_MASTER # @DESCRIPTION: # Variable for specifying master branch. # Usefull when upstream don't have master branch. - : ${ESCM_MASTER:=master} + : ${EGIT_MASTER:=master} - # @ECLASS-VARIABLE: ESCM_REPO_URI + # @ECLASS-VARIABLE: EGIT_REPO_URI # @DESCRIPTION: # URI for the repository # e.g. http://foo, git://bar @@ -75,55 +71,49 @@ git-2_init_variables() { # ssh:// eval X="\$${PN//[-+]/_}_LIVE_REPO" if [[ ${X} = "" ]]; then - : ${ESCM_REPO_URI:=} + : ${EGIT_REPO_URI:=} else - ESCM_REPO_URI="${X}" - fi - [[ -z ${ESCM_REPO_URI} ]] && die "ESCM_REPO_URI must have some value." - if [[ -z ${ESCM_REPO_URI%%:*} ]] ; then - case ${ESCM_REPO_URI%%:*} in - git*|http|https|rsync|ssh) ;; - *) die "Protocol for fetch from "${ESCM_REPO_URI%:*}" is not yet implemented in eclass." ;; - esac + EGIT_REPO_URI="${X}" fi + [[ -z ${EGIT_REPO_URI} ]] && die "EGIT_REPO_URI must have some value." - # @ECLASS-VARIABLE: ESCM_OFFLINE + # @ECLASS-VARIABLE: EVCS_OFFLINE # @DESCRIPTION: - # Set this variable to a non-empty value to disable the automatic updating of - # an GIT source tree. This is intended to be set outside the git source + # Set this variable to a non-empty value to disable the automatic updating + # of an GIT source tree. This is intended to be set outside the git source # tree by users. - : ${ESCM_OFFLINE:=${ESCM_OFFLINE}} + : ${EVCS_OFFLINE:=} - # @ECLASS-VARIABLE: ESCM_BRANCH + # @ECLASS-VARIABLE: EGIT_BRANCH # @DESCRIPTION: # Specify the branch we want to check out from the repository eval X="\$${PN//[-+]/_}_LIVE_BRANCH" if [[ "${X}" = "" ]]; then - : ${ESCM_BRANCH:=${ESCM_MASTER}} + : ${EGIT_BRANCH:=${EGIT_MASTER}} else - ESCM_BRANCH="${X}" + EGIT_BRANCH="${X}" fi - # @ECLASS-VARIABLE: ESCM_COMMIT + # @ECLASS-VARIABLE: EGIT_COMMIT # @DESCRIPTION: # Specify commit we want to check out from the repository. eval X="\$${PN//[-+]/_}_LIVE_COMMIT" if [[ "${X}" = "" ]]; then - : ${ESCM_COMMIT:=${ESCM_BRANCH}} + : ${EGIT_COMMIT:=${EGIT_BRANCH}} else - ESCM_COMMIT="${X}" + EGIT_COMMIT="${X}" fi # @ECLASS-VARIABLE: EGIT_REPACK # @DESCRIPTION: - # Set to non-empty value to repack objects to save disk space. However this can - # take a REALLY LONG time with VERY big repositories. + # Set to non-empty value to repack objects to save disk space. However this + # can take a REALLY LONG time with VERY big repositories. : ${EGIT_REPACK:=} # @ECLASS-VARIABLE: EGIT_PRUNE # @DESCRIPTION: - # Set to non-empty value to prune loose objects on each fetch. This is useful - # if upstream rewinds and rebases branches often. + # Set to non-empty value to prune loose objects on each fetch. This is + # useful if upstream rewinds and rebases branches often. : ${EGIT_PRUNE:=} } @@ -140,10 +130,11 @@ git-2_submodules() { pushd "${1}" &> /dev/null # for submodules operations we need to be online - if [[ -z ${ESCM_OFFLINE} && -n ${EGIT_HAS_SUBMODULES} ]]; then + if [[ -z ${EVCS_OFFLINE} && -n ${EGIT_HAS_SUBMODULES} ]]; then export GIT_DIR=${EGIT_DIR} debug-print "${FUNCNAME}: git submodule init" - git submodule init || die "${FUNCNAME}: git submodule initialisation failed" + git submodule init \ + || die "${FUNCNAME}: git submodule initialisation failed" debug-print "${FUNCNAME}: git submodule sync" git submodule sync "" die "${FUNCNAME}: git submodule sync failed" debug-print "${FUNCNAME}: git submodule update" @@ -156,21 +147,22 @@ git-2_submodules() { # @FUNCTION: git-2_branch # @DESCRIPTION: -# Internal function that changes branch for the repo based on ESCM_COMMIT and -# ESCM_BRANCH variables. +# Internal function that changes branch for the repo based on EGIT_COMMIT and +# EGIT_BRANCH variables. git-2_branch() { debug-print-function ${FUNCNAME} "$@" debug-print "${FUNCNAME}: working in \"${EGIT_SOURCEDIR}\"" pushd "${EGIT_SOURCEDIR}" &> /dev/null - local branchname=branch-${ESCM_BRANCH} src=origin/${ESCM_BRANCH} - if [[ "${ESCM_COMMIT}" != "${ESCM_BRANCH}" ]]; then - branchname=tree-${ESCM_COMMIT} - src=${ESCM_COMMIT} + local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH} + if [[ "${EGIT_COMMIT}" != "${EGIT_BRANCH}" ]]; then + branchname=tree-${EGIT_COMMIT} + src=${EGIT_COMMIT} fi debug-print "${FUNCNAME}: git checkout -b ${branchname} ${src}" - git checkout -b ${branchname} ${src} || die "${FUNCNAME}: changing the branch failed" + git checkout -b ${branchname} ${src} \ + || die "${FUNCNAME}: changing the branch failed" popd > /dev/null @@ -197,39 +189,40 @@ git-2_gc() { # @FUNCTION: git-2_prepare_storedir # @DESCRIPTION: -# Internal function preparing directory where we are going to store SCM repository. +# Internal function preparing directory where we are going to store SCM +# repository. git-2_prepare_storedir() { debug-print-function ${FUNCNAME} "$@" local clone_dir + local save_sandbox_write=${SANDBOX_WRITE} # initial clone, we have to create master git storage directory and play # nicely with sandbox - if [[ ! -d "${ESCM_STORE_DIR}" ]] ; then + if [[ ! -d "${EGIT_STORE_DIR}" ]] ; then debug-print "${FUNCNAME}: Creating git main storage directory" - addwrite "${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}" - mkdir -p "${ESCM_STORE_DIR}" \ - || die "${FUNCNAME}: can't mkdir \"${ESCM_STORE_DIR}\"." + addwrite / + mkdir -p "${EGIT_STORE_DIR}" \ + || die "${FUNCNAME}: can't mkdir \"${EGIT_STORE_DIR}\"." + SANDBOX_WRITE=${save_sandbox_write} fi - cd -P "${ESCM_STORE_DIR}" || die "${FUNCNAME}: can't chdir to \"${ESCM_STORE_DIR}\"" - # allow writing into ESCM_STORE_DIR - addwrite "${ESCM_STORE_DIR}" + cd -P "${EGIT_STORE_DIR}" \ + || die "${FUNCNAME}: can't chdir to \"${EGIT_STORE_DIR}\"" + # allow writing into EGIT_STORE_DIR + addwrite "${EGIT_STORE_DIR}" # calculate the proper store dir for data - [[ -z ${ESCM_REPO_URI##*/} ]] && ESCM_REPO_URI="${ESCM_REPO_URI%/}" - clone_dir="${ESCM_REPO_URI##*/}" - export EGIT_DIR="${ESCM_STORE_DIR}/${clone_dir}" + [[ -z ${EGIT_REPO_URI##*/} ]] && EGIT_REPO_URI="${EGIT_REPO_URI%/}" + clone_dir="${EGIT_REPO_URI##*/}" + export EGIT_DIR="${EGIT_STORE_DIR}/${clone_dir}" debug-print "${FUNCNAME}: Storing the repo into \"${EGIT_DIR}\"." # we can not jump between using and not using SUBMODULES so we need to # refetch the source when needed - if [[ -n ${EGIT_HAS_SUBMODULES} && -d "${EGIT_DIR}" && ! -d "${EGIT_DIR}"/.git ]]; then - debug-print "${FUNCNAME}: \"${clone_dir}\" was bare copy removing..." - rm -rf "${EGIT_DIR}" - fi - if [[ -z ${EGIT_HAS_SUBMODULES} && -d "${EGIT_DIR}" && -d "${EGIT_DIR}"/.git ]]; then - debug-print "${FUNCNAME}: \"${clone_dir}\" was not copy removing..." - rm -rf "${EGIT_DIR}" + if [[ -d "${EGIT_DIR}" && ! -d "${EGIT_DIR}"/.git ]]; then + debug-print "${FUNCNAME}: \"${clone_dir}\" was bare copy moving..." + mv "${EGIT_DIR}" "${EGIT_DIR}.bare" \ + || die "${FUNCNAME}: Moving the bare sources failed." fi } @@ -239,41 +232,33 @@ git-2_prepare_storedir() { git-2_move_source() { debug-print-function ${FUNCNAME} "$@" - if [[ -n ${EGIT_HAS_SUBMODULES} ]]; then - pushd "${EGIT_DIR}" &> /dev/null - debug-print "${FUNCNAME}: rsync -rlpgo . \"${EGIT_SOURCEDIR}\"" - rsync -rlpgo . "${EGIT_SOURCEDIR}" || die "${FUNCNAME}: sync of git data to \"${EGIT_SOURCEDIR}\" failed" - popd &> /dev/null - else - debug-print "${FUNCNAME}: git clone -l -s -n \"${EGIT_DIR}\" \"${EGIT_SOURCEDIR}\"" - git clone -l -s -n "${EGIT_DIR}" "${EGIT_SOURCEDIR}" || die "${FUNCNAME}: sync of git data to \"${EGIT_SOURCEDIR}\" failed" - fi + pushd "${EGIT_DIR}" &> /dev/null + debug-print "${FUNCNAME}: rsync -rlpgo . \"${EGIT_SOURCEDIR}\"" + rsync -rlpgo . "${EGIT_SOURCEDIR}" \ + || die "${FUNCNAME}: sync to \"${EGIT_SOURCEDIR}\" failed" + popd &> /dev/null } # @FUNCTION: git-2_fetch # @DESCRIPTION: -# Internal function fetching repository from ESCM_REPO_URI and storing it in specified ESCM_STORE_DIR. +# Internal function fetching repository from EGIT_REPO_URI and storing it in +# specified EGIT_STORE_DIR. git-2_fetch() { debug-print-function ${FUNCNAME} "$@" - local oldsha1 cursha1 extra_clone_opts upstream_branch + local oldsha1 cursha1 upstream_branch - if [[ -n ${EGIT_HAS_SUBMODULES} ]]; then - upstream_branch=origin/${ESCM_BRANCH} - else - upstream_branch=${ESCM_BRANCH} - extra_clone_opts="--bare" - fi + upstream_branch=origin/${EGIT_BRANCH} if [[ ! -d ${EGIT_DIR} ]] ; then # first clone einfo "GIT NEW clone -->" - einfo " repository: ${ESCM_REPO_URI}" + einfo " repository: ${EGIT_REPO_URI}" - debug-print "${ESCM_FETCH_CMD} ${extra_clone_opts} ${ESCM_OPTIONS} \"${ESCM_REPO_URI}\" \"${EGIT_DIR}\"" - ${ESCM_FETCH_CMD} ${extra_clone_opts} ${ESCM_OPTIONS} "${ESCM_REPO_URI}" "${EGIT_DIR}" \ - || die "${FUNCNAME}: can't fetch from ${ESCM_REPO_URI}." + debug-print "${EGIT_FETCH_CMD} ${EGIT_OPTIONS} \"${EGIT_REPO_URI}\" \"${EGIT_DIR}\"" + ${EGIT_FETCH_CMD} ${EGIT_OPTIONS} "${EGIT_REPO_URI}" "${EGIT_DIR}" \ + || die "${FUNCNAME}: can't fetch from ${EGIT_REPO_URI}." pushd "${EGIT_DIR}" &> /dev/null cursha1=$(git rev-parse ${upstream_branch}) @@ -281,37 +266,37 @@ git-2_fetch() { git-2_submodules "${EGIT_DIR}" popd &> /dev/null - elif [[ -n ${ESCM_OFFLINE} ]] ; then + elif [[ -n ${EVCS_OFFLINE} ]] ; then pushd "${EGIT_DIR}" &> /dev/null cursha1=$(git rev-parse ${upstream_branch}) einfo "GIT offline update -->" - einfo " repository: ${ESCM_REPO_URI}" + einfo " repository: ${EGIT_REPO_URI}" einfo " at the commit: ${cursha1}" popd &> /dev/null else pushd "${EGIT_DIR}" &> /dev/null # Git urls might change, so unconditionally set it here - git config remote.origin.url "${ESCM_REPO_URI}" + git config remote.origin.url "${EGIT_REPO_URI}" # fetch updates einfo "GIT update -->" - einfo " repository: ${ESCM_REPO_URI}" + einfo " repository: ${EGIT_REPO_URI}" oldsha1=$(git rev-parse ${upstream_branch}) if [[ -n ${EGIT_HAS_SUBMODULES} ]]; then - debug-print "${ESCM_UPDATE_CMD} ${ESCM_OPTIONS}" + debug-print "${EGIT_UPDATE_CMD} ${EGIT_OPTIONS}" # fix branching - git checkout ${ESCM_MASTER} - for x in $(git branch |grep -v "* ${ESCM_MASTER}" |tr '\n' ' '); do + git checkout ${EGIT_MASTER} + for x in $(git branch |grep -v "* ${EGIT_MASTER}" |tr '\n' ' '); do git branch -D ${x} done - ${ESCM_UPDATE_CMD} ${ESCM_OPTIONS} \ - || die "${FUNCNAME}: can't update from ${ESCM_REPO_URI}." + ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} \ + || die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}." else - debug-print "${ESCM_UPDATE_CMD} ${ESCM_OPTIONS} origin ${ESCM_BRANCH}:${ESCM_BRANCH}" - ${ESCM_UPDATE_CMD} ${ESCM_OPTIONS} origin ${ESCM_BRANCH}:${ESCM_BRANCH} \ - || die "${FUNCNAME}: can't update from ${ESCM_REPO_URI}." + debug-print "${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} origin ${EGIT_BRANCH}:${EGIT_BRANCH}" + ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} origin ${EGIT_BRANCH}:${EGIT_BRANCH} \ + || die "${FUNCNAME}: can't update from ${EGIT_REPO_URI}." fi git-2_submodules "${EGIT_DIR}" @@ -328,10 +313,11 @@ git-2_fetch() { popd &> /dev/null fi # export the version the repository is at - export ESCM_VERSION="${cursha1}" + export EGIT_VERSION="${cursha1}" # log the repo state - [[ "${ESCM_COMMIT}" != "${ESCM_BRANCH}" ]] && einfo " commit: ${ESCM_COMMIT}" - einfo " branch: ${ESCM_BRANCH}" + [[ "${EGIT_COMMIT}" != "${EGIT_BRANCH}" ]] \ + && einfo " commit: ${EGIT_COMMIT}" + einfo " branch: ${EGIT_BRANCH}" einfo " storage directory: \"${EGIT_DIR}\"" } @@ -341,34 +327,34 @@ git-2_fetch() { git-2_bootstrap() { debug-print-function ${FUNCNAME} "$@" - # @ECLASS_VARIABLE: ESCM_BOOTSTRAP + # @ECLASS_VARIABLE: EGIT_BOOTSTRAP # @DESCRIPTION: # Command to be executed after checkout and clone of the specified # repository. # enviroment the package will fail if there is no update, thus in # combination with --keep-going it would lead in not-updating # pakcages that are up-to-date. - if [[ -n ${ESCM_BOOTSTRAP} ]] ; then + if [[ -n ${EGIT_BOOTSTRAP} ]] ; then pushd "${EGIT_SOURCEDIR}" &> /dev/null einfo "Starting bootstrap" - if [[ -f ${ESCM_BOOTSTRAP} ]]; then + if [[ -f ${EGIT_BOOTSTRAP} ]]; then # we have file in the repo which we should execute - debug-print "${FUNCNAME}: bootstraping with file \"${ESCM_BOOTSTRAP}\"" + debug-print "${FUNCNAME}: bootstraping with file \"${EGIT_BOOTSTRAP}\"" - if [[ -x ${ESCM_BOOTSTRAP} ]]; then - eval "./${ESCM_BOOTSTRAP}" \ + if [[ -x ${EGIT_BOOTSTRAP} ]]; then + eval "./${EGIT_BOOTSTRAP}" \ || die "${FUNCNAME}: bootstrap script failed" else - eerror "\"${ESCM_BOOTSTRAP}\" is not executable." + eerror "\"${EGIT_BOOTSTRAP}\" is not executable." eerror "Report upstream, or bug ebuild maintainer to remove bootstrap command." - die "\"${ESCM_BOOTSTRAP}\" is not executable." + die "\"${EGIT_BOOTSTRAP}\" is not executable." fi else # we execute some system command - debug-print "${FUNCNAME}: bootstraping with commands \"${ESCM_BOOTSTRAP}\"" + debug-print "${FUNCNAME}: bootstraping with commands \"${EGIT_BOOTSTRAP}\"" - eval "${ESCM_BOOTSTRAP}" \ + eval "${EGIT_BOOTSTRAP}" \ || die "${FUNCNAME}: bootstrap commands failed." fi |
