From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 07/14] transport: stop needlessly copying bundle header references
Date: Wed, 2 Mar 2022 18:10:13 +0100 [thread overview]
Message-ID: <patch-07.14-be62ca89bf5-20220302T170718Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-00.14-00000000000-20220302T170718Z-avarab@gmail.com>
Amend the logic added in fddf2ebe388 (transport: teach all vtables to
allow fetch first, 2019-08-21) and save ourselves pointless work in
fetch_refs_from_bundle().
The fetch_refs_from_bundle() caller doesn't care about the "struct
ref *result" return value of get_refs_from_bundle(), and doesn't need
any of the work we were doing in looping over the
"data->header.references" in get_refs_from_bundle().
So this change saves us work, and also fixes a memory leak that we had
when called from fetch_refs_from_bundle(). The other caller of
get_refs_from_bundle() is the "get_refs_list" member we set up for the
"struct transport_vtable bundle_vtable". That caller does care about
the "struct ref *result" return value.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
transport.c | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/transport.c b/transport.c
index 253d6671b1f..9a7d32b4b7d 100644
--- a/transport.c
+++ b/transport.c
@@ -125,6 +125,19 @@ struct bundle_transport_data {
unsigned get_refs_from_bundle_called : 1;
};
+static void get_refs_from_bundle_inner(struct transport *transport)
+{
+ struct bundle_transport_data *data = transport->data;
+
+ if (data->fd > 0)
+ close(data->fd);
+ data->fd = read_bundle_header(transport->url, &data->header);
+ if (data->fd < 0)
+ die(_("could not read bundle '%s'"), transport->url);
+
+ transport->hash_algo = data->header.hash_algo;
+}
+
static struct ref *get_refs_from_bundle(struct transport *transport,
int for_push,
struct transport_ls_refs_options *transport_options)
@@ -136,15 +149,7 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
if (for_push)
return NULL;
- data->get_refs_from_bundle_called = 1;
-
- if (data->fd > 0)
- close(data->fd);
- data->fd = read_bundle_header(transport->url, &data->header);
- if (data->fd < 0)
- die(_("could not read bundle '%s'"), transport->url);
-
- transport->hash_algo = data->header.hash_algo;
+ get_refs_from_bundle_inner(transport);
for (i = 0; i < data->header.references.nr; i++) {
struct string_list_item *e = data->header.references.items + i;
@@ -168,8 +173,8 @@ static int fetch_refs_from_bundle(struct transport *transport,
if (transport->progress)
strvec_push(&extra_index_pack_args, "-v");
- if (!data->get_refs_from_bundle_called)
- get_refs_from_bundle(transport, 0, NULL);
+ if (!data->get_refs_from_bundle_called++)
+ get_refs_from_bundle_inner(transport);
ret = unbundle(the_repository, &data->header, data->fd,
&extra_index_pack_args);
transport->hash_algo = data->header.hash_algo;
--
2.35.1.1228.g56895c6ee86
next prev parent reply other threads:[~2022-03-02 17:10 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-02 17:10 [PATCH 00/14] tree-wide: small fixes for memory leaks Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 01/14] index-pack: fix " Ævar Arnfjörð Bjarmason
2022-03-02 20:36 ` Derrick Stolee
2022-03-03 16:19 ` Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 02/14] merge-base: free() allocated "struct commit **" list Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 03/14] diff.c: free "buf" in diff_words_flush() Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 04/14] urlmatch.c: add and use a *_release() function Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 05/14] remote-curl.c: free memory in cmd_main() Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 06/14] bundle: call strvec_clear() on allocated strvec Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` Ævar Arnfjörð Bjarmason [this message]
2022-03-02 20:47 ` [PATCH 07/14] transport: stop needlessly copying bundle header references Derrick Stolee
2022-03-03 16:20 ` Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 08/14] submodule--helper: fix trivial leak in module_add() Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 09/14] commit-graph: fix memory leak in misused string_list API Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 10/14] commit-graph: stop fill_oids_from_packs() progress on error and free() Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 11/14] lockfile API users: simplify and don't leak "path" Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 12/14] range-diff: plug memory leak in common invocation Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 13/14] range-diff: plug memory leak in read_patches() Ævar Arnfjörð Bjarmason
2022-03-02 17:10 ` [PATCH 14/14] repository.c: free the "path cache" in repo_clear() Ævar Arnfjörð Bjarmason
2022-03-02 20:58 ` [PATCH 00/14] tree-wide: small fixes for memory leaks Derrick Stolee
2022-03-04 18:32 ` [PATCH v2 " Ævar Arnfjörð Bjarmason
2022-03-04 18:32 ` [PATCH v2 01/14] index-pack: fix " Ævar Arnfjörð Bjarmason
2022-03-04 18:32 ` [PATCH v2 02/14] merge-base: free() allocated "struct commit **" list Ævar Arnfjörð Bjarmason
2022-03-04 18:32 ` [PATCH v2 03/14] diff.c: free "buf" in diff_words_flush() Ævar Arnfjörð Bjarmason
2022-03-04 18:32 ` [PATCH v2 04/14] urlmatch.c: add and use a *_release() function Ævar Arnfjörð Bjarmason
2022-03-04 18:32 ` [PATCH v2 05/14] remote-curl.c: free memory in cmd_main() Ævar Arnfjörð Bjarmason
2022-03-04 18:32 ` [PATCH v2 06/14] bundle: call strvec_clear() on allocated strvec Ævar Arnfjörð Bjarmason
2022-03-04 18:32 ` [PATCH v2 07/14] transport: stop needlessly copying bundle header references Ævar Arnfjörð Bjarmason
2022-03-04 19:10 ` Derrick Stolee
2022-03-04 18:32 ` [PATCH v2 08/14] submodule--helper: fix trivial leak in module_add() Ævar Arnfjörð Bjarmason
2022-03-04 18:32 ` [PATCH v2 09/14] commit-graph: fix memory leak in misused string_list API Ævar Arnfjörð Bjarmason
2022-03-04 18:32 ` [PATCH v2 10/14] commit-graph: stop fill_oids_from_packs() progress on error and free() Ævar Arnfjörð Bjarmason
2022-03-04 18:32 ` [PATCH v2 11/14] lockfile API users: simplify and don't leak "path" Ævar Arnfjörð Bjarmason
2022-03-04 18:32 ` [PATCH v2 12/14] range-diff: plug memory leak in common invocation Ævar Arnfjörð Bjarmason
2022-03-04 18:32 ` [PATCH v2 13/14] range-diff: plug memory leak in read_patches() Ævar Arnfjörð Bjarmason
2022-03-04 18:32 ` [PATCH v2 14/14] repository.c: free the "path cache" in repo_clear() Ævar Arnfjörð Bjarmason
2022-03-04 19:11 ` [PATCH v2 00/14] tree-wide: small fixes for memory leaks Derrick Stolee
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=patch-07.14-be62ca89bf5-20220302T170718Z-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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).