Skip to content

Commit 3882a0d

Browse files
committed
Documentation: add lint-fsck-msgids
During the initial development of the fsck-msgids.txt feature, it has become apparent that it is very much error prone to make sure the description in the documentation file are sorted and correctly match what is in the fsck.h header file. Add a quick-and-dirty Perl script and doc-lint target to sanity check that the fsck-msgids.txt is consistent with the error type list in the fsck.h header file. Signed-off-by: Junio C Hamano <[email protected]>
1 parent f6534db commit 3882a0d

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

Documentation/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,19 @@ $(LINT_DOCS_MAN_SECTION_ORDER): .build/lint-docs/man-section-order/%.ok: %.txt
476476
.PHONY: lint-docs-man-section-order
477477
lint-docs-man-section-order: $(LINT_DOCS_MAN_SECTION_ORDER)
478478

479+
.PHONY: lint-docs-fsck-msgids
480+
LINT_DOCS_FSCK_MSGIDS = .build/lint-docs/fsck-msgids.ok
481+
$(LINT_DOCS_FSCK_MSGIDS): lint-fsck-msgids.perl
482+
$(LINT_DOCS_FSCK_MSGIDS): ../fsck.h fsck-msgids.txt
483+
$(call mkdir_p_parent_template)
484+
$(QUIET_GEN)$(PERL_PATH) lint-fsck-msgids.perl \
485+
../fsck.h fsck-msgids.txt $@
486+
487+
lint-docs-fsck-msgids: $(LINT_DOCS_FSCK_MSGIDS)
488+
479489
## Lint: list of targets above
480490
.PHONY: lint-docs
491+
lint-docs: lint-docs-fsck-msgids
481492
lint-docs: lint-docs-gitlink
482493
lint-docs: lint-docs-man-end-blurb
483494
lint-docs: lint-docs-man-section-order

Documentation/lint-fsck-msgids.perl

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/perl
2+
3+
my ($fsck_h, $fsck_msgids_txt, $okfile) = @ARGV;
4+
5+
my (%in_fsck_h, $fh, $bad);
6+
7+
open($fh, "<", "$fsck_h") or die;
8+
while (<$fh>) {
9+
if (/^\s+FUNC\(([0-9A-Z_]+), ([A-Z]+)\)/) {
10+
my ($name, $severity) = ($1, $2);
11+
my ($first) = 1;
12+
$name = join('',
13+
map {
14+
y/A-Z/a-z/;
15+
if (!$first) {
16+
s/^(.)/uc($1)/e;
17+
} else {
18+
$first = 0;
19+
}
20+
$_;
21+
}
22+
split(/_/, $name));
23+
$in_fsck_h{$name} = $severity;
24+
}
25+
}
26+
close($fh);
27+
28+
open($fh, "<", "$fsck_msgids_txt") or die;
29+
my ($previous, $current);
30+
while (<$fh>) {
31+
if (!defined $current) {
32+
if (/^\`([a-zA-Z0-9]*)\`::/) {
33+
$current = $1;
34+
if ((defined $previous) &&
35+
($current le $previous)) {
36+
print STDERR "$previous >= $current in doc\n";
37+
$bad = 1;
38+
}
39+
}
40+
} elsif (/^\s+\(([A-Z]+)\) /) {
41+
my ($level) = $1;
42+
if (!exists $in_fsck_h{$current}) {
43+
print STDERR "$current does not exist in fsck.h\n";
44+
$bad = 1;
45+
} elsif ($in_fsck_h{$current} eq "") {
46+
print STDERR "$current defined twice\n";
47+
$bad = 1;
48+
} elsif ($in_fsck_h{$current} ne $level) {
49+
print STDERR "$current severity $level != $in_fsck_h{$current}\n";
50+
$bad = 1;
51+
}
52+
$previous = $current;
53+
$in_fsck_h{$current} = ""; # mark as seen.
54+
undef $current;
55+
}
56+
}
57+
close($fh);
58+
59+
for my $key (keys %in_fsck_h) {
60+
if ($in_fsck_h{$key} ne "") {
61+
print STDERR "$key not explained in doc.\n";
62+
$bad = 1;
63+
}
64+
}
65+
66+
die if ($bad);
67+
68+
open($fh, ">", "$okfile");
69+
print $fh "good\n";
70+
close($fh);

0 commit comments

Comments
 (0)