Compare
b4dedbc0615bddbad6a5bd18345d9da766d95dfa..e4ad79fd9d8984827b2dc304f1ed99fa69e1ad11
submodule-config: stop using `the_hash_algo`
We have two uses of `the_hash_algo` in "submodule-config.c":
- One trivial use in `gitmodules_cb`, which we can convert to use the
hash algorithm of the repository that's already available in the
caller's context.
- One use where we compute the hashmap key of an object ID. We should
only ever get valid, populated object IDs here, and consequently we
can easily adapt that function to use the hash algorithm of the
passed-in object ID.
Adapt both sites accordingly. Safeguard us against the case where the
passed-in object ID is _not_ properly initialized. While this case
shouldn't ever happen, it doesn't hurt to be defensive.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt <ps@pks.im> · 2026-09-11 05:51 UTC · committed by Junio C Hamano
12 files changed,
+106
−83
- builtin/fetch.c
- builtin/grep.c
- builtin/submodule--helper.c
- cache-tree.c
- cache-tree.h
- read-cache-ll.h
- read-cache.c
- submodule-config.c
- submodule-config.h
- submodule.c
- t/helper/test-submodule.c
- unpack-trees.c
modified builtin/fetch.c
| @@ -2681,7 +2681,7 @@ int cmd_fetch(int argc, | |||
| 2681 | 2681 | int *rs = config.recurse_submodules == RECURSE_SUBMODULES_DEFAULT | |
| 2682 | 2682 | ? &config.recurse_submodules : NULL; | |
| 2683 | 2683 | ||
| 2684 | - | fetch_config_from_gitmodules(sfjc, rs); | |
| 2684 | + | fetch_config_from_gitmodules(the_repository, sfjc, rs); | |
| 2685 | 2685 | } | |
| 2686 | 2686 | ||
| 2687 | 2687 | ||
modified builtin/grep.c
| @@ -897,7 +897,7 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec, | |||
| 897 | 897 | if (recurse_submodules) { | |
| 898 | 898 | submodule_free(opt->repo); | |
| 899 | 899 | obj_read_lock(); | |
| 900 | - | gitmodules_config_oid(&real_obj->oid); | |
| 900 | + | gitmodules_config_oid(the_repository, &real_obj->oid); | |
| 901 | 901 | obj_read_unlock(); | |
| 902 | 902 | } | |
| 903 | 903 | if (grep_object(opt, pathspec, real_obj, list->objects[i].name, | |
modified builtin/submodule--helper.c
| @@ -3041,7 +3041,7 @@ static int module_update(int argc, const char **argv, const char *prefix, | |||
| 3041 | 3041 | NULL | |
| 3042 | 3042 | }; | |
| 3043 | 3043 | ||
| 3044 | - | update_clone_config_from_gitmodules(&opt.max_jobs); | |
| 3044 | + | update_clone_config_from_gitmodules(the_repository, &opt.max_jobs); | |
| 3045 | 3045 | repo_config(the_repository, git_update_clone_config, &opt.max_jobs); | |
| 3046 | 3046 | ||
| 3047 | 3047 | argc = parse_options(argc, argv, prefix, module_update_options, | |
| @@ -3255,7 +3255,7 @@ static int module_set_url(int argc, const char **argv, const char *prefix, | |||
| 3255 | 3255 | path); | |
| 3256 | 3256 | ||
| 3257 | 3257 | config_name = xstrfmt("submodule.%s.url", sub->name); | |
| 3258 | - | ret = config_set_in_gitmodules_file_gently(config_name, newurl); | |
| 3258 | + | ret = config_set_in_gitmodules_file_gently(the_repository, config_name, newurl); | |
| 3259 | 3259 | ||
| 3260 | 3260 | if (!ret) { | |
| 3261 | 3261 | repo_read_gitmodules(the_repository, 0); | |
| @@ -3311,7 +3311,7 @@ static int module_set_branch(int argc, const char **argv, const char *prefix, | |||
| 3311 | 3311 | path); | |
| 3312 | 3312 | ||
| 3313 | 3313 | config_name = xstrfmt("submodule.%s.branch", sub->name); | |
| 3314 | - | ret = config_set_in_gitmodules_file_gently(config_name, opt_branch); | |
| 3314 | + | ret = config_set_in_gitmodules_file_gently(the_repository, config_name, opt_branch); | |
| 3315 | 3315 | ||
| 3316 | 3316 | free(config_name); | |
| 3317 | 3317 | return !!ret; | |
| @@ -3510,7 +3510,7 @@ static int config_submodule_in_gitmodules(const char *name, const char *var, con | |||
| 3510 | 3510 | die(_("please make sure that the .gitmodules file is in the working tree")); | |
| 3511 | 3511 | ||
| 3512 | 3512 | key = xstrfmt("submodule.%s.%s", name, var); | |
| 3513 | - | ret = config_set_in_gitmodules_file_gently(key, value); | |
| 3513 | + | ret = config_set_in_gitmodules_file_gently(the_repository, key, value); | |
| 3514 | 3514 | free(key); | |
| 3515 | 3515 | ||
| 3516 | 3516 | return ret; | |
modified cache-tree.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" | |
| @@ -298,12 +297,14 @@ int cache_tree_fully_valid(struct index_state *istate) | |||
| 298 | 297 | istate->cache_tree); | |
| 299 | 298 | } | |
| 300 | 299 | ||
| 301 | - | static int must_check_existence(const struct cache_entry *ce) | |
| 300 | + | static int must_check_existence(const struct cache_entry *ce, void *cb_data) | |
| 302 | 301 | { | |
| 303 | - | return !(repo_has_promisor_remote(the_repository) && ce_skip_worktree(ce)); | |
| 302 | + | struct repository *repo = cb_data; | |
| 303 | + | return !(repo_has_promisor_remote(repo) && ce_skip_worktree(ce)); | |
| 304 | 304 | } | |
| 305 | 305 | ||
| 306 | - | static int update_one(struct cache_tree *it, | |
| 306 | + | static int update_one(struct repository *repo, | |
| 307 | + | struct cache_tree *it, | |
| 307 | 308 | struct cache_entry **cache, | |
| 308 | 309 | int entries, | |
| 309 | 310 | const char *base, | |
| @@ -341,7 +342,7 @@ static int update_one(struct cache_tree *it, | |||
| 341 | 342 | } | |
| 342 | 343 | ||
| 343 | 344 | if (0 <= it->entry_count && | |
| 344 | - | odb_has_object(the_repository->objects, &it->oid, | |
| 345 | + | odb_has_object(repo->objects, &it->oid, | |
| 345 | 346 | ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR)) | |
| 346 | 347 | return it->entry_count; | |
| 347 | 348 | ||
| @@ -382,7 +383,8 @@ static int update_one(struct cache_tree *it, | |||
| 382 | 383 | sub = find_subtree(it, path + baselen, sublen, 1); | |
| 383 | 384 | if (!sub->cache_tree) | |
| 384 | 385 | sub->cache_tree = cache_tree(); | |
| 385 | - | subcnt = update_one(sub->cache_tree, | |
| 386 | + | subcnt = update_one(repo, | |
| 387 | + | sub->cache_tree, | |
| 386 | 388 | cache + i, entries - i, | |
| 387 | 389 | path, | |
| 388 | 390 | baselen + sublen + 1, | |
| @@ -446,10 +448,10 @@ static int update_one(struct cache_tree *it, | |||
| 446 | 448 | } | |
| 447 | 449 | ||
| 448 | 450 | ce_missing_ok = mode == S_IFGITLINK || missing_ok || | |
| 449 | - | !must_check_existence(ce); | |
| 451 | + | !must_check_existence(ce, repo); | |
| 450 | 452 | if (is_null_oid(oid) || | |
| 451 | 453 | (!ce_missing_ok && | |
| 452 | - | !odb_has_object(the_repository->objects, oid, | |
| 454 | + | !odb_has_object(repo->objects, oid, | |
| 453 | 455 | ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR))) { | |
| 454 | 456 | strbuf_release(&buffer); | |
| 455 | 457 | if (expected_missing) | |
| @@ -481,12 +483,12 @@ static int update_one(struct cache_tree *it, | |||
| 481 | 483 | /* | |
| 482 | 484 | * "sub" can be an empty tree if all subentries are i-t-a. | |
| 483 | 485 | */ | |
| 484 | - | if (contains_ita && is_empty_tree_oid(oid, the_repository->hash_algo)) | |
| 486 | + | if (contains_ita && is_empty_tree_oid(oid, repo->hash_algo)) | |
| 485 | 487 | continue; | |
| 486 | 488 | ||
| 487 | 489 | strbuf_grow(&buffer, entlen + 100); | |
| 488 | 490 | strbuf_addf(&buffer, "%o %.*s%c", mode, entlen, path + baselen, '\0'); | |
| 489 | - | strbuf_add(&buffer, oid->hash, the_hash_algo->rawsz); | |
| 491 | + | strbuf_add(&buffer, oid->hash, repo->hash_algo->rawsz); | |
| 490 | 492 | ||
| 491 | 493 | #if DEBUG_CACHE_TREE | |
| 492 | 494 | fprintf(stderr, "cache-tree update-one %o %.*s\n", | |
| @@ -496,16 +498,16 @@ static int update_one(struct cache_tree *it, | |||
| 496 | 498 | ||
| 497 | 499 | if (repair) { | |
| 498 | 500 | struct object_id oid; | |
| 499 | - | hash_object_file(the_hash_algo, buffer.buf, buffer.len, | |
| 501 | + | hash_object_file(repo->hash_algo, buffer.buf, buffer.len, | |
| 500 | 502 | OBJ_TREE, &oid); | |
| 501 | - | if (odb_has_object(the_repository->objects, &oid, ODB_HAS_OBJECT_RECHECK_PACKED)) | |
| 503 | + | if (odb_has_object(repo->objects, &oid, ODB_HAS_OBJECT_RECHECK_PACKED)) | |
| 502 | 504 | oidcpy(&it->oid, &oid); | |
| 503 | 505 | else | |
| 504 | 506 | to_invalidate = 1; | |
| 505 | 507 | } else if (dryrun) { | |
| 506 | - | hash_object_file(the_hash_algo, buffer.buf, buffer.len, | |
| 508 | + | hash_object_file(repo->hash_algo, buffer.buf, buffer.len, | |
| 507 | 509 | OBJ_TREE, &it->oid); | |
| 508 | - | } else if (odb_write_object_ext(the_repository->objects, buffer.buf, buffer.len, OBJ_TREE, | |
| 510 | + | } else if (odb_write_object_ext(repo->objects, buffer.buf, buffer.len, OBJ_TREE, | |
| 509 | 511 | &it->oid, NULL, flags & WRITE_TREE_SILENT ? ODB_WRITE_OBJECT_SILENT : 0)) { | |
| 510 | 512 | strbuf_release(&buffer); | |
| 511 | 513 | return -1; | |
| @@ -523,7 +525,7 @@ static int update_one(struct cache_tree *it, | |||
| 523 | 525 | ||
| 524 | 526 | int cache_tree_update(struct index_state *istate, int flags) | |
| 525 | 527 | { | |
| 526 | - | int inflight = !!the_repository->objects->transaction; | |
| 528 | + | int inflight = !!istate->repo->objects->transaction; | |
| 527 | 529 | struct odb_transaction *transaction; | |
| 528 | 530 | int skip, i; | |
| 529 | 531 | ||
| @@ -535,14 +537,14 @@ int cache_tree_update(struct index_state *istate, int flags) | |||
| 535 | 537 | if (!istate->cache_tree) | |
| 536 | 538 | istate->cache_tree = cache_tree(); | |
| 537 | 539 | ||
| 538 | - | if (!(flags & WRITE_TREE_MISSING_OK) && repo_has_promisor_remote(the_repository)) | |
| 539 | - | prefetch_cache_entries(istate, must_check_existence); | |
| 540 | + | if (!(flags & WRITE_TREE_MISSING_OK) && repo_has_promisor_remote(istate->repo)) | |
| 541 | + | prefetch_cache_entries(istate, must_check_existence, istate->repo); | |
| 540 | 542 | ||
| 541 | 543 | trace_performance_enter(); | |
| 542 | 544 | trace2_region_enter("cache_tree", "update", istate->repo); | |
| 543 | 545 | if (!inflight) | |
| 544 | - | odb_transaction_begin_or_die(the_repository->objects, &transaction, 0); | |
| 545 | - | i = update_one(istate->cache_tree, istate->cache, istate->cache_nr, | |
| 546 | + | odb_transaction_begin_or_die(istate->repo->objects, &transaction, 0); | |
| 547 | + | i = update_one(istate->repo, istate->cache_tree, istate->cache, istate->cache_nr, | |
| 546 | 548 | "", 0, &skip, flags); | |
| 547 | 549 | if (!inflight) | |
| 548 | 550 | odb_transaction_commit_and_finalize_or_die(transaction); | |
| @@ -554,7 +556,8 @@ int cache_tree_update(struct index_state *istate, int flags) | |||
| 554 | 556 | return 0; | |
| 555 | 557 | } | |
| 556 | 558 | ||
| 557 | - | static void write_one(struct strbuf *buffer, struct cache_tree *it, | |
| 559 | + | static void write_one(struct repository *repo, | |
| 560 | + | struct strbuf *buffer, struct cache_tree *it, | |
| 558 | 561 | const char *path, int pathlen) | |
| 559 | 562 | { | |
| 560 | 563 | int i; | |
| @@ -580,7 +583,7 @@ static void write_one(struct strbuf *buffer, struct cache_tree *it, | |||
| 580 | 583 | #endif | |
| 581 | 584 | ||
| 582 | 585 | if (0 <= it->entry_count) { | |
| 583 | - | strbuf_add(buffer, it->oid.hash, the_hash_algo->rawsz); | |
| 586 | + | strbuf_add(buffer, it->oid.hash, repo->hash_algo->rawsz); | |
| 584 | 587 | } | |
| 585 | 588 | for (i = 0; i < it->subtree_nr; i++) { | |
| 586 | 589 | struct cache_tree_sub *down = it->down[i]; | |
| @@ -590,15 +593,16 @@ static void write_one(struct strbuf *buffer, struct cache_tree *it, | |||
| 590 | 593 | prev->name, prev->namelen) <= 0) | |
| 591 | 594 | die("fatal - unsorted cache subtree"); | |
| 592 | 595 | } | |
| 593 | - | write_one(buffer, down->cache_tree, down->name, down->namelen); | |
| 596 | + | write_one(repo, buffer, down->cache_tree, down->name, down->namelen); | |
| 594 | 597 | } | |
| 595 | 598 | } | |
| 596 | 599 | ||
| 597 | - | void cache_tree_write(struct strbuf *sb, struct cache_tree *root) | |
| 600 | + | void cache_tree_write(struct repository *repo, | |
| 601 | + | struct strbuf *sb, struct cache_tree *root) | |
| 598 | 602 | { | |
| 599 | - | trace2_region_enter("cache_tree", "write", the_repository); | |
| 600 | - | write_one(sb, root, "", 0); | |
| 601 | - | trace2_region_leave("cache_tree", "write", the_repository); | |
| 603 | + | trace2_region_enter("cache_tree", "write", repo); | |
| 604 | + | write_one(repo, sb, root, "", 0); | |
| 605 | + | trace2_region_leave("cache_tree", "write", repo); | |
| 602 | 606 | } | |
| 603 | 607 | ||
| 604 | 608 | static int parse_int(const char **ptr, unsigned long *len_p, int *out) | |
| @@ -632,13 +636,14 @@ static int parse_int(const char **ptr, unsigned long *len_p, int *out) | |||
| 632 | 636 | return 0; | |
| 633 | 637 | } | |
| 634 | 638 | ||
| 635 | - | static struct cache_tree *read_one(const char **buffer, unsigned long *size_p) | |
| 639 | + | static struct cache_tree *read_one(struct repository *repo, | |
| 640 | + | const char **buffer, unsigned long *size_p) | |
| 636 | 641 | { | |
| 637 | 642 | const char *buf = *buffer; | |
| 638 | 643 | unsigned long size = *size_p; | |
| 639 | 644 | struct cache_tree *it; | |
| 640 | 645 | int i, subtree_nr; | |
| 641 | - | const unsigned rawsz = the_hash_algo->rawsz; | |
| 646 | + | const unsigned rawsz = repo->hash_algo->rawsz; | |
| 642 | 647 | ||
| 643 | 648 | it = NULL; | |
| 644 | 649 | /* skip name, but make sure name exists */ | |
| @@ -665,7 +670,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p) | |||
| 665 | 670 | if (size < rawsz) | |
| 666 | 671 | goto free_return; | |
| 667 | 672 | oidread(&it->oid, (const unsigned char *)buf, | |
| 668 | - | the_repository->hash_algo); | |
| 673 | + | repo->hash_algo); | |
| 669 | 674 | buf += rawsz; | |
| 670 | 675 | size -= rawsz; | |
| 671 | 676 | } | |
| @@ -693,7 +698,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p) | |||
| 693 | 698 | struct cache_tree_sub *subtree; | |
| 694 | 699 | const char *name = buf; | |
| 695 | 700 | ||
| 696 | - | sub = read_one(&buf, &size); | |
| 701 | + | sub = read_one(repo, &buf, &size); | |
| 697 | 702 | if (!sub) | |
| 698 | 703 | goto free_return; | |
| 699 | 704 | subtree = cache_tree_sub(it, name); | |
| @@ -710,16 +715,17 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p) | |||
| 710 | 715 | return NULL; | |
| 711 | 716 | } | |
| 712 | 717 | ||
| 713 | - | struct cache_tree *cache_tree_read(const char *buffer, unsigned long size) | |
| 718 | + | struct cache_tree *cache_tree_read(struct repository *repo, | |
| 719 | + | const char *buffer, unsigned long size) | |
| 714 | 720 | { | |
| 715 | 721 | struct cache_tree *result; | |
| 716 | 722 | ||
| 717 | 723 | if (buffer[0]) | |
| 718 | 724 | return NULL; /* not the whole tree */ | |
| 719 | 725 | ||
| 720 | - | trace2_region_enter("cache_tree", "read", the_repository); | |
| 721 | - | result = read_one(&buffer, &size); | |
| 722 | - | trace2_region_leave("cache_tree", "read", the_repository); | |
| 726 | + | trace2_region_enter("cache_tree", "read", repo); | |
| 727 | + | result = read_one(repo, &buffer, &size); | |
| 728 | + | trace2_region_leave("cache_tree", "read", repo); | |
| 723 | 729 | ||
| 724 | 730 | return result; | |
| 725 | 731 | } | |
| @@ -810,7 +816,7 @@ int write_index_as_tree(struct object_id *oid, struct index_state *index_state, | |||
| 810 | 816 | hold_lock_file_for_update(&lock_file, index_path, LOCK_DIE_ON_ERROR); | |
| 811 | 817 | ||
| 812 | 818 | entries = read_index_from(index_state, index_path, | |
| 813 | - | repo_get_git_dir(the_repository)); | |
| 819 | + | repo_get_git_dir(index_state->repo)); | |
| 814 | 820 | if (entries < 0) { | |
| 815 | 821 | ret = WRITE_TREE_UNREADABLE_INDEX; | |
| 816 | 822 | goto out; | |
| @@ -866,7 +872,7 @@ static void prime_cache_tree_rec(struct repository *r, | |||
| 866 | 872 | struct cache_tree_sub *sub; | |
| 867 | 873 | struct tree *subtree = lookup_tree(r, &entry.oid); | |
| 868 | 874 | ||
| 869 | - | if (repo_parse_tree(the_repository, subtree) < 0) | |
| 875 | + | if (repo_parse_tree(r, subtree) < 0) | |
| 870 | 876 | exit(128); | |
| 871 | 877 | sub = cache_tree_sub(it, entry.path); | |
| 872 | 878 | sub->cache_tree = cache_tree(); | |
modified cache-tree.h
| @@ -28,8 +28,9 @@ struct cache_tree_sub *cache_tree_sub(struct cache_tree *, const char *); | |||
| 28 | 28 | ||
| 29 | 29 | int cache_tree_subtree_pos(struct cache_tree *it, const char *path, int pathlen); | |
| 30 | 30 | ||
| 31 | - | void cache_tree_write(struct strbuf *, struct cache_tree *root); | |
| 32 | - | struct cache_tree *cache_tree_read(const char *buffer, unsigned long size); | |
| 31 | + | void cache_tree_write(struct repository *repo, struct strbuf *, struct cache_tree *root); | |
| 32 | + | struct cache_tree *cache_tree_read(struct repository *repo, | |
| 33 | + | const char *buffer, unsigned long size); | |
| 33 | 34 | ||
| 34 | 35 | int cache_tree_fully_valid(struct index_state *); | |
| 35 | 36 | int cache_tree_update(struct index_state *, int); | |
modified read-cache-ll.h
| @@ -269,9 +269,10 @@ void validate_cache_entries(const struct index_state *istate); | |||
| 269 | 269 | * the given predicate. This function should only be called if | |
| 270 | 270 | * repo_has_promisor_remote() returns true. | |
| 271 | 271 | */ | |
| 272 | - | typedef int (*must_prefetch_predicate)(const struct cache_entry *); | |
| 272 | + | typedef int (*must_prefetch_predicate)(const struct cache_entry *, void *cb_data); | |
| 273 | 273 | void prefetch_cache_entries(const struct index_state *istate, | |
| 274 | - | must_prefetch_predicate must_prefetch); | |
| 274 | + | must_prefetch_predicate must_prefetch, | |
| 275 | + | void *cb_data); | |
| 275 | 276 | ||
| 276 | 277 | /* Initialize and use the cache information */ | |
| 277 | 278 | struct lock_file; | |
modified read-cache.c
| @@ -1748,7 +1748,7 @@ static int read_index_extension(struct index_state *istate, | |||
| 1748 | 1748 | { | |
| 1749 | 1749 | switch (CACHE_EXT(ext)) { | |
| 1750 | 1750 | case CACHE_EXT_TREE: | |
| 1751 | - | istate->cache_tree = cache_tree_read(data, sz); | |
| 1751 | + | istate->cache_tree = cache_tree_read(istate->repo, data, sz); | |
| 1752 | 1752 | break; | |
| 1753 | 1753 | case CACHE_EXT_RESOLVE_UNDO: | |
| 1754 | 1754 | istate->resolve_undo = resolve_undo_read(data, sz, the_hash_algo); | |
| @@ -3012,7 +3012,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile, | |||
| 3012 | 3012 | !drop_cache_tree && istate->cache_tree) { | |
| 3013 | 3013 | strbuf_reset(&sb); | |
| 3014 | 3014 | ||
| 3015 | - | cache_tree_write(&sb, istate->cache_tree); | |
| 3015 | + | cache_tree_write(istate->repo, &sb, istate->cache_tree); | |
| 3016 | 3016 | err = write_index_ext_header(f, eoie_c, CACHE_EXT_TREE, sb.len) < 0; | |
| 3017 | 3017 | hashwrite(f, sb.buf, sb.len); | |
| 3018 | 3018 | if (err) { | |
| @@ -3733,7 +3733,8 @@ static void write_ieot_extension(struct strbuf *sb, struct index_entry_offset_ta | |||
| 3733 | 3733 | } | |
| 3734 | 3734 | ||
| 3735 | 3735 | void prefetch_cache_entries(const struct index_state *istate, | |
| 3736 | - | must_prefetch_predicate must_prefetch) | |
| 3736 | + | must_prefetch_predicate must_prefetch, | |
| 3737 | + | void *cb_data) | |
| 3737 | 3738 | { | |
| 3738 | 3739 | int i; | |
| 3739 | 3740 | struct oid_array to_fetch = OID_ARRAY_INIT; | |
| @@ -3741,7 +3742,7 @@ void prefetch_cache_entries(const struct index_state *istate, | |||
| 3741 | 3742 | for (i = 0; i < istate->cache_nr; i++) { | |
| 3742 | 3743 | struct cache_entry *ce = istate->cache[i]; | |
| 3743 | 3744 | ||
| 3744 | - | if (S_ISGITLINK(ce->ce_mode) || !must_prefetch(ce)) | |
| 3745 | + | if (S_ISGITLINK(ce->ce_mode) || !must_prefetch(ce, cb_data)) | |
| 3745 | 3746 | continue; | |
| 3746 | 3747 | if (!odb_read_object_info_extended(the_repository->objects, | |
| 3747 | 3748 | &ce->oid, NULL, | |
modified submodule-config.c
| @@ -133,7 +133,9 @@ void submodule_cache_free(struct submodule_cache *cache) | |||
| 133 | 133 | static unsigned int hash_oid_string(const struct object_id *oid, | |
| 134 | 134 | const char *string) | |
| 135 | 135 | { | |
| 136 | - | return memhash(oid->hash, the_hash_algo->rawsz) + strhash(string); | |
| 136 | + | if (oid->algo == GIT_HASH_UNKNOWN) | |
| 137 | + | BUG("hashing an object ID with unknown algorithm"); | |
| 138 | + | return memhash(oid->hash, hash_algos[oid->algo].rawsz) + strhash(string); | |
| 137 | 139 | } | |
| 138 | 140 | ||
| 139 | 141 | static void cache_put_path(struct submodule_cache *cache, | |
| @@ -667,19 +669,20 @@ static int parse_config(const char *var, const char *value, | |||
| 667 | 669 | return ret; | |
| 668 | 670 | } | |
| 669 | 671 | ||
| 670 | - | static int gitmodule_oid_from_commit(const struct object_id *treeish_name, | |
| 672 | + | static int gitmodule_oid_from_commit(struct repository *repo, | |
| 673 | + | const struct object_id *treeish_name, | |
| 671 | 674 | struct object_id *gitmodules_oid, | |
| 672 | 675 | struct strbuf *rev) | |
| 673 | 676 | { | |
| 674 | 677 | int ret = 0; | |
| 675 | 678 | ||
| 676 | 679 | if (is_null_oid(treeish_name)) { | |
| 677 | - | oidclr(gitmodules_oid, the_repository->hash_algo); | |
| 680 | + | oidclr(gitmodules_oid, repo->hash_algo); | |
| 678 | 681 | return 1; | |
| 679 | 682 | } | |
| 680 | 683 | ||
| 681 | 684 | strbuf_addf(rev, "%s:.gitmodules", oid_to_hex(treeish_name)); | |
| 682 | - | if (repo_get_oid(the_repository, rev->buf, gitmodules_oid) >= 0) | |
| 685 | + | if (repo_get_oid(repo, rev->buf, gitmodules_oid) >= 0) | |
| 683 | 686 | ret = 1; | |
| 684 | 687 | ||
| 685 | 688 | return ret; | |
| @@ -689,9 +692,11 @@ static int gitmodule_oid_from_commit(const struct object_id *treeish_name, | |||
| 689 | 692 | * (key) with on-demand reading of the appropriate .gitmodules from | |
| 690 | 693 | * revisions. | |
| 691 | 694 | */ | |
| 692 | - | static const struct submodule *config_from(struct submodule_cache *cache, | |
| 693 | - | const struct object_id *treeish_name, const char *key, | |
| 694 | - | enum lookup_type lookup_type) | |
| 695 | + | static const struct submodule *config_from(struct repository *repo, | |
| 696 | + | struct submodule_cache *cache, | |
| 697 | + | const struct object_id *treeish_name, | |
| 698 | + | const char *key, | |
| 699 | + | enum lookup_type lookup_type) | |
| 695 | 700 | { | |
| 696 | 701 | struct strbuf rev = STRBUF_INIT; | |
| 697 | 702 | size_t config_size; | |
| @@ -718,7 +723,7 @@ static const struct submodule *config_from(struct submodule_cache *cache, | |||
| 718 | 723 | return entry->config; | |
| 719 | 724 | } | |
| 720 | 725 | ||
| 721 | - | if (!gitmodule_oid_from_commit(treeish_name, &oid, &rev)) | |
| 726 | + | if (!gitmodule_oid_from_commit(repo, treeish_name, &oid, &rev)) | |
| 722 | 727 | goto out; | |
| 723 | 728 | ||
| 724 | 729 | switch (lookup_type) { | |
| @@ -732,7 +737,7 @@ static const struct submodule *config_from(struct submodule_cache *cache, | |||
| 732 | 737 | if (submodule) | |
| 733 | 738 | goto out; | |
| 734 | 739 | ||
| 735 | - | config = odb_read_object(the_repository->objects, &oid, | |
| 740 | + | config = odb_read_object(repo->objects, &oid, | |
| 736 | 741 | &type, &config_size); | |
| 737 | 742 | if (!config || type != OBJ_BLOB) | |
| 738 | 743 | goto out; | |
| @@ -821,7 +826,7 @@ static int gitmodules_cb(const char *var, const char *value, | |||
| 821 | 826 | ||
| 822 | 827 | parameter.cache = repo->submodule_cache; | |
| 823 | 828 | parameter.treeish_name = NULL; | |
| 824 | - | parameter.gitmodules_oid = null_oid(the_hash_algo); | |
| 829 | + | parameter.gitmodules_oid = null_oid(repo->hash_algo); | |
| 825 | 830 | parameter.overwrite = 1; | |
| 826 | 831 | ||
| 827 | 832 | return parse_config(var, value, ctx, ¶meter); | |
| @@ -843,21 +848,22 @@ void repo_read_gitmodules(struct repository *repo, int skip_if_read) | |||
| 843 | 848 | repo->submodule_cache->gitmodules_read = 1; | |
| 844 | 849 | } | |
| 845 | 850 | ||
| 846 | - | void gitmodules_config_oid(const struct object_id *commit_oid) | |
| 851 | + | void gitmodules_config_oid(struct repository *repo, | |
| 852 | + | const struct object_id *commit_oid) | |
| 847 | 853 | { | |
| 848 | 854 | struct strbuf rev = STRBUF_INIT; | |
| 849 | 855 | struct object_id oid; | |
| 850 | 856 | ||
| 851 | - | submodule_cache_check_init(the_repository); | |
| 857 | + | submodule_cache_check_init(repo); | |
| 852 | 858 | ||
| 853 | - | if (gitmodule_oid_from_commit(commit_oid, &oid, &rev)) { | |
| 859 | + | if (gitmodule_oid_from_commit(repo, commit_oid, &oid, &rev)) { | |
| 854 | 860 | git_config_from_blob_oid(gitmodules_cb, rev.buf, | |
| 855 | - | the_repository, &oid, the_repository, | |
| 861 | + | repo, &oid, repo, | |
| 856 | 862 | CONFIG_SCOPE_UNKNOWN); | |
| 857 | 863 | } | |
| 858 | 864 | strbuf_release(&rev); | |
| 859 | 865 | ||
| 860 | - | the_repository->submodule_cache->gitmodules_read = 1; | |
| 866 | + | repo->submodule_cache->gitmodules_read = 1; | |
| 861 | 867 | } | |
| 862 | 868 | ||
| 863 | 869 | const struct submodule *submodule_from_name(struct repository *r, | |
| @@ -865,7 +871,7 @@ const struct submodule *submodule_from_name(struct repository *r, | |||
| 865 | 871 | const char *name) | |
| 866 | 872 | { | |
| 867 | 873 | repo_read_gitmodules(r, 1); | |
| 868 | - | return config_from(r->submodule_cache, treeish_name, name, lookup_name); | |
| 874 | + | return config_from(r, r->submodule_cache, treeish_name, name, lookup_name); | |
| 869 | 875 | } | |
| 870 | 876 | ||
| 871 | 877 | const struct submodule *submodule_from_path(struct repository *r, | |
| @@ -873,7 +879,7 @@ const struct submodule *submodule_from_path(struct repository *r, | |||
| 873 | 879 | const char *path) | |
| 874 | 880 | { | |
| 875 | 881 | repo_read_gitmodules(r, 1); | |
| 876 | - | return config_from(r->submodule_cache, treeish_name, path, lookup_path); | |
| 882 | + | return config_from(r, r->submodule_cache, treeish_name, path, lookup_path); | |
| 877 | 883 | } | |
| 878 | 884 | ||
| 879 | 885 | /** | |
| @@ -980,11 +986,12 @@ int print_config_from_gitmodules(struct repository *repo, const char *key) | |||
| 980 | 986 | return 0; | |
| 981 | 987 | } | |
| 982 | 988 | ||
| 983 | - | int config_set_in_gitmodules_file_gently(const char *key, const char *value) | |
| 989 | + | int config_set_in_gitmodules_file_gently(struct repository *repo, | |
| 990 | + | const char *key, const char *value) | |
| 984 | 991 | { | |
| 985 | 992 | int ret; | |
| 986 | 993 | ||
| 987 | - | ret = repo_config_set_in_file_gently(the_repository, GITMODULES_FILE, key, NULL, value); | |
| 994 | + | ret = repo_config_set_in_file_gently(repo, GITMODULES_FILE, key, NULL, value); | |
| 988 | 995 | if (ret < 0) | |
| 989 | 996 | /* Maybe the user already did that, don't error out here */ | |
| 990 | 997 | warning(_("Could not update .gitmodules entry %s"), key); | |
| @@ -1017,13 +1024,15 @@ static int gitmodules_fetch_config(const char *var, const char *value, | |||
| 1017 | 1024 | return 0; | |
| 1018 | 1025 | } | |
| 1019 | 1026 | ||
| 1020 | - | void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules) | |
| 1027 | + | void fetch_config_from_gitmodules(struct repository *repo, | |
| 1028 | + | int *max_children, | |
| 1029 | + | int *recurse_submodules) | |
| 1021 | 1030 | { | |
| 1022 | 1031 | struct fetch_config config = { | |
| 1023 | 1032 | .max_children = max_children, | |
| 1024 | 1033 | .recurse_submodules = recurse_submodules | |
| 1025 | 1034 | }; | |
| 1026 | - | config_from_gitmodules(gitmodules_fetch_config, the_repository, &config); | |
| 1035 | + | config_from_gitmodules(gitmodules_fetch_config, repo, &config); | |
| 1027 | 1036 | } | |
| 1028 | 1037 | ||
| 1029 | 1038 | static int gitmodules_update_clone_config(const char *var, const char *value, | |
| @@ -1036,7 +1045,7 @@ static int gitmodules_update_clone_config(const char *var, const char *value, | |||
| 1036 | 1045 | return 0; | |
| 1037 | 1046 | } | |
| 1038 | 1047 | ||
| 1039 | - | void update_clone_config_from_gitmodules(int *max_jobs) | |
| 1048 | + | void update_clone_config_from_gitmodules(struct repository *repo, int *max_jobs) | |
| 1040 | 1049 | { | |
| 1041 | - | config_from_gitmodules(gitmodules_update_clone_config, the_repository, max_jobs); | |
| 1050 | + | config_from_gitmodules(gitmodules_update_clone_config, repo, max_jobs); | |
| 1042 | 1051 | } | |
modified submodule-config.h
| @@ -57,7 +57,8 @@ int option_fetch_parse_recurse_submodules(const struct option *opt, | |||
| 57 | 57 | int parse_update_recurse_submodules_arg(const char *opt, const char *arg); | |
| 58 | 58 | int parse_push_recurse_submodules_arg(const char *opt, const char *arg); | |
| 59 | 59 | void repo_read_gitmodules(struct repository *repo, int skip_if_read); | |
| 60 | - | void gitmodules_config_oid(const struct object_id *commit_oid); | |
| 60 | + | void gitmodules_config_oid(struct repository *repo, | |
| 61 | + | const struct object_id *commit_oid); | |
| 61 | 62 | ||
| 62 | 63 | /** | |
| 63 | 64 | * Same as submodule_from_path but lookup by name. | |
| @@ -80,7 +81,8 @@ const struct submodule *submodule_from_path(struct repository *r, | |||
| 80 | 81 | void submodule_free(struct repository *r); | |
| 81 | 82 | ||
| 82 | 83 | int print_config_from_gitmodules(struct repository *repo, const char *key); | |
| 83 | - | int config_set_in_gitmodules_file_gently(const char *key, const char *value); | |
| 84 | + | int config_set_in_gitmodules_file_gently(struct repository *repo, | |
| 85 | + | const char *key, const char *value); | |
| 84 | 86 | ||
| 85 | 87 | /* | |
| 86 | 88 | * Returns 0 if the name is syntactically acceptable as a submodule "name" | |
| @@ -100,8 +102,10 @@ int check_submodule_url(const char *url); | |||
| 100 | 102 | * New helpers to retrieve arbitrary configuration from the '.gitmodules' file | |
| 101 | 103 | * should NOT be added. | |
| 102 | 104 | */ | |
| 103 | - | void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules); | |
| 104 | - | void update_clone_config_from_gitmodules(int *max_jobs); | |
| 105 | + | void fetch_config_from_gitmodules(struct repository *repo, | |
| 106 | + | int *max_children, | |
| 107 | + | int *recurse_submodules); | |
| 108 | + | void update_clone_config_from_gitmodules(struct repository *repo, int *max_jobs); | |
| 105 | 109 | ||
| 106 | 110 | /* | |
| 107 | 111 | * Submodule entry that contains relevant information about a | |
modified submodule.c
| @@ -133,7 +133,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath) | |||
| 133 | 133 | strbuf_addstr(&entry, "submodule."); | |
| 134 | 134 | strbuf_addstr(&entry, submodule->name); | |
| 135 | 135 | strbuf_addstr(&entry, ".path"); | |
| 136 | - | ret = config_set_in_gitmodules_file_gently(entry.buf, newpath); | |
| 136 | + | ret = config_set_in_gitmodules_file_gently(the_repository, entry.buf, newpath); | |
| 137 | 137 | strbuf_release(&entry); | |
| 138 | 138 | return ret; | |
| 139 | 139 | } | |
modified t/helper/test-submodule.c
| @@ -168,7 +168,7 @@ static int cmd__submodule_config_set(int argc, const char **argv) | |||
| 168 | 168 | if (!is_writing_gitmodules_ok()) | |
| 169 | 169 | die("please make sure that the .gitmodules file is in the working tree"); | |
| 170 | 170 | ||
| 171 | - | return config_set_in_gitmodules_file_gently(argv[1], argv[2]); | |
| 171 | + | return config_set_in_gitmodules_file_gently(the_repository, argv[1], argv[2]); | |
| 172 | 172 | } | |
| 173 | 173 | usage_with_options(usage, options); | |
| 174 | 174 | } | |
| @@ -188,7 +188,7 @@ static int cmd__submodule_config_unset(int argc, const char **argv) | |||
| 188 | 188 | if (argc == 2) { | |
| 189 | 189 | if (!is_writing_gitmodules_ok()) | |
| 190 | 190 | die("please make sure that the .gitmodules file is in the working tree"); | |
| 191 | - | return config_set_in_gitmodules_file_gently(argv[1], NULL); | |
| 191 | + | return config_set_in_gitmodules_file_gently(the_repository, argv[1], NULL); | |
| 192 | 192 | } | |
| 193 | 193 | usage_with_options(usage, options); | |
| 194 | 194 | } | |
modified unpack-trees.c
| @@ -416,7 +416,8 @@ static void report_collided_checkout(struct index_state *index) | |||
| 416 | 416 | string_list_clear(&list, 0); | |
| 417 | 417 | } | |
| 418 | 418 | ||
| 419 | - | static int must_checkout(const struct cache_entry *ce) | |
| 419 | + | static int must_checkout(const struct cache_entry *ce, | |
| 420 | + | void *cb_data UNUSED) | |
| 420 | 421 | { | |
| 421 | 422 | return ce->ce_flags & CE_UPDATE; | |
| 422 | 423 | } | |
| @@ -477,7 +478,7 @@ static int check_updates(struct unpack_trees_options *o, | |||
| 477 | 478 | * Prefetch the objects that are to be checked out in the loop | |
| 478 | 479 | * below. | |
| 479 | 480 | */ | |
| 480 | - | prefetch_cache_entries(index, must_checkout); | |
| 481 | + | prefetch_cache_entries(index, must_checkout, NULL); | |
| 481 | 482 | ||
| 482 | 483 | get_parallel_checkout_configs(&pc_workers, &pc_threshold); | |
| 483 | 484 | ||
| @@ -487,7 +488,7 @@ static int check_updates(struct unpack_trees_options *o, | |||
| 487 | 488 | for (i = 0; i < index->cache_nr; i++) { | |
| 488 | 489 | struct cache_entry *ce = index->cache[i]; | |
| 489 | 490 | ||
| 490 | - | if (must_checkout(ce)) { | |
| 491 | + | if (must_checkout(ce, NULL)) { | |
| 491 | 492 | size_t last_pc_queue_size = pc_queue_size(); | |
| 492 | 493 | ||
| 493 | 494 | if (ce->ce_flags & CE_WT_REMOVE) | |