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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Nov 12, 2017 at 21:28 UTC
eb0ccfd7f5ce1765ada74abf272f002e1e34d1e4
10 files changed
+15
-15
builtin/am.c
+1
-1
@@ -1433,7 +1433,7 @@ static void write_index_patch(const struct am_state *state)
1433
if (!get_oid_tree("HEAD", &head))
1434
tree = lookup_tree(&head);
1435
else
1436
- tree = lookup_tree(&empty_tree_oid);
1436
+ tree = lookup_tree(the_hash_algo->empty_tree);
1437
1438
fp = xfopen(am_path(state, "patch"), "w");
1439
init_revisions(&rev_info, NULL);
builtin/checkout.c
+1
-1
@@ -514,7 +514,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
514
}
515
tree = parse_tree_indirect(old->commit ?
516
&old->commit->object.oid :
517
- &empty_tree_oid);
517
+ the_hash_algo->empty_tree);
518
init_tree_desc(&trees[0], tree->buffer, tree->size);
519
tree = parse_tree_indirect(&new->commit->object.oid);
520
init_tree_desc(&trees[1], tree->buffer, tree->size);
builtin/diff.c
+1
-1
@@ -379,7 +379,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
379
add_head_to_pending(&rev);
380
if (!rev.pending.nr) {
381
struct tree *tree;
382
- tree = lookup_tree(&empty_tree_oid);
382
+ tree = lookup_tree(the_hash_algo->empty_tree);
383
add_pending_object(&rev, &tree->object, "HEAD");
384
}
385
break;
builtin/pull.c
+1
-1
@@ -545,7 +545,7 @@ static int pull_into_void(const struct object_id *merge_head,
545
* index/worktree changes that the user already made on the unborn
546
* branch.
547
*/
548
- if (checkout_fast_forward(&empty_tree_oid, merge_head, 0))
548
+ if (checkout_fast_forward(the_hash_algo->empty_tree, merge_head, 0))
549
return 1;
550
551
if (update_ref("initial pull", "HEAD", merge_head, curr_head, 0, UPDATE_REFS_DIE_ON_ERR))
cache.h
+4
-4
@@ -1024,22 +1024,22 @@ extern const struct object_id empty_blob_oid;
1024
1025
static inline int is_empty_blob_sha1(const unsigned char *sha1)
1026
{
1027
- return !hashcmp(sha1, EMPTY_BLOB_SHA1_BIN);
1027
+ return !hashcmp(sha1, the_hash_algo->empty_blob->hash);
1028
}
1029
1030
static inline int is_empty_blob_oid(const struct object_id *oid)
1031
{
1032
- return !hashcmp(oid->hash, EMPTY_BLOB_SHA1_BIN);
1032
+ return !oidcmp(oid, the_hash_algo->empty_blob);
1033
}
1034
1035
static inline int is_empty_tree_sha1(const unsigned char *sha1)
1036
{
1037
- return !hashcmp(sha1, EMPTY_TREE_SHA1_BIN);
1037
+ return !hashcmp(sha1, the_hash_algo->empty_tree->hash);
1038
}
1039
1040
static inline int is_empty_tree_oid(const struct object_id *oid)
1041
{
1042
- return !hashcmp(oid->hash, EMPTY_TREE_SHA1_BIN);
1042
+ return !oidcmp(oid, the_hash_algo->empty_tree);
1043
}
1044
1045
/* set default permissions by passing mode arguments to open(2) */
diff-lib.c
+1
-1
@@ -217,7 +217,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
217
} else if (revs->diffopt.ita_invisible_in_index &&
218
ce_intent_to_add(ce)) {
219
diff_addremove(&revs->diffopt, '+', ce->ce_mode,
220
- &empty_tree_oid, 0,
220
+ the_hash_algo->empty_tree, 0,
221
ce->name, 0);
222
continue;
223
}
merge-recursive.c
+1
-1
@@ -2081,7 +2081,7 @@ int merge_recursive(struct merge_options *o,
2081
/* if there is no common ancestor, use an empty tree */
2082
struct tree *tree;
2083
2084
- tree = lookup_tree(&empty_tree_oid);
2084
+ tree = lookup_tree(the_hash_algo->empty_tree);
2085
merged_common_ancestors = make_virtual_commit(tree, "ancestor");
2086
}
2087
notes-merge.c
+1
-1
@@ -595,7 +595,7 @@ int notes_merge(struct notes_merge_options *o,
595
bases = get_merge_bases(local, remote);
596
if (!bases) {
597
base_oid = &null_oid;
598
- base_tree_oid = &empty_tree_oid;
598
+ base_tree_oid = the_hash_algo->empty_tree;
599
if (o->verbosity >= 4)
600
printf("No merge base found; doing history-less merge\n");
601
} else if (!bases->next) {
sequencer.c
+3
-3
@@ -347,7 +347,7 @@ static int read_oneliner(struct strbuf *buf,
347
348
static struct tree *empty_tree(void)
349
{
350
- return lookup_tree(&empty_tree_oid);
350
+ return lookup_tree(the_hash_algo->empty_tree);
351
}
352
353
static int error_dirty_index(struct replay_opts *opts)
@@ -705,7 +705,7 @@ static int is_original_commit_empty(struct commit *commit)
705
oid_to_hex(&parent->object.oid));
706
ptree_oid = &parent->tree->object.oid;
707
} else {
708
- ptree_oid = &empty_tree_oid; /* commit is root */
708
+ ptree_oid = the_hash_algo->empty_tree; /* commit is root */
709
}
710
711
return !oidcmp(ptree_oid, &commit->tree->object.oid);
@@ -958,7 +958,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
958
} else {
959
unborn = get_oid("HEAD", &head);
960
if (unborn)
961
- oidcpy(&head, &empty_tree_oid);
961
+ oidcpy(&head, the_hash_algo->empty_tree);
962
if (index_differs_from(unborn ? EMPTY_TREE_SHA1_HEX : "HEAD",
963
NULL, 0))
964
return error_dirty_index(opts);
submodule.c
+1
-1
@@ -587,7 +587,7 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path,
587
struct object_id *one, struct object_id *two,
588
unsigned dirty_submodule)
589
{
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;
591
struct commit *left = NULL, *right = NULL;
592
struct commit_list *merge_bases = NULL;
593
struct child_process cp = CHILD_PROCESS_INIT;