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 <sandals@crustytoothpaste.net> Signed-off-by: Jeff King <peff@peff.net>

brian m. carlson committed Nov 10, 2015 at 02:22 UTC f2fd0760f62e79609fef7bfd7ecebb002e8e4ced
54 files changed +256 -256
bisect.c
+2 -2
@@ -193,7 +193,7 @@ static int compare_commit_dist(const void *a_, const void *b_)
193 b = (struct commit_dist *)b_;
194 if (a->distance != b->distance)
195 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);
197 }
198
199 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)
575
576 for (i = 0; cur; cur = cur->next, i++) {
577 if (i == index) {
578 - if (hashcmp(cur->item->object.sha1, current_bad_oid->hash))
578 + if (oidcmp(&cur->item->object.oid, current_bad_oid))
579 return cur;
580 if (previous)
581 return previous;
builtin/am.c
+1 -1
@@ -1441,7 +1441,7 @@ static void get_commit_info(struct am_state *state, struct commit *commit)
1441 assert(!state->msg);
1442 msg = strstr(buffer, "\n\n");
1443 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));
1445 state->msg = xstrdup(msg + 2);
1446 state->msg_len = strlen(state->msg);
1447 }
builtin/blame.c
+16 -16
@@ -557,7 +557,7 @@ static struct origin *find_origin(struct scoreboard *sb,
557 PATHSPEC_LITERAL_PATH, "", paths);
558 diff_setup_done(&diff_opts);
559
560 - if (is_null_sha1(origin->commit->object.sha1))
560 + if (is_null_oid(&origin->commit->object.oid))
561 do_diff_cache(get_object_hash(parent->tree->object), &diff_opts);
562 else
563 diff_tree_sha1(get_object_hash(parent->tree->object),
@@ -627,7 +627,7 @@ static struct origin *find_rename(struct scoreboard *sb,
627 diff_opts.single_follow = origin->path;
628 diff_setup_done(&diff_opts);
629
630 - if (is_null_sha1(origin->commit->object.sha1))
630 + if (is_null_oid(&origin->commit->object.oid))
631 do_diff_cache(get_object_hash(parent->tree->object), &diff_opts);
632 else
633 diff_tree_sha1(get_object_hash(parent->tree->object),
@@ -977,8 +977,8 @@ static void pass_blame_to_parent(struct scoreboard *sb,
977
978 if (diff_hunks(&file_p, &file_o, 0, blame_chunk_cb, &d))
979 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));
982 /* The rest are the same as the parent */
983 blame_chunk(&d.dstq, &d.srcq, INT_MAX, d.offset, INT_MAX, parent);
984 *d.dstq = NULL;
@@ -1126,7 +1126,7 @@ static void find_copy_in_blob(struct scoreboard *sb,
1126 memset(split, 0, sizeof(struct blame_entry [3]));
1127 if (diff_hunks(file_p, &file_o, 1, handle_split_cb, &d))
1128 die("unable to generate diff (%s)",
1129 - sha1_to_hex(parent->commit->object.sha1));
1129 + oid_to_hex(&parent->commit->object.oid));
1130 /* remainder, if any, all match the preimage */
1131 handle_split(sb, ent, d.tlno, d.plno, ent->num_lines, parent, split);
1132 }
@@ -1275,7 +1275,7 @@ static void find_copy_in_parent(struct scoreboard *sb,
1275 && (!porigin || strcmp(target->path, porigin->path))))
1276 DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);
1277
1278 - if (is_null_sha1(target->commit->object.sha1))
1278 + if (is_null_oid(&target->commit->object.oid))
1279 do_diff_cache(get_object_hash(parent->tree->object), &diff_opts);
1280 else
1281 diff_tree_sha1(get_object_hash(parent->tree->object),
@@ -1690,7 +1690,7 @@ static void get_commit_info(struct commit *commit,
1690 if (len)
1691 strbuf_add(&ret->summary, subject, len);
1692 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));
1694
1695 unuse_commit_buffer(commit, message);
1696 }
@@ -1733,7 +1733,7 @@ static int emit_one_suspect_detail(struct origin *suspect, int repeat)
1733 printf("boundary\n");
1734 if (suspect->previous) {
1735 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));
1737 write_name_quoted(prev->path, stdout, '\n');
1738 }
1739
@@ -1752,7 +1752,7 @@ static void found_guilty_entry(struct blame_entry *ent)
1752 struct origin *suspect = ent->suspect;
1753
1754 printf("%s %d %d %d\n",
1755 - sha1_to_hex(suspect->commit->object.sha1),
1755 + oid_to_hex(&suspect->commit->object.oid),
1756 ent->s_lno + 1, ent->lno + 1, ent->num_lines);
1757 emit_one_suspect_detail(suspect, 0);
1758 write_filename_info(suspect->path);
@@ -1882,7 +1882,7 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent,
1882 struct origin *suspect = ent->suspect;
1883 char hex[GIT_SHA1_HEXSZ + 1];
1884
1885 - sha1_to_hex_r(hex, suspect->commit->object.sha1);
1885 + sha1_to_hex_r(hex, suspect->commit->object.oid.hash);
1886 printf("%s %d %d %d\n",
1887 hex,
1888 ent->s_lno + 1,
@@ -1922,7 +1922,7 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
1922 int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP);
1923
1924 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);
1926
1927 cp = nth_line(sb, ent->lno);
1928 for (cnt = 0; cnt < ent->num_lines; cnt++) {
@@ -2153,7 +2153,7 @@ static void sanity_check_refcnt(struct scoreboard *sb)
2153 if (ent->suspect->refcnt <= 0) {
2154 fprintf(stderr, "%s in %s has negative refcnt %d\n",
2155 ent->suspect->path,
2156 - sha1_to_hex(ent->suspect->commit->object.sha1),
2156 + oid_to_hex(&ent->suspect->commit->object.oid),
2157 ent->suspect->refcnt);
2158 baa = 1;
2159 }
@@ -2310,7 +2310,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
2310 strbuf_addstr(&msg, "tree 0000000000000000000000000000000000000000\n");
2311 for (parent = commit->parents; parent; parent = parent->next)
2312 strbuf_addf(&msg, "parent %s\n",
2313 - sha1_to_hex(parent->item->object.sha1));
2313 + oid_to_hex(&parent->item->object.oid));
2314 strbuf_addf(&msg,
2315 "author %s\n"
2316 "committer %s\n\n"
@@ -2740,7 +2740,7 @@ parse_done:
2740
2741 sb.revs->children.name = "children";
2742 while (c->parents &&
2743 - hashcmp(c->object.sha1, sb.final->object.sha1)) {
2743 + oidcmp(&c->object.oid, &sb.final->object.oid)) {
2744 struct commit_list *l = xcalloc(1, sizeof(*l));
2745
2746 l->item = c;
@@ -2750,11 +2750,11 @@ parse_done:
2750 c = c->parents->item;
2751 }
2752
2753 - if (hashcmp(c->object.sha1, sb.final->object.sha1))
2753 + if (oidcmp(&c->object.oid, &sb.final->object.oid))
2754 die("--reverse --first-parent together require range along first-parent chain");
2755 }
2756
2757 - if (is_null_sha1(sb.final->object.sha1)) {
2757 + if (is_null_oid(&sb.final->object.oid)) {
2758 o = sb.final->util;
2759 sb.final_buf = xmemdupz(o->file.ptr, o->file.size);
2760 sb.final_buf_size = o->file.size;
builtin/checkout.c
+6 -6
@@ -56,8 +56,8 @@ static int post_checkout_hook(struct commit *old, struct commit *new,
56 int changed)
57 {
58 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),
61 changed ? "1" : "0", NULL);
62 /* "new" can be NULL when checking out from the index before
63 a commit exists. */
@@ -513,7 +513,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
513 get_object_hash(old->commit->object) :
514 EMPTY_TREE_SHA1_BIN);
515 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);
517 init_tree_desc(&trees[1], tree->buffer, tree->size);
518
519 ret = unpack_trees(2, trees, &topts);
@@ -641,7 +641,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
641
642 old_desc = old->name;
643 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);
645
646 reflog_msg = getenv("GIT_REFLOG_ACTION");
647 if (!reflog_msg)
@@ -780,10 +780,10 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new)
780 setup_revisions(0, NULL, &revs, NULL);
781
782 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));
784
785 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);
787
788 refs = revs.pending;
789 revs.leak_pending = 1;
builtin/commit-tree.c
+2 -2
@@ -16,11 +16,11 @@ static const char *sign_commit;
16
17 static void new_parent(struct commit *parent, struct commit_list **parents_p)
18 {
19 - unsigned char *sha1 = parent->object.sha1;
19 + struct object_id *oid = &parent->object.oid;
20 struct commit_list *parents;
21 for (parents = *parents_p; parents; parents = parents->next) {
22 if (parents->item == parent) {
23 - error("duplicate parent %s ignored", sha1_to_hex(sha1));
23 + error("duplicate parent %s ignored", oid_to_hex(oid));
24 return;
25 }
26 parents_p = &parents->next;
builtin/describe.c
+7 -7
@@ -267,7 +267,7 @@ static void describe(const char *arg, int last_one)
267 }
268
269 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));
271 if (debug)
272 fprintf(stderr, _("searching to describe %s\n"), arg);
273
@@ -317,7 +317,7 @@ static void describe(const char *arg, int last_one)
317 if (annotated_cnt && !list) {
318 if (debug)
319 fprintf(stderr, _("finished search at %s\n"),
320 - sha1_to_hex(c->object.sha1));
320 + oid_to_hex(&c->object.oid));
321 break;
322 }
323 while (parents) {
@@ -334,9 +334,9 @@ static void describe(const char *arg, int last_one)
334 }
335
336 if (!match_cnt) {
337 - const unsigned char *sha1 = cmit->object.sha1;
337 + struct object_id *oid = &cmit->object.oid;
338 if (always) {
339 - printf("%s", find_unique_abbrev(sha1, abbrev));
339 + printf("%s", find_unique_abbrev(oid->hash, abbrev));
340 if (dirty)
341 printf("%s", dirty);
342 printf("\n");
@@ -345,11 +345,11 @@ static void describe(const char *arg, int last_one)
345 if (unannotated_cnt)
346 die(_("No annotated tags can describe '%s'.\n"
347 "However, there were unannotated tags: try --tags."),
348 - sha1_to_hex(sha1));
348 + oid_to_hex(oid));
349 else
350 die(_("No tags can describe '%s'.\n"
351 "Try --always, or create some tags."),
352 - sha1_to_hex(sha1));
352 + oid_to_hex(oid));
353 }
354
355 qsort(all_matches, match_cnt, sizeof(all_matches[0]), compare_pt);
@@ -374,7 +374,7 @@ static void describe(const char *arg, int last_one)
374 _("more than %i tags found; listed %i most recent\n"
375 "gave up search at %s\n"),
376 max_candidates, max_candidates,
377 - sha1_to_hex(gave_up_on->object.sha1));
377 + oid_to_hex(&gave_up_on->object.oid));
378 }
379 }
380
builtin/diff-tree.c
+2 -2
@@ -49,8 +49,8 @@ static int stdin_diff_trees(struct tree *tree1, char *line, int len)
49 tree2 = lookup_tree(sha1);
50 if (!tree2 || parse_tree(tree2))
51 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));
54 diff_tree_sha1(get_object_hash(tree1->object), get_object_hash(tree2->object),
55 "", &log_tree_opt.diffopt);
56 log_tree_diff_flush(&log_tree_opt);
builtin/fast-export.c
+11 -11
@@ -544,13 +544,13 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
544 author = strstr(commit_buffer, "\nauthor ");
545 if (!author)
546 die ("Could not find author in commit %s",
547 - sha1_to_hex(commit->object.sha1));
547 + oid_to_hex(&commit->object.oid));
548 author++;
549 author_end = strchrnul(author, '\n');
550 committer = strstr(author_end, "\ncommitter ");
551 if (!committer)
552 die ("Could not find committer in commit %s",
553 - sha1_to_hex(commit->object.sha1));
553 + oid_to_hex(&commit->object.oid));
554 committer++;
555 committer_end = strchrnul(committer, '\n');
556 message = strstr(committer_end, "\n\n");
@@ -661,13 +661,13 @@ static void handle_tag(const char *name, struct tag *tag)
661 }
662 if (tagged->type == OBJ_TREE) {
663 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));
665 return;
666 }
667
668 buf = read_sha1_file(get_object_hash(tag->object), &type, &size);
669 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));
671 message = memmem(buf, size, "\n\n", 2);
672 if (message) {
673 message += 2;
@@ -706,16 +706,16 @@ static void handle_tag(const char *name, struct tag *tag)
706 case ABORT:
707 die ("Encountered signed tag %s; use "
708 "--signed-tags=<mode> to handle it.",
709 - sha1_to_hex(tag->object.sha1));
709 + oid_to_hex(&tag->object.oid));
710 case WARN:
711 warning ("Exporting signed tag %s",
712 - sha1_to_hex(tag->object.sha1));
712 + oid_to_hex(&tag->object.oid));
713 /* fallthru */
714 case VERBATIM:
715 break;
716 case WARN_STRIP:
717 warning ("Stripping signature from tag %s",
718 - sha1_to_hex(tag->object.sha1));
718 + oid_to_hex(&tag->object.oid));
719 /* fallthru */
720 case STRIP:
721 message_size = signature + 1 - message;
@@ -731,14 +731,14 @@ static void handle_tag(const char *name, struct tag *tag)
731 case ABORT:
732 die ("Tag %s tags unexported object; use "
733 "--tag-of-filtered-object=<mode> to handle it.",
734 - sha1_to_hex(tag->object.sha1));
734 + oid_to_hex(&tag->object.oid));
735 case DROP:
736 /* Ignore this tag altogether */
737 return;
738 case REWRITE:
739 if (tagged->type != OBJ_COMMIT) {
740 die ("Tag %s tags unexported %s!",
741 - sha1_to_hex(tag->object.sha1),
741 + oid_to_hex(&tag->object.oid),
742 typename(tagged->type));
743 }
744 p = (struct commit *)tagged;
@@ -751,7 +751,7 @@ static void handle_tag(const char *name, struct tag *tag)
751 break;
752 if (!p->parents)
753 die ("Can't find replacement commit for tag %s\n",
754 - sha1_to_hex(tag->object.sha1));
754 + oid_to_hex(&tag->object.oid));
755 p = p->parents->item;
756 }
757 tagged_mark = get_object_mark(&p->object);
@@ -888,7 +888,7 @@ static void export_marks(char *file)
888 if (deco->base && deco->base->type == 1) {
889 mark = ptr_to_mark(deco->decoration);
890 if (fprintf(f, ":%"PRIu32" %s\n", mark,
891 - sha1_to_hex(deco->base->sha1)) < 0) {
891 + oid_to_hex(&deco->base->oid)) < 0) {
892 e = 1;
893 break;
894 }
builtin/fmt-merge-msg.c
+1 -1
@@ -378,7 +378,7 @@ static void shortlog(const char *name,
378
379 if (!sb.len)
380 string_list_append(&subjects,
381 - sha1_to_hex(commit->object.sha1));
381 + oid_to_hex(&commit->object.oid));
382 else
383 string_list_append(&subjects, strbuf_detach(&sb, NULL));
384 }
builtin/fsck.c
+16 -16
@@ -67,7 +67,7 @@ static void objreport(struct object *obj, const char *msg_type,
67 const char *err)
68 {
69 fprintf(stderr, "%s in %s %s: %s\n",
70 - msg_type, typename(obj->type), sha1_to_hex(obj->sha1), err);
70 + msg_type, typename(obj->type), oid_to_hex(&obj->oid), err);
71 }
72
73 static int objerror(struct object *obj, const char *err)
@@ -97,7 +97,7 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt
97 if (!obj) {
98 /* ... these references to parent->fld are safe here */
99 printf("broken link from %7s %s\n",
100 - typename(parent->type), sha1_to_hex(parent->sha1));
100 + typename(parent->type), oid_to_hex(&parent->oid));
101 printf("broken link from %7s %s\n",
102 (type == OBJ_ANY ? "unknown" : typename(type)), "unknown");
103 errors_found |= ERROR_REACHABLE;
@@ -112,11 +112,11 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt
112 return 0;
113 obj->flags |= REACHABLE;
114 if (!(obj->flags & HAS_OBJ)) {
115 - if (parent && !has_sha1_file(obj->sha1)) {
115 + if (parent && !has_object_file(&obj->oid)) {
116 printf("broken link from %7s %s\n",
117 - typename(parent->type), sha1_to_hex(parent->sha1));
117 + typename(parent->type), oid_to_hex(&parent->oid));
118 printf(" to %7s %s\n",
119 - typename(obj->type), sha1_to_hex(obj->sha1));
119 + typename(obj->type), oid_to_hex(&obj->oid));
120 errors_found |= ERROR_REACHABLE;
121 }
122 return 1;
@@ -188,9 +188,9 @@ static void check_reachable_object(struct object *obj)
188 if (!(obj->flags & HAS_OBJ)) {
189 if (has_sha1_pack(get_object_hash(*obj)))
190 return; /* it is in pack - forget about it */
191 - if (connectivity_only && has_sha1_file(obj->sha1))
191 + if (connectivity_only && has_object_file(&obj->oid))
192 return;
193 - printf("missing %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1));
193 + printf("missing %s %s\n", typename(obj->type), oid_to_hex(&obj->oid));
194 errors_found |= ERROR_REACHABLE;
195 return;
196 }
@@ -215,7 +215,7 @@ static void check_unreachable_object(struct object *obj)
215 * since this is something that is prunable.
216 */
217 if (show_unreachable) {
218 - printf("unreachable %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1));
218 + printf("unreachable %s %s\n", typename(obj->type), oid_to_hex(&obj->oid));
219 return;
220 }
221
@@ -234,11 +234,11 @@ static void check_unreachable_object(struct object *obj)
234 if (!obj->used) {
235 if (show_dangling)
236 printf("dangling %s %s\n", typename(obj->type),
237 - sha1_to_hex(obj->sha1));
237 + oid_to_hex(&obj->oid));
238 if (write_lost_and_found) {
239 char *filename = git_pathdup("lost-found/%s/%s",
240 obj->type == OBJ_COMMIT ? "commit" : "other",
241 - sha1_to_hex(obj->sha1));
241 + oid_to_hex(&obj->oid));
242 FILE *f;
243
244 if (safe_create_leading_directories_const(filename)) {
@@ -252,7 +252,7 @@ static void check_unreachable_object(struct object *obj)
252 if (stream_blob_to_fd(fileno(f), get_object_hash(*obj), NULL, 1))
253 die_errno("Could not write '%s'", filename);
254 } else
255 - fprintf(f, "%s\n", sha1_to_hex(obj->sha1));
255 + fprintf(f, "%s\n", oid_to_hex(&obj->oid));
256 if (fclose(f))
257 die_errno("Could not finish '%s'",
258 filename);
@@ -271,7 +271,7 @@ static void check_unreachable_object(struct object *obj)
271 static void check_object(struct object *obj)
272 {
273 if (verbose)
274 - fprintf(stderr, "Checking %s\n", sha1_to_hex(obj->sha1));
274 + fprintf(stderr, "Checking %s\n", oid_to_hex(&obj->oid));
275
276 if (obj->flags & REACHABLE)
277 check_reachable_object(obj);
@@ -307,7 +307,7 @@ static int fsck_obj(struct object *obj)
307
308 if (verbose)
309 fprintf(stderr, "Checking %s %s\n",
310 - typename(obj->type), sha1_to_hex(obj->sha1));
310 + typename(obj->type), oid_to_hex(&obj->oid));
311
312 if (fsck_walk(obj, NULL, &fsck_obj_options))
313 objerror(obj, "broken links");
@@ -326,15 +326,15 @@ static int fsck_obj(struct object *obj)
326 free_commit_buffer(commit);
327
328 if (!commit->parents && show_root)
329 - printf("root %s\n", sha1_to_hex(commit->object.sha1));
329 + printf("root %s\n", oid_to_hex(&commit->object.oid));
330 }
331
332 if (obj->type == OBJ_TAG) {
333 struct tag *tag = (struct tag *) obj;
334
335 if (show_tags && tag->tagged) {
336 - printf("tagged %s %s", typename(tag->tagged->type), sha1_to_hex(tag->tagged->sha1));
337 - printf(" (%s) in %s\n", tag->tag, sha1_to_hex(tag->object.sha1));
336 + printf("tagged %s %s", typename(tag->tagged->type), oid_to_hex(&tag->tagged->oid));
337 + printf(" (%s) in %s\n", tag->tag, oid_to_hex(&tag->object.oid));
338 }
339 }
340
builtin/grep.c
+2 -2
@@ -468,12 +468,12 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
468 int hit, len;
469
470 grep_read_lock();
471 - data = read_object_with_reference(obj->sha1, tree_type,
471 + data = read_object_with_reference(obj->oid.hash, tree_type,
472 &size, NULL);
473 grep_read_unlock();
474
475 if (!data)
476 - die(_("unable to read tree (%s)"), sha1_to_hex(obj->sha1));
476 + die(_("unable to read tree (%s)"), oid_to_hex(&obj->oid));
477
478 len = name ? strlen(name) : 0;
479 strbuf_init(&base, PATH_MAX + len + 1);
builtin/index-pack.c
+4 -4
@@ -199,7 +199,7 @@ static int mark_link(struct object *obj, int type, void *data, struct fsck_optio
199 return -1;
200
201 if (type != OBJ_ANY && obj->type != type)
202 - die(_("object type mismatch at %s"), sha1_to_hex(obj->sha1));
202 + die(_("object type mismatch at %s"), oid_to_hex(&obj->oid));
203
204 obj->flags |= FLAG_LINK;
205 return 0;
@@ -220,10 +220,10 @@ static unsigned check_object(struct object *obj)
220 int type = sha1_object_info(get_object_hash(*obj), &size);
221 if (type <= 0)
222 die(_("did not receive expected object %s"),
223 - sha1_to_hex(obj->sha1));
223 + oid_to_hex(&obj->oid));
224 if (type != obj->type)
225 die(_("object %s: expected type %s, found %s"),
226 - sha1_to_hex(obj->sha1),
226 + oid_to_hex(&obj->oid),
227 typename(obj->type), typename(type));
228 obj->flags |= FLAG_CHECKED;
229 return 1;
@@ -842,7 +842,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
842 fsck_object(obj, buf, size, &fsck_options))
843 die(_("Error in object"));
844 if (fsck_walk(obj, NULL, &fsck_options))
845 - die(_("Not all child objects of %s are reachable"), sha1_to_hex(obj->sha1));
845 + die(_("Not all child objects of %s are reachable"), oid_to_hex(&obj->oid));
846
847 if (obj->type == OBJ_TREE) {
848 struct tree *item = (struct tree *) obj;
builtin/log.c
+9 -9
@@ -570,7 +570,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
570 o = parse_object(get_object_hash(*t->tagged));
571 if (!o)
572 ret = error(_("Could not read object %s"),
573 - sha1_to_hex(t->tagged->sha1));
573 + oid_to_hex(&t->tagged->oid));
574 objects[i].item = o;
575 i--;
576 break;
@@ -896,8 +896,8 @@ static void add_branch_description(struct strbuf *buf, const char *branch_name)
896 static char *find_branch_name(struct rev_info *rev)
897 {
898 int i, positive = -1;
899 - unsigned char branch_sha1[20];
900 - const unsigned char *tip_sha1;
899 + struct object_id branch_oid;
900 + const struct object_id *tip_oid;
901 const char *ref, *v;
902 char *full_ref, *branch = NULL;
903
@@ -912,10 +912,10 @@ static char *find_branch_name(struct rev_info *rev)
912 if (positive < 0)
913 return NULL;
914 ref = rev->cmdline.rev[positive].name;
915 - tip_sha1 = rev->cmdline.rev[positive].item->sha1;
916 - if (dwim_ref(ref, strlen(ref), branch_sha1, &full_ref) &&
915 + tip_oid = &rev->cmdline.rev[positive].item->oid;
916 + if (dwim_ref(ref, strlen(ref), branch_oid.hash, &full_ref) &&
917 skip_prefix(full_ref, "refs/heads/", &v) &&
918 - !hashcmp(tip_sha1, branch_sha1))
918 + !oidcmp(tip_oid, &branch_oid))
919 branch = xstrdup(v);
920 free(full_ref);
921 return branch;
@@ -1443,7 +1443,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1443 /* Don't say anything if head and upstream are the same. */
1444 if (rev.pending.nr == 2) {
1445 struct object_array_entry *o = rev.pending.objects;
1446 - if (hashcmp(o[0].item->sha1, o[1].item->sha1) == 0)
1446 + if (oidcmp(&o[0].item->oid, &o[1].item->oid) == 0)
1447 return 0;
1448 }
1449 get_patch_ids(&rev, &ids);
@@ -1550,7 +1550,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1550 string_list_append(rev.ref_message_ids,
1551 rev.message_id);
1552 }
1553 - gen_message_id(&rev, sha1_to_hex(commit->object.sha1));
1553 + gen_message_id(&rev, oid_to_hex(&commit->object.oid));
1554 }
1555
1556 if (!use_stdout &&
@@ -1675,7 +1675,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
1675 /* Don't say anything if head and upstream are the same. */
1676 if (revs.pending.nr == 2) {
1677 struct object_array_entry *o = revs.pending.objects;
1678 - if (hashcmp(o[0].item->sha1, o[1].item->sha1) == 0)
1678 + if (oidcmp(&o[0].item->oid, &o[1].item->oid) == 0)
1679 return 0;
1680 }
1681
builtin/merge-base.c
+4 -4
@@ -16,7 +16,7 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
16 return 1;
17
18 while (result) {
19 - printf("%s\n", sha1_to_hex(result->item->object.sha1));
19 + printf("%s\n", oid_to_hex(&result->item->object.oid));
20 if (!show_all)
21 return 0;
22 result = result->next;
@@ -62,7 +62,7 @@ static int handle_independent(int count, const char **args)
62 return 1;
63
64 while (result) {
65 - printf("%s\n", sha1_to_hex(result->item->object.sha1));
65 + printf("%s\n", oid_to_hex(&result->item->object.oid));
66 result = result->next;
67 }
68 return 0;
@@ -83,7 +83,7 @@ static int handle_octopus(int count, const char **args, int show_all)
83 return 1;
84
85 while (result) {
86 - printf("%s\n", sha1_to_hex(result->item->object.sha1));
86 + printf("%s\n", oid_to_hex(&result->item->object.oid));
87 if (!show_all)
88 return 0;
89 result = result->next;
@@ -196,7 +196,7 @@ static int handle_fork_point(int argc, const char **argv)
196 goto cleanup_return;
197 }
198
199 - printf("%s\n", sha1_to_hex(bases->item->object.sha1));
199 + printf("%s\n", oid_to_hex(&bases->item->object.oid));
200
201 cleanup_return:
202 free_commit_list(bases);
builtin/merge-tree.c
+1 -1
@@ -130,7 +130,7 @@ static void show_result_list(struct merge_list *entry)
130 do {
131 struct merge_list *link = entry->link;
132 static const char *desc[4] = { "result", "base", "our", "their" };
133 - printf(" %-6s %o %s %s\n", desc[entry->stage], entry->mode, sha1_to_hex(entry->blob->object.sha1), entry->path);
133 + printf(" %-6s %o %s %s\n", desc[entry->stage], entry->mode, oid_to_hex(&entry->blob->object.oid), entry->path);
134 entry = link;
135 } while (entry);
136 }
builtin/merge.c
+5 -5
@@ -365,7 +365,7 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead
365 while ((commit = get_revision(&rev)) != NULL) {
366 strbuf_addch(&out, '\n');
367 strbuf_addf(&out, "commit %s\n",
368 - sha1_to_hex(get_object_hash(commit->object)));
368 + oid_to_hex(&commit->object.oid));
369 pretty_print_commit(&ctx, commit, &out);
370 }
371 if (write_in_full(fd, out.buf, out.len) != out.len)
@@ -958,14 +958,14 @@ static void write_merge_state(struct commit_list *remoteheads)
958 struct strbuf buf = STRBUF_INIT;
959
960 for (j = remoteheads; j; j = j->next) {
961 - unsigned const char *sha1;
961 + struct object_id *oid;
962 struct commit *c = j->item;
963 if (c->util && merge_remote_util(c)->obj) {
964 - sha1 = merge_remote_util(c)->obj->sha1;
964 + oid = &merge_remote_util(c)->obj->oid;
965 } else {
966 - sha1 = get_object_hash(c->object);
966 + oid = &c->object.oid;
967 }
968 - strbuf_addf(&buf, "%s\n", sha1_to_hex(sha1));
968 + strbuf_addf(&buf, "%s\n", oid_to_hex(oid));
969 }
970 filename = git_path_merge_head();
971 fd = open(filename, O_WRONLY | O_CREAT, 0666);
builtin/name-rev.c
+4 -4
@@ -232,19 +232,19 @@ static void show_name(const struct object *obj,
232 int always, int allow_undefined, int name_only)
233 {
234 const char *name;
235 - const unsigned char *sha1 = get_object_hash(*obj);
235 + const struct object_id *oid = &obj->oid;
236
237 if (!name_only)
238 - printf("%s ", caller_name ? caller_name : sha1_to_hex(sha1));
238 + printf("%s ", caller_name ? caller_name : oid_to_hex(oid));
239 name = get_rev_name(obj);
240 if (name)
241 printf("%s\n", name);
242 else if (allow_undefined)
243 printf("undefined\n");
244 else if (always)
245 - printf("%s\n", find_unique_abbrev(sha1, DEFAULT_ABBREV));
245 + printf("%s\n", find_unique_abbrev(oid->hash, DEFAULT_ABBREV));
246 else
247 - die("cannot describe '%s'", sha1_to_hex(sha1));
247 + die("cannot describe '%s'", oid_to_hex(oid));
248 }
249
250 static char const * const name_rev_usage[] = {
builtin/pack-objects.c
+1 -1
@@ -2338,7 +2338,7 @@ static int ofscmp(const void *a_, const void *b_)
2338 else if (a->offset > b->offset)
2339 return 1;
2340 else
2341 - return hashcmp(a->object->sha1, b->object->sha1);
2341 + return oidcmp(&a->object->oid, &b->object->oid);
2342 }
2343
2344 static void add_objects_in_unpacked_packs(struct rev_info *revs)
builtin/pull.c
+1 -1
@@ -743,7 +743,7 @@ static int get_octopus_merge_base(unsigned char *merge_base,
743 if (!result)
744 return 1;
745
746 - hashcpy(merge_base, result->item->object.sha1);
746 + hashcpy(merge_base, get_object_hash(result->item->object));
747 return 0;
748 }
749
builtin/replace.c
+3 -3
@@ -358,10 +358,10 @@ static void check_one_mergetag(struct commit *commit,
358
359 /* iterate over new parents */
360 for (i = 1; i < mergetag_data->argc; i++) {
361 - unsigned char sha1[20];
362 - if (get_sha1(mergetag_data->argv[i], sha1) < 0)
361 + struct object_id oid;
362 + if (get_sha1(mergetag_data->argv[i], oid.hash) < 0)
363 die(_("Not a valid object name: '%s'"), mergetag_data->argv[i]);
364 - if (!hashcmp(tag->tagged->sha1, sha1))
364 + if (!oidcmp(&tag->tagged->oid, &oid))
365 return; /* found */
366 }
367
builtin/reset.c
+14 -14
@@ -269,7 +269,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
269 int reset_type = NONE, update_ref_status = 0, quiet = 0;
270 int patch_mode = 0, unborn;
271 const char *rev;
272 - unsigned char sha1[20];
272 + struct object_id oid;
273 struct pathspec pathspec;
274 int intent_to_add = 0;
275 const struct option options[] = {
@@ -295,26 +295,26 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
295 PARSE_OPT_KEEP_DASHDASH);
296 parse_args(&pathspec, argv, prefix, patch_mode, &rev);
297
298 - unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", sha1);
298 + unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", oid.hash);
299 if (unborn) {
300 /* reset on unborn branch: treat as reset to empty tree */
301 - hashcpy(sha1, EMPTY_TREE_SHA1_BIN);
301 + hashcpy(oid.hash, EMPTY_TREE_SHA1_BIN);
302 } else if (!pathspec.nr) {
303 struct commit *commit;
304 - if (get_sha1_committish(rev, sha1))
304 + if (get_sha1_committish(rev, oid.hash))
305 die(_("Failed to resolve '%s' as a valid revision."), rev);
306 - commit = lookup_commit_reference(sha1);
306 + commit = lookup_commit_reference(oid.hash);
307 if (!commit)
308 die(_("Could not parse object '%s'."), rev);
309 - hashcpy(sha1, commit->object.sha1);
309 + oidcpy(&oid, &commit->object.oid);
310 } else {
311 struct tree *tree;
312 - if (get_sha1_treeish(rev, sha1))
312 + if (get_sha1_treeish(rev, oid.hash))
313 die(_("Failed to resolve '%s' as a valid tree."), rev);
314 - tree = parse_tree_indirect(sha1);
314 + tree = parse_tree_indirect(oid.hash);
315 if (!tree)
316 die(_("Could not parse object '%s'."), rev);
317 - hashcpy(sha1, tree->object.sha1);
317 + oidcpy(&oid, &tree->object.oid);
318 }
319
320 if (patch_mode) {
@@ -357,15 +357,15 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
357 hold_locked_index(lock, 1);
358 if (reset_type == MIXED) {
359 int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;
360 - if (read_from_tree(&pathspec, sha1, intent_to_add))
360 + if (read_from_tree(&pathspec, oid.hash, intent_to_add))
361 return 1;
362 if (get_git_work_tree())
363 refresh_index(&the_index, flags, NULL, NULL,
364 _("Unstaged changes after reset:"));
365 } else {
366 - int err = reset_index(sha1, reset_type, quiet);
366 + int err = reset_index(oid.hash, reset_type, quiet);
367 if (reset_type == KEEP && !err)
368 - err = reset_index(sha1, MIXED, quiet);
368 + err = reset_index(oid.hash, MIXED, quiet);
369 if (err)
370 die(_("Could not reset index file to revision '%s'."), rev);
371 }
@@ -377,10 +377,10 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
377 if (!pathspec.nr && !unborn) {
378 /* Any resets without paths update HEAD to the head being
379 * switched to, saving the previous head in ORIG_HEAD before. */
380 - update_ref_status = reset_refs(rev, sha1);
380 + update_ref_status = reset_refs(rev, oid.hash);
381
382 if (reset_type == HARD && !update_ref_status && !quiet)
383 - print_new_head_line(lookup_commit_reference(sha1));
383 + print_new_head_line(lookup_commit_reference(oid.hash));
384 }
385 if (!pathspec.nr)
386 remove_branch_state();
builtin/rev-list.c
+7 -7
@@ -84,11 +84,11 @@ static void show_commit(struct commit *commit, void *data)
84 fputs(find_unique_abbrev(get_object_hash(commit->object), revs->abbrev),
85 stdout);
86 else
87 - fputs(sha1_to_hex(commit->object.sha1), stdout);
87 + fputs(oid_to_hex(&commit->object.oid), stdout);
88 if (revs->print_parents) {
89 struct commit_list *parents = commit->parents;
90 while (parents) {
91 - printf(" %s", sha1_to_hex(parents->item->object.sha1));
91 + printf(" %s", oid_to_hex(&parents->item->object.oid));
92 parents = parents->next;
93 }
94 }
@@ -97,7 +97,7 @@ static void show_commit(struct commit *commit, void *data)
97
98 children = lookup_decoration(&revs->children, &commit->object);
99 while (children) {
100 - printf(" %s", sha1_to_hex(children->item->object.sha1));
100 + printf(" %s", oid_to_hex(&children->item->object.oid));
101 children = children->next;
102 }
103 }
@@ -182,8 +182,8 @@ static void finish_object(struct object *obj,
182 void *cb_data)
183 {
184 struct rev_list_info *info = cb_data;
185 - if (obj->type == OBJ_BLOB && !has_sha1_file(obj->sha1))
186 - die("missing blob object '%s'", sha1_to_hex(obj->sha1));
185 + if (obj->type == OBJ_BLOB && !has_object_file(&obj->oid))
186 + die("missing blob object '%s'", oid_to_hex(&obj->oid));
187 if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)
188 parse_object(get_object_hash(*obj));
189 }
@@ -201,7 +201,7 @@ static void show_object(struct object *obj,
201
202 static void show_edge(struct commit *commit)
203 {
204 - printf("-%s\n", sha1_to_hex(commit->object.sha1));
204 + printf("-%s\n", oid_to_hex(&commit->object.oid));
205 }
206
207 static void print_var_str(const char *var, const char *val)
@@ -242,7 +242,7 @@ static int show_bisect_vars(struct rev_list_info *info, int reaches, int all)
242 cnt = reaches;
243
244 if (revs->commits)
245 - sha1_to_hex_r(hex, revs->commits->item->object.sha1);
245 + sha1_to_hex_r(hex, revs->commits->item->object.oid.hash);
246
247 if (flags & BISECT_SHOW_ALL) {
248 traverse_commit_list(revs, show_commit, show_object, info);
builtin/shortlog.c
+1 -1
@@ -129,7 +129,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
129 }
130 if (!author) {
131 warning(_("Missing author: %s"),
132 - sha1_to_hex(commit->object.sha1));
132 + oid_to_hex(&commit->object.oid));
133 return;
134 }
135 if (log->user_format) {
builtin/show-branch.c
+2 -2
@@ -496,7 +496,7 @@ static int show_merge_base(struct commit_list *seen, int num_rev)
496 int flags = commit->object.flags & all_mask;
497 if (!(flags & UNINTERESTING) &&
498 ((flags & all_revs) == all_revs)) {
499 - puts(sha1_to_hex(commit->object.sha1));
499 + puts(oid_to_hex(&commit->object.oid));
500 exit_status = 0;
501 commit->object.flags |= UNINTERESTING;
502 }
@@ -516,7 +516,7 @@ static int show_independent(struct commit **rev,
516 unsigned int flag = rev_mask[i];
517
518 if (commit->object.flags == flag)
519 - puts(sha1_to_hex(commit->object.sha1));
519 + puts(oid_to_hex(&commit->object.oid));
520 commit->object.flags |= UNINTERESTING;
521 }
522 return 0;
builtin/unpack-objects.c
+4 -4
@@ -46,7 +46,7 @@ static void add_object_buffer(struct object *object, char *buffer, unsigned long
46 obj->buffer = buffer;
47 obj->size = size;
48 if (add_decoration(&obj_decorate, object, obj))
49 - die("object %s tried to add buffer twice!", sha1_to_hex(object->sha1));
49 + die("object %s tried to add buffer twice!", oid_to_hex(&object->oid));
50 }
51
52 /*
@@ -170,7 +170,7 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
170 unsigned char sha1[20];
171
172 if (write_sha1_file(obj_buf->buffer, obj_buf->size, typename(obj->type), sha1) < 0)
173 - die("failed to write object %s", sha1_to_hex(obj->sha1));
173 + die("failed to write object %s", oid_to_hex(&obj->oid));
174 obj->flags |= FLAG_WRITTEN;
175 }
176
@@ -203,12 +203,12 @@ static int check_object(struct object *obj, int type, void *data, struct fsck_op
203
204 obj_buf = lookup_object_buffer(obj);
205 if (!obj_buf)
206 - die("Whoops! Cannot find object '%s'", sha1_to_hex(obj->sha1));
206 + die("Whoops! Cannot find object '%s'", oid_to_hex(&obj->oid));
207 if (fsck_object(obj, obj_buf->buffer, obj_buf->size, &fsck_options))
208 die("Error in object");
209 fsck_options.walk = check_object;
210 if (fsck_walk(obj, NULL, &fsck_options))
211 - die("Error on reachable objects of %s", sha1_to_hex(obj->sha1));
211 + die("Error on reachable objects of %s", oid_to_hex(&obj->oid));
212 write_cached_object(obj, obj_buf);
213 return 0;
214 }
builtin/worktree.c
+1 -1
@@ -277,7 +277,7 @@ static int add_worktree(const char *path, const char *refname,
277
278 if (commit)
279 argv_array_pushl(&cp.args, "update-ref", "HEAD",
280 - sha1_to_hex(commit->object.sha1), NULL);
280 + oid_to_hex(&commit->object.oid), NULL);
281 else
282 argv_array_pushl(&cp.args, "symbolic-ref", "HEAD",
283 symref.buf, NULL);
bundle.c
+9 -9
@@ -171,7 +171,7 @@ int verify_bundle(struct bundle_header *header, int verbose)
171 if (!(refs.objects[i].item->flags & SHOWN)) {
172 if (++ret == 1)
173 error("%s", message);
174 - error("%s %s", sha1_to_hex(refs.objects[i].item->sha1),
174 + error("%s %s", oid_to_hex(&refs.objects[i].item->oid),
175 refs.objects[i].name);
176 }
177
@@ -256,7 +256,7 @@ static int write_pack_data(int bundle_fd, struct rev_info *revs)
256 struct object *object = revs->pending.objects[i].item;
257 if (object->flags & UNINTERESTING)
258 write_or_die(pack_objects.in, "^", 1);
259 - write_or_die(pack_objects.in, sha1_to_hex(object->sha1), 40);
259 + write_or_die(pack_objects.in, oid_to_hex(&object->oid), GIT_SHA1_HEXSZ);
260 write_or_die(pack_objects.in, "\n", 1);
261 }
262 close(pack_objects.in);
@@ -321,16 +321,16 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
321
322 for (i = 0; i < revs->pending.nr; i++) {
323 struct object_array_entry *e = revs->pending.objects + i;
324 - unsigned char sha1[20];
324 + struct object_id oid;
325 char *ref;
326 const char *display_ref;
327 int flag;
328
329 if (e->item->flags & UNINTERESTING)
330 continue;
331 - if (dwim_ref(e->name, strlen(e->name), sha1, &ref) != 1)
331 + if (dwim_ref(e->name, strlen(e->name), oid.hash, &ref) != 1)
332 goto skip_write_ref;
333 - if (read_ref_full(e->name, RESOLVE_REF_READING, sha1, &flag))
333 + if (read_ref_full(e->name, RESOLVE_REF_READING, oid.hash, &flag))
334 flag = 0;
335 display_ref = (flag & REF_ISSYMREF) ? e->name : ref;
336
@@ -360,13 +360,13 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
360 * commit that is referenced by the tag, and not the tag
361 * itself.
362 */
363 - if (hashcmp(sha1, e->item->sha1)) {
363 + if (oidcmp(&oid, &e->item->oid)) {
364 /*
365 * Is this the positive end of a range expressed
366 * in terms of a tag (e.g. v2.0 from the range
367 * "v1.0..v2.0")?
368 */
369 - struct commit *one = lookup_commit_reference(sha1);
369 + struct commit *one = lookup_commit_reference(oid.hash);
370 struct object *obj;
371
372 if (e->item == &(one->object)) {
@@ -378,7 +378,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
378 * end up triggering "empty bundle"
379 * error.
380 */
381 - obj = parse_object_or_die(sha1, e->name);
381 + obj = parse_object_or_die(oid.hash, e->name);
382 obj->flags |= SHOWN;
383 add_pending_object(revs, obj, e->name);
384 }
@@ -386,7 +386,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
386 }
387
388 ref_count++;
389 - write_or_die(bundle_fd, sha1_to_hex(e->item->sha1), 40);
389 + write_or_die(bundle_fd, oid_to_hex(&e->item->oid), 40);
390 write_or_die(bundle_fd, " ", 1);
391 write_or_die(bundle_fd, display_ref, strlen(display_ref));
392 write_or_die(bundle_fd, "\n", 1);
commit.c
+10 -10
@@ -265,10 +265,10 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
265 ret = read_sha1_file(get_object_hash(commit->object), &type, &size);
266 if (!ret)
267 die("cannot read commit object %s",
268 - sha1_to_hex(commit->object.sha1));
268 + oid_to_hex(&commit->object.oid));
269 if (type != OBJ_COMMIT)
270 die("expected commit for %s, got %s",
271 - sha1_to_hex(commit->object.sha1), typename(type));
271 + oid_to_hex(&commit->object.oid), typename(type));
272 if (sizep)
273 *sizep = size;
274 }
@@ -327,10 +327,10 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
327 tail += size;
328 if (tail <= bufptr + tree_entry_len + 1 || memcmp(bufptr, "tree ", 5) ||
329 bufptr[tree_entry_len] != '\n')
330 - return error("bogus commit object %s", sha1_to_hex(item->object.sha1));
330 + return error("bogus commit object %s", oid_to_hex(&item->object.oid));
331 if (get_sha1_hex(bufptr + 5, parent.hash) < 0)
332 return error("bad tree pointer in commit %s",
333 - sha1_to_hex(item->object.sha1));
333 + oid_to_hex(&item->object.oid));
334 item->tree = lookup_tree(parent.hash);
335 bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
336 pptr = &item->parents;
@@ -342,7 +342,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
342 if (tail <= bufptr + parent_entry_len + 1 ||
343 get_sha1_hex(bufptr + 7, parent.hash) ||
344 bufptr[parent_entry_len] != '\n')
345 - return error("bad parents in commit %s", sha1_to_hex(item->object.sha1));
345 + return error("bad parents in commit %s", oid_to_hex(&item->object.oid));
346 bufptr += parent_entry_len + 1;
347 /*
348 * The clone is shallow if nr_parent < 0, and we must
@@ -384,11 +384,11 @@ int parse_commit_gently(struct commit *item, int quiet_on_missing)
384 if (!buffer)
385 return quiet_on_missing ? -1 :
386 error("Could not read %s",
387 - sha1_to_hex(item->object.sha1));
387 + oid_to_hex(&item->object.oid));
388 if (type != OBJ_COMMIT) {
389 free(buffer);
390 return error("Object %s not a commit",
391 - sha1_to_hex(item->object.sha1));
391 + oid_to_hex(&item->object.oid));
392 }
393 ret = parse_commit_buffer(item, buffer, size);
394 if (save_commit_buffer && !ret) {
@@ -403,7 +403,7 @@ void parse_commit_or_die(struct commit *item)
403 {
404 if (parse_commit(item))
405 die("unable to parse commit %s",
406 - item ? sha1_to_hex(item->object.sha1) : "(null)");
406 + item ? oid_to_hex(&item->object.oid) : "(null)");
407 }
408
409 int find_commit_subject(const char *commit_buffer, const char **subject)
@@ -1539,7 +1539,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
1539 while (parents) {
1540 struct commit *parent = pop_commit(&parents);
1541 strbuf_addf(&buffer, "parent %s\n",
1542 - sha1_to_hex(parent->object.sha1));
1542 + oid_to_hex(&parent->object.oid));
1543 }
1544
1545 /* Person/date information */
@@ -1623,7 +1623,7 @@ void print_commit_list(struct commit_list *list,
1623 {
1624 for ( ; list; list = list->next) {
1625 const char *format = list->next ? format_cur : format_last;
1626 - printf(format, sha1_to_hex(list->item->object.sha1));
1626 + printf(format, oid_to_hex(&list->item->object.oid));
1627 }
1628 }
1629
fetch-pack.c
+1 -1
@@ -511,7 +511,7 @@ static void mark_recent_complete_commits(struct fetch_pack_args *args,
511 while (complete && cutoff <= complete->item->date) {
512 if (args->verbose)
513 fprintf(stderr, "Marking %s as complete\n",
514 - sha1_to_hex(complete->item->object.sha1));
514 + oid_to_hex(&complete->item->object.oid));
515 pop_most_recent_commit(&complete, COMPLETE);
516 }
517 }
fsck.c
+4 -4
@@ -316,7 +316,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
316 result = options->walk(&lookup_blob(entry.sha1)->object, OBJ_BLOB, data, options);
317 else {
318 result = error("in tree %s: entry %s has bad mode %.6o",
319 - sha1_to_hex(tree->object.sha1), entry.path, entry.mode);
319 + oid_to_hex(&tree->object.oid), entry.path, entry.mode);
320 }
321 if (result < 0)
322 return result;
@@ -373,7 +373,7 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options)
373 case OBJ_TAG:
374 return fsck_walk_tag((struct tag *)obj, data, options);
375 default:
376 - error("Unknown object type for %s", sha1_to_hex(obj->sha1));
376 + error("Unknown object type for %s", oid_to_hex(&obj->oid));
377 return -1;
378 }
379 }
@@ -809,9 +809,9 @@ int fsck_object(struct object *obj, void *data, unsigned long size,
809 int fsck_error_function(struct object *obj, int msg_type, const char *message)
810 {
811 if (msg_type == FSCK_WARN) {
812 - warning("object %s: %s", sha1_to_hex(obj->sha1), message);
812 + warning("object %s: %s", oid_to_hex(&obj->oid), message);
813 return 0;
814 }
815 - error("object %s: %s", sha1_to_hex(obj->sha1), message);
815 + error("object %s: %s", oid_to_hex(&obj->oid), message);
816 return 1;
817 }
http-backend.c
+1 -1
@@ -436,7 +436,7 @@ static int show_text_ref(const char *name, const struct object_id *oid,
436 o = deref_tag(o, name, 0);
437 if (!o)
438 return 0;
439 - strbuf_addf(buf, "%s\t%s^{}\n", sha1_to_hex(o->sha1),
439 + strbuf_addf(buf, "%s\t%s^{}\n", oid_to_hex(&o->oid),
440 name_nons);
441 }
442 return 0;
http-push.c
+11 -11
@@ -275,7 +275,7 @@ static void start_fetch_loose(struct transfer_request *request)
275
276 static void start_mkcol(struct transfer_request *request)
277 {
278 - char *hex = sha1_to_hex(request->obj->sha1);
278 + char *hex = oid_to_hex(&request->obj->oid);
279 struct active_request_slot *slot;
280
281 request->url = get_remote_object_url(repo->url, hex, 1);
@@ -306,14 +306,14 @@ static void start_fetch_packed(struct transfer_request *request)
306
307 target = find_sha1_pack(get_object_hash(*request->obj), repo->packs);
308 if (!target) {
309 - fprintf(stderr, "Unable to fetch %s, will not be able to update server info refs\n", sha1_to_hex(request->obj->sha1));
309 + fprintf(stderr, "Unable to fetch %s, will not be able to update server info refs\n", oid_to_hex(&request->obj->oid));
310 repo->can_update_info_refs = 0;
311 release_request(request);
312 return;
313 }
314
315 fprintf(stderr, "Fetching pack %s\n", sha1_to_hex(target->sha1));
316 - fprintf(stderr, " which contains %s\n", sha1_to_hex(request->obj->sha1));
316 + fprintf(stderr, " which contains %s\n", oid_to_hex(&request->obj->oid));
317
318 preq = new_http_pack_request(target, repo->url);
319 if (preq == NULL) {
@@ -350,7 +350,7 @@ static void start_fetch_packed(struct transfer_request *request)
350
351 static void start_put(struct transfer_request *request)
352 {
353 - char *hex = sha1_to_hex(request->obj->sha1);
353 + char *hex = oid_to_hex(&request->obj->oid);
354 struct active_request_slot *slot;
355 struct strbuf buf = STRBUF_INIT;
356 enum object_type type;
@@ -537,7 +537,7 @@ static void finish_request(struct transfer_request *request)
537 start_put(request);
538 } else {
539 fprintf(stderr, "MKCOL %s failed, aborting (%d/%ld)\n",
540 - sha1_to_hex(request->obj->sha1),
540 + oid_to_hex(&request->obj->oid),
541 request->curl_result, request->http_code);
542 request->state = ABORTED;
543 aborted = 1;
@@ -547,7 +547,7 @@ static void finish_request(struct transfer_request *request)
547 start_move(request);
548 } else {
549 fprintf(stderr, "PUT %s failed, aborting (%d/%ld)\n",
550 - sha1_to_hex(request->obj->sha1),
550 + oid_to_hex(&request->obj->oid),
551 request->curl_result, request->http_code);
552 request->state = ABORTED;
553 aborted = 1;
@@ -556,12 +556,12 @@ static void finish_request(struct transfer_request *request)
556 if (request->curl_result == CURLE_OK) {
557 if (push_verbosely)
558 fprintf(stderr, " sent %s\n",
559 - sha1_to_hex(request->obj->sha1));
559 + oid_to_hex(&request->obj->oid));
560 request->obj->flags |= REMOTE;
561 release_request(request);
562 } else {
563 fprintf(stderr, "MOVE %s failed, aborting (%d/%ld)\n",
564 - sha1_to_hex(request->obj->sha1),
564 + oid_to_hex(&request->obj->oid),
565 request->curl_result, request->http_code);
566 request->state = ABORTED;
567 aborted = 1;
@@ -1307,7 +1307,7 @@ static struct object_list **process_tree(struct tree *tree,
1307 if (obj->flags & (UNINTERESTING | SEEN))
1308 return p;
1309 if (parse_tree(tree) < 0)
1310 - die("bad tree object %s", sha1_to_hex(obj->sha1));
1310 + die("bad tree object %s", oid_to_hex(&obj->oid));
1311
1312 obj->flags |= SEEN;
1313 name = xstrdup(name);
@@ -1369,7 +1369,7 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock)
1369 p = process_blob((struct blob *)obj, p, NULL, name);
1370 continue;
1371 }
1372 - die("unknown pending object %s (%s)", sha1_to_hex(obj->sha1), name);
1372 + die("unknown pending object %s (%s)", oid_to_hex(&obj->oid), name);
1373 }
1374
1375 while (objects) {
@@ -1490,7 +1490,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
1490 o = deref_tag(o, ls->dentry_name, 0);
1491 if (o)
1492 strbuf_addf(buf, "%s\t%s^{}\n",
1493 - sha1_to_hex(o->sha1), ls->dentry_name);
1493 + oid_to_hex(&o->oid), ls->dentry_name);
1494 }
1495 free(ref);
1496 }
list-objects.c
+2 -2
@@ -84,7 +84,7 @@ static void process_tree(struct rev_info *revs,
84 if (parse_tree_gently(tree, revs->ignore_missing_links) < 0) {
85 if (revs->ignore_missing_links)
86 return;
87 - die("bad tree object %s", sha1_to_hex(obj->sha1));
87 + die("bad tree object %s", oid_to_hex(&obj->oid));
88 }
89 obj->flags |= SEEN;
90 show(obj, path, name, cb_data);
@@ -229,7 +229,7 @@ void traverse_commit_list(struct rev_info *revs,
229 continue;
230 }
231 die("unknown pending object %s (%s)",
232 - sha1_to_hex(obj->sha1), name);
232 + oid_to_hex(&obj->oid), name);
233 }
234 object_array_clear(&revs->pending);
235 strbuf_release(&base);
log-tree.c
+10 -10
@@ -342,7 +342,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
342 {
343 const char *subject = NULL;
344 const char *extra_headers = opt->extra_headers;
345 - const char *name = sha1_to_hex(commit->object.sha1);
345 + const char *name = oid_to_hex(&commit->object.oid);
346
347 *need_8bit_cte_p = 0; /* unknown */
348 if (opt->total > 0) {
@@ -503,8 +503,8 @@ static void show_one_mergetag(struct commit *commit,
503 if (parse_tag_buffer(tag, extra->value, extra->len))
504 strbuf_addstr(&verify_message, "malformed mergetag\n");
505 else if (is_common_merge(commit) &&
506 - !hashcmp(tag->tagged->sha1,
507 - commit->parents->next->item->object.sha1))
506 + !oidcmp(&tag->tagged->oid,
507 + &commit->parents->next->item->object.oid))
508 strbuf_addf(&verify_message,
509 "merged tag '%s'\n", tag->tag);
510 else if ((nth = which_parent(get_object_hash(*tag->tagged), commit)) < 0)
@@ -796,19 +796,19 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
796 {
797 int showed_log;
798 struct commit_list *parents;
799 - unsigned const char *sha1;
799 + struct object_id *oid;
800
801 if (!opt->diff && !DIFF_OPT_TST(&opt->diffopt, EXIT_WITH_STATUS))
802 return 0;
803
804 parse_commit_or_die(commit);
805 - sha1 = commit->tree->object.sha1;
805 + oid = &commit->tree->object.oid;
806
807 /* Root commit? */
808 parents = get_saved_parents(opt, commit);
809 if (!parents) {
810 if (opt->show_root_diff) {
811 - diff_root_tree_sha1(sha1, "", &opt->diffopt);
811 + diff_root_tree_sha1(oid->hash, "", &opt->diffopt);
812 log_tree_diff_flush(opt);
813 }
814 return !opt->loginfo;
@@ -827,8 +827,8 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
827 * we merged _in_.
828 */
829 parse_commit_or_die(parents->item);
830 - diff_tree_sha1(parents->item->tree->object.sha1,
831 - sha1, "", &opt->diffopt);
830 + diff_tree_sha1(parents->item->tree->object.oid.hash,
831 + oid->hash, "", &opt->diffopt);
832 log_tree_diff_flush(opt);
833 return !opt->loginfo;
834 }
@@ -842,8 +842,8 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
842 struct commit *parent = parents->item;
843
844 parse_commit_or_die(parent);
845 - diff_tree_sha1(parent->tree->object.sha1,
846 - sha1, "", &opt->diffopt);
845 + diff_tree_sha1(parent->tree->object.oid.hash,
846 + oid->hash, "", &opt->diffopt);
847 log_tree_diff_flush(opt);
848
849 showed_log |= !opt->loginfo;
merge-recursive.c
+7 -7
@@ -26,17 +26,17 @@
26 static struct tree *shift_tree_object(struct tree *one, struct tree *two,
27 const char *subtree_shift)
28 {
29 - unsigned char shifted[20];
29 + struct object_id shifted;
30
31 if (!*subtree_shift) {
32 - shift_tree(get_object_hash(one->object), get_object_hash(two->object), shifted, 0);
32 + shift_tree(get_object_hash(one->object), get_object_hash(two->object), shifted.hash, 0);
33 } else {
34 - shift_tree_by(get_object_hash(one->object), get_object_hash(two->object), shifted,
34 + shift_tree_by(get_object_hash(one->object), get_object_hash(two->object), shifted.hash,
35 subtree_shift);
36 }
37 - if (!hashcmp(two->object.sha1, shifted))
37 + if (!oidcmp(&two->object.oid, &shifted))
38 return two;
39 - return lookup_tree(shifted);
39 + return lookup_tree(shifted.hash);
40 }
41
42 static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
@@ -1823,8 +1823,8 @@ int merge_trees(struct merge_options *o,
1823 if (code != 0) {
1824 if (show(o, 4) || o->call_depth)
1825 die(_("merging of trees %s and %s failed"),
1826 - sha1_to_hex(head->object.sha1),
1827 - sha1_to_hex(merge->object.sha1));
1826 + oid_to_hex(&head->object.oid),
1827 + oid_to_hex(&merge->object.oid));
1828 else
1829 exit(128);
1830 }
merge.c
+1 -1
@@ -10,7 +10,7 @@
10 static const char *merge_argument(struct commit *commit)
11 {
12 if (commit)
13 - return sha1_to_hex(commit->object.sha1);
13 + return oid_to_hex(&commit->object.oid);
14 else
15 return EMPTY_TREE_SHA1_HEX;
16 }
notes-merge.c
+2 -2
@@ -618,8 +618,8 @@ int notes_merge(struct notes_merge_options *o,
618
619 if (o->verbosity >= 4)
620 printf("Merging remote commit %.7s into local commit %.7s with "
621 - "merge-base %.7s\n", sha1_to_hex(remote->object.sha1),
622 - sha1_to_hex(local->object.sha1),
621 + "merge-base %.7s\n", oid_to_hex(&remote->object.oid),
622 + oid_to_hex(&local->object.oid),
623 sha1_to_hex(base_sha1));
624
625 if (!hashcmp(get_object_hash(remote->object), base_sha1)) {
object.c
+1 -1
@@ -168,7 +168,7 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet)
168 else {
169 if (!quiet)
170 error("object %s is a %s, not a %s",
171 - sha1_to_hex(obj->sha1),
171 + oid_to_hex(&obj->oid),
172 typename(obj->type), typename(type));
173 return NULL;
174 }
object.h
+2 -2
@@ -49,10 +49,10 @@ struct object {
49 unsigned used : 1;
50 unsigned type : TYPE_BITS;
51 unsigned flags : FLAG_BITS;
52 - unsigned char sha1[20];
52 + struct object_id oid;
53 };
54
55 -#define get_object_hash(x) ((x).sha1)
55 +#define get_object_hash(x) ((x).oid.hash)
56
57 extern const char *typename(unsigned int type);
58 extern int type_from_string_gently(const char *str, ssize_t, int gentle);
pack-bitmap-write.c
+1 -1
@@ -311,7 +311,7 @@ void bitmap_writer_build(struct packing_data *to_pack)
311 hash_pos = kh_put_sha1(writer.bitmaps, get_object_hash(*object), &hash_ret);
312 if (hash_ret == 0)
313 die("Duplicate entry when writing index: %s",
314 - sha1_to_hex(object->sha1));
314 + oid_to_hex(&object->oid));
315
316 kh_value(writer.bitmaps, hash_pos) = stored;
317 display_progress(writer.progress, writer.selected_nr - i);
pack-bitmap.c
+4 -4
@@ -906,7 +906,7 @@ static void test_show_object(struct object *object,
906
907 bitmap_pos = bitmap_position(get_object_hash(*object));
908 if (bitmap_pos < 0)
909 - die("Object not in bitmap: %s\n", sha1_to_hex(object->sha1));
909 + die("Object not in bitmap: %s\n", oid_to_hex(&object->oid));
910
911 bitmap_set(tdata->base, bitmap_pos);
912 display_progress(tdata->prg, ++tdata->seen);
@@ -919,7 +919,7 @@ static void test_show_commit(struct commit *commit, void *data)
919
920 bitmap_pos = bitmap_position(get_object_hash(commit->object));
921 if (bitmap_pos < 0)
922 - die("Object not in bitmap: %s\n", sha1_to_hex(commit->object.sha1));
922 + die("Object not in bitmap: %s\n", oid_to_hex(&commit->object.oid));
923
924 bitmap_set(tdata->base, bitmap_pos);
925 display_progress(tdata->prg, ++tdata->seen);
@@ -950,13 +950,13 @@ void test_bitmap_walk(struct rev_info *revs)
950 struct ewah_bitmap *bm = lookup_stored_bitmap(st);
951
952 fprintf(stderr, "Found bitmap for %s. %d bits / %08x checksum\n",
953 - sha1_to_hex(root->sha1), (int)bm->bit_size, ewah_checksum(bm));
953 + oid_to_hex(&root->oid), (int)bm->bit_size, ewah_checksum(bm));
954
955 result = ewah_to_bitmap(bm);
956 }
957
958 if (result == NULL)
959 - die("Commit %s doesn't have an indexed bitmap", sha1_to_hex(root->sha1));
959 + die("Commit %s doesn't have an indexed bitmap", oid_to_hex(&root->oid));
960
961 revs->tag_objects = 1;
962 revs->tree_objects = 1;
pretty.c
+5 -5
@@ -545,7 +545,7 @@ static void add_merge_info(const struct pretty_print_context *pp,
545 if (pp->abbrev)
546 hex = find_unique_abbrev(get_object_hash(p->object), pp->abbrev);
547 if (!hex)
548 - hex = sha1_to_hex(p->object.sha1);
548 + hex = oid_to_hex(&p->object.oid);
549 parent = parent->next;
550
551 strbuf_addf(sb, " %s", hex);
@@ -1124,7 +1124,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1124 switch (placeholder[0]) {
1125 case 'H': /* commit hash */
1126 strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_COMMIT));
1127 - strbuf_addstr(sb, sha1_to_hex(commit->object.sha1));
1127 + strbuf_addstr(sb, oid_to_hex(&commit->object.oid));
1128 strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
1129 return 1;
1130 case 'h': /* abbreviated commit hash */
@@ -1139,12 +1139,12 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1139 c->abbrev_commit_hash.len = sb->len - c->abbrev_commit_hash.off;
1140 return 1;
1141 case 'T': /* tree hash */
1142 - strbuf_addstr(sb, sha1_to_hex(commit->tree->object.sha1));
1142 + strbuf_addstr(sb, oid_to_hex(&commit->tree->object.oid));
1143 return 1;
1144 case 't': /* abbreviated tree hash */
1145 if (add_again(sb, &c->abbrev_tree_hash))
1146 return 1;
1147 - strbuf_addstr(sb, find_unique_abbrev(commit->tree->object.sha1,
1147 + strbuf_addstr(sb, find_unique_abbrev(commit->tree->object.oid.hash,
1148 c->pretty_ctx->abbrev));
1149 c->abbrev_tree_hash.len = sb->len - c->abbrev_tree_hash.off;
1150 return 1;
@@ -1152,7 +1152,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1152 for (p = commit->parents; p; p = p->next) {
1153 if (p != commit->parents)
1154 strbuf_addch(sb, ' ');
1155 - strbuf_addstr(sb, sha1_to_hex(p->item->object.sha1));
1155 + strbuf_addstr(sb, oid_to_hex(&p->item->object.oid));
1156 }
1157 return 1;
1158 case 'p': /* abbreviated parent hashes */
ref-filter.c
+4 -4
@@ -394,7 +394,7 @@ static void grab_tag_values(struct atom_value *val, int deref, struct object *ob
394 else if (!strcmp(name, "type") && tag->tagged)
395 v->s = typename(tag->tagged->type);
396 else if (!strcmp(name, "object") && tag->tagged)
397 - v->s = xstrdup(sha1_to_hex(tag->tagged->sha1));
397 + v->s = xstrdup(oid_to_hex(&tag->tagged->oid));
398 }
399 }
400
@@ -412,7 +412,7 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object
412 if (deref)
413 name++;
414 if (!strcmp(name, "tree")) {
415 - v->s = xstrdup(sha1_to_hex(commit->tree->object.sha1));
415 + v->s = xstrdup(oid_to_hex(&commit->tree->object.oid));
416 }
417 else if (!strcmp(name, "numparent")) {
418 v->ul = commit_list_count(commit->parents);
@@ -425,7 +425,7 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object
425 struct commit *parent = parents->item;
426 if (parents != commit->parents)
427 strbuf_addch(&s, ' ');
428 - strbuf_addstr(&s, sha1_to_hex(parent->object.sha1));
428 + strbuf_addstr(&s, oid_to_hex(&parent->object.oid));
429 }
430 v->s = strbuf_detach(&s, NULL);
431 }
@@ -1049,7 +1049,7 @@ struct contains_stack {
1049 static int in_commit_list(const struct commit_list *want, struct commit *c)
1050 {
1051 for (; want; want = want->next)
1052 - if (!hashcmp(want->item->object.sha1, c->object.sha1))
1052 + if (!oidcmp(&want->item->object.oid, &c->object.oid))
1053 return 1;
1054 return 0;
1055 }
remote.c
+2 -2
@@ -2031,8 +2031,8 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
2031 argv_array_push(&argv, ""); /* ignored */
2032 argv_array_push(&argv, "--left-right");
2033 argv_array_pushf(&argv, "%s...%s",
2034 - sha1_to_hex(ours->object.sha1),
2035 - sha1_to_hex(theirs->object.sha1));
2034 + oid_to_hex(&ours->object.oid),
2035 + oid_to_hex(&theirs->object.oid));
2036 argv_array_push(&argv, "--");
2037
2038 init_revisions(&revs, NULL);
revision.c
+16 -16
@@ -86,7 +86,7 @@ void show_object_with_name(FILE *out, struct object *obj,
86 leaf.elem = component;
87 leaf.elem_len = strlen(component);
88
89 - fprintf(out, "%s ", sha1_to_hex(obj->sha1));
89 + fprintf(out, "%s ", oid_to_hex(&obj->oid));
90 show_path_truncated(out, &leaf);
91 fputc('\n', out);
92 }
@@ -106,10 +106,10 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
106 struct name_entry entry;
107 struct object *obj = &tree->object;
108
109 - if (!has_sha1_file(obj->sha1))
109 + if (!has_object_file(&obj->oid))
110 return;
111 if (parse_tree(tree) < 0)
112 - die("bad tree %s", sha1_to_hex(obj->sha1));
112 + die("bad tree %s", oid_to_hex(&obj->oid));
113
114 init_tree_desc(&desc, tree->buffer, tree->size);
115 while (tree_entry(&desc, &entry)) {
@@ -164,7 +164,7 @@ void mark_parents_uninteresting(struct commit *commit)
164 * it is popped next time around, we won't be trying
165 * to parse it and get an error.
166 */
167 - if (!has_sha1_file(commit->object.sha1))
167 + if (!has_object_file(&commit->object.oid))
168 commit->object.parsed = 1;
169
170 if (commit->object.flags & UNINTERESTING)
@@ -286,7 +286,7 @@ static struct commit *handle_commit(struct rev_info *revs,
286 if (!object) {
287 if (flags & UNINTERESTING)
288 return NULL;
289 - die("bad object %s", sha1_to_hex(tag->tagged->sha1));
289 + die("bad object %s", oid_to_hex(&tag->tagged->oid));
290 }
291 object->flags |= flags;
292 /*
@@ -610,7 +610,7 @@ static unsigned update_treesame(struct rev_info *revs, struct commit *commit)
610
611 st = lookup_decoration(&revs->treesame, &commit->object);
612 if (!st)
613 - die("update_treesame %s", sha1_to_hex(commit->object.sha1));
613 + die("update_treesame %s", oid_to_hex(&commit->object.oid));
614 relevant_parents = 0;
615 relevant_change = irrelevant_change = 0;
616 for (p = commit->parents, n = 0; p; n++, p = p->next) {
@@ -708,8 +708,8 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
708 }
709 if (parse_commit(p) < 0)
710 die("cannot simplify commit %s (because of %s)",
711 - sha1_to_hex(commit->object.sha1),
712 - sha1_to_hex(p->object.sha1));
711 + oid_to_hex(&commit->object.oid),
712 + oid_to_hex(&p->object.oid));
713 switch (rev_compare_tree(revs, p, commit)) {
714 case REV_TREE_SAME:
715 if (!revs->simplify_history || !relevant_commit(p)) {
@@ -741,8 +741,8 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
741 */
742 if (parse_commit(p) < 0)
743 die("cannot simplify commit %s (invalid %s)",
744 - sha1_to_hex(commit->object.sha1),
745 - sha1_to_hex(p->object.sha1));
744 + oid_to_hex(&commit->object.oid),
745 + oid_to_hex(&p->object.oid));
746 p->parents = NULL;
747 }
748 /* fallthrough */
@@ -754,7 +754,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit)
754 irrelevant_change = 1;
755 continue;
756 }
757 - die("bad tree compare for commit %s", sha1_to_hex(commit->object.sha1));
757 + die("bad tree compare for commit %s", oid_to_hex(&commit->object.oid));
758 }
759
760 /*
@@ -1189,7 +1189,7 @@ static void add_rev_cmdline_list(struct rev_info *revs,
1189 {
1190 while (commit_list) {
1191 struct object *object = &commit_list->item->object;
1192 - add_rev_cmdline(revs, object, sha1_to_hex(object->sha1),
1192 + add_rev_cmdline(revs, object, oid_to_hex(&object->oid),
1193 whence, flags);
1194 commit_list = commit_list->next;
1195 }
@@ -1435,7 +1435,7 @@ static void add_pending_commit_list(struct rev_info *revs,
1435 while (commit_list) {
1436 struct object *object = &commit_list->item->object;
1437 object->flags |= flags;
1438 - add_pending_object(revs, object, sha1_to_hex(object->sha1));
1438 + add_pending_object(revs, object, oid_to_hex(&object->oid));
1439 commit_list = commit_list->next;
1440 }
1441 }
@@ -3094,7 +3094,7 @@ static void track_linear(struct rev_info *revs, struct commit *commit)
3094 struct commit_list *p;
3095 for (p = revs->previous_parents; p; p = p->next)
3096 if (p->item == NULL || /* first commit */
3097 - !hashcmp(p->item->object.sha1, commit->object.sha1))
3097 + !oidcmp(&p->item->object.oid, &commit->object.oid))
3098 break;
3099 revs->linear = p != NULL;
3100 }
@@ -3132,7 +3132,7 @@ static struct commit *get_revision_1(struct rev_info *revs)
3132 if (add_parents_to_list(revs, commit, &revs->commits, NULL) < 0) {
3133 if (!revs->ignore_missing_links)
3134 die("Failed to traverse parents of commit %s",
3135 - sha1_to_hex(commit->object.sha1));
3135 + oid_to_hex(&commit->object.oid));
3136 }
3137 }
3138
@@ -3141,7 +3141,7 @@ static struct commit *get_revision_1(struct rev_info *revs)
3141 continue;
3142 case commit_error:
3143 die("Failed to simplify parents of commit %s",
3144 - sha1_to_hex(commit->object.sha1));
3144 + oid_to_hex(&commit->object.oid));
3145 default:
3146 if (revs->track_linear)
3147 track_linear(revs, commit);
sequencer.c
+11 -11
@@ -139,7 +139,7 @@ static int get_message(struct commit *commit, struct commit_message *out)
139 git_commit_encoding = "UTF-8";
140
141 out->message = logmsg_reencode(commit, NULL, git_commit_encoding);
142 - abbrev = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
142 + abbrev = find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV);
143 abbrev_len = strlen(abbrev);
144
145 subject_len = find_commit_subject(out->message, &subject);
@@ -397,12 +397,12 @@ static int is_original_commit_empty(struct commit *commit)
397
398 if (parse_commit(commit))
399 return error(_("Could not parse commit %s\n"),
400 - sha1_to_hex(commit->object.sha1));
400 + oid_to_hex(&commit->object.oid));
401 if (commit->parents) {
402 struct commit *parent = commit->parents->item;
403 if (parse_commit(parent))
404 return error(_("Could not parse parent commit %s\n"),
405 - sha1_to_hex(parent->object.sha1));
405 + oid_to_hex(&parent->object.oid));
406 ptree_sha1 = get_object_hash(parent->tree->object);
407 } else {
408 ptree_sha1 = EMPTY_TREE_SHA1_BIN; /* commit is root */
@@ -486,7 +486,7 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
486
487 if (!opts->mainline)
488 return error(_("Commit %s is a merge but no -m option was given."),
489 - sha1_to_hex(commit->object.sha1));
489 + oid_to_hex(&commit->object.oid));
490
491 for (cnt = 1, p = commit->parents;
492 cnt != opts->mainline && p;
@@ -494,11 +494,11 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
494 p = p->next;
495 if (cnt != opts->mainline || !p)
496 return error(_("Commit %s does not have parent %d"),
497 - sha1_to_hex(commit->object.sha1), opts->mainline);
497 + oid_to_hex(&commit->object.oid), opts->mainline);
498 parent = p->item;
499 } else if (0 < opts->mainline)
500 return error(_("Mainline was specified but commit %s is not a merge."),
501 - sha1_to_hex(commit->object.sha1));
501 + oid_to_hex(&commit->object.oid));
502 else
503 parent = commit->parents->item;
504
@@ -511,11 +511,11 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
511 /* TRANSLATORS: The first %s will be "revert" or
512 "cherry-pick", the second %s a SHA1 */
513 return error(_("%s: cannot parse parent commit %s"),
514 - action_name(opts), sha1_to_hex(parent->object.sha1));
514 + action_name(opts), oid_to_hex(&parent->object.oid));
515
516 if (get_message(commit, &msg) != 0)
517 return error(_("Cannot get commit message for %s"),
518 - sha1_to_hex(commit->object.sha1));
518 + oid_to_hex(&commit->object.oid));
519
520 /*
521 * "commit" is an existing commit. We would want to apply
@@ -532,11 +532,11 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
532 strbuf_addstr(&msgbuf, "Revert \"");
533 strbuf_addstr(&msgbuf, msg.subject);
534 strbuf_addstr(&msgbuf, "\"\n\nThis reverts commit ");
535 - strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));
535 + strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
536
537 if (commit->parents && commit->parents->next) {
538 strbuf_addstr(&msgbuf, ", reversing\nchanges made to ");
539 - strbuf_addstr(&msgbuf, sha1_to_hex(parent->object.sha1));
539 + strbuf_addstr(&msgbuf, oid_to_hex(&parent->object.oid));
540 }
541 strbuf_addstr(&msgbuf, ".\n");
542 } else {
@@ -562,7 +562,7 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
562 if (!has_conforming_footer(&msgbuf, NULL, 0))
563 strbuf_addch(&msgbuf, '\n');
564 strbuf_addstr(&msgbuf, cherry_picked_prefix);
565 - strbuf_addstr(&msgbuf, sha1_to_hex(commit->object.sha1));
565 + strbuf_addstr(&msgbuf, oid_to_hex(&commit->object.oid));
566 strbuf_addstr(&msgbuf, ")\n");
567 }
568 }
server-info.c
+1 -1
@@ -62,7 +62,7 @@ static int add_info_ref(const char *path, const struct object_id *oid,
62 o = deref_tag(o, path, 0);
63 if (o)
64 if (fprintf(fp, "%s %s^{}\n",
65 - sha1_to_hex(o->sha1), path) < 0)
65 + oid_to_hex(&o->oid), path) < 0)
66 return -1;
67 }
68 return 0;
sha1_name.c
+2 -2
@@ -738,7 +738,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
738 o = deref_tag(o, name, sp - name - 2);
739 if (!o || (!o->parsed && !parse_object(get_object_hash(*o))))
740 return -1;
741 - hashcpy(sha1, o->sha1);
741 + hashcpy(sha1, o->oid.hash);
742 return 0;
743 }
744
@@ -1022,7 +1022,7 @@ int get_sha1_mb(const char *name, unsigned char *sha1)
1022 st = -1;
1023 else {
1024 st = 0;
1025 - hashcpy(sha1, mbs->item->object.sha1);
1025 + hashcpy(sha1, mbs->item->object.oid.hash);
1026 }
1027 free_commit_list(mbs);
1028 return st;
shallow.c
+2 -2
@@ -167,7 +167,7 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data)
167 if (!c || !(c->object.flags & SEEN)) {
168 if (data->flags & VERBOSE)
169 printf("Removing %s from .git/shallow\n",
170 - sha1_to_hex(c->object.sha1));
170 + oid_to_hex(&c->object.oid));
171 return 0;
172 }
173 }
@@ -426,7 +426,7 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1,
426
427 if (parse_commit(c))
428 die("unable to parse commit %s",
429 - sha1_to_hex(c->object.sha1));
429 + oid_to_hex(&c->object.oid));
430
431 for (p = c->parents; p; p = p->next) {
432 uint32_t **p_refs = ref_bitmap_at(&info->ref_bitmap,
submodule.c
+3 -3
@@ -249,7 +249,7 @@ static int prepare_submodule_summary(struct rev_info *rev, const char *path,
249 for (list = merge_bases; list; list = list->next) {
250 list->item->object.flags |= UNINTERESTING;
251 add_pending_object(rev, &list->item->object,
252 - sha1_to_hex(list->item->object.sha1));
252 + oid_to_hex(&list->item->object.oid));
253 }
254 return prepare_revision_walk(rev);
255 }
@@ -875,7 +875,7 @@ static int find_first_merges(struct object_array *result, const char *path,
875
876 /* get all revisions that merge commit a */
877 snprintf(merged_revision, sizeof(merged_revision), "^%s",
878 - sha1_to_hex(a->object.sha1));
878 + oid_to_hex(&a->object.oid));
879 init_revisions(&revs, NULL);
880 rev_opts.submodule = path;
881 setup_revisions(ARRAY_SIZE(rev_args)-1, rev_args, &revs, &rev_opts);
@@ -1006,7 +1006,7 @@ int merge_submodule(unsigned char result[20], const char *path,
1006 "by using:\n\n"
1007 " git update-index --cacheinfo 160000 %s \"%s\"\n\n"
1008 "which will accept this suggestion.\n",
1009 - sha1_to_hex(merges.objects[0].item->sha1), path);
1009 + oid_to_hex(&merges.objects[0].item->oid), path);
1010 break;
1011
1012 default:
tag.c
+2 -2
@@ -130,11 +130,11 @@ int parse_tag(struct tag *item)
130 data = read_sha1_file(get_object_hash(item->object), &type, &size);
131 if (!data)
132 return error("Could not read %s",
133 - sha1_to_hex(item->object.sha1));
133 + oid_to_hex(&item->object.oid));
134 if (type != OBJ_TAG) {
135 free(data);
136 return error("Object %s not a tag",
137 - sha1_to_hex(item->object.sha1));
137 + oid_to_hex(&item->object.oid));
138 }
139 ret = parse_tag_buffer(item, data, size);
140 free(data);
tree.c
+3 -3
@@ -216,11 +216,11 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)
216 if (!buffer)
217 return quiet_on_missing ? -1 :
218 error("Could not read %s",
219 - sha1_to_hex(item->object.sha1));
219 + oid_to_hex(&item->object.oid));
220 if (type != OBJ_TREE) {
221 free(buffer);
222 return error("Object %s not a tree",
223 - sha1_to_hex(item->object.sha1));
223 + oid_to_hex(&item->object.oid));
224 }
225 return parse_tree_buffer(item, buffer, size);
226 }
@@ -248,6 +248,6 @@ struct tree *parse_tree_indirect(const unsigned char *sha1)
248 else
249 return NULL;
250 if (!obj->parsed)
251 - parse_object(obj->sha1);
251 + parse_object(obj->oid.hash);
252 } while (1);
253 }
upload-pack.c
+8 -8
@@ -130,14 +130,14 @@ static void create_pack_file(void)
130
131 for (i = 0; i < want_obj.nr; i++)
132 fprintf(pipe_fd, "%s\n",
133 - sha1_to_hex(want_obj.objects[i].item->sha1));
133 + oid_to_hex(&want_obj.objects[i].item->oid));
134 fprintf(pipe_fd, "--not\n");
135 for (i = 0; i < have_obj.nr; i++)
136 fprintf(pipe_fd, "%s\n",
137 - sha1_to_hex(have_obj.objects[i].item->sha1));
137 + oid_to_hex(&have_obj.objects[i].item->oid));
138 for (i = 0; i < extra_edge_obj.nr; i++)
139 fprintf(pipe_fd, "%s\n",
140 - sha1_to_hex(extra_edge_obj.objects[i].item->sha1));
140 + oid_to_hex(&extra_edge_obj.objects[i].item->oid));
141 fprintf(pipe_fd, "\n");
142 fflush(pipe_fd);
143 fclose(pipe_fd);
@@ -491,7 +491,7 @@ static void check_non_tip(void)
491 continue;
492 if (!is_our_ref(o))
493 continue;
494 - memcpy(namebuf + 1, sha1_to_hex(o->sha1), 40);
494 + memcpy(namebuf + 1, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);
495 if (write_in_full(cmd.in, namebuf, 42) < 0)
496 goto error;
497 }
@@ -500,7 +500,7 @@ static void check_non_tip(void)
500 o = want_obj.objects[i].item;
501 if (is_our_ref(o))
502 continue;
503 - memcpy(namebuf, sha1_to_hex(o->sha1), 40);
503 + memcpy(namebuf, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);
504 if (write_in_full(cmd.in, namebuf, 41) < 0)
505 goto error;
506 }
@@ -534,7 +534,7 @@ error:
534 o = want_obj.objects[i].item;
535 if (!is_our_ref(o))
536 die("git upload-pack: not our ref %s",
537 - sha1_to_hex(o->sha1));
537 + oid_to_hex(&o->oid));
538 }
539 }
540
@@ -646,7 +646,7 @@ static void receive_needs(void)
646 struct object *object = &result->item->object;
647 if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
648 packet_write(1, "shallow %s",
649 - sha1_to_hex(object->sha1));
649 + oid_to_hex(&object->oid));
650 register_shallow(get_object_hash(*object));
651 shallow_nr++;
652 }
@@ -658,7 +658,7 @@ static void receive_needs(void)
658 if (object->flags & NOT_SHALLOW) {
659 struct commit_list *parents;
660 packet_write(1, "unshallow %s",
661 - sha1_to_hex(object->sha1));
661 + oid_to_hex(&object->oid));
662 object->flags &= ~CLIENT_SHALLOW;
663 /* make sure the real parents are parsed */
664 unregister_shallow(get_object_hash(*object));
walker.c
+4 -4
@@ -19,7 +19,7 @@ static void report_missing(const struct object *obj)
19 {
20 fprintf(stderr, "Cannot obtain needed %s %s\n",
21 obj->type ? typename(obj->type): "object",
22 - sha1_to_hex(obj->sha1));
22 + oid_to_hex(&obj->oid));
23 if (!is_null_sha1(current_commit_sha1))
24 fprintf(stderr, "while processing commit %s.\n",
25 sha1_to_hex(current_commit_sha1));
@@ -80,7 +80,7 @@ static int process_commit(struct walker *walker, struct commit *commit)
80
81 hashcpy(current_commit_sha1, get_object_hash(commit->object));
82
83 - walker_say(walker, "walk %s\n", sha1_to_hex(commit->object.sha1));
83 + walker_say(walker, "walk %s\n", oid_to_hex(&commit->object.oid));
84
85 if (walker->get_tree) {
86 if (process(walker, &commit->tree->object))
@@ -130,7 +130,7 @@ static int process_object(struct walker *walker, struct object *obj)
130 }
131 return error("Unable to determine requirements "
132 "of type %s for %s",
133 - typename(obj->type), sha1_to_hex(obj->sha1));
133 + typename(obj->type), oid_to_hex(&obj->oid));
134 }
135
136 static int process(struct walker *walker, struct object *obj)
@@ -139,7 +139,7 @@ static int process(struct walker *walker, struct object *obj)
139 return 0;
140 obj->flags |= SEEN;
141
142 - if (has_sha1_file(obj->sha1)) {
142 + if (has_object_file(&obj->oid)) {
143 /* We already have it, so we should scan it now. */
144 obj->flags |= TO_SCAN;
145 }