#!/bin/sh
#
# Part of the prcsutils package
# Copyright (C) 2001  Hugo Cornelis <hugo@bbf.uia.ac.be>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# 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 prcs, The Project Revision Control System available at 
# http://www.xcf.berkeley.edu ; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# $Project: prcs $
# $ProjectHeader: prcs 1.3.3-relase.1 Sun, 09 May 2004 18:34:01 -0700 jmacd $
# $Id: prcspatch2 1.1 Fri, 03 May 2002 09:09:57 -0700 jmacd $
#
# prcspatch2 : create a patch file for project given on command line and
#		two revisions given on command line.
#		patch file contains differences between given revisions
#		and is named after project and the two revisions.
#
#		log message can be given after '-m' option which must 
#		be the first option on the command line.
#		if no '-m', log message is Version-Log from second version
#		The log message is present in the header of the patch file.
#

# get log message

if [ x"$1" = x-m ]; then

    log_message="$2" && shift && shift

    log=1

else

    log=0

fi

#projects=`ls 2>/dev/null -l *.prj | wc -l`

# check command line (

[ x"$3" = x ] && echo 1>&2 "Usage : $0 <project> <version1> <version2>" && echo 1>&2 "Create a unified patchfile between different version of the same project" && echo 1>&2 "patchfile will have name according to project and versions" && echo 1>&2 "-m allows to give a message log (which defaults to contents of " && echo 1>&2 "	Version-Log entry of <version2>)" && exit 1

# get project and versions

project=$1
version1=$2
version2=$3

# construct an appropriate name for the patch file

patchfile=$project-$version1-$project-$version2.patch

# check log message

if [ $log = 0 ]; then

    log_message=`prcs info -l -r $version2 $project`
fi

# generate patch file

echo >$patchfile "$log_message"

# I'm not sure anymore why, but the --exclude-project-file did not work 
# to generate correct patchfiles

prcs >>$patchfile 2>&1 diff -N -r $version1 -r $version2 -N $project `prcs execute -r $version1 --not :project-file $project` `prcs execute -r $version2 --not :project-file $project` -- --unified
