Merge branch 'km/send-email-with-v-reroll-count'
[alt-git.git] / bundle-uri.h
blobd5e89f1671caa3717b35242f20b8993cea32d14f
1 #ifndef BUNDLE_URI_H
2 #define BUNDLE_URI_H
4 #include "hashmap.h"
5 #include "strbuf.h"
7 struct packet_reader;
8 struct repository;
9 struct string_list;
11 /**
12 * The remote_bundle_info struct contains information for a single bundle
13 * URI. This may be initialized simply by a given URI or might have
14 * additional metadata associated with it if the bundle was advertised by
15 * a bundle list.
17 struct remote_bundle_info {
18 struct hashmap_entry ent;
20 /**
21 * The 'id' is a name given to the bundle for reference
22 * by other bundle infos.
24 char *id;
26 /**
27 * The 'uri' is the location of the remote bundle so
28 * it can be downloaded on-demand. This will be NULL
29 * if there was no table of contents.
31 char *uri;
33 /**
34 * If the bundle has been downloaded, then 'file' is a
35 * filename storing its contents. Otherwise, 'file' is
36 * NULL.
38 char *file;
40 /**
41 * If the bundle has been unbundled successfully, then
42 * this boolean is true.
44 unsigned unbundled:1;
47 #define REMOTE_BUNDLE_INFO_INIT { 0 }
49 enum bundle_list_mode {
50 BUNDLE_MODE_NONE = 0,
51 BUNDLE_MODE_ALL,
52 BUNDLE_MODE_ANY
55 /**
56 * A bundle_list contains an unordered set of remote_bundle_info structs,
57 * as well as information about the bundle listing, such as version and
58 * mode.
60 struct bundle_list {
61 int version;
62 enum bundle_list_mode mode;
63 struct hashmap bundles;
65 /**
66 * The baseURI of a bundle_list is the URI that provided the list.
68 * In the case of the 'bundle-uri' protocol v2 command, the base
69 * URI is the URI of the Git remote.
71 * Otherwise, the bundle list was downloaded over HTTP from some
72 * known URI. 'baseURI' is set to that value.
74 * The baseURI is used as the base for any relative URIs
75 * advertised by the bundle list at that location.
77 char *baseURI;
80 void init_bundle_list(struct bundle_list *list);
81 void clear_bundle_list(struct bundle_list *list);
83 typedef int (*bundle_iterator)(struct remote_bundle_info *bundle,
84 void *data);
86 int for_all_bundles_in_list(struct bundle_list *list,
87 bundle_iterator iter,
88 void *data);
90 struct FILE;
91 void print_bundle_list(FILE *fp, struct bundle_list *list);
93 /**
94 * A bundle URI may point to a bundle list where the key=value
95 * pairs are provided in config file format. This method is
96 * exposed publicly for testing purposes.
98 int bundle_uri_parse_config_format(const char *uri,
99 const char *filename,
100 struct bundle_list *list);
103 * Fetch data from the given 'uri' and unbundle the bundle data found
104 * based on that information.
106 * Returns non-zero if no bundle information is found at the given 'uri'.
108 int fetch_bundle_uri(struct repository *r, const char *uri);
111 * Given a bundle list that was already advertised (likely by the
112 * bundle-uri protocol v2 verb) at the given uri, fetch and unbundle the
113 * bundles according to the bundle strategy of that list.
115 * It is expected that the given 'list' is initialized, including its
116 * 'baseURI' value.
118 * Returns non-zero if there was an error trying to download the list
119 * or any of its advertised bundles.
121 int fetch_bundle_list(struct repository *r,
122 struct bundle_list *list);
125 * API for serve.c.
127 int bundle_uri_advertise(struct repository *r, struct strbuf *value);
128 int bundle_uri_command(struct repository *r, struct packet_reader *request);
131 * General API for {transport,connect}.c etc.
135 * Parse a "key=value" packet line from the bundle-uri verb.
137 * Returns 0 on success and non-zero on error.
139 int bundle_uri_parse_line(struct bundle_list *list,
140 const char *line);
142 #endif