]> git.ipfire.org Git - thirdparty/git.git/blame - bundle-uri.h
maintenance(systemd): support the Windows Subsystem for Linux
[thirdparty/git.git] / bundle-uri.h
CommitLineData
53a50892
DS
1#ifndef BUNDLE_URI_H
2#define BUNDLE_URI_H
3
0634f717
DS
4#include "hashmap.h"
5#include "strbuf.h"
6
8b8d9a22 7struct packet_reader;
53a50892 8struct repository;
0634f717
DS
9struct string_list;
10
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.
16 */
17struct remote_bundle_info {
18 struct hashmap_entry ent;
19
20 /**
21 * The 'id' is a name given to the bundle for reference
22 * by other bundle infos.
23 */
24 char *id;
25
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.
30 */
31 char *uri;
c23f5921
DS
32
33 /**
34 * If the bundle has been downloaded, then 'file' is a
35 * filename storing its contents. Otherwise, 'file' is
36 * NULL.
37 */
38 char *file;
39
40 /**
41 * If the bundle has been unbundled successfully, then
42 * this boolean is true.
43 */
44 unsigned unbundled:1;
512fccf8
DS
45
46 /**
47 * If the bundle is part of a list with the creationToken
48 * heuristic, then we use this member for sorting the bundles.
49 */
50 uint64_t creationToken;
0634f717
DS
51};
52
53#define REMOTE_BUNDLE_INFO_INIT { 0 }
54
55enum bundle_list_mode {
56 BUNDLE_MODE_NONE = 0,
57 BUNDLE_MODE_ALL,
58 BUNDLE_MODE_ANY
59};
60
c93c3d2f
DS
61enum bundle_list_heuristic {
62 BUNDLE_HEURISTIC_NONE = 0,
63 BUNDLE_HEURISTIC_CREATIONTOKEN,
64
65 /* Must be last. */
66 BUNDLE_HEURISTIC__COUNT
67};
68
0634f717
DS
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.
73 */
74struct bundle_list {
75 int version;
76 enum bundle_list_mode mode;
77 struct hashmap bundles;
ebc39479
DS
78
79 /**
80 * The baseURI of a bundle_list is the URI that provided the list.
81 *
82 * In the case of the 'bundle-uri' protocol v2 command, the base
83 * URI is the URI of the Git remote.
84 *
85 * Otherwise, the bundle list was downloaded over HTTP from some
86 * known URI. 'baseURI' is set to that value.
87 *
88 * The baseURI is used as the base for any relative URIs
89 * advertised by the bundle list at that location.
90 */
91 char *baseURI;
c93c3d2f
DS
92
93 /**
94 * A list can have a heuristic, which helps reduce the number of
95 * downloaded bundles.
96 */
97 enum bundle_list_heuristic heuristic;
0634f717
DS
98};
99
100void init_bundle_list(struct bundle_list *list);
101void clear_bundle_list(struct bundle_list *list);
102
103typedef int (*bundle_iterator)(struct remote_bundle_info *bundle,
104 void *data);
105
106int for_all_bundles_in_list(struct bundle_list *list,
107 bundle_iterator iter,
108 void *data);
53a50892 109
d796cedb
ÆAB
110struct FILE;
111void print_bundle_list(FILE *fp, struct bundle_list *list);
112
738e5245
DS
113/**
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.
117 */
118int bundle_uri_parse_config_format(const char *uri,
119 const char *filename,
120 struct bundle_list *list);
121
53a50892
DS
122/**
123 * Fetch data from the given 'uri' and unbundle the bundle data found
124 * based on that information.
125 *
126 * Returns non-zero if no bundle information is found at the given 'uri'.
4074d3c7
DS
127 *
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.
53a50892 132 */
4074d3c7
DS
133int fetch_bundle_uri(struct repository *r, const char *uri,
134 int *has_heuristic);
53a50892 135
12b0a14b
DS
136/**
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.
140 *
141 * It is expected that the given 'list' is initialized, including its
142 * 'baseURI' value.
143 *
144 * Returns non-zero if there was an error trying to download the list
145 * or any of its advertised bundles.
146 */
147int fetch_bundle_list(struct repository *r,
148 struct bundle_list *list);
149
8b8d9a22
ÆAB
150/**
151 * API for serve.c.
152 */
153int bundle_uri_advertise(struct repository *r, struct strbuf *value);
154int bundle_uri_command(struct repository *r, struct packet_reader *request);
155
9424e373
ÆAB
156/**
157 * General API for {transport,connect}.c etc.
158 */
159
160/**
161 * Parse a "key=value" packet line from the bundle-uri verb.
162 *
163 * Returns 0 on success and non-zero on error.
164 */
165int bundle_uri_parse_line(struct bundle_list *list,
166 const char *line);
167
53a50892 168#endif