Skip to content

Commit 92e2cab

Browse files
bk2204gitster
authored andcommitted
Always use oidread to read into struct object_id
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cf09832 commit 92e2cab

File tree

13 files changed

+23
-23
lines changed

13 files changed

+23
-23
lines changed

archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static void queue_directory(const unsigned char *sha1,
203203
d->mode = mode;
204204
c->bottom = d;
205205
d->len = xsnprintf(d->path, len, "%.*s%s/", (int)base->len, base->buf, filename);
206-
hashcpy(d->oid.hash, sha1);
206+
oidread(&d->oid, sha1);
207207
}
208208

209209
static int write_directory(struct archiver_context *c)

builtin/fast-import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,8 +1276,8 @@ static void load_tree(struct tree_entry *root)
12761276
e->versions[0].mode = e->versions[1].mode;
12771277
e->name = to_atom(c, strlen(c));
12781278
c += e->name->str_len + 1;
1279-
hashcpy(e->versions[0].oid.hash, (unsigned char *)c);
1280-
hashcpy(e->versions[1].oid.hash, (unsigned char *)c);
1279+
oidread(&e->versions[0].oid, (unsigned char *)c);
1280+
oidread(&e->versions[1].oid, (unsigned char *)c);
12811281
c += the_hash_algo->rawsz;
12821282
}
12831283
free(buf);

builtin/index-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ static void *unpack_raw_entry(struct object_entry *obj,
524524

525525
switch (obj->type) {
526526
case OBJ_REF_DELTA:
527-
hashcpy(ref_oid->hash, fill(the_hash_algo->rawsz));
527+
oidread(ref_oid, fill(the_hash_algo->rawsz));
528528
use(the_hash_algo->rawsz);
529529
break;
530530
case OBJ_OFS_DELTA:
@@ -1358,7 +1358,7 @@ static struct object_entry *append_obj_to_pack(struct hashfile *f,
13581358
obj[1].idx.offset += write_compressed(f, buf, size);
13591359
obj[0].idx.crc32 = crc32_end(f);
13601360
hashflush(f);
1361-
hashcpy(obj->idx.oid.hash, sha1);
1361+
oidread(&obj->idx.oid, sha1);
13621362
return obj;
13631363
}
13641364

builtin/unpack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
355355
struct object_id base_oid;
356356

357357
if (type == OBJ_REF_DELTA) {
358-
hashcpy(base_oid.hash, fill(the_hash_algo->rawsz));
358+
oidread(&base_oid, fill(the_hash_algo->rawsz));
359359
use(the_hash_algo->rawsz);
360360
delta_data = get_data(delta_size);
361361
if (dry_run || !delta_data) {

commit-graph.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ struct commit_graph *parse_commit_graph(struct repository *r,
425425
FREE_AND_NULL(graph->bloom_filter_settings);
426426
}
427427

428-
hashcpy(graph->oid.hash, graph->data + graph->data_len - graph->hash_len);
428+
oidread(&graph->oid, graph->data + graph->data_len - graph->hash_len);
429429

430430
if (verify_commit_graph_lite(graph))
431431
goto free_and_return;
@@ -746,7 +746,7 @@ static void load_oid_from_graph(struct commit_graph *g,
746746

747747
lex_index = pos - g->num_commits_in_base;
748748

749-
hashcpy(oid->hash, g->chunk_oid_lookup + g->hash_len * lex_index);
749+
oidread(oid, g->chunk_oid_lookup + g->hash_len * lex_index);
750750
}
751751

752752
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,
939939
commit_data = g->chunk_commit_data +
940940
GRAPH_DATA_WIDTH * (graph_pos - g->num_commits_in_base);
941941

942-
hashcpy(oid.hash, commit_data);
942+
oidread(&oid, commit_data);
943943
set_commit_tree(c, lookup_tree(r, &oid));
944944

945945
return c->maybe_tree;
@@ -2322,7 +2322,7 @@ int write_commit_graph(struct object_directory *odb,
23222322
struct commit_graph *g = ctx->r->objects->commit_graph;
23232323
for (i = 0; i < g->num_commits; i++) {
23242324
struct object_id oid;
2325-
hashcpy(oid.hash, g->chunk_oid_lookup + g->hash_len * i);
2325+
oidread(&oid, g->chunk_oid_lookup + g->hash_len * i);
23262326
oid_array_append(&ctx->oids, &oid);
23272327
}
23282328
}
@@ -2453,7 +2453,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
24532453
for (i = 0; i < g->num_commits; i++) {
24542454
struct commit *graph_commit;
24552455

2456-
hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
2456+
oidread(&cur_oid, g->chunk_oid_lookup + g->hash_len * i);
24572457

24582458
if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
24592459
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)
25012501
timestamp_t generation;
25022502

25032503
display_progress(progress, i + 1);
2504-
hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
2504+
oidread(&cur_oid, g->chunk_oid_lookup + g->hash_len * i);
25052505

25062506
graph_commit = lookup_commit(r, &cur_oid);
25072507
odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r));

dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3344,15 +3344,15 @@ static void read_oid(size_t pos, void *cb)
33443344
rd->data = rd->end + 1;
33453345
return;
33463346
}
3347-
hashcpy(ud->exclude_oid.hash, rd->data);
3347+
oidread(&ud->exclude_oid, rd->data);
33483348
rd->data += the_hash_algo->rawsz;
33493349
}
33503350

33513351
static void load_oid_stat(struct oid_stat *oid_stat, const unsigned char *data,
33523352
const unsigned char *sha1)
33533353
{
33543354
stat_data_from_disk(&oid_stat->stat, data);
3355-
hashcpy(oid_stat->oid.hash, sha1);
3355+
oidread(&oid_stat->oid, sha1);
33563356
oid_stat->valid = 1;
33573357
}
33583358

http-walker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static void prefetch(struct walker *walker, unsigned char *sha1)
155155

156156
newreq = xmalloc(sizeof(*newreq));
157157
newreq->walker = walker;
158-
hashcpy(newreq->oid.hash, sha1);
158+
oidread(&newreq->oid, sha1);
159159
newreq->repo = data->alt;
160160
newreq->state = WAITING;
161161
newreq->req = NULL;

match-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
226226
oid_to_hex(oid1));
227227
if (*subpath) {
228228
struct object_id tree_oid;
229-
hashcpy(tree_oid.hash, rewrite_here);
229+
oidread(&tree_oid, rewrite_here);
230230
status = splice_tree(&tree_oid, subpath, oid2, &subtree);
231231
if (status)
232232
return status;

midx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ struct object_id *nth_midxed_object_oid(struct object_id *oid,
247247
if (n >= m->num_objects)
248248
return NULL;
249249

250-
hashcpy(oid->hash, m->chunk_oid_lookup + m->hash_len * n);
250+
oidread(oid, m->chunk_oid_lookup + m->hash_len * n);
251251
return oid;
252252
}
253253

notes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ static void add_non_note(struct notes_tree *t, char *path,
352352
n->next = NULL;
353353
n->path = path;
354354
n->mode = mode;
355-
hashcpy(n->oid.hash, sha1);
355+
oidread(&n->oid, sha1);
356356
t->prev_non_note = n;
357357

358358
if (!t->first_non_note) {
@@ -1134,7 +1134,7 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
11341134
if (!t)
11351135
t = &default_notes_tree;
11361136
assert(t->initialized);
1137-
hashcpy(l.key_oid.hash, object_sha1);
1137+
oidread(&l.key_oid, object_sha1);
11381138
oidclr(&l.val_oid);
11391139
note_tree_remove(t, t->root, 0, &l);
11401140
if (is_null_oid(&l.val_oid)) /* no note was removed */

0 commit comments

Comments
 (0)