git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Andy Koppe <andy.koppe@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, stolee@gmail.com
Subject: Re: [PATCH 0/7] log: decorate pseudorefs and other refs
Date: Mon, 23 Oct 2023 23:15:36 +0100	[thread overview]
Message-ID: <50a646f6-730d-4d79-84b6-c0ee8be748e7@gmail.com> (raw)
In-Reply-To: <xmqqpm16p4t3.fsf@gitster.g>

On 23/10/2023 01:20, Junio C Hamano wrote:
> Andy Koppe <andy.koppe@gmail.com> writes:
> 
>>>    [2/7] is a trivial readability improvement.  It obviously should be
>>>          left outside the scope of this series, but we should notice
>>>          the same pattern in similar color tables (e.g., wt-status.c
>>>          has one, diff.c has another) and perform the same clean-up as
>>>          a #leftoverbits item.
>>
>> Okay, I've removed that commit in v2. (I should have mentioned in the
>> commit message that it was triggered by the inconsistency with the
>> immediately following color_decorate_slots array, which uses
>> designated initializers.)
> 
> Sorry, that is not what I meant.  [2/7] as a preliminary clean-up to
> work in the same area does make very much sense.  What I meant to be
> "outside the scope" was to make similar fixes to other color tables
> that this series does not care about.

Ah, sorry for misreading. Commit reinstated in v3.


>> Fair enough, although the array already contains HEAD and refs/stash
>> as singletons.
> 
> But these deserve to be singletons, don't they?  There is no other
> thing that behaves like HEAD; there is no other thing that behaves
> like stash; and they do not behave like each other.

They do indeed, but arguably the pseudorefs are singletons rather than a 
namespace like refs/heads as well, as there is a defined and documented 
set of them.


>> I've rewritten things to not touch the ref_namespace array.
> 
> Well, the namespace_info mechanism still may be a good place to have
> the necessary information; it may be that the current implementation
> detail of how a given ref is classified to one of the namespaces is
> too limiting---it essentially allows the string match with the .ref
> member.  But we can imagine that it could be extended a bit, e.g.
> 
> 	struct ref_namespace_info {
> 		char *ref;
> 		int (*membership)(const char *, const struct ref_namespace_info *);
> 		... other members ...;
> 	};
> 
> where the .membership member is used in add_ref_decoration() to
> determine the membership of a given "refname" to the namespace "i"
> perhaps like so:
> 
> 	struct ref_namespace_info *info = &ref_namespace[i];
> 
> 	if (!info->decoration)
> 		continue;
> +	if (info->membership) {
> +		if (info->membership(refname, info)) {
> +			deco_type = info->decoration;
> +			break;
> +		}
> +	} else if (info->exact) {
> -	if (info->exact) {
> 		if (!strcmp(refname, info->ref)) {
> 			deco_type = info_decoration;
> 			break;
> 	}
> 
> Then you can arrange the pseudoref class to use .membership function
> perhaps like this:
> 
> 	static int pseudoref_namespace_membership(
> 		const char *refname, const struct ref_namespace_info *info UNUSED
> 	)
> 	{
> 		return is_pseudoref(refname);
> 	}
> 
> and make them all into a single class.

That's an interesting idea, but I'm not convinced it would buy us much, 
while also potentially complicating things for any other uses of the 
ref_namespace array.

My premise here is that we do need a list of the documented pseudorefs, 
so that we can iterate through them and add the ones that do exist to 
the decorations, whereby I admit that shoe-horning that list into the 
ref_namespace array wasn't a good idea. If that premise is wrong, and 
there's a better way to discover the pseudorefs, the following might be 
moot.

Sending each found pseudoref through add_ref_decoration() and its lookup 
of ref_namespace would just confirm what we already know: it's a 
pseudoref. Which is why both my initial attempt and the current one 
don't actually invoke add_ref_decoration() for them.

Could you have a closer look at the current design? It handles the 
pseudorefs separately from proper refs, with their own iteration and 
callback functions, which I think makes for simpler more self-contained 
changes than v1 or the approach suggested above.


> Having said that, I do not think it makes much sense to decorate a
> commit off of refs/stash, as the true richeness of the stash is not
> in its history but in its reflog, which the decoration code does not
> dig into.  But obviously it is not a part of the topic we are
> discussing (unless, of course, we are not "adding" new decoration
> sources and colors, but we are improving the decoration sources and
> colors by adding new useful ones while retiring existing useless
> ones).

I agree refs/stash is a weird one, and that it could be subsumed into 
the color.decoration.ref setting for 'refs/*' that I'm adding here, 
which is also why I chose the same default color for it. I'd be happy to 
drop color.decoration.stash if the minor break in compatibility for 
anyone who has customized it is acceptable. The setting would be quietly 
ignored.

Another related thought: the '--clear-decorations' option of git-log 
seems unfortunately named as it suggests the opposite of what it 
actually does, which is to enable all decorations (unless subsequently 
constrained with '--decorate-refs{,--exclude}=...').

Regards,
Andy


  reply	other threads:[~2023-10-23 22:15 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-03 20:54 [PATCH] decorate: add color.decorate.symbols config option Andy Koppe
2023-10-19 19:39 ` [PATCH 0/7] log: decorate pseudorefs and other refs Andy Koppe
2023-10-22  0:13   ` Junio C Hamano
2023-10-22 21:49     ` Andy Koppe
2023-10-23  0:20       ` Junio C Hamano
2023-10-23 22:15         ` Andy Koppe [this message]
2023-10-22 21:44   ` [PATCH v2 0/6] " Andy Koppe
2023-10-22 21:44     ` [PATCH v2 1/6] config: restructure color.decorate documentation Andy Koppe
2023-10-22 21:44     ` [PATCH v2 2/6] log: add color.decorate.symbol config variable Andy Koppe
2023-10-22 21:44     ` [PATCH v2 3/6] log: add color.decorate.ref " Andy Koppe
2023-10-22 21:44     ` [PATCH v2 4/6] refs: add pseudorefs array and iteration functions Andy Koppe
2023-10-22 21:44     ` [PATCH v2 5/6] refs: exempt pseudorefs from pattern prefixing Andy Koppe
2023-10-22 21:44     ` [PATCH v2 6/6] log: add color.decorate.pseudoref config variable Andy Koppe
2023-10-23 22:11     ` [PATCH v3 0/7] log: decorate pseudorefs and other refs Andy Koppe
2023-10-23 22:11       ` [PATCH v3 1/7] config: restructure color.decorate documentation Andy Koppe
2023-10-23 22:11       ` [PATCH v3 2/7] log: use designated inits for decoration_colors Andy Koppe
2023-10-23 22:11       ` [PATCH v3 3/7] log: add color.decorate.symbol config variable Andy Koppe
2023-10-23 22:11       ` [PATCH v3 4/7] log: add color.decorate.ref " Andy Koppe
2023-10-23 22:11       ` [PATCH v3 5/7] refs: add pseudorefs array and iteration functions Andy Koppe
2023-10-24  0:08         ` Junio C Hamano
2024-02-05 18:55         ` Kousik Sanagavarapu
2024-02-07 22:02           ` Junio C Hamano
2023-10-23 22:11       ` [PATCH v3 6/7] refs: exempt pseudorefs from pattern prefixing Andy Koppe
2023-10-23 22:11       ` [PATCH v3 7/7] log: add color.decorate.pseudoref config variable Andy Koppe
2023-10-19 19:39 ` [PATCH 1/7] config: restructure color.decorate documentation Andy Koppe
2023-10-19 19:39 ` [PATCH 2/7] log: use designated inits for decoration_colors Andy Koppe
2023-10-19 19:39 ` [PATCH 3/7] log: add color.decorate.symbol config option Andy Koppe
2023-10-19 19:39 ` [PATCH 4/7] refs: separate decoration type from default filter Andy Koppe
2023-10-19 19:39 ` [PATCH 5/7] log: add color.decorate.ref option for other refs Andy Koppe
2023-10-19 19:39 ` [PATCH 6/7] refs: exempt pseudoref patterns from prefixing Andy Koppe
2023-10-19 19:39 ` [PATCH 7/7] log: show pseudorefs in decorations Andy Koppe

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=50a646f6-730d-4d79-84b6-c0ee8be748e7@gmail.com \
    --to=andy.koppe@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=stolee@gmail.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).