Skip to content

Commit 1422844

Browse files
bk2204gitster
authored andcommitted
hash: provide per-algorithm null OIDs
Up until recently, object IDs did not have an algorithm member, only a hash. Consequently, it was possible to share one null (all-zeros) object ID among all hash algorithms. Now that we're going to be handling objects from multiple hash algorithms, it's important to make sure that all object IDs have a correct algorithm field. Introduce a per-algorithm null OID, and add it to struct hash_algo. Introduce a wrapper function as well, and use it everywhere we used to use the null_oid constant. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5a6dce7 commit 1422844

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+119
-95
lines changed

archive.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,11 @@ int write_archive_entries(struct archiver_args *args,
275275
int err;
276276
struct strbuf path_in_archive = STRBUF_INIT;
277277
struct strbuf content = STRBUF_INIT;
278-
struct object_id fake_oid = null_oid;
278+
struct object_id fake_oid;
279279
int i;
280280

281+
oidcpy(&fake_oid, null_oid());
282+
281283
if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
282284
size_t len = args->baselen;
283285

blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
242242
switch (st.st_mode & S_IFMT) {
243243
case S_IFREG:
244244
if (opt->flags.allow_textconv &&
245-
textconv_object(r, read_from, mode, &null_oid, 0, &buf_ptr, &buf_len))
245+
textconv_object(r, read_from, mode, null_oid(), 0, &buf_ptr, &buf_len))
246246
strbuf_attach(&buf, buf_ptr, buf_len, buf_len + 1);
247247
else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
248248
die_errno("cannot open or read '%s'", read_from);

branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ void create_branch(struct repository *r,
322322
transaction = ref_transaction_begin(&err);
323323
if (!transaction ||
324324
ref_transaction_update(transaction, ref.buf,
325-
&oid, forcing ? NULL : &null_oid,
325+
&oid, forcing ? NULL : null_oid(),
326326
0, msg, &err) ||
327327
ref_transaction_commit(transaction, &err))
328328
die("%s", err.buf);

builtin/checkout.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ static int post_checkout_hook(struct commit *old_commit, struct commit *new_comm
106106
int changed)
107107
{
108108
return run_hook_le(NULL, "post-checkout",
109-
oid_to_hex(old_commit ? &old_commit->object.oid : &null_oid),
110-
oid_to_hex(new_commit ? &new_commit->object.oid : &null_oid),
109+
oid_to_hex(old_commit ? &old_commit->object.oid : null_oid()),
110+
oid_to_hex(new_commit ? &new_commit->object.oid : null_oid()),
111111
changed ? "1" : "0", NULL);
112112
/* "new_commit" can be NULL when checking out from the index before
113113
a commit exists. */
@@ -638,7 +638,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
638638
opts.src_index = &the_index;
639639
opts.dst_index = &the_index;
640640
init_checkout_metadata(&opts.meta, info->refname,
641-
info->commit ? &info->commit->object.oid : &null_oid,
641+
info->commit ? &info->commit->object.oid : null_oid(),
642642
NULL);
643643
parse_tree(tree);
644644
init_tree_desc(&tree_desc, tree->buffer, tree->size);

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ static int checkout(int submodule_progress)
820820
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
821821
die(_("unable to write new index file"));
822822

823-
err |= run_hook_le(NULL, "post-checkout", oid_to_hex(&null_oid),
823+
err |= run_hook_le(NULL, "post-checkout", oid_to_hex(null_oid()),
824824
oid_to_hex(&oid), "1", NULL);
825825

826826
if (!err && (option_recurse_submodules.nr > 0)) {

builtin/describe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ static void describe_blob(struct object_id oid, struct strbuf *dst)
502502
{
503503
struct rev_info revs;
504504
struct strvec args = STRVEC_INIT;
505-
struct process_commit_data pcd = { null_oid, oid, dst, &revs};
505+
struct process_commit_data pcd = { *null_oid(), oid, dst, &revs};
506506

507507
strvec_pushl(&args, "internal: The first arg is not parsed",
508508
"--objects", "--in-commit-order", "--reverse", "HEAD",

builtin/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static int builtin_diff_b_f(struct rev_info *revs,
9898

9999
stuff_change(&revs->diffopt,
100100
blob[0]->mode, canon_mode(st.st_mode),
101-
&blob[0]->item->oid, &null_oid,
101+
&blob[0]->item->oid, null_oid(),
102102
1, 0,
103103
blob[0]->path ? blob[0]->path : path,
104104
path);

builtin/fast-export.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ static void handle_tag(const char *name, struct tag *tag)
870870
p = rewrite_commit((struct commit *)tagged);
871871
if (!p) {
872872
printf("reset %s\nfrom %s\n\n",
873-
name, oid_to_hex(&null_oid));
873+
name, oid_to_hex(null_oid()));
874874
free(buf);
875875
return;
876876
}
@@ -884,7 +884,7 @@ static void handle_tag(const char *name, struct tag *tag)
884884

885885
if (tagged->type == OBJ_TAG) {
886886
printf("reset %s\nfrom %s\n\n",
887-
name, oid_to_hex(&null_oid));
887+
name, oid_to_hex(null_oid()));
888888
}
889889
skip_prefix(name, "refs/tags/", &name);
890890
printf("tag %s\n", name);
@@ -1016,7 +1016,7 @@ static void handle_tags_and_duplicates(struct string_list *extras)
10161016
* it.
10171017
*/
10181018
printf("reset %s\nfrom %s\n\n",
1019-
name, oid_to_hex(&null_oid));
1019+
name, oid_to_hex(null_oid()));
10201020
continue;
10211021
}
10221022

@@ -1035,7 +1035,7 @@ static void handle_tags_and_duplicates(struct string_list *extras)
10351035
if (!reference_excluded_commits) {
10361036
/* delete the ref */
10371037
printf("reset %s\nfrom %s\n\n",
1038-
name, oid_to_hex(&null_oid));
1038+
name, oid_to_hex(null_oid()));
10391039
continue;
10401040
}
10411041
/* set ref to commit using oid, not mark */
@@ -1146,7 +1146,7 @@ static void handle_deletes(void)
11461146
continue;
11471147

11481148
printf("reset %s\nfrom %s\n\n",
1149-
refspec->dst, oid_to_hex(&null_oid));
1149+
refspec->dst, oid_to_hex(null_oid()));
11501150
}
11511151
}
11521152

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ static int grep_submodule(struct grep_opt *opt,
421421
struct grep_opt subopt;
422422
int hit;
423423

424-
sub = submodule_from_path(superproject, &null_oid, path);
424+
sub = submodule_from_path(superproject, null_oid(), path);
425425

426426
if (!is_submodule_active(superproject, path))
427427
return 0;

builtin/ls-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ static void show_submodule(struct repository *superproject,
210210
{
211211
struct repository subrepo;
212212
const struct submodule *sub = submodule_from_path(superproject,
213-
&null_oid, path);
213+
null_oid(), path);
214214

215215
if (repo_submodule_init(&subrepo, superproject, sub))
216216
return;

0 commit comments

Comments
 (0)