mirror of
https://github.com/git/git
synced 2024-11-05 18:59:29 +00:00
10b635b773
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 in2e0afafebd
(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. See8fd2cb4069
(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>
35 lines
1 KiB
C
35 lines
1 KiB
C
#ifndef BUNDLE_H
|
|
#define BUNDLE_H
|
|
|
|
#include "strvec.h"
|
|
#include "cache.h"
|
|
#include "string-list.h"
|
|
|
|
struct bundle_header {
|
|
unsigned version;
|
|
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,
|
|
int argc, const char **argv, struct strvec *pack_options,
|
|
int version);
|
|
int verify_bundle(struct repository *r, struct bundle_header *header, int verbose);
|
|
#define BUNDLE_VERBOSE 1
|
|
int unbundle(struct repository *r, struct bundle_header *header,
|
|
int bundle_fd, int flags);
|
|
int list_bundle_refs(struct bundle_header *header,
|
|
int argc, const char **argv);
|
|
|
|
#endif
|