Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2021-07-02 12:57:32 +0300
committerJunio C Hamano <gitster@pobox.com>2021-07-06 22:10:17 +0300
commit10b635b77311badcbb5045b7421e6826c4536613 (patch)
tree82fda8f84620a0dfc3c48770430194f848ca92e0 /bundle.h
parent15e7c7dca66ab7b020316696f54433f76e5e1084 (diff)
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 'bundle.h')
-rw-r--r--bundle.h21
1 files changed, 11 insertions, 10 deletions
diff --git a/bundle.h b/bundle.h
index f9e2d1c8ef..1927d8cd6a 100644
--- a/bundle.h
+++ b/bundle.h
@@ -3,22 +3,23 @@
#include "strvec.h"
#include "cache.h"
-
-struct ref_list {
- unsigned int nr, alloc;
- struct ref_list_entry {
- struct object_id oid;
- char *name;
- } *list;
-};
+#include "string-list.h"
struct bundle_header {
unsigned version;
- struct ref_list prerequisites;
- struct ref_list references;
+ struct string_list prerequisites;
+ struct string_list references;
const struct git_hash_algo *hash_algo;
};
+#define BUNDLE_HEADER_INIT \
+{ \
+ .prerequisites = STRING_LIST_INIT_DUP, \
+ .references = STRING_LIST_INIT_DUP, \
+}
+void bundle_header_init(struct bundle_header *header);
+void bundle_header_release(struct bundle_header *header);
+
int is_bundle(const char *path, int quiet);
int read_bundle_header(const char *path, struct bundle_header *header);
int create_bundle(struct repository *r, const char *path,