#!/bin/bash

# © 2007-2008 Manoël Trapier aka Godzil <godzil at godzil.net>
# All right reserved
#
# Licence: 
# This script is neither in GPL nor LGPL you can use it like you want, but not redistribute it, modified or not without prior permission from me
# You must too leave this copyright notice as is, and if you want to share this file, give you friend a link to where you find it, 
# not by direct distribution.

# Read configuration file
. ${HOME}/bin/mklog.cfg

# Source some usefull functions
. ${HOME}/bin/function.sh

function Failed()
{
    eerror $*

    exit 1
}

TEMPFILE=`mktemp mklog.XXXXXXXXX` || Failed "Cannot create temp file"

SVN=`whereis svn | sed -e "s|svn: ||g" -e "s| .*$||g"` || Failed "Can't find svn binary !!!"


cat > ${TEMPFILE} <<EOF
${SEPARATOR}
`LANG="en" date +"${DATEFORMAT}"` - ${COMMITER}

   * [`whoami`]

EOF
 
EDITFILE=`mktemp mklog.XXXXXXXXX` || (rm ${TEMPFILE} && Failed "Cannot create temp file")


cat > ${EDITFILE} <<EOF
#Each line starting with a # (sharp) will be ignored when merging with
#the ChangeLog.
#Please fill with information for each modified file :
EOF

${SVN} status | grep -e "^M " | sed -e "s|^M[ \t]*|   |g" -e "s|$|:\n\n#Please make a comment\n   \n|g" >> ${EDITFILE}

if [[ ${EDITOR} == "" ]]; then

    ${DEFAULT_EDITOR} ${EDITFILE}

else
    
    ${EDITOR} ${EDITFILE}

fi

cat ${EDITFILE} | awk "! /#/ { print $1 }" >> ${TEMPFILE}


cat >> ${TEMPFILE} <<EOF
   BR: #${BRNUM}
   TS: #xxx
   Build: 

EOF

cat ${TEMPFILE}


#The End !
rm ${TEMPFILE}
rm ${EDITFILE}
