Skip to content

Commit

Permalink
Merge branch 'bc/hash-transition-interop-part-1'
Browse files Browse the repository at this point in the history
SHA-256 transition.

* bc/hash-transition-interop-part-1:
  hex: print objects using the hash algorithm member
  hex: default to the_hash_algo on zero algorithm value
  builtin/pack-objects: avoid using struct object_id for pack hash
  commit-graph: don't store file hashes as struct object_id
  builtin/show-index: set the algorithm for object IDs
  hash: provide per-algorithm null OIDs
  hash: set, copy, and use algo field in struct object_id
  builtin/pack-redundant: avoid casting buffers to struct object_id
  Use the final_oid_fn to finalize hashing of object IDs
  hash: add a function to finalize object IDs
  http-push: set algorithm when reading object ID
  Always use oidread to read into struct object_id
  hash: add an algo member to struct object_id
  • Loading branch information
gitster committed May 10, 2021
2 parents 2d677e5 + 3dd7146 commit aaa3c80
Show file tree
Hide file tree
Showing 58 changed files with 304 additions and 197 deletions.
6 changes: 4 additions & 2 deletions archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ static void queue_directory(const unsigned char *sha1,
d->mode = mode;
c->bottom = d;
d->len = xsnprintf(d->path, len, "%.*s%s/", (int)base->len, base->buf, filename);
hashcpy(d->oid.hash, sha1);
oidread(&d->oid, sha1);
}

static int write_directory(struct archiver_context *c)
Expand Down Expand Up @@ -275,9 +275,11 @@ int write_archive_entries(struct archiver_args *args,
int err;
struct strbuf path_in_archive = STRBUF_INIT;
struct strbuf content = STRBUF_INIT;
struct object_id fake_oid = null_oid;
struct object_id fake_oid;
int i;

oidcpy(&fake_oid, null_oid());

if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
size_t len = args->baselen;

Expand Down
2 changes: 1 addition & 1 deletion blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
switch (st.st_mode & S_IFMT) {
case S_IFREG:
if (opt->flags.allow_textconv &&
textconv_object(r, read_from, mode, &null_oid, 0, &buf_ptr, &buf_len))
textconv_object(r, read_from, mode, null_oid(), 0, &buf_ptr, &buf_len))
strbuf_attach(&buf, buf_ptr, buf_len, buf_len + 1);
else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
die_errno("cannot open or read '%s'", read_from);
Expand Down
2 changes: 1 addition & 1 deletion branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ void create_branch(struct repository *r,
transaction = ref_transaction_begin(&err);
if (!transaction ||
ref_transaction_update(transaction, ref.buf,
&oid, forcing ? NULL : &null_oid,
&oid, forcing ? NULL : null_oid(),
0, msg, &err) ||
ref_transaction_commit(transaction, &err))
die("%s", err.buf);
Expand Down
6 changes: 3 additions & 3 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ static int post_checkout_hook(struct commit *old_commit, struct commit *new_comm
int changed)
{
return run_hook_le(NULL, "post-checkout",
oid_to_hex(old_commit ? &old_commit->object.oid : &null_oid),
oid_to_hex(new_commit ? &new_commit->object.oid : &null_oid),
oid_to_hex(old_commit ? &old_commit->object.oid : null_oid()),
oid_to_hex(new_commit ? &new_commit->object.oid : null_oid()),
changed ? "1" : "0", NULL);
/* "new_commit" can be NULL when checking out from the index before
a commit exists. */
Expand Down Expand Up @@ -644,7 +644,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
opts.src_index = &the_index;
opts.dst_index = &the_index;
init_checkout_metadata(&opts.meta, info->refname,
info->commit ? &info->commit->object.oid : &null_oid,
info->commit ? &info->commit->object.oid : null_oid(),
NULL);
parse_tree(tree);
init_tree_desc(&tree_desc, tree->buffer, tree->size);
Expand Down
2 changes: 1 addition & 1 deletion builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ static int checkout(int submodule_progress)
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
die(_("unable to write new index file"));

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

if (!err && (option_recurse_submodules.nr > 0)) {
Expand Down
2 changes: 1 addition & 1 deletion builtin/describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ static void describe_blob(struct object_id oid, struct strbuf *dst)
{
struct rev_info revs;
struct strvec args = STRVEC_INIT;
struct process_commit_data pcd = { null_oid, oid, dst, &revs};
struct process_commit_data pcd = { *null_oid(), oid, dst, &revs};

strvec_pushl(&args, "internal: The first arg is not parsed",
"--objects", "--in-commit-order", "--reverse", "HEAD",
Expand Down
2 changes: 1 addition & 1 deletion builtin/diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static int builtin_diff_b_f(struct rev_info *revs,

stuff_change(&revs->diffopt,
blob[0]->mode, canon_mode(st.st_mode),
&blob[0]->item->oid, &null_oid,
&blob[0]->item->oid, null_oid(),
1, 0,
blob[0]->path ? blob[0]->path : path,
path);
Expand Down
10 changes: 5 additions & 5 deletions builtin/fast-export.c
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ static void handle_tag(const char *name, struct tag *tag)
p = rewrite_commit((struct commit *)tagged);
if (!p) {
printf("reset %s\nfrom %s\n\n",
name, oid_to_hex(&null_oid));
name, oid_to_hex(null_oid()));
free(buf);
return;
}
Expand All @@ -884,7 +884,7 @@ static void handle_tag(const char *name, struct tag *tag)

if (tagged->type == OBJ_TAG) {
printf("reset %s\nfrom %s\n\n",
name, oid_to_hex(&null_oid));
name, oid_to_hex(null_oid()));
}
skip_prefix(name, "refs/tags/", &name);
printf("tag %s\n", name);
Expand Down Expand Up @@ -1016,7 +1016,7 @@ static void handle_tags_and_duplicates(struct string_list *extras)
* it.
*/
printf("reset %s\nfrom %s\n\n",
name, oid_to_hex(&null_oid));
name, oid_to_hex(null_oid()));
continue;
}

Expand All @@ -1035,7 +1035,7 @@ static void handle_tags_and_duplicates(struct string_list *extras)
if (!reference_excluded_commits) {
/* delete the ref */
printf("reset %s\nfrom %s\n\n",
name, oid_to_hex(&null_oid));
name, oid_to_hex(null_oid()));
continue;
}
/* set ref to commit using oid, not mark */
Expand Down Expand Up @@ -1146,7 +1146,7 @@ static void handle_deletes(void)
continue;

printf("reset %s\nfrom %s\n\n",
refspec->dst, oid_to_hex(&null_oid));
refspec->dst, oid_to_hex(null_oid()));
}
}

Expand Down
8 changes: 4 additions & 4 deletions builtin/fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ static int store_object(
the_hash_algo->init_fn(&c);
the_hash_algo->update_fn(&c, hdr, hdrlen);
the_hash_algo->update_fn(&c, dat->buf, dat->len);
the_hash_algo->final_fn(oid.hash, &c);
the_hash_algo->final_oid_fn(&oid, &c);
if (oidout)
oidcpy(oidout, &oid);

Expand Down Expand Up @@ -1136,7 +1136,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)
}
}
git_deflate_end(&s);
the_hash_algo->final_fn(oid.hash, &c);
the_hash_algo->final_oid_fn(&oid, &c);

if (oidout)
oidcpy(oidout, &oid);
Expand Down Expand Up @@ -1276,8 +1276,8 @@ static void load_tree(struct tree_entry *root)
e->versions[0].mode = e->versions[1].mode;
e->name = to_atom(c, strlen(c));
c += e->name->str_len + 1;
hashcpy(e->versions[0].oid.hash, (unsigned char *)c);
hashcpy(e->versions[1].oid.hash, (unsigned char *)c);
oidread(&e->versions[0].oid, (unsigned char *)c);
oidread(&e->versions[1].oid, (unsigned char *)c);
c += the_hash_algo->rawsz;
}
free(buf);
Expand Down
2 changes: 1 addition & 1 deletion builtin/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ static int grep_submodule(struct grep_opt *opt,
struct grep_opt subopt;
int hit;

sub = submodule_from_path(superproject, &null_oid, path);
sub = submodule_from_path(superproject, null_oid(), path);

if (!is_submodule_active(superproject, path))
return 0;
Expand Down
6 changes: 3 additions & 3 deletions builtin/index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ static void *unpack_entry_data(off_t offset, unsigned long size,
bad_object(offset, _("inflate returned %d"), status);
git_inflate_end(&stream);
if (oid)
the_hash_algo->final_fn(oid->hash, &c);
the_hash_algo->final_oid_fn(oid, &c);
return buf == fixed_buf ? NULL : buf;
}

Expand Down Expand Up @@ -524,7 +524,7 @@ static void *unpack_raw_entry(struct object_entry *obj,

switch (obj->type) {
case OBJ_REF_DELTA:
hashcpy(ref_oid->hash, fill(the_hash_algo->rawsz));
oidread(ref_oid, fill(the_hash_algo->rawsz));
use(the_hash_algo->rawsz);
break;
case OBJ_OFS_DELTA:
Expand Down Expand Up @@ -1358,7 +1358,7 @@ static struct object_entry *append_obj_to_pack(struct hashfile *f,
obj[1].idx.offset += write_compressed(f, buf, size);
obj[0].idx.crc32 = crc32_end(f);
hashflush(f);
hashcpy(obj->idx.oid.hash, sha1);
oidread(&obj->idx.oid, sha1);
return obj;
}

Expand Down
2 changes: 1 addition & 1 deletion builtin/ls-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static void show_submodule(struct repository *superproject,
{
struct repository subrepo;
const struct submodule *sub = submodule_from_path(superproject,
&null_oid, path);
null_oid(), path);

if (repo_submodule_init(&subrepo, superproject, sub))
return;
Expand Down
20 changes: 10 additions & 10 deletions builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ static void write_pack_file(void)
write_order = compute_write_order();

do {
struct object_id oid;
unsigned char hash[GIT_MAX_RAWSZ];
char *pack_tmp_name = NULL;

if (pack_to_stdout)
Expand Down Expand Up @@ -1059,13 +1059,13 @@ static void write_pack_file(void)
* If so, rewrite it like in fast-import
*/
if (pack_to_stdout) {
finalize_hashfile(f, oid.hash, CSUM_HASH_IN_STREAM | CSUM_CLOSE);
finalize_hashfile(f, hash, CSUM_HASH_IN_STREAM | CSUM_CLOSE);
} else if (nr_written == nr_remaining) {
finalize_hashfile(f, oid.hash, CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
finalize_hashfile(f, hash, CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
} else {
int fd = finalize_hashfile(f, oid.hash, 0);
fixup_pack_header_footer(fd, oid.hash, pack_tmp_name,
nr_written, oid.hash, offset);
int fd = finalize_hashfile(f, hash, 0);
fixup_pack_header_footer(fd, hash, pack_tmp_name,
nr_written, hash, offset);
close(fd);
if (write_bitmap_index) {
if (write_bitmap_index != WRITE_BITMAP_QUIET)
Expand Down Expand Up @@ -1100,17 +1100,17 @@ static void write_pack_file(void)
strbuf_addf(&tmpname, "%s-", base_name);

if (write_bitmap_index) {
bitmap_writer_set_checksum(oid.hash);
bitmap_writer_set_checksum(hash);
bitmap_writer_build_type_index(
&to_pack, written_list, nr_written);
}

finish_tmp_packfile(&tmpname, pack_tmp_name,
written_list, nr_written,
&pack_idx_opts, oid.hash);
&pack_idx_opts, hash);

if (write_bitmap_index) {
strbuf_addf(&tmpname, "%s.bitmap", oid_to_hex(&oid));
strbuf_addf(&tmpname, "%s.bitmap", hash_to_hex(hash));

stop_progress(&progress_state);

Expand All @@ -1124,7 +1124,7 @@ static void write_pack_file(void)

strbuf_release(&tmpname);
free(pack_tmp_name);
puts(oid_to_hex(&oid));
puts(hash_to_hex(hash));
}

/* mark written objects as written to previous pack */
Expand Down
28 changes: 14 additions & 14 deletions builtin/pack-redundant.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static int load_all_packs, verbose, alt_odb;

struct llist_item {
struct llist_item *next;
const struct object_id *oid;
struct object_id oid;
};
static struct llist {
struct llist_item *front;
Expand Down Expand Up @@ -95,10 +95,10 @@ static struct llist * llist_copy(struct llist *list)

static inline struct llist_item *llist_insert(struct llist *list,
struct llist_item *after,
const struct object_id *oid)
const unsigned char *oid)
{
struct llist_item *new_item = llist_item_get();
new_item->oid = oid;
oidread(&new_item->oid, oid);
new_item->next = NULL;

if (after != NULL) {
Expand All @@ -118,7 +118,7 @@ static inline struct llist_item *llist_insert(struct llist *list,
}

static inline struct llist_item *llist_insert_back(struct llist *list,
const struct object_id *oid)
const unsigned char *oid)
{
return llist_insert(list, list->back, oid);
}
Expand All @@ -130,9 +130,9 @@ static inline struct llist_item *llist_insert_sorted_unique(struct llist *list,

l = (hint == NULL) ? list->front : hint;
while (l) {
int cmp = oidcmp(l->oid, oid);
int cmp = oidcmp(&l->oid, oid);
if (cmp > 0) { /* we insert before this entry */
return llist_insert(list, prev, oid);
return llist_insert(list, prev, oid->hash);
}
if (!cmp) { /* already exists */
return l;
Expand All @@ -141,19 +141,19 @@ static inline struct llist_item *llist_insert_sorted_unique(struct llist *list,
l = l->next;
}
/* insert at the end */
return llist_insert_back(list, oid);
return llist_insert_back(list, oid->hash);
}

/* returns a pointer to an item in front of sha1 */
static inline struct llist_item * llist_sorted_remove(struct llist *list, const struct object_id *oid, struct llist_item *hint)
static inline struct llist_item * llist_sorted_remove(struct llist *list, const unsigned char *oid, struct llist_item *hint)
{
struct llist_item *prev, *l;

redo_from_start:
l = (hint == NULL) ? list->front : hint;
prev = NULL;
while (l) {
const int cmp = oidcmp(l->oid, oid);
const int cmp = hashcmp(l->oid.hash, oid);
if (cmp > 0) /* not in list, since sorted */
return prev;
if (!cmp) { /* found */
Expand Down Expand Up @@ -188,7 +188,7 @@ static void llist_sorted_difference_inplace(struct llist *A,
b = B->front;

while (b) {
hint = llist_sorted_remove(A, b->oid, hint);
hint = llist_sorted_remove(A, b->oid.hash, hint);
b = b->next;
}
}
Expand Down Expand Up @@ -260,10 +260,10 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
/* cmp ~ p1 - p2 */
if (cmp == 0) {
p1_hint = llist_sorted_remove(p1->unique_objects,
(const struct object_id *)(p1_base + p1_off),
p1_base + p1_off,
p1_hint);
p2_hint = llist_sorted_remove(p2->unique_objects,
(const struct object_id *)(p1_base + p1_off),
p1_base + p1_off,
p2_hint);
p1_off += p1_step;
p2_off += p2_step;
Expand Down Expand Up @@ -455,7 +455,7 @@ static void load_all_objects(void)
l = pl->remaining_objects->front;
while (l) {
hint = llist_insert_sorted_unique(all_objects,
l->oid, hint);
&l->oid, hint);
l = l->next;
}
pl = pl->next;
Expand Down Expand Up @@ -521,7 +521,7 @@ static struct pack_list * add_pack(struct packed_git *p)
base += 256 * 4 + ((p->index_version < 2) ? 4 : 8);
step = the_hash_algo->rawsz + ((p->index_version < 2) ? 4 : 0);
while (off < p->num_objects * step) {
llist_insert_back(l.remaining_objects, (const struct object_id *)(base + off));
llist_insert_back(l.remaining_objects, base + off);
off += step;
}
l.all_objects_size = l.remaining_objects->size;
Expand Down
4 changes: 2 additions & 2 deletions builtin/rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ static const char * const builtin_rebase_interactive_usage[] = {
int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
{
struct rebase_options opts = REBASE_OPTIONS_INIT;
struct object_id squash_onto = null_oid;
struct object_id squash_onto = *null_oid();
enum action command = ACTION_NONE;
struct option options[] = {
OPT_NEGBIT(0, "ff", &opts.flags, N_("allow fast-forward"),
Expand Down Expand Up @@ -1140,7 +1140,7 @@ static int can_fast_forward(struct commit *onto, struct commit *upstream,

merge_bases = get_merge_bases(onto, head);
if (!merge_bases || merge_bases->next) {
oidcpy(merge_base, &null_oid);
oidcpy(merge_base, null_oid());
goto done;
}

Expand Down
2 changes: 1 addition & 1 deletion builtin/receive-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ static void write_head_info(void)
for_each_alternate_ref(show_one_alternate_ref, &seen);
oidset_clear(&seen);
if (!sent_capabilities)
show_ref("capabilities^{}", &null_oid);
show_ref("capabilities^{}", null_oid());

advertise_shallow_grafts(1);

Expand Down

0 comments on commit aaa3c80

Please sign in to comment.