#!/bin/bash

# Commits changes to po file and updates ChangeLog
# Usage: ./commit-po ??.po
# Copyright © 2005: Joachim Breitner <mail@joachim-breitner.de>
#
# Permission is hereby granted, free of charge, to any
# person obtaining a copy of this software and associated
# documentation files (the "Software"), to deal in the
# Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the
# Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall
# be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

po=$1
shift
message=$@

if [ -z "$message" ]
then
  message="Update"
fi

if [ ! -e "$po" ]
then
  echo "PO-File $po not found. Usage: $0 ??.po [ message ]"
  exit 1
fi

if [ ! -e ChangeLog ]
then
  echo ChangeLog not found. Please run from po directory.
  exit 1
fi


name=$(perl -n -e 'print $1 if /Last-Translator: (.*)\\n/' "$po")

if [ -z "$name" ]
then
  echo Could not parse out name
  exit 1
fi

set -e

svn update ChangeLog
( echo "$(date +%Y-%m-%d)  $name"
  echo 
  echo "	* $po: $message"
  echo
  cat ChangeLog
) > ChangeLogX
mv ChangeLogX ChangeLog

svn ci -m "$po: $message" "$po" ChangeLog

echo Successfully commite new Versions of $po and ChangeLog
