]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Always use oidread to read into struct object_id
authorbrian m. carlson <sandals@crustytoothpaste.net>
Mon, 26 Apr 2021 01:02:50 +0000 (01:02 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Apr 2021 07:31:38 +0000 (16:31 +0900)
In the future, we'll want oidread to automatically set the hash
algorithm member for an object ID we read into it, so ensure we use
oidread instead of hashcpy everywhere we're copying a hash value into a
struct object_id.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
13 files changed:
archive.c
builtin/fast-import.c
builtin/index-pack.c
builtin/unpack-objects.c
commit-graph.c
dir.c
http-walker.c
match-trees.c
midx.c
notes.c
read-cache.c
split-index.c
tree-walk.c

index 295615580d710672404a82f5c104ccc5c78ed700..6cfb9e42d6ce96fbbc152ac038d890d28620ca98 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -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)
index 3afa81cf9acdba53ef6ddaa30b54e5ae539f745d..9d2a058a6664a4c8a71e3fe83c1d93edbcddec2d 100644 (file)
@@ -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);
index 15507b5cff0f7dd241e77c1f1daeb6cdee7b01c5..41e2c240b890dfd7c751366cb130be00b919d75a 100644 (file)
@@ -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:
@@ -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;
 }
 
index 4a70b17f8fb394c17f98bc8683e7b38f5bf975ba..a8b73ecf43a6dd9411f5f8772b6a4ef939ef9c5a 100644 (file)
@@ -355,7 +355,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
        struct object_id base_oid;
 
        if (type == OBJ_REF_DELTA) {
-               hashcpy(base_oid.hash, fill(the_hash_algo->rawsz));
+               oidread(&base_oid, fill(the_hash_algo->rawsz));
                use(the_hash_algo->rawsz);
                delta_data = get_data(delta_size);
                if (dry_run || !delta_data) {
index f18380b922c12208cbceae92fce98e2e6b42e6ed..23fef56d3112dc5701754fbea5fe821ba3100a96 100644 (file)
@@ -425,7 +425,7 @@ struct commit_graph *parse_commit_graph(struct repository *r,
                FREE_AND_NULL(graph->bloom_filter_settings);
        }
 
-       hashcpy(graph->oid.hash, graph->data + graph->data_len - graph->hash_len);
+       oidread(&graph->oid, graph->data + graph->data_len - graph->hash_len);
 
        if (verify_commit_graph_lite(graph))
                goto free_and_return;
@@ -746,7 +746,7 @@ static void load_oid_from_graph(struct commit_graph *g,
 
        lex_index = pos - g->num_commits_in_base;
 
-       hashcpy(oid->hash, g->chunk_oid_lookup + g->hash_len * lex_index);
+       oidread(oid, g->chunk_oid_lookup + g->hash_len * lex_index);
 }
 
 static struct commit_list **insert_parent_or_die(struct repository *r,
@@ -939,7 +939,7 @@ static struct tree *load_tree_for_commit(struct repository *r,
        commit_data = g->chunk_commit_data +
                        GRAPH_DATA_WIDTH * (graph_pos - g->num_commits_in_base);
 
-       hashcpy(oid.hash, commit_data);
+       oidread(&oid, commit_data);
        set_commit_tree(c, lookup_tree(r, &oid));
 
        return c->maybe_tree;
@@ -2322,7 +2322,7 @@ int write_commit_graph(struct object_directory *odb,
                struct commit_graph *g = ctx->r->objects->commit_graph;
                for (i = 0; i < g->num_commits; i++) {
                        struct object_id oid;
-                       hashcpy(oid.hash, g->chunk_oid_lookup + g->hash_len * i);
+                       oidread(&oid, g->chunk_oid_lookup + g->hash_len * i);
                        oid_array_append(&ctx->oids, &oid);
                }
        }
@@ -2453,7 +2453,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
        for (i = 0; i < g->num_commits; i++) {
                struct commit *graph_commit;
 
-               hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
+               oidread(&cur_oid, g->chunk_oid_lookup + g->hash_len * i);
 
                if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
                        graph_report(_("commit-graph has incorrect OID order: %s then %s"),
@@ -2501,7 +2501,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
                timestamp_t generation;
 
                display_progress(progress, i + 1);
-               hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
+               oidread(&cur_oid, g->chunk_oid_lookup + g->hash_len * i);
 
                graph_commit = lookup_commit(r, &cur_oid);
                odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r));
diff --git a/dir.c b/dir.c
index 3474e67e8f3c0f12303784dca09be56c7a226344..813dd7ba53723442dc54d095d38f1930a869a808 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -3344,7 +3344,7 @@ static void read_oid(size_t pos, void *cb)
                rd->data = rd->end + 1;
                return;
        }
-       hashcpy(ud->exclude_oid.hash, rd->data);
+       oidread(&ud->exclude_oid, rd->data);
        rd->data += the_hash_algo->rawsz;
 }
 
@@ -3352,7 +3352,7 @@ static void load_oid_stat(struct oid_stat *oid_stat, const unsigned char *data,
                          const unsigned char *sha1)
 {
        stat_data_from_disk(&oid_stat->stat, data);
-       hashcpy(oid_stat->oid.hash, sha1);
+       oidread(&oid_stat->oid, sha1);
        oid_stat->valid = 1;
 }
 
index 4fb1235cd455464ad863a76097197f1c27827509..90d8ecb57ef8629e1691f7e785fea1446c09017c 100644 (file)
@@ -155,7 +155,7 @@ static void prefetch(struct walker *walker, unsigned char *sha1)
 
        newreq = xmalloc(sizeof(*newreq));
        newreq->walker = walker;
-       hashcpy(newreq->oid.hash, sha1);
+       oidread(&newreq->oid, sha1);
        newreq->repo = data->alt;
        newreq->state = WAITING;
        newreq->req = NULL;
index f6c194c1cca6bd64489b5dc1e90e5525da25d873..df413989fa85cb007f3c7d88375283b6243687ca 100644 (file)
@@ -226,7 +226,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
                    oid_to_hex(oid1));
        if (*subpath) {
                struct object_id tree_oid;
-               hashcpy(tree_oid.hash, rewrite_here);
+               oidread(&tree_oid, rewrite_here);
                status = splice_tree(&tree_oid, subpath, oid2, &subtree);
                if (status)
                        return status;
diff --git a/midx.c b/midx.c
index 9e8658317251dfc5c2d5aa116305e229783dde76..21d6a05e887283400ae0ee10dd06d62418021997 100644 (file)
--- a/midx.c
+++ b/midx.c
@@ -247,7 +247,7 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,
        if (n >= m->num_objects)
                return NULL;
 
-       hashcpy(oid->hash, m->chunk_oid_lookup + m->hash_len * n);
+       oidread(oid, m->chunk_oid_lookup + m->hash_len * n);
        return oid;
 }
 
diff --git a/notes.c b/notes.c
index a19e4ad79434336eea35b614342534a19a56042e..a44b25858f538d35db879e0626bc862026f557d9 100644 (file)
--- a/notes.c
+++ b/notes.c
@@ -352,7 +352,7 @@ static void add_non_note(struct notes_tree *t, char *path,
        n->next = NULL;
        n->path = path;
        n->mode = mode;
-       hashcpy(n->oid.hash, sha1);
+       oidread(&n->oid, sha1);
        t->prev_non_note = n;
 
        if (!t->first_non_note) {
@@ -1134,7 +1134,7 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
        if (!t)
                t = &default_notes_tree;
        assert(t->initialized);
-       hashcpy(l.key_oid.hash, object_sha1);
+       oidread(&l.key_oid, object_sha1);
        oidclr(&l.val_oid);
        note_tree_remove(t, t->root, 0, &l);
        if (is_null_oid(&l.val_oid)) /* no note was removed */
index 5a907af2fb52f53d2e533edeec5f9ed470f8ba31..2944146545ec30e6bb47ff17844fa7d32b8607f6 100644 (file)
@@ -1845,7 +1845,7 @@ static struct cache_entry *create_from_disk(struct mem_pool *ce_mem_pool,
        ce->ce_flags = flags & ~CE_NAMEMASK;
        ce->ce_namelen = len;
        ce->index = 0;
-       hashcpy(ce->oid.hash, ondisk->data);
+       oidread(&ce->oid, ondisk->data);
        memcpy(ce->name, name, len);
        ce->name[len] = '\0';
 
@@ -2195,7 +2195,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)
        if (verify_hdr(hdr, mmap_size) < 0)
                goto unmap;
 
-       hashcpy(istate->oid.hash, (const unsigned char *)hdr + mmap_size - the_hash_algo->rawsz);
+       oidread(&istate->oid, (const unsigned char *)hdr + mmap_size - the_hash_algo->rawsz);
        istate->version = ntohl(hdr->hdr_version);
        istate->cache_nr = ntohl(hdr->hdr_entries);
        istate->cache_alloc = alloc_nr(istate->cache_nr);
index 94937d21a39da8e0e3de9413019fdeae3db06a20..4d6e52d46f7549c9c14d78c036bcccac400db30f 100644 (file)
@@ -21,7 +21,7 @@ int read_link_extension(struct index_state *istate,
        if (sz < the_hash_algo->rawsz)
                return error("corrupt link extension (too short)");
        si = init_split_index(istate);
-       hashcpy(si->base_oid.hash, data);
+       oidread(&si->base_oid, data);
        data += the_hash_algo->rawsz;
        sz -= the_hash_algo->rawsz;
        if (!sz)
index 2d6226d5f1883669e9fb775914512dea2ed0dd7a..3a94959d64a3a63b784bcadfd47cd12213f3fb2d 100644 (file)
@@ -49,7 +49,7 @@ static int decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned l
        desc->entry.path = path;
        desc->entry.mode = canon_mode(mode);
        desc->entry.pathlen = len - 1;
-       hashcpy(desc->entry.oid.hash, (const unsigned char *)path + len);
+       oidread(&desc->entry.oid, (const unsigned char *)path + len);
 
        return 0;
 }