public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Tian Yuchen <a3205153416@gmail.com>
To: JAYATHEERTH K <jayatheerthkulkarni2005@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	"brian m. carlson" <sandals@crustytoothpaste.net>,
	Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>,
	git@vger.kernel.org, kumarayushjha123@gmail.com,
	valusoutrik@gmail.com, pushkarkumarsingh1970@gmail.com
Subject: Re: [PATCH 0/4] repo: add support for path-related fields
Date: Tue, 3 Mar 2026 12:32:32 +0800	[thread overview]
Message-ID: <108ccc9d-5777-4c84-9dad-c2d0f5dc2e42@gmail.com> (raw)
In-Reply-To: <CA+rGoLfbzXqP1Tw+94jMmWcSGPoefMv5E_fvwriad-O5CUeKHQ@mail.gmail.com>

Hi JAYATHEERTH,

> I see your point here.
> but wouldn't this effectively be the same as Ayush's suggestion, just
> with a different syntax?

In my view, this issue is actually to choose the most suitable tool for 
the job. After all, we don't want to use something like rev-parse, which 
is riddled with *ancient* technical debt, nor do we want to write an 
even more verbose parsing function from scratch for what you call 
verbose user input, right?

If I'm not mistaken, using different parsing functions to parse input is 
absolutely not just a matter of syntax differences. Instead, this will 
directly result in differences in data structures.

In ref-filter.c, we can easily see how Git parses format modifiers.

After the user input is parse by parse_ref_filter_atom(), it is then 
passed to the atom_valid[] static registry, which is like;

static struct {
	const char *name;
	info_source source;
	cmp_type cmp_type;
	int (*parser)(struct ref_format *format, struct used_atom *atom,
		      const char *arg, struct strbuf *err);
} valid_atom[] = {
	[ATOM_REFNAME] = { "refname", SOURCE_NONE, FIELD_STR, 
refname_atom_parser },
	[ATOM_OBJECTTYPE] = { "objecttype", SOURCE_OTHER, FIELD_STR, 
objecttype_atom_parser },
	[ATOM_OBJECTSIZE] = { "objectsize", SOURCE_OTHER, FIELD_ULONG, 
objectsize_atom_parser },
	[ATOM_OBJECTNAME] = { "objectname", SOURCE_OTHER, FIELD_STR, 
oid_atom_parser },
...

As you can see, each mapping relationship points to a parsing function 
(..._parser()). This parsing function is solely responsible for handling 
the state arg, fundamentally resolving the issue of function 
responsibility/naming confusion.

The reason I recommend this approach is because its implementation is 
incredibly clear and concise. To achieve the functionality we desire, 
all we need to do is add the following to the registry:

[ATOM_PATH] = { "path", SOURCE_NONE, FIELD_STR, path_atom_parser }

And the corresponding path_atom_parser().

This approach also offers strong scalability: If one day I decide to add 
a new feature like %(path:commondir,relative) output, all it would take 
is adding a switch statement in the parser() function (along with a few 
other minor tweaks).

*I'm not saying this approach is better than the solution you've 
discussed. I'm simply presenting a possible implementation for 
reference. (´~`)

> Coming to user friendliness
> I believe Junio has already raised an appropriate question.

This isn't a case of “you can't have your cake and eat it too,” right? I 
think user-friendliness can be achieved without compromising 
maintainability, predictability, or high performance in this case.

Regards,

Yuchen

  reply	other threads:[~2026-03-03  4:32 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-28 22:05 [PATCH 0/4] repo: add support for path-related fields Lucas Seiki Oshiro
2026-02-28 22:05 ` [PATCH 1/4] rev-parse: prepend `path_` to path-related enums Lucas Seiki Oshiro
2026-02-28 22:05 ` [PATCH 2/4] path: add new function strbuf_add_path Lucas Seiki Oshiro
2026-02-28 22:05 ` [PATCH 3/4] repo: add the --format-path flag Lucas Seiki Oshiro
2026-02-28 22:05 ` [PATCH 4/4] repo: add the field path.toplevel Lucas Seiki Oshiro
2026-03-01  4:24   ` Tian Yuchen
2026-03-01 20:21     ` Lucas Seiki Oshiro
2026-03-02  4:54       ` Tian Yuchen
2026-03-01  2:58 ` [PATCH 0/4] repo: add support for path-related fields JAYATHEERTH K
2026-03-01  5:45   ` Ayush Jha
2026-03-01  6:50     ` JAYATHEERTH K
2026-03-01 19:55     ` Lucas Seiki Oshiro
2026-03-03  3:27       ` Ayush Jha
2026-03-01 19:49   ` Lucas Seiki Oshiro
2026-03-01 10:44 ` Phillip Wood
2026-03-01 19:40   ` Lucas Seiki Oshiro
2026-03-01 21:25 ` brian m. carlson
2026-03-02 16:38   ` Junio C Hamano
2026-03-02 18:51     ` Tian Yuchen
2026-03-02 21:34       ` Junio C Hamano
2026-03-03  2:48       ` JAYATHEERTH K
2026-03-03  4:32         ` Tian Yuchen [this message]
2026-03-03  7:23           ` JAYATHEERTH K
2026-03-03  9:28             ` Tian Yuchen
2026-03-03 10:31               ` JAYATHEERTH K
2026-03-08  0:29   ` Lucas Seiki Oshiro

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=108ccc9d-5777-4c84-9dad-c2d0f5dc2e42@gmail.com \
    --to=a3205153416@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jayatheerthkulkarni2005@gmail.com \
    --cc=kumarayushjha123@gmail.com \
    --cc=lucasseikioshiro@gmail.com \
    --cc=pushkarkumarsingh1970@gmail.com \
    --cc=sandals@crustytoothpaste.net \
    --cc=valusoutrik@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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox