Skip to content

Commit 9c34eb9

Browse files
pks-tgitster
authored andcommitted
hash: require hash algorithm in is_empty_{blob,tree}_oid()
Both functions `is_empty_{blob,tree}_oid()` 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. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 861e8c7 commit 9c34eb9

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

builtin/fast-import.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -2361,7 +2361,9 @@ static void file_change_m(const char *p, struct branch *b)
23612361
parse_path_eol(&path, p, "path");
23622362

23632363
/* Git does not track empty, non-toplevel directories. */
2364-
if (S_ISDIR(mode) && is_empty_tree_oid(&oid) && *path.buf) {
2364+
if (S_ISDIR(mode) &&
2365+
is_empty_tree_oid(&oid, the_repository->hash_algo) &&
2366+
*path.buf) {
23652367
tree_content_remove(&b->branch_tree, path.buf, NULL, 0);
23662368
return;
23672369
}

cache-tree.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ static int update_one(struct cache_tree *it,
422422
/*
423423
* "sub" can be an empty tree if all subentries are i-t-a.
424424
*/
425-
if (contains_ita && is_empty_tree_oid(oid))
425+
if (contains_ita && is_empty_tree_oid(oid, the_repository->hash_algo))
426426
continue;
427427

428428
strbuf_grow(&buffer, entlen + 100);

diffcore-rename.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ void diffcore_rename_extended(struct diff_options *options,
14221422
strcmp(options->single_follow, p->two->path))
14231423
continue; /* not interested */
14241424
else if (!options->flags.rename_empty &&
1425-
is_empty_blob_oid(&p->two->oid))
1425+
is_empty_blob_oid(&p->two->oid, the_repository->hash_algo))
14261426
continue;
14271427
else if (add_rename_dst(p) < 0) {
14281428
warning("skipping rename detection, detected"
@@ -1432,7 +1432,7 @@ void diffcore_rename_extended(struct diff_options *options,
14321432
}
14331433
}
14341434
else if (!options->flags.rename_empty &&
1435-
is_empty_blob_oid(&p->one->oid))
1435+
is_empty_blob_oid(&p->one->oid, the_repository->hash_algo))
14361436
continue;
14371437
else if (!DIFF_PAIR_UNMERGED(p) && !DIFF_FILE_VALID(p->two)) {
14381438
/*

hash-ll.h

+12
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,16 @@ static inline int is_null_oid(const struct object_id *oid)
350350
const char *empty_tree_oid_hex(void);
351351
const char *empty_blob_oid_hex(void);
352352

353+
static inline int is_empty_blob_oid(const struct object_id *oid,
354+
const struct git_hash_algo *algop)
355+
{
356+
return oideq(oid, algop->empty_blob);
357+
}
358+
359+
static inline int is_empty_tree_oid(const struct object_id *oid,
360+
const struct git_hash_algo *algop)
361+
{
362+
return oideq(oid, algop->empty_tree);
363+
}
364+
353365
#endif

hash.h

-10
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,4 @@
66

77
#define the_hash_algo the_repository->hash_algo
88

9-
static inline int is_empty_blob_oid(const struct object_id *oid)
10-
{
11-
return oideq(oid, the_hash_algo->empty_blob);
12-
}
13-
14-
static inline int is_empty_tree_oid(const struct object_id *oid)
15-
{
16-
return oideq(oid, the_hash_algo->empty_tree);
17-
}
18-
199
#endif

read-cache.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
337337

338338
/* Racily smudged entry? */
339339
if (!ce->ce_stat_data.sd_size) {
340-
if (!is_empty_blob_oid(&ce->oid))
340+
if (!is_empty_blob_oid(&ce->oid, the_repository->hash_algo))
341341
changed |= DATA_CHANGED;
342342
}
343343

0 commit comments

Comments
 (0)