Skip to content

Commit 7abbca0

Browse files
pks-tgitster
authored andcommitted
hash: require hash algorithm in empty_tree_oid_hex()
The `empty_tree_oid_hex()` function use `the_repository` to derive the hash function that shall be used. Require callers to pass in the hash algorithm to get rid of this implicit dependency. While at it, remove the unused `empty_blob_oid_hex()` function. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9c34eb9 commit 7abbca0

9 files changed

+14
-20
lines changed

add-interactive.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ static int get_modified_files(struct repository *r,
557557
s.skip_unseen = filter && i;
558558

559559
opt.def = is_initial ?
560-
empty_tree_oid_hex() : oid_to_hex(&head_oid);
560+
empty_tree_oid_hex(the_repository->hash_algo) : oid_to_hex(&head_oid);
561561

562562
repo_init_revisions(r, &rev, NULL);
563563
setup_revisions(0, NULL, &rev, &opt);

add-patch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
420420
/* could be on an unborn branch */
421421
!strcmp("HEAD", s->revision) &&
422422
repo_get_oid(the_repository, "HEAD", &oid) ?
423-
empty_tree_oid_hex() : s->revision);
423+
empty_tree_oid_hex(the_repository->hash_algo) : s->revision);
424424
}
425425
color_arg_index = args.nr;
426426
/* Use `--no-color` explicitly, just in case `diff.color = always`. */

builtin/merge.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ static void read_empty(const struct object_id *oid)
330330
{
331331
struct child_process cmd = CHILD_PROCESS_INIT;
332332

333-
strvec_pushl(&cmd.args, "read-tree", "-m", "-u", empty_tree_oid_hex(),
333+
strvec_pushl(&cmd.args, "read-tree", "-m", "-u",
334+
empty_tree_oid_hex(the_repository->hash_algo),
334335
oid_to_hex(oid), NULL);
335336
cmd.git_cmd = 1;
336337

builtin/receive-pack.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ static const char *push_to_deploy(unsigned char *sha1,
13711371
strvec_pushl(&child.args, "diff-index", "--quiet", "--cached",
13721372
"--ignore-submodules",
13731373
/* diff-index with either HEAD or an empty tree */
1374-
head_has_history() ? "HEAD" : empty_tree_oid_hex(),
1374+
head_has_history() ? "HEAD" : empty_tree_oid_hex(the_repository->hash_algo),
13751375
"--", NULL);
13761376
strvec_pushv(&child.env, env->v);
13771377
child.no_stdin = 1;

hash-ll.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,7 @@ static inline int is_null_oid(const struct object_id *oid)
347347
return !memcmp(oid->hash, null_hash, GIT_MAX_RAWSZ);
348348
}
349349

350-
const char *empty_tree_oid_hex(void);
351-
const char *empty_blob_oid_hex(void);
350+
const char *empty_tree_oid_hex(const struct git_hash_algo *algop);
352351

353352
static inline int is_empty_blob_oid(const struct object_id *oid,
354353
const struct git_hash_algo *algop)

object-file.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,10 @@ const struct object_id *null_oid(void)
227227
return the_hash_algo->null_oid;
228228
}
229229

230-
const char *empty_tree_oid_hex(void)
230+
const char *empty_tree_oid_hex(const struct git_hash_algo *algop)
231231
{
232232
static char buf[GIT_MAX_HEXSZ + 1];
233-
return oid_to_hex_r(buf, the_hash_algo->empty_tree);
234-
}
235-
236-
const char *empty_blob_oid_hex(void)
237-
{
238-
static char buf[GIT_MAX_HEXSZ + 1];
239-
return oid_to_hex_r(buf, the_hash_algo->empty_blob);
233+
return oid_to_hex_r(buf, algop->empty_tree);
240234
}
241235

242236
int hash_algo_by_name(const char *name)

sequencer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,7 @@ static int do_pick_commit(struct repository *r,
22632263
unborn = 1;
22642264
} else if (unborn)
22652265
oidcpy(&head, the_hash_algo->empty_tree);
2266-
if (index_differs_from(r, unborn ? empty_tree_oid_hex() : "HEAD",
2266+
if (index_differs_from(r, unborn ? empty_tree_oid_hex(the_repository->hash_algo) : "HEAD",
22672267
NULL, 0))
22682268
return error_dirty_index(r, opts);
22692269
}

submodule.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -2119,7 +2119,7 @@ static void submodule_reset_index(const char *path, const char *super_prefix)
21192119
strvec_pushf(&cp.args, "--super-prefix=%s%s/",
21202120
(super_prefix ? super_prefix : ""), path);
21212121

2122-
strvec_push(&cp.args, empty_tree_oid_hex());
2122+
strvec_push(&cp.args, empty_tree_oid_hex(the_repository->hash_algo));
21232123

21242124
if (run_command(&cp))
21252125
die(_("could not reset submodule index"));
@@ -2229,9 +2229,9 @@ int submodule_move_head(const char *path, const char *super_prefix,
22292229
strvec_push(&cp.args, "-m");
22302230

22312231
if (!(flags & SUBMODULE_MOVE_HEAD_FORCE))
2232-
strvec_push(&cp.args, old_head ? old_head : empty_tree_oid_hex());
2232+
strvec_push(&cp.args, old_head ? old_head : empty_tree_oid_hex(the_repository->hash_algo));
22332233

2234-
strvec_push(&cp.args, new_head ? new_head : empty_tree_oid_hex());
2234+
strvec_push(&cp.args, new_head ? new_head : empty_tree_oid_hex(the_repository->hash_algo));
22352235

22362236
if (run_command(&cp)) {
22372237
ret = error(_("Submodule '%s' could not be updated."), path);

wt-status.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ static void wt_status_collect_changes_index(struct wt_status *s)
641641

642642
repo_init_revisions(s->repo, &rev, NULL);
643643
memset(&opt, 0, sizeof(opt));
644-
opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
644+
opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
645645
setup_revisions(0, NULL, &rev, &opt);
646646

647647
rev.diffopt.flags.override_submodule_config = 1;
@@ -1136,7 +1136,7 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
11361136
rev.diffopt.ita_invisible_in_index = 1;
11371137

11381138
memset(&opt, 0, sizeof(opt));
1139-
opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
1139+
opt.def = s->is_initial ? empty_tree_oid_hex(the_repository->hash_algo) : s->reference;
11401140
setup_revisions(0, NULL, &rev, &opt);
11411141

11421142
rev.diffopt.output_format |= DIFF_FORMAT_PATCH;

0 commit comments

Comments
 (0)