Git development
 help / color / mirror / Atom feed
From: Tuomas Ahola <taahol@utu.fi>
To: Junio C Hamano <gitster@pobox.com>
Cc: <git@vger.kernel.org>, Julia Evans <julia@jvns.ca>
Subject: Re: [PATCH v4 2/2] lint-docs: ensure command-list.txt lists all guides
Date: Fri, 27 Nov 2026 19:42:23 +0200	[thread overview]
Message-ID: <20261127174223.Yr6v-%taahol@utu.fi> (raw)
In-Reply-To: <xmqqy0aecnyd.fsf@gitster.g>

Junio C Hamano <gitster@pobox.com> wrote:

> Tuomas Ahola <taahol@utu.fi> writes:
> 
> > diff --git a/Documentation/lint-manpages.sh b/Documentation/lint-manpages.sh
> > index a0ea572382..87a652bd22 100755
> > --- a/Documentation/lint-manpages.sh
> > +++ b/Documentation/lint-manpages.sh
> > @@ -1,21 +1,27 @@
> >  #!/bin/sh
> >  
> >  extract_variable () {
> > -	(
> > -		cat ../Makefile
> > -		cat <<EOF
> > +	file="$1"
> > +	directory="$(dirname "$file")"
> > +	shift
> 
> The first argument to the function becomes $file and then is used to
> compute $directory; and we shift it out and loop over the remaining
> arguments.
> 

Yep.

> > +	for i in "$@"
> > +	do
> > +		(
> > +			cat "$file"
> > +			cat <<EOF
> >  print_variable:
> >  	@\$(foreach b,\$($1),echo XXX \$(b:\$X=) YYY;)
> >  EOF
> 
> The fact that this patch does not touch these three lines gives a strong
> smell, especially the reference to "$1", which was part of a single
> addition to the target Makefile to ask what value an arbitrary single
> variable has, dating back to 2dd100c513 (Makefile: extract script to
> lint missing/extraneous manpages, 2024-06-06).  Now that you are looping
> over a list of variable names in "$@" using "for i in ...", shouldn't it
> refer to "$i" instead?
> 

Yes, I already noticed that blunder (cf. <20261127103346.vPrBT%taahol@utu.fi>)

> Because 'for i in "$@"' does not alter the positional parameters, "$1"
> inside the heredoc stays bound to the first variable name on every
> iteration.  When the script later runs
> 
>     MAN_GUIDES="$(extract_variable Makefile MAN5_TXT MAN7_TXT |
>                   sed -e 's/\.adoc//')"
> 
> extract_variable() invokes make twice with $(MAN5_TXT) both times
> and never evaluates $(MAN7_TXT).  None of the section 7 guides
> (including gitpacking and gittutorial-2) are ever visited by
> check_missing_docs() because of this, I suspect.  Have you tried
> introducing discrepancies to section 7 entries and seeing if your
> version detects them?
> 

I did all that when I first wrote that reroll.  However, my draft used 'shift'
in the loop which looked a bit funny when I revisited the patch and sent it
out.  Obviously I should have replaced $i with $i when I dropped that shift.

> Even better, instead of running make multiple times, use something like
> this (warning: totally untested)
> 
>     vars="$*"
>     (
>             cat "$file"
>             sed -e "s/^|//" <<-EOF
>             |print_variable:
>             |	@\$(foreach b,\$(foreach v,$vars,\$(\$(v))),echo XXX \$(b:\$X=) YYY;)
>     EOF
>     ) |
>     make -C "$directory" -f - print_variable 2>/dev/null |
>     sed -n -e 's/.*XXX \(.*\) YYY.*/\1/p
> 
> perhaps?
> 

Hmm, I think I decided against something like that but perhaps I should
reconsider that option.

> Unlike "make -f -" that feeds the top-level Makefile,
> Documentation/Makefile has a conditional include of "doc.dep" unless we
> are running "make clean".  And doc.dep has a rule that depends on
> $(docdep_prereqs), which includes cmd-list.made.
> 
> Does that mean running lint-manpages.sh in a clean tree causes us to
> build doc.dep while it attempts to extract MAN5_TXT and MAN7_TXT and/or
> fails the build altogether (we cannot see, due to "2>/dev/null" in the
> above script, the error message)?  Have you tried?
> 

Good point.  That indeed seems to be the case.

> It might be less error-prone than the above gymnastics to add a new
> print-guides target to Documentation/Makefile, next to where it defines
> the print-man1 target, imitating how the print-man1 target does its
> thing.
> 
> > -	) |
> > -	make -C .. -f - print_variable 2>/dev/null |
> > -	sed -n -e 's/.*XXX \(.*\) YYY.*/\1/p'
> > +		) |
> > +		make -C "$directory" -f - print_variable 2>/dev/null |
> > +		sed -n -e 's/.*XXX \(.*\) YYY.*/\1/p'
> > +	done
> >  }
> >  
> >  check_missing_docs () (
> >  	ret=0
> >  
> > -	for v in $ALL_COMMANDS
> > +	for v in $ALL_COMMANDS $MAN_GUIDES
> >  	do
> >  		case "$v" in
> >  		git-merge-octopus) continue;;
> > @@ -29,6 +35,8 @@ check_missing_docs () (
> >  		git-stage) continue;;
> >  		git-legacy-*) continue;;
> >  		git-?*--?* ) continue ;;
> > +		gittutorial-2) continue ;;
> > +		gitweb.conf) continue ;;
> >  		esac
> 
> Placing gittutorial-2 and gitweb.conf in the top case statement
> skips the "test -f $v.adoc" check as well as the command-list.txt
> lookup.
> 
> Moving those two arms down into the inner 'case "$v" in git) ...'
> block would exempt them from command-list.txt while still catching a
> stale entry in MAN5_TXT or MAN7_TXT whose '.adoc' file disappeared.
> I do not know which is more appropriate for these two entries.
> 

On the other hand, having such stale entries still makes 'make check-docs'
barf:

$ rm Documentation/gittutorial-2.adoc && make check-docs
make -C Documentation lint-docs
make[1]: Entering directory '.../git-docs/Documentation'
make[1]: *** No rule to make target 'gittutorial-2.adoc', needed by '.build/lint-docs/man-section-order/gittutorial-2.ok'.  Stop.
make[1]: Leaving directory '.../git-docs/Documentation'
make: *** [Makefile:3984: check-docs] Error 2

Hmm...

> >  
> >  		if ! test -f "$v.adoc"
> > @@ -84,9 +92,10 @@ check_extraneous_docs () {
> >  	)
> >  }
> >  
> > -BUILT_INS="$(extract_variable BUILT_INS)"
> > -ALL_COMMANDS="$(extract_variable ALL_COMMANDS)"
> > -EXCLUDED_PROGRAMS="$(extract_variable EXCLUDED_PROGRAMS)"
> > +BUILT_INS="$(extract_variable ../Makefile BUILT_INS)"
> > +ALL_COMMANDS="$(extract_variable ../Makefile ALL_COMMANDS)"
> > +EXCLUDED_PROGRAMS="$(extract_variable ../Makefile EXCLUDED_PROGRAMS)"
> 
> Note that all three above read variables from somebody else; running
> an extra "make" process might be warranted.  But ...
> 
> > +MAN_GUIDES="$(extract_variable Makefile MAN5_TXT MAN7_TXT | sed -e 's/\.adoc//')"
> 
> ... here, you are asking for the values of variables that are defined in
> *this* Makefile.  Why can't you inspect $(MAN5_TXT) and $(MAN7_TXT)
> yourself, e.g.,
> 
> 	MAN_GUIDES=$(patsubst %.adoc,%,$(MAN5_TXT) $(MAN7_TXT))
> 
> or something?

Huh?  I'm not sure what you mean by "this" Makefile (this is a shell script,
isn't it?)

Oh, I think I got it.  Indeed, perhaps we can invoke the script within the
Makefile with the guides fed in as command-line parameters:

diff --git a/Documentation/Makefile b/Documentation/Makefile
index b574ca2044..0ef57503a9 100644
--- a/Documentation/Makefile
+++ b/Documentation/Makefile
@@ -532,8 +532,8 @@ $(LINT_DOCS_DOC_STYLE): .build/lint-docs/doc-style/%.ok: %.adoc
 .PHONY: lint-docs-doc-style
 lint-docs-doc-style: $(LINT_DOCS_DOC_STYLE)
 
-lint-docs-manpages:
-	$(QUIET_GEN)./lint-manpages.sh
+lint-docs-manpages: $(MAN5_TXT) $(MAN7_TXT)
+	$(QUIET_GEN)./lint-manpages.sh $(patsubst %.adoc,%,$(MAN5_TXT) $(MAN7_TXT))
 
 .PHONY: lint-docs-meson
 lint-docs-meson:

I quite like that approach.  So, let's make it our plan for v5(?)

> 
> It might mean that almost all the things I discussed in this review,
> including all the changes to the extract_variable() procedure or the
> addition of the print-guides target, were unnecessary.  It is great
> if we have to worry about fewer things going wrong ;-).
> 
> Thanks.

Thanks!

  reply	other threads:[~2026-11-27 17:42 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09  5:24 [PATCH 0/2] guides: keep Documentation/Makefile and command-list.txt in sync Tuomas Ahola
2026-09-09  5:25 ` [PATCH 1/2] command-list: add gitformat-loose(5) and gitpacking(7) Tuomas Ahola
2026-09-09 18:15   ` Junio C Hamano
2026-09-09  5:25 ` [PATCH 2/2] lint-docs: check the guide list in command-list.txt Tuomas Ahola
2026-09-09 18:15   ` Junio C Hamano
2026-09-10 19:43 ` [PATCH v2 0/2] guides: keep Documentation/Makefile and command-list.txt in sync Tuomas Ahola
2026-09-10 19:43   ` [PATCH v2 1/2] command-list.txt: add gitformat-loose(5) and gitpacking(7) Tuomas Ahola
2026-09-10 19:43   ` [PATCH v2 2/2] lint-docs: check the guide list in command-list.txt Tuomas Ahola
2026-10-29 18:48 ` [PATCH v3 0/2] guides: keep Documentation/Makefile and command-list.txt in sync Tuomas Ahola
2026-10-29 18:48   ` [PATCH v3 1/2] command-list.txt: add gitformat-loose(5) and gitpacking(7) Tuomas Ahola
2026-11-05 19:32     ` Junio C Hamano
2026-11-11 21:57       ` Tuomas Ahola
2026-10-29 18:48   ` [PATCH v3 2/2] lint-docs: check the guide list in command-list.txt Tuomas Ahola
2026-11-02 18:39     ` Julia Evans
2026-11-03 17:09       ` Tuomas Ahola
2026-11-05 19:41     ` Junio C Hamano
2026-11-11 22:00       ` Tuomas Ahola
2026-11-26 20:11 ` [PATCH v4 0/2] guides: keep Documentation/Makefile and command-list.txt in sync Tuomas Ahola
2026-11-26 20:11   ` [PATCH v4 1/2] command-list.txt: add gitformat-loose(5) and gitpacking(7) Tuomas Ahola
2026-11-27 14:17     ` Junio C Hamano
2026-11-27 21:02       ` Kristoffer Haugsbakk
2026-11-27 22:14         ` Junio C Hamano
2026-11-26 20:11   ` [PATCH v4 2/2] lint-docs: ensure command-list.txt lists all guides Tuomas Ahola
2026-11-27 10:33     ` Tuomas Ahola
2026-11-27 15:07     ` Junio C Hamano
2026-11-27 17:42       ` Tuomas Ahola [this message]
2026-11-27 19:13         ` Junio C Hamano
2026-11-30 16:22 ` [PATCH v5 0/2] guides: keep Documentation/Makefile and command-list.txt in sync Tuomas Ahola
2026-11-30 16:22   ` [PATCH v5 1/2] command-list.txt: add gitformat-loose(5) and gitpacking(7) Tuomas Ahola
2026-11-30 16:22   ` [PATCH v5 2/2] lint-docs: ensure command-list.txt lists all guides Tuomas Ahola

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127174223.Yr6v-%taahol@utu.fi \
    --to=taahol@utu.fi \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=julia@jvns.ca \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox