#!/bin/bash
# vim:sw=2:et
echo=
#echo=echo

usage()
{
  echo "$0 <path_to_orig_tree> <path_to_updated_tree>"
  exit 1
}

orig_tree=$1
test -n "$orig_tree" -a -d "$orig_tree" || usage
updated_tree=$2
test -n "$updated_tree" -a -d "$updated_tree" || usage

for p in $(find "$updated_tree" -name '*.po'); do
  d=$(dirname "$p" | sed -e "s,$updated_tree,,")
  p=$(basename "$p")
  case $p in
    *desktop_*)
      continue
      ;;
    *others/*)
      continue
      ;;
    *kdenonbeta/*)
      continue
      ;;
    *extragear-*/*)
      continue
      ;;
    *kdekiosk*/*)
      continue
      ;;
    *playground*/*)
      continue
      ;;
    *kdereview*/*)
      continue
      ;;
    *koffice*/*)
      continue
      ;;
    esac

  if test -f "$orig_tree/$d/$p"; then
    $echo msgmerge -q -o $orig_tree/$d/$p.new --no-fuzzy-matching $updated_tree/$d/$p $orig_tree/$d/$p
    #$echo msgmerge -q -o $orig_tree/$d/$p.new --no-fuzzy-matching $orig_tree/$d/$p $orig_tree/$d/$p -C $updated_tree/$d/$p
    $echo python /space/kde/sources/3_5/l10n/scripts/msgsplit $orig_tree/$d/$p.new
    $echo diff --label messages/$d/$p -b -u -d $orig_tree/$d/$p $orig_tree/$d/$p.new | sed -e "s,^\+\+\+ .*,+++ messages/$d/$p,"
    rm -f $orig_tree/$d/$p.new
  else
    $echo diff -u /dev/null $updated_tree/$d/$p | sed -e "s,^\+\+\+ .*,+++ messages/$d/$p,"
  fi
done
