diff mbox series

[2/2] Make HEAD a PSEUDOREF rather than PER_WORKTREE.

Message ID 470821dc6d4b72c6414b3458883277ad36952892.1594056572.git.gitgitgadget@gmail.com (mailing list archive)
State New, archived
Headers show
Series Remove special casing for PSEUDOREF updates | expand

Commit Message

Derrick Stolee via GitGitGadget July 6, 2020, 5:29 p.m. UTC
From: Han-Wen Nienhuys <hanwen@google.com>

This is consistent with the definition of REF_TYPE_PSEUDOREF
(uppercase in the root ref namespace).

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
---
 refs.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Junio C Hamano July 6, 2020, 8:30 p.m. UTC | #1
"Han-Wen Nienhuys via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Han-Wen Nienhuys <hanwen@google.com>
>
> This is consistent with the definition of REF_TYPE_PSEUDOREF
> (uppercase in the root ref namespace).

I wonder if some special casing we saw for "HEAD" in 1/2 (e.g. we no
longer do this to pseudorefs in this codepath but HEAD is different
and will continue to be dealt with in the codepath) needs adjustment
after this change?  HEAD still needs to be able to have a different
value (either detached or pointing to another ref) per worktree, but
it is unclear where that knowledge now resides in the new code.  Are
we declaring that all pseudorefs are per worktree (which I think is
not wrong)?

> Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
> ---
>  refs.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/refs.c b/refs.c
> index a2fd42364f..265767a234 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -676,10 +676,9 @@ int dwim_log(const char *str, int len, struct object_id *oid, char **log)
>  
>  static int is_per_worktree_ref(const char *refname)
>  {
> -	return !strcmp(refname, "HEAD") ||
> -		starts_with(refname, "refs/worktree/") ||
> -		starts_with(refname, "refs/bisect/") ||
> -		starts_with(refname, "refs/rewritten/");
> +	return starts_with(refname, "refs/worktree/") ||
> +	       starts_with(refname, "refs/bisect/") ||
> +	       starts_with(refname, "refs/rewritten/");
>  }
>  
>  static int is_pseudoref_syntax(const char *refname)
Han-Wen Nienhuys July 7, 2020, 9:24 a.m. UTC | #2
On Mon, Jul 6, 2020 at 10:30 PM Junio C Hamano <gitster@pobox.com> wrote:
> > This is consistent with the definition of REF_TYPE_PSEUDOREF
> > (uppercase in the root ref namespace).
>
> I wonder if some special casing we saw for "HEAD" in 1/2 (e.g. we no
> longer do this to pseudorefs in this codepath but HEAD is different
> and will continue to be dealt with in the codepath) needs adjustment
> after this change?  HEAD still needs to be able to have a different
> value (either detached or pointing to another ref) per worktree, but
> it is unclear where that knowledge now resides in the new code.  Are
> we declaring that all pseudorefs are per worktree (which I think is
> not wrong)?

the source code already says

enum ref_type {
 REF_TYPE_PER_WORKTREE, /* refs inside refs/ but not shared */
 REF_TYPE_PSEUDOREF, /* refs outside refs/ in current worktree */

but considers HEAD a REF_TYPE_PER_WORKTREE, counter to the comment.

IIRC, this change actually has almost no effect, because most code
treats both enum values as equivalent. (see eg. builtin/reflog.c),
except for the code that the preceding commit changes.
diff mbox series

Patch

diff --git a/refs.c b/refs.c
index a2fd42364f..265767a234 100644
--- a/refs.c
+++ b/refs.c
@@ -676,10 +676,9 @@  int dwim_log(const char *str, int len, struct object_id *oid, char **log)
 
 static int is_per_worktree_ref(const char *refname)
 {
-	return !strcmp(refname, "HEAD") ||
-		starts_with(refname, "refs/worktree/") ||
-		starts_with(refname, "refs/bisect/") ||
-		starts_with(refname, "refs/rewritten/");
+	return starts_with(refname, "refs/worktree/") ||
+	       starts_with(refname, "refs/bisect/") ||
+	       starts_with(refname, "refs/rewritten/");
 }
 
 static int is_pseudoref_syntax(const char *refname)