Skip to content

Commit eb0ccfd

Browse files
bk2204gitster
authored andcommitted
Switch empty tree and blob lookups to use hash abstraction
Switch the uses of empty_tree_oid and empty_blob_oid to use the current_hash abstraction that represents the current hash algorithm in use. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 78a6766 commit eb0ccfd

File tree

10 files changed

+15
-15
lines changed

10 files changed

+15
-15
lines changed

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ static void write_index_patch(const struct am_state *state)
14331433
if (!get_oid_tree("HEAD", &head))
14341434
tree = lookup_tree(&head);
14351435
else
1436-
tree = lookup_tree(&empty_tree_oid);
1436+
tree = lookup_tree(the_hash_algo->empty_tree);
14371437

14381438
fp = xfopen(am_path(state, "patch"), "w");
14391439
init_revisions(&rev_info, NULL);

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
514514
}
515515
tree = parse_tree_indirect(old->commit ?
516516
&old->commit->object.oid :
517-
&empty_tree_oid);
517+
the_hash_algo->empty_tree);
518518
init_tree_desc(&trees[0], tree->buffer, tree->size);
519519
tree = parse_tree_indirect(&new->commit->object.oid);
520520
init_tree_desc(&trees[1], tree->buffer, tree->size);

builtin/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
379379
add_head_to_pending(&rev);
380380
if (!rev.pending.nr) {
381381
struct tree *tree;
382-
tree = lookup_tree(&empty_tree_oid);
382+
tree = lookup_tree(the_hash_algo->empty_tree);
383383
add_pending_object(&rev, &tree->object, "HEAD");
384384
}
385385
break;

builtin/pull.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ static int pull_into_void(const struct object_id *merge_head,
545545
* index/worktree changes that the user already made on the unborn
546546
* branch.
547547
*/
548-
if (checkout_fast_forward(&empty_tree_oid, merge_head, 0))
548+
if (checkout_fast_forward(the_hash_algo->empty_tree, merge_head, 0))
549549
return 1;
550550

551551
if (update_ref("initial pull", "HEAD", merge_head, curr_head, 0, UPDATE_REFS_DIE_ON_ERR))

cache.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,22 +1024,22 @@ extern const struct object_id empty_blob_oid;
10241024

10251025
static inline int is_empty_blob_sha1(const unsigned char *sha1)
10261026
{
1027-
return !hashcmp(sha1, EMPTY_BLOB_SHA1_BIN);
1027+
return !hashcmp(sha1, the_hash_algo->empty_blob->hash);
10281028
}
10291029

10301030
static inline int is_empty_blob_oid(const struct object_id *oid)
10311031
{
1032-
return !hashcmp(oid->hash, EMPTY_BLOB_SHA1_BIN);
1032+
return !oidcmp(oid, the_hash_algo->empty_blob);
10331033
}
10341034

10351035
static inline int is_empty_tree_sha1(const unsigned char *sha1)
10361036
{
1037-
return !hashcmp(sha1, EMPTY_TREE_SHA1_BIN);
1037+
return !hashcmp(sha1, the_hash_algo->empty_tree->hash);
10381038
}
10391039

10401040
static inline int is_empty_tree_oid(const struct object_id *oid)
10411041
{
1042-
return !hashcmp(oid->hash, EMPTY_TREE_SHA1_BIN);
1042+
return !oidcmp(oid, the_hash_algo->empty_tree);
10431043
}
10441044

10451045
/* set default permissions by passing mode arguments to open(2) */

diff-lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
217217
} else if (revs->diffopt.ita_invisible_in_index &&
218218
ce_intent_to_add(ce)) {
219219
diff_addremove(&revs->diffopt, '+', ce->ce_mode,
220-
&empty_tree_oid, 0,
220+
the_hash_algo->empty_tree, 0,
221221
ce->name, 0);
222222
continue;
223223
}

merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2081,7 +2081,7 @@ int merge_recursive(struct merge_options *o,
20812081
/* if there is no common ancestor, use an empty tree */
20822082
struct tree *tree;
20832083

2084-
tree = lookup_tree(&empty_tree_oid);
2084+
tree = lookup_tree(the_hash_algo->empty_tree);
20852085
merged_common_ancestors = make_virtual_commit(tree, "ancestor");
20862086
}
20872087

notes-merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ int notes_merge(struct notes_merge_options *o,
595595
bases = get_merge_bases(local, remote);
596596
if (!bases) {
597597
base_oid = &null_oid;
598-
base_tree_oid = &empty_tree_oid;
598+
base_tree_oid = the_hash_algo->empty_tree;
599599
if (o->verbosity >= 4)
600600
printf("No merge base found; doing history-less merge\n");
601601
} else if (!bases->next) {

sequencer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ static int read_oneliner(struct strbuf *buf,
347347

348348
static struct tree *empty_tree(void)
349349
{
350-
return lookup_tree(&empty_tree_oid);
350+
return lookup_tree(the_hash_algo->empty_tree);
351351
}
352352

353353
static int error_dirty_index(struct replay_opts *opts)
@@ -705,7 +705,7 @@ static int is_original_commit_empty(struct commit *commit)
705705
oid_to_hex(&parent->object.oid));
706706
ptree_oid = &parent->tree->object.oid;
707707
} else {
708-
ptree_oid = &empty_tree_oid; /* commit is root */
708+
ptree_oid = the_hash_algo->empty_tree; /* commit is root */
709709
}
710710

711711
return !oidcmp(ptree_oid, &commit->tree->object.oid);
@@ -958,7 +958,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
958958
} else {
959959
unborn = get_oid("HEAD", &head);
960960
if (unborn)
961-
oidcpy(&head, &empty_tree_oid);
961+
oidcpy(&head, the_hash_algo->empty_tree);
962962
if (index_differs_from(unborn ? EMPTY_TREE_SHA1_HEX : "HEAD",
963963
NULL, 0))
964964
return error_dirty_index(opts);

submodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
587587
struct object_id *one, struct object_id *two,
588588
unsigned dirty_submodule)
589589
{
590-
const struct object_id *old = &empty_tree_oid, *new = &empty_tree_oid;
590+
const struct object_id *old = the_hash_algo->empty_tree, *new = the_hash_algo->empty_tree;
591591
struct commit *left = NULL, *right = NULL;
592592
struct commit_list *merge_bases = NULL;
593593
struct child_process cp = CHILD_PROCESS_INIT;

0 commit comments

Comments
 (0)