1#!/bin/sh
23
OPTIONS_SPEC="\
4doc-diff [options] <from> <to> [-- <diff-options>]
5--
6j=n parallel argument to pass to make
7f force rebuild; do not rely on cached results
8"
9SUBDIRECTORY_OK=1
10. "$(git --exec-path)/git-sh-setup"
1112
parallel=
13force=
14while test $# -gt 0
15do
16case "$1" in
17-j)
18parallel=$2; shift ;;
19-f)
20force=t ;;
21--)
22shift; break ;;
23*)
24usage ;;
25esac
26shift
27done
2829
if test -z "$parallel"
30then
31parallel=$(getconf _NPROCESSORS_ONLN 2>/dev/null)
32if test $? != 0 || test -z "$parallel"
33then
34parallel=1
35fi
36fi
3738
test $# -gt 1 || usage
39from=$1; shift
40to=$1; shift
4142
from_oid=$(git rev-parse --verify "$from") || exit 1
43to_oid=$(git rev-parse --verify "$to") || exit 1
4445
cd_to_toplevel
46tmp=Documentation/tmp-doc-diff
4748
if test -n "$force"
49then
50rm -rf "$tmp"
51fi
5253
# We'll do both builds in a single worktree, which lets "make" reuse
54# results that don't differ between the two trees.
55if ! test -d "$tmp/worktree"
56then
57git worktree add --detach "$tmp/worktree" "$from" &&
58dots=$(echo "$tmp/worktree" | sed 's#[^/]*#..#g') &&
59ln -s "$dots/config.mak" "$tmp/worktree/config.mak"
60fi
6162
# generate_render_makefile <srcdir> <dstdir>
63generate_render_makefile () {
64find "$1" -type f |
65while read src
66do
67dst=$2/${src#$1/}
68printf 'all:: %s\n' "$dst"
69printf '%s: %s\n' "$dst" "$src"
70printf '\t@echo >&2 " RENDER $(notdir $@)" && \\\n'
71printf '\tmkdir -p $(dir $@) && \\\n'
72printf '\tMANWIDTH=80 man -l $< >$@+ && \\\n'
73printf '\tmv $@+ $@\n'
74done
75}
7677
# render_tree <dirname> <committish>
78render_tree () {
79# Skip install-man entirely if we already have an installed directory.
80# We can't rely on make here, since "install-man" unconditionally
81# copies the files (spending effort, but also updating timestamps that
82# we then can't rely on during the render step). We use "mv" to make
83# sure we don't get confused by a previous run that failed partway
84# through.
85if ! test -d "$tmp/installed/$1"
86then
87git -C "$tmp/worktree" checkout "$2" &&
88make -j$parallel -C "$tmp/worktree" \
89GIT_VERSION=omitted \
90SOURCE_DATE_EPOCH=0 \
91DESTDIR="$PWD/$tmp/installed/$1+" \
92install-man &&
93mv "$tmp/installed/$1+" "$tmp/installed/$1"
94fi &&
9596
# As with "installed" above, we skip the render if it's already been
97# done. So using make here is primarily just about running in
98# parallel.
99if ! test -d "$tmp/rendered/$1"
100then
101generate_render_makefile "$tmp/installed/$1" "$tmp/rendered/$1+" |
102make -j$parallel -f - &&
103mv "$tmp/rendered/$1+" "$tmp/rendered/$1"
104fi
105}
106107
render_tree $from_oid "$from" &&
108render_tree $to_oid "$to" &&
109git -C $tmp/rendered diff --no-index "$@" $from_oid $to_oid