public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Tian Yuchen <a3205153416@gmail.com>
To: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Cc: git@vger.kernel.org, sandals@crustytoothpaste.net,
	kumarayushjha123@gmail.com, jayatheerthkulkarni2005@gmail.com,
	valusoutrik@gmail.com, pushkarkumarsingh1970@gmail.com
Subject: Re: [PATCH 4/4] repo: add the field path.toplevel
Date: Mon, 2 Mar 2026 12:54:13 +0800	[thread overview]
Message-ID: <6d87ec49-6f24-42c5-86b2-6a4825607bb2@gmail.com> (raw)
In-Reply-To: <9789E676-4DE0-4C4C-BCAC-5BD880A51CE1@gmail.com>

Hi Lucas

> I don't think it can be considered a low-level function, but I
> agree that its name can be misleading.

Hummm...If a function is solely responsible for string concatenation and 
resides in  like path.c, why isn't it a low level function?

I think the key issue lies in the fact that this function's 
responsibilities are not quite appropriate, rather than merely the 
name. Does a string buffer need to understand Git's path formatting 
rules? It should only know how to append bytes, right? Maybe it would be 
better suited as a domain-specific formatter like 'format_path_output()' 
in a higher level module? I am quite uncertain about it.


> In this case, no, it is defined in wrapper.h.

Yes it is defined in wrapper.h. However in wrapper.c we have:

char *xgetcwd(void)
{
	struct strbuf sb = STRBUF_INIT;
	if (strbuf_getcwd(&sb))
		die_errno(_("unable to get current working directory"));
	return strbuf_detach(&sb, NULL);
}

and the for the stfbuf_getcwd(), in strbuf.c we have:

int strbuf_getcwd(struct strbuf *sb)
{
	size_t oldalloc = sb->alloc;
	size_t guessed_len = 128;

	for (;; guessed_len *= 2) {
		strbuf_grow(sb, guessed_len);
		if (getcwd(sb->buf, sb->alloc)) {
			strbuf_setlen(sb, strlen(sb->buf));
			return 0;
...

Notice the getcwd() function, which is indeed a system call, which you 
can check with 'man 2 getcwd' in terminal. Wrapping it in wrapper.c is 
just providing a shortcut, right?

But I don't think using system calls is inherently problematic. The 
issue lies in where this xgetbuf() is placed:

In builtin/rev-parse.c, the print_path() function is inside of 
cmd_rev_parse(), which is like:

int cmd_rev_parse(....){
	for (i = 1; i < argc; i++){
	...
	if (....){
		print_path(....)
	}
	...
}

And your print_path() implement was:

> +static void print_path(const char *path, const char *prefix,
> +		       enum path_format_type format, enum path_default_type def)
>  {
> +	struct strbuf sb = STRBUF_INIT;
> +	strbuf_add_path(&sb, path, prefix, format, def);
> +	puts(sb.buf);
> +	strbuf_release(&sb);
>  }

So this system call is indeed invoked in the loop. Specifically, it gets 
called every time 'git rev-parse' is invoked, and as far as I know it 
should be a command used extensively in like shell scripts...?

Maybe cache-up approach is more robust? For example in builtin/rev-parse.c:

const char *cached_cwd = ...->original_cwd;
if (!cached_cwd)
	cached_cwd = xgetcwd();

for (...) {
	if (...) {
		print_path_with_cwd(..., cached_cwd, ...);
	}
}


> In this case, we need to add them to match the signature of
> get_value_fn. Those values will be useful for all the path.*, but
> if we start to add more than that I agree that we'll need to think
> in a better solution.

Yes indeed.

> Thanks, it's also good to see more points of view. I'm also not
> sure about it :-)

Thank you for the patch again!

Regards,

Yuchen


  reply	other threads:[~2026-03-02  4:54 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 [this message]
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
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=6d87ec49-6f24-42c5-86b2-6a4825607bb2@gmail.com \
    --to=a3205153416@gmail.com \
    --cc=git@vger.kernel.org \
    --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