Start preparing for the next cycle.
[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 DOCREPO=`pwd`
39
40 tmp=`pwd`/.doctmp-$$
41 trap 'rm -f "$tmp".*' 0
42
43 git pull "$MASTERREPO" master &&
44 git fetch --tags "$MASTERREPO" || exit $?
45 test $(git-rev-parse --verify refs/heads/master) == "$ID" &&
46 NID=$(git-describe --abbrev=4 "$ID") &&
47 test '' != "$NID" ||  exit $?
48
49 # Set up subrepositories
50 for type in man html
51 do
52         test -d doc-${type}pages || (
53                 mkdir doc-${type}pages &&
54                 cd doc-${type}pages &&
55                 git init-db || exit $?
56
57                 git fetch-pack "$MASTERREPO" ${type} |
58                 while read sha1 name
59                 do
60                         case "$name" in
61                         refs/heads/${type})
62                                 git update-ref HEAD $sha1 &&
63                                 git checkout || exit $?
64                                 break
65                                 ;;
66                         esac
67                 done || exit $?
68         ) || exit
69         rm -fr doc-$type-inst
70 done
71
72 make >./:html.log 2>&1 \
73         -C Documentation -j 2 \
74         WEBDOC_DEST="$DOCREPO/doc-html-inst" install-webdoc || exit
75
76 make >./:man.log 2>&1 \
77         -C Documentation -j 2 \
78         man1="$DOCREPO/doc-man-inst/man1" \
79         man7="$DOCREPO/doc-man-inst/man7" \
80         man1dir="$DOCREPO/doc-man-inst/man1" \
81         man7dir="$DOCREPO/doc-man-inst/man7" install || exit
82
83 for type in html man
84 do
85         find doc-$type-inst -type f |
86         while read path
87         do
88                 it=$(expr "$path" : doc-$type-inst/'\(.*\)') || continue
89                 t="doc-${type}pages/$it"
90                 test -f "$t" && diff -q "$path" "$t" && continue
91
92                 echo ": $t" && rm -f "$t" && ln "$path" "$t" || exit
93                 ( cd doc-${type}pages && git add "$it" )
94         done || exit
95
96         find doc-$type-inst -type f |
97         sed -e 's|^doc-'$type'-inst/||' | sort >"$tmp.1" &&
98         (cd doc-${type}pages && git ls-files | sort) >"$tmp.2" &&
99         comm -13 "$tmp.1" "$tmp.2" |
100         ( cd doc-${type}pages && xargs rm -f -- ) || exit
101
102         (
103                 cd doc-${type}pages
104
105                 case "$type" in
106                 html)
107                         TYPE='HTML docs'
108                         rm -f index.html
109                         ln -sf git.html index.html
110                         git add index.html
111                         ;;
112                 man)
113                         TYPE='manpages'
114                         ;;
115                 esac
116
117                 if git commit -a -m "Autogenerated $TYPE for $NID"
118                 then
119                         git send-pack "$MASTERREPO" master:refs/heads/$type
120                 else
121                         echo "* No changes in $type docs"
122                 fi
123         ) || exit
124 done
125
126 if test -d $PUBLIC
127 then
128         # This is iffy...
129         mv Documentation/git.html Documentation/saved-git-html
130         make >>./:html.log 2>&1 \
131                 -C Documentation \
132                 WEBDOC_DEST="$PUBLIC" ASCIIDOC_EXTRA='-a stalenotes' \
133                 install-webdoc &&
134         mv Documentation/saved-git-html Documentation/git.html
135 else
136         echo "* No public html at $PUBLIC"
137 fi || exit $?
138