All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Matt Hunter <m@lfurio.us>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] init: show absolute path of (re)initialized repository
Date: Tue, 20 Oct 2026 08:55:43 +0200	[thread overview]
Message-ID: <atcQb_V69vvKnxoF@pks.im> (raw)
In-Reply-To: <20261020053932.1274210-1-m@lfurio.us>

On Tue, Oct 20, 2026 at 01:38:47AM -0400, Matt Hunter wrote:
> Since 20e38cba3926 (setup: split up concerns of `init_db()`,
> 2026-09-10), git-init produces the message:
> 
>     Initialized empty Git repository in .git/
> 
> instead of the previous
> 
>     Initialized empty Git repository in /full/path/to/repo/.git/
> 
> Prior to 20e38cba3926, the code producing this message was in function
> init_db (renamed at the time to create_repository).  In that context,
> the git_dir variable was updated by 'git_dir = repo_get_git_dir(repo);'
> earlier in the function, to set the value used in printf.
> 
> None of the discussion [1] around the original patch indicates that this
> change was intentional, so address the regression by similarly using
> repo_get_git_dir in this code's new location.

This indeed wasn't an intentional change. I also confirmed that with
v2.55 we print the full path.

> In this case, git_dir is referencing owned memory that is later freed,
> so declare a new variable to hold the used string.

This sentence doesn't add any value as it simply explains parts that are
obvious when reading the patch. I'd just drop it.

> diff --git a/builtin/init-db.c b/builtin/init-db.c
> index 374ed3a74706..a2628568ff6a 100644
> --- a/builtin/init-db.c
> +++ b/builtin/init-db.c
> @@ -248,18 +248,19 @@ int cmd_init_db(int argc,
>  	create_object_database(the_repository, NULL);
>  
>  	if (!quiet) {
> -		int len = strlen(git_dir);
> +		const char *full_git_dir = repo_get_git_dir(the_repository);

Previously, in `init_db()` we always assigned `git_dir =
repo_get_git_dir(repo)`, so it's clear that this change here does the
equivalent.

> +		int len = strlen(full_git_dir);

I was wondering whether we want to fix the variable type to be a
`size_t` while at it. But maybe we should just keep it as-is.

>  		if (reinit)
>  			printf(repo_settings_get_shared_repository(the_repository)
>  			       ? _("Reinitialized existing shared Git repository in %s%s\n")
>  			       : _("Reinitialized existing Git repository in %s%s\n"),
> -			       git_dir, len && git_dir[len-1] != '/' ? "/" : "");
> +			       full_git_dir, len && full_git_dir[len-1] != '/' ? "/" : "");
>  		else
>  			printf(repo_settings_get_shared_repository(the_repository)
>  			       ? _("Initialized empty shared Git repository in %s%s\n")
>  			       : _("Initialized empty Git repository in %s%s\n"),
> -			       git_dir, len && git_dir[len-1] != '/' ? "/" : "");
> +			       full_git_dir, len && full_git_dir[len-1] != '/' ? "/" : "");
>  	}

The changes look obviously good to me.

I'm a bit on the fence about whether we want to have a regression test
or not. It feels like a very specific thing in the user-facing output,
so it's a bit dubious whether it's really worth it. But on the other
hand, folks like you seem to care enough to make the test worthwhile, so
maybe we should have one?

Thanks!

Patrick

  reply	other threads:[~2026-10-20  6:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20  5:38 [PATCH] init: show absolute path of (re)initialized repository Matt Hunter
2026-10-20  6:55 ` Patrick Steinhardt [this message]
2026-10-20  9:13   ` Matt Hunter
2026-10-20 12:14     ` Patrick Steinhardt
2026-10-20 12:37   ` Harald Nordgren
2026-10-20 14:37     ` Patrick Steinhardt
2026-10-20 15:32       ` Harald Nordgren
2026-10-20 16:29       ` Junio C Hamano

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=atcQb_V69vvKnxoF@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=m@lfurio.us \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.