Skip to content

Commit efed687

Browse files
ebiedermgitster
authored andcommitted
tree-walk: init_tree_desc take an oid to get the hash algorithm
To make it possible for git ls-tree to display the tree encoded in the hash algorithm of the oid specified to git ls-tree, update init_tree_desc to take as a parameter the oid of the tree object. Update all callers of init_tree_desc and init_tree_desc_gently to pass the oid of the tree object. Use the oid of the tree object to discover the hash algorithm of the oid and store that hash algorithm in struct tree_desc. Use the hash algorithm in decode_tree_entry and update_tree_entry_internal to handle reading a tree object encoded in a hash algorithm that differs from the repositories hash algorithm. Signed-off-by: "Eric W. Biederman" <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d6222a2 commit efed687

28 files changed

+80
-59
lines changed

archive.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ int write_archive_entries(struct archiver_args *args,
339339
opts.src_index = args->repo->index;
340340
opts.dst_index = args->repo->index;
341341
opts.fn = oneway_merge;
342-
init_tree_desc(&t, args->tree->buffer, args->tree->size);
342+
init_tree_desc(&t, &args->tree->object.oid,
343+
args->tree->buffer, args->tree->size);
343344
if (unpack_trees(1, &t, &opts))
344345
return -1;
345346
git_attr_set_direction(GIT_ATTR_INDEX);

builtin/am.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,8 +1991,8 @@ static int fast_forward_to(struct tree *head, struct tree *remote, int reset)
19911991
opts.reset = reset ? UNPACK_RESET_PROTECT_UNTRACKED : 0;
19921992
opts.preserve_ignored = 0; /* FIXME: !overwrite_ignore */
19931993
opts.fn = twoway_merge;
1994-
init_tree_desc(&t[0], head->buffer, head->size);
1995-
init_tree_desc(&t[1], remote->buffer, remote->size);
1994+
init_tree_desc(&t[0], &head->object.oid, head->buffer, head->size);
1995+
init_tree_desc(&t[1], &remote->object.oid, remote->buffer, remote->size);
19961996

19971997
if (unpack_trees(2, t, &opts)) {
19981998
rollback_lock_file(&lock_file);
@@ -2026,7 +2026,7 @@ static int merge_tree(struct tree *tree)
20262026
opts.dst_index = &the_index;
20272027
opts.merge = 1;
20282028
opts.fn = oneway_merge;
2029-
init_tree_desc(&t[0], tree->buffer, tree->size);
2029+
init_tree_desc(&t[0], &tree->object.oid, tree->buffer, tree->size);
20302030

20312031
if (unpack_trees(1, t, &opts)) {
20322032
rollback_lock_file(&lock_file);

builtin/checkout.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
701701
info->commit ? &info->commit->object.oid : null_oid(),
702702
NULL);
703703
parse_tree(tree);
704-
init_tree_desc(&tree_desc, tree->buffer, tree->size);
704+
init_tree_desc(&tree_desc, &tree->object.oid, tree->buffer, tree->size);
705705
switch (unpack_trees(1, &tree_desc, &opts)) {
706706
case -2:
707707
*writeout_error = 1;
@@ -815,10 +815,12 @@ static int merge_working_tree(const struct checkout_opts *opts,
815815
die(_("unable to parse commit %s"),
816816
oid_to_hex(old_commit_oid));
817817

818-
init_tree_desc(&trees[0], tree->buffer, tree->size);
818+
init_tree_desc(&trees[0], &tree->object.oid,
819+
tree->buffer, tree->size);
819820
parse_tree(new_tree);
820821
tree = new_tree;
821-
init_tree_desc(&trees[1], tree->buffer, tree->size);
822+
init_tree_desc(&trees[1], &tree->object.oid,
823+
tree->buffer, tree->size);
822824

823825
ret = unpack_trees(2, trees, &topts);
824826
clear_unpack_trees_porcelain(&topts);

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ static int checkout(int submodule_progress, int filter_submodules)
737737
if (!tree)
738738
die(_("unable to parse commit %s"), oid_to_hex(&oid));
739739
parse_tree(tree);
740-
init_tree_desc(&t, tree->buffer, tree->size);
740+
init_tree_desc(&t, &tree->object.oid, tree->buffer, tree->size);
741741
if (unpack_trees(1, &t, &opts) < 0)
742742
die(_("unable to checkout working tree"));
743743

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static void create_base_index(const struct commit *current_head)
340340
if (!tree)
341341
die(_("failed to unpack HEAD tree object"));
342342
parse_tree(tree);
343-
init_tree_desc(&t, tree->buffer, tree->size);
343+
init_tree_desc(&t, &tree->object.oid, tree->buffer, tree->size);
344344
if (unpack_trees(1, &t, &opts))
345345
exit(128); /* We've already reported the error, finish dying */
346346
}

builtin/grep.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ static int grep_submodule(struct grep_opt *opt,
530530
strbuf_addstr(&base, filename);
531531
strbuf_addch(&base, '/');
532532

533-
init_tree_desc(&tree, data, size);
533+
init_tree_desc(&tree, oid, data, size);
534534
hit = grep_tree(&subopt, pathspec, &tree, &base, base.len,
535535
object_type == OBJ_COMMIT);
536536
strbuf_release(&base);
@@ -574,7 +574,7 @@ static int grep_cache(struct grep_opt *opt,
574574

575575
data = repo_read_object_file(the_repository, &ce->oid,
576576
&type, &size);
577-
init_tree_desc(&tree, data, size);
577+
init_tree_desc(&tree, &ce->oid, data, size);
578578

579579
hit |= grep_tree(opt, pathspec, &tree, &name, 0, 0);
580580
strbuf_setlen(&name, name_base_len);
@@ -670,7 +670,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
670670
oid_to_hex(&entry.oid));
671671

672672
strbuf_addch(base, '/');
673-
init_tree_desc(&sub, data, size);
673+
init_tree_desc(&sub, &entry.oid, data, size);
674674
hit |= grep_tree(opt, pathspec, &sub, base, tn_len,
675675
check_attr);
676676
free(data);
@@ -714,7 +714,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
714714
strbuf_add(&base, name, len);
715715
strbuf_addch(&base, ':');
716716
}
717-
init_tree_desc(&tree, data, size);
717+
init_tree_desc(&tree, &obj->oid, data, size);
718718
hit = grep_tree(opt, pathspec, &tree, &base, base.len,
719719
obj->type == OBJ_COMMIT);
720720
strbuf_release(&base);

builtin/merge.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,8 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head,
704704
cache_tree_free(&the_index.cache_tree);
705705
for (i = 0; i < nr_trees; i++) {
706706
parse_tree(trees[i]);
707-
init_tree_desc(t+i, trees[i]->buffer, trees[i]->size);
707+
init_tree_desc(t+i, &trees[i]->object.oid,
708+
trees[i]->buffer, trees[i]->size);
708709
}
709710
if (unpack_trees(nr_trees, t, &opts))
710711
return -1;

builtin/pack-objects.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,7 +1756,8 @@ static void add_pbase_object(struct tree_desc *tree,
17561756
tree = pbase_tree_get(&entry.oid);
17571757
if (!tree)
17581758
return;
1759-
init_tree_desc(&sub, tree->tree_data, tree->tree_size);
1759+
init_tree_desc(&sub, &tree->oid,
1760+
tree->tree_data, tree->tree_size);
17601761

17611762
add_pbase_object(&sub, down, downlen, fullname);
17621763
pbase_tree_put(tree);
@@ -1816,7 +1817,8 @@ static void add_preferred_base_object(const char *name)
18161817
}
18171818
else {
18181819
struct tree_desc tree;
1819-
init_tree_desc(&tree, it->pcache.tree_data, it->pcache.tree_size);
1820+
init_tree_desc(&tree, &it->pcache.oid,
1821+
it->pcache.tree_data, it->pcache.tree_size);
18201822
add_pbase_object(&tree, name, cmplen, name);
18211823
}
18221824
}

builtin/read-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix)
264264
for (i = 0; i < nr_trees; i++) {
265265
struct tree *tree = trees[i];
266266
parse_tree(tree);
267-
init_tree_desc(t+i, tree->buffer, tree->size);
267+
init_tree_desc(t+i, &tree->object.oid, tree->buffer, tree->size);
268268
}
269269
if (unpack_trees(nr_trees, t, &opts))
270270
return 128;

builtin/stash.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static int reset_tree(struct object_id *i_tree, int update, int reset)
285285
if (parse_tree(tree))
286286
return -1;
287287

288-
init_tree_desc(t, tree->buffer, tree->size);
288+
init_tree_desc(t, &tree->object.oid, tree->buffer, tree->size);
289289

290290
opts.head_idx = 1;
291291
opts.src_index = &the_index;
@@ -871,7 +871,8 @@ static void diff_include_untracked(const struct stash_info *info, struct diff_op
871871
tree[i] = parse_tree_indirect(oid[i]);
872872
if (parse_tree(tree[i]) < 0)
873873
die(_("failed to parse tree"));
874-
init_tree_desc(&tree_desc[i], tree[i]->buffer, tree[i]->size);
874+
init_tree_desc(&tree_desc[i], &tree[i]->object.oid,
875+
tree[i]->buffer, tree[i]->size);
875876
}
876877

877878
unpack_tree_opt.head_idx = -1;

0 commit comments

Comments
 (0)