What's cooking (2011/10 #02)
[alt-git.git] / dodoc.sh
blobe11bacd069bc2fe1c20d1621363b981420ceb7d0
1 #!/bin/sh
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
8 $ cat >hooks/post-update
9 #!/bin/sh
10 case " $* " in
11 *' refs/heads/master '*)
12 echo $HOME/git-doc/dodoc.sh | at now
14 esac
15 exec git update-server-info
16 $ chmod +x hooks/post-update
18 END_OF_COMMENTARY
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.
28 ID=`git rev-parse --verify refs/heads/master` || exit $?
30 unset GIT_DIR
32 : ${PUBLIC=/pub/software/scm/git/docs} &&
33 : ${MASTERREPO=`pwd`} &&
34 : ${DOCREPO=`dirname "$0"`} &&
35 test "$DOCREPO" != "" &&
36 cd "$DOCREPO" || exit $?
38 DOCREPO=`pwd`
40 tmp=`pwd`/.doctmp-$$
41 trap 'rm -f "$tmp".*' 0
44 git pull "$MASTERREPO" master &&
45 git fetch --tags "$MASTERREPO"
46 ) >/dev/null 2>/dev/null || exit $?
47 test $(git rev-parse --verify refs/heads/master) == "$ID" &&
48 NID=$(git describe --abbrev=4 "$ID") &&
49 test '' != "$NID" || exit $?
51 # Set up subrepositories
52 for type in man html
54 test -d doc-${type}pages || (
55 mkdir doc-${type}pages &&
56 cd doc-${type}pages &&
57 git init-db || exit $?
59 git fetch-pack "$MASTERREPO" ${type} |
60 while read sha1 name
62 case "$name" in
63 refs/heads/${type})
64 git update-ref HEAD $sha1 &&
65 git checkout || exit $?
66 break
68 esac
69 done || exit $?
70 ) || exit
71 rm -fr doc-$type-inst
72 done
74 dd='ASCIIDOC_NO_ROFF=YesPlease
75 ASCIIDOC8=YesPlease
76 MAN_BASE_URL="http://www.kernel.org/pub/software/scm/git/docs/"
77 BLK_SHA1=YesPlease
78 GNU_ROFF=YesPlease'
80 case "$NID" in
81 ?*-?*) ;;
82 ?*)
83 make clean &&
84 rm -fr doc-html-inst doc-man-inst &&
85 mkdir doc-html-inst doc-man-inst || exit
87 esac
89 DIFF=diff
90 export DIFF
92 make >./:html.log 2>&1 \
93 -C Documentation -j 2 $dd \
94 WEBDOC_DEST="$DOCREPO/doc-html-inst" install-webdoc || exit
96 make >./:man.log 2>&1 \
97 -C Documentation -j 2 $dd \
98 man1="$DOCREPO/doc-man-inst/man1" \
99 man5="$DOCREPO/doc-man-inst/man5" \
100 man7="$DOCREPO/doc-man-inst/man7" \
101 man1dir="$DOCREPO/doc-man-inst/man1" \
102 man5dir="$DOCREPO/doc-man-inst/man5" \
103 man7dir="$DOCREPO/doc-man-inst/man7" install || exit
105 for type in html man
107 find doc-$type-inst -type f |
108 while read path
110 it=$(expr "$path" : doc-$type-inst/'\(.*\)') || continue
111 t="doc-${type}pages/$it"
112 test -f "$t" && diff -q "$path" "$t" && continue
113 mkdir -p "$(dirname "$t")" &&
114 echo ": $t" && rm -f "$t" && ln "$path" "$t" || exit
115 ( cd doc-${type}pages && git add "$it" )
116 done || exit
118 find doc-$type-inst -type f |
119 sed -e 's|^doc-'$type'-inst/||' | sort >"$tmp.1" &&
120 (cd doc-${type}pages && git ls-files | sort) >"$tmp.2" &&
121 comm -13 "$tmp.1" "$tmp.2" |
122 ( cd doc-${type}pages && xargs rm -f -- ) || exit
125 cd doc-${type}pages
127 case "$type" in
128 html)
129 TYPE='HTML docs'
130 rm -f index.html
131 ln -sf git.html index.html
132 git add index.html
134 man)
135 TYPE='manpages'
137 esac
139 if git commit -a -m "Autogenerated $TYPE for $NID"
140 then
141 git send-pack "$MASTERREPO" master:refs/heads/$type \
142 >/dev/null 2>&1
143 else
144 echo "* No changes in $type docs"
146 ) || exit
147 done
149 if test -d $PUBLIC
150 then
151 # This is iffy...
152 mv Documentation/git.html Documentation/saved-git-html
153 make >>./:html.log 2>&1 \
154 -C Documentation \
155 WEBDOC_DEST="$PUBLIC" ASCIIDOC_EXTRA='-a stalenotes' \
156 install-webdoc &&
157 mv Documentation/saved-git-html Documentation/git.html
158 else
159 echo "* No public html at $PUBLIC"
160 fi || exit $?
162 echo '
164 *** ALL DONE ***
165 ' >>./:html.log