Skip to content

Commit c7a8a16

Browse files
dschogitster
authored andcommitted
Add bundle transport
Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 30415d5 commit c7a8a16

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

transport.c

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "pkt-line.h"
66
#include "fetch-pack.h"
77
#include "walker.h"
8+
#include "bundle.h"
89

910
/* Generic functions for using commit walkers */
1011

@@ -184,7 +185,55 @@ static const struct transport_ops curl_transport = {
184185
/* disconnect */ disconnect_walker
185186
};
186187

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+
187230
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
188237
};
189238

190239
struct git_transport_data {
@@ -367,8 +416,9 @@ struct transport *transport_get(struct remote *remote, const char *url,
367416
else
368417
ret->data = NULL;
369418
} else if (is_local(url) && is_file(url)) {
419+
struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
370420
ret = xmalloc(sizeof(*ret));
371-
ret->data = NULL;
421+
ret->data = data;
372422
ret->ops = &bundle_transport;
373423
} else {
374424
struct git_transport_data *data = xcalloc(1, sizeof(*data));

0 commit comments

Comments
 (0)