#!/bin/sh
#
#	pci -- postgres checkin command
#
#	this script should be used to check in changes made in a
#	developer's private copy of the postgres tree.  it will
#	run the rcs checkin command, and then guarantee that the
#	source file is checked out in the postgres master tree.
#
#	Usage:  pci [-v] [-M master_tree_pathname] <ci flags> file file ...
#
#		-v puts pci into verbose mode
#		-M tells pci to use master_tree_pathname as the root of
#		   the postgres master tree
#
#	$Header: /home2/aoki/postgres/src/RCS/pci,v 1.5 1993/08/10 01:44:24 aoki Exp $
#

# control the behavior of this script
verbose=0
master=/usr/local/devel/postgres

# control the behavior of ci and co
ulf=
msgs=
files=

# parse the argument list -- we know what ci expects
while [ $# -gt 0 ]
do
	case $1 in

#	pci args
	-v)		verbose=1;;
	-M)		master=$2;shift;;
	-M*)		master=`echo $2 | sed -e "s/-M//"`;;

#	ci args
	-[ulf])		ulf="$ulf $1";;
	-[mnNst])	msgs="$msgs $1 ""'""$2""'";shift;;
	-[mnNs]t*)	msgs="$msgs ""'""$1""'";;
	*)		files="$files $1";;

	esac
	shift
done

# tell them what they've won, don pardo...
if [ $verbose -ne 0 ]
then
	echo ci $ulf $msgs $files
fi

# do it
ci $ulf $msgs $files

if [ $? -ne 0 ]
then
	echo checkin failed.
	exit 1
fi

# extract the pathname relative to the postgres root directory from curdir
curdir=`pwd`
#subtree=`echo $curdir | sed -e "s%.*/postgres/%%"`
subtree=`echo $curdir | sed -e "s%.*/src/%src/%"`

if [ $verbose -ne 0 ]
then
	echo cd $master/$subtree
fi

# go to the master tree
cd $master/$subtree
if [ $? -ne 0 ]
then
	echo cannot chdir to $master/$subtree
	echo checkout of $files in master tree failed
	echo please do the checkout manually
	exit 1
fi

if [ $verbose -ne 0 ]
then
	echo co $files
fi

# check out the files
co $files

exit 0
