2007-09-11 05:03:15 +02:00
|
|
|
#ifndef BUNDLE_H
|
|
|
|
#define BUNDLE_H
|
|
|
|
|
2020-07-28 22:23:39 +02:00
|
|
|
#include "strvec.h"
|
2017-05-01 04:28:59 +02:00
|
|
|
#include "cache.h"
|
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>
2021-07-02 11:57:32 +02:00
|
|
|
#include "string-list.h"
|
2022-03-09 17:01:39 +01:00
|
|
|
#include "list-objects-filter-options.h"
|
2007-09-11 05:03:15 +02:00
|
|
|
|
|
|
|
struct bundle_header {
|
2020-07-30 01:14:20 +02:00
|
|
|
unsigned version;
|
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>
2021-07-02 11:57:32 +02:00
|
|
|
struct string_list prerequisites;
|
|
|
|
struct string_list references;
|
2020-06-19 19:56:00 +02:00
|
|
|
const struct git_hash_algo *hash_algo;
|
2022-03-09 17:01:39 +01:00
|
|
|
struct list_objects_filter_options filter;
|
2007-09-11 05:03:15 +02:00
|
|
|
};
|
|
|
|
|
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>
2021-07-02 11:57:32 +02:00
|
|
|
#define BUNDLE_HEADER_INIT \
|
|
|
|
{ \
|
|
|
|
.prerequisites = STRING_LIST_INIT_DUP, \
|
|
|
|
.references = STRING_LIST_INIT_DUP, \
|
list-objects-filter: add and use initializers
In 7e2619d8ff (list_objects_filter_options: plug leak of filter_spec
strings, 2022-09-08), we noted that the filter_spec string_list was
inconsistent in how it handled memory ownership of strings stored in the
list. The fix there was a bit of a band-aid to set the "strdup_strings"
variable right before adding anything.
That works OK, and it lets the users of the API continue to
zero-initialize the struct. But it makes the code a bit hard to follow
and accident-prone, as any other spots appending the filter_spec need to
think about whether to set the strdup_strings value, too (there's one
such spot in partial_clone_get_default_filter_spec(), which is probably
a possible memory leak).
So let's do that full cleanup now. We'll introduce a
LIST_OBJECTS_FILTER_INIT macro and matching function, and use them as
appropriate (though it is for the "_options" struct, this matches the
corresponding list_objects_filter_release() function).
This is harder than it seems! Many other structs, like
git_transport_data, embed the filter struct. So they need to initialize
it themselves even if the rest of the enclosing struct is OK with
zero-initialization. I found all of the relevant spots by grepping
manually for declarations of list_objects_filter_options. And then doing
so recursively for structs which embed it, and ones which embed those,
and so on.
I'm pretty sure I got everything, but there's no change that would alert
the compiler if any topics in flight added new declarations. To catch
this case, we now double-check in the parsing function that things were
initialized as expected and BUG() if appropriate.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-09-11 07:03:07 +02:00
|
|
|
.filter = LIST_OBJECTS_FILTER_INIT, \
|
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>
2021-07-02 11:57:32 +02:00
|
|
|
}
|
|
|
|
void bundle_header_init(struct bundle_header *header);
|
|
|
|
void bundle_header_release(struct bundle_header *header);
|
|
|
|
|
2011-10-14 00:19:31 +02:00
|
|
|
int is_bundle(const char *path, int quiet);
|
2007-09-11 05:03:15 +02:00
|
|
|
int read_bundle_header(const char *path, struct bundle_header *header);
|
2022-05-16 22:11:05 +02:00
|
|
|
int read_bundle_header_fd(int fd, struct bundle_header *header,
|
|
|
|
const char *report_path);
|
2019-01-24 14:11:51 +01:00
|
|
|
int create_bundle(struct repository *r, const char *path,
|
2020-08-12 03:04:11 +02:00
|
|
|
int argc, const char **argv, struct strvec *pack_options,
|
2020-07-30 01:14:20 +02:00
|
|
|
int version);
|
2022-10-12 14:52:37 +02:00
|
|
|
|
|
|
|
enum verify_bundle_flags {
|
|
|
|
VERIFY_BUNDLE_VERBOSE = (1 << 0),
|
2022-10-12 14:52:38 +02:00
|
|
|
VERIFY_BUNDLE_QUIET = (1 << 1),
|
2022-10-12 14:52:37 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
int verify_bundle(struct repository *r, struct bundle_header *header,
|
|
|
|
enum verify_bundle_flags flags);
|
2021-08-26 16:05:47 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbundle after reading the header with read_bundle_header().
|
|
|
|
*
|
|
|
|
* We'll invoke "git index-pack --stdin --fix-thin" for you on the
|
|
|
|
* provided `bundle_fd` from read_bundle_header().
|
2021-09-05 09:34:43 +02:00
|
|
|
*
|
|
|
|
* Provide "extra_index_pack_args" to pass any extra arguments
|
|
|
|
* (e.g. "-v" for verbose/progress), NULL otherwise. The provided
|
|
|
|
* "extra_index_pack_args" (if any) will be strvec_clear()'d for you.
|
2022-10-12 14:52:37 +02:00
|
|
|
*
|
|
|
|
* Before unbundling, this method will call verify_bundle() with the
|
|
|
|
* given 'flags'.
|
2021-08-26 16:05:47 +02:00
|
|
|
*/
|
2018-11-10 06:49:01 +01:00
|
|
|
int unbundle(struct repository *r, struct bundle_header *header,
|
2022-10-12 14:52:37 +02:00
|
|
|
int bundle_fd, struct strvec *extra_index_pack_args,
|
|
|
|
enum verify_bundle_flags flags);
|
2007-09-11 05:03:15 +02:00
|
|
|
int list_bundle_refs(struct bundle_header *header,
|
|
|
|
int argc, const char **argv);
|
|
|
|
|
|
|
|
#endif
|