#!/bin/sh ############################################################################### ## ## hook - tla hook. ## Copyright (C) 2003 Robert Collins ## ## Portions adapted from : ## ## Copyright (C) 2003 Ethan Benson ## ## Portions adapted from larch: ## ## Copyright (C) 2001-2003 Tom Lord ## ## This program is free software; you can redistribute it and/or ## modify it under the terms of version 2 of the GNU General Public License ## as published by the Free Software Foundation. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## ############################################################################### MAILX=sendmail_wrapper sendmail_wrapper() { if [ $# -ne 3 ] ; then echo 1>&2 "sendmail usage error: need 3 arguments" exit 1 fi if [ "$1" != "-s" ] ; then echo 1>&2 "sendmail usage error: first argument must be -s" exit 1 fi ( printf "To: %s\\n" "$3" ; \ printf "Subject: %s\\n" "$2" ; \ printf "\\n" ; \ cat ) \ | /usr/sbin/sendmail -t } new_category() { printf "\\n" printf "New categories created in %s\\n" "$ARCH_ARCHIVE" printf "\\n" printf " %s\\n" "$ARCH_CATEGORY" printf "\\n" printf "\\n" printf "regards,\\n" printf "\"tla mail-new-categories\"\\n" printf "\\n" } new_branch() { printf "\\n" printf "New branches created in %s\\n" "${ARCH_ARCHIVE}/${ARCH_BRANCH%%--*}" printf "\\n" printf " %s\\n" "$ARCH_BRANCH" printf "\\n" printf "\\n" printf "regards,\\n" printf "\"tla mail-new-branches\"\\n" printf "\\n" } new_version() { printf "\\n" printf "New versions created in %s\\n" "${ARCH_ARCHIVE}/${ARCH_VERSION%--*}" printf "\\n" printf " %s\\n" "$ARCH_VERSION" printf "\\n" printf "\\n" printf "regards,\\n" printf "\"tla mail-new-versions\"\\n" printf "\\n" } cl_entry() { awk -v archive="$archive" \ -v version="$version" \ -v category="$category" \ -v branch="$branch" \ -v patch="$patch" \ -v no_files="$no_files" \ 'BEGIN { getline; while (!match ($0, "^$")) { field = tolower ($1); sub (":.*", "", field); headers[field] = $0; sub ("^[^:]*:[ \t]*", "", headers[field]); getline; while (match ($0, "^[ \t]")) { headers[field] = headers[field] $0; getline; } } } { if (body == "") body = " " $0; else body = body "\n " $0; } END { date = headers["standard-date"]; if (date == "") { # this is almost vestigial: a backwards compatibility # hack just for the author of arch, some of whose log # messages pre-date the "standard-date" header field. # split (headers["date"], ugly_date, "[ \t]+"); date = ugly_date[6] "-" ugly_date[2] "-" ugly_date[3]; } sub("[[:space:]].*GMT.*", " GMT", date); print date "\t" headers["creator"] "\t" patch; print ""; print " Summary:"; print " " headers["summary"]; print " Revision:"; print " " headers["revision"]; print ""; print body; print ""; if (no_files == "") { file_list(0, "new-files", "{arch}/" category "/" branch "/" version "/" archive "/patch-log/" patch); file_list(0, "removed-files"); file_list(0, "modified-files"); file_pair_list("renamed-files"); file_list(0, "new-directories"); file_list(0, "removed-directories"); file_list(0, "modified-directories"); file_pair_list("renamed-directories"); file_list(0, "new-patches", archive "/" version "--" patch); print "" } } function file_list (base_only, field_name, exclude) { for (x in items) delete items[x]; n_items = split (headers[field_name], items, "[ \t]+"); if ((n_items == 0) || ((exclude != "") && (n_items == 1))) return; sub("-", " ", field_name); print " " field_name ":" printf(" "); width = 0; items_on_line = 0; for (x = 1; x <= n_items; ++x) { if (exclude == items[x]) continue; if (base_only) sub (".*/", "", items[x]); if ((items_on_line == 0) || ((width + length (items[x]) + 1) < 64)) { width += length (items[x]) + 1; ++items_on_line; printf(" %s", items[x]); } else { printf("\n"); printf(" "); printf(" %s", items[x]); width = length(items[x]) + 1; items_on_line = 1; } } printf "\n" printf "\n" } function file_pair_list (field_name) { for (x in items) delete items[x]; n_items = split (headers[field_name], items, "[ \t]+"); if (n_items == 0) return; sub("-", " ", field_name); print " " field_name ":" for (x = 1; x <= n_items; ++x) { printf(" %s\n", items[x]); printf(" ==> %s\n", items[x + 1]); x = x + 1; } printf "\n" printf "\n" }' } new_revision() { local archive="$ARCH_ARCHIVE" local version="$(v=${ARCH_REVISION%--*};echo ${v##*--})" local category="${ARCH_REVISION%%--*}" local branch="$(v=${ARCH_REVISION%--*--*};echo ${v##*--})" local patch="${ARCH_REVISION##*--}" printf "\\n" printf "New revisions created in %s\\n" "${ARCH_ARCHIVE}/${ARCH_REVISION%--*}" printf "\\n" tla cat-archive-log "${ARCH_ARCHIVE}/${ARCH_REVISION}" | cl_entry printf "\\n" printf "regards,\\n" printf "\"tla mail-new-revisions\"\\n" printf "\\n" } update_library() { local buf="" buf="$(tla library-add "${ARCH_ARCHIVE}/${ARCH_REVISION}" 2>&1)" if [ $? -ne 0 ] ; then echo "$buf" | $MAILX -s "tla library-add ${ARCH_ARCHIVE}/${ARCH_REVISION} failed" eb return 1 fi return 0 } update_mirror() { #TODO: support branchless versions. tla push-mirror $ARCH_ARCHIVE `tla parse-package-name --package-version $ARCH_REVISION` || true; return 0 } case "$1" in # make-category) # case "$ARCH_ARCHIVE" in # "address@hidden") # new_category \ # | $MAILX -s "Changes to archive $ARCH_ARCHIVE" eb # ;; # "address@hidden") # update_mirror # case "$ARCH_CATEGORY" in # yaboot*|prom-libc*|libc-test*) # new_category \ # | $MAILX -s "Changes to archive $ARCH_ARCHIVE" \ # address@hidden # ;; # *) # new_category \ # | $MAILX -s "Changes to archive $ARCH_ARCHIVE" eb # ;; # esac # ;; # "address@hidden") # ;; # *) # new_category | $MAILX -s "Changes to archive $ARCH_ARCHIVE" eb # ;; # esac # ;; # make-branch) # case "$ARCH_ARCHIVE" in # *) # new_branch | $MAILX -s "Changes to archive ${ARCH_ARCHIVE}/${ARCH_BRANCH%%--*}" eb # ;; # esac # ;; # make-version) # case "$ARCH_ARCHIVE" in # *) # new_version | $MAILX -s "Changes to archive ${ARCH_ARCHIVE}/${ARCH_VERSION%--*}" eb # ;; # esac # ;; commit|import|tag) update_mirror # if [ "$ARCH_ARCHIVE" == "address@hidden" ]; then # echo "New changesets in $ARCH_ARCHIVE" | mail oan-commit -s "OAN commit $ARCH_REVISION" ; # fi case "$ARCH_ARCHIVE" in "address@hidden") new_revision \ | $MAILX -s "Changes to archive ${ARCH_ARCHIVE}/${ARCH_REVISION%--*}" oan-commit ;; "address@hidden") case "$ARCH_REVISION" in *) new_revision \ | $MAILX -s "Changes to archive ${ARCH_ARCHIVE}/${ARCH_REVISION%--*}" squid-commit ;; esac ;; "address@hidden") case "$ARCH_REVISION" in *) new_revision \ | $MAILX -s "Changes to archive ${ARCH_ARCHIVE}/${ARCH_REVISION%--*}" swell-proj-commit ;; esac ;; *) ;; esac # update_library ;; esac