git-commit-vandalism/bundle-uri.h
Ævar Arnfjörð Bjarmason 8b8d9a2298 protocol v2: add server-side "bundle-uri" skeleton
Add a skeleton server-side implementation of a new "bundle-uri" command
to protocol v2. This will allow conforming clients to optionally seed
their initial clones or incremental fetches from URLs containing
"*.bundle" files created with "git bundle create".

This change only performs the basic boilerplate of advertising a new
protocol v2 capability. The new 'bundle-uri' capability allows a client
to request a list of bundles. Right now, the server only returns a flush
packet, which corresponds to an empty advertisement. The bundle.* config
namespace describes which key-value pairs will be communicated across
this interface in future updates.

The critical bit right now is that the new boolean
uploadPack.adverstiseBundleURIs config value signals whether or not this
capability should be advertised at all.

An earlier version of this patch [1] used a different transfer format
than the "key=value" pairs in the current implementation. The change was
made to unify the protocol v2 command with the bundle lists provided by
independent bundle servers. Further, the standard allows for the server
to advertise a URI that contains a bundle list. This allows users
automatically discovering bundle providers that are loosely associated
with the origin server, but without the origin server knowing exactly
which bundles are currently available.

[1] https://lore.kernel.org/git/RFC-patch-v2-01.13-2fc87ce092b-20220311T155841Z-avarab@gmail.com/

The very-deep headings needed to be modified to stop at level 4 due to
documentation build issues. These were not recognized in earlier builds
since the file was previously in the Documentation/technical/ directory
and was built in a different way. With its current location, the
heavily-nested details were causing build issues and they are now
replaced with a bulletted list of details.

Co-authored-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-12-25 16:24:23 +09:00

115 lines
2.6 KiB
C

#ifndef BUNDLE_URI_H
#define BUNDLE_URI_H
#include "hashmap.h"
#include "strbuf.h"
struct packet_reader;
struct repository;
struct string_list;
/**
* The remote_bundle_info struct contains information for a single bundle
* URI. This may be initialized simply by a given URI or might have
* additional metadata associated with it if the bundle was advertised by
* a bundle list.
*/
struct remote_bundle_info {
struct hashmap_entry ent;
/**
* The 'id' is a name given to the bundle for reference
* by other bundle infos.
*/
char *id;
/**
* The 'uri' is the location of the remote bundle so
* it can be downloaded on-demand. This will be NULL
* if there was no table of contents.
*/
char *uri;
/**
* If the bundle has been downloaded, then 'file' is a
* filename storing its contents. Otherwise, 'file' is
* NULL.
*/
char *file;
/**
* If the bundle has been unbundled successfully, then
* this boolean is true.
*/
unsigned unbundled:1;
};
#define REMOTE_BUNDLE_INFO_INIT { 0 }
enum bundle_list_mode {
BUNDLE_MODE_NONE = 0,
BUNDLE_MODE_ALL,
BUNDLE_MODE_ANY
};
/**
* A bundle_list contains an unordered set of remote_bundle_info structs,
* as well as information about the bundle listing, such as version and
* mode.
*/
struct bundle_list {
int version;
enum bundle_list_mode mode;
struct hashmap bundles;
};
void init_bundle_list(struct bundle_list *list);
void clear_bundle_list(struct bundle_list *list);
typedef int (*bundle_iterator)(struct remote_bundle_info *bundle,
void *data);
int for_all_bundles_in_list(struct bundle_list *list,
bundle_iterator iter,
void *data);
struct FILE;
void print_bundle_list(FILE *fp, struct bundle_list *list);
/**
* A bundle URI may point to a bundle list where the key=value
* pairs are provided in config file format. This method is
* exposed publicly for testing purposes.
*/
int bundle_uri_parse_config_format(const char *uri,
const char *filename,
struct bundle_list *list);
/**
* Fetch data from the given 'uri' and unbundle the bundle data found
* based on that information.
*
* Returns non-zero if no bundle information is found at the given 'uri'.
*/
int fetch_bundle_uri(struct repository *r, const char *uri);
/**
* API for serve.c.
*/
int bundle_uri_advertise(struct repository *r, struct strbuf *value);
int bundle_uri_command(struct repository *r, struct packet_reader *request);
/**
* General API for {transport,connect}.c etc.
*/
/**
* Parse a "key=value" packet line from the bundle-uri verb.
*
* Returns 0 on success and non-zero on error.
*/
int bundle_uri_parse_line(struct bundle_list *list,
const char *line);
#endif