doc: Ueberarbeite README.
[wortliste.git] / patgen-list-diff.sh
blobdae0275af9141020270de6ef3d03460b2a494f8f
1 #!/bin/sh
2 # -*- coding: utf-8 -*-
4 # Dieses Skript erzeugt Differenzbilder (diff) für die
5 # Patgen-Eingabelisten zwischen zwei angegebenen Commits. Wird nur ein
6 # Commit angegeben, wird als Zielcommit "master" verwendet. Die
7 # Ausgabedateien werden als Dateien
9 # dehyph*-x/<Start-Commit-Hash>-<Ziel-Commit-Hash>.diff
11 # in Verzeichnissen gespeichert, die der jeweiligen Rechtschreibung
12 # entsprechen. Start- und Ziel-Commit können in jeder gültigen
13 # Git-Syntax angegeben werden. Für die Dateinamen werden die
14 # entsprechenden abgekürzten alphanumerischen Commit-Hashes
15 # verwendet.
17 # Aufruf: sh patgen-list-diff.sh <start commit> [<ziel commit>]
20 # Eingabe: <start commit> Ein Start-Commit.
21 # <ziel commit> Ein optionaler Ziel-Commit.
23 # Ausgabe:
24 # dehyphn-x/<hashes>.diff Differenzbild refromierte Rechtschreibung
25 # dehypht-x/<hashes>.diff Differenzbild traditionelle Rechtschreibung
26 # dehyphts-x/<hashes>.diff Differenzbild traditionelle Rechtschreibung
27 # in der Schweiz.
29 if test $# -eq 0
30 then
31 echo 'usage: patgen-list-diff <start commit> [<target commit>]'
32 echo 'Create diffs for patgen input lists between <start commit> and'
33 echo '<target commit> (by default "master") and save them as files'
34 echo 'dehyph*-x/<start commit hash>-<target commit hash>.diff in'
35 echo 'directories corresponding to the spelling.'
36 exit 1
38 FROMCOMMIT=$1
39 if test $# -eq 1
40 then
41 TOCOMMIT=HEAD
42 else
43 TOCOMMIT=$2
45 typeset GITDATA=`git log -1 --format=%ci-%H $FROMCOMMIT --`
46 FROMDATE=${GITDATA:0:10}+${GITDATA:11:2}-${GITDATA:14:2}-${GITDATA:17:2}
47 FROMHASH=${GITDATA:26}
48 if test -z $FROMHASH
49 then
50 echo 'patgen-list-diff.sh: error identifying start commit hash: ' $FROMCOMMIT
51 exit 1
53 typeset GITDATA=`git log -1 --format=%ci-%H $TOCOMMIT --`
54 TODATE=${GITDATA:0:10}+${GITDATA:11:2}-${GITDATA:14:2}-${GITDATA:17:2}
55 TOHASH=${GITDATA:26}
56 if test -z $TOHASH
57 then
58 echo 'patgen-list-diff.sh: error identifying target commit hash: ' $TOCOMMIT
59 exit 1
64 # Function definition. If not already present, place a copy of a
65 # commit's working copy in a directory 'wl-<commit hash>'.
66 get_working_copy() {
67 typeset commit=$1 commitdate=$2
68 typeset commitdir=$commitdate-$commit
69 if test ! -d $commitdir
70 then
71 git archive --format=tar --prefix=$commitdir/ $commit | tar xf -
75 # Function definition.
76 create_patgen_list() {
77 typeset commit=$1 commitdate=$2 patgenlist=$3
78 typeset commitdir=$commitdate-$commit
79 echo "Making ${commit:0:7} file $patgenlist."
80 if test ! -e $commitdir/$patgenlist
81 then
82 # 'make -C $commitdir $patgenlist' doesn't work reliably on Git
83 # for Windows shell.
84 (cd $commitdir && make $patgenlist > /dev/null)
88 # Function definition.
89 diff_patgen_list() {
90 typeset fromcommit=$1 fromcommitdate=$2 tocommit=$3 tocommitdate=$4 dehyph=$5 spell=$6
91 typeset fromcommitdir=$fromcommitdate-$fromcommit tocommitdir=$tocommitdate-$tocommit patgenlist=$dehyph/words.hyphenated.$spell difffile=${fromcommit:0:7}-${tocommit:0:7}.diff
92 create_patgen_list $fromcommit $fromcommitdate $patgenlist
93 create_patgen_list $tocommit $tocommitdate $patgenlist
94 if test ! -d $dehyph; then mkdir $dehyph; fi
95 diff $fromcommitdir/$patgenlist $tocommitdir/$patgenlist > $dehyph/$difffile
96 gawk -f patgen-list-diff.awk -v ftr=daten/german.tr $dehyph/$difffile
101 echo "Diff'ing patgen input files."
102 printf "from: %7s %10s %s\n" ${FROMHASH:0:7} ${FROMDATE:0:10} $FROMCOMMIT
103 printf "to: %7s %10s %s\n" ${TOHASH:0:7} ${TODATE:0:10} $TOCOMMIT
104 # Get commit's working copies.
105 get_working_copy $FROMHASH $FROMDATE
106 get_working_copy $TOHASH $TODATE
107 # Write header to summary table file.
108 PLDTABLE=CHANGES.table.txt
109 echo " Rechtschreibung hinzugefügt entfernt korrigiert" > $PLDTABLE
110 echo " ---------------------------------------------------------------" >> $PLDTABLE
111 # Diff patgen lists and write results to summary table file.
112 echo -n " traditionell (DE, AT)" >> $PLDTABLE
113 diff_patgen_list $FROMHASH $FROMDATE $TOHASH $TODATE dehypht-x trad
114 echo -n " traditionell (CH) " >> $PLDTABLE
115 diff_patgen_list $FROMHASH $FROMDATE $TOHASH $TODATE dehyphts-x swiss
116 echo -n " reformiert " >> $PLDTABLE
117 diff_patgen_list $FROMHASH $FROMDATE $TOHASH $TODATE dehyphn-x refo