From: Junio C Hamano <gitster@pobox.com>
To: "John Cai via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, John Cai <johncai86@gmail.com>
Subject: [PATCH] Documentation: add lint-fsck-msgids
Date: Mon, 24 Oct 2022 22:12:51 -0700 [thread overview]
Message-ID: <xmqqa65kpju4.fsf_-_@gitster.g> (raw)
In-Reply-To: <xmqqwn8oplsh.fsf@gitster.g> (Junio C. Hamano's message of "Mon, 24 Oct 2022 21:30:38 -0700")
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>
---
* So the quick-and-dirty one gets repackaged with minimum polish to
become such a lint-doc checker. With the MISSING_TREE_OBJECT
removed from fsck.h header, and the fixes to the msgids.txt
documentation applied, the result passes the check.
Documentation/Makefile | 11 +++++
Documentation/lint-fsck-msgids.perl | 70 +++++++++++++++++++++++++++++
2 files changed, 81 insertions(+)
create mode 100755 Documentation/lint-fsck-msgids.perl
diff --git a/Documentation/Makefile b/Documentation/Makefile
index d47acb2e25..5e1a7f655c 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -476,8 +476,19 @@ $(LINT_DOCS_MAN_SECTION_ORDER): .build/lint-docs/man-section-order/%.ok: %.txt
.PHONY: lint-docs-man-section-order
lint-docs-man-section-order: $(LINT_DOCS_MAN_SECTION_ORDER)
+.PHONY: lint-docs-fsck-msgids
+LINT_DOCS_FSCK_MSGIDS = .build/lint-docs/fsck-msgids.ok
+$(LINT_DOCS_FSCK_MSGIDS): lint-fsck-msgids.perl
+$(LINT_DOCS_FSCK_MSGIDS): ../fsck.h fsck-msgids.txt
+ $(call mkdir_p_parent_template)
+ $(QUIET_GEN)$(PERL_PATH) lint-fsck-msgids.perl \
+ ../fsck.h fsck-msgids.txt $@
+
+lint-docs-fsck-msgids: $(LINT_DOCS_FSCK_MSGIDS)
+
## Lint: list of targets above
.PHONY: lint-docs
+lint-docs: lint-docs-fsck-msgids
lint-docs: lint-docs-gitlink
lint-docs: lint-docs-man-end-blurb
lint-docs: lint-docs-man-section-order
diff --git a/Documentation/lint-fsck-msgids.perl b/Documentation/lint-fsck-msgids.perl
new file mode 100755
index 0000000000..1233ffe815
--- /dev/null
+++ b/Documentation/lint-fsck-msgids.perl
@@ -0,0 +1,70 @@
+#!/usr/bin/perl
+
+my ($fsck_h, $fsck_msgids_txt, $okfile) = @ARGV;
+
+my (%in_fsck_h, $fh, $bad);
+
+open($fh, "<", "$fsck_h") or die;
+while (<$fh>) {
+ if (/^\s+FUNC\(([0-9A-Z_]+), ([A-Z]+)\)/) {
+ my ($name, $severity) = ($1, $2);
+ my ($first) = 1;
+ $name = join('',
+ map {
+ y/A-Z/a-z/;
+ if (!$first) {
+ s/^(.)/uc($1)/e;
+ } else {
+ $first = 0;
+ }
+ $_;
+ }
+ split(/_/, $name));
+ $in_fsck_h{$name} = $severity;
+ }
+}
+close($fh);
+
+open($fh, "<", "$fsck_msgids_txt") or die;
+my ($previous, $current);
+while (<$fh>) {
+ if (!defined $current) {
+ if (/^\`([a-zA-Z0-9]*)\`::/) {
+ $current = $1;
+ if ((defined $previous) &&
+ ($current le $previous)) {
+ print STDERR "$previous >= $current in doc\n";
+ $bad = 1;
+ }
+ }
+ } elsif (/^\s+\(([A-Z]+)\) /) {
+ my ($level) = $1;
+ if (!exists $in_fsck_h{$current}) {
+ print STDERR "$current does not exist in fsck.h\n";
+ $bad = 1;
+ } elsif ($in_fsck_h{$current} eq "") {
+ print STDERR "$current defined twice\n";
+ $bad = 1;
+ } elsif ($in_fsck_h{$current} ne $level) {
+ print STDERR "$current severity $level != $in_fsck_h{$current}\n";
+ $bad = 1;
+ }
+ $previous = $current;
+ $in_fsck_h{$current} = ""; # mark as seen.
+ undef $current;
+ }
+}
+close($fh);
+
+for my $key (keys %in_fsck_h) {
+ if ($in_fsck_h{$key} ne "") {
+ print STDERR "$key not explained in doc.\n";
+ $bad = 1;
+ }
+}
+
+die if ($bad);
+
+open($fh, ">", "$okfile");
+print $fh "good\n";
+close($fh);
--
2.38.1-359-g84c4c6d5a5
next prev parent reply other threads:[~2022-10-25 5:13 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-24 15:00 [PATCH 0/2] Document fsck msg ids John Cai via GitGitGadget
2022-10-24 15:00 ` [PATCH 1/2] fsck: remove the unused BAD_TAG_OBJECT John Cai via GitGitGadget
2022-10-24 16:57 ` Junio C Hamano
2022-10-24 18:16 ` Junio C Hamano
2022-10-24 18:33 ` John Cai
2022-10-24 23:39 ` Jeff King
2022-10-24 15:00 ` [PATCH 2/2] fsck: document msg-id John Cai via GitGitGadget
2022-10-24 17:33 ` Junio C Hamano
2022-10-25 9:41 ` Ævar Arnfjörð Bjarmason
2022-10-25 16:07 ` Junio C Hamano
2022-10-24 18:51 ` [PATCH 0/2] Document fsck msg ids Junio C Hamano
2022-10-25 3:17 ` [PATCH v2 " John Cai via GitGitGadget
2022-10-25 3:17 ` [PATCH v2 1/2] fsck: remove the unused BAD_TAG_OBJECT John Cai via GitGitGadget
2022-10-25 3:17 ` [PATCH v2 2/2] fsck: document msg-id John Cai via GitGitGadget
2022-10-25 4:30 ` [PATCH v2 0/2] Document fsck msg ids Junio C Hamano
2022-10-25 4:40 ` Junio C Hamano
2022-10-25 5:12 ` Junio C Hamano [this message]
2022-10-25 22:42 ` [PATCH v3 0/4] document fsck error message ids Junio C Hamano
2022-10-25 22:42 ` [PATCH v3 1/4] fsck: remove the unused BAD_TAG_OBJECT Junio C Hamano
2022-10-25 22:42 ` [PATCH v3 2/4] fsck: remove the unused MISSING_TREE_OBJECT Junio C Hamano
2022-10-25 22:42 ` [PATCH v3 3/4] fsck: document msg-id Junio C Hamano
2022-10-25 22:42 ` [PATCH v3 4/4] Documentation: add lint-fsck-msgids Junio C Hamano
2022-10-26 2:43 ` Ævar Arnfjörð Bjarmason
2022-10-26 5:34 ` Jeff King
2022-10-26 6:46 ` Junio C Hamano
2022-10-26 11:35 ` Ævar Arnfjörð Bjarmason
2022-10-28 1:23 ` Jeff King
2022-10-28 2:04 ` Ævar Arnfjörð Bjarmason
2022-10-28 5:32 ` Jeff King
2022-10-28 10:41 ` Ævar Arnfjörð Bjarmason
2022-10-28 3:02 ` John Cai
2022-10-28 3:11 ` Ævar Arnfjörð Bjarmason
2022-10-28 5:32 ` Junio C Hamano
2022-10-28 5:37 ` Jeff King
2022-10-28 5:35 ` Jeff King
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=xmqqa65kpju4.fsf_-_@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=johncai86@gmail.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).