git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Karthik Nayak <karthik.188@gmail.com>, git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 2/5] refs: make `is_pseudoref_syntax()` stricter
Date: Mon, 22 Jan 2024 20:13:22 +0000	[thread overview]
Message-ID: <ee977173-bc6d-48f6-9bc8-e1d84fe3d95d@gmail.com> (raw)
In-Reply-To: <20240119142705.139374-3-karthik.188@gmail.com>

Hi Karthik

On 19/01/2024 14:27, Karthik Nayak wrote:
> The `is_pseudoref_syntax()` function is used to determine if a
> particular refname follows the pseudoref syntax. The pseudoref syntax is
> loosely defined at this instance as all refs which are in caps and use
> underscores. Most of the pseudorefs also have the "HEAD" suffix.
> 
> Using this information we make the `is_pseudoref_syntax()` function
> stricter, by adding the check for "HEAD" suffix and for refs which don't
> end with the HEAD suffix, matching them with a predetermined list.
> 
> This requires fixing up t1407 to use the "HEAD" suffix for creation of
> pseudorefs.

I'm concerned that this change is a regression. is_pseudoref_syntax() is 
used by is_current_worktree_ref() and so scripts that create pseudorefs 
that do not conform to your new rules will break as git will no-longer 
consider the pseudorefs they create to be worktree specific. The list of 
hard coded exceptions also looks quite short, I can see MERGE_AUTOSTASH 
and BISECT_START are missing and there are probably others I've not 
thought of.

The commit message would be a good place to discuss why you're making 
this change, the implications of the change and any alternative 
approaches that you considered. As I understand it you're tying to get 
round the problem that the files backend stores pseudorefs mixed up with 
other non-ref files in $GIT_DIR. Another approach would be to read all 
the files whose name matches the pseudoref syntax and see if its 
contents looks like a valid ref skipping names like COMMIT_EDITMSG that 
we know are not pseudorefs.

Best Wishes

Phillip

> Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
> ---
>   refs.c                        | 21 ++++++++++++++++++---
>   t/t1407-worktree-ref-store.sh | 12 ++++++------
>   2 files changed, 24 insertions(+), 9 deletions(-)
> 
> diff --git a/refs.c b/refs.c
> index 5999605230..b84e173762 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -829,6 +829,14 @@ int is_per_worktree_ref(const char *refname)
>   
>   int is_pseudoref_syntax(const char *refname)
>   {
> +	/* TODO: move these pseudorefs to have _HEAD suffix */
> +	static const char *const irregular_pseudorefs[] = {
> +		"BISECT_EXPECTED_REV",
> +		"NOTES_MERGE_PARTIAL",
> +		"NOTES_MERGE_REF",
> +		"AUTO_MERGE"
> +	};
> +	size_t i;
>   	const char *c;
>   
>   	for (c = refname; *c; c++) {
> @@ -837,10 +845,17 @@ int is_pseudoref_syntax(const char *refname)
>   	}
>   
>   	/*
> -	 * HEAD is not a pseudoref, but it certainly uses the
> -	 * pseudoref syntax.
> +	 * Most pseudorefs end with _HEAD. HEAD itself is not a
> +	 * pseudoref, but it certainly uses the pseudoref syntax.
>   	 */
> -	return 1;
> +	if (ends_with(refname, "HEAD"))
> +		return 1;
> +
> +	for (i = 0; i < ARRAY_SIZE(irregular_pseudorefs); i++)
> +		if (!strcmp(refname, irregular_pseudorefs[i]))
> +			return 1;
> +
> +	return 0;
>   }
>   
>   static int is_current_worktree_ref(const char *ref) {
> diff --git a/t/t1407-worktree-ref-store.sh b/t/t1407-worktree-ref-store.sh
> index 05b1881c59..53592c95f3 100755
> --- a/t/t1407-worktree-ref-store.sh
> +++ b/t/t1407-worktree-ref-store.sh
> @@ -61,18 +61,18 @@ test_expect_success 'create_symref(FOO, refs/heads/main)' '
>   # PSEUDO-WT and refs/bisect/random do not create reflogs by default, so it is
>   # not testing a realistic scenario.
>   test_expect_success REFFILES 'for_each_reflog()' '
> -	echo $ZERO_OID > .git/logs/PSEUDO-MAIN &&
> +	echo $ZERO_OID >.git/logs/PSEUDO_MAIN_HEAD &&
>   	mkdir -p     .git/logs/refs/bisect &&
> -	echo $ZERO_OID > .git/logs/refs/bisect/random &&
> +	echo $ZERO_OID >.git/logs/refs/bisect/random &&
>   
> -	echo $ZERO_OID > .git/worktrees/wt/logs/PSEUDO-WT &&
> +	echo $ZERO_OID >.git/worktrees/wt/logs/PSEUDO_WT_HEAD &&
>   	mkdir -p     .git/worktrees/wt/logs/refs/bisect &&
> -	echo $ZERO_OID > .git/worktrees/wt/logs/refs/bisect/wt-random &&
> +	echo $ZERO_OID >.git/worktrees/wt/logs/refs/bisect/wt-random &&
>   
>   	$RWT for-each-reflog | cut -d" " -f 2- | sort >actual &&
>   	cat >expected <<-\EOF &&
>   	HEAD 0x1
> -	PSEUDO-WT 0x0
> +	PSEUDO_WT_HEAD 0x0
>   	refs/bisect/wt-random 0x0
>   	refs/heads/main 0x0
>   	refs/heads/wt-main 0x0
> @@ -82,7 +82,7 @@ test_expect_success REFFILES 'for_each_reflog()' '
>   	$RMAIN for-each-reflog | cut -d" " -f 2- | sort >actual &&
>   	cat >expected <<-\EOF &&
>   	HEAD 0x1
> -	PSEUDO-MAIN 0x0
> +	PSEUDO_MAIN_HEAD 0x0
>   	refs/bisect/random 0x0
>   	refs/heads/main 0x0
>   	refs/heads/wt-main 0x0

  parent reply	other threads:[~2024-01-22 20:13 UTC|newest]

Thread overview: 96+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-19 14:27 [PATCH 0/5] for-each-ref: print all refs on empty string pattern Karthik Nayak
2024-01-19 14:27 ` [PATCH 1/5] refs: expose `is_pseudoref_syntax()` Karthik Nayak
2024-01-19 20:37   ` Junio C Hamano
2024-01-22 15:40     ` Karthik Nayak
2024-01-19 14:27 ` [PATCH 2/5] refs: make `is_pseudoref_syntax()` stricter Karthik Nayak
2024-01-19 20:44   ` Junio C Hamano
2024-01-22 20:13   ` Phillip Wood [this message]
2024-01-22 20:22     ` Junio C Hamano
2024-01-23 11:03       ` Phillip Wood
2024-01-23 12:49         ` Karthik Nayak
2024-01-23 16:40           ` phillip.wood123
2024-01-23 17:46           ` Junio C Hamano
2024-01-23 17:38         ` Junio C Hamano
2024-01-23 11:16       ` Patrick Steinhardt
2024-01-23 16:30         ` Phillip Wood
2024-01-23 17:44         ` Junio C Hamano
2024-01-24  8:51           ` Patrick Steinhardt
2024-01-19 14:27 ` [PATCH 3/5] refs: extract out `loose_fill_ref_dir_regular_file()` Karthik Nayak
2024-01-19 14:27 ` [PATCH 4/5] refs: introduce `refs_for_each_all_refs()` Karthik Nayak
2024-01-19 20:57   ` Junio C Hamano
2024-01-22 15:48     ` Karthik Nayak
2024-01-22 17:45       ` Junio C Hamano
2024-01-19 14:27 ` [PATCH 5/5] for-each-ref: avoid filtering on empty pattern Karthik Nayak
2024-01-24 15:27 ` [PATCH v2 0/4] for-each-ref: print all refs on empty string pattern Karthik Nayak
2024-01-24 15:27   ` [PATCH v2 1/4] refs: introduce `is_pseudoref()` and `is_headref()` Karthik Nayak
2024-01-24 19:09     ` Junio C Hamano
2024-01-25 16:20       ` Karthik Nayak
2024-01-25 16:28         ` Junio C Hamano
2024-01-25 21:48           ` Karthik Nayak
2024-01-24 15:27   ` [PATCH v2 2/4] refs: extract out `loose_fill_ref_dir_regular_file()` Karthik Nayak
2024-01-24 15:27   ` [PATCH v2 3/4] refs: introduce `refs_for_each_all_refs()` Karthik Nayak
2024-01-24 15:27   ` [PATCH v2 4/4] for-each-ref: avoid filtering on empty pattern Karthik Nayak
2024-01-29 11:35 ` [PATCH v3 0/4] for-each-ref: print all refs on empty string pattern Karthik Nayak
2024-01-29 11:35   ` [PATCH v3 1/4] refs: introduce `is_pseudoref()` and `is_headref()` Karthik Nayak
2024-02-07  1:48     ` Jeff King
2024-02-07  9:27       ` Karthik Nayak
2024-01-29 11:35   ` [PATCH v3 2/4] refs: extract out `loose_fill_ref_dir_regular_file()` Karthik Nayak
2024-01-29 11:35   ` [PATCH v3 3/4] refs: introduce `refs_for_each_all_refs()` Karthik Nayak
2024-01-29 11:35   ` [PATCH v3 4/4] for-each-ref: avoid filtering on empty pattern Karthik Nayak
2024-02-05 18:48     ` Phillip Wood
2024-02-06  5:33       ` Patrick Steinhardt
2024-02-06 10:49         ` Phillip Wood
2024-02-06  8:52       ` Karthik Nayak
2024-02-06 13:55         ` Phillip Wood
2024-02-06 15:30           ` Karthik Nayak
2024-02-06 17:03           ` Junio C Hamano
2024-02-06 18:47             ` Junio C Hamano
2024-02-06 22:10               ` Karthik Nayak
2024-02-06 22:16                 ` Junio C Hamano
2024-02-07 14:10                   ` Karthik Nayak
2024-02-07 16:00                     ` Junio C Hamano
2024-02-07 16:18                       ` Karthik Nayak
2024-02-07 16:46                         ` Junio C Hamano
2024-02-07 17:02                           ` Karthik Nayak
2024-02-08  8:50                             ` Patrick Steinhardt
2024-02-08 17:04                               ` Junio C Hamano
2024-02-08 17:24                                 ` Patrick Steinhardt
2024-02-08 17:53                                   ` Junio C Hamano
2024-02-09  8:08                                     ` Patrick Steinhardt
2024-02-09 17:15                                       ` Junio C Hamano
2024-02-09 18:27                                         ` Karthik Nayak
2024-02-12  6:51                                           ` Patrick Steinhardt
2024-02-08 10:28                   ` Phillip Wood
2024-02-08 17:07                     ` Junio C Hamano
2024-02-07  7:48                 ` Patrick Steinhardt
2024-02-07 16:01                   ` Junio C Hamano
2024-01-29 20:37   ` [PATCH v3 0/4] for-each-ref: print all refs on empty string pattern Junio C Hamano
2024-02-11 18:39 ` [PATCH v4 0/5] for-each-ref: add '--include-root-refs' option Karthik Nayak
2024-02-11 18:39   ` [PATCH v4 1/5] refs: introduce `is_pseudoref()` and `is_headref()` Karthik Nayak
2024-02-12 12:47     ` Patrick Steinhardt
2024-02-12 17:01       ` Junio C Hamano
2024-02-13 15:48       ` Karthik Nayak
2024-02-13 19:42       ` Junio C Hamano
2024-02-14 10:28         ` Karthik Nayak
2024-02-14 16:59           ` Junio C Hamano
2024-02-14 18:15             ` Karthik Nayak
2024-02-12 18:05     ` Junio C Hamano
2024-02-11 18:39   ` [PATCH v4 2/5] refs: extract out `loose_fill_ref_dir_regular_file()` Karthik Nayak
2024-02-11 18:39   ` [PATCH v4 3/5] refs: introduce `refs_for_each_include_root_refs()` Karthik Nayak
2024-02-11 18:39   ` [PATCH v4 4/5] ref-filter: rename 'FILTER_REFS_ALL' to 'FILTER_REFS_REGULAR' Karthik Nayak
2024-02-11 18:39   ` [PATCH v4 5/5] for-each-ref: add new option to include root refs Karthik Nayak
2024-02-22  8:46     ` Patrick Steinhardt
2024-02-22 12:57       ` Karthik Nayak
2024-02-22 13:17         ` Patrick Steinhardt
2024-02-23 10:01 ` [PATCH v5 0/5] for-each-ref: add '--include-root-refs' option Karthik Nayak
2024-02-23 10:01   ` [PATCH v5 1/5] refs: introduce `is_pseudoref()` and `is_headref()` Karthik Nayak
2024-02-23 10:01   ` [PATCH v5 2/5] refs: extract out `loose_fill_ref_dir_regular_file()` Karthik Nayak
2024-02-23 10:01   ` [PATCH v5 3/5] refs: introduce `refs_for_each_include_root_refs()` Karthik Nayak
2024-02-23 10:01   ` [PATCH v5 4/5] ref-filter: rename 'FILTER_REFS_ALL' to 'FILTER_REFS_REGULAR' Karthik Nayak
2024-02-23 10:01   ` [PATCH v5 5/5] for-each-ref: add new option to include root refs Karthik Nayak
2024-02-23 18:41   ` [PATCH v5 0/5] for-each-ref: add '--include-root-refs' option Junio C Hamano
2024-02-23 20:13     ` Junio C Hamano
2024-02-27  7:39   ` Patrick Steinhardt
2024-02-27 16:54     ` Junio C Hamano
  -- strict thread matches above, loose matches on Subject: below --
2024-03-15 10:05 [PATCH 2/5] refs: make `is_pseudoref_syntax()` stricter eugenio gigante
2024-03-21 13:09 ` Patrick Steinhardt

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=ee977173-bc6d-48f6-9bc8-e1d84fe3d95d@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=karthik.188@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    /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).