]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/doc-diff
doc-diff: support diffing from/to AsciiDoc(tor)
[thirdparty/git.git] / Documentation / doc-diff
CommitLineData
beb188e2 1#!/bin/sh
7a76f5c6
JK
2#
3# Build two documentation trees and diff the resulting formatted output.
4# Compared to a source diff, this can reveal mistakes in the formatting.
5# For example:
6#
7# ./doc-diff origin/master HEAD
8#
9# would show the differences introduced by a branch based on master.
beb188e2
JK
10
11OPTIONS_SPEC="\
12doc-diff [options] <from> <to> [-- <diff-options>]
ad517430 13doc-diff (-c|--clean)
beb188e2 14--
2be39bb4
15j=n parallel argument to pass to make
16f force rebuild; do not rely on cached results
17c,clean cleanup temporary working files
18from-asciidoc use asciidoc with the 'from'-commit
19from-asciidoctor use asciidoctor with the 'from'-commit
20asciidoc use asciidoc with both commits
21to-asciidoc use asciidoc with the 'to'-commit
22to-asciidoctor use asciidoctor with the 'to'-commit
23asciidoctor use asciidoctor with both commits
beb188e2
JK
24"
25SUBDIRECTORY_OK=1
26. "$(git --exec-path)/git-sh-setup"
27
28parallel=
29force=
ad517430 30clean=
2be39bb4
31from_program=
32to_program=
beb188e2
JK
33while test $# -gt 0
34do
35 case "$1" in
36 -j)
37 parallel=$2; shift ;;
ad517430
ES
38 -c|--clean)
39 clean=t ;;
beb188e2
JK
40 -f)
41 force=t ;;
2be39bb4
42 --from-asciidoctor)
43 from_program=-asciidoctor ;;
44 --to-asciidoctor)
45 to_program=-asciidoctor ;;
46 --asciidoctor)
47 from_program=-asciidoctor
48 to_program=-asciidoctor ;;
49 --from-asciidoc)
50 from_program=-asciidoc ;;
51 --to-asciidoc)
52 to_program=-asciidoc ;;
53 --asciidoc)
54 from_program=-asciidoc
55 to_program=-asciidoc ;;
beb188e2
JK
56 --)
57 shift; break ;;
58 *)
59 usage ;;
60 esac
61 shift
62done
63
2afe9278 64tmp="$(git rev-parse --show-toplevel)/Documentation/tmp-doc-diff" || exit 1
ad517430
ES
65
66if test -n "$clean"
67then
68 test $# -eq 0 || usage
69 git worktree remove --force "$tmp/worktree" 2>/dev/null
70 rm -rf "$tmp"
71 exit 0
72fi
73
beb188e2
JK
74if test -z "$parallel"
75then
76 parallel=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
77 if test $? != 0 || test -z "$parallel"
78 then
79 parallel=1
80 fi
81fi
82
83test $# -gt 1 || usage
84from=$1; shift
85to=$1; shift
86
87from_oid=$(git rev-parse --verify "$from") || exit 1
88to_oid=$(git rev-parse --verify "$to") || exit 1
89
beb188e2
JK
90if test -n "$force"
91then
92 rm -rf "$tmp"
93fi
94
95# We'll do both builds in a single worktree, which lets "make" reuse
96# results that don't differ between the two trees.
97if ! test -d "$tmp/worktree"
98then
684e7422 99 git worktree add -f --detach "$tmp/worktree" "$from" &&
beb188e2
JK
100 dots=$(echo "$tmp/worktree" | sed 's#[^/]*#..#g') &&
101 ln -s "$dots/config.mak" "$tmp/worktree/config.mak"
102fi
103
2be39bb4
104construct_makemanflags () {
105 if test "$1" = "-asciidoc"
106 then
107 echo USE_ASCIIDOCTOR=
108 elif test "$1" = "-asciidoctor"
109 then
110 echo USE_ASCIIDOCTOR=YesPlease
111 fi
112}
113
114from_makemanflags=$(construct_makemanflags "$from_program") &&
115to_makemanflags=$(construct_makemanflags "$to_program") &&
116
117from_dir=$from_oid$from_program &&
118to_dir=$to_oid$to_program &&
bc71dc3f 119
beb188e2
JK
120# generate_render_makefile <srcdir> <dstdir>
121generate_render_makefile () {
122 find "$1" -type f |
123 while read src
124 do
125 dst=$2/${src#$1/}
126 printf 'all:: %s\n' "$dst"
127 printf '%s: %s\n' "$dst" "$src"
128 printf '\t@echo >&2 " RENDER $(notdir $@)" && \\\n'
129 printf '\tmkdir -p $(dir $@) && \\\n'
83d4b5ff 130 printf '\tMANWIDTH=80 man $< >$@+ && \\\n'
beb188e2
JK
131 printf '\tmv $@+ $@\n'
132 done
133}
134
2be39bb4 135# render_tree <committish_oid> <directory_name> <makemanflags>
beb188e2
JK
136render_tree () {
137 # Skip install-man entirely if we already have an installed directory.
138 # We can't rely on make here, since "install-man" unconditionally
139 # copies the files (spending effort, but also updating timestamps that
140 # we then can't rely on during the render step). We use "mv" to make
141 # sure we don't get confused by a previous run that failed partway
142 # through.
bc71dc3f
143 oid=$1 &&
144 dname=$2 &&
2be39bb4 145 makemanflags=$3 &&
bc71dc3f 146 if ! test -d "$tmp/installed/$dname"
beb188e2 147 then
bc71dc3f 148 git -C "$tmp/worktree" checkout --detach "$oid" &&
beb188e2 149 make -j$parallel -C "$tmp/worktree" \
2be39bb4 150 $makemanflags \
beb188e2
JK
151 GIT_VERSION=omitted \
152 SOURCE_DATE_EPOCH=0 \
bc71dc3f 153 DESTDIR="$tmp/installed/$dname+" \
beb188e2 154 install-man &&
bc71dc3f 155 mv "$tmp/installed/$dname+" "$tmp/installed/$dname"
beb188e2
JK
156 fi &&
157
158 # As with "installed" above, we skip the render if it's already been
159 # done. So using make here is primarily just about running in
160 # parallel.
bc71dc3f 161 if ! test -d "$tmp/rendered/$dname"
beb188e2 162 then
bc71dc3f
163 generate_render_makefile "$tmp/installed/$dname" \
164 "$tmp/rendered/$dname+" |
beb188e2 165 make -j$parallel -f - &&
bc71dc3f 166 mv "$tmp/rendered/$dname+" "$tmp/rendered/$dname"
beb188e2
JK
167 fi
168}
169
2be39bb4
170render_tree $from_oid $from_dir $from_makemanflags &&
171render_tree $to_oid $to_dir $to_makemanflags &&
bc71dc3f 172git -C $tmp/rendered diff --no-index "$@" $from_dir $to_dir