diff options
author | brian m. carlson <sandals@crustytoothpaste.net> | 2015-11-10 02:22:28 +0000 |
---|---|---|
committer | Jeff King <peff@peff.net> | 2015-11-20 08:02:05 -0500 |
commit | f2fd0760f62e79609fef7bfd7ecebb002e8e4ced (patch) | |
tree | 1f915114b015428730e95a89697783560b672008 /builtin | |
parent | 7999b2cf772956466baa8925491d6fb1b0963292 (diff) | |
download | git-f2fd0760f62e79609fef7bfd7ecebb002e8e4ced.tar.gz git-f2fd0760f62e79609fef7bfd7ecebb002e8e4ced.tar.xz |
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>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/am.c | 2 | ||||
-rw-r--r-- | builtin/blame.c | 32 | ||||
-rw-r--r-- | builtin/checkout.c | 12 | ||||
-rw-r--r-- | builtin/commit-tree.c | 4 | ||||
-rw-r--r-- | builtin/describe.c | 14 | ||||
-rw-r--r-- | builtin/diff-tree.c | 4 | ||||
-rw-r--r-- | builtin/fast-export.c | 22 | ||||
-rw-r--r-- | builtin/fmt-merge-msg.c | 2 | ||||
-rw-r--r-- | builtin/fsck.c | 32 | ||||
-rw-r--r-- | builtin/grep.c | 4 | ||||
-rw-r--r-- | builtin/index-pack.c | 8 | ||||
-rw-r--r-- | builtin/log.c | 18 | ||||
-rw-r--r-- | builtin/merge-base.c | 8 | ||||
-rw-r--r-- | builtin/merge-tree.c | 2 | ||||
-rw-r--r-- | builtin/merge.c | 10 | ||||
-rw-r--r-- | builtin/name-rev.c | 8 | ||||
-rw-r--r-- | builtin/pack-objects.c | 2 | ||||
-rw-r--r-- | builtin/pull.c | 2 | ||||
-rw-r--r-- | builtin/replace.c | 6 | ||||
-rw-r--r-- | builtin/reset.c | 28 | ||||
-rw-r--r-- | builtin/rev-list.c | 14 | ||||
-rw-r--r-- | builtin/shortlog.c | 2 | ||||
-rw-r--r-- | builtin/show-branch.c | 4 | ||||
-rw-r--r-- | builtin/unpack-objects.c | 8 | ||||
-rw-r--r-- | builtin/worktree.c | 2 |
25 files changed, 125 insertions, 125 deletions
diff --git a/builtin/am.c b/builtin/am.c index f1a25ab6a..9fb42fdd7 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1441,7 +1441,7 @@ static void get_commit_info(struct am_state *state, struct commit *commit) assert(!state->msg); msg = strstr(buffer, "\n\n"); if (!msg) - die(_("unable to parse commit %s"), sha1_to_hex(commit->object.sha1)); + die(_("unable to parse commit %s"), oid_to_hex(&commit->object.oid)); state->msg = xstrdup(msg + 2); state->msg_len = strlen(state->msg); } diff --git a/builtin/blame.c b/builtin/blame.c index c6ea9774b..28c48bd45 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -557,7 +557,7 @@ static struct origin *find_origin(struct scoreboard *sb, PATHSPEC_LITERAL_PATH, "", paths); diff_setup_done(&diff_opts); - if (is_null_sha1(origin->commit->object.sha1)) + if (is_null_oid(&origin->commit->object.oid)) do_diff_cache(get_object_hash(parent->tree->object), &diff_opts); else diff_tree_sha1(get_object_hash(parent->tree->object), @@ -627,7 +627,7 @@ static struct origin *find_rename(struct scoreboard *sb, diff_opts.single_follow = origin->path; diff_setup_done(&diff_opts); - if (is_null_sha1(origin->commit->object.sha1)) + if (is_null_oid(&origin->commit->object.oid)) do_diff_cache(get_object_hash(parent->tree->object), &diff_opts); else diff_tree_sha1(get_object_hash(parent->tree->object), @@ -977,8 +977,8 @@ static void pass_blame_to_parent(struct scoreboard *sb, if (diff_hunks(&file_p, &file_o, 0, blame_chunk_cb, &d)) die("unable to generate diff (%s -> %s)", - sha1_to_hex(parent->commit->object.sha1), - sha1_to_hex(target->commit->object.sha1)); + oid_to_hex(&parent->commit->object.oid), + oid_to_hex(&target->commit->object.oid)); /* The rest are the same as the parent */ blame_chunk(&d.dstq, &d.srcq, INT_MAX, d.offset, INT_MAX, parent); *d.dstq = NULL; @@ -1126,7 +1126,7 @@ static void find_copy_in_blob(struct scoreboard *sb, memset(split, 0, sizeof(struct blame_entry [3])); if (diff_hunks(file_p, &file_o, 1, handle_split_cb, &d)) die("unable to generate diff (%s)", - sha1_to_hex(parent->commit->object.sha1)); + oid_to_hex(&parent->commit->object.oid)); /* remainder, if any, all match the preimage */ handle_split(sb, ent, d.tlno, d.plno, ent->num_lines, parent, split); } @@ -1275,7 +1275,7 @@ static void find_copy_in_parent(struct scoreboard *sb, && (!porigin || strcmp(target->path, porigin->path)))) DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER); - if (is_null_sha1(target->commit->object.sha1)) + if (is_null_oid(&target->commit->object.oid)) do_diff_cache(get_object_hash(parent->tree->object), &diff_opts); else diff_tree_sha1(get_object_hash(parent->tree->object), @@ -1690,7 +1690,7 @@ static void get_commit_info(struct commit *commit, if (len) strbuf_add(&ret->summary, subject, len); else - strbuf_addf(&ret->summary, "(%s)", sha1_to_hex(commit->object.sha1)); + strbuf_addf(&ret->summary, "(%s)", oid_to_hex(&commit->object.oid)); unuse_commit_buffer(commit, message); } @@ -1733,7 +1733,7 @@ static int emit_one_suspect_detail(struct origin *suspect, int repeat) printf("boundary\n"); if (suspect->previous) { struct origin *prev = suspect->previous; - printf("previous %s ", sha1_to_hex(prev->commit->object.sha1)); + printf("previous %s ", oid_to_hex(&prev->commit->object.oid)); write_name_quoted(prev->path, stdout, '\n'); } @@ -1752,7 +1752,7 @@ static void found_guilty_entry(struct blame_entry *ent) struct origin *suspect = ent->suspect; printf("%s %d %d %d\n", - sha1_to_hex(suspect->commit->object.sha1), + oid_to_hex(&suspect->commit->object.oid), ent->s_lno + 1, ent->lno + 1, ent->num_lines); emit_one_suspect_detail(suspect, 0); write_filename_info(suspect->path); @@ -1882,7 +1882,7 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent, struct origin *suspect = ent->suspect; char hex[GIT_SHA1_HEXSZ + 1]; - sha1_to_hex_r(hex, suspect->commit->object.sha1); + sha1_to_hex_r(hex, suspect->commit->object.oid.hash); printf("%s %d %d %d\n", hex, ent->s_lno + 1, @@ -1922,7 +1922,7 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt) int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP); get_commit_info(suspect->commit, &ci, 1); - sha1_to_hex_r(hex, suspect->commit->object.sha1); + sha1_to_hex_r(hex, suspect->commit->object.oid.hash); cp = nth_line(sb, ent->lno); for (cnt = 0; cnt < ent->num_lines; cnt++) { @@ -2153,7 +2153,7 @@ static void sanity_check_refcnt(struct scoreboard *sb) if (ent->suspect->refcnt <= 0) { fprintf(stderr, "%s in %s has negative refcnt %d\n", ent->suspect->path, - sha1_to_hex(ent->suspect->commit->object.sha1), + oid_to_hex(&ent->suspect->commit->object.oid), ent->suspect->refcnt); baa = 1; } @@ -2310,7 +2310,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt, strbuf_addstr(&msg, "tree 0000000000000000000000000000000000000000\n"); for (parent = commit->parents; parent; parent = parent->next) strbuf_addf(&msg, "parent %s\n", - sha1_to_hex(parent->item->object.sha1)); + oid_to_hex(&parent->item->object.oid)); strbuf_addf(&msg, "author %s\n" "committer %s\n\n" @@ -2740,7 +2740,7 @@ parse_done: sb.revs->children.name = "children"; while (c->parents && - hashcmp(c->object.sha1, sb.final->object.sha1)) { + oidcmp(&c->object.oid, &sb.final->object.oid)) { struct commit_list *l = xcalloc(1, sizeof(*l)); l->item = c; @@ -2750,11 +2750,11 @@ parse_done: c = c->parents->item; } - if (hashcmp(c->object.sha1, sb.final->object.sha1)) + if (oidcmp(&c->object.oid, &sb.final->object.oid)) die("--reverse --first-parent together require range along first-parent chain"); } - if (is_null_sha1(sb.final->object.sha1)) { + if (is_null_oid(&sb.final->object.oid)) { o = sb.final->util; sb.final_buf = xmemdupz(o->file.ptr, o->file.size); sb.final_buf_size = o->file.size; diff --git a/builtin/checkout.c b/builtin/checkout.c index bca3a04c0..50fd893f7 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -56,8 +56,8 @@ static int post_checkout_hook(struct commit *old, struct commit *new, int changed) { return run_hook_le(NULL, "post-checkout", - sha1_to_hex(old ? old->object.sha1 : null_sha1), - sha1_to_hex(new ? new->object.sha1 : null_sha1), + sha1_to_hex(old ? old->object.oid.hash : null_sha1), + sha1_to_hex(new ? new->object.oid.hash : null_sha1), changed ? "1" : "0", NULL); /* "new" can be NULL when checking out from the index before a commit exists. */ @@ -513,7 +513,7 @@ static int merge_working_tree(const struct checkout_opts *opts, get_object_hash(old->commit->object) : EMPTY_TREE_SHA1_BIN); init_tree_desc(&trees[0], tree->buffer, tree->size); - tree = parse_tree_indirect(new->commit->object.sha1); + tree = parse_tree_indirect(new->commit->object.oid.hash); init_tree_desc(&trees[1], tree->buffer, tree->size); ret = unpack_trees(2, trees, &topts); @@ -641,7 +641,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts, old_desc = old->name; if (!old_desc && old->commit) - old_desc = sha1_to_hex(old->commit->object.sha1); + old_desc = oid_to_hex(&old->commit->object.oid); reflog_msg = getenv("GIT_REFLOG_ACTION"); if (!reflog_msg) @@ -780,10 +780,10 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new) setup_revisions(0, NULL, &revs, NULL); object->flags &= ~UNINTERESTING; - add_pending_object(&revs, object, sha1_to_hex(object->sha1)); + add_pending_object(&revs, object, oid_to_hex(&object->oid)); for_each_ref(add_pending_uninteresting_ref, &revs); - add_pending_sha1(&revs, "HEAD", new->object.sha1, UNINTERESTING); + add_pending_sha1(&revs, "HEAD", new->object.oid.hash, UNINTERESTING); refs = revs.pending; revs.leak_pending = 1; diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index 8747c0f2f..3feeffeab 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -16,11 +16,11 @@ static const char *sign_commit; static void new_parent(struct commit *parent, struct commit_list **parents_p) { - unsigned char *sha1 = parent->object.sha1; + struct object_id *oid = &parent->object.oid; struct commit_list *parents; for (parents = *parents_p; parents; parents = parents->next) { if (parents->item == parent) { - error("duplicate parent %s ignored", sha1_to_hex(sha1)); + error("duplicate parent %s ignored", oid_to_hex(oid)); return; } parents_p = &parents->next; diff --git a/builtin/describe.c b/builtin/describe.c index c0c373b41..11f7300aa 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -267,7 +267,7 @@ static void describe(const char *arg, int last_one) } if (!max_candidates) - die(_("no tag exactly matches '%s'"), sha1_to_hex(cmit->object.sha1)); + die(_("no tag exactly matches '%s'"), oid_to_hex(&cmit->object.oid)); if (debug) fprintf(stderr, _("searching to describe %s\n"), arg); @@ -317,7 +317,7 @@ static void describe(const char *arg, int last_one) if (annotated_cnt && !list) { if (debug) fprintf(stderr, _("finished search at %s\n"), - sha1_to_hex(c->object.sha1)); + oid_to_hex(&c->object.oid)); break; } while (parents) { @@ -334,9 +334,9 @@ static void describe(const char *arg, int last_one) } if (!match_cnt) { - const unsigned char *sha1 = cmit->object.sha1; + struct object_id *oid = &cmit->object.oid; if (always) { - printf("%s", find_unique_abbrev(sha1, abbrev)); + printf("%s", find_unique_abbrev(oid->hash, abbrev)); if (dirty) printf("%s", dirty); printf("\n"); @@ -345,11 +345,11 @@ static void describe(const char *arg, int last_one) if (unannotated_cnt) die(_("No annotated tags can describe '%s'.\n" "However, there were unannotated tags: try --tags."), - sha1_to_hex(sha1)); + oid_to_hex(oid)); else die(_("No tags can describe '%s'.\n" "Try --always, or create some tags."), - sha1_to_hex(sha1)); + oid_to_hex(oid)); } qsort(all_matches, match_cnt, sizeof(all_matches[0]), compare_pt); @@ -374,7 +374,7 @@ static void describe(const char *arg, int last_one) _("more than %i tags found; listed %i most recent\n" "gave up search at %s\n"), max_candidates, max_candidates, - sha1_to_hex(gave_up_on->object.sha1)); + oid_to_hex(&gave_up_on->object.oid)); } } diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index cf7e9604b..6fef266ea 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -49,8 +49,8 @@ static int stdin_diff_trees(struct tree *tree1, char *line, int len) tree2 = lookup_tree(sha1); if (!tree2 || parse_tree(tree2)) return -1; - printf("%s %s\n", sha1_to_hex(tree1->object.sha1), - sha1_to_hex(tree2->object.sha1)); + printf("%s %s\n", oid_to_hex(&tree1->object.oid), + oid_to_hex(&tree2->object.oid)); diff_tree_sha1(get_object_hash(tree1->object), get_object_hash(tree2->object), "", &log_tree_opt.diffopt); log_tree_diff_flush(&log_tree_opt); diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 30faf248f..1337a2385 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -544,13 +544,13 @@ static void handle_commit(struct commit *commit, struct rev_info *rev) author = strstr(commit_buffer, "\nauthor "); if (!author) die ("Could not find author in commit %s", - sha1_to_hex(commit->object.sha1)); + oid_to_hex(&commit->object.oid)); author++; author_end = strchrnul(author, '\n'); committer = strstr(author_end, "\ncommitter "); if (!committer) die ("Could not find committer in commit %s", - sha1_to_hex(commit->object.sha1)); + oid_to_hex(&commit->object.oid)); committer++; committer_end = strchrnul(committer, '\n'); message = strstr(committer_end, "\n\n"); @@ -661,13 +661,13 @@ static void handle_tag(const char *name, struct tag *tag) } if (tagged->type == OBJ_TREE) { warning("Omitting tag %s,\nsince tags of trees (or tags of tags of trees, etc.) are not supported.", - sha1_to_hex(tag->object.sha1)); + oid_to_hex(&tag->object.oid)); return; } buf = read_sha1_file(get_object_hash(tag->object), &type, &size); if (!buf) - die ("Could not read tag %s", sha1_to_hex(tag->object.sha1)); + die ("Could not read tag %s", oid_to_hex(&tag->object.oid)); message = memmem(buf, size, "\n\n", 2); if (message) { message += 2; @@ -706,16 +706,16 @@ static void handle_tag(const char *name, struct tag *tag) case ABORT: die ("Encountered signed tag %s; use " "--signed-tags=<mode> to handle it.", - sha1_to_hex(tag->object.sha1)); + oid_to_hex(&tag->object.oid)); case WARN: warning ("Exporting signed tag %s", - sha1_to_hex(tag->object.sha1)); + oid_to_hex(&tag->object.oid)); /* fallthru */ case VERBATIM: break; case WARN_STRIP: warning ("Stripping signature from tag %s", - sha1_to_hex(tag->object.sha1)); + oid_to_hex(&tag->object.oid)); /* fallthru */ case STRIP: message_size = signature + 1 - message; @@ -731,14 +731,14 @@ static void handle_tag(const char *name, struct tag *tag) case ABORT: die ("Tag %s tags unexported object; use " "--tag-of-filtered-object=<mode> to handle it.", - sha1_to_hex(tag->object.sha1)); + oid_to_hex(&tag->object.oid)); case DROP: /* Ignore this tag altogether */ return; case REWRITE: if (tagged->type != OBJ_COMMIT) { die ("Tag %s tags unexported %s!", - sha1_to_hex(tag->object.sha1), + oid_to_hex(&tag->object.oid), typename(tagged->type)); } p = (struct commit *)tagged; @@ -751,7 +751,7 @@ static void handle_tag(const char *name, struct tag *tag) break; if (!p->parents) die ("Can't find replacement commit for tag %s\n", - sha1_to_hex(tag->object.sha1)); + oid_to_hex(&tag->object.oid)); p = p->parents->item; } tagged_mark = get_object_mark(&p->object); @@ -888,7 +888,7 @@ static void export_marks(char *file) if (deco->base && deco->base->type == 1) { mark = ptr_to_mark(deco->decoration); if (fprintf(f, ":%"PRIu32" %s\n", mark, - sha1_to_hex(deco->base->sha1)) < 0) { + oid_to_hex(&deco->base->oid)) < 0) { e = 1; break; } diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index a1505002b..12aba984e 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -378,7 +378,7 @@ static void shortlog(const char *name, if (!sb.len) string_list_append(&subjects, - sha1_to_hex(commit->object.sha1)); + oid_to_hex(&commit->object.oid)); else string_list_append(&subjects, strbuf_detach(&sb, NULL)); } diff --git a/builtin/fsck.c b/builtin/fsck.c index 40206696c..7bfb4938f 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -67,7 +67,7 @@ static void objreport(struct object *obj, const char *msg_type, const char *err) { fprintf(stderr, "%s in %s %s: %s\n", - msg_type, typename(obj->type), sha1_to_hex(obj->sha1), err); + msg_type, typename(obj->type), oid_to_hex(&obj->oid), err); } 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 if (!obj) { /* ... these references to parent->fld are safe here */ printf("broken link from %7s %s\n", - typename(parent->type), sha1_to_hex(parent->sha1)); + typename(parent->type), oid_to_hex(&parent->oid)); printf("broken link from %7s %s\n", (type == OBJ_ANY ? "unknown" : typename(type)), "unknown"); errors_found |= ERROR_REACHABLE; @@ -112,11 +112,11 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt return 0; obj->flags |= REACHABLE; if (!(obj->flags & HAS_OBJ)) { - if (parent && !has_sha1_file(obj->sha1)) { + if (parent && !has_object_file(&obj->oid)) { printf("broken link from %7s %s\n", - typename(parent->type), sha1_to_hex(parent->sha1)); + typename(parent->type), oid_to_hex(&parent->oid)); printf(" to %7s %s\n", - typename(obj->type), sha1_to_hex(obj->sha1)); + typename(obj->type), oid_to_hex(&obj->oid)); errors_found |= ERROR_REACHABLE; } return 1; @@ -188,9 +188,9 @@ static void check_reachable_object(struct object *obj) if (!(obj->flags & HAS_OBJ)) { if (has_sha1_pack(get_object_hash(*obj))) return; /* it is in pack - forget about it */ - if (connectivity_only && has_sha1_file(obj->sha1)) + if (connectivity_only && has_object_file(&obj->oid)) return; - printf("missing %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1)); + printf("missing %s %s\n", typename(obj->type), oid_to_hex(&obj->oid)); errors_found |= ERROR_REACHABLE; return; } @@ -215,7 +215,7 @@ static void check_unreachable_object(struct object *obj) * since this is something that is prunable. */ if (show_unreachable) { - printf("unreachable %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1)); + printf("unreachable %s %s\n", typename(obj->type), oid_to_hex(&obj->oid)); return; } @@ -234,11 +234,11 @@ static void check_unreachable_object(struct object *obj) if (!obj->used) { if (show_dangling) printf("dangling %s %s\n", typename(obj->type), - sha1_to_hex(obj->sha1)); + oid_to_hex(&obj->oid)); if (write_lost_and_found) { char *filename = git_pathdup("lost-found/%s/%s", obj->type == OBJ_COMMIT ? "commit" : "other", - sha1_to_hex(obj->sha1)); + oid_to_hex(&obj->oid)); FILE *f; if (safe_create_leading_directories_const(filename)) { @@ -252,7 +252,7 @@ static void check_unreachable_object(struct object *obj) if (stream_blob_to_fd(fileno(f), get_object_hash(*obj), NULL, 1)) die_errno("Could not write '%s'", filename); } else - fprintf(f, "%s\n", sha1_to_hex(obj->sha1)); + fprintf(f, "%s\n", oid_to_hex(&obj->oid)); if (fclose(f)) die_errno("Could not finish '%s'", filename); @@ -271,7 +271,7 @@ static void check_unreachable_object(struct object *obj) static void check_object(struct object *obj) { if (verbose) - fprintf(stderr, "Checking %s\n", sha1_to_hex(obj->sha1)); + fprintf(stderr, "Checking %s\n", oid_to_hex(&obj->oid)); if (obj->flags & REACHABLE) check_reachable_object(obj); @@ -307,7 +307,7 @@ static int fsck_obj(struct object *obj) if (verbose) fprintf(stderr, "Checking %s %s\n", - typename(obj->type), sha1_to_hex(obj->sha1)); + typename(obj->type), oid_to_hex(&obj->oid)); if (fsck_walk(obj, NULL, &fsck_obj_options)) objerror(obj, "broken links"); @@ -326,15 +326,15 @@ static int fsck_obj(struct object *obj) free_commit_buffer(commit); if (!commit->parents && show_root) - printf("root %s\n", sha1_to_hex(commit->object.sha1)); + printf("root %s\n", oid_to_hex(&commit->object.oid)); } if (obj->type == OBJ_TAG) { struct tag *tag = (struct tag *) obj; if (show_tags && tag->tagged) { - printf("tagged %s %s", typename(tag->tagged->type), sha1_to_hex(tag->tagged->sha1)); - printf(" (%s) in %s\n", tag->tag, sha1_to_hex(tag->object.sha1)); + printf("tagged %s %s", typename(tag->tagged->type), oid_to_hex(&tag->tagged->oid)); + printf(" (%s) in %s\n", tag->tag, oid_to_hex(&tag->object.oid)); } } diff --git a/builtin/grep.c b/builtin/grep.c index 9c42fc03b..ca3ceea42 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -468,12 +468,12 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec, int hit, len; grep_read_lock(); - data = read_object_with_reference(obj->sha1, tree_type, + data = read_object_with_reference(obj->oid.hash, tree_type, &size, NULL); grep_read_unlock(); if (!data) - die(_("unable to read tree (%s)"), sha1_to_hex(obj->sha1)); + die(_("unable to read tree (%s)"), oid_to_hex(&obj->oid)); len = name ? strlen(name) : 0; strbuf_init(&base, PATH_MAX + len + 1); diff --git a/builtin/index-pack.c b/builtin/index-pack.c index b01a8c0e2..48b470dd7 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -199,7 +199,7 @@ static int mark_link(struct object *obj, int type, void *data, struct fsck_optio return -1; if (type != OBJ_ANY && obj->type != type) - die(_("object type mismatch at %s"), sha1_to_hex(obj->sha1)); + die(_("object type mismatch at %s"), oid_to_hex(&obj->oid)); obj->flags |= FLAG_LINK; return 0; @@ -220,10 +220,10 @@ static unsigned check_object(struct object *obj) int type = sha1_object_info(get_object_hash(*obj), &size); if (type <= 0) die(_("did not receive expected object %s"), - sha1_to_hex(obj->sha1)); + oid_to_hex(&obj->oid)); if (type != obj->type) die(_("object %s: expected type %s, found %s"), - sha1_to_hex(obj->sha1), + oid_to_hex(&obj->oid), typename(obj->type), typename(type)); obj->flags |= FLAG_CHECKED; return 1; @@ -842,7 +842,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry, fsck_object(obj, buf, size, &fsck_options)) die(_("Error in object")); if (fsck_walk(obj, NULL, &fsck_options)) - die(_("Not all child objects of %s are reachable"), sha1_to_hex(obj->sha1)); + die(_("Not all child objects of %s are reachable"), oid_to_hex(&obj->oid)); if (obj->type == OBJ_TREE) { struct tree *item = (struct tree *) obj; diff --git a/builtin/log.c b/builtin/log.c index 0977c8248..a16ec3243 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -570,7 +570,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) o = parse_object(get_object_hash(*t->tagged)); if (!o) ret = error(_("Could not read object %s"), - sha1_to_hex(t->tagged->sha1)); + oid_to_hex(&t->tagged->oid)); objects[i].item = o; i--; break; @@ -896,8 +896,8 @@ static void add_branch_description(struct strbuf *buf, const char *branch_name) static char *find_branch_name(struct rev_info *rev) { int i, positive = -1; - unsigned char branch_sha1[20]; - const unsigned char *tip_sha1; + struct object_id branch_oid; + const struct object_id *tip_oid; const char *ref, *v; char *full_ref, *branch = NULL; @@ -912,10 +912,10 @@ static char *find_branch_name(struct rev_info *rev) if (positive < 0) return NULL; ref = rev->cmdline.rev[positive].name; - tip_sha1 = rev->cmdline.rev[positive].item->sha1; - if (dwim_ref(ref, strlen(ref), branch_sha1, &full_ref) && + tip_oid = &rev->cmdline.rev[positive].item->oid; + if (dwim_ref(ref, strlen(ref), branch_oid.hash, &full_ref) && skip_prefix(full_ref, "refs/heads/", &v) && - !hashcmp(tip_sha1, branch_sha1)) + !oidcmp(tip_oid, &branch_oid)) branch = xstrdup(v); free(full_ref); return branch; @@ -1443,7 +1443,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) /* Don't say anything if head and upstream are the same. */ if (rev.pending.nr == 2) { struct object_array_entry *o = rev.pending.objects; - if (hashcmp(o[0].item->sha1, o[1].item->sha1) == 0) + if (oidcmp(&o[0].item->oid, &o[1].item->oid) == 0) return 0; } get_patch_ids(&rev, &ids); @@ -1550,7 +1550,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) string_list_append(rev.ref_message_ids, rev.message_id); } - gen_message_id(&rev, sha1_to_hex(commit->object.sha1)); + gen_message_id(&rev, oid_to_hex(&commit->object.oid)); } if (!use_stdout && @@ -1675,7 +1675,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix) /* Don't say anything if head and upstream are the same. */ if (revs.pending.nr == 2) { struct object_array_entry *o = revs.pending.objects; - if (hashcmp(o[0].item->sha1, o[1].item->sha1) == 0) + if (oidcmp(&o[0].item->oid, &o[1].item->oid) == 0) return 0; } diff --git a/builtin/merge-base.c b/builtin/merge-base.c index 08a821789..a8911626c 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -16,7 +16,7 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all) return 1; while (result) { - printf("%s\n", sha1_to_hex(result->item->object.sha1)); + printf("%s\n", oid_to_hex(&result->item->object.oid)); if (!show_all) return 0; result = result->next; @@ -62,7 +62,7 @@ static int handle_independent(int count, const char **args) return 1; while (result) { - printf("%s\n", sha1_to_hex(result->item->object.sha1)); + printf("%s\n", oid_to_hex(&result->item->object.oid)); result = result->next; } return 0; @@ -83,7 +83,7 @@ static int handle_octopus(int count, const char **args, int show_all) return 1; while (result) { - printf("%s\n", sha1_to_hex(result->item->object.sha1)); + printf("%s\n", oid_to_hex(&result->item->object.oid)); if (!show_all) return 0; result = result->next; @@ -196,7 +196,7 @@ static int handle_fork_point(int argc, const char **argv) goto cleanup_return; } - printf("%s\n", sha1_to_hex(bases->item->object.sha1)); + printf("%s\n", oid_to_hex(&bases->item->object.oid)); cleanup_return: free_commit_list(bases); diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index cf1cee1d5..e124886ef 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -130,7 +130,7 @@ static void show_result_list(struct merge_list *entry) do { struct merge_list *link = entry->link; static const char *desc[4] = { "result", "base", "our", "their" }; - printf(" %-6s %o %s %s\n", desc[entry->stage], entry->mode, sha1_to_hex(entry->blob->object.sha1), entry->path); + printf(" %-6s %o %s %s\n", desc[entry->stage], entry->mode, oid_to_hex(&entry->blob->object.oid), entry->path); entry = link; } while (entry); } diff --git a/builtin/merge.c b/builtin/merge.c index a6e598d95..c804218fb 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -365,7 +365,7 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead while ((commit = get_revision(&rev)) != NULL) { strbuf_addch(&out, '\n'); strbuf_addf(&out, "commit %s\n", - sha1_to_hex(get_object_hash(commit->object))); + oid_to_hex(&commit->object.oid)); pretty_print_commit(&ctx, commit, &out); } if (write_in_full(fd, out.buf, out.len) != out.len) @@ -958,14 +958,14 @@ static void write_merge_state(struct commit_list *remoteheads) struct strbuf buf = STRBUF_INIT; for (j = remoteheads; j; j = j->next) { - unsigned const char *sha1; + struct object_id *oid; struct commit *c = j->item; if (c->util && merge_remote_util(c)->obj) { - sha1 = merge_remote_util(c)->obj->sha1; + oid = &merge_remote_util(c)->obj->oid; } else { - sha1 = get_object_hash(c->object); + oid = &c->object.oid; } - strbuf_addf(&buf, "%s\n", sha1_to_hex(sha1)); + strbuf_addf(&buf, "%s\n", oid_to_hex(oid)); } filename = git_path_merge_head(); fd = open(filename, O_WRONLY | O_CREAT, 0666); diff --git a/builtin/name-rev.c b/builtin/name-rev.c index cac66a589..49e6e91b1 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -232,19 +232,19 @@ static void show_name(const struct object *obj, int always, int allow_undefined, int name_only) { const char *name; - const unsigned char *sha1 = get_object_hash(*obj); + const struct object_id *oid = &obj->oid; if (!name_only) - printf("%s ", caller_name ? caller_name : sha1_to_hex(sha1)); + printf("%s ", caller_name ? caller_name : oid_to_hex(oid)); name = get_rev_name(obj); if (name) printf("%s\n", name); else if (allow_undefined) printf("undefined\n"); else if (always) - printf("%s\n", find_unique_abbrev(sha1, DEFAULT_ABBREV)); + printf("%s\n", find_unique_abbrev(oid->hash, DEFAULT_ABBREV)); else - die("cannot describe '%s'", sha1_to_hex(sha1)); + die("cannot describe '%s'", oid_to_hex(oid)); } static char const * const name_rev_usage[] = { diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index b2d3e4ea2..fa1b5cd71 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -2338,7 +2338,7 @@ static int ofscmp(const void *a_, const void *b_) else if (a->offset > b->offset) return 1; else - return hashcmp(a->object->sha1, b->object->sha1); + return oidcmp(&a->object->oid, &b->object->oid); } static void add_objects_in_unpacked_packs(struct rev_info *revs) diff --git a/builtin/pull.c b/builtin/pull.c index bf3fd3f9c..4b7e344ac 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -743,7 +743,7 @@ static int get_octopus_merge_base(unsigned char *merge_base, if (!result) return 1; - hashcpy(merge_base, result->item->object.sha1); + hashcpy(merge_base, get_object_hash(result->item->object)); return 0; } diff --git a/builtin/replace.c b/builtin/replace.c index 6b3c469a3..748c6ca95 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -358,10 +358,10 @@ static void check_one_mergetag(struct commit *commit, /* iterate over new parents */ for (i = 1; i < mergetag_data->argc; i++) { - unsigned char sha1[20]; - if (get_sha1(mergetag_data->argv[i], sha1) < 0) + struct object_id oid; + if (get_sha1(mergetag_data->argv[i], oid.hash) < 0) die(_("Not a valid object name: '%s'"), mergetag_data->argv[i]); - if (!hashcmp(tag->tagged->sha1, sha1)) + if (!oidcmp(&tag->tagged->oid, &oid)) return; /* found */ } diff --git a/builtin/reset.c b/builtin/reset.c index 9b8898818..d0014b625 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -269,7 +269,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) int reset_type = NONE, update_ref_status = 0, quiet = 0; int patch_mode = 0, unborn; const char *rev; - unsigned char sha1[20]; + struct object_id oid; struct pathspec pathspec; int intent_to_add = 0; const struct option options[] = { @@ -295,26 +295,26 @@ int cmd_reset(int argc, const char **argv, const char *prefix) PARSE_OPT_KEEP_DASHDASH); parse_args(&pathspec, argv, prefix, patch_mode, &rev); - unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", sha1); + unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", oid.hash); if (unborn) { /* reset on unborn branch: treat as reset to empty tree */ - hashcpy(sha1, EMPTY_TREE_SHA1_BIN); + hashcpy(oid.hash, EMPTY_TREE_SHA1_BIN); } else if (!pathspec.nr) { struct commit *commit; - if (get_sha1_committish(rev, sha1)) + if (get_sha1_committish(rev, oid.hash)) die(_("Failed to resolve '%s' as a valid revision."), rev); - commit = lookup_commit_reference(sha1); + commit = lookup_commit_reference(oid.hash); if (!commit) die(_("Could not parse object '%s'."), rev); - hashcpy(sha1, commit->object.sha1); + oidcpy(&oid, &commit->object.oid); } else { struct tree *tree; - if (get_sha1_treeish(rev, sha1)) + if (get_sha1_treeish(rev, oid.hash)) die(_("Failed to resolve '%s' as a valid tree."), rev); - tree = parse_tree_indirect(sha1); + tree = parse_tree_indirect(oid.hash); if (!tree) die(_("Could not parse object '%s'."), rev); - hashcpy(sha1, tree->object.sha1); + oidcpy(&oid, &tree->object.oid); } if (patch_mode) { @@ -357,15 +357,15 @@ int cmd_reset(int argc, const char **argv, const char *prefix) hold_locked_index(lock, 1); if (reset_type == MIXED) { int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN; - if (read_from_tree(&pathspec, sha1, intent_to_add)) + if (read_from_tree(&pathspec, oid.hash, intent_to_add)) return 1; if (get_git_work_tree()) refresh_index(&the_index, flags, NULL, NULL, _("Unstaged changes after reset:")); } else { - int err = reset_index(sha1, reset_type, quiet); + int err = reset_index(oid.hash, reset_type, quiet); if (reset_type == KEEP && !err) - err = reset_index(sha1, MIXED, quiet); + err = reset_index(oid.hash, MIXED, quiet); if (err) die(_("Could not reset index file to revision '%s'."), rev); } @@ -377,10 +377,10 @@ int cmd_reset(int argc, const char **argv, const char *prefix) if (!pathspec.nr && !unborn) { /* Any resets without paths update HEAD to the head being * switched to, saving the previous head in ORIG_HEAD before. */ - update_ref_status = reset_refs(rev, sha1); + update_ref_status = reset_refs(rev, oid.hash); if (reset_type == HARD && !update_ref_status && !quiet) - print_new_head_line(lookup_commit_reference(sha1)); + print_new_head_line(lookup_commit_reference(oid.hash)); } if (!pathspec.nr) remove_branch_state(); diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 1cd5db1ae..c4166ea7d 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -84,11 +84,11 @@ static void show_commit(struct commit *commit, void *data) fputs(find_unique_abbrev(get_object_hash(commit->object), revs->abbrev), stdout); else - fputs(sha1_to_hex(commit->object.sha1), stdout); + fputs(oid_to_hex(&commit->object.oid), stdout); if (revs->print_parents) { struct commit_list *parents = commit->parents; while (parents) { - printf(" %s", sha1_to_hex(parents->item->object.sha1)); + printf(" %s", oid_to_hex(&parents->item->object.oid)); parents = parents->next; } } @@ -97,7 +97,7 @@ static void show_commit(struct commit *commit, void *data) children = lookup_decoration(&revs->children, &commit->object); while (children) { - printf(" %s", sha1_to_hex(children->item->object.sha1)); + printf(" %s", oid_to_hex(&children->item->object.oid)); children = children->next; } } @@ -182,8 +182,8 @@ static void finish_object(struct object *obj, void *cb_data) { struct rev_list_info *info = cb_data; - if (obj->type == OBJ_BLOB && !has_sha1_file(obj->sha1)) - die("missing blob object '%s'", sha1_to_hex(obj->sha1)); + if (obj->type == OBJ_BLOB && !has_object_file(&obj->oid)) + die("missing blob object '%s'", oid_to_hex(&obj->oid)); if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT) parse_object(get_object_hash(*obj)); } @@ -201,7 +201,7 @@ static void show_object(struct object *obj, static void show_edge(struct commit *commit) { - printf("-%s\n", sha1_to_hex(commit->object.sha1)); + printf("-%s\n", oid_to_hex(&commit->object.oid)); } 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) cnt = reaches; if (revs->commits) - sha1_to_hex_r(hex, revs->commits->item->object.sha1); + sha1_to_hex_r(hex, revs->commits->item->object.oid.hash); if (flags & BISECT_SHOW_ALL) { traverse_commit_list(revs, show_commit, show_object, info); diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 007cc66a0..35ebd17f8 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -129,7 +129,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit) } if (!author) { warning(_("Missing author: %s"), - sha1_to_hex(commit->object.sha1)); + oid_to_hex(&commit->object.oid)); return; } if (log->user_format) { diff --git a/builtin/show-branch.c b/builtin/show-branch.c index eb8857050..182864090 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -496,7 +496,7 @@ static int show_merge_base(struct commit_list *seen, int num_rev) int flags = commit->object.flags & all_mask; if (!(flags & UNINTERESTING) && ((flags & all_revs) == all_revs)) { - puts(sha1_to_hex(commit->object.sha1)); + puts(oid_to_hex(&commit->object.oid)); exit_status = 0; commit->object.flags |= UNINTERESTING; } @@ -516,7 +516,7 @@ static int show_independent(struct commit **rev, unsigned int flag = rev_mask[i]; if (commit->object.flags == flag) - puts(sha1_to_hex(commit->object.sha1)); + puts(oid_to_hex(&commit->object.oid)); commit->object.flags |= UNINTERESTING; } return 0; diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 1cf2806ee..61a337889 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -46,7 +46,7 @@ static void add_object_buffer(struct object *object, char *buffer, unsigned long obj->buffer = buffer; obj->size = size; if (add_decoration(&obj_decorate, object, obj)) - die("object %s tried to add buffer twice!", sha1_to_hex(object->sha1)); + die("object %s tried to add buffer twice!", oid_to_hex(&object->oid)); } /* @@ -170,7 +170,7 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf) unsigned char sha1[20]; if (write_sha1_file(obj_buf->buffer, obj_buf->size, typename(obj->type), sha1) < 0) - die("failed to write object %s", sha1_to_hex(obj->sha1)); + die("failed to write object %s", oid_to_hex(&obj->oid)); obj->flags |= FLAG_WRITTEN; } @@ -203,12 +203,12 @@ static int check_object(struct object *obj, int type, void *data, struct fsck_op obj_buf = lookup_object_buffer(obj); if (!obj_buf) - die("Whoops! Cannot find object '%s'", sha1_to_hex(obj->sha1)); + die("Whoops! Cannot find object '%s'", oid_to_hex(&obj->oid)); if (fsck_object(obj, obj_buf->buffer, obj_buf->size, &fsck_options)) die("Error in object"); fsck_options.walk = check_object; if (fsck_walk(obj, NULL, &fsck_options)) - die("Error on reachable objects of %s", sha1_to_hex(obj->sha1)); + die("Error on reachable objects of %s", oid_to_hex(&obj->oid)); write_cached_object(obj, obj_buf); return 0; } diff --git a/builtin/worktree.c b/builtin/worktree.c index d281f6d88..475b9581a 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -277,7 +277,7 @@ static int add_worktree(const char *path, const char *refname, if (commit) argv_array_pushl(&cp.args, "update-ref", "HEAD", - sha1_to_hex(commit->object.sha1), NULL); + oid_to_hex(&commit->object.oid), NULL); else argv_array_pushl(&cp.args, "symbolic-ref", "HEAD", symref.buf, NULL); |