[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [PATCH] Allow creation of new branches via cvs-import.sh



On Wed, 2005-12-28 at 00:41 -0500, Ignacio Vazquez-Abrams wrote:
> The attached patch (hopefully) allows cvs-import.sh to create new
> branches. Please check it extra-super-thoroughly for correctness before
> applying.

Silly bugs. Silly me. New patch.

-- 
Ignacio Vazquez-Abrams <ivazquez ivazquez net>
http://fedora.ivazquez.net/

gpg --keyserver hkp://subkeys.pgp.net --recv-key 38028b72
diff -urN common/cvs-import.sh common.new/cvs-import.sh
--- common/cvs-import.sh	2005-10-14 14:26:06.000000000 -0400
+++ common.new/cvs-import.sh	2005-12-28 02:49:33.000000000 -0500
@@ -8,8 +8,8 @@
 # $Id: cvs-import.sh,v 1.10 2005/10/14 18:26:06 sopwith Exp $
 
 # Initial setup
-CVSTREE=${CVSTREE:=extras}
-TOPLEVEL=${TOPLEVEL:=rpms}
+CVSTREE=${CVSTREE:-extras}
+TOPLEVEL=${TOPLEVEL:-rpms}
 
 # Check that we're being run from a good location
 MYDIR=$(dirname $0)
@@ -26,10 +26,10 @@
 CVSROOT=$(cat ${MYDIR}/CVS/Root)
 
 # We need a writable directory for temporary checkouts and CVS work
-WORKDIR="/tmp"
 if test -w $(pwd) ; then
-    WORKDIR="$(pwd)"
+    WORKDIR=${WORKDIR:-"$(pwd)"}
 fi
+WORKDIR=${WORKDIR:-"/tmp"}
 
 # short usage help
 Usage() {
@@ -42,8 +42,7 @@
 CVSROOT    = $CVSROOT
 BRANCH     = ${BRANCH:-devel}
 
-The package can also be imported on a PRE-EXISTING branch using the 
-"-b BRANCH" flag. This script can not create new branches for you.
+The package can also be imported to a branch using the "-b BRANCH" flag.
 EOF
     exit 1
 }
@@ -58,8 +57,7 @@
 	# the import
 	-b | --branch )
 	    shift
-	    BRANCH="$1"
-	    if [ -z "$BRANCH" ] ; then
+	    if [ -z "$1" ] ; then
 		echo "ERROR: --branch requires an argument"
 		Usage
 		exit -1
@@ -68,6 +66,11 @@
 	    if [ "$BRANCH" = "HEAD" -o "$BRANCH" = "devel" ] ; then
 		BRANCH=
 	    fi
+	    grep -q "^$1:" ${MYDIR}/branches && BRANCH="$1" || {
+		echo "ERROR: branch '$1' not recognized"
+		Usage
+		exit -1
+	    }
 	    ;;
 
 	-m | --message )
@@ -154,21 +157,55 @@
 # Now make sure we have the requested to operate on a branch
 if [ -n "$BRANCH" ] ; then
     # check that this branch exists before importing anything into it
-    if [ -z "$(grep ""^$NAME-$BRANCH[[:space:]]"" modules 2>/dev/null)" ] ; then
-	# XXX: allow the creation of branches
-	cat <<EOF
-ERROR: You have requested to import a package into the branch $BRANCH of the
-module $NAME, but according to the modules file this branch does not exist.
-
-This tool allows you to import packages only on pre-existing branches. If you
-would like the new branch created, please email sysadmin-devel redhat com 
+    grep -q "^$NAME-$BRANCH[[:space:]]" modules || {
+	grep -q "^$NAME"$'\t' modules || {
+	    cat << EOF
+ERROR: Cannot create a new branch on a non-existent module. Please import
+the package normally first.
 EOF
-	exit -1
-    fi
+	    exit -1
+	}
+	[ -f ${MYDIR}/Makefile.template.module -a -f ${MYDIR}/Makefile.template.branch ] || {
+	    echo << EOF
+ERROR: Makefile templates not found. Make sure you have checked out
+'common' completely.
+EOF
+	    exit -1
+	}
+	# Create the branch
+	cvs -Q update modules && {
+	    echo "Creating new branch for $NAME: $BRANCH"
+	    cat << EOF >> modules
+$NAME-$BRANCH    	&$NAME-$BRANCH-dir &common
+$NAME-$BRANCH-dir	-d $NAME $TOPLEVEL/$NAME/$BRANCH
+EOF
+	    sed -i "s/^\($BRANCH.*\)$/\1 &$NAME-$BRANCH-dir/" modules
+	    cvs -Q commit -m "Added new branch $BRANCH on $NAME" >/dev/null
+	    pushd $TMPDIR >/dev/null
+	    $CVS -Q checkout -l $TOPLEVEL/$NAME
+	    mkdir $TOPLEVEL/$NAME/$BRANCH
+	    cvs -Q add $TOPLEVEL/$NAME/$BRANCH
+	    cd $TOPLEVEL/$NAME/$BRANCH
+	    touch sources .cvsignore
+	    cp ${MYDIR}/Makefile.template.branch Makefile
+	    sed -i "s/@@NAME@@/$NAME/g" Makefile
+	    cvs -Q add Makefile sources .cvsignore
+            # commit all the added stuff
+	    cd .. && cvs -Q commit -m "Setup of branch $BRANCH of $NAME" >/dev/null
+	    popd
+	}
+    }
 fi
 
 # Figure out if we need to import a new module
 if [ -z "$(grep ""^$NAME[[:space:]]"" modules 2>/dev/null)" ] ; then
+    [ -f ${MYDIR}/Makefile.template.module -a -f ${MYDIR}/Makefile.template.branch ] || {
+	echo << EOF
+ERROR: Makefile templates not found. Make sure you have checked out
+'common' completely.
+EOF
+	exit -1
+    }
     # This is a new module, it does not exist
     cvs -Q update modules && \
 	echo "Creating new module: $NAME" && \
@@ -184,50 +221,14 @@
 	    # handle the top level stuff
 	    cd $NAME
 	    touch import.log
-	    cat >Makefile <<EOF
-# Top level Makefile for module $NAME
-all : CVS/Root common-update
-	@cvs update
-
-common-update : common
-	@cd common && cvs update
-
-common : CVS/Root
-	@cvs checkout common
-
-CVS/Root :
-	@echo "ERROR: This does not look like a CVS checkout" && exit 1
-
-clean :
-	@find . -type f -name *~ -exec rm -fv {} \;
-EOF
+	    cp ${MYDIR}/Makefile.template.module Makefile
+	    sed -i "s/@@NAME@@/$NAME/g" Makefile
 	    cvs -Q add Makefile import.log
 	    # handle the module build
 	    cd devel
 	    touch sources .cvsignore
-	    cat >Makefile <<EOF
-# Makefile for source rpm: $NAME
-# \$Id\$
-NAME := $NAME
-SPECFILE = \$(firstword \$(wildcard *.spec))
-
-define find-makefile-common
-for d in common ../common ../../common ; do if [ -f \$\$d/Makefile.common ] ; then if [ -f \$\$d/CVS/Root -a -w \$\$/Makefile.common ] ; then cd \$\$d ; cvs -Q update ; fi ; echo "\$\$d/Makefile.common" ; break ; fi ; done
-endef
-
-MAKEFILE_COMMON := \$(shell \$(find-makefile-common))
-
-ifeq (\$(MAKEFILE_COMMON),)
-# attept a checkout
-define checkout-makefile-common
-test -f CVS/Root && { cvs -Q -d \$\$(cat CVS/Root) checkout common && echo "common/Makefile.common" ; } || { echo "ERROR: I can't figure out how to checkout the 'common' module." ; exit -1 ; } >&2
-endef
-
-MAKEFILE_COMMON := \$(shell \$(checkout-makefile-common))
-endif
-
-include \$(MAKEFILE_COMMON)
-EOF
+	    cp ${MYDIR}/Makefile.template.branch Makefile
+	    sed -i "s/@@NAME@@/$NAME/g" Makefile
 	    cvs -Q add Makefile sources .cvsignore
             # commit all the added stuff
 	    cd .. && cvs -Q commit -m "Setup of module $NAME" >/dev/null
diff -urN common/Makefile.template.branch common.new/Makefile.template.branch
--- common/Makefile.template.branch	1969-12-31 19:00:00.000000000 -0500
+++ common.new/Makefile.template.branch	2005-12-28 00:03:44.000000000 -0500
@@ -0,0 +1,21 @@
+# Makefile for source rpm: @@NAME@@
+# $Id: Makefile,v 1.1 2005/04/10 03:47:56 spot Exp $
+NAME := @@NAME@@
+SPECFILE = $(firstword $(wildcard *.spec))
+
+define find-makefile-common
+for d in common ../common ../../common ; do if [ -f $$d/Makefile.common ] ; then if [ -f $$d/CVS/Root -a -w $$/Makefile.common ] ; then cd $$d ; cvs -Q update ; fi ; echo "$$d/Makefile.common" ; break ; fi ; done
+endef
+
+MAKEFILE_COMMON := $(shell $(find-makefile-common))
+
+ifeq ($(MAKEFILE_COMMON),)
+# attept a checkout
+define checkout-makefile-common
+test -f CVS/Root && { cvs -Q -d $$(cat CVS/Root) checkout common && echo "common/Makefile.common" ; } || { echo "ERROR: I can't figure out how to checkout the 'common' module." ; exit -1 ; } >&2
+endef
+
+MAKEFILE_COMMON := $(shell $(checkout-makefile-common))
+endif
+
+include $(MAKEFILE_COMMON)
diff -urN common/Makefile.template.module common.new/Makefile.template.module
--- common/Makefile.template.module	1969-12-31 19:00:00.000000000 -0500
+++ common.new/Makefile.template.module	2005-12-28 00:03:23.000000000 -0500
@@ -0,0 +1,15 @@
+# Top level Makefile for module @@NAME@@
+all : CVS/Root common-update
+	@cvs update
+
+common-update : common
+	@cd common && cvs update
+
+common : CVS/Root
+	@cvs checkout common
+
+CVS/Root :
+	@echo "ERROR: This does not look like a CVS checkout" && exit 1
+
+clean :
+	@find . -type f -name *~ -exec rm -fv {} \;

Attachment: signature.asc
Description: This is a digitally signed message part


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]