summaryrefslogtreecommitdiff
path: root/transport.c
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2021-07-02 09:57:32 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-07-06 19:10:17 (GMT)
commit10b635b77311badcbb5045b7421e6826c4536613 (patch)
tree82fda8f84620a0dfc3c48770430194f848ca92e0 /transport.c
parent15e7c7dca66ab7b020316696f54433f76e5e1084 (diff)
downloadgit-10b635b77311badcbb5045b7421e6826c4536613.zip
git-10b635b77311badcbb5045b7421e6826c4536613.tar.gz
git-10b635b77311badcbb5045b7421e6826c4536613.tar.bz2
bundle: remove "ref_list" in favor of string-list.c API
Move away from the "struct ref_list" in bundle.c in favor of the almost identical string-list.c API. That API fits this use-case perfectly, but did not exist in its current form when this code was added in 2e0afafebd (Add git-bundle: move objects and references by archive, 2007-02-22), with hindsight we could have used the path-list API, which later got renamed to string-list. See 8fd2cb4069 (Extract helper bits from c-merge-recursive work, 2006-07-25) We need to change "name" to "string" and "oid" to "util" to make this conversion, but other than that the APIs are pretty much identical for what bundle.c made use of. Let's also replace the memset(..,0,...) pattern with a more idiomatic "INIT" macro, and finally add a *_release() function so to free the allocated memory. Before this the add_to_ref_list() would leak memory, now e.g. "bundle list-heads" reports no memory leaks at all under valgrind. In the bundle_header_init() function we're using a clever trick to memcpy() what we'd get from the corresponding BUNDLE_HEADER_INIT. There is a concurrent series to make use of that pattern more generally, see [1]. 1. https://lore.kernel.org/git/cover-0.5-00000000000-20210701T104855Z-avarab@gmail.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'transport.c')
-rw-r--r--transport.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/transport.c b/transport.c
index 95c1138..745ffa2 100644
--- a/transport.c
+++ b/transport.c
@@ -147,10 +147,10 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
transport->hash_algo = data->header.hash_algo;
for (i = 0; i < data->header.references.nr; i++) {
- struct ref_list_entry *e = data->header.references.list + i;
- const char *name = e->name;
+ struct string_list_item *e = data->header.references.items + i;
+ const char *name = e->string;
struct ref *ref = alloc_ref(name);
- struct object_id *oid = &e->oid;
+ struct object_id *oid = e->util;
oidcpy(&ref->old_oid, oid);
ref->next = result;
result = ref;
@@ -177,6 +177,7 @@ static int close_bundle(struct transport *transport)
struct bundle_transport_data *data = transport->data;
if (data->fd > 0)
close(data->fd);
+ bundle_header_release(&data->header);
free(data);
return 0;
}
@@ -1083,6 +1084,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
die(_("git-over-rsync is no longer supported"));
} else if (url_is_local_not_ssh(url) && is_file(url) && is_bundle(url, 1)) {
struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
+ bundle_header_init(&data->header);
transport_check_allowed("file");
ret->data = data;
ret->vtable = &bundle_vtable;