From: Patrick Steinhardt <ps@pks.im>
To: Karthik Nayak <karthik.188@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 09/16] worktree: return allocated string from `get_worktree_git_dir()`
Date: Fri, 7 Feb 2025 11:49:13 +0100 [thread overview]
Message-ID: <Z6XlKVwsYNskS_nR@pks.im> (raw)
In-Reply-To: <CAOLa=ZSXFqvwFEfJ+cktqzSUf0XMoFC8Z0S0DJHcg4jYN4+DcA@mail.gmail.com>
On Thu, Feb 06, 2025 at 11:15:58PM -0800, Karthik Nayak wrote:
> Patrick Steinhardt <ps@pks.im> writes:
>
> > The `get_worktree_git_dir()` function returns a string constant that
> > does not need to be free'd by the caller. For `repo_get_git_dir()` and
> > `repo_get_common_dir()` this is because we return strings owned by
> > `the_repository`.
> >
>
> Not sure what the second sentence is signifying here. What relation does
> `get_worktree_git_dir()` have with `repo_get_git_dir()` and
> `repo_get_common_dir()`?
These are getting called in `get_worktree_git_dir()`. I'll rephrase the
message to make this clearer.
> > But for `git_common_path()` it's a bit less obvious though, because that
> > function does end up allocating memory. This doesn't result in a memory
> > leak either because we write into a buffer returned by `get_pathname()`,
> > which returns one out of four static buffers.
> >
>
> Now `git_common_path()`, what is binding all these functions together?
> Sneaking down to the code, it looks like `get_worktree_git_dir()` calls
> one of the other three functions. Maybe we should start with that?
Yeah, I've reworded the commit message accordingly.
> > diff --git a/revision.c b/revision.c
> > index 474fa1e767..be72f226f3 100644
> > --- a/revision.c
> > +++ b/revision.c
> > @@ -1874,15 +1874,20 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned int flags)
> > for (p = worktrees; *p; p++) {
> > struct worktree *wt = *p;
> > struct index_state istate = INDEX_STATE_INIT(revs->repo);
> > + char *gitdir;
> >
>
> Nit: should this be named `wt_gitdir` to stay consistent?
Makes sense.
> > diff --git a/worktree.c b/worktree.c
> > index 8f4fc10c44..3b94535963 100644
> > --- a/worktree.c
> > +++ b/worktree.c
> > @@ -59,8 +59,9 @@ static void add_head_info(struct worktree *wt)
> > static int is_current_worktree(struct worktree *wt)
> > {
> > char *git_dir = absolute_pathdup(repo_get_git_dir(the_repository));
> > - const char *wt_git_dir = get_worktree_git_dir(wt);
> > + char *wt_git_dir = get_worktree_git_dir(wt);
>
> Nit: here too, even though it is a pre-existing name. Perhaps it is just
> me. So feel free to ignore :)
I'll leave that one as-is, even though I share your sentiment.
Patrick
next prev parent reply other threads:[~2025-02-07 10:49 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-06 7:57 [PATCH 00/16] path: remove dependency on `the_repository` Patrick Steinhardt
2025-02-06 7:57 ` [PATCH 01/16] path: refactor `repo_common_path()` family of functions Patrick Steinhardt
2025-02-06 11:17 ` Karthik Nayak
2025-02-07 6:16 ` Patrick Steinhardt
2025-02-06 14:21 ` shejialuo
2025-02-07 6:16 ` Patrick Steinhardt
2025-02-06 7:57 ` [PATCH 02/16] path: refactor `repo_git_path()` " Patrick Steinhardt
2025-02-06 11:53 ` Karthik Nayak
2025-02-07 6:15 ` Patrick Steinhardt
2025-02-06 7:57 ` [PATCH 03/16] path: refactor `repo_worktree_path()` " Patrick Steinhardt
2025-02-06 7:58 ` [PATCH 04/16] submodule: refactor `submodule_to_gitdir()` to accept a repo Patrick Steinhardt
2025-02-06 7:58 ` [PATCH 05/16] path: refactor `repo_submodule_path()` family of functions Patrick Steinhardt
2025-02-06 12:05 ` Karthik Nayak
2025-02-07 6:16 ` Patrick Steinhardt
2025-02-07 7:04 ` Karthik Nayak
2025-02-06 15:03 ` shejialuo
2025-02-06 7:58 ` [PATCH 06/16] path: drop unused `strbuf_git_path()` function Patrick Steinhardt
2025-02-06 7:58 ` [PATCH 07/16] path: drop `git_pathdup()` in favor of `repo_git_path()` Patrick Steinhardt
2025-02-06 7:58 ` [PATCH 08/16] path: drop `git_path_buf()` in favor of `repo_git_path_replace()` Patrick Steinhardt
2025-02-06 7:58 ` [PATCH 09/16] worktree: return allocated string from `get_worktree_git_dir()` Patrick Steinhardt
2025-02-07 7:15 ` Karthik Nayak
2025-02-07 10:49 ` Patrick Steinhardt [this message]
2025-02-06 7:58 ` [PATCH 10/16] path: drop `git_common_path()` in favor of `repo_common_path()` Patrick Steinhardt
2025-02-06 15:54 ` shejialuo
2025-02-07 6:16 ` Patrick Steinhardt
2025-02-06 7:58 ` [PATCH 11/16] rerere: let `rerere_path()` write paths into a caller-provided buffer Patrick Steinhardt
2025-02-06 7:58 ` [PATCH 12/16] path: drop `git_path()` in favor of `repo_git_path()` Patrick Steinhardt
2025-02-06 16:01 ` shejialuo
2025-02-07 6:16 ` Patrick Steinhardt
2025-02-06 7:58 ` [PATCH 13/16] repo-settings: introduce function to clear struct Patrick Steinhardt
2025-02-06 7:58 ` [PATCH 14/16] environment: move access to "core.hooksPath" into repo settings Patrick Steinhardt
2025-02-06 7:58 ` [PATCH 15/16] environment: move access to "core.sharedRepository" " Patrick Steinhardt
2025-02-06 7:58 ` [PATCH 16/16] path: adjust last remaining users of `the_repository` Patrick Steinhardt
2025-02-06 16:14 ` [PATCH 00/16] path: remove dependency on `the_repository` shejialuo
2025-02-07 6:16 ` Patrick Steinhardt
2025-02-07 8:17 ` Karthik Nayak
2025-02-07 11:03 ` [PATCH v2 " Patrick Steinhardt
2025-02-07 11:03 ` [PATCH v2 01/16] path: refactor `repo_common_path()` family of functions Patrick Steinhardt
2025-02-07 11:03 ` [PATCH v2 02/16] path: refactor `repo_git_path()` " Patrick Steinhardt
2025-02-07 11:03 ` [PATCH v2 03/16] path: refactor `repo_worktree_path()` " Patrick Steinhardt
2025-02-07 11:03 ` [PATCH v2 04/16] submodule: refactor `submodule_to_gitdir()` to accept a repo Patrick Steinhardt
2025-02-07 11:03 ` [PATCH v2 05/16] path: refactor `repo_submodule_path()` family of functions Patrick Steinhardt
2025-02-07 11:03 ` [PATCH v2 06/16] path: drop unused `strbuf_git_path()` function Patrick Steinhardt
2025-02-07 11:03 ` [PATCH v2 07/16] path: drop `git_pathdup()` in favor of `repo_git_path()` Patrick Steinhardt
2025-02-07 11:03 ` [PATCH v2 08/16] path: drop `git_path_buf()` in favor of `repo_git_path_replace()` Patrick Steinhardt
2025-02-07 11:03 ` [PATCH v2 09/16] worktree: return allocated string from `get_worktree_git_dir()` Patrick Steinhardt
2025-02-07 11:03 ` [PATCH v2 10/16] path: drop `git_common_path()` in favor of `repo_common_path()` Patrick Steinhardt
2025-02-07 11:03 ` [PATCH v2 11/16] rerere: let `rerere_path()` write paths into a caller-provided buffer Patrick Steinhardt
2025-02-22 7:20 ` Jeff King
2025-02-24 16:14 ` Junio C Hamano
2025-02-24 22:19 ` Jeff King
2025-02-24 22:50 ` Junio C Hamano
2025-02-24 23:10 ` Jeff King
2025-02-24 23:14 ` Junio C Hamano
2025-02-25 6:24 ` Patrick Steinhardt
2025-02-07 11:03 ` [PATCH v2 12/16] path: drop `git_path()` in favor of `repo_git_path()` Patrick Steinhardt
2025-02-07 11:03 ` [PATCH v2 13/16] repo-settings: introduce function to clear struct Patrick Steinhardt
2025-02-07 11:03 ` [PATCH v2 14/16] environment: move access to "core.hooksPath" into repo settings Patrick Steinhardt
2025-02-07 11:03 ` [PATCH v2 15/16] environment: move access to "core.sharedRepository" " Patrick Steinhardt
2025-02-07 11:03 ` [PATCH v2 16/16] path: adjust last remaining users of `the_repository` Patrick Steinhardt
2025-02-07 11:44 ` [PATCH v2 00/16] path: remove dependency on `the_repository` Karthik Nayak
2025-02-08 15:31 ` shejialuo
2025-02-10 18:32 ` Junio C Hamano
2025-02-11 10:03 ` shejialuo
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=Z6XlKVwsYNskS_nR@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=karthik.188@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;
as well as URLs for NNTP newsgroup(s).