Commit
9e8558a31d896ca1508a8e6febb1e54b04188eef
bundle: get (mostly) rid of `the_repository`
Refactor "bundle.c" so that we don't depend on `the_repository` anymore. This conversion is trivial for most of the part, as we already have a repository available in all calling conexts. The only exception is that we use `get_log_output_encoding()`, which implicitly depends on `the_repository`. Add an `extern` declaration for this function so that we can drop `USE_THE_REPOSITORY_VARIABLE` and not accidentally introduce more uses of `the_repository`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt <ps@pks.im> · 2026-08-21 06:30 UTC · committed by Junio C Hamano
1 file changed,
+21
−11
modified bundle.c
| @@ -1,4 +1,3 @@ | |||
| 1 | - | #define USE_THE_REPOSITORY_VARIABLE | |
| 2 | 1 | #define DISABLE_SIGN_COMPARE_WARNINGS | |
| 3 | 2 | ||
| 4 | 3 | #include "git-compat-util.h" | |
| @@ -21,6 +20,13 @@ | |||
| 21 | 20 | #include "connected.h" | |
| 22 | 21 | #include "write-or-die.h" | |
| 23 | 22 | ||
| 23 | + | /* | |
| 24 | + | * NEEDSWORK: this function implicitly depends on `the_repository` and is not | |
| 25 | + | * available because we dropped USE_THE_REPOSITORY_VARIABLE. We can remove the | |
| 26 | + | * declaration once it's accessible via `repo_config_values`. | |
| 27 | + | */ | |
| 28 | + | extern const char *get_log_output_encoding(void); | |
| 29 | + | ||
| 24 | 30 | static const char v2_bundle_signature[] = "# v2 git bundle\n"; | |
| 25 | 31 | static const char v3_bundle_signature[] = "# v3 git bundle\n"; | |
| 26 | 32 | static struct { | |
| @@ -294,7 +300,8 @@ int list_bundle_refs(struct bundle_header *header, int argc, const char **argv) | |||
| 294 | 300 | return list_refs(&header->references, argc, argv); | |
| 295 | 301 | } | |
| 296 | 302 | ||
| 297 | - | static int is_tag_in_date_range(struct object *tag, struct rev_info *revs) | |
| 303 | + | static int is_tag_in_date_range(struct repository *repo, | |
| 304 | + | struct object *tag, struct rev_info *revs) | |
| 298 | 305 | { | |
| 299 | 306 | size_t size; | |
| 300 | 307 | enum object_type type; | |
| @@ -305,7 +312,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs) | |||
| 305 | 312 | if (revs->max_age == -1 && revs->min_age == -1) | |
| 306 | 313 | goto out; | |
| 307 | 314 | ||
| 308 | - | buf = odb_read_object(the_repository->objects, &tag->oid, &type, &size); | |
| 315 | + | buf = odb_read_object(repo->objects, &tag->oid, &type, &size); | |
| 309 | 316 | if (!buf) | |
| 310 | 317 | goto out; | |
| 311 | 318 | line = memmem(buf, size, "\ntagger ", 8); | |
| @@ -362,7 +369,8 @@ static int write_pack_data(int bundle_fd, struct rev_info *revs, struct strvec * | |||
| 362 | 369 | struct object *object = revs->pending.objects[i].item; | |
| 363 | 370 | if (object->flags & UNINTERESTING) | |
| 364 | 371 | write_or_die(pack_objects.in, "^", 1); | |
| 365 | - | write_or_die(pack_objects.in, oid_to_hex(&object->oid), the_hash_algo->hexsz); | |
| 372 | + | write_or_die(pack_objects.in, oid_to_hex(&object->oid), | |
| 373 | + | revs->repo->hash_algo->hexsz); | |
| 366 | 374 | write_or_die(pack_objects.in, "\n", 1); | |
| 367 | 375 | } | |
| 368 | 376 | close(pack_objects.in); | |
| @@ -395,10 +403,10 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs) | |||
| 395 | 403 | ||
| 396 | 404 | if (e->item->flags & UNINTERESTING) | |
| 397 | 405 | continue; | |
| 398 | - | if (repo_dwim_ref(the_repository, e->name, strlen(e->name), | |
| 406 | + | if (repo_dwim_ref(revs->repo, e->name, strlen(e->name), | |
| 399 | 407 | &oid, &ref, 0) != 1) | |
| 400 | 408 | goto skip_write_ref; | |
| 401 | - | if (refs_read_ref_full(get_main_ref_store(the_repository), e->name, RESOLVE_REF_READING, &oid, &flag)) | |
| 409 | + | if (refs_read_ref_full(get_main_ref_store(revs->repo), e->name, RESOLVE_REF_READING, &oid, &flag)) | |
| 402 | 410 | flag = 0; | |
| 403 | 411 | display_ref = (flag & REF_ISSYMREF) ? e->name : ref; | |
| 404 | 412 | ||
| @@ -406,7 +414,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs) | |||
| 406 | 414 | goto skip_write_ref; | |
| 407 | 415 | ||
| 408 | 416 | if (e->item->type == OBJ_TAG && | |
| 409 | - | !is_tag_in_date_range(e->item, revs)) { | |
| 417 | + | !is_tag_in_date_range(revs->repo, e->item, revs)) { | |
| 410 | 418 | e->item->flags |= UNINTERESTING; | |
| 411 | 419 | goto skip_write_ref; | |
| 412 | 420 | } | |
| @@ -428,7 +436,8 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs) | |||
| 428 | 436 | ||
| 429 | 437 | ref_count++; | |
| 430 | 438 | strset_add(&objects, display_ref); | |
| 431 | - | write_or_die(bundle_fd, oid_to_hex(&e->item->oid), the_hash_algo->hexsz); | |
| 439 | + | write_or_die(bundle_fd, oid_to_hex(&e->item->oid), | |
| 440 | + | revs->repo->hash_algo->hexsz); | |
| 432 | 441 | write_or_die(bundle_fd, " ", 1); | |
| 433 | 442 | write_or_die(bundle_fd, display_ref, strlen(display_ref)); | |
| 434 | 443 | write_or_die(bundle_fd, "\n", 1); | |
| @@ -507,7 +516,7 @@ int create_bundle(struct repository *r, const char *path, | |||
| 507 | 516 | * SHA1. | |
| 508 | 517 | * 2. @filter is required because we parsed an object filter. | |
| 509 | 518 | */ | |
| 510 | - | if (the_hash_algo != &hash_algos[GIT_HASH_SHA1_LEGACY] || revs.filter.choice) | |
| 519 | + | if (r->hash_algo != &hash_algos[GIT_HASH_SHA1_LEGACY] || revs.filter.choice) | |
| 511 | 520 | min_version = 3; | |
| 512 | 521 | ||
| 513 | 522 | if (argc > 1) { | |
| @@ -528,14 +537,15 @@ int create_bundle(struct repository *r, const char *path, | |||
| 528 | 537 | if (version < 2 || version > 3) { | |
| 529 | 538 | die(_("unsupported bundle version %d"), version); | |
| 530 | 539 | } else if (version < min_version) { | |
| 531 | - | die(_("cannot write bundle version %d with algorithm %s"), version, the_hash_algo->name); | |
| 540 | + | die(_("cannot write bundle version %d with algorithm %s"), version, | |
| 541 | + | r->hash_algo->name); | |
| 532 | 542 | } else if (version == 2) { | |
| 533 | 543 | write_or_die(bundle_fd, v2_bundle_signature, strlen(v2_bundle_signature)); | |
| 534 | 544 | } else { | |
| 535 | 545 | const char *capability = "@object-format="; | |
| 536 | 546 | write_or_die(bundle_fd, v3_bundle_signature, strlen(v3_bundle_signature)); | |
| 537 | 547 | write_or_die(bundle_fd, capability, strlen(capability)); | |
| 538 | - | write_or_die(bundle_fd, the_hash_algo->name, strlen(the_hash_algo->name)); | |
| 548 | + | write_or_die(bundle_fd, r->hash_algo->name, strlen(r->hash_algo->name)); | |
| 539 | 549 | write_or_die(bundle_fd, "\n", 1); | |
| 540 | 550 | ||
| 541 | 551 | if (revs.filter.choice) { | |