Add bundle transport
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Sep 10, 2007 at 23:03 UTC
c7a8a16239c6bdbb4041dd8a8773ae055d3cccf8
1 file changed
+51
-1
transport.c
+51
-1
@@ -5,6 +5,7 @@
5
#include "pkt-line.h"
6
#include "fetch-pack.h"
7
#include "walker.h"
8
+#include "bundle.h"
9
10
/* Generic functions for using commit walkers */
11
@@ -184,7 +185,55 @@ static const struct transport_ops curl_transport = {
185
/* disconnect */ disconnect_walker
186
};
187
188
+struct bundle_transport_data {
189
+ int fd;
190
+ struct bundle_header header;
191
+};
192
+
193
+static struct ref *get_refs_from_bundle(const struct transport *transport)
194
+{
195
+ struct bundle_transport_data *data = transport->data;
196
+ struct ref *result = NULL;
197
+ int i;
198
+
199
+ if (data->fd > 0)
200
+ close(data->fd);
201
+ data->fd = read_bundle_header(transport->url, &data->header);
202
+ if (data->fd < 0)
203
+ die ("Could not read bundle '%s'.", transport->url);
204
+ for (i = 0; i < data->header.references.nr; i++) {
205
+ struct ref_list_entry *e = data->header.references.list + i;
206
+ struct ref *ref = alloc_ref(strlen(e->name));
207
+ hashcpy(ref->old_sha1, e->sha1);
208
+ strcpy(ref->name, e->name);
209
+ ref->next = result;
210
+ result = ref;
211
+ }
212
+ return result;
213
+}
214
+
215
+static int fetch_refs_from_bundle(const struct transport *transport,
216
+ int nr_heads, char **heads)
217
+{
218
+ struct bundle_transport_data *data = transport->data;
219
+ return unbundle(&data->header, data->fd);
220
+}
221
+
222
+static int close_bundle(struct transport *transport)
223
+{
224
+ struct bundle_transport_data *data = transport->data;
225
+ if (data->fd > 0)
226
+ close(data->fd);
227
+ return 0;
228
+}
229
+
230
static const struct transport_ops bundle_transport = {
231
+ /* set_option */ NULL,
232
+ /* get_refs_list */ get_refs_from_bundle,
233
+ /* fetch_refs */ fetch_refs_from_bundle,
234
+ /* fetch_objs */ NULL,
235
+ /* push */ NULL,
236
+ /* disconnect */ close_bundle
237
};
238
239
struct git_transport_data {
@@ -367,8 +416,9 @@ struct transport *transport_get(struct remote *remote, const char *url,
416
else
417
ret->data = NULL;
418
} else if (is_local(url) && is_file(url)) {
419
+ struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
420
ret = xmalloc(sizeof(*ret));
371
- ret->data = NULL;
421
+ ret->data = data;
422
ret->ops = &bundle_transport;
423
} else {
424
struct git_transport_data *data = xcalloc(1, sizeof(*data));