summaryrefslogtreecommitdiffstats
path: root/Documentation/lint-gitlink.perl
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-09 13:34:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-09 13:34:27 +0000
commit4dbdc42d9e7c3968ff7f690d00680419c9b8cb0f (patch)
tree47c1d492e9c956c1cd2b74dbd3b9d8b0db44dc4e /Documentation/lint-gitlink.perl
parentInitial commit. (diff)
downloadgit-4dbdc42d9e7c3968ff7f690d00680419c9b8cb0f.tar.xz
git-4dbdc42d9e7c3968ff7f690d00680419c9b8cb0f.zip
Adding upstream version 1:2.43.0.upstream/1%2.43.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'Documentation/lint-gitlink.perl')
-rwxr-xr-xDocumentation/lint-gitlink.perl69
1 files changed, 69 insertions, 0 deletions
diff --git a/Documentation/lint-gitlink.perl b/Documentation/lint-gitlink.perl
new file mode 100755
index 0000000..1c61dd9
--- /dev/null
+++ b/Documentation/lint-gitlink.perl
@@ -0,0 +1,69 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+# Parse arguments, a simple state machine for input like:
+#
+# <file-to-check.txt> <valid-files-to-link-to> --section=1 git.txt git-add.txt [...] --to-lint git-add.txt a-file.txt [...]
+my %TXT;
+my %SECTION;
+my $section;
+my $lint_these = 0;
+my $to_check = shift @ARGV;
+for my $arg (@ARGV) {
+ if (my ($sec) = $arg =~ /^--section=(\d+)$/s) {
+ $section = $sec;
+ next;
+ }
+
+ my ($name) = $arg =~ /^(.*?)\.txt$/s;
+ unless (defined $section) {
+ $TXT{$name} = $arg;
+ next;
+ }
+
+ $SECTION{$name} = $section;
+}
+
+my $exit_code = 0;
+sub report {
+ my ($pos, $line, $target, $msg) = @_;
+ substr($line, $pos) = "' <-- HERE";
+ $line =~ s/^\s+//;
+ print STDERR "$ARGV:$.: error: $target: $msg, shown with 'HERE' below:\n";
+ print STDERR "$ARGV:$.:\t'$line\n";
+ $exit_code = 1;
+}
+
+@ARGV = sort values %TXT;
+die "BUG: No list of valid linkgit:* files given" unless @ARGV;
+@ARGV = $to_check;
+while (<>) {
+ my $line = $_;
+ while ($line =~ m/linkgit:((.*?)\[(\d)\])/g) {
+ my $pos = pos $line;
+ my ($target, $page, $section) = ($1, $2, $3);
+
+ # De-AsciiDoc
+ $page =~ s/{litdd}/--/g;
+
+ if (!exists $TXT{$page}) {
+ report($pos, $line, $target, "link outside of our own docs");
+ next;
+ }
+ if (!exists $SECTION{$page}) {
+ report($pos, $line, $target, "link outside of our sectioned docs");
+ next;
+ }
+ my $real_section = $SECTION{$page};
+ if ($section != $SECTION{$page}) {
+ report($pos, $line, $target, "wrong section (should be $real_section)");
+ next;
+ }
+ }
+ # this resets our $. for each file
+ close ARGV if eof;
+}
+
+exit $exit_code;