| 476 | } |
| 477 | |
| 478 | int create_bundle(struct repository *r, const char *path, |
| 479 | int argc, const char **argv, struct strvec *pack_options, int version) |
| 480 | { |
| 481 | struct lock_file lock = LOCK_INIT; |
| 482 | int bundle_fd = -1; |
| 483 | int bundle_to_stdout; |
| 484 | int ref_count = 0; |
| 485 | struct rev_info revs, revs_copy; |
| 486 | int min_version = 2; |
| 487 | struct bundle_prerequisites_info bpi; |
| 488 | int ret; |
| 489 | int i; |
| 490 | |
| 491 | /* init revs to list objects for pack-objects later */ |
| 492 | save_commit_buffer = 0; |
| 493 | repo_init_revisions(r, &revs, NULL); |
| 494 | |
| 495 | /* |
| 496 | * Pre-initialize the '--objects' flag so we can parse a |
| 497 | * --filter option successfully. |
| 498 | */ |
| 499 | revs.tree_objects = revs.blob_objects = 1; |
| 500 | |
| 501 | argc = setup_revisions(argc, argv, &revs, NULL); |
| 502 | |
| 503 | /* |
| 504 | * Reasons to require version 3: |
| 505 | * |
| 506 | * 1. @object-format is required because our hash algorithm is not |
| 507 | * SHA1. |
| 508 | * 2. @filter is required because we parsed an object filter. |
| 509 | */ |
| 510 | if (the_hash_algo != &hash_algos[GIT_HASH_SHA1_LEGACY] || revs.filter.choice) |
| 511 | min_version = 3; |
| 512 | |
| 513 | if (argc > 1) { |
| 514 | ret = error(_("unrecognized argument: %s"), argv[1]); |
| 515 | goto out; |
| 516 | } |
| 517 | |
| 518 | bundle_to_stdout = !strcmp(path, "-"); |
| 519 | if (bundle_to_stdout) |
| 520 | bundle_fd = 1; |
| 521 | else |
| 522 | bundle_fd = hold_lock_file_for_update(&lock, path, |
| 523 | LOCK_DIE_ON_ERROR); |
| 524 | |
| 525 | if (version == -1) |
| 526 | version = min_version; |
| 527 | |
| 528 | if (version < 2 || version > 3) { |
| 529 | die(_("unsupported bundle version %d"), version); |
| 530 | } else if (version < min_version) { |
| 531 | die(_("cannot write bundle version %d with algorithm %s"), version, the_hash_algo->name); |
| 532 | } else if (version == 2) { |
| 533 | write_or_die(bundle_fd, v2_bundle_signature, strlen(v2_bundle_signature)); |
| 534 | } else { |
| 535 | const char *capability = "@object-format="; |
no test coverage detected