git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/4] doc-diff: add `--cut-header-footer`

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Mar 17, 2019, 18:36 UTC
Message-ID
<7ce7aa6f2f1ea40442c17c15fe8d7744b29d8650.1552838239.git.martin.agren@gmail.com>
In-Reply-To
<cover.1552838239.git.martin.agren@gmail.com>

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>
---
 Documentation/doc-diff | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/Documentation/doc-diff b/Documentation/doc-diff
index 36fc2307a7..3355be4798 100755
--- a/Documentation/doc-diff
+++ b/Documentation/doc-diff
@@ -21,6 +21,7 @@ asciidoc		use asciidoc with both commits
 to-asciidoc		use asciidoc with the 'to'-commit
 to-asciidoctor		use asciidoctor with the 'to'-commit
 asciidoctor		use asciidoctor with both commits
+cut-header-footer	cut away header and footer
 "
 SUBDIRECTORY_OK=1
 . "$(git --exec-path)/git-sh-setup"
@@ -30,6 +31,7 @@ force=
 clean=
 from_program=
 to_program=
+cut_header_footer=
 while test $# -gt 0
 do
 	case "$1" in
@@ -53,6 +55,8 @@ do
 	--asciidoc)
 		from_program=-asciidoc
 		to_program=-asciidoc ;;
+	--cut-header-footer)
+		cut_header_footer=-cut-header-footer ;;
 	--)
 		shift; break ;;
 	*)
@@ -114,8 +118,8 @@ construct_makemanflags () {
 from_makemanflags=$(construct_makemanflags "$from_program") &&
 to_makemanflags=$(construct_makemanflags "$to_program") &&
 
-from_dir=$from_oid$from_program &&
-to_dir=$to_oid$to_program &&
+from_dir=$from_oid$from_program$cut_header_footer &&
+to_dir=$to_oid$to_program$cut_header_footer &&
 
 # generate_render_makefile <srcdir> <dstdir>
 generate_render_makefile () {
@@ -164,6 +168,17 @@ render_tree () {
 			"$tmp/rendered/$dname+" |
 		make -j$parallel -f - &&
 		mv "$tmp/rendered/$dname+" "$tmp/rendered/$dname"
+
+		if test "$cut_header_footer" = "-cut-header-footer"
+		then
+			for f in $(find "$tmp/rendered/$dname" -type f)
+			do
+				tail -n +3 "$f" | head -n -2 |
+				sed -e '1{/^$/d}' -e '${/^$/d}' >"$f+" &&
+				mv "$f+" "$f" ||
+				return 1
+			done
+		fi
 	fi
 }
 
-- 
2.21.0
Previous: Martin ÅgrenNext: Junio C Hamano
Message 5 of 8 in “doc-diff: support diffing from/to AsciiDoc(tor)”
  1. 0/4 doc-diff: support diffing from/to AsciiDoc(tor)Martin Ågren, Mar 17, 2019
  2. 1/4 Doc: auto-detect changed build flagsMartin Ågren, Mar 17, 2019
  3. 2/4 doc-diff: let `render_tree()` take an explicit directory nameMartin Ågren, Mar 17, 2019
  4. 3/4 doc-diff: support diffing from/to AsciiDoc(tor)Martin Ågren, Mar 17, 2019
  5. 4/4 doc-diff: add `--cut-header-footer`Martin Ågren, Mar 17, 2019
  6. Junio C HamanoMar 18, 2019
  7. Jeff KingMar 19, 2019
  8. Martin ÅgrenMar 20, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.