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

Re: [PATCH v4 1/2] Documentation: fix linkgit references

From
Junio C Hamano <gitster@pobox.com>
Date
May 4, 2016, 21:34 UTC
Message-ID
<xmqq4madfqxs.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160504213149.GA22828@sigill.intra.peff.net>
Third time's a charm, perhaps?
 
-- >8 --
Subject: [PATCH] ci: validate "gitlink:" in documentation

It is easy to add incorrect "linkgit:<page>[<section>]" references to our documentation suite. Catch these common classes of errors:

 * Referring to Documentation/<page>.txt that does not exist.
 * Referring to a <page> outside the Git suite.  In general, <page>
   must begin with "git".
 * Listing the manual <section> incorrectly.  The first line of the
   Documentation/<page>.txt must end with "(<section>)".
with a new script "ci/lint-gitlink", and drive it from "make check-docs".
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/Makefile |  5 +++++
 Makefile               |  1 +
 ci/lint-gitlink        | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)
 create mode 100755 ci/lint-gitlink
diff --git a/Documentation/Makefile b/Documentation/Makefile
index 3e39e28..e9cd43d 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -204,6 +204,7 @@ ifndef V
 	QUIET_DBLATEX	= @echo '   ' DBLATEX $@;
 	QUIET_XSLTPROC	= @echo '   ' XSLTPROC $@;
 	QUIET_GEN	= @echo '   ' GEN $@;
+	QUIET_LINT	= @echo '   ' LINT $@;
 	QUIET_STDERR	= 2> /dev/null
 	QUIET_SUBDIR0	= +@subdir=
 	QUIET_SUBDIR1	= ;$(NO_SUBDIR) echo '   ' SUBDIR $$subdir; \
@@ -427,4 +428,8 @@ quick-install-html: require-htmlrepo
 print-man1:
 	@for i in $(MAN1_TXT); do echo $$i; done
 
+lint-docs::
+	$(QUIET_LINT)$(foreach txt,$(patsubst %.html,%.txt,$(DOC_HTML)), \
+	../ci/lint-gitlink $(txt))
+
 .PHONY: FORCE
diff --git a/Makefile b/Makefile
index 2742a69..61bd0ab 100644
--- a/Makefile
+++ b/Makefile
@@ -2496,6 +2496,7 @@ ALL_COMMANDS += git-gui git-citool
 
 .PHONY: check-docs
 check-docs::
+	$(MAKE) -C Documentation lint-docs
 	@(for v in $(ALL_COMMANDS); \
 	do \
 		case "$$v" in \
diff --git a/ci/lint-gitlink b/ci/lint-gitlink
new file mode 100755
index 0000000..6b6bf91
--- /dev/null
+++ b/ci/lint-gitlink
@@ -0,0 +1,56 @@
+#!/usr/bin/perl
+
+my $found_errors = 0;
+
+sub report {
+	my ($where, $what, $error) = @_;
+	print "$where: $error: $what\n";
+	$found_errors = 1;
+}
+
+sub grab_section {
+	my ($page) = @_;
+	open my $fh, "<", "$page.txt";
+	my $firstline = <$fh>;
+	chomp $firstline;
+	close $fh;
+	my ($section) = ($firstline =~ /.*\((\d)\)$/);
+	return $section;
+}
+
+sub lint {
+	my ($file) = @_;
+	open my $fh, "<", $file
+		or return;
+	while (<$fh>) {
+		my $where = "$file:$.";
+		while (s/linkgit:((.*?)\[(\d)\])//) {
+			my ($target, $page, $section) = ($1, $2, $3);
+
+			# De-AsciiDoc
+			$page =~ s/{litdd}/--/g;
+
+			if ($page !~ /^git/) {
+				report($where, $target, "nongit link");
+				next;
+			}
+			if (! -f "$page.txt") {
+				report($where, $target, "no such source");
+				next;
+			}
+			$real_section = grab_section($page);
+			if ($real_section != $section) {
+				report($where, $target,
+					"wrong section (should be $real_section)");
+				next;
+			}
+		}
+	}
+	close $fh;
+}
+
+for (@ARGV) {
+	lint($_);
+}
+
+exit $found_errors;
-- 
2.8.2-498-g6350fe8
Previous: Jeff KingNext: Jeff King
Message 30 of 53 in “travis-ci: build documentation”
  1. travis-ci: build documentationlarsxschneider@gmail.com, Apr 29, 2016
  2. Jeff KingApr 29, 2016
  3. Matthieu MoyApr 29, 2016
  4. Lars SchneiderApr 29, 2016
  5. Jeff KingApr 29, 2016
  6. Stefan BellerApr 29, 2016
  7. Matthieu MoyApr 29, 2016
  8. Lars SchneiderApr 29, 2016
  9. Junio C HamanoApr 29, 2016
  10. 0/2 travis-ci: build documentationlarsxschneider@gmail.com, May 2, 2016
  11. 1/2 Documentation: fix linkgit referenceslarsxschneider@gmail.com, May 2, 2016
  12. Jeff KingMay 2, 2016
  13. Lars SchneiderMay 3, 2016
  14. Junio C HamanoMay 3, 2016
  15. Jeff KingMay 3, 2016
  16. Jeff KingMay 3, 2016
  17. 0/2 travis-ci: build documentationlarsxschneider@gmail.com, May 4, 2016
  18. 1/2 Documentation: fix linkgit referenceslarsxschneider@gmail.com, May 4, 2016
  19. Lars SchneiderMay 4, 2016
  20. Jeff KingMay 4, 2016
  21. Ramsay JonesMay 4, 2016
  22. Junio C HamanoMay 4, 2016
  23. Junio C HamanoMay 4, 2016
  24. Junio C HamanoMay 4, 2016
  25. Jeff KingMay 4, 2016
  26. Junio C HamanoMay 4, 2016
  27. Jeff KingMay 4, 2016
  28. Junio C HamanoMay 4, 2016
  29. Jeff KingMay 4, 2016
  30. Junio C HamanoMay 4, 2016
  31. Jeff KingMay 4, 2016
  32. Junio C HamanoMay 4, 2016
  33. Jeff KingMay 4, 2016
  34. Junio C HamanoMay 4, 2016
  35. Junio C HamanoMay 4, 2016
  36. Junio C HamanoMay 4, 2016
  37. Jeff KingMay 4, 2016
  38. Jeff KingMay 4, 2016
  39. Ævar Arnfjörð BjarmasonMay 4, 2016
  40. Jeff KingMay 4, 2016
  41. 2/2 travis-ci: build documentationlarsxschneider@gmail.com, May 4, 2016
  42. Junio C HamanoMay 10, 2016
  43. Lars SchneiderMay 13, 2016
  44. 2/2 travis-ci: build documentationlarsxschneider@gmail.com, May 2, 2016
  45. Junio C HamanoMay 2, 2016
  46. Lars SchneiderMay 3, 2016
  47. Junio C HamanoMay 3, 2016
  48. Lars SchneiderMay 4, 2016
  49. Eric WongMay 4, 2016
  50. Junio C HamanoMay 4, 2016
  51. Christian CouderMay 4, 2016
  52. Matthieu MoyMay 4, 2016
  53. Matthieu MoyApr 29, 2016

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.