From: Junio C Hamano <gitster@pobox.com>
To: "Nicolas Guichard via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Nicolas Guichard <nicolas@guichard.eu>
Subject: Re: [PATCH 1/2] sequencer.c: extract load_branch_decorations
Date: Mon, 23 Sep 2024 12:32:40 -0700 [thread overview]
Message-ID: <xmqq7cb217zb.fsf@gitster.g> (raw)
In-Reply-To: <7f3d5e5da356f93ebef300ef73bfd6c312013e09.1726943880.git.gitgitgadget@gmail.com> (Nicolas Guichard via GitGitGadget's message of "Sat, 21 Sep 2024 18:37:59 +0000")
"Nicolas Guichard via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Nicolas Guichard <nicolas@guichard.eu>
>
> Extract load_branch_decorations from todo_list_add_update_ref_commands so
> it can be re-used in make_script_with_merges.
>
> Signed-off-by: Nicolas Guichard <nicolas@guichard.eu>
> ---
> sequencer.c | 25 +++++++++++++++----------
> 1 file changed, 15 insertions(+), 10 deletions(-)
This intends no behaviour change, and it indeed does not make any
behaviour change. Good.
> diff --git a/sequencer.c b/sequencer.c
> index 8d01cd50ac9..e5eb6f8cd76 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -5810,6 +5810,20 @@ static const char *label_oid(struct object_id *oid, const char *label,
> return string_entry->string;
> }
>
> +static void load_branch_decorations(void)
> +{
> + static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP;
> + static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP;
> + static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
> + struct decoration_filter decoration_filter = {
> + .include_ref_pattern = &decorate_refs_include,
> + .exclude_ref_pattern = &decorate_refs_exclude,
> + .exclude_ref_config_pattern = &decorate_refs_exclude_config,
> + };
> + string_list_append(&decorate_refs_include, "refs/heads/");
> + load_ref_decorations(&decoration_filter, 0);
> +}
The load_ref_decorations() function can be called only once per
process, so it does not matter whatever garbage your second and
later invocations throw at it.
But if this function is ever called N times, you'll add N copies of
"refs/heads/" in the _include list, and because the variable is
static, it is not reported as a leak.
It may have been OK back when this implementation was inside
todo_list_add_update_ref_commands(), which was called by
complete_action() only once before the process exited.
But now you made it a "reusable" function, we should clean up after
ourselves, perhaps by dropping "static" from these three string_list
instances and clearing them after calling load_ref_decorations().
next prev parent reply other threads:[~2024-09-23 19:32 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-21 18:37 [PATCH 0/2] rebase-merges: try and use branch names for labels Nicolas Guichard via GitGitGadget
2024-09-21 18:37 ` [PATCH 1/2] sequencer.c: extract load_branch_decorations Nicolas Guichard via GitGitGadget
2024-09-23 19:32 ` Junio C Hamano [this message]
2024-09-21 18:38 ` [PATCH 2/2] rebase-merges: try and use branch names as labels Nicolas Guichard via GitGitGadget
2024-09-23 19:38 ` Junio C Hamano
2024-10-04 23:22 ` [PATCH v2 0/3] rebase-merges: try and use branch names for labels Nicolas Guichard via GitGitGadget
2024-10-04 23:22 ` [PATCH v2 1/3] load_branch_decorations: fix memory leak with non-static filters Nicolas Guichard via GitGitGadget
2024-10-05 3:43 ` Eric Sunshine
2024-10-04 23:22 ` [PATCH v2 2/3] rebase-update-refs: extract load_branch_decorations Nicolas Guichard via GitGitGadget
2024-10-05 3:44 ` Eric Sunshine
2024-10-04 23:22 ` [PATCH v2 3/3] rebase-merges: try and use branch names as labels Nicolas Guichard via GitGitGadget
2024-10-09 7:58 ` [PATCH v3 0/3] rebase-merges: try and use branch names for labels Nicolas Guichard via GitGitGadget
2024-10-09 7:58 ` [PATCH v3 1/3] load_branch_decorations: fix memory leak with non-static filters Nicolas Guichard via GitGitGadget
2024-10-09 7:58 ` [PATCH v3 2/3] rebase-update-refs: extract load_branch_decorations Nicolas Guichard via GitGitGadget
2024-10-09 7:58 ` [PATCH v3 3/3] rebase-merges: try and use branch names as labels Nicolas Guichard via GitGitGadget
2024-10-09 14:21 ` Phillip Wood
2024-10-09 17:57 ` Junio C Hamano
2024-10-09 14:22 ` [PATCH v3 0/3] rebase-merges: try and use branch names for labels Phillip Wood
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=xmqq7cb217zb.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=nicolas@guichard.eu \
/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).