From: Toon Claes <toon@iotcl.com>
To: Karthik Nayak <karthik.188@gmail.com>, git@vger.kernel.org
Cc: Karthik Nayak <karthik.188@gmail.com>,
ps@pks.im, Christian Couder <chriscool@tuxfamily.org>
Subject: Re: [PATCH v4 4/8] refs: extract out refname verification in transactions
Date: Thu, 19 Dec 2024 20:29:17 +0100 [thread overview]
Message-ID: <87a5crh3oy.fsf@iotcl.com> (raw)
In-Reply-To: <20241216-320-git-refs-migrate-reflogs-v4-4-d7cd3f197453@gmail.com>
Karthik Nayak <karthik.188@gmail.com> writes:
> Unless the `REF_SKIP_REFNAME_VERIFICATION` flag is set for an update,
> the refname of the update is verified for:
>
> - Ensuring it is not a pseudoref.
> - Checking the refname format.
>
> These checks will also be needed in a following commit where the
> function to add reflog updates to the transaction is introduced. Extract
> the code out into a new static function.
>
> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
> ---
> refs.c | 37 +++++++++++++++++++++++--------------
> 1 file changed, 23 insertions(+), 14 deletions(-)
>
> diff --git a/refs.c b/refs.c
> index f003e51c6bf5229bfbce8ce61ffad7cdba0572e0..9c9f4940c60d3cdd34ce8f1e668d17b9da3cd801 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -1196,6 +1196,28 @@ struct ref_update *ref_transaction_add_update(
> return update;
> }
>
> +static int transaction_refname_valid(const char *refname,
> + const struct object_id *new_oid,
> + unsigned int flags, struct strbuf *err)
> +{
> + if (flags & REF_SKIP_REFNAME_VERIFICATION)
> + return 1;
> +
> + if (is_pseudo_ref(refname)) {
> + strbuf_addf(err, _("refusing to update pseudoref '%s'"),
> + refname);
> + return 0;
With this early return you don't need the `else` below? Why did you add
it?
> + } else if ((new_oid && !is_null_oid(new_oid)) ?
> + check_refname_format(refname, REFNAME_ALLOW_ONELEVEL) :
> + !refname_is_safe(refname)) {
> + strbuf_addf(err, _("refusing to update ref with bad name '%s'"),
> + refname);
> + return 0;
> + }
I see you've swapped order of checking whether it's a pseudoref with
checking whether the format is okay. I think this shouldn't make a big
difference, but it will give a different error message when attempting
to update an illformatted pseudoref. For me it makes more sense how
you've done it now. But because you mention both checks as bullet points
in the commit message, do you think it would make sense to say something
about them being swapped?
--
Toon
next prev parent reply other threads:[~2024-12-19 19:29 UTC|newest]
Thread overview: 93+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-09 11:07 [PATCH 0/7] refs: add reflog support to `git refs migrate` Karthik Nayak
2024-12-09 11:07 ` [PATCH 1/7] refs: include committer info in `ref_update` struct Karthik Nayak
2024-12-10 16:51 ` Christian Couder
2024-12-11 10:13 ` karthik nayak
2024-12-09 11:07 ` [PATCH 2/7] refs: add `index` field to `struct ref_udpate` Karthik Nayak
2024-12-09 11:07 ` [PATCH 3/7] refs/files: add count field to ref_lock Karthik Nayak
2024-12-10 17:22 ` Christian Couder
2024-12-11 10:18 ` karthik nayak
2024-12-11 9:05 ` Christian Couder
2024-12-11 10:26 ` karthik nayak
2024-12-09 11:07 ` [PATCH 4/7] refs: extract out refname verification in transactions Karthik Nayak
2024-12-11 9:26 ` Christian Couder
2024-12-11 10:31 ` karthik nayak
2024-12-11 14:26 ` Patrick Steinhardt
2024-12-09 11:07 ` [PATCH 5/7] refs: introduce the `ref_transaction_update_reflog` function Karthik Nayak
2024-12-11 10:10 ` Christian Couder
2024-12-11 18:06 ` karthik nayak
2024-12-11 14:26 ` Patrick Steinhardt
2024-12-11 18:09 ` karthik nayak
2024-12-09 11:07 ` [PATCH 6/7] refs: allow multiple reflog entries for the same refname Karthik Nayak
2024-12-11 10:44 ` Christian Couder
2024-12-12 14:52 ` karthik nayak
2024-12-11 14:26 ` Patrick Steinhardt
2024-12-12 14:47 ` karthik nayak
2024-12-09 11:07 ` [PATCH 7/7] refs: add support for migrating reflogs Karthik Nayak
2024-12-11 14:26 ` Patrick Steinhardt
2024-12-12 14:04 ` karthik nayak
2024-12-10 12:13 ` [PATCH 0/7] refs: add reflog support to `git refs migrate` Junio C Hamano
2024-12-10 17:42 ` karthik nayak
2024-12-10 18:03 ` karthik nayak
2024-12-13 10:36 ` [PATCH v2 0/8] " Karthik Nayak
2024-12-13 10:36 ` [PATCH v2 1/8] refs: include committer info in `ref_update` struct Karthik Nayak
2024-12-13 10:36 ` [PATCH v2 2/8] refs: add `index` field to `struct ref_udpate` Karthik Nayak
2024-12-13 10:36 ` [PATCH v2 3/8] refs/files: add count field to ref_lock Karthik Nayak
2024-12-13 10:36 ` [PATCH v2 4/8] refs: extract out refname verification in transactions Karthik Nayak
2024-12-13 10:36 ` [PATCH v2 5/8] refs: add `committer_info` to `ref_transaction_add_update()` Karthik Nayak
2024-12-13 12:24 ` Patrick Steinhardt
2024-12-13 19:43 ` karthik nayak
2024-12-19 19:31 ` Toon Claes
2024-12-20 11:31 ` karthik nayak
2024-12-13 10:36 ` [PATCH v2 6/8] refs: introduce the `ref_transaction_update_reflog` function Karthik Nayak
2024-12-13 11:44 ` Christian Couder
2024-12-13 19:49 ` karthik nayak
2024-12-13 12:24 ` Patrick Steinhardt
2024-12-13 10:36 ` [PATCH v2 7/8] refs: allow multiple reflog entries for the same refname Karthik Nayak
2024-12-13 12:24 ` Patrick Steinhardt
2024-12-13 20:02 ` karthik nayak
2024-12-13 10:36 ` [PATCH v2 8/8] refs: add support for migrating reflogs Karthik Nayak
2024-12-13 12:24 ` Patrick Steinhardt
2024-12-15 11:09 ` karthik nayak
2024-12-15 16:25 ` [PATCH v3 0/8] refs: add reflog support to `git refs migrate` Karthik Nayak
2024-12-15 16:25 ` [PATCH v3 1/8] refs: include committer info in `ref_update` struct Karthik Nayak
2024-12-15 16:25 ` [PATCH v3 2/8] refs: add `index` field to `struct ref_udpate` Karthik Nayak
2024-12-15 16:25 ` [PATCH v3 3/8] refs/files: add count field to ref_lock Karthik Nayak
2024-12-15 16:25 ` [PATCH v3 4/8] refs: extract out refname verification in transactions Karthik Nayak
2024-12-15 16:25 ` [PATCH v3 5/8] refs: add `committer_info` to `ref_transaction_add_update()` Karthik Nayak
2024-12-15 16:25 ` [PATCH v3 6/8] refs: introduce the `ref_transaction_update_reflog` function Karthik Nayak
2024-12-15 16:25 ` [PATCH v3 7/8] refs: allow multiple reflog entries for the same refname Karthik Nayak
2024-12-15 16:25 ` [PATCH v3 8/8] refs: add support for migrating reflogs Karthik Nayak
2024-12-16 7:25 ` Patrick Steinhardt
2024-12-16 15:50 ` Junio C Hamano
2024-12-16 15:59 ` karthik nayak
2024-12-15 23:54 ` [PATCH v3 0/8] refs: add reflog support to `git refs migrate` Junio C Hamano
2024-12-16 14:33 ` karthik nayak
2024-12-16 16:32 ` Junio C Hamano
2024-12-16 16:44 ` [PATCH v4 " Karthik Nayak
2024-12-16 16:44 ` [PATCH v4 1/8] refs: include committer info in `ref_update` struct Karthik Nayak
2024-12-16 16:44 ` [PATCH v4 2/8] refs: add `index` field to `struct ref_udpate` Karthik Nayak
2024-12-19 19:28 ` Toon Claes
2024-12-20 10:09 ` karthik nayak
2024-12-16 16:44 ` [PATCH v4 3/8] refs/files: add count field to ref_lock Karthik Nayak
2024-12-16 16:44 ` [PATCH v4 4/8] refs: extract out refname verification in transactions Karthik Nayak
2024-12-19 19:29 ` Toon Claes [this message]
2024-12-20 10:30 ` karthik nayak
2024-12-16 16:44 ` [PATCH v4 5/8] refs: add `committer_info` to `ref_transaction_add_update()` Karthik Nayak
2024-12-19 19:30 ` Toon Claes
2024-12-20 10:44 ` karthik nayak
2024-12-16 16:44 ` [PATCH v4 6/8] refs: introduce the `ref_transaction_update_reflog` function Karthik Nayak
2024-12-19 19:32 ` Toon Claes
2024-12-19 20:25 ` Junio C Hamano
2024-12-20 10:55 ` karthik nayak
2024-12-20 12:58 ` [PATCH] refs: mark invalid refname message for translation Karthik Nayak
2024-12-20 15:53 ` Junio C Hamano
2024-12-24 10:34 ` Toon Claes
2024-12-16 16:44 ` [PATCH v4 7/8] refs: allow multiple reflog entries for the same refname Karthik Nayak
2024-12-19 19:33 ` Toon Claes
2024-12-20 11:15 ` karthik nayak
2024-12-16 16:44 ` [PATCH v4 8/8] refs: add support for migrating reflogs Karthik Nayak
2024-12-17 6:59 ` [PATCH v4 0/8] refs: add reflog support to `git refs migrate` Patrick Steinhardt
2024-12-17 9:35 ` karthik nayak
2024-12-17 21:28 ` Junio C Hamano
2024-12-19 19:32 ` Toon Claes
2024-12-20 11:23 ` karthik nayak
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=87a5crh3oy.fsf@iotcl.com \
--to=toon@iotcl.com \
--cc=chriscool@tuxfamily.org \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
--cc=ps@pks.im \
/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).