|
5 | 5 | #include "pkt-line.h"
|
6 | 6 | #include "fetch-pack.h"
|
7 | 7 | #include "walker.h"
|
| 8 | +#include "bundle.h" |
8 | 9 |
|
9 | 10 | /* Generic functions for using commit walkers */
|
10 | 11 |
|
@@ -184,7 +185,55 @@ static const struct transport_ops curl_transport = {
|
184 | 185 | /* disconnect */ disconnect_walker
|
185 | 186 | };
|
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 | + |
187 | 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 |
188 | 237 | };
|
189 | 238 |
|
190 | 239 | struct git_transport_data {
|
@@ -367,8 +416,9 @@ struct transport *transport_get(struct remote *remote, const char *url,
|
367 | 416 | else
|
368 | 417 | ret->data = NULL;
|
369 | 418 | } else if (is_local(url) && is_file(url)) {
|
| 419 | + struct bundle_transport_data *data = xcalloc(1, sizeof(*data)); |
370 | 420 | ret = xmalloc(sizeof(*ret));
|
371 |
| - ret->data = NULL; |
| 421 | + ret->data = data; |
372 | 422 | ret->ops = &bundle_transport;
|
373 | 423 | } else {
|
374 | 424 | struct git_transport_data *data = xcalloc(1, sizeof(*data));
|
|
0 commit comments