]> git.ipfire.org Git - thirdparty/git.git/blame - bundle.c
treewide: remove cache.h inclusion due to setup.h changes
[thirdparty/git.git] / bundle.c
CommitLineData
30415d50 1#include "cache.h"
697cc8ef 2#include "lockfile.h"
30415d50 3#include "bundle.h"
32a8f510 4#include "environment.h"
f394e093 5#include "gettext.h"
41771fa4 6#include "hex.h"
cbd53a21 7#include "object-store.h"
109cd76d 8#include "repository.h"
30415d50
JS
9#include "object.h"
10#include "commit.h"
11#include "diff.h"
12#include "revision.h"
13#include "list-objects.h"
14#include "run-command.h"
fa303836 15#include "refs.h"
dbbcd44f 16#include "strvec.h"
105c6f14 17#include "list-objects-filter-options.h"
d9fd674c 18#include "connected.h"
c5aecfc8 19
20static const char v2_bundle_signature[] = "# v2 git bundle\n";
21static const char v3_bundle_signature[] = "# v3 git bundle\n";
22static struct {
23 int version;
24 const char *signature;
25} bundle_sigs[] = {
26 { 2, v2_bundle_signature },
27 { 3, v3_bundle_signature },
28};
30415d50 29
10b635b7 30void bundle_header_init(struct bundle_header *header)
30415d50 31{
10b635b7
ÆAB
32 struct bundle_header blank = BUNDLE_HEADER_INIT;
33 memcpy(header, &blank, sizeof(*header));
34}
35
36void bundle_header_release(struct bundle_header *header)
37{
38 string_list_clear(&header->prerequisites, 1);
39 string_list_clear(&header->references, 1);
105c6f14 40 list_objects_filter_release(&header->filter);
30415d50
JS
41}
42
c5aecfc8 43static int parse_capability(struct bundle_header *header, const char *capability)
6161ce7b 44{
c5aecfc8 45 const char *arg;
46 if (skip_prefix(capability, "object-format=", &arg)) {
47 int algo = hash_algo_by_name(arg);
48 if (algo == GIT_HASH_UNKNOWN)
49 return error(_("unrecognized bundle hash algorithm: %s"), arg);
50 header->hash_algo = &hash_algos[algo];
51 return 0;
52 }
105c6f14
DS
53 if (skip_prefix(capability, "filter=", &arg)) {
54 parse_list_objects_filter(&header->filter, arg);
55 return 0;
56 }
c5aecfc8 57 return error(_("unknown capability '%s'"), capability);
58}
6161ce7b 59
c5aecfc8 60static int parse_bundle_signature(struct bundle_header *header, const char *line)
61{
62 int i;
63
64 for (i = 0; i < ARRAY_SIZE(bundle_sigs); i++) {
65 if (!strcmp(line, bundle_sigs[i].signature)) {
66 header->version = bundle_sigs[i].version;
67 return 0;
68 }
69 }
70 return -1;
6161ce7b 71}
72
89c6e450
ÆAB
73int read_bundle_header_fd(int fd, struct bundle_header *header,
74 const char *report_path)
f3fa1838 75{
e9ee84cf 76 struct strbuf buf = STRBUF_INIT;
e9ee84cf 77 int status = 0;
30415d50 78
e9ee84cf 79 /* The bundle header begins with the signature */
5e8617f5 80 if (strbuf_getwholeline_fd(&buf, fd, '\n') ||
c5aecfc8 81 parse_bundle_signature(header, buf.buf)) {
2727b71f 82 if (report_path)
c5aecfc8 83 error(_("'%s' does not look like a v2 or v3 bundle file"),
2727b71f 84 report_path);
e9ee84cf
JH
85 status = -1;
86 goto abort;
30415d50 87 }
e9ee84cf 88
c5aecfc8 89 header->hash_algo = the_hash_algo;
90
e9ee84cf 91 /* The bundle header ends with an empty line */
5e8617f5 92 while (!strbuf_getwholeline_fd(&buf, fd, '\n') &&
e9ee84cf 93 buf.len && buf.buf[0] != '\n') {
b8607f35 94 struct object_id oid;
e9ee84cf 95 int is_prereq = 0;
b8607f35 96 const char *p;
e9ee84cf 97
e9ee84cf 98 strbuf_rtrim(&buf);
30415d50 99
c5aecfc8 100 if (header->version == 3 && *buf.buf == '@') {
101 if (parse_capability(header, buf.buf + 1)) {
6161ce7b 102 status = -1;
103 break;
104 }
c5aecfc8 105 continue;
106 }
107
108 if (*buf.buf == '-') {
109 is_prereq = 1;
110 strbuf_remove(&buf, 0, 1);
6161ce7b 111 }
112
e9ee84cf
JH
113 /*
114 * Tip lines have object name, SP, and refname.
115 * Prerequisites have object name that is optionally
116 * followed by SP and subject line.
117 */
6161ce7b 118 if (parse_oid_hex_algop(buf.buf, &oid, &p, header->hash_algo) ||
b8607f35 119 (*p && !isspace(*p)) ||
120 (!is_prereq && !*p)) {
2727b71f 121 if (report_path)
8a1e7eac 122 error(_("unrecognized header: %s%s (%d)"),
2727b71f 123 (is_prereq ? "-" : ""), buf.buf, (int)buf.len);
e9ee84cf
JH
124 status = -1;
125 break;
126 } else {
10b635b7 127 struct object_id *dup = oiddup(&oid);
e9ee84cf 128 if (is_prereq)
10b635b7 129 string_list_append(&header->prerequisites, "")->util = dup;
e9ee84cf 130 else
10b635b7 131 string_list_append(&header->references, p + 1)->util = dup;
30415d50 132 }
30415d50 133 }
e9ee84cf
JH
134
135 abort:
136 if (status) {
137 close(fd);
138 fd = -1;
30415d50 139 }
e9ee84cf 140 strbuf_release(&buf);
30415d50
JS
141 return fd;
142}
143
2727b71f
JH
144int read_bundle_header(const char *path, struct bundle_header *header)
145{
146 int fd = open(path, O_RDONLY);
147
30415d50 148 if (fd < 0)
8a1e7eac 149 return error(_("could not open '%s'"), path);
89c6e450 150 return read_bundle_header_fd(fd, header, path);
2727b71f
JH
151}
152
153int is_bundle(const char *path, int quiet)
154{
10b635b7 155 struct bundle_header header = BUNDLE_HEADER_INIT;
2727b71f
JH
156 int fd = open(path, O_RDONLY);
157
158 if (fd < 0)
159 return 0;
89c6e450 160 fd = read_bundle_header_fd(fd, &header, quiet ? NULL : path);
2727b71f
JH
161 if (fd >= 0)
162 close(fd);
10b635b7 163 bundle_header_release(&header);
2727b71f 164 return (fd >= 0);
30415d50
JS
165}
166
10b635b7 167static int list_refs(struct string_list *r, int argc, const char **argv)
30415d50
JS
168{
169 int i;
170
171 for (i = 0; i < r->nr; i++) {
15e7c7dc
ÆAB
172 struct object_id *oid;
173 const char *name;
174
30415d50
JS
175 if (argc > 1) {
176 int j;
177 for (j = 1; j < argc; j++)
10b635b7 178 if (!strcmp(r->items[i].string, argv[j]))
30415d50
JS
179 break;
180 if (j == argc)
181 continue;
182 }
15e7c7dc 183
10b635b7
ÆAB
184 oid = r->items[i].util;
185 name = r->items[i].string;
15e7c7dc 186 printf("%s %s\n", oid_to_hex(oid), name);
30415d50
JS
187 }
188 return 0;
189}
190
208acbfb 191/* Remember to update object flag allocation in object.h */
30415d50
JS
192#define PREREQ_MARK (1u<<16)
193
d9fd674c
DS
194struct string_list_iterator {
195 struct string_list *list;
196 size_t cur;
197};
198
199static const struct object_id *iterate_ref_map(void *cb_data)
200{
201 struct string_list_iterator *iter = cb_data;
202
203 if (iter->cur >= iter->list->nr)
204 return NULL;
205
206 return iter->list->items[iter->cur++].util;
207}
208
74ae4b63
NTND
209int verify_bundle(struct repository *r,
210 struct bundle_header *header,
89bd7fed 211 enum verify_bundle_flags flags)
30415d50
JS
212{
213 /*
214 * Do fast check, then if any prereqs are missing then go line by line
215 * to be verbose about the errors
216 */
10b635b7 217 struct string_list *p = &header->prerequisites;
d9fd674c 218 int i, ret = 0;
8a1e7eac 219 const char *message = _("Repository lacks these prerequisite commits:");
d9fd674c
DS
220 struct string_list_iterator iter = {
221 .list = p,
222 };
223 struct check_connected_options opts = {
224 .quiet = 1,
225 };
30415d50 226
c96060b0
DS
227 if (!r || !r->objects || !r->objects->odb)
228 return error(_("need a repository to verify a bundle"));
3bbbe467 229
30415d50 230 for (i = 0; i < p->nr; i++) {
10b635b7
ÆAB
231 struct string_list_item *e = p->items + i;
232 const char *name = e->string;
233 struct object_id *oid = e->util;
15e7c7dc 234 struct object *o = parse_object(r, oid);
d9fd674c 235 if (o)
30415d50 236 continue;
70334fc3
DS
237 ret++;
238 if (flags & VERIFY_BUNDLE_QUIET)
239 continue;
240 if (ret == 1)
9db56f71 241 error("%s", message);
15e7c7dc 242 error("%s %s", oid_to_hex(oid), name);
30415d50 243 }
d9fd674c 244 if (ret)
f196c1e9 245 goto cleanup;
105c6f14 246
d9fd674c
DS
247 if ((ret = check_connected(iterate_ref_map, &iter, &opts)))
248 error(_("some prerequisite commits exist in the object store, "
249 "but are not connected to the repository's history"));
30415d50 250
d9fd674c 251 /* TODO: preserve this verbose language. */
89bd7fed 252 if (flags & VERIFY_BUNDLE_VERBOSE) {
10b635b7 253 struct string_list *r;
30415d50
JS
254
255 r = &header->references;
a02ffe0e 256 printf_ln(Q_("The bundle contains this ref:",
99d60545 257 "The bundle contains these %"PRIuMAX" refs:",
8a1e7eac 258 r->nr),
99d60545 259 (uintmax_t)r->nr);
30415d50 260 list_refs(r, 0, NULL);
105c6f14 261
71ba6b10 262 r = &header->prerequisites;
8c3710fd
JH
263 if (!r->nr) {
264 printf_ln(_("The bundle records a complete history."));
265 } else {
a02ffe0e 266 printf_ln(Q_("The bundle requires this ref:",
99d60545 267 "The bundle requires these %"PRIuMAX" refs:",
8c3710fd 268 r->nr),
99d60545 269 (uintmax_t)r->nr);
8c3710fd
JH
270 list_refs(r, 0, NULL);
271 }
017303eb 272
8ba221e2
DS
273 printf_ln("The bundle uses this hash algorithm: %s",
274 header->hash_algo->name);
017303eb
DS
275 if (header->filter.choice)
276 printf_ln("The bundle uses this filter: %s",
277 list_objects_filter_spec(&header->filter));
30415d50 278 }
f196c1e9 279cleanup:
30415d50
JS
280 return ret;
281}
282
283int list_bundle_refs(struct bundle_header *header, int argc, const char **argv)
284{
285 return list_refs(&header->references, argc, argv);
286}
287
c9a42c4a
JS
288static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
289{
290 unsigned long size;
291 enum object_type type;
64045940 292 char *buf = NULL, *line, *lineend;
dddbad72 293 timestamp_t date;
64045940 294 int result = 1;
c9a42c4a
JS
295
296 if (revs->max_age == -1 && revs->min_age == -1)
64045940 297 goto out;
c9a42c4a 298
b4f5aca4 299 buf = read_object_file(&tag->oid, &type, &size);
c9a42c4a 300 if (!buf)
64045940 301 goto out;
c9a42c4a
JS
302 line = memmem(buf, size, "\ntagger ", 8);
303 if (!line++)
64045940 304 goto out;
2c8544ab
LF
305 lineend = memchr(line, '\n', buf + size - line);
306 line = memchr(line, '>', lineend ? lineend - line : buf + size - line);
c9a42c4a 307 if (!line++)
64045940 308 goto out;
1aeb7e75 309 date = parse_timestamp(line, NULL, 10);
64045940 310 result = (revs->max_age == -1 || revs->max_age < date) &&
c9a42c4a 311 (revs->min_age == -1 || revs->min_age > date);
64045940
RS
312out:
313 free(buf);
314 return result;
c9a42c4a
JS
315}
316
e54c347c 317
2c8ee1f5 318/* Write the pack data to bundle_fd */
ef8d7ac4 319static int write_pack_data(int bundle_fd, struct rev_info *revs, struct strvec *pack_options)
5e626b91
JH
320{
321 struct child_process pack_objects = CHILD_PROCESS_INIT;
322 int i;
323
ef8d7ac4 324 strvec_pushl(&pack_objects.args,
f6d8942b
JK
325 "pack-objects",
326 "--stdout", "--thin", "--delta-base-offset",
327 NULL);
d70a9eb6 328 strvec_pushv(&pack_objects.args, pack_options->v);
f18b512b
DS
329 if (revs->filter.choice)
330 strvec_pushf(&pack_objects.args, "--filter=%s",
331 list_objects_filter_spec(&revs->filter));
5e626b91
JH
332 pack_objects.in = -1;
333 pack_objects.out = bundle_fd;
334 pack_objects.git_cmd = 1;
2c8ee1f5
JK
335
336 /*
337 * start_command() will close our descriptor if it's >1. Duplicate it
338 * to avoid surprising the caller.
339 */
340 if (pack_objects.out > 1) {
341 pack_objects.out = dup(pack_objects.out);
342 if (pack_objects.out < 0) {
343 error_errno(_("unable to dup bundle descriptor"));
344 child_process_clear(&pack_objects);
345 return -1;
346 }
347 }
348
5e626b91
JH
349 if (start_command(&pack_objects))
350 return error(_("Could not spawn pack-objects"));
351
5e626b91
JH
352 for (i = 0; i < revs->pending.nr; i++) {
353 struct object *object = revs->pending.objects[i].item;
354 if (object->flags & UNINTERESTING)
355 write_or_die(pack_objects.in, "^", 1);
703d2d41 356 write_or_die(pack_objects.in, oid_to_hex(&object->oid), the_hash_algo->hexsz);
5e626b91
JH
357 write_or_die(pack_objects.in, "\n", 1);
358 }
359 close(pack_objects.in);
360 if (finish_command(&pack_objects))
361 return error(_("pack-objects died"));
362 return 0;
363}
364
d9362ef9
JK
365/*
366 * Write out bundle refs based on the tips already
367 * parsed into revs.pending. As a side effect, may
368 * manipulate revs.pending to include additional
369 * necessary objects (like tags).
370 *
371 * Returns the number of refs written, or negative
372 * on error.
373 */
374static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
e8eb2512 375{
d9362ef9
JK
376 int i;
377 int ref_count = 0;
b2a6d1c6 378
d9362ef9
JK
379 for (i = 0; i < revs->pending.nr; i++) {
380 struct object_array_entry *e = revs->pending.objects + i;
f2fd0760 381 struct object_id oid;
30415d50 382 char *ref;
fa303836
JH
383 const char *display_ref;
384 int flag;
30415d50
JS
385
386 if (e->item->flags & UNINTERESTING)
387 continue;
f24c30e0 388 if (dwim_ref(e->name, strlen(e->name), &oid, &ref, 0) != 1)
c8a571d8 389 goto skip_write_ref;
34c290a6 390 if (read_ref_full(e->name, RESOLVE_REF_READING, &oid, &flag))
fa303836
JH
391 flag = 0;
392 display_ref = (flag & REF_ISSYMREF) ? e->name : ref;
393
c9a42c4a 394 if (e->item->type == OBJ_TAG &&
d9362ef9 395 !is_tag_in_date_range(e->item, revs)) {
c9a42c4a 396 e->item->flags |= UNINTERESTING;
c8a571d8 397 goto skip_write_ref;
c9a42c4a
JS
398 }
399
30415d50
JS
400 /*
401 * Make sure the refs we wrote out is correct; --max-count and
402 * other limiting options could have prevented all the tips
403 * from getting output.
404 *
405 * Non commit objects such as tags and blobs do not have
406 * this issue as they are not affected by those extra
407 * constraints.
408 */
409 if (!(e->item->flags & SHOWN) && e->item->type == OBJ_COMMIT) {
8a1e7eac 410 warning(_("ref '%s' is excluded by the rev-list options"),
30415d50 411 e->name);
c8a571d8 412 goto skip_write_ref;
30415d50
JS
413 }
414 /*
415 * If you run "git bundle create bndl v1.0..v2.0", the
416 * name of the positive ref is "v2.0" but that is the
417 * commit that is referenced by the tag, and not the tag
418 * itself.
419 */
9001dc2a 420 if (!oideq(&oid, &e->item->oid)) {
30415d50
JS
421 /*
422 * Is this the positive end of a range expressed
423 * in terms of a tag (e.g. v2.0 from the range
424 * "v1.0..v2.0")?
425 */
74ae4b63 426 struct commit *one = lookup_commit_reference(revs->repo, &oid);
30415d50
JS
427 struct object *obj;
428
429 if (e->item == &(one->object)) {
430 /*
431 * Need to include e->name as an
432 * independent ref to the pack-objects
433 * input, so that the tag is included
434 * in the output; otherwise we would
435 * end up triggering "empty bundle"
436 * error.
437 */
c251c83d 438 obj = parse_object_or_die(&oid, e->name);
30415d50 439 obj->flags |= SHOWN;
d9362ef9 440 add_pending_object(revs, obj, e->name);
30415d50 441 }
c8a571d8 442 goto skip_write_ref;
30415d50
JS
443 }
444
445 ref_count++;
703d2d41 446 write_or_die(bundle_fd, oid_to_hex(&e->item->oid), the_hash_algo->hexsz);
30415d50 447 write_or_die(bundle_fd, " ", 1);
fa303836 448 write_or_die(bundle_fd, display_ref, strlen(display_ref));
30415d50 449 write_or_die(bundle_fd, "\n", 1);
c8a571d8 450 skip_write_ref:
30415d50
JS
451 free(ref);
452 }
30415d50
JS
453
454 /* end header */
455 write_or_die(bundle_fd, "\n", 1);
d9362ef9
JK
456 return ref_count;
457}
458
5bb0fd2c
JX
459struct bundle_prerequisites_info {
460 struct object_array *pending;
461 int fd;
462};
463
464static void write_bundle_prerequisites(struct commit *commit, void *data)
465{
466 struct bundle_prerequisites_info *bpi = data;
467 struct object *object;
468 struct pretty_print_context ctx = { 0 };
469 struct strbuf buf = STRBUF_INIT;
470
471 if (!(commit->object.flags & BOUNDARY))
472 return;
473 strbuf_addf(&buf, "-%s ", oid_to_hex(&commit->object.oid));
474 write_or_die(bpi->fd, buf.buf, buf.len);
475
476 ctx.fmt = CMIT_FMT_ONELINE;
477 ctx.output_encoding = get_log_output_encoding();
478 strbuf_reset(&buf);
479 pretty_print_commit(&ctx, commit, &buf);
480 strbuf_trim(&buf);
481
482 object = (struct object *)commit;
483 object->flags |= UNINTERESTING;
484 add_object_array_with_path(object, buf.buf, bpi->pending, S_IFINVALID,
485 NULL);
486 strbuf_addch(&buf, '\n');
487 write_or_die(bpi->fd, buf.buf, buf.len);
488 strbuf_release(&buf);
489}
490
fcb133e9 491int create_bundle(struct repository *r, const char *path,
e0ad9574 492 int argc, const char **argv, struct strvec *pack_options, int version)
d9362ef9 493{
b2275868 494 struct lock_file lock = LOCK_INIT;
d9362ef9
JK
495 int bundle_fd = -1;
496 int bundle_to_stdout;
497 int ref_count = 0;
5bb0fd2c 498 struct rev_info revs, revs_copy;
f18b512b 499 int min_version = 2;
5bb0fd2c
JX
500 struct bundle_prerequisites_info bpi;
501 int i;
d9362ef9 502
f18b512b
DS
503 /* init revs to list objects for pack-objects later */
504 save_commit_buffer = 0;
505 repo_init_revisions(r, &revs, NULL);
506
507 /*
508 * Pre-initialize the '--objects' flag so we can parse a
509 * --filter option successfully.
510 */
511 revs.tree_objects = revs.blob_objects = 1;
512
513 argc = setup_revisions(argc, argv, &revs, NULL);
514
515 /*
516 * Reasons to require version 3:
517 *
518 * 1. @object-format is required because our hash algorithm is not
519 * SHA1.
520 * 2. @filter is required because we parsed an object filter.
521 */
522 if (the_hash_algo != &hash_algos[GIT_HASH_SHA1] || revs.filter.choice)
523 min_version = 3;
524
525 if (argc > 1) {
526 error(_("unrecognized argument: %s"), argv[1]);
527 goto err;
528 }
529
d9362ef9
JK
530 bundle_to_stdout = !strcmp(path, "-");
531 if (bundle_to_stdout)
532 bundle_fd = 1;
2c8ee1f5 533 else
d9362ef9
JK
534 bundle_fd = hold_lock_file_for_update(&lock, path,
535 LOCK_DIE_ON_ERROR);
536
c5aecfc8 537 if (version == -1)
538 version = min_version;
539
540 if (version < 2 || version > 3) {
541 die(_("unsupported bundle version %d"), version);
542 } else if (version < min_version) {
543 die(_("cannot write bundle version %d with algorithm %s"), version, the_hash_algo->name);
544 } else if (version == 2) {
545 write_or_die(bundle_fd, v2_bundle_signature, strlen(v2_bundle_signature));
546 } else {
547 const char *capability = "@object-format=";
548 write_or_die(bundle_fd, v3_bundle_signature, strlen(v3_bundle_signature));
549 write_or_die(bundle_fd, capability, strlen(capability));
550 write_or_die(bundle_fd, the_hash_algo->name, strlen(the_hash_algo->name));
551 write_or_die(bundle_fd, "\n", 1);
d9362ef9 552
f18b512b
DS
553 if (revs.filter.choice) {
554 const char *value = expand_list_objects_filter_spec(&revs.filter);
555 capability = "@filter=";
556 write_or_die(bundle_fd, capability, strlen(capability));
557 write_or_die(bundle_fd, value, strlen(value));
558 write_or_die(bundle_fd, "\n", 1);
559 }
f5ff5fb5 560 }
d9362ef9 561
5bb0fd2c
JX
562 /* save revs.pending in revs_copy for later use */
563 memcpy(&revs_copy, &revs, sizeof(revs));
564 revs_copy.pending.nr = 0;
565 revs_copy.pending.alloc = 0;
566 revs_copy.pending.objects = NULL;
567 for (i = 0; i < revs.pending.nr; i++) {
568 struct object_array_entry *e = revs.pending.objects + i;
569 if (e)
570 add_object_array_with_path(e->item, e->name,
571 &revs_copy.pending,
572 e->mode, e->path);
573 }
d9362ef9 574
5bb0fd2c
JX
575 /* write prerequisites */
576 revs.boundary = 1;
577 if (prepare_revision_walk(&revs))
578 die("revision walk setup failed");
579 bpi.fd = bundle_fd;
580 bpi.pending = &revs_copy.pending;
4f33a634 581
f18b512b
DS
582 /*
583 * Remove any object walking here. We only care about commits and
584 * tags here. The revs_copy has the right instances of these values.
585 */
4f33a634 586 revs.blob_objects = revs.tree_objects = 0;
5bb0fd2c
JX
587 traverse_commit_list(&revs, write_bundle_prerequisites, NULL, &bpi);
588 object_array_remove_duplicates(&revs_copy.pending);
589
590 /* write bundle refs */
591 ref_count = write_bundle_refs(bundle_fd, &revs_copy);
d9362ef9
JK
592 if (!ref_count)
593 die(_("Refusing to create empty bundle."));
594 else if (ref_count < 0)
f5ff5fb5 595 goto err;
30415d50
JS
596
597 /* write pack */
5bb0fd2c 598 if (write_pack_data(bundle_fd, &revs_copy, pack_options))
f5ff5fb5 599 goto err;
4ed7cd3a 600
0f5cdf65
CH
601 if (!bundle_to_stdout) {
602 if (commit_lock_file(&lock))
8a1e7eac 603 die_errno(_("cannot create '%s'"), path);
0f5cdf65 604 }
c20181e3 605 return 0;
f5ff5fb5 606err:
2c8ee1f5 607 rollback_lock_file(&lock);
f5ff5fb5 608 return -1;
30415d50
JS
609}
610
74ae4b63 611int unbundle(struct repository *r, struct bundle_header *header,
89bd7fed
DS
612 int bundle_fd, struct strvec *extra_index_pack_args,
613 enum verify_bundle_flags flags)
30415d50 614{
d3180279 615 struct child_process ip = CHILD_PROCESS_INIT;
53537c6c
ÆAB
616
617 if (verify_bundle(r, header, flags))
618 return -1;
619
7366096d 620 strvec_pushl(&ip.args, "index-pack", "--fix-thin", "--stdin", NULL);
30415d50 621
4f39eb03
DS
622 /* If there is a filter, then we need to create the promisor pack. */
623 if (header->filter.choice)
624 strvec_push(&ip.args, "--promisor=from-bundle");
625
7366096d
ÆAB
626 if (extra_index_pack_args) {
627 strvec_pushv(&ip.args, extra_index_pack_args->v);
628 strvec_clear(extra_index_pack_args);
629 }
be042aff 630
30415d50
JS
631 ip.in = bundle_fd;
632 ip.no_stdout = 1;
633 ip.git_cmd = 1;
634 if (run_command(&ip))
8a1e7eac 635 return error(_("index-pack died"));
30415d50
JS
636 return 0;
637}