git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Robin Jarry <robin@jarry.cc>
Cc: git@vger.kernel.org, "Phillip Wood" <phillip.wood123@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Tim Culverhouse" <tim@timculverhouse.com>,
	"Nicolas Dichtel" <nicolas.dichtel@6wind.com>,
	"Bagas Sanjaya" <bagasdotme@gmail.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Michael Strawbridge" <michael.strawbridge@amd.com>
Subject: Re: [PATCH v2] send-email: export patch counters in validate environment
Date: Wed, 12 Apr 2023 10:53:31 -0700	[thread overview]
Message-ID: <xmqqfs957zs4.fsf@gitster.g> (raw)
In-Reply-To: <20230412095434.140754-1-robin@jarry.cc> (Robin Jarry's message of "Wed, 12 Apr 2023 11:54:34 +0200")

Robin Jarry <robin@jarry.cc> writes:

>  if ($validate) {
> +	# FIFOs can only be read once, exclude them from validation.

It is very good to see this comment here, as it may not be obvious
to everybody why we exclude them.

> +validate_cover_letter()
> +{

See Documentation/CodingGuidelines, look for "For shell scripts
specifically" and follow what is in the section.  There may be style
violations of other kinds in the file.

> +validate_patch()
> +{
> +	file="$1"
> +	# Ensure that the patch applies without conflicts to the latest
> +	# upstream version.

That comment is true only for the first one.  The second patch needs
to apply to the upstream plus the first patch, and so on.

> +	git am -3 "$file" || die "failed to apply patch on upstream repo"
> +	# XXX: Add appropriate checks here (e.g. checkpatch.pl).
> +}
> +
> +validate_series()
> +{
> +	# XXX: Add appropriate checks here (e.g. quick build, etc.).
> +}
> +
> +die()
> +{
> +	echo "sendemail-validate: error: $*" >&2
> +	exit 1
> +}
> +
> +get_work_dir()
> +{
> +	git config --get sendemail.validateWorkdir || {
> +		# Initialize it to a temp dir, if unset.
> +		git config --add sendemail.validateWorkdir "$(mktemp -d)"
> +		git config --get sendemail.validateWorkdir
> +	}
> +}
> +
> +get_upstream_url()
> +{
> +	git config --get remote.origin.url ||
> +		die "cannot get remote.origin.url"
> +}
> +
> +clone_upstream()
> +{
> +	workdir="$1"
> +	url="$(get_upstream_url)"
> +	rm -rf -- "$workdir"
> +	git clone --depth=1 "$url" "$workdir" ||
> +		die "failed to clone upstream repository"
> +}

Style-wise, it is better to get rid of get_upstream_url and write
the above more like

	workdir=$1 &&
	url=$(git config remote.originurl) &&
	rm -r -- "$workdir" &&
	git clone ... ||
	die "failed to ..."

and that would be less error prone (e.g. you will catch failure from
"rm" yourself, instead of relying on "git clone" to catch it for
you).

In any case, I would avoid network traffic and extra disk usage if I
were showing an example for readers to follow, and would not
recommend you to use "clone" here, even if it were a shallow one.

It would make much more sense to create a secondary worktree based
on this repository, with its HEAD detached at the copy of the target
branch (e.g. refs/remotes/origin/HEAD), and use that secondary
worktree, as the necessary objects for "am -3" to fall back on are
more likely to be found in such a setting, compared to a shallow
clone that only can have the blobs at the tip.

> +
> +# main -------------------------------------------------------------------------

> +workdir=$(get_work_dir)
> +if [ "$GIT_SENDEMAIL_FILE_COUNTER" = 1 ]; then
> +	clone_upstream "$workdir"
> +fi
> +cd "$workdir"
> +export GIT_DIR="$workdir/.git"

It is a good discipline to always set GIT_DIR and GIT_WORK_TREE as a
pair.  Working in a subdirectory of a working tree becomes awkward,
because the presence of the former without the latter signals that
your $(cwd) is at the top of the working tree.

But that is more or less moot, because I am suggesting not to use
"git clone" to prepare the playground and instead use a secondary
worktree that is attached to the same current repository, so GIT_DIR
would be the same as the current one.

And because you are "cd"ing there anyway, it probably is much
simpler to just 

    unset GIT_DIR GIT_WORK_TREE

to let the repository discovery mechanism take care of it.

> +if grep -q "^diff --git " "$1"; then
> +	validate_patch "$1"
> +else
> +	validate_cover_letter "$1"
> +fi
> +
> +if [ "$GIT_SENDEMAIL_FILE_COUNTER" = "$GIT_SENDEMAIL_FILE_TOTAL" ]; then
> +	validate_series || die "patch series was rejected"
> +fi

It is uneven that validate_patch and validate_cover_letter are
responsible for dying when problem is found, but validate_series is
not and the caller is made responsible for that.

I would make the caller responsible for dying with message for all
three by removing the calls to "die" or "exit" from the former two,
if I were showing an example for readers to follow.

Overall, a very well crafted patch, even though little details and
some design choices can be improved.

Thanks.


  reply	other threads:[~2023-04-12 17:53 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-11 11:47 [PATCH] send-email: export patch counters in validate environment Robin Jarry
2023-04-11 13:23 ` Phillip Wood
2023-04-11 16:28   ` Junio C Hamano
2023-04-11 17:13     ` Robin Jarry
2023-04-11 19:14       ` Junio C Hamano
2023-04-11 16:47   ` Robin Jarry
2023-04-12  9:54 ` [PATCH v2] " Robin Jarry
2023-04-12 17:53   ` Junio C Hamano [this message]
2023-04-12 18:33     ` Robin Jarry
2023-04-12 20:37       ` Junio C Hamano
2023-04-12 20:39         ` Robin Jarry
2023-04-12 21:48     ` Junio C Hamano
2023-04-12 21:45   ` [PATCH v3] " Robin Jarry
2023-04-13 13:52     ` Phillip Wood
2023-04-13 14:01       ` Robin Jarry
2023-04-14 12:58         ` Phillip Wood
2023-04-14 15:28     ` [PATCH v4] " Robin Jarry
2023-04-14 15:50       ` Robin Jarry
2023-04-14 15:52       ` [PATCH v5] " Robin Jarry
2023-04-20 19:16         ` Robin Jarry
2023-04-20 19:25           ` Junio C Hamano

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=xmqqfs957zs4.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=bagasdotme@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=michael.strawbridge@amd.com \
    --cc=nicolas.dichtel@6wind.com \
    --cc=phillip.wood123@gmail.com \
    --cc=robin@jarry.cc \
    --cc=sunshine@sunshineco.com \
    --cc=tim@timculverhouse.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.
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 NNTP newsgroup(s).