doc-diff: add `--cut-header-footer`

AsciiDoc and Asciidoctor do not agree on what to write in the header and footer of each man-page, i.e., the very first and the very last line of *.[157]. Those differences can certainly be interesting in their own right, but they clutter the output of `./doc-diff --from-asciidoc --to-asciidoctor HEAD HEAD` quite a bit since the diff contains some 10-15 lines of noise per file diffed. Teach doc-diff to cut away the first two and last two lines, i.e., the header/footer and the empty line immediately following/preceding it. Because Asciidoctor uses an extra empty line compared to AsciiDoc, remove one more line at each end of the file, but only if it's empty. An alternative approach might be to pass down `--no-header-footer`, which both AsciiDoc and Asciidoctor understand, but it has some drawbacks. First of all, the result doesn't build -- `xmlto` stumbles on the resulting xml since it has multiple root elements. Second, it cuts too much -- dropping the header loses the synopsis, which would be interesting to diff. Like in the previous commit, encode this option into the directory name of the "installed" and "rendered" files. Otherwise, we wouldn't be able to trust that what we use out of that cache actually corresponds to the options given for this run. (We could optimize this caching a little since this flag doesn't affect the contents of "installed" at all, but let's punt on that.) Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin Ågren committed Mar 17, 2019 at 19:36 UTC e605077260080584ec03be039a8c62ed2bd52e81
1 file changed +17 -2
Documentation/doc-diff
+17 -2
@@ -21,6 +21,7 @@ asciidoc use asciidoc with both commits
21 to-asciidoc use asciidoc with the 'to'-commit
22 to-asciidoctor use asciidoctor with the 'to'-commit
23 asciidoctor use asciidoctor with both commits
24 +cut-header-footer cut away header and footer
25 "
26 SUBDIRECTORY_OK=1
27 . "$(git --exec-path)/git-sh-setup"
@@ -30,6 +31,7 @@ force=
31 clean=
32 from_program=
33 to_program=
34 +cut_header_footer=
35 while test $# -gt 0
36 do
37 case "$1" in
@@ -53,6 +55,8 @@ do
55 --asciidoc)
56 from_program=-asciidoc
57 to_program=-asciidoc ;;
58 + --cut-header-footer)
59 + cut_header_footer=-cut-header-footer ;;
60 --)
61 shift; break ;;
62 *)
@@ -114,8 +118,8 @@ construct_makemanflags () {
118 from_makemanflags=$(construct_makemanflags "$from_program") &&
119 to_makemanflags=$(construct_makemanflags "$to_program") &&
120
117 -from_dir=$from_oid$from_program &&
118 -to_dir=$to_oid$to_program &&
121 +from_dir=$from_oid$from_program$cut_header_footer &&
122 +to_dir=$to_oid$to_program$cut_header_footer &&
123
124 # generate_render_makefile <srcdir> <dstdir>
125 generate_render_makefile () {
@@ -164,6 +168,17 @@ render_tree () {
168 "$tmp/rendered/$dname+" |
169 make -j$parallel -f - &&
170 mv "$tmp/rendered/$dname+" "$tmp/rendered/$dname"
171 +
172 + if test "$cut_header_footer" = "-cut-header-footer"
173 + then
174 + for f in $(find "$tmp/rendered/$dname" -type f)
175 + do
176 + tail -n +3 "$f" | head -n -2 |
177 + sed -e '1{/^$/d}' -e '${/^$/d}' >"$f+" &&
178 + mv "$f+" "$f" ||
179 + return 1
180 + done
181 + fi
182 fi
183 }
184