Skip to content

Commit 844a9ce

Browse files
committed
Merge branch 'bc/object-id'
More transition from "unsigned char[40]" to "struct object_id". This needed a few merge fixups, but is mostly disentangled from other topics. * bc/object-id: remote: convert functions to struct object_id Remove get_object_hash. Convert struct object to object_id Add several uses of get_object_hash. object: introduce get_object_hash macro. ref_newer: convert to use struct object_id push_refs_with_export: convert to struct object_id get_remote_heads: convert to struct object_id parse_fetch: convert to use struct object_id add_sought_entry_mem: convert to struct object_id Convert struct ref to use object_id. sha1_file: introduce has_object_file helper.
2 parents b12a966 + fcd30b1 commit 844a9ce

Some content is hidden

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

88 files changed

+716
-704
lines changed

archive.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ int write_archive_entries(struct archiver_args *args,
241241
len--;
242242
if (args->verbose)
243243
fprintf(stderr, "%.*s\n", (int)len, args->base);
244-
err = write_entry(args, args->tree->object.sha1, args->base,
244+
err = write_entry(args, args->tree->object.oid.hash, args->base,
245245
len, 040777);
246246
if (err)
247247
return err;
@@ -374,7 +374,7 @@ static void parse_treeish_arg(const char **argv,
374374

375375
commit = lookup_commit_reference_gently(oid.hash, 1);
376376
if (commit) {
377-
commit_sha1 = commit->object.sha1;
377+
commit_sha1 = commit->object.oid.hash;
378378
archive_time = commit->date;
379379
} else {
380380
commit_sha1 = NULL;
@@ -390,7 +390,7 @@ static void parse_treeish_arg(const char **argv,
390390
unsigned int mode;
391391
int err;
392392

393-
err = get_tree_entry(tree->object.sha1, prefix,
393+
err = get_tree_entry(tree->object.oid.hash, prefix,
394394
tree_oid.hash, &mode);
395395
if (err || !S_ISDIR(mode))
396396
die("current working directory is untracked");

bisect.c

Lines changed: 5 additions & 5 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)
@@ -500,7 +500,7 @@ struct commit_list *filter_skipped(struct commit_list *list,
500500
struct commit_list *next = list->next;
501501
list->next = NULL;
502502
if (0 <= sha1_array_lookup(&skipped_revs,
503-
list->item->object.sha1)) {
503+
list->item->object.oid.hash)) {
504504
if (skipped_first && !*skipped_first)
505505
*skipped_first = 1;
506506
/* Move current to tried list */
@@ -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;
@@ -784,7 +784,7 @@ static void check_merge_bases(int no_checkout)
784784
result = get_merge_bases_many(rev[0], rev_nr - 1, rev + 1);
785785

786786
for (; result; result = result->next) {
787-
const unsigned char *mb = result->item->object.sha1;
787+
const unsigned char *mb = result->item->object.oid.hash;
788788
if (!hashcmp(mb, current_bad_oid->hash)) {
789789
handle_bad_merge_base();
790790
} else if (0 <= sha1_array_lookup(&good_revs, mb)) {
@@ -973,7 +973,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
973973
exit(4);
974974
}
975975

976-
bisect_rev = revs.commits->item->object.sha1;
976+
bisect_rev = revs.commits->item->object.oid.hash;
977977

978978
if (!hashcmp(bisect_rev, current_bad_oid->hash)) {
979979
exit_if_skipped_commits(tried, current_bad_oid);

branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ void create_branch(const char *head,
267267

268268
if ((commit = lookup_commit_reference(sha1)) == NULL)
269269
die(_("Not a valid branch point: '%s'."), start_name);
270-
hashcpy(sha1, commit->object.sha1);
270+
hashcpy(sha1, commit->object.oid.hash);
271271

272272
if (forcing)
273273
snprintf(msg, sizeof msg, "branch: Reset to %s",

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: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ static int fill_blob_sha1_and_mode(struct origin *origin)
506506
{
507507
if (!is_null_sha1(origin->blob_sha1))
508508
return 0;
509-
if (get_tree_entry(origin->commit->object.sha1,
509+
if (get_tree_entry(origin->commit->object.oid.hash,
510510
origin->path,
511511
origin->blob_sha1, &origin->mode))
512512
goto error_out;
@@ -557,11 +557,11 @@ 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))
561-
do_diff_cache(parent->tree->object.sha1, &diff_opts);
560+
if (is_null_oid(&origin->commit->object.oid))
561+
do_diff_cache(parent->tree->object.oid.hash, &diff_opts);
562562
else
563-
diff_tree_sha1(parent->tree->object.sha1,
564-
origin->commit->tree->object.sha1,
563+
diff_tree_sha1(parent->tree->object.oid.hash,
564+
origin->commit->tree->object.oid.hash,
565565
"", &diff_opts);
566566
diffcore_std(&diff_opts);
567567

@@ -627,11 +627,11 @@ 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))
631-
do_diff_cache(parent->tree->object.sha1, &diff_opts);
630+
if (is_null_oid(&origin->commit->object.oid))
631+
do_diff_cache(parent->tree->object.oid.hash, &diff_opts);
632632
else
633-
diff_tree_sha1(parent->tree->object.sha1,
634-
origin->commit->tree->object.sha1,
633+
diff_tree_sha1(parent->tree->object.oid.hash,
634+
origin->commit->tree->object.oid.hash,
635635
"", &diff_opts);
636636
diffcore_std(&diff_opts);
637637

@@ -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,11 +1275,11 @@ 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))
1279-
do_diff_cache(parent->tree->object.sha1, &diff_opts);
1278+
if (is_null_oid(&target->commit->object.oid))
1279+
do_diff_cache(parent->tree->object.oid.hash, &diff_opts);
12801280
else
1281-
diff_tree_sha1(parent->tree->object.sha1,
1282-
target->commit->tree->object.sha1,
1281+
diff_tree_sha1(parent->tree->object.oid.hash,
1282+
target->commit->tree->object.oid.hash,
12831283
"", &diff_opts);
12841284

12851285
if (!DIFF_OPT_TST(&diff_opts, FIND_COPIES_HARDER))
@@ -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++) {
@@ -2077,7 +2077,7 @@ static int read_ancestry(const char *graft_file)
20772077

20782078
static int update_auto_abbrev(int auto_abbrev, struct origin *suspect)
20792079
{
2080-
const char *uniq = find_unique_abbrev(suspect->commit->object.sha1,
2080+
const char *uniq = find_unique_abbrev(suspect->commit->object.oid.hash,
20812081
auto_abbrev);
20822082
int len = strlen(uniq);
20832083
if (auto_abbrev < len)
@@ -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
}
@@ -2216,7 +2216,7 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
22162216
struct commit_list *parents;
22172217

22182218
for (parents = work_tree->parents; parents; parents = parents->next) {
2219-
const unsigned char *commit_sha1 = parents->item->object.sha1;
2219+
const unsigned char *commit_sha1 = parents->item->object.oid.hash;
22202220
unsigned char blob_sha1[20];
22212221
unsigned mode;
22222222

@@ -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"
@@ -2738,7 +2738,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
27382738

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

27442744
l->item = c;
@@ -2748,11 +2748,11 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
27482748
c = c->parents->item;
27492749
}
27502750

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

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

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ static void add_verbose_info(struct strbuf *out, struct ref_array_item *item,
349349
fill_tracking_info(&stat, refname, filter->verbose > 1);
350350

351351
strbuf_addf(out, " %s %s%s",
352-
find_unique_abbrev(item->commit->object.sha1, filter->abbrev),
352+
find_unique_abbrev(item->commit->object.oid.hash, filter->abbrev),
353353
stat.buf, sub);
354354
strbuf_release(&stat);
355355
strbuf_release(&subject);

builtin/checkout.c

Lines changed: 11 additions & 11 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. */
@@ -401,7 +401,7 @@ static void describe_detached_head(const char *msg, struct commit *commit)
401401
if (!parse_commit(commit))
402402
pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
403403
fprintf(stderr, "%s %s... %s\n", msg,
404-
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV), sb.buf);
404+
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf);
405405
strbuf_release(&sb);
406406
}
407407

@@ -510,10 +510,10 @@ static int merge_working_tree(const struct checkout_opts *opts,
510510
setup_standard_excludes(topts.dir);
511511
}
512512
tree = parse_tree_indirect(old->commit ?
513-
old->commit->object.sha1 :
513+
old->commit->object.oid.hash :
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)
@@ -653,7 +653,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
653653
if (!strcmp(new->name, "HEAD") && !new->path && !opts->force_detach) {
654654
/* Nothing to do. */
655655
} else if (opts->force_detach || !new->path) { /* No longer on any branch. */
656-
update_ref(msg.buf, "HEAD", new->commit->object.sha1, NULL,
656+
update_ref(msg.buf, "HEAD", new->commit->object.oid.hash, NULL,
657657
REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
658658
if (!opts->quiet) {
659659
if (old->path && advice_detached_head)
@@ -704,7 +704,7 @@ static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
704704
{
705705
strbuf_addstr(sb, " ");
706706
strbuf_addstr(sb,
707-
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
707+
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV));
708708
strbuf_addch(sb, ' ');
709709
if (!parse_commit(commit))
710710
pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
@@ -762,7 +762,7 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
762762
" git branch <new-branch-name> %s\n\n",
763763
/* Give ngettext() the count */
764764
lost),
765-
find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
765+
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV));
766766
}
767767

768768
/*
@@ -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;

0 commit comments

Comments
 (0)