git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Lars Schneider <larsxschneider@gmail.com>,
	Ramsay Jones <ramsay@ramsayjones.plus.com>,
	git@vger.kernel.org, Matthieu.Moy@grenoble-inp.fr,
	sbeller@google.com
Subject: Re: [PATCH v4 1/2] Documentation: fix linkgit references
Date: Wed, 04 May 2016 14:34:23 -0700	[thread overview]
Message-ID: <xmqq4madfqxs.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20160504213149.GA22828@sigill.intra.peff.net> (Jeff King's message of "Wed, 4 May 2016 17:31:50 -0400")

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

  reply	other threads:[~2016-05-04 21:34 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-29  9:35 [PATCH v2] travis-ci: build documentation larsxschneider
2016-04-29 12:14 ` Jeff King
2016-04-29 12:21   ` Matthieu Moy
2016-04-29 14:22     ` Lars Schneider
2016-04-29 14:32       ` Jeff King
2016-04-29 17:27     ` Stefan Beller
2016-04-29 17:53       ` Matthieu Moy
2016-04-29 20:44       ` Lars Schneider
2016-04-29 21:05         ` Junio C Hamano
2016-05-02 20:20           ` [PATCH v3 0/2] " larsxschneider
2016-05-02 20:20             ` [PATCH v3 1/2] Documentation: fix linkgit references larsxschneider
2016-05-02 20:34               ` Jeff King
2016-05-03  8:30                 ` Lars Schneider
2016-05-03 15:41                   ` Junio C Hamano
2016-05-03 17:59                     ` Jeff King
2016-05-03 17:58                   ` Jeff King
2016-05-04  8:38                   ` [PATCH v4 0/2] travis-ci: build documentation larsxschneider
2016-05-04  8:38                     ` [PATCH v4 1/2] Documentation: fix linkgit references larsxschneider
2016-05-04  8:43                       ` Lars Schneider
2016-05-04  8:57                         ` Jeff King
2016-05-04 11:38                         ` Ramsay Jones
2016-05-04 17:28                           ` Junio C Hamano
2016-05-04 17:36                             ` Junio C Hamano
2016-05-04 18:52                             ` Junio C Hamano
2016-05-04 19:25                               ` Jeff King
2016-05-04 19:57                                 ` Junio C Hamano
2016-05-04 20:06                                   ` Jeff King
2016-05-04 21:15                                     ` Junio C Hamano
2016-05-04 21:31                                       ` Jeff King
2016-05-04 21:34                                         ` Junio C Hamano [this message]
2016-05-04 21:44                                           ` Jeff King
2016-05-04 21:52                                             ` Junio C Hamano
2016-05-04 22:09                                               ` Jeff King
2016-05-04 22:17                                                 ` Junio C Hamano
2016-05-04 22:27                                                   ` Junio C Hamano
2016-05-04 23:28                                                     ` Junio C Hamano
2016-05-04 23:41                                                       ` Jeff King
2016-05-04 23:53                                                         ` Jeff King
2016-05-04 21:54                                     ` Ævar Arnfjörð Bjarmason
2016-05-04 22:11                                       ` Jeff King
2016-05-04  8:38                     ` [PATCH v4 2/2] travis-ci: build documentation larsxschneider
2016-05-10 17:12                       ` Junio C Hamano
2016-05-13  6:26                         ` Lars Schneider
2016-05-02 20:20             ` [PATCH v3 " larsxschneider
2016-05-02 20:45               ` Junio C Hamano
2016-05-03  8:12                 ` Lars Schneider
2016-05-03 15:43                   ` Junio C Hamano
2016-05-04  8:04                     ` Lars Schneider
2016-05-04  8:18                       ` Eric Wong
2016-05-04  8:19                       ` Junio C Hamano
2016-05-04  9:11                       ` Christian Couder
2016-05-04 11:27                         ` Matthieu Moy
2016-04-29 14:40 ` [PATCH v2] " Matthieu Moy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq4madfqxs.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=git@vger.kernel.org \
    --cc=larsxschneider@gmail.com \
    --cc=peff@peff.net \
    --cc=ramsay@ramsayjones.plus.com \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).