3 # Build two documentation trees and diff the resulting formatted output.
4 # Compared to a source diff, this can reveal mistakes in the formatting.
7 # ./doc-diff origin/master HEAD
9 # would show the differences introduced by a branch based on master.
12 doc-diff [options] <from> <to> [-- <diff-options>]
14 j=n parallel argument to pass to make
15 f force rebuild; do not rely on cached results
18 . "$(git --exec-path)/git-sh-setup"
37 if test -z "$parallel"
39 parallel=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
40 if test $? != 0 || test -z "$parallel"
46 test $# -gt 1 || usage
50 from_oid=$(git rev-parse --verify "$from") || exit 1
51 to_oid=$(git rev-parse --verify "$to") || exit 1
54 tmp=Documentation/tmp-doc-diff
61 # We'll do both builds in a single worktree, which lets "make" reuse
62 # results that don't differ between the two trees.
63 if ! test -d "$tmp/worktree"
65 git worktree add --detach "$tmp/worktree" "$from" &&
66 dots=$(echo "$tmp/worktree" | sed 's#[^/]*#..#g') &&
67 ln -s "$dots/config.mak" "$tmp/worktree/config.mak"
70 # generate_render_makefile <srcdir> <dstdir>
71 generate_render_makefile () {
76 printf 'all:: %s\n' "$dst"
77 printf '%s: %s\n' "$dst" "$src"
78 printf '\t@echo >&2 " RENDER $(notdir $@)" && \\\n'
79 printf '\tmkdir -p $(dir $@) && \\\n'
80 printf '\tMANWIDTH=80 man -l $< >$@+ && \\\n'
81 printf '\tmv $@+ $@\n'
85 # render_tree <committish_oid>
87 # Skip install-man entirely if we already have an installed directory.
88 # We can't rely on make here, since "install-man" unconditionally
89 # copies the files (spending effort, but also updating timestamps that
90 # we then can't rely on during the render step). We use "mv" to make
91 # sure we don't get confused by a previous run that failed partway
93 if ! test -d "$tmp/installed/$1"
95 git -C "$tmp/worktree" checkout --detach "$1" &&
96 make -j$parallel -C "$tmp/worktree" \
99 DESTDIR="$PWD/$tmp/installed/$1+" \
101 mv "$tmp/installed/$1+" "$tmp/installed/$1"
104 # As with "installed" above, we skip the render if it's already been
105 # done. So using make here is primarily just about running in
107 if ! test -d "$tmp/rendered/$1"
109 generate_render_makefile "$tmp/installed/$1" "$tmp/rendered/$1+" |
110 make -j$parallel -f - &&
111 mv "$tmp/rendered/$1+" "$tmp/rendered/$1"
115 render_tree $from_oid &&
116 render_tree $to_oid &&
117 git -C $tmp/rendered diff --no-index "$@" $from_oid $to_oid