1#!/bin/sh 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. 10 11OPTIONS_SPEC="\ 12doc-diff [options] <from> <to> [-- <diff-options>] 13-- 14j=n parallel argument to pass to make 15f force rebuild; do not rely on cached results 16" 17SUBDIRECTORY_OK=1 18. "$(git --exec-path)/git-sh-setup" 19 20parallel= 21force= 22whiletest$#-gt0 23do 24case"$1"in 25-j) 26 parallel=$2;shift;; 27-f) 28 force=t ;; 29--) 30shift;break;; 31*) 32 usage ;; 33esac 34shift 35done 36 37iftest -z"$parallel" 38then 39 parallel=$(getconf _NPROCESSORS_ONLN 2>/dev/null) 40iftest $? !=0||test -z"$parallel" 41then 42 parallel=1 43fi 44fi 45 46test$#-gt1|| usage 47from=$1;shift 48to=$1;shift 49 50from_oid=$(git rev-parse --verify "$from")||exit1 51to_oid=$(git rev-parse --verify "$to")||exit1 52 53cd_to_toplevel 54tmp=Documentation/tmp-doc-diff 55 56iftest -n"$force" 57then 58rm-rf"$tmp" 59fi 60 61# We'll do both builds in a single worktree, which lets "make" reuse 62# results that don't differ between the two trees. 63if!test -d"$tmp/worktree" 64then 65 git worktree add --detach"$tmp/worktree""$from"&& 66 dots=$(echo "$tmp/worktree" | sed 's#[^/]*#..#g')&& 67ln-s"$dots/config.mak""$tmp/worktree/config.mak" 68fi 69 70# generate_render_makefile <srcdir> <dstdir> 71generate_render_makefile () { 72find"$1"-type f | 73whileread src 74do 75 dst=$2/${src#$1/} 76printf'all:: %s\n'"$dst" 77printf'%s: %s\n'"$dst""$src" 78printf'\t@echo >&2 " RENDER$(notdir $@)" &&\\\n' 79printf'\tmkdir -p$(dir $@)&&\\\n' 80printf'\tMANWIDTH=80 man -l $< >$@+ &&\\\n' 81printf'\tmv $@+ $@\n' 82done 83} 84 85# render_tree <committish_oid> 86render_tree () { 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 92# through. 93if!test -d"$tmp/installed/$1" 94then 95 git -C"$tmp/worktree" checkout --detach"$1"&& 96make-j$parallel-C"$tmp/worktree" \ 97 GIT_VERSION=omitted \ 98 SOURCE_DATE_EPOCH=0 \ 99 DESTDIR="$PWD/$tmp/installed/$1+" \ 100install-man&& 101mv"$tmp/installed/$1+""$tmp/installed/$1" 102fi&& 103 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 106# parallel. 107if!test -d"$tmp/rendered/$1" 108then 109 generate_render_makefile "$tmp/installed/$1""$tmp/rendered/$1+"| 110make-j$parallel-f- && 111mv"$tmp/rendered/$1+""$tmp/rendered/$1" 112fi 113} 114 115render_tree $from_oid&& 116render_tree $to_oid&& 117git -C$tmp/rendered diff--no-index"$@"$from_oid $to_oid