summaryrefslogtreecommitdiff
path: root/Documentation
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-05-23 21:54:34 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-05-23 21:54:34 (GMT)
commitfa4f29b8a8febd454fb589f96afa014d73f157c1 (patch)
tree6ed7628590efa59242e5e10b7bd8174333132f5d /Documentation
parent7b02771b4f98cff47504cc6210e7fe9c8138f307 (diff)
parentab81411cede9e5fe52b416c4df835e19f1048426 (diff)
downloadgit-fa4f29b8a8febd454fb589f96afa014d73f157c1.zip
git-fa4f29b8a8febd454fb589f96afa014d73f157c1.tar.gz
git-fa4f29b8a8febd454fb589f96afa014d73f157c1.tar.bz2
Merge branch 'jc/doc-lint'
Find common mistakes when writing gitlink: in our documentation and drive the check from "make check-docs". I am not entirely happy with the way the script chooses what input file to validate, but it is not worse than not having anything, so let's move it forward and have the logic improved later when people care about it deeply. * jc/doc-lint: ci: validate "linkgit:" in documentation
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/Makefile4
-rwxr-xr-xDocumentation/lint-gitlink.perl71
2 files changed, 75 insertions, 0 deletions
diff --git a/Documentation/Makefile b/Documentation/Makefile
index 3e39e28..f6e288b 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,7 @@ quick-install-html: require-htmlrepo
print-man1:
@for i in $(MAN1_TXT); do echo $$i; done
+lint-docs::
+ $(QUIET_LINT)$(PERL_PATH) lint-gitlink.perl
+
.PHONY: FORCE
diff --git a/Documentation/lint-gitlink.perl b/Documentation/lint-gitlink.perl
new file mode 100755
index 0000000..476cc30
--- /dev/null
+++ b/Documentation/lint-gitlink.perl
@@ -0,0 +1,71 @@
+#!/usr/bin/perl
+
+use File::Find;
+use Getopt::Long;
+
+my $basedir = ".";
+GetOptions("basedir=s" => \$basedir)
+ or die("Cannot parse command line arguments\n");
+
+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, "<", "$basedir/$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 "$basedir/$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;
+}
+
+sub lint_it {
+ lint($File::Find::name) if -f && /\.txt$/;
+}
+
+if (!@ARGV) {
+ find({ wanted => \&lint_it, no_chdir => 1 }, $basedir);
+} else {
+ for (@ARGV) {
+ lint($_);
+ }
+}
+
+exit $found_errors;