hash: stop depending on `the_repository` in `null_oid()`

The `null_oid()` function returns the object ID that only consists of zeroes. Naturally, this ID also depends on the hash algorithm used, as the number of zeroes is different between SHA1 and SHA256. Consequently, the function returns the hash-algorithm-specific null object ID. This is currently done by depending on `the_hash_algo`, which implicitly makes us depend on `the_repository`. Refactor the function to instead pass in the hash algorithm for which we want to retrieve the null object ID. Adapt callsites accordingly by passing in `the_repository`, thus bubbling up the dependency on that global variable by one layer. There are a couple of trivial exceptions for subsystems that already got rid of `the_repository`. These subsystems instead use the repository that is available via the calling context: - "builtin/grep.c" - "grep.c" - "refs/debug.c" There are also two non-trivial exceptions: - "diff-no-index.c": Here we know that we may not have a repository initialized at all, so we cannot rely on `the_repository`. Instead, we adapt `diff_no_index()` to get a `struct git_hash_algo` as parameter. The only caller is located in "builtin/diff.c", where we know to call `repo_set_hash_algo()` in case we're running outside of a Git repository. Consequently, it is fine to continue passing `the_repository->hash_algo` even in this case. - "builtin/ls-files.c": There is an in-flight patch series that drops `USE_THE_REPOSITORY_VARIABLE` in this file, which causes a semantic conflict because we use `null_oid()` in `show_submodule()`. The value is passed to `repo_submodule_init()`, which may use the object ID to resolve a tree-ish in the superproject from which we want to read the submodule config. As such, the object ID should refer to an object in the superproject, and consequently we need to use its hash algorithm. This means that we could in theory just not bother about this edge case at all and just use `the_repository` in "diff-no-index.c". But doing so would feel misdesigned. Remove the `USE_THE_REPOSITORY_VARIABLE` preprocessor define in "hash.c". Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Mar 10, 2025 at 08:13 UTC 7d70b29c4f0b2fd3c6698956d9fb4026632d9c6e
48 files changed +136 -136
archive.c
+1 -1
@@ -312,7 +312,7 @@ int write_archive_entries(struct archiver_args *args,
312 struct object_id fake_oid;
313 int i;
314
315 - oidcpy(&fake_oid, null_oid());
315 + oidcpy(&fake_oid, null_oid(the_hash_algo));
316
317 if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
318 size_t len = args->baselen;
blame.c
+1 -1
@@ -255,7 +255,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
255 switch (st.st_mode & S_IFMT) {
256 case S_IFREG:
257 if (opt->flags.allow_textconv &&
258 - textconv_object(r, read_from, mode, null_oid(), 0, &buf_ptr, &buf_len))
258 + textconv_object(r, read_from, mode, null_oid(the_hash_algo), 0, &buf_ptr, &buf_len))
259 strbuf_attach(&buf, buf_ptr, buf_len, buf_len + 1);
260 else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
261 die_errno("cannot open or read '%s'", read_from);
branch.c
+1 -1
@@ -633,7 +633,7 @@ void create_branch(struct repository *r,
633 0, &err);
634 if (!transaction ||
635 ref_transaction_update(transaction, ref.buf,
636 - &oid, forcing ? NULL : null_oid(),
636 + &oid, forcing ? NULL : null_oid(the_hash_algo),
637 NULL, NULL, flags, msg, &err) ||
638 ref_transaction_commit(transaction, &err))
639 die("%s", err.buf);
builtin/checkout.c
+3 -3
@@ -130,8 +130,8 @@ static int post_checkout_hook(struct commit *old_commit, struct commit *new_comm
130 int changed)
131 {
132 return run_hooks_l(the_repository, "post-checkout",
133 - oid_to_hex(old_commit ? &old_commit->object.oid : null_oid()),
134 - oid_to_hex(new_commit ? &new_commit->object.oid : null_oid()),
133 + oid_to_hex(old_commit ? &old_commit->object.oid : null_oid(the_hash_algo)),
134 + oid_to_hex(new_commit ? &new_commit->object.oid : null_oid(the_hash_algo)),
135 changed ? "1" : "0", NULL);
136 /* "new_commit" can be NULL when checking out from the index before
137 a commit exists. */
@@ -710,7 +710,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
710 opts.src_index = the_repository->index;
711 opts.dst_index = the_repository->index;
712 init_checkout_metadata(&opts.meta, info->refname,
713 - info->commit ? &info->commit->object.oid : null_oid(),
713 + info->commit ? &info->commit->object.oid : null_oid(the_hash_algo),
714 NULL);
715 if (parse_tree(tree) < 0)
716 return 128;
builtin/clone.c
+1 -1
@@ -690,7 +690,7 @@ static int checkout(int submodule_progress, int filter_submodules,
690 if (write_locked_index(the_repository->index, &lock_file, COMMIT_LOCK))
691 die(_("unable to write new index file"));
692
693 - err |= run_hooks_l(the_repository, "post-checkout", oid_to_hex(null_oid()),
693 + err |= run_hooks_l(the_repository, "post-checkout", oid_to_hex(null_oid(the_hash_algo)),
694 oid_to_hex(&oid), "1", NULL);
695
696 if (!err && (option_recurse_submodules.nr > 0)) {
builtin/describe.c
+1 -1
@@ -518,7 +518,7 @@ static void describe_blob(struct object_id oid, struct strbuf *dst)
518 {
519 struct rev_info revs;
520 struct strvec args = STRVEC_INIT;
521 - struct process_commit_data pcd = { *null_oid(), oid, dst, &revs};
521 + struct process_commit_data pcd = { *null_oid(the_hash_algo), oid, dst, &revs};
522
523 strvec_pushl(&args, "internal: The first arg is not parsed",
524 "--objects", "--in-commit-order", "--reverse", "HEAD",
builtin/diff.c
+3 -2
@@ -104,7 +104,7 @@ static void builtin_diff_b_f(struct rev_info *revs,
104
105 stuff_change(&revs->diffopt,
106 blob[0]->mode, canon_mode(st.st_mode),
107 - &blob[0]->item->oid, null_oid(),
107 + &blob[0]->item->oid, null_oid(the_hash_algo),
108 1, 0,
109 blob[0]->path ? blob[0]->path : path,
110 path);
@@ -498,7 +498,8 @@ int cmd_diff(int argc,
498
499 /* If this is a no-index diff, just run it and exit there. */
500 if (no_index)
501 - exit(diff_no_index(&rev, no_index == DIFF_NO_INDEX_IMPLICIT,
501 + exit(diff_no_index(&rev, the_repository->hash_algo,
502 + no_index == DIFF_NO_INDEX_IMPLICIT,
503 argc, argv));
504
505
builtin/fast-export.c
+5 -5
@@ -869,7 +869,7 @@ static void handle_tag(const char *name, struct tag *tag)
869 p = rewrite_commit((struct commit *)tagged);
870 if (!p) {
871 printf("reset %s\nfrom %s\n\n",
872 - name, oid_to_hex(null_oid()));
872 + name, oid_to_hex(null_oid(the_hash_algo)));
873 free(buf);
874 return;
875 }
@@ -883,7 +883,7 @@ static void handle_tag(const char *name, struct tag *tag)
883
884 if (tagged->type == OBJ_TAG) {
885 printf("reset %s\nfrom %s\n\n",
886 - name, oid_to_hex(null_oid()));
886 + name, oid_to_hex(null_oid(the_hash_algo)));
887 }
888 skip_prefix(name, "refs/tags/", &name);
889 printf("tag %s\n", name);
@@ -1023,7 +1023,7 @@ static void handle_tags_and_duplicates(struct string_list *extras)
1023 * it.
1024 */
1025 printf("reset %s\nfrom %s\n\n",
1026 - name, oid_to_hex(null_oid()));
1026 + name, oid_to_hex(null_oid(the_hash_algo)));
1027 continue;
1028 }
1029
@@ -1042,7 +1042,7 @@ static void handle_tags_and_duplicates(struct string_list *extras)
1042 if (!reference_excluded_commits) {
1043 /* delete the ref */
1044 printf("reset %s\nfrom %s\n\n",
1045 - name, oid_to_hex(null_oid()));
1045 + name, oid_to_hex(null_oid(the_hash_algo)));
1046 continue;
1047 }
1048 /* set ref to commit using oid, not mark */
@@ -1153,7 +1153,7 @@ static void handle_deletes(void)
1153 continue;
1154
1155 printf("reset %s\nfrom %s\n\n",
1156 - refspec->dst, oid_to_hex(null_oid()));
1156 + refspec->dst, oid_to_hex(null_oid(the_hash_algo)));
1157 }
1158 }
1159
builtin/fsck.c
+1 -1
@@ -625,7 +625,7 @@ static int fsck_loose(const struct object_id *oid, const char *path, void *data)
625 void *contents = NULL;
626 int eaten;
627 struct object_info oi = OBJECT_INFO_INIT;
628 - struct object_id real_oid = *null_oid();
628 + struct object_id real_oid = *null_oid(the_hash_algo);
629 int err = 0;
630
631 strbuf_reset(&cb_data->obj_type);
builtin/grep.c
+1 -1
@@ -453,7 +453,7 @@ static int grep_submodule(struct grep_opt *opt,
453 return 0;
454
455 subrepo = xmalloc(sizeof(*subrepo));
456 - if (repo_submodule_init(subrepo, superproject, path, null_oid())) {
456 + if (repo_submodule_init(subrepo, superproject, path, null_oid(opt->repo->hash_algo))) {
457 free(subrepo);
458 return 0;
459 }
builtin/ls-files.c
+2 -1
@@ -234,7 +234,8 @@ static void show_submodule(struct repository *superproject,
234 {
235 struct repository subrepo;
236
237 - if (repo_submodule_init(&subrepo, superproject, path, null_oid()))
237 + if (repo_submodule_init(&subrepo, superproject, path,
238 + null_oid(superproject->hash_algo)))
239 return;
240
241 if (repo_read_index(&subrepo) < 0)
builtin/rebase.c
+1 -1
@@ -925,7 +925,7 @@ static void fill_branch_base(struct rebase_options *options,
925 options->orig_head, &merge_bases) < 0)
926 exit(128);
927 if (!merge_bases || merge_bases->next)
928 - oidcpy(branch_base, null_oid());
928 + oidcpy(branch_base, null_oid(the_hash_algo));
929 else
930 oidcpy(branch_base, &merge_bases->item->object.oid);
931
builtin/receive-pack.c
+1 -1
@@ -363,7 +363,7 @@ static void write_head_info(void)
363 strvec_clear(&excludes_vector);
364
365 if (!sent_capabilities)
366 - show_ref("capabilities^{}", null_oid());
366 + show_ref("capabilities^{}", null_oid(the_hash_algo));
367
368 advertise_shallow_grafts(1);
369
builtin/submodule--helper.c
+18 -18
@@ -78,7 +78,7 @@ static int get_default_remote_submodule(const char *module_path, char **default_
78 int ret;
79
80 if (repo_submodule_init(&subrepo, the_repository, module_path,
81 - null_oid()) < 0)
81 + null_oid(the_hash_algo)) < 0)
82 return die_message(_("could not get a repository handle for submodule '%s'"),
83 module_path);
84 ret = repo_get_default_remote(&subrepo, default_remote);
@@ -308,7 +308,7 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item,
308 displaypath = get_submodule_displaypath(path, info->prefix,
309 info->super_prefix);
310
311 - sub = submodule_from_path(the_repository, null_oid(), path);
311 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path);
312
313 if (!sub)
314 die(_("No url found for submodule path '%s' in .gitmodules"),
@@ -468,7 +468,7 @@ static void init_submodule(const char *path, const char *prefix,
468
469 displaypath = get_submodule_displaypath(path, prefix, super_prefix);
470
471 - sub = submodule_from_path(the_repository, null_oid(), path);
471 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path);
472
473 if (!sub)
474 die(_("No url found for submodule path '%s' in .gitmodules"),
@@ -645,14 +645,14 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
645 if (validate_submodule_path(path) < 0)
646 exit(128);
647
648 - if (!submodule_from_path(the_repository, null_oid(), path))
648 + if (!submodule_from_path(the_repository, null_oid(the_hash_algo), path))
649 die(_("no submodule mapping found in .gitmodules for path '%s'"),
650 path);
651
652 displaypath = get_submodule_displaypath(path, prefix, super_prefix);
653
654 if ((CE_STAGEMASK & ce_flags) >> CE_STAGESHIFT) {
655 - print_status(flags, 'U', path, null_oid(), displaypath);
655 + print_status(flags, 'U', path, null_oid(the_hash_algo), displaypath);
656 goto cleanup;
657 }
658
@@ -912,7 +912,7 @@ static void generate_submodule_summary(struct summary_cb *info,
912 struct strbuf errmsg = STRBUF_INIT;
913 int total_commits = -1;
914
915 - if (!info->cached && oideq(&p->oid_dst, null_oid())) {
915 + if (!info->cached && oideq(&p->oid_dst, null_oid(the_hash_algo))) {
916 if (S_ISGITLINK(p->mod_dst)) {
917 struct ref_store *refs = repo_get_submodule_ref_store(the_repository,
918 p->sm_path);
@@ -1051,7 +1051,7 @@ static void prepare_submodule_summary(struct summary_cb *info,
1051
1052 if (info->for_status && p->status != 'A' &&
1053 (sub = submodule_from_path(the_repository,
1054 - null_oid(), p->sm_path))) {
1054 + null_oid(the_hash_algo), p->sm_path))) {
1055 char *config_key = NULL;
1056 const char *value;
1057 int ignore_all = 0;
@@ -1259,7 +1259,7 @@ static void sync_submodule(const char *path, const char *prefix,
1259 if (validate_submodule_path(path) < 0)
1260 exit(128);
1261
1262 - sub = submodule_from_path(the_repository, null_oid(), path);
1262 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path);
1263
1264 if (sub && sub->url) {
1265 if (starts_with_dot_dot_slash(sub->url) ||
@@ -1404,7 +1404,7 @@ static void deinit_submodule(const char *path, const char *prefix,
1404 if (validate_submodule_path(path) < 0)
1405 exit(128);
1406
1407 - sub = submodule_from_path(the_repository, null_oid(), path);
1407 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path);
1408
1409 if (!sub || !sub->name)
1410 goto cleanup;
@@ -1929,7 +1929,7 @@ static int determine_submodule_update_strategy(struct repository *r,
1929 enum submodule_update_type update,
1930 struct submodule_update_strategy *out)
1931 {
1932 - const struct submodule *sub = submodule_from_path(r, null_oid(), path);
1932 + const struct submodule *sub = submodule_from_path(r, null_oid(the_hash_algo), path);
1933 char *key;
1934 const char *val;
1935 int ret;
@@ -2089,7 +2089,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
2089 goto cleanup;
2090 }
2091
2092 - sub = submodule_from_path(the_repository, null_oid(), ce->name);
2092 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), ce->name);
2093
2094 if (!sub) {
2095 next_submodule_warn_missing(suc, out, displaypath);
@@ -2485,7 +2485,7 @@ static int remote_submodule_branch(const char *path, const char **branch)
2485 char *key;
2486 *branch = NULL;
2487
2488 - sub = submodule_from_path(the_repository, null_oid(), path);
2488 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path);
2489 if (!sub)
2490 return die_message(_("could not initialize submodule at path '%s'"),
2491 path);
@@ -2531,7 +2531,7 @@ static int ensure_core_worktree(const char *path)
2531 const char *cw;
2532 struct repository subrepo;
2533
2534 - if (repo_submodule_init(&subrepo, the_repository, path, null_oid()))
2534 + if (repo_submodule_init(&subrepo, the_repository, path, null_oid(the_hash_algo)))
2535 return die_message(_("could not get a repository handle for submodule '%s'"),
2536 path);
2537
@@ -2644,7 +2644,7 @@ static int update_submodule(struct update_data *update_data)
2644 return ret;
2645
2646 if (update_data->just_cloned)
2647 - oidcpy(&update_data->suboid, null_oid());
2647 + oidcpy(&update_data->suboid, null_oid(the_hash_algo));
2648 else if (repo_resolve_gitlink_ref(the_repository, update_data->sm_path,
2649 "HEAD", &update_data->suboid))
2650 return die_message(_("Unable to find current revision in submodule path '%s'"),
@@ -2697,8 +2697,8 @@ static int update_submodule(struct update_data *update_data)
2697 struct update_data next = *update_data;
2698
2699 next.prefix = NULL;
2700 - oidcpy(&next.oid, null_oid());
2701 - oidcpy(&next.suboid, null_oid());
2700 + oidcpy(&next.oid, null_oid(the_hash_algo));
2701 + oidcpy(&next.suboid, null_oid(the_hash_algo));
2702
2703 cp.dir = update_data->sm_path;
2704 cp.git_cmd = 1;
@@ -3057,7 +3057,7 @@ static int module_set_url(int argc, const char **argv, const char *prefix,
3057 if (argc != 2 || !(path = argv[0]) || !(newurl = argv[1]))
3058 usage_with_options(usage, options);
3059
3060 - sub = submodule_from_path(the_repository, null_oid(), path);
3060 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path);
3061
3062 if (!sub)
3063 die(_("no submodule mapping found in .gitmodules for path '%s'"),
@@ -3113,7 +3113,7 @@ static int module_set_branch(int argc, const char **argv, const char *prefix,
3113 if (argc != 1 || !(path = argv[0]))
3114 usage_with_options(usage, options);
3115
3116 - sub = submodule_from_path(the_repository, null_oid(), path);
3116 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path);
3117
3118 if (!sub)
3119 die(_("no submodule mapping found in .gitmodules for path '%s'"),
builtin/unpack-objects.c
+1 -1
@@ -505,7 +505,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
505 * has not been resolved yet.
506 */
507 oidclr(&obj_list[nr].oid, the_repository->hash_algo);
508 - add_delta_to_list(nr, null_oid(), base_offset,
508 + add_delta_to_list(nr, null_oid(the_hash_algo), base_offset,
509 delta_data, delta_size);
510 return;
511 }
builtin/update-ref.c
+1 -1
@@ -500,7 +500,7 @@ static void parse_cmd_symref_verify(struct ref_transaction *transaction,
500 */
501 old_target = parse_next_refname(&next);
502 if (!old_target)
503 - oidcpy(&old_oid, null_oid());
503 + oidcpy(&old_oid, null_oid(the_hash_algo));
504
505 if (*next != line_termination)
506 die("symref-verify %s: extra input: %s", refname, next);
builtin/worktree.c
+1 -1
@@ -578,7 +578,7 @@ done:
578
579 strvec_pushl(&opt.env, "GIT_DIR", "GIT_WORK_TREE", NULL);
580 strvec_pushl(&opt.args,
581 - oid_to_hex(null_oid()),
581 + oid_to_hex(null_oid(the_hash_algo)),
582 oid_to_hex(&commit->object.oid),
583 "1",
584 NULL);
combine-diff.c
+1 -1
@@ -1066,7 +1066,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
1066 &result_size, NULL, NULL);
1067 } else if (textconv) {
1068 struct diff_filespec *df = alloc_filespec(elem->path);
1069 - fill_filespec(df, null_oid(), 0, st.st_mode);
1069 + fill_filespec(df, null_oid(the_hash_algo), 0, st.st_mode);
1070 result_size = fill_textconv(opt->repo, textconv, df, &result);
1071 free_filespec(df);
1072 } else if (0 <= (fd = open(elem->path, O_RDONLY))) {
diff-lib.c
+5 -5
@@ -172,7 +172,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
172 * these from (stage - 2).
173 */
174 dpath = combine_diff_path_new(ce->name, ce_namelen(ce),
175 - wt_mode, null_oid(), 2);
175 + wt_mode, null_oid(the_hash_algo), 2);
176
177 while (i < entries) {
178 struct cache_entry *nce = istate->cache[i];
@@ -257,7 +257,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
257 ce_intent_to_add(ce)) {
258 newmode = ce_mode_from_stat(ce, st.st_mode);
259 diff_addremove(&revs->diffopt, '+', newmode,
260 - null_oid(), 0, ce->name, 0);
260 + null_oid(the_hash_algo), 0, ce->name, 0);
261 continue;
262 }
263
@@ -274,7 +274,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
274 }
275 oldmode = ce->ce_mode;
276 old_oid = &ce->oid;
277 - new_oid = changed ? null_oid() : &ce->oid;
277 + new_oid = changed ? null_oid(the_hash_algo) : &ce->oid;
278 diff_change(&revs->diffopt, oldmode, newmode,
279 old_oid, new_oid,
280 !is_null_oid(old_oid),
@@ -330,7 +330,7 @@ static int get_stat_data(const struct cache_entry *ce,
330 0, dirty_submodule);
331 if (changed) {
332 mode = ce_mode_from_stat(ce, st.st_mode);
333 - oid = null_oid();
333 + oid = null_oid(the_hash_algo);
334 }
335 }
336
@@ -402,7 +402,7 @@ static int show_modified(struct rev_info *revs,
402
403 p = combine_diff_path_new(new_entry->name,
404 ce_namelen(new_entry),
405 - mode, null_oid(), 2);
405 + mode, null_oid(the_hash_algo), 2);
406 p->parent[0].status = DIFF_STATUS_MODIFIED;
407 p->parent[0].mode = new_entry->ce_mode;
408 oidcpy(&p->parent[0].oid, &new_entry->oid);
diff-no-index.c
+14 -14
@@ -113,7 +113,8 @@ static void populate_from_stdin(struct diff_filespec *s)
113 populate_common(s, &buf);
114 }
115
116 -static struct diff_filespec *noindex_filespec(const char *name, int mode,
116 +static struct diff_filespec *noindex_filespec(const struct git_hash_algo *algop,
117 + const char *name, int mode,
118 enum special special)
119 {
120 struct diff_filespec *s;
@@ -121,7 +122,7 @@ static struct diff_filespec *noindex_filespec(const char *name, int mode,
122 if (!name)
123 name = "/dev/null";
124 s = alloc_filespec(name);
124 - fill_filespec(s, null_oid(), 0, mode);
125 + fill_filespec(s, null_oid(algop), 0, mode);
126 if (special == SPECIAL_STDIN)
127 populate_from_stdin(s);
128 else if (special == SPECIAL_PIPE)
@@ -129,7 +130,7 @@ static struct diff_filespec *noindex_filespec(const char *name, int mode,
130 return s;
131 }
132
132 -static int queue_diff(struct diff_options *o,
133 +static int queue_diff(struct diff_options *o, const struct git_hash_algo *algop,
134 const char *name1, const char *name2, int recursing)
135 {
136 int mode1 = 0, mode2 = 0;
@@ -145,14 +146,14 @@ static int queue_diff(struct diff_options *o,
146
147 if (S_ISDIR(mode1)) {
148 /* 2 is file that is created */
148 - d1 = noindex_filespec(NULL, 0, SPECIAL_NONE);
149 - d2 = noindex_filespec(name2, mode2, special2);
149 + d1 = noindex_filespec(algop, NULL, 0, SPECIAL_NONE);
150 + d2 = noindex_filespec(algop, name2, mode2, special2);
151 name2 = NULL;
152 mode2 = 0;
153 } else {
154 /* 1 is file that is deleted */
154 - d1 = noindex_filespec(name1, mode1, special1);
155 - d2 = noindex_filespec(NULL, 0, SPECIAL_NONE);
155 + d1 = noindex_filespec(algop, name1, mode1, special1);
156 + d2 = noindex_filespec(algop, NULL, 0, SPECIAL_NONE);
157 name1 = NULL;
158 mode1 = 0;
159 }
@@ -217,7 +218,7 @@ static int queue_diff(struct diff_options *o,
218 n2 = buffer2.buf;
219 }
220
220 - ret = queue_diff(o, n1, n2, 1);
221 + ret = queue_diff(o, algop, n1, n2, 1);
222 }
223 string_list_clear(&p1, 0);
224 string_list_clear(&p2, 0);
@@ -234,8 +235,8 @@ static int queue_diff(struct diff_options *o,
235 SWAP(special1, special2);
236 }
237
237 - d1 = noindex_filespec(name1, mode1, special1);
238 - d2 = noindex_filespec(name2, mode2, special2);
238 + d1 = noindex_filespec(algop, name1, mode1, special1);
239 + d2 = noindex_filespec(algop, name2, mode2, special2);
240 diff_queue(&diff_queued_diff, d1, d2);
241 return 0;
242 }
@@ -297,9 +298,8 @@ static const char * const diff_no_index_usage[] = {
298 NULL
299 };
300
300 -int diff_no_index(struct rev_info *revs,
301 - int implicit_no_index,
302 - int argc, const char **argv)
301 +int diff_no_index(struct rev_info *revs, const struct git_hash_algo *algop,
302 + int implicit_no_index, int argc, const char **argv)
303 {
304 int i, no_index;
305 int ret = 1;
@@ -354,7 +354,7 @@ int diff_no_index(struct rev_info *revs,
354 setup_diff_pager(&revs->diffopt);
355 revs->diffopt.flags.exit_with_status = 1;
356
357 - if (queue_diff(&revs->diffopt, paths[0], paths[1], 0))
357 + if (queue_diff(&revs->diffopt, algop, paths[0], paths[1], 0))
358 goto out;
359 diff_set_mnemonic_prefix(&revs->diffopt, "1/", "2/");
360 diffcore_std(&revs->diffopt);
diff.c
+4 -4
@@ -4346,7 +4346,7 @@ static struct diff_tempfile *prepare_temp_file(struct repository *r,
4346 die_errno("readlink(%s)", one->path);
4347 prep_temp_blob(r->index, one->path, temp, sb.buf, sb.len,
4348 (one->oid_valid ?
4349 - &one->oid : null_oid()),
4349 + &one->oid : null_oid(the_hash_algo)),
4350 (one->oid_valid ?
4351 one->mode : S_IFLNK));
4352 strbuf_release(&sb);
@@ -4355,7 +4355,7 @@ static struct diff_tempfile *prepare_temp_file(struct repository *r,
4355 /* we can borrow from the file in the work tree */
4356 temp->name = one->path;
4357 if (!one->oid_valid)
4358 - oid_to_hex_r(temp->hex, null_oid());
4358 + oid_to_hex_r(temp->hex, null_oid(the_hash_algo));
4359 else
4360 oid_to_hex_r(temp->hex, &one->oid);
4361 /* Even though we may sometimes borrow the
@@ -6649,8 +6649,8 @@ static void create_filepairs_for_header_only_notifications(struct diff_options *
6649
6650 one = alloc_filespec(e->key);
6651 two = alloc_filespec(e->key);
6652 - fill_filespec(one, null_oid(), 0, 0);
6653 - fill_filespec(two, null_oid(), 0, 0);
6652 + fill_filespec(one, null_oid(the_hash_algo), 0, 0);
6653 + fill_filespec(two, null_oid(the_hash_algo), 0, 0);
6654 p = diff_queue(q, one, two);
6655 p->status = DIFF_STATUS_MODIFIED;
6656 }
diff.h
+1 -1
@@ -656,7 +656,7 @@ void flush_one_hunk(struct object_id *result, struct git_hash_ctx *ctx);
656
657 int diff_result_code(struct rev_info *);
658
659 -int diff_no_index(struct rev_info *,
659 +int diff_no_index(struct rev_info *, const struct git_hash_algo *algop,
660 int implicit_no_index, int, const char **);
661
662 int index_differs_from(struct repository *r, const char *def,
dir.c
+1 -1
@@ -4035,7 +4035,7 @@ static void connect_wt_gitdir_in_nested(const char *sub_worktree,
4035 */
4036 i++;
4037
4038 - sub = submodule_from_path(&subrepo, null_oid(), ce->name);
4038 + sub = submodule_from_path(&subrepo, null_oid(the_hash_algo), ce->name);
4039 if (!sub || !is_submodule_active(&subrepo, ce->name))
4040 /* .gitmodules broken or inactive sub */
4041 continue;
grep.c
+1 -1
@@ -1517,7 +1517,7 @@ static int fill_textconv_grep(struct repository *r,
1517 fill_filespec(df, gs->identifier, 1, 0100644);
1518 break;
1519 case GREP_SOURCE_FILE:
1520 - fill_filespec(df, null_oid(), 0, 0100644);
1520 + fill_filespec(df, null_oid(r->hash_algo), 0, 0100644);
1521 break;
1522 default:
1523 BUG("attempt to textconv something without a path?");
hash.c
+2 -4
@@ -1,5 +1,3 @@
1 -#define USE_THE_REPOSITORY_VARIABLE
2 -
1 #include "git-compat-util.h"
2 #include "hash.h"
3 #include "hex.h"
@@ -232,9 +230,9 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
230 }
231 };
232
235 -const struct object_id *null_oid(void)
233 +const struct object_id *null_oid(const struct git_hash_algo *algop)
234 {
237 - return the_hash_algo->null_oid;
235 + return algop->null_oid;
236 }
237
238 const char *empty_tree_oid_hex(const struct git_hash_algo *algop)
hash.h
+1 -1
@@ -340,7 +340,7 @@ static inline int hash_algo_by_ptr(const struct git_hash_algo *p)
340
341 const struct git_hash_algo *unsafe_hash_algo(const struct git_hash_algo *algop);
342
343 -const struct object_id *null_oid(void);
343 +const struct object_id *null_oid(const struct git_hash_algo *algop);
344
345 static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2, const struct git_hash_algo *algop)
346 {
log-tree.c
+1 -1
@@ -499,7 +499,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
499 {
500 struct strbuf headers = STRBUF_INIT;
501 const char *name = oid_to_hex(opt->zero_commit ?
502 - null_oid() : &commit->object.oid);
502 + null_oid(the_hash_algo) : &commit->object.oid);
503
504 *need_8bit_cte_p = 0; /* unknown */
505
merge-ort.c
+13 -13
@@ -1817,7 +1817,7 @@ static int merge_submodule(struct merge_options *opt,
1817 BUG("submodule deleted on one side; this should be handled outside of merge_submodule()");
1818
1819 if ((sub_not_initialized = repo_submodule_init(&subrepo,
1820 - opt->repo, path, null_oid()))) {
1820 + opt->repo, path, null_oid(the_hash_algo)))) {
1821 path_msg(opt, CONFLICT_SUBMODULE_NOT_INITIALIZED, 0,
1822 path, NULL, NULL, NULL,
1823 _("Failed to merge submodule %s (not checked out)"),
@@ -2199,7 +2199,7 @@ static int handle_content_merge(struct merge_options *opt,
2199 two_way = ((S_IFMT & o->mode) != (S_IFMT & a->mode));
2200
2201 merge_status = merge_3way(opt, path,
2202 - two_way ? null_oid() : &o->oid,
2202 + two_way ? null_oid(the_hash_algo) : &o->oid,
2203 &a->oid, &b->oid,
2204 pathnames, extra_marker_size,
2205 &result_buf);
@@ -2231,7 +2231,7 @@ static int handle_content_merge(struct merge_options *opt,
2231 } else if (S_ISGITLINK(a->mode)) {
2232 int two_way = ((S_IFMT & o->mode) != (S_IFMT & a->mode));
2233 clean = merge_submodule(opt, pathnames[0],
2234 - two_way ? null_oid() : &o->oid,
2234 + two_way ? null_oid(the_hash_algo) : &o->oid,
2235 &a->oid, &b->oid, &result->oid);
2236 if (clean < 0)
2237 return -1;
@@ -2739,7 +2739,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
2739 assert(!new_ci->match_mask);
2740 new_ci->dirmask = 0;
2741 new_ci->stages[1].mode = 0;
2742 - oidcpy(&new_ci->stages[1].oid, null_oid());
2742 + oidcpy(&new_ci->stages[1].oid, null_oid(the_hash_algo));
2743
2744 /*
2745 * Now that we have the file information in new_ci, make sure
@@ -2752,7 +2752,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
2752 continue;
2753 /* zero out any entries related to files */
2754 ci->stages[i].mode = 0;
2755 - oidcpy(&ci->stages[i].oid, null_oid());
2755 + oidcpy(&ci->stages[i].oid, null_oid(the_hash_algo));
2756 }
2757
2758 /* Now we want to focus on new_ci, so reassign ci to it. */
@@ -3122,7 +3122,7 @@ static int process_renames(struct merge_options *opt,
3122 if (type_changed) {
3123 /* rename vs. typechange */
3124 /* Mark the original as resolved by removal */
3125 - memcpy(&oldinfo->stages[0].oid, null_oid(),
3125 + memcpy(&oldinfo->stages[0].oid, null_oid(the_hash_algo),
3126 sizeof(oldinfo->stages[0].oid));
3127 oldinfo->stages[0].mode = 0;
3128 oldinfo->filemask &= 0x06;
@@ -3994,7 +3994,7 @@ static int process_entry(struct merge_options *opt,
3994 if (ci->filemask & (1 << i))
3995 continue;
3996 ci->stages[i].mode = 0;
3997 - oidcpy(&ci->stages[i].oid, null_oid());
3997 + oidcpy(&ci->stages[i].oid, null_oid(the_hash_algo));
3998 }
3999 } else if (ci->df_conflict && ci->merged.result.mode != 0) {
4000 /*
@@ -4041,7 +4041,7 @@ static int process_entry(struct merge_options *opt,
4041 continue;
4042 /* zero out any entries related to directories */
4043 new_ci->stages[i].mode = 0;
4044 - oidcpy(&new_ci->stages[i].oid, null_oid());
4044 + oidcpy(&new_ci->stages[i].oid, null_oid(the_hash_algo));
4045 }
4046
4047 /*
@@ -4163,11 +4163,11 @@ static int process_entry(struct merge_options *opt,
4163 new_ci->merged.result.mode = ci->stages[2].mode;
4164 oidcpy(&new_ci->merged.result.oid, &ci->stages[2].oid);
4165 new_ci->stages[1].mode = 0;
4166 - oidcpy(&new_ci->stages[1].oid, null_oid());
4166 + oidcpy(&new_ci->stages[1].oid, null_oid(the_hash_algo));
4167 new_ci->filemask = 5;
4168 if ((S_IFMT & b_mode) != (S_IFMT & o_mode)) {
4169 new_ci->stages[0].mode = 0;
4170 - oidcpy(&new_ci->stages[0].oid, null_oid());
4170 + oidcpy(&new_ci->stages[0].oid, null_oid(the_hash_algo));
4171 new_ci->filemask = 4;
4172 }
4173
@@ -4175,11 +4175,11 @@ static int process_entry(struct merge_options *opt,
4175 ci->merged.result.mode = ci->stages[1].mode;
4176 oidcpy(&ci->merged.result.oid, &ci->stages[1].oid);
4177 ci->stages[2].mode = 0;
4178 - oidcpy(&ci->stages[2].oid, null_oid());
4178 + oidcpy(&ci->stages[2].oid, null_oid(the_hash_algo));
4179 ci->filemask = 3;
4180 if ((S_IFMT & a_mode) != (S_IFMT & o_mode)) {
4181 ci->stages[0].mode = 0;
4182 - oidcpy(&ci->stages[0].oid, null_oid());
4182 + oidcpy(&ci->stages[0].oid, null_oid(the_hash_algo));
4183 ci->filemask = 2;
4184 }
4185
@@ -4304,7 +4304,7 @@ static int process_entry(struct merge_options *opt,
4304 /* Deleted on both sides */
4305 ci->merged.is_null = 1;
4306 ci->merged.result.mode = 0;
4307 - oidcpy(&ci->merged.result.oid, null_oid());
4307 + oidcpy(&ci->merged.result.oid, null_oid(the_hash_algo));
4308 assert(!ci->df_conflict);
4309 ci->merged.clean = !ci->path_conflict;
4310 }
merge-recursive.c
+6 -6
@@ -502,7 +502,7 @@ static int get_tree_entry_if_blob(struct repository *r,
502
503 ret = get_tree_entry(r, tree, path, &dfs->oid, &dfs->mode);
504 if (S_ISDIR(dfs->mode)) {
505 - oidcpy(&dfs->oid, null_oid());
505 + oidcpy(&dfs->oid, null_oid(the_hash_algo));
506 dfs->mode = 0;
507 }
508 return ret;
@@ -1238,7 +1238,7 @@ static int merge_submodule(struct merge_options *opt,
1238 if (is_null_oid(b))
1239 return 0;
1240
1241 - if (repo_submodule_init(&subrepo, opt->repo, path, null_oid())) {
1241 + if (repo_submodule_init(&subrepo, opt->repo, path, null_oid(the_hash_algo))) {
1242 output(opt, 1, _("Failed to merge submodule %s (not checked out)"), path);
1243 return 0;
1244 }
@@ -1698,7 +1698,7 @@ static int handle_file_collision(struct merge_options *opt,
1698
1699 /* Store things in diff_filespecs for functions that need it */
1700 null.path = (char *)collide_path;
1701 - oidcpy(&null.oid, null_oid());
1701 + oidcpy(&null.oid, null_oid(the_hash_algo));
1702 null.mode = 0;
1703
1704 if (merge_mode_and_contents(opt, &null, a, b, collide_path,
@@ -2897,14 +2897,14 @@ static int process_renames(struct merge_options *opt,
2897 dst_other.mode = ren1->dst_entry->stages[other_stage].mode;
2898 try_merge = 0;
2899
2900 - if (oideq(&src_other.oid, null_oid()) &&
2900 + if (oideq(&src_other.oid, null_oid(the_hash_algo)) &&
2901 ren1->dir_rename_original_type == 'A') {
2902 setup_rename_conflict_info(RENAME_VIA_DIR,
2903 opt, ren1, NULL);
2904 } else if (renamed_to_self) {
2905 setup_rename_conflict_info(RENAME_NORMAL,
2906 opt, ren1, NULL);
2907 - } else if (oideq(&src_other.oid, null_oid())) {
2907 + } else if (oideq(&src_other.oid, null_oid(the_hash_algo))) {
2908 setup_rename_conflict_info(RENAME_DELETE,
2909 opt, ren1, NULL);
2910 } else if ((dst_other.mode == ren1->pair->two->mode) &&
@@ -2923,7 +2923,7 @@ static int process_renames(struct merge_options *opt,
2923 1, /* update_cache */
2924 0 /* update_wd */))
2925 clean_merge = -1;
2926 - } else if (!oideq(&dst_other.oid, null_oid())) {
2926 + } else if (!oideq(&dst_other.oid, null_oid(the_hash_algo))) {
2927 /*
2928 * Probably not a clean merge, but it's
2929 * premature to set clean_merge to 0 here,
notes-merge.c
+1 -1
@@ -617,7 +617,7 @@ int notes_merge(struct notes_merge_options *o,
617 if (repo_get_merge_bases(the_repository, local, remote, &bases) < 0)
618 exit(128);
619 if (!bases) {
620 - base_oid = null_oid();
620 + base_oid = null_oid(the_hash_algo);
621 base_tree_oid = the_hash_algo->empty_tree;
622 if (o->verbosity >= 4)
623 printf("No merge base found; doing history-less merge\n");
notes.c
+1 -1
@@ -1353,7 +1353,7 @@ int copy_note(struct notes_tree *t,
1353 if (note)
1354 return add_note(t, to_obj, note, combine_notes);
1355 else if (existing_note)
1356 - return add_note(t, to_obj, null_oid(), combine_notes);
1356 + return add_note(t, to_obj, null_oid(the_hash_algo), combine_notes);
1357
1358 return 0;
1359 }
object-file.c
+1 -1
@@ -2405,7 +2405,7 @@ static int index_mem(struct index_state *istate,
2405
2406 opts.strict = 1;
2407 opts.error_func = hash_format_check_report;
2408 - if (fsck_buffer(null_oid(), type, buf, size, &opts))
2408 + if (fsck_buffer(null_oid(the_hash_algo), type, buf, size, &opts))
2409 die(_("refusing to create malformed object"));
2410 fsck_finish(&opts);
2411 }
parse-options-cb.c
+1 -1
@@ -145,7 +145,7 @@ int parse_opt_object_id(const struct option *opt, const char *arg, int unset)
145 struct object_id *target = opt->value;
146
147 if (unset) {
148 - oidcpy(target, null_oid());
148 + oidcpy(target, null_oid(the_hash_algo));
149 return 0;
150 }
151 if (!arg)
range-diff.c
+1 -1
@@ -467,7 +467,7 @@ static struct diff_filespec *get_filespec(const char *name, const char *p)
467 {
468 struct diff_filespec *spec = alloc_filespec(name);
469
470 - fill_filespec(spec, null_oid(), 0, 0100644);
470 + fill_filespec(spec, null_oid(the_hash_algo), 0, 0100644);
471 spec->data = (char *)p;
472 spec->size = strlen(p);
473 spec->should_munmap = 0;
read-cache.c
+1 -1
@@ -1735,7 +1735,7 @@ static int verify_hdr(const struct cache_header *hdr, unsigned long size)
1735 end = (unsigned char *)hdr + size;
1736 start = end - the_hash_algo->rawsz;
1737 oidread(&oid, start, the_repository->hash_algo);
1738 - if (oideq(&oid, null_oid()))
1738 + if (oideq(&oid, null_oid(the_hash_algo)))
1739 return 0;
1740
1741 the_hash_algo->init_fn(&c);
refs.c
+6 -6
@@ -1377,7 +1377,7 @@ int ref_transaction_create(struct ref_transaction *transaction,
1377 return 1;
1378 }
1379 return ref_transaction_update(transaction, refname, new_oid,
1380 - null_oid(), new_target, NULL, flags,
1380 + null_oid(the_hash_algo), new_target, NULL, flags,
1381 msg, err);
1382 }
1383
@@ -1396,7 +1396,7 @@ int ref_transaction_delete(struct ref_transaction *transaction,
1396 if (old_target && !(flags & REF_NO_DEREF))
1397 BUG("delete cannot operate on symrefs with deref mode");
1398 return ref_transaction_update(transaction, refname,
1399 - null_oid(), old_oid,
1399 + null_oid(the_hash_algo), old_oid,
1400 NULL, old_target, flags,
1401 msg, err);
1402 }
@@ -2160,7 +2160,7 @@ struct ref_store *repo_get_submodule_ref_store(struct repository *repo,
2160 subrepo = xmalloc(sizeof(*subrepo));
2161
2162 if (repo_submodule_init(subrepo, repo, submodule,
2163 - null_oid())) {
2163 + null_oid(the_hash_algo))) {
2164 free(subrepo);
2165 goto done;
2166 }
@@ -2345,14 +2345,14 @@ static int run_transaction_hook(struct ref_transaction *transaction,
2345 strbuf_reset(&buf);
2346
2347 if (!(update->flags & REF_HAVE_OLD))
2348 - strbuf_addf(&buf, "%s ", oid_to_hex(null_oid()));
2348 + strbuf_addf(&buf, "%s ", oid_to_hex(null_oid(the_hash_algo)));
2349 else if (update->old_target)
2350 strbuf_addf(&buf, "ref:%s ", update->old_target);
2351 else
2352 strbuf_addf(&buf, "%s ", oid_to_hex(&update->old_oid));
2353
2354 if (!(update->flags & REF_HAVE_NEW))
2355 - strbuf_addf(&buf, "%s ", oid_to_hex(null_oid()));
2355 + strbuf_addf(&buf, "%s ", oid_to_hex(null_oid(the_hash_algo)));
2356 else if (update->new_target)
2357 strbuf_addf(&buf, "ref:%s ", update->new_target);
2358 else
@@ -2794,7 +2794,7 @@ static int migrate_one_ref(const char *refname, const char *referent UNUSED, con
2794 if (ret < 0)
2795 goto done;
2796
2797 - ret = ref_transaction_update(data->transaction, refname, NULL, null_oid(),
2797 + ret = ref_transaction_update(data->transaction, refname, NULL, null_oid(the_hash_algo),
2798 symref_target.buf, NULL,
2799 REF_SKIP_CREATE_REFLOG | REF_NO_DEREF, NULL, data->errbuf);
2800 if (ret < 0)
refs/debug.c
+1 -1
@@ -217,7 +217,7 @@ static int debug_read_raw_ref(struct ref_store *ref_store, const char *refname,
217 struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
218 int res = 0;
219
220 - oidcpy(oid, null_oid());
220 + oidcpy(oid, null_oid(ref_store->repo->hash_algo));
221 res = drefs->refs->be->read_raw_ref(drefs->refs, refname, oid, referent,
222 type, failure_errno);
223
refs/files-backend.c
+1 -1
@@ -1270,7 +1270,7 @@ static void prune_ref(struct files_ref_store *refs, struct ref_to_prune *r)
1270 ref_transaction_add_update(
1271 transaction, r->name,
1272 REF_NO_DEREF | REF_HAVE_NEW | REF_HAVE_OLD | REF_IS_PRUNING,
1273 - null_oid(), &r->oid, NULL, NULL, NULL, NULL);
1273 + null_oid(the_hash_algo), &r->oid, NULL, NULL, NULL, NULL);
1274 if (ref_transaction_commit(transaction, &err))
1275 goto cleanup;
1276
reset.c
+1 -1
@@ -80,7 +80,7 @@ static int update_refs(const struct reset_head_opts *opts,
80 }
81 if (!ret && run_hook)
82 run_hooks_l(the_repository, "post-checkout",
83 - oid_to_hex(head ? head : null_oid()),
83 + oid_to_hex(head ? head : null_oid(the_hash_algo)),
84 oid_to_hex(oid), "1", NULL);
85 strbuf_release(&msg);
86 return ret;
sequencer.c
+5 -5
@@ -265,8 +265,8 @@ static struct update_ref_record *init_update_ref_record(const char *ref)
265
266 CALLOC_ARRAY(rec, 1);
267
268 - oidcpy(&rec->before, null_oid());
269 - oidcpy(&rec->after, null_oid());
268 + oidcpy(&rec->before, null_oid(the_hash_algo));
269 + oidcpy(&rec->after, null_oid(the_hash_algo));
270
271 /* This may fail, but that's fine, we will keep the null OID. */
272 refs_read_ref(get_main_ref_store(the_repository), ref, &rec->before);
@@ -667,7 +667,7 @@ static int fast_forward_to(struct repository *r,
667 if (!transaction ||
668 ref_transaction_update(transaction, "HEAD",
669 to, unborn && !is_rebase_i(opts) ?
670 - null_oid() : from, NULL, NULL,
670 + null_oid(the_hash_algo) : from, NULL, NULL,
671 0, sb.buf, &err) ||
672 ref_transaction_commit(transaction, &err)) {
673 ref_transaction_free(transaction);
@@ -1301,7 +1301,7 @@ int update_head_with_reflog(const struct commit *old_head,
1301 0, err);
1302 if (!transaction ||
1303 ref_transaction_update(transaction, "HEAD", new_head,
1304 - old_head ? &old_head->object.oid : null_oid(),
1304 + old_head ? &old_head->object.oid : null_oid(the_hash_algo),
1305 NULL, NULL, 0, sb.buf, err) ||
1306 ref_transaction_commit(transaction, err)) {
1307 ret = -1;
@@ -4683,7 +4683,7 @@ static void create_autostash_internal(struct repository *r,
4683 write_file(path, "%s", oid_to_hex(&oid));
4684 } else {
4685 refs_update_ref(get_main_ref_store(r), "", refname,
4686 - &oid, null_oid(), 0, UPDATE_REFS_DIE_ON_ERR);
4686 + &oid, null_oid(the_hash_algo), 0, UPDATE_REFS_DIE_ON_ERR);
4687 }
4688
4689 printf(_("Created autostash: %s\n"), buf.buf);
submodule-config.c
+1 -1
@@ -831,7 +831,7 @@ static int gitmodules_cb(const char *var, const char *value,
831
832 parameter.cache = repo->submodule_cache;
833 parameter.treeish_name = NULL;
834 - parameter.gitmodules_oid = null_oid();
834 + parameter.gitmodules_oid = null_oid(the_hash_algo);
835 parameter.overwrite = 1;
836
837 return parse_config(var, value, ctx, &parameter);
submodule.c
+14 -14
@@ -124,7 +124,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
124 if (is_gitmodules_unmerged(the_repository->index))
125 die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
126
127 - submodule = submodule_from_path(the_repository, null_oid(), oldpath);
127 + submodule = submodule_from_path(the_repository, null_oid(the_hash_algo), oldpath);
128 if (!submodule || !submodule->name) {
129 warning(_("Could not find section in .gitmodules where path=%s"), oldpath);
130 return -1;
@@ -153,7 +153,7 @@ int remove_path_from_gitmodules(const char *path)
153 if (is_gitmodules_unmerged(the_repository->index))
154 die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
155
156 - submodule = submodule_from_path(the_repository, null_oid(), path);
156 + submodule = submodule_from_path(the_repository, null_oid(the_hash_algo), path);
157 if (!submodule || !submodule->name) {
158 warning(_("Could not find section in .gitmodules where path=%s"), path);
159 return -1;
@@ -204,7 +204,7 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
204 const char *path)
205 {
206 const struct submodule *submodule = submodule_from_path(the_repository,
207 - null_oid(),
207 + null_oid(the_hash_algo),
208 path);
209 if (submodule) {
210 const char *ignore;
@@ -312,7 +312,7 @@ int is_tree_submodule_active(struct repository *repo,
312
313 int is_submodule_active(struct repository *repo, const char *path)
314 {
315 - return is_tree_submodule_active(repo, null_oid(), path);
315 + return is_tree_submodule_active(repo, null_oid(the_hash_algo), path);
316 }
317
318 int is_submodule_populated_gently(const char *path, int *return_error_code)
@@ -778,7 +778,7 @@ const struct submodule *submodule_from_ce(const struct cache_entry *ce)
778 if (!should_update_submodules())
779 return NULL;
780
781 - return submodule_from_path(the_repository, null_oid(), ce->name);
781 + return submodule_from_path(the_repository, null_oid(the_hash_algo), ce->name);
782 }
783
784
@@ -1062,7 +1062,7 @@ static int submodule_needs_pushing(struct repository *r,
1062 const char *path,
1063 struct oid_array *commits)
1064 {
1065 - if (!submodule_has_commits(r, path, null_oid(), commits))
1065 + if (!submodule_has_commits(r, path, null_oid(the_hash_algo), commits))
1066 /*
1067 * NOTE: We do consider it safe to return "no" here. The
1068 * correct answer would be "We do not know" instead of
@@ -1126,7 +1126,7 @@ int find_unpushed_submodules(struct repository *r,
1126 const struct submodule *submodule;
1127 const char *path = NULL;
1128
1129 - submodule = submodule_from_name(r, null_oid(), name->string);
1129 + submodule = submodule_from_name(r, null_oid(the_hash_algo), name->string);
1130 if (submodule)
1131 path = submodule->path;
1132 else
@@ -1351,7 +1351,7 @@ static void calculate_changed_submodule_paths(struct repository *r,
1351 const struct submodule *submodule;
1352 const char *path = NULL;
1353
1354 - submodule = submodule_from_name(r, null_oid(), name->string);
1354 + submodule = submodule_from_name(r, null_oid(the_hash_algo), name->string);
1355 if (submodule)
1356 path = submodule->path;
1357 else
@@ -1360,7 +1360,7 @@ static void calculate_changed_submodule_paths(struct repository *r,
1360 if (!path)
1361 continue;
1362
1363 - if (submodule_has_commits(r, path, null_oid(), &cs_data->new_commits)) {
1363 + if (submodule_has_commits(r, path, null_oid(the_hash_algo), &cs_data->new_commits)) {
1364 changed_submodule_data_clear(cs_data);
1365 *name->string = '\0';
1366 }
@@ -1602,7 +1602,7 @@ get_fetch_task_from_index(struct submodule_parallel_fetch *spf,
1602 if (!S_ISGITLINK(ce->ce_mode))
1603 continue;
1604
1605 - task = fetch_task_create(spf, ce->name, null_oid());
1605 + task = fetch_task_create(spf, ce->name, null_oid(the_hash_algo));
1606 if (!task)
1607 continue;
1608
@@ -2166,7 +2166,7 @@ int submodule_move_head(const char *path, const char *super_prefix,
2166 if (old_head && !is_submodule_populated_gently(path, error_code_ptr))
2167 return 0;
2168
2169 - sub = submodule_from_path(the_repository, null_oid(), path);
2169 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path);
2170
2171 if (!sub)
2172 BUG("could not get submodule information for '%s'", path);
@@ -2376,7 +2376,7 @@ static void relocate_single_git_dir_into_superproject(const char *path,
2376
2377 real_old_git_dir = real_pathdup(old_git_dir, 1);
2378
2379 - sub = submodule_from_path(the_repository, null_oid(), path);
2379 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path);
2380 if (!sub)
2381 die(_("could not lookup name for submodule '%s'"), path);
2382
@@ -2462,7 +2462,7 @@ void absorb_git_dir_into_superproject(const char *path,
2462 * superproject did not rewrite the git file links yet,
2463 * fix it now.
2464 */
2465 - sub = submodule_from_path(the_repository, null_oid(), path);
2465 + sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path);
2466 if (!sub)
2467 die(_("could not lookup name for submodule '%s'"), path);
2468 submodule_name_to_gitdir(&sub_gitdir, the_repository, sub->name);
@@ -2594,7 +2594,7 @@ int submodule_to_gitdir(struct repository *repo,
2594 strbuf_addstr(buf, git_dir);
2595 }
2596 if (!is_git_directory(buf->buf)) {
2597 - sub = submodule_from_path(repo, null_oid(), submodule);
2597 + sub = submodule_from_path(repo, null_oid(the_hash_algo), submodule);
2598 if (!sub) {
2599 ret = -1;
2600 goto cleanup;
t/helper/test-ref-store.c
+1 -1
@@ -179,7 +179,7 @@ static int cmd_for_each_ref__exclude(struct ref_store *refs, const char **argv)
179
180 static int cmd_resolve_ref(struct ref_store *refs, const char **argv)
181 {
182 - struct object_id oid = *null_oid();
182 + struct object_id oid = *null_oid(the_hash_algo);
183 const char *refname = notnull(*argv++, "refname");
184 int resolve_flags = arg_flags(*argv++, "resolve-flags", empty_flags);
185 int flags;
t/helper/test-submodule-nested-repo-config.c
+1 -1
@@ -21,7 +21,7 @@ int cmd__submodule_nested_repo_config(int argc, const char **argv)
21
22 setup_git_directory();
23
24 - if (repo_submodule_init(&subrepo, the_repository, argv[1], null_oid())) {
24 + if (repo_submodule_init(&subrepo, the_repository, argv[1], null_oid(the_hash_algo))) {
25 die_usage(argv, "Submodule not found.");
26 }
27
tree-diff.c
+2 -2
@@ -181,7 +181,7 @@ static void emit_path(struct combine_diff_path ***tail,
181
182 strbuf_add(base, path, pathlen);
183 p = combine_diff_path_new(base->buf, base->len, mode,
184 - oid ? oid : null_oid(),
184 + oid ? oid : null_oid(the_hash_algo),
185 nparent);
186 strbuf_setlen(base, old_baselen);
187
@@ -206,7 +206,7 @@ static void emit_path(struct combine_diff_path ***tail,
206 mode_i = tp[i].entry.mode;
207 }
208 else {
209 - oid_i = null_oid();
209 + oid_i = null_oid(the_hash_algo);
210 mode_i = 0;
211 }
212
upload-pack.c
+1 -1
@@ -1449,7 +1449,7 @@ void upload_pack(const int advertise_refs, const int stateless_rpc,
1449 for_each_namespaced_ref_1(send_ref, &data);
1450 if (!data.sent_capabilities) {
1451 const char *refname = "capabilities^{}";
1452 - write_v0_ref(&data, refname, refname, null_oid());
1452 + write_v0_ref(&data, refname, refname, null_oid(the_hash_algo));
1453 }
1454 /*
1455 * fflush stdout before calling advertise_shallow_grafts because send_ref
wt-status.c
+2 -2
@@ -1824,10 +1824,10 @@ void wt_status_get_state(struct repository *r,
1824 if (!sequencer_get_last_command(r, &action)) {
1825 if (action == REPLAY_PICK && !state->cherry_pick_in_progress) {
1826 state->cherry_pick_in_progress = 1;
1827 - oidcpy(&state->cherry_pick_head_oid, null_oid());
1827 + oidcpy(&state->cherry_pick_head_oid, null_oid(the_hash_algo));
1828 } else if (action == REPLAY_REVERT && !state->revert_in_progress) {
1829 state->revert_in_progress = 1;
1830 - oidcpy(&state->revert_head_oid, null_oid());
1830 + oidcpy(&state->revert_head_oid, null_oid(the_hash_algo));
1831 }
1832 }
1833 if (get_detached_from)
xdiff-interface.c
+1 -1
@@ -181,7 +181,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)
181 unsigned long size;
182 enum object_type type;
183
184 - if (oideq(oid, null_oid())) {
184 + if (oideq(oid, null_oid(the_hash_algo))) {
185 ptr->ptr = xstrdup("");
186 ptr->size = 0;
187 return;