Merge branch 'rs/unit-tests-test-run'
[git/gitster.git] / bundle-uri.h
blob6dbc780f661bc06bbc9f0badddec91101814349c
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;
46 /**
47 * If the bundle is part of a list with the creationToken
48 * heuristic, then we use this member for sorting the bundles.
50 uint64_t creationToken;
53 #define REMOTE_BUNDLE_INFO_INIT { 0 }
55 enum bundle_list_mode {
56 BUNDLE_MODE_NONE = 0,
57 BUNDLE_MODE_ALL,
58 BUNDLE_MODE_ANY
61 enum bundle_list_heuristic {
62 BUNDLE_HEURISTIC_NONE = 0,
63 BUNDLE_HEURISTIC_CREATIONTOKEN,
65 /* Must be last. */
66 BUNDLE_HEURISTIC__COUNT
69 /**
70 * A bundle_list contains an unordered set of remote_bundle_info structs,
71 * as well as information about the bundle listing, such as version and
72 * mode.
74 struct bundle_list {
75 int version;
76 enum bundle_list_mode mode;
77 struct hashmap bundles;
79 /**
80 * The baseURI of a bundle_list is the URI that provided the list.
82 * In the case of the 'bundle-uri' protocol v2 command, the base
83 * URI is the URI of the Git remote.
85 * Otherwise, the bundle list was downloaded over HTTP from some
86 * known URI. 'baseURI' is set to that value.
88 * The baseURI is used as the base for any relative URIs
89 * advertised by the bundle list at that location.
91 char *baseURI;
93 /**
94 * A list can have a heuristic, which helps reduce the number of
95 * downloaded bundles.
97 enum bundle_list_heuristic heuristic;
100 void init_bundle_list(struct bundle_list *list);
101 void clear_bundle_list(struct bundle_list *list);
103 typedef int (*bundle_iterator)(struct remote_bundle_info *bundle,
104 void *data);
106 int for_all_bundles_in_list(struct bundle_list *list,
107 bundle_iterator iter,
108 void *data);
110 struct FILE;
111 void print_bundle_list(FILE *fp, struct bundle_list *list);
114 * A bundle URI may point to a bundle list where the key=value
115 * pairs are provided in config file format. This method is
116 * exposed publicly for testing purposes.
118 int bundle_uri_parse_config_format(const char *uri,
119 const char *filename,
120 struct bundle_list *list);
123 * Fetch data from the given 'uri' and unbundle the bundle data found
124 * based on that information.
126 * Returns non-zero if no bundle information is found at the given 'uri'.
128 * If the pointer 'has_heuristic' is non-NULL, then the value it points to
129 * will be set to be non-zero if and only if the fetched list has a
130 * heuristic value. Such a value indicates that the list was designed for
131 * incremental fetches.
133 int fetch_bundle_uri(struct repository *r, const char *uri,
134 int *has_heuristic);
137 * Given a bundle list that was already advertised (likely by the
138 * bundle-uri protocol v2 verb) at the given uri, fetch and unbundle the
139 * bundles according to the bundle strategy of that list.
141 * It is expected that the given 'list' is initialized, including its
142 * 'baseURI' value.
144 * Returns non-zero if there was an error trying to download the list
145 * or any of its advertised bundles.
147 int fetch_bundle_list(struct repository *r,
148 struct bundle_list *list);
151 * API for serve.c.
153 int bundle_uri_advertise(struct repository *r, struct strbuf *value);
154 int bundle_uri_command(struct repository *r, struct packet_reader *request);
157 * General API for {transport,connect}.c etc.
161 * Parse a "key=value" packet line from the bundle-uri verb.
163 * Returns 0 on success and non-zero on error.
165 int bundle_uri_parse_line(struct bundle_list *list,
166 const char *line);
168 #endif