Git fork

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 <gitster@pobox.com>

+81
+11
Documentation/Makefile
··· 476 476 .PHONY: lint-docs-man-section-order 477 477 lint-docs-man-section-order: $(LINT_DOCS_MAN_SECTION_ORDER) 478 478 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 + 479 489 ## Lint: list of targets above 480 490 .PHONY: lint-docs 491 + lint-docs: lint-docs-fsck-msgids 481 492 lint-docs: lint-docs-gitlink 482 493 lint-docs: lint-docs-man-end-blurb 483 494 lint-docs: lint-docs-man-section-order
+70
Documentation/lint-fsck-msgids.perl
··· 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);