Skip to content

Commit e605077

Browse files
Martin Ågrengitster
authored andcommitted
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>
1 parent 2be39bb commit e605077

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Documentation/doc-diff

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ asciidoc use asciidoc with both commits
2121
to-asciidoc use asciidoc with the 'to'-commit
2222
to-asciidoctor use asciidoctor with the 'to'-commit
2323
asciidoctor use asciidoctor with both commits
24+
cut-header-footer cut away header and footer
2425
"
2526
SUBDIRECTORY_OK=1
2627
. "$(git --exec-path)/git-sh-setup"
@@ -30,6 +31,7 @@ force=
3031
clean=
3132
from_program=
3233
to_program=
34+
cut_header_footer=
3335
while test $# -gt 0
3436
do
3537
case "$1" in
@@ -53,6 +55,8 @@ do
5355
--asciidoc)
5456
from_program=-asciidoc
5557
to_program=-asciidoc ;;
58+
--cut-header-footer)
59+
cut_header_footer=-cut-header-footer ;;
5660
--)
5761
shift; break ;;
5862
*)
@@ -114,8 +118,8 @@ construct_makemanflags () {
114118
from_makemanflags=$(construct_makemanflags "$from_program") &&
115119
to_makemanflags=$(construct_makemanflags "$to_program") &&
116120

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 &&
119123

120124
# generate_render_makefile <srcdir> <dstdir>
121125
generate_render_makefile () {
@@ -164,6 +168,17 @@ render_tree () {
164168
"$tmp/rendered/$dname+" |
165169
make -j$parallel -f - &&
166170
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
167182
fi
168183
}
169184

0 commit comments

Comments
 (0)