Skip to content

Commit 0f0d118

Browse files
avargitster
authored andcommitted
transport: stop needlessly copying bundle header references
Amend the logic added in fddf2eb (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bf67dd8 commit 0f0d118

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

transport.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,9 @@ struct bundle_transport_data {
125125
unsigned get_refs_from_bundle_called : 1;
126126
};
127127

128-
static struct ref *get_refs_from_bundle(struct transport *transport,
129-
int for_push,
130-
struct transport_ls_refs_options *transport_options)
128+
static void get_refs_from_bundle_inner(struct transport *transport)
131129
{
132130
struct bundle_transport_data *data = transport->data;
133-
struct ref *result = NULL;
134-
int i;
135-
136-
if (for_push)
137-
return NULL;
138131

139132
data->get_refs_from_bundle_called = 1;
140133

@@ -145,6 +138,20 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
145138
die(_("could not read bundle '%s'"), transport->url);
146139

147140
transport->hash_algo = data->header.hash_algo;
141+
}
142+
143+
static struct ref *get_refs_from_bundle(struct transport *transport,
144+
int for_push,
145+
struct transport_ls_refs_options *transport_options)
146+
{
147+
struct bundle_transport_data *data = transport->data;
148+
struct ref *result = NULL;
149+
int i;
150+
151+
if (for_push)
152+
return NULL;
153+
154+
get_refs_from_bundle_inner(transport);
148155

149156
for (i = 0; i < data->header.references.nr; i++) {
150157
struct string_list_item *e = data->header.references.items + i;
@@ -169,7 +176,7 @@ static int fetch_refs_from_bundle(struct transport *transport,
169176
strvec_push(&extra_index_pack_args, "-v");
170177

171178
if (!data->get_refs_from_bundle_called)
172-
get_refs_from_bundle(transport, 0, NULL);
179+
get_refs_from_bundle_inner(transport);
173180
ret = unbundle(the_repository, &data->header, data->fd,
174181
&extra_index_pack_args);
175182
transport->hash_algo = data->header.hash_algo;

0 commit comments

Comments
 (0)