Skip to content

Commit f2fd076

Browse files
bk2204peff
authored andcommitted
Convert struct object to object_id
struct object is one of the major data structures dealing with object IDs. Convert it to use struct object_id instead of an unsigned char array. Convert get_object_hash to refer to the new member as well. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Jeff King <[email protected]>
1 parent 7999b2c commit f2fd076

Some content is hidden

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

54 files changed

+256
-256
lines changed

bisect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ static int compare_commit_dist(const void *a_, const void *b_)
193193
b = (struct commit_dist *)b_;
194194
if (a->distance != b->distance)
195195
return b->distance - a->distance; /* desc sort */
196-
return hashcmp(a->commit->object.sha1, b->commit->object.sha1);
196+
return oidcmp(&a->commit->object.oid, &b->commit->object.oid);
197197
}
198198

199199
static struct commit_list *best_bisection_sorted(struct commit_list *list, int nr)
@@ -575,7 +575,7 @@ static struct commit_list *skip_away(struct commit_list *list, int count)
575575

576576
for (i = 0; cur; cur = cur->next, i++) {
577577
if (i == index) {
578-
if (hashcmp(cur->item->object.sha1, current_bad_oid->hash))
578+
if (oidcmp(&cur->item->object.oid, current_bad_oid))
579579
return cur;
580580
if (previous)
581581
return previous;

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,7 @@ static void get_commit_info(struct am_state *state, struct commit *commit)
14411441
assert(!state->msg);
14421442
msg = strstr(buffer, "\n\n");
14431443
if (!msg)
1444-
die(_("unable to parse commit %s"), sha1_to_hex(commit->object.sha1));
1444+
die(_("unable to parse commit %s"), oid_to_hex(&commit->object.oid));
14451445
state->msg = xstrdup(msg + 2);
14461446
state->msg_len = strlen(state->msg);
14471447
}

builtin/blame.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ static struct origin *find_origin(struct scoreboard *sb,
557557
PATHSPEC_LITERAL_PATH, "", paths);
558558
diff_setup_done(&diff_opts);
559559

560-
if (is_null_sha1(origin->commit->object.sha1))
560+
if (is_null_oid(&origin->commit->object.oid))
561561
do_diff_cache(get_object_hash(parent->tree->object), &diff_opts);
562562
else
563563
diff_tree_sha1(get_object_hash(parent->tree->object),
@@ -627,7 +627,7 @@ static struct origin *find_rename(struct scoreboard *sb,
627627
diff_opts.single_follow = origin->path;
628628
diff_setup_done(&diff_opts);
629629

630-
if (is_null_sha1(origin->commit->object.sha1))
630+
if (is_null_oid(&origin->commit->object.oid))
631631
do_diff_cache(get_object_hash(parent->tree->object), &diff_opts);
632632
else
633633
diff_tree_sha1(get_object_hash(parent->tree->object),
@@ -977,8 +977,8 @@ static void pass_blame_to_parent(struct scoreboard *sb,
977977

978978
if (diff_hunks(&file_p, &file_o, 0, blame_chunk_cb, &d))
979979
die("unable to generate diff (%s -> %s)",
980-
sha1_to_hex(parent->commit->object.sha1),
981-
sha1_to_hex(target->commit->object.sha1));
980+
oid_to_hex(&parent->commit->object.oid),
981+
oid_to_hex(&target->commit->object.oid));
982982
/* The rest are the same as the parent */
983983
blame_chunk(&d.dstq, &d.srcq, INT_MAX, d.offset, INT_MAX, parent);
984984
*d.dstq = NULL;
@@ -1126,7 +1126,7 @@ static void find_copy_in_blob(struct scoreboard *sb,
11261126
memset(split, 0, sizeof(struct blame_entry [3]));
11271127
if (diff_hunks(file_p, &file_o, 1, handle_split_cb, &d))
11281128
die("unable to generate diff (%s)",
1129-
sha1_to_hex(parent->commit->object.sha1));
1129+
oid_to_hex(&parent->commit->object.oid));
11301130
/* remainder, if any, all match the preimage */
11311131
handle_split(sb, ent, d.tlno, d.plno, ent->num_lines, parent, split);
11321132
}
@@ -1275,7 +1275,7 @@ static void find_copy_in_parent(struct scoreboard *sb,
12751275
&& (!porigin || strcmp(target->path, porigin->path))))
12761276
DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);
12771277

1278-
if (is_null_sha1(target->commit->object.sha1))
1278+
if (is_null_oid(&target->commit->object.oid))
12791279
do_diff_cache(get_object_hash(parent->tree->object), &diff_opts);
12801280
else
12811281
diff_tree_sha1(get_object_hash(parent->tree->object),
@@ -1690,7 +1690,7 @@ static void get_commit_info(struct commit *commit,
16901690
if (len)
16911691
strbuf_add(&ret->summary, subject, len);
16921692
else
1693-
strbuf_addf(&ret->summary, "(%s)", sha1_to_hex(commit->object.sha1));
1693+
strbuf_addf(&ret->summary, "(%s)", oid_to_hex(&commit->object.oid));
16941694

16951695
unuse_commit_buffer(commit, message);
16961696
}
@@ -1733,7 +1733,7 @@ static int emit_one_suspect_detail(struct origin *suspect, int repeat)
17331733
printf("boundary\n");
17341734
if (suspect->previous) {
17351735
struct origin *prev = suspect->previous;
1736-
printf("previous %s ", sha1_to_hex(prev->commit->object.sha1));
1736+
printf("previous %s ", oid_to_hex(&prev->commit->object.oid));
17371737
write_name_quoted(prev->path, stdout, '\n');
17381738
}
17391739

@@ -1752,7 +1752,7 @@ static void found_guilty_entry(struct blame_entry *ent)
17521752
struct origin *suspect = ent->suspect;
17531753

17541754
printf("%s %d %d %d\n",
1755-
sha1_to_hex(suspect->commit->object.sha1),
1755+
oid_to_hex(&suspect->commit->object.oid),
17561756
ent->s_lno + 1, ent->lno + 1, ent->num_lines);
17571757
emit_one_suspect_detail(suspect, 0);
17581758
write_filename_info(suspect->path);
@@ -1882,7 +1882,7 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent,
18821882
struct origin *suspect = ent->suspect;
18831883
char hex[GIT_SHA1_HEXSZ + 1];
18841884

1885-
sha1_to_hex_r(hex, suspect->commit->object.sha1);
1885+
sha1_to_hex_r(hex, suspect->commit->object.oid.hash);
18861886
printf("%s %d %d %d\n",
18871887
hex,
18881888
ent->s_lno + 1,
@@ -1922,7 +1922,7 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
19221922
int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP);
19231923

19241924
get_commit_info(suspect->commit, &ci, 1);
1925-
sha1_to_hex_r(hex, suspect->commit->object.sha1);
1925+
sha1_to_hex_r(hex, suspect->commit->object.oid.hash);
19261926

19271927
cp = nth_line(sb, ent->lno);
19281928
for (cnt = 0; cnt < ent->num_lines; cnt++) {
@@ -2153,7 +2153,7 @@ static void sanity_check_refcnt(struct scoreboard *sb)
21532153
if (ent->suspect->refcnt <= 0) {
21542154
fprintf(stderr, "%s in %s has negative refcnt %d\n",
21552155
ent->suspect->path,
2156-
sha1_to_hex(ent->suspect->commit->object.sha1),
2156+
oid_to_hex(&ent->suspect->commit->object.oid),
21572157
ent->suspect->refcnt);
21582158
baa = 1;
21592159
}
@@ -2310,7 +2310,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
23102310
strbuf_addstr(&msg, "tree 0000000000000000000000000000000000000000\n");
23112311
for (parent = commit->parents; parent; parent = parent->next)
23122312
strbuf_addf(&msg, "parent %s\n",
2313-
sha1_to_hex(parent->item->object.sha1));
2313+
oid_to_hex(&parent->item->object.oid));
23142314
strbuf_addf(&msg,
23152315
"author %s\n"
23162316
"committer %s\n\n"
@@ -2740,7 +2740,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
27402740

27412741
sb.revs->children.name = "children";
27422742
while (c->parents &&
2743-
hashcmp(c->object.sha1, sb.final->object.sha1)) {
2743+
oidcmp(&c->object.oid, &sb.final->object.oid)) {
27442744
struct commit_list *l = xcalloc(1, sizeof(*l));
27452745

27462746
l->item = c;
@@ -2750,11 +2750,11 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
27502750
c = c->parents->item;
27512751
}
27522752

2753-
if (hashcmp(c->object.sha1, sb.final->object.sha1))
2753+
if (oidcmp(&c->object.oid, &sb.final->object.oid))
27542754
die("--reverse --first-parent together require range along first-parent chain");
27552755
}
27562756

2757-
if (is_null_sha1(sb.final->object.sha1)) {
2757+
if (is_null_oid(&sb.final->object.oid)) {
27582758
o = sb.final->util;
27592759
sb.final_buf = xmemdupz(o->file.ptr, o->file.size);
27602760
sb.final_buf_size = o->file.size;

builtin/checkout.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ static int post_checkout_hook(struct commit *old, struct commit *new,
5656
int changed)
5757
{
5858
return run_hook_le(NULL, "post-checkout",
59-
sha1_to_hex(old ? old->object.sha1 : null_sha1),
60-
sha1_to_hex(new ? new->object.sha1 : null_sha1),
59+
sha1_to_hex(old ? old->object.oid.hash : null_sha1),
60+
sha1_to_hex(new ? new->object.oid.hash : null_sha1),
6161
changed ? "1" : "0", NULL);
6262
/* "new" can be NULL when checking out from the index before
6363
a commit exists. */
@@ -513,7 +513,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
513513
get_object_hash(old->commit->object) :
514514
EMPTY_TREE_SHA1_BIN);
515515
init_tree_desc(&trees[0], tree->buffer, tree->size);
516-
tree = parse_tree_indirect(new->commit->object.sha1);
516+
tree = parse_tree_indirect(new->commit->object.oid.hash);
517517
init_tree_desc(&trees[1], tree->buffer, tree->size);
518518

519519
ret = unpack_trees(2, trees, &topts);
@@ -641,7 +641,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
641641

642642
old_desc = old->name;
643643
if (!old_desc && old->commit)
644-
old_desc = sha1_to_hex(old->commit->object.sha1);
644+
old_desc = oid_to_hex(&old->commit->object.oid);
645645

646646
reflog_msg = getenv("GIT_REFLOG_ACTION");
647647
if (!reflog_msg)
@@ -780,10 +780,10 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new)
780780
setup_revisions(0, NULL, &revs, NULL);
781781

782782
object->flags &= ~UNINTERESTING;
783-
add_pending_object(&revs, object, sha1_to_hex(object->sha1));
783+
add_pending_object(&revs, object, oid_to_hex(&object->oid));
784784

785785
for_each_ref(add_pending_uninteresting_ref, &revs);
786-
add_pending_sha1(&revs, "HEAD", new->object.sha1, UNINTERESTING);
786+
add_pending_sha1(&revs, "HEAD", new->object.oid.hash, UNINTERESTING);
787787

788788
refs = revs.pending;
789789
revs.leak_pending = 1;

builtin/commit-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ static const char *sign_commit;
1616

1717
static void new_parent(struct commit *parent, struct commit_list **parents_p)
1818
{
19-
unsigned char *sha1 = parent->object.sha1;
19+
struct object_id *oid = &parent->object.oid;
2020
struct commit_list *parents;
2121
for (parents = *parents_p; parents; parents = parents->next) {
2222
if (parents->item == parent) {
23-
error("duplicate parent %s ignored", sha1_to_hex(sha1));
23+
error("duplicate parent %s ignored", oid_to_hex(oid));
2424
return;
2525
}
2626
parents_p = &parents->next;

builtin/describe.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ static void describe(const char *arg, int last_one)
267267
}
268268

269269
if (!max_candidates)
270-
die(_("no tag exactly matches '%s'"), sha1_to_hex(cmit->object.sha1));
270+
die(_("no tag exactly matches '%s'"), oid_to_hex(&cmit->object.oid));
271271
if (debug)
272272
fprintf(stderr, _("searching to describe %s\n"), arg);
273273

@@ -317,7 +317,7 @@ static void describe(const char *arg, int last_one)
317317
if (annotated_cnt && !list) {
318318
if (debug)
319319
fprintf(stderr, _("finished search at %s\n"),
320-
sha1_to_hex(c->object.sha1));
320+
oid_to_hex(&c->object.oid));
321321
break;
322322
}
323323
while (parents) {
@@ -334,9 +334,9 @@ static void describe(const char *arg, int last_one)
334334
}
335335

336336
if (!match_cnt) {
337-
const unsigned char *sha1 = cmit->object.sha1;
337+
struct object_id *oid = &cmit->object.oid;
338338
if (always) {
339-
printf("%s", find_unique_abbrev(sha1, abbrev));
339+
printf("%s", find_unique_abbrev(oid->hash, abbrev));
340340
if (dirty)
341341
printf("%s", dirty);
342342
printf("\n");
@@ -345,11 +345,11 @@ static void describe(const char *arg, int last_one)
345345
if (unannotated_cnt)
346346
die(_("No annotated tags can describe '%s'.\n"
347347
"However, there were unannotated tags: try --tags."),
348-
sha1_to_hex(sha1));
348+
oid_to_hex(oid));
349349
else
350350
die(_("No tags can describe '%s'.\n"
351351
"Try --always, or create some tags."),
352-
sha1_to_hex(sha1));
352+
oid_to_hex(oid));
353353
}
354354

355355
qsort(all_matches, match_cnt, sizeof(all_matches[0]), compare_pt);
@@ -374,7 +374,7 @@ static void describe(const char *arg, int last_one)
374374
_("more than %i tags found; listed %i most recent\n"
375375
"gave up search at %s\n"),
376376
max_candidates, max_candidates,
377-
sha1_to_hex(gave_up_on->object.sha1));
377+
oid_to_hex(&gave_up_on->object.oid));
378378
}
379379
}
380380

builtin/diff-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ static int stdin_diff_trees(struct tree *tree1, char *line, int len)
4949
tree2 = lookup_tree(sha1);
5050
if (!tree2 || parse_tree(tree2))
5151
return -1;
52-
printf("%s %s\n", sha1_to_hex(tree1->object.sha1),
53-
sha1_to_hex(tree2->object.sha1));
52+
printf("%s %s\n", oid_to_hex(&tree1->object.oid),
53+
oid_to_hex(&tree2->object.oid));
5454
diff_tree_sha1(get_object_hash(tree1->object), get_object_hash(tree2->object),
5555
"", &log_tree_opt.diffopt);
5656
log_tree_diff_flush(&log_tree_opt);

builtin/fast-export.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -544,13 +544,13 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
544544
author = strstr(commit_buffer, "\nauthor ");
545545
if (!author)
546546
die ("Could not find author in commit %s",
547-
sha1_to_hex(commit->object.sha1));
547+
oid_to_hex(&commit->object.oid));
548548
author++;
549549
author_end = strchrnul(author, '\n');
550550
committer = strstr(author_end, "\ncommitter ");
551551
if (!committer)
552552
die ("Could not find committer in commit %s",
553-
sha1_to_hex(commit->object.sha1));
553+
oid_to_hex(&commit->object.oid));
554554
committer++;
555555
committer_end = strchrnul(committer, '\n');
556556
message = strstr(committer_end, "\n\n");
@@ -661,13 +661,13 @@ static void handle_tag(const char *name, struct tag *tag)
661661
}
662662
if (tagged->type == OBJ_TREE) {
663663
warning("Omitting tag %s,\nsince tags of trees (or tags of tags of trees, etc.) are not supported.",
664-
sha1_to_hex(tag->object.sha1));
664+
oid_to_hex(&tag->object.oid));
665665
return;
666666
}
667667

668668
buf = read_sha1_file(get_object_hash(tag->object), &type, &size);
669669
if (!buf)
670-
die ("Could not read tag %s", sha1_to_hex(tag->object.sha1));
670+
die ("Could not read tag %s", oid_to_hex(&tag->object.oid));
671671
message = memmem(buf, size, "\n\n", 2);
672672
if (message) {
673673
message += 2;
@@ -706,16 +706,16 @@ static void handle_tag(const char *name, struct tag *tag)
706706
case ABORT:
707707
die ("Encountered signed tag %s; use "
708708
"--signed-tags=<mode> to handle it.",
709-
sha1_to_hex(tag->object.sha1));
709+
oid_to_hex(&tag->object.oid));
710710
case WARN:
711711
warning ("Exporting signed tag %s",
712-
sha1_to_hex(tag->object.sha1));
712+
oid_to_hex(&tag->object.oid));
713713
/* fallthru */
714714
case VERBATIM:
715715
break;
716716
case WARN_STRIP:
717717
warning ("Stripping signature from tag %s",
718-
sha1_to_hex(tag->object.sha1));
718+
oid_to_hex(&tag->object.oid));
719719
/* fallthru */
720720
case STRIP:
721721
message_size = signature + 1 - message;
@@ -731,14 +731,14 @@ static void handle_tag(const char *name, struct tag *tag)
731731
case ABORT:
732732
die ("Tag %s tags unexported object; use "
733733
"--tag-of-filtered-object=<mode> to handle it.",
734-
sha1_to_hex(tag->object.sha1));
734+
oid_to_hex(&tag->object.oid));
735735
case DROP:
736736
/* Ignore this tag altogether */
737737
return;
738738
case REWRITE:
739739
if (tagged->type != OBJ_COMMIT) {
740740
die ("Tag %s tags unexported %s!",
741-
sha1_to_hex(tag->object.sha1),
741+
oid_to_hex(&tag->object.oid),
742742
typename(tagged->type));
743743
}
744744
p = (struct commit *)tagged;
@@ -751,7 +751,7 @@ static void handle_tag(const char *name, struct tag *tag)
751751
break;
752752
if (!p->parents)
753753
die ("Can't find replacement commit for tag %s\n",
754-
sha1_to_hex(tag->object.sha1));
754+
oid_to_hex(&tag->object.oid));
755755
p = p->parents->item;
756756
}
757757
tagged_mark = get_object_mark(&p->object);
@@ -888,7 +888,7 @@ static void export_marks(char *file)
888888
if (deco->base && deco->base->type == 1) {
889889
mark = ptr_to_mark(deco->decoration);
890890
if (fprintf(f, ":%"PRIu32" %s\n", mark,
891-
sha1_to_hex(deco->base->sha1)) < 0) {
891+
oid_to_hex(&deco->base->oid)) < 0) {
892892
e = 1;
893893
break;
894894
}

builtin/fmt-merge-msg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ static void shortlog(const char *name,
378378

379379
if (!sb.len)
380380
string_list_append(&subjects,
381-
sha1_to_hex(commit->object.sha1));
381+
oid_to_hex(&commit->object.oid));
382382
else
383383
string_list_append(&subjects, strbuf_detach(&sb, NULL));
384384
}

0 commit comments

Comments
 (0)