dodoc updates.
[git] / dodoc.sh
1 #!/bin/sh
2 #
3 # This script is called from the post-update hook, and when
4 # the master branch is updated, run in $HOME/git-doc, like
5 # this:
6 : <<\END_OF_COMMENTARY
7
8 $ cat >hooks/post-update
9 #!/bin/sh
10 case " $* " in
11 *' refs/heads/master '*)
12         echo $HOME/git-doc/dodoc.sh | at now
13         ;;
14 esac
15 exec git-update-server-info
16 $ chmod +x hooks/post-update
17
18 END_OF_COMMENTARY
19
20 # $HOME/git-doc is a clone of the git.git repository and
21 # has the master branch checkd out.  We update the working
22 # tree and build pre-formatted documentation pages, install
23 # in doc-htmlpages and doc-manapges subdirectory here.
24 # These two are their own git repository, and when they are
25 # updated the updates are pushed back into their own branches
26 # in git.git repository.
27
28 ID=`git-rev-parse --verify refs/heads/master` || exit $?
29
30 unset GIT_DIR
31
32 : ${PUBLIC=/pub/software/scm/git/docs} &&
33 : ${MASTERREPO=`pwd`} &&
34 : ${DOCREPO=`dirname "$0"`} &&
35 test "$DOCREPO" != "" &&
36 cd "$DOCREPO" || exit $?
37
38 tmp=`pwd`/.doctmp-$$
39 trap 'rm -f "$tmp".*' 0
40
41 git pull "$MASTERREPO" master &&
42 git fetch --tags "$MASTERREPO" || exit $?
43 test $(git-rev-parse --verify refs/heads/master) == "$ID" &&
44 NID=$(git-describe --abbrev=4 "$ID") &&
45 test '' != "$NID" ||  exit $?
46
47 # Set up subrepositories
48 for type in man html
49 do
50         test -d doc-${type}pages || (
51                 mkdir doc-${type}pages &&
52                 cd doc-${type}pages &&
53                 git init-db || exit $?
54
55                 git fetch-pack "$MASTERREPO" ${type} |
56                 while read sha1 name
57                 do
58                         case "$name" in
59                         refs/heads/${type})
60                                 git update-ref HEAD $sha1 &&
61                                 git checkout || exit $?
62                                 break
63                                 ;;
64                         esac
65                 done || exit $?
66         ) || exit
67         rm -fr doc-$type-inst
68 done
69
70 make >../:html.log 2>&1 \
71         -C Documentation -j 2 \
72         WEBDOC_DEST="$DOCREPO/doc-html-inst" install-webdoc || exit
73
74 make >../:man.log 2>&1 \
75         -C Documentation -j 2 \
76         man1="$DOCREPO/doc-man-inst/man1" \
77         man7="$DOCREPO/doc-man-inst/man7" \
78         man1dir="$DOCREPO/doc-man-inst/man1" \
79         man7dir="$DOCREPO/doc-man-inst/man7" install || exit
80
81 for type in html man
82 do
83         find doc-$type-inst -type f |
84         while read path
85         do
86                 it=$(expr "$path" : doc-$type-inst/'\(.*\)') || continue
87                 t="doc-${type}pages/$it"
88                 test -f "$t" && diff -q "$path" "$t" && continue
89
90                 echo ": $t" && rm -f "$t" && ln "$path" "$t" || exit
91                 ( cd doc-${type}pages && git add "$it" )
92         done || exit
93
94         find doc-$type-inst -type f |
95         sed -e 's|^doc-'$type'-inst/||' | sort >"$tmp.1" &&
96         (cd doc-${type}pages && git ls-files | sort) >"$tmp.2" &&
97         comm -13 "$tmp.1" "$tmp.2" |
98         ( cd doc-${type}pages && xargs rm -f -- ) || exit
99
100         (
101                 cd doc-${type}pages
102
103                 if git commit -a -m "Autogenerated docs for $NID"
104                 then
105                         git send-pack "$MASTERREPO" master:refs/heads/$type
106                 else
107                         echo "* No changes in $type docs"
108                 fi
109         ) || exit
110 done
111
112 if test -d $PUBLIC
113 then
114         # This is iffy...
115         mv Documentation/git.html Documentation/saved-git-html
116         make >>../:html.log 2>&1 \
117                 -C Documentation \
118                 WEBDOC_DEST="$PUBLIC" ASCIIDOC_EXTRA='-a stalenotes' \
119                 install-webdoc &&
120         mv Documentation/saved-git-html Documentation/git.html
121 else
122         echo "* No public html at $PUBLIC"
123 fi || exit $?
124