Add support for ESCM_LOGDIR using pkg_preinst.
authorBo Ørsted Andresen <zlin@gentoo.org>
Wed, 20 Feb 2008 20:36:30 +0000 (20:36 +0000)
committerBo Ørsted Andresen <zlin@gentoo.org>
Wed, 20 Feb 2008 20:36:30 +0000 (20:36 +0000)
eclass/subversion.eclass

index 33bd9a7b75aabf37a1b17b8346c2fb1b62c63bc0..abc8a057e6f3955cd045462ae47ce496085bf9d5 100644 (file)
@@ -1,6 +1,6 @@
 # Copyright 1999-2008 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/subversion.eclass,v 1.49 2008/02/20 20:32:00 zlin Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/subversion.eclass,v 1.50 2008/02/20 20:36:30 zlin Exp $
 
 # @ECLASS: subversion.eclass
 # @MAINTAINER:
@@ -20,7 +20,7 @@ inherit eutils
 
 ESVN="${ECLASS}"
 
-EXPORT_FUNCTIONS src_unpack
+EXPORT_FUNCTIONS src_unpack pkg_preinst
 
 DESCRIPTION="Based on the ${ECLASS} eclass"
 
@@ -131,6 +131,14 @@ ESVN_RESTRICT="${ESVN_RESTRICT:-}"
 # tree by users.
 ESVN_OFFLINE="${ESVN_OFFLINE:-${ESCM_OFFLINE}}"
 
+# @ECLASS-VARIABLE: ESCM_LOGDIR
+# @DESCRIPTION:
+# User configuration variable. If set to a path such as e.g. /var/log/scm any
+# package inheriting from subversion.eclass will record svn revision to
+# ${CATEGORY}/${PN}.log in that path in pkg_preinst. This is not supposed to be
+# set by ebuilds/eclasses. It defaults to empty so users need to opt in.
+ESCM_LOGDIR="${ESCM_LOGDIR:=}"
+
 # @FUNCTION: subversion_fetch
 # @USAGE: [repo_uri] [destination]
 # @DESCRIPTION:
@@ -401,3 +409,26 @@ subversion__get_peg_revision() {
 
        echo "${peg_rev}"
 }
+
+# @FUNCTION: subversion_pkg_preinst
+# @DESCRIPTION:
+# Log the svn revision of source code. Doing this in pkg_preinst because we
+# want the logs to stick around if packages are uninstalled without messing with
+# config protection.
+subversion_pkg_preinst() {
+       local pkgdate=$(date "+%Y%m%d %H:%M:%S")
+       subversion_wc_info
+       if [[ -n ${ESCM_LOGDIR} ]]; then
+               local dir="${ROOT}/${ESCM_LOGDIR}/${CATEGORY}"
+               if [[ ! -d ${dir} ]]; then
+                       mkdir -p "${dir}" || \
+                               eerror "Failed to create '${dir}' for logging svn revision to '${PORTDIR_SCM}'"
+               fi
+               local logmessage="svn: ${pkgdate} - ${PF}:${SLOT} was merged at revision ${ESVN_WC_REVISION}"
+               if [[ -d ${dir} ]]; then
+                       echo "${logmessage}" >> "${dir}/${PN}.log"
+               else
+                       eerror "Could not log the message '${logmessage}' to '${dir}/${PN}.log'"
+               fi
+       fi
+}
\ No newline at end of file