diff options
106 files changed, 1173 insertions, 1134 deletions
@@ -360,7 +360,7 @@ static void parse_treeish_arg(const char **argv, if (get_sha1(name, oid.hash)) die("Not a valid object name"); - commit = lookup_commit_reference_gently(oid.hash, 1); + commit = lookup_commit_reference_gently(&oid, 1); if (commit) { commit_sha1 = commit->object.oid.hash; archive_time = commit->date; @@ -369,7 +369,7 @@ static void parse_treeish_arg(const char **argv, archive_time = time(NULL); } - tree = parse_tree_indirect(oid.hash); + tree = parse_tree_indirect(&oid); if (tree == NULL) die("not a tree object"); @@ -383,7 +383,7 @@ static void parse_treeish_arg(const char **argv, if (err || !S_ISDIR(mode)) die("current working directory is untracked"); - tree = parse_tree_indirect(tree_oid.hash); + tree = parse_tree_indirect(&tree_oid); } ar_args->tree = tree; ar_args->commit_sha1 = commit_sha1; @@ -705,7 +705,7 @@ static int bisect_checkout(const unsigned char *bisect_rev, int no_checkout) static struct commit *get_commit_reference(const struct object_id *oid) { - struct commit *r = lookup_commit_reference(oid->hash); + struct commit *r = lookup_commit_reference(oid); if (!r) die(_("Not a valid commit name %s"), oid_to_hex(oid)); return r; @@ -3,11 +3,11 @@ const char *blob_type = "blob"; -struct blob *lookup_blob(const unsigned char *sha1) +struct blob *lookup_blob(const struct object_id *oid) { - struct object *obj = lookup_object(sha1); + struct object *obj = lookup_object(oid->hash); if (!obj) - return create_object(sha1, alloc_blob_node()); + return create_object(oid->hash, alloc_blob_node()); return object_as_type(obj, OBJ_BLOB, 0); } @@ -9,7 +9,7 @@ struct blob { struct object object; }; -struct blob *lookup_blob(const unsigned char *sha1); +struct blob *lookup_blob(const struct object_id *oid); int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size); @@ -191,9 +191,9 @@ int validate_new_branchname(const char *name, struct strbuf *ref, if (!attr_only) { const char *head; - unsigned char sha1[20]; + struct object_id oid; - head = resolve_ref_unsafe("HEAD", 0, sha1, NULL); + head = resolve_ref_unsafe("HEAD", 0, oid.hash, NULL); if (!is_bare_repository() && head && !strcmp(head, ref->buf)) die(_("Cannot force update the current branch.")); } @@ -233,7 +233,7 @@ void create_branch(const char *name, const char *start_name, int quiet, enum branch_track track) { struct commit *commit; - unsigned char sha1[20]; + struct object_id oid; char *real_ref; struct strbuf ref = STRBUF_INIT; int forcing = 0; @@ -253,7 +253,7 @@ void create_branch(const char *name, const char *start_name, } real_ref = NULL; - if (get_sha1(start_name, sha1)) { + if (get_oid(start_name, &oid)) { if (explicit_tracking) { if (advice_set_upstream_failure) { error(_(upstream_missing), start_name); @@ -265,7 +265,7 @@ void create_branch(const char *name, const char *start_name, die(_("Not a valid object name: '%s'."), start_name); } - switch (dwim_ref(start_name, strlen(start_name), sha1, &real_ref)) { + switch (dwim_ref(start_name, strlen(start_name), oid.hash, &real_ref)) { case 0: /* Not branching from any existing branch */ if (explicit_tracking) @@ -286,9 +286,9 @@ void create_branch(const char *name, const char *start_name, break; } - if ((commit = lookup_commit_reference(sha1)) == NULL) + if ((commit = lookup_commit_reference(&oid)) == NULL) die(_("Not a valid branch point: '%s'."), start_name); - hashcpy(sha1, commit->object.oid.hash); + oidcpy(&oid, &commit->object.oid); if (reflog) log_all_ref_updates = LOG_REFS_NORMAL; @@ -306,7 +306,7 @@ void create_branch(const char *name, const char *start_name, transaction = ref_transaction_begin(&err); if (!transaction || ref_transaction_update(transaction, ref.buf, - sha1, forcing ? NULL : null_sha1, + oid.hash, forcing ? NULL : null_sha1, 0, msg, &err) || ref_transaction_commit(transaction, &err)) die("%s", err.buf); diff --git a/builtin/am.c b/builtin/am.c index 8e9ac1144d..2ec1d7b71e 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1145,7 +1145,7 @@ static int index_has_changes(struct strbuf *sb) DIFF_OPT_SET(&opt, EXIT_WITH_STATUS); if (!sb) DIFF_OPT_SET(&opt, QUICK); - do_diff_cache(head.hash, &opt); + do_diff_cache(&head, &opt); diffcore_std(&opt); for (i = 0; sb && i < diff_queued_diff.nr; i++) { if (i) @@ -1447,9 +1447,9 @@ static void write_index_patch(const struct am_state *state) FILE *fp; if (!get_sha1_tree("HEAD", head.hash)) - tree = lookup_tree(head.hash); + tree = lookup_tree(&head); else - tree = lookup_tree(EMPTY_TREE_SHA1_BIN); + tree = lookup_tree(&empty_tree_oid); fp = xfopen(am_path(state, "patch"), "w"); init_revisions(&rev_info, NULL); @@ -1482,7 +1482,7 @@ static int parse_mail_rebase(struct am_state *state, const char *mail) if (get_mail_commit_oid(&commit_oid, mail) < 0) die(_("could not parse %s"), mail); - commit = lookup_commit_or_die(commit_oid.hash, mail); + commit = lookup_commit_or_die(&commit_oid, mail); get_commit_info(state, commit); @@ -1612,7 +1612,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa init_revisions(&rev_info, NULL); rev_info.diffopt.output_format = DIFF_FORMAT_NAME_STATUS; diff_opt_parse(&rev_info.diffopt, &diff_filter_str, 1, rev_info.prefix); - add_pending_sha1(&rev_info, "HEAD", our_tree.hash, 0); + add_pending_oid(&rev_info, "HEAD", &our_tree, 0); diff_setup_done(&rev_info.diffopt); run_diff_index(&rev_info, 1); } @@ -1677,7 +1677,7 @@ static void do_commit(const struct am_state *state) if (!get_sha1_commit("HEAD", parent.hash)) { old_oid = &parent; - commit_list_insert(lookup_commit(parent.hash), &parents); + commit_list_insert(lookup_commit(&parent), &parents); } else { old_oid = NULL; say(state, stderr, _("applying to an empty history")); @@ -2039,11 +2039,11 @@ static int clean_index(const struct object_id *head, const struct object_id *rem struct tree *head_tree, *remote_tree, *index_tree; struct object_id index; - head_tree = parse_tree_indirect(head->hash); + head_tree = parse_tree_indirect(head); if (!head_tree) return error(_("Could not parse object '%s'."), oid_to_hex(head)); - remote_tree = parse_tree_indirect(remote->hash); + remote_tree = parse_tree_indirect(remote); if (!remote_tree) return error(_("Could not parse object '%s'."), oid_to_hex(remote)); @@ -2055,7 +2055,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem if (write_cache_as_tree(index.hash, 0, NULL)) return -1; - index_tree = parse_tree_indirect(index.hash); + index_tree = parse_tree_indirect(&index); if (!index_tree) return error(_("Could not parse object '%s'."), oid_to_hex(&index)); diff --git a/builtin/blame.c b/builtin/blame.c index f00eda1637..1043e5376f 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -563,7 +563,7 @@ static struct origin *find_origin(struct scoreboard *sb, diff_setup_done(&diff_opts); if (is_null_oid(&origin->commit->object.oid)) - do_diff_cache(parent->tree->object.oid.hash, &diff_opts); + do_diff_cache(&parent->tree->object.oid, &diff_opts); else diff_tree_sha1(parent->tree->object.oid.hash, origin->commit->tree->object.oid.hash, @@ -633,7 +633,7 @@ static struct origin *find_rename(struct scoreboard *sb, diff_setup_done(&diff_opts); if (is_null_oid(&origin->commit->object.oid)) - do_diff_cache(parent->tree->object.oid.hash, &diff_opts); + do_diff_cache(&parent->tree->object.oid, &diff_opts); else diff_tree_sha1(parent->tree->object.oid.hash, origin->commit->tree->object.oid.hash, @@ -1272,7 +1272,7 @@ static void find_copy_in_parent(struct scoreboard *sb, DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER); if (is_null_oid(&target->commit->object.oid)) - do_diff_cache(parent->tree->object.oid.hash, &diff_opts); + do_diff_cache(&parent->tree->object.oid, &diff_opts); else diff_tree_sha1(parent->tree->object.oid.hash, target->commit->tree->object.oid.hash, @@ -2253,7 +2253,7 @@ static struct commit_list **append_parent(struct commit_list **tail, const struc { struct commit *parent; - parent = lookup_commit_reference(oid->hash); + parent = lookup_commit_reference(oid); if (!parent) die("no such commit %s", oid_to_hex(oid)); return &commit_list_insert(parent, tail)->next; @@ -2461,7 +2461,7 @@ static const char *dwim_reverse_initial(struct scoreboard *sb) */ struct object *obj; struct commit *head_commit; - unsigned char head_sha1[20]; + struct object_id head_oid; if (sb->revs->pending.nr != 1) return NULL; @@ -2473,9 +2473,9 @@ static const char *dwim_reverse_initial(struct scoreboard *sb) return NULL; /* Do we have HEAD? */ - if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_sha1, NULL)) + if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL)) return NULL; - head_commit = lookup_commit_reference_gently(head_sha1, 1); + head_commit = lookup_commit_reference_gently(&head_oid, 1); if (!head_commit) return NULL; diff --git a/builtin/branch.c b/builtin/branch.c index 48a513a84d..83fcda43dc 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -124,7 +124,7 @@ static int branch_merged(int kind, const char *name, (reference_name = reference_name_to_free = resolve_refdup(upstream, RESOLVE_REF_READING, oid.hash, NULL)) != NULL) - reference_rev = lookup_commit_reference(oid.hash); + reference_rev = lookup_commit_reference(&oid); } if (!reference_rev) reference_rev = head_rev; @@ -157,7 +157,7 @@ static int check_branch_commit(const char *branchname, const char *refname, const struct object_id *oid, struct commit *head_rev, int kinds, int force) { - struct commit *rev = lookup_commit_reference(oid->hash); + struct commit *rev = lookup_commit_reference(oid); if (!rev) { error(_("Couldn't look up commit object for '%s'"), refname); return -1; @@ -211,7 +211,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds, } if (!force) { - head_rev = lookup_commit_reference(head_oid.hash); + head_rev = lookup_commit_reference(&head_oid); if (!head_rev) die(_("Couldn't look up commit object for HEAD")); } diff --git a/builtin/checkout.c b/builtin/checkout.c index 6c3d2e4f4c..65877bacb1 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -393,7 +393,7 @@ static int checkout_paths(const struct checkout_opts *opts, die(_("unable to write new index file")); read_ref_full("HEAD", 0, rev.hash, NULL); - head = lookup_commit_reference_gently(rev.hash, 1); + head = lookup_commit_reference_gently(&rev, 1); errs |= post_checkout_hook(head, head, 0); return errs; @@ -527,10 +527,10 @@ static int merge_working_tree(const struct checkout_opts *opts, setup_standard_excludes(topts.dir); } tree = parse_tree_indirect(old->commit ? - old->commit->object.oid.hash : - EMPTY_TREE_SHA1_BIN); + &old->commit->object.oid : + &empty_tree_oid); init_tree_desc(&trees[0], tree->buffer, tree->size); - tree = parse_tree_indirect(new->commit->object.oid.hash); + tree = parse_tree_indirect(&new->commit->object.oid); init_tree_desc(&trees[1], tree->buffer, tree->size); ret = unpack_trees(2, trees, &topts); @@ -721,7 +721,7 @@ static int add_pending_uninteresting_ref(const char *refname, const struct object_id *oid, int flags, void *cb_data) { - add_pending_sha1(cb_data, refname, oid->hash, UNINTERESTING); + add_pending_oid(cb_data, refname, oid, UNINTERESTING); return 0; } @@ -807,7 +807,7 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new) 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.oid.hash, UNINTERESTING); + add_pending_oid(&revs, "HEAD", &new->object.oid, UNINTERESTING); refs = revs.pending; revs.leak_pending = 1; @@ -834,7 +834,7 @@ static int switch_branches(const struct checkout_opts *opts, memset(&old, 0, sizeof(old)); old.path = path_to_free = resolve_refdup("HEAD", 0, rev.hash, &flag); if (old.path) - old.commit = lookup_commit_reference_gently(rev.hash, 1); + old.commit = lookup_commit_reference_gently(&rev, 1); if (!(flag & REF_ISSYMREF)) old.path = NULL; @@ -1048,10 +1048,10 @@ static int parse_branchname_arg(int argc, const char **argv, else new->path = NULL; /* not an existing branch */ - new->commit = lookup_commit_reference_gently(rev->hash, 1); + new->commit = lookup_commit_reference_gently(rev, 1); if (!new->commit) { /* not a commit */ - *source_tree = parse_tree_indirect(rev->hash); + *source_tree = parse_tree_indirect(rev); } else { parse_commit_or_die(new->commit); *source_tree = new->commit->tree; diff --git a/builtin/clone.c b/builtin/clone.c index afab299433..743f16ae2a 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -685,7 +685,7 @@ static void update_head(const struct ref *our, const struct ref *remote, install_branch_config(0, head, option_origin, our->name); } } else if (our) { - struct commit *c = lookup_commit_reference(our->old_oid.hash); + struct commit *c = lookup_commit_reference(&our->old_oid); /* --branch specifies a non-branch (i.e. tags), detach HEAD */ update_ref(msg, "HEAD", c->object.oid.hash, NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR); @@ -742,7 +742,7 @@ static int checkout(int submodule_progress) opts.src_index = &the_index; opts.dst_index = &the_index; - tree = parse_tree_indirect(oid.hash); + tree = parse_tree_indirect(&oid); parse_tree(tree); init_tree_desc(&t, tree->buffer, tree->size); if (unpack_trees(1, &t, &opts) < 0) diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index 605017261c..f39c2b2737 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -58,7 +58,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix) if (get_sha1_commit(argv[i], oid.hash)) die("Not a valid object name %s", argv[i]); assert_sha1_type(oid.hash, OBJ_COMMIT); - new_parent(lookup_commit(oid.hash), &parents); + new_parent(lookup_commit(&oid), &parents); continue; } diff --git a/builtin/commit.c b/builtin/commit.c index 9028bfacf8..1d191a49f8 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -313,7 +313,7 @@ static void create_base_index(const struct commit *current_head) opts.dst_index = &the_index; opts.fn = oneway_merge; - tree = parse_tree_indirect(current_head->object.oid.hash); + tree = parse_tree_indirect(¤t_head->object.oid); if (!tree) die(_("failed to unpack HEAD tree object")); parse_tree(tree); @@ -1434,7 +1434,7 @@ static void print_summary(const char *prefix, const struct object_id *oid, struct strbuf author_ident = STRBUF_INIT; struct strbuf committer_ident = STRBUF_INIT; - commit = lookup_commit(oid->hash); + commit = lookup_commit(oid); if (!commit) die(_("couldn't look up newly created commit")); if (parse_commit(commit)) @@ -1658,7 +1658,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) if (get_sha1("HEAD", oid.hash)) current_head = NULL; else { - current_head = lookup_commit_or_die(oid.hash, "HEAD"); + current_head = lookup_commit_or_die(&oid, "HEAD"); if (parse_commit(current_head)) die(_("could not parse HEAD commit")); } @@ -1762,7 +1762,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) append_merge_tag_headers(parents, &tail); } - if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->sha1, + if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->oid.hash, parents, oid.hash, author_ident.buf, sign_commit, extra)) { rollback_index_files(); die(_("failed to write commit object")); diff --git a/builtin/describe.c b/builtin/describe.c index a5cd8c513f..893c8789f4 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -79,13 +79,13 @@ static int replace_name(struct commit_name *e, struct tag *t; if (!e->tag) { - t = lookup_tag(e->oid.hash); + t = lookup_tag(&e->oid); if (!t || parse_tag(t)) return 1; e->tag = t; } - t = lookup_tag(oid->hash); + t = lookup_tag(oid); if (!t || parse_tag(t)) return 0; *tag = t; @@ -245,7 +245,7 @@ static unsigned long finish_depth_computation( static void display_name(struct commit_name *n) { if (n->prio == 2 && !n->tag) { - n->tag = lookup_tag(n->oid.hash); + n->tag = lookup_tag(&n->oid); if (!n->tag || parse_tag(n->tag)) die(_("annotated tag %s not available"), n->path); } @@ -281,7 +281,7 @@ static void describe(const char *arg, int last_one) if (get_oid(arg, &oid)) die(_("Not a valid object name %s"), arg); - cmit = lookup_commit_reference(oid.hash); + cmit = lookup_commit_reference(&oid); if (!cmit) die(_("%s is not a valid '%s' object"), arg, commit_type); @@ -309,7 +309,7 @@ static void describe(const char *arg, int last_one) struct commit *c; struct commit_name *n = hashmap_iter_first(&names, &iter); for (; n; n = hashmap_iter_next(&iter)) { - c = lookup_commit_reference_gently(n->peeled.hash, 1); + c = lookup_commit_reference_gently(&n->peeled, 1); if (c) c->util = n; } diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index 326f88b657..5ea1c14317 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -9,7 +9,7 @@ static struct rev_info log_tree_opt; static int diff_tree_commit_sha1(const struct object_id *oid) { - struct commit *commit = lookup_commit_reference(oid->hash); + struct commit *commit = lookup_commit_reference(oid); if (!commit) return -1; return log_tree_commit(&log_tree_opt, commit); @@ -23,7 +23,7 @@ static int stdin_diff_commit(struct commit *commit, const char *p) /* Graft the fake parents locally to the commit */ while (isspace(*p++) && !parse_oid_hex(p, &oid, &p)) { - struct commit *parent = lookup_commit(oid.hash); + struct commit *parent = lookup_commit(&oid); if (!pptr) { /* Free the real parent list */ free_commit_list(commit->parents); @@ -44,7 +44,7 @@ static int stdin_diff_trees(struct tree *tree1, const char *p) struct tree *tree2; if (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p) return error("Need exactly two trees, separated by a space"); - tree2 = lookup_tree(oid.hash); + tree2 = lookup_tree(&oid); if (!tree2 || parse_tree(tree2)) return -1; printf("%s %s\n", oid_to_hex(&tree1->object.oid), @@ -67,7 +67,7 @@ static int diff_tree_stdin(char *line) line[len-1] = 0; if (parse_oid_hex(line, &oid, &p)) return -1; - obj = parse_object(oid.hash); + obj = parse_object(&oid); if (!obj) return -1; if (obj->type == OBJ_COMMIT) diff --git a/builtin/diff.c b/builtin/diff.c index d184aafab9..8c03ddaf58 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -381,7 +381,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) add_head_to_pending(&rev); if (!rev.pending.nr) { struct tree *tree; - tree = lookup_tree(EMPTY_TREE_SHA1_BIN); + tree = lookup_tree(&empty_tree_oid); add_pending_object(&rev, &tree->object, "HEAD"); } break; @@ -395,7 +395,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) const char *name = entry->name; int flags = (obj->flags & UNINTERESTING); if (!obj->parsed) - obj = parse_object(obj->oid.hash); + obj = parse_object(&obj->oid); obj = deref_tag(obj, NULL, 0); if (!obj) die(_("invalid object '%s' given."), name); @@ -408,7 +408,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix) } else if (obj->type == OBJ_BLOB) { if (2 <= blobs) die(_("more than two blobs given: '%s'"), name); - hashcpy(blob[blobs].oid.hash, obj->oid.hash); + oidcpy(&blob[blobs].oid, &obj->oid); blob[blobs].name = name; blob[blobs].mode = entry->mode; blobs++; diff --git a/builtin/fast-export.c b/builtin/fast-export.c index e0220630d0..969550531b 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -232,7 +232,7 @@ static void export_blob(const struct object_id *oid) if (anonymize) { buf = anonymize_blob(&size); - object = (struct object *)lookup_blob(oid->hash); + object = (struct object *)lookup_blob(oid); eaten = 0; } else { buf = read_sha1_file(oid->hash, &type, &size); @@ -240,7 +240,7 @@ static void export_blob(const struct object_id *oid) die ("Could not read blob %s", oid_to_hex(oid)); if (check_sha1_signature(oid->hash, buf, size, typename(type)) < 0) die("sha1 mismatch in blob %s", oid_to_hex(oid)); - object = parse_object_buffer(oid->hash, type, size, buf, &eaten); + object = parse_object_buffer(oid, type, size, buf, &eaten); } if (!object) @@ -777,7 +777,7 @@ static struct commit *get_commit(struct rev_cmdline_entry *e, char *full_name) /* handle nested tags */ while (tag && tag->object.type == OBJ_TAG) { - parse_object(tag->object.oid.hash); + parse_object(&tag->object.oid); string_list_append(&extra_refs, full_name)->util = tag; tag = (struct tag *)tag->tagged; } @@ -938,7 +938,7 @@ static void import_marks(char *input_file) /* only commits */ continue; - commit = lookup_commit(oid.hash); + commit = lookup_commit(&oid); if (!commit) die("not a commit? can't happen: %s", oid_to_hex(&oid)); diff --git a/builtin/fetch.c b/builtin/fetch.c index 5f2c2ab23e..d4d573b985 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -636,8 +636,8 @@ static int update_local_ref(struct ref *ref, return r; } - current = lookup_commit_reference_gently(ref->old_oid.hash, 1); - updated = lookup_commit_reference_gently(ref->new_oid.hash, 1); + current = lookup_commit_reference_gently(&ref->old_oid, 1); + updated = lookup_commit_reference_gently(&ref->new_oid, 1); if (!current || !updated) { const char *msg; const char *what; @@ -770,7 +770,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, continue; } - commit = lookup_commit_reference_gently(rm->old_oid.hash, 1); + commit = lookup_commit_reference_gently(&rm->old_oid, + 1); if (!commit) rm->fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE; diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index 6faa3c0d24..70137b0b7e 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -341,7 +341,7 @@ static void shortlog(const char *name, const struct object_id *oid = &origin_data->oid; int limit = opts->shortlog_len; - branch = deref_tag(parse_object(oid->hash), oid_to_hex(oid), GIT_SHA1_HEXSZ); + branch = deref_tag(parse_object(oid), oid_to_hex(oid), GIT_SHA1_HEXSZ); if (!branch || branch->type != OBJ_COMMIT) return; @@ -559,14 +559,14 @@ static void find_merge_parents(struct merge_parents *result, * "name" here and we do not want to contaminate its * util field yet. */ - obj = parse_object(oid.hash); + obj = parse_object(&oid); parent = (struct commit *)peel_to_type(NULL, 0, obj, OBJ_COMMIT); if (!parent) continue; commit_list_insert(parent, &parents); add_merge_parent(result, &obj->oid, &parent->object.oid); } - head_commit = lookup_commit(head->hash); + head_commit = lookup_commit(head); if (head_commit) commit_list_insert(head_commit, &parents); parents = reduce_heads(parents); @@ -633,7 +633,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out, struct commit *head; struct rev_info rev; - head = lookup_commit_or_die(head_oid.hash, "HEAD"); + head = lookup_commit_or_die(&head_oid, "HEAD"); init_revisions(&rev, NULL); rev.commit_format = CMIT_FMT_ONELINE; rev.ignore_merges = 1; diff --git a/builtin/fsck.c b/builtin/fsck.c index 32a32e55c8..cb2ba6cd1b 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -377,7 +377,7 @@ static int fsck_obj(struct object *obj) return 0; } -static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type, +static int fsck_obj_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten) { /* @@ -385,10 +385,10 @@ static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type, * verify_packfile(), data_valid variable for details. */ struct object *obj; - obj = parse_object_buffer(sha1, type, size, buffer, eaten); + obj = parse_object_buffer(oid, type, size, buffer, eaten); if (!obj) { errors_found |= ERROR_OBJECT; - return error("%s: object corrupt or missing", sha1_to_hex(sha1)); + return error("%s: object corrupt or missing", oid_to_hex(oid)); } obj->flags = HAS_OBJ; return fsck_obj(obj); @@ -444,7 +444,7 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid, { struct object *obj; - obj = parse_object(oid->hash); + obj = parse_object(oid); if (!obj) { error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid)); errors_found |= ERROR_REACHABLE; @@ -506,7 +506,7 @@ static struct object *parse_loose_object(const struct object_id *oid, if (!contents && type != OBJ_BLOB) die("BUG: read_loose_object streamed a non-blob"); - obj = parse_object_buffer(oid->hash, type, size, contents, &eaten); + obj = parse_object_buffer(oid, type, size, contents, &eaten); if (!eaten) free(contents); @@ -599,10 +599,10 @@ static int fsck_cache_tree(struct cache_tree *it) fprintf(stderr, "Checking cache tree\n"); if (0 <= it->entry_count) { - struct object *obj = parse_object(it->sha1); + struct object *obj = parse_object(&it->oid); if (!obj) { error("%s: invalid sha1 pointer in cache-tree", - sha1_to_hex(it->sha1)); + oid_to_hex(&it->oid)); errors_found |= ERROR_REFS; return 1; } @@ -781,7 +781,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) mode = active_cache[i]->ce_mode; if (S_ISGITLINK(mode)) continue; - blob = lookup_blob(active_cache[i]->oid.hash); + blob = lookup_blob(&active_cache[i]->oid); if (!blob) continue; obj = &blob->object; diff --git a/builtin/grep.c b/builtin/grep.c index f2829629b6..c6c26e9b9e 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -1196,7 +1196,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix) break; } - object = parse_object_or_die(oid.hash, arg); + object = parse_object_or_die(&oid, arg); if (!seen_dashdash) verify_non_filename(prefix, arg); add_object_array_with_path(object, arg, &list, oc.mode, oc.path); diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 4ff567db47..04b9dcaf0f 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -747,13 +747,13 @@ static int compare_objects(const unsigned char *buf, unsigned long size, ssize_t len = read_istream(data->st, data->buf, size); if (len == 0) die(_("SHA1 COLLISION FOUND WITH %s !"), - sha1_to_hex(data->entry->idx.sha1)); + oid_to_hex(&data->entry->idx.oid)); if (len < 0) die(_("unable to read %s"), - sha1_to_hex(data->entry->idx.sha1)); + oid_to_hex(&data->entry->idx.oid)); if (memcmp(buf, data->buf, len)) die(_("SHA1 COLLISION FOUND WITH %s !"), - sha1_to_hex(data->entry->idx.sha1)); + oid_to_hex(&data->entry->idx.oid)); size -= len; buf += len; } @@ -771,12 +771,12 @@ static int check_collison(struct object_entry *entry) memset(&data, 0, sizeof(data)); data.entry = entry; - data.st = open_istream(entry->idx.sha1, &type, &size, NULL); + data.st = open_istream(entry->idx.oid.hash, &type, &size, NULL); if (!data.st) return -1; if (size != entry->size || type != entry->type) die(_("SHA1 COLLISION FOUND WITH %s !"), - sha1_to_hex(entry->idx.sha1)); + oid_to_hex(&entry->idx.oid)); unpack_data(entry, compare_objects, &data); close_istream(data.st); free(data.buf); @@ -785,7 +785,7 @@ static int check_collison(struct object_entry *entry) static void sha1_object(const void *data, struct object_entry *obj_entry, unsigned long size, enum object_type type, - const unsigned char *sha1) + const struct object_id *oid) { void *new_data = NULL; int collision_test_needed = 0; @@ -794,7 +794,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry, if (startup_info->have_repository) { read_lock(); - collision_test_needed = has_sha1_file_with_flags(sha1, HAS_SHA1_QUICK); + collision_test_needed = has_sha1_file_with_flags(oid->hash, HAS_SHA1_QUICK); read_unlock(); } @@ -809,31 +809,31 @@ static void sha1_object(const void *data, struct object_entry *obj_entry, enum object_type has_type; unsigned long has_size; read_lock(); - has_type = sha1_object_info(sha1, &has_size); + has_type = sha1_object_info(oid->hash, &has_size); if (has_type < 0) - die(_("cannot read existing object info %s"), sha1_to_hex(sha1)); + die(_("cannot read existing object info %s"), oid_to_hex(oid)); if (has_type != type || has_size != size) - die(_("SHA1 COLLISION FOUND WITH %s !"), sha1_to_hex(sha1)); - has_data = read_sha1_file(sha1, &has_type, &has_size); + die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid)); + has_data = read_sha1_file(oid->hash, &has_type, &has_size); read_unlock(); if (!data) data = new_data = get_data_from_pack(obj_entry); if (!has_data) - die(_("cannot read existing object %s"), sha1_to_hex(sha1)); + die(_("cannot read existing object %s"), oid_to_hex(oid)); if (size != has_size || type != has_type || memcmp(data, has_data, size) != 0) - die(_("SHA1 COLLISION FOUND WITH %s !"), sha1_to_hex(sha1)); + die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid)); free(has_data); } if (strict) { read_lock(); if (type == OBJ_BLOB) { - struct blob *blob = lookup_blob(sha1); + struct blob *blob = lookup_blob(oid); if (blob) blob->object.flags |= FLAG_CHECKED; else - die(_("invalid blob object %s"), sha1_to_hex(sha1)); + die(_("invalid blob object %s"), oid_to_hex(oid)); } else { struct object *obj; int eaten; @@ -845,7 +845,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry, * we do not need to free the memory here, as the * buf is deleted by the caller. */ - obj = parse_object_buffer(sha1, type, size, buf, &eaten); + obj = parse_object_buffer(oid, type, size, buf, + &eaten); if (!obj) die(_("invalid %s"), typename(type)); if (do_fsck_object && @@ -957,9 +958,10 @@ static void resolve_delta(struct object_entry *delta_obj, if (!result->data) bad_object(delta_obj->idx.offset, _("failed to apply delta")); hash_sha1_file(result->data, result->size, - typename(delta_obj->real_type), delta_obj->idx.sha1); + typename(delta_obj->real_type), + delta_obj->idx.oid.hash); sha1_object(result->data, NULL, result->size, delta_obj->real_type, - delta_obj->idx.sha1); + &delta_obj->idx.oid); counter_lock(); nr_resolved_deltas++; counter_unlock(); @@ -989,7 +991,7 @@ static struct base_data *find_unresolved_deltas_1(struct base_data *base, struct base_data *prev_base) { if (base->ref_last == -1 && base->ofs_last == -1) { - find_ref_delta_children(base->obj->idx.sha1, + find_ref_delta_children(base->obj->idx.oid.hash, &base->ref_first, &base->ref_last, OBJ_REF_DELTA); @@ -1130,7 +1132,8 @@ static void parse_pack_objects(unsigned char *sha1) for (i = 0; i < nr_objects; i++) { struct object_entry *obj = &objects[i]; void *data = unpack_raw_entry(obj, &ofs_delta->offset, - ref_delta_sha1, obj->idx.sha1); + ref_delta_sha1, + obj->idx.oid.hash); obj->real_type = obj->type; if (obj->type == OBJ_OFS_DELTA) { nr_ofs_deltas++; @@ -1146,7 +1149,8 @@ static void parse_pack_objects(unsigned char *sha1) obj->real_type = OBJ_BAD; nr_delays++; } else - sha1_object(data, NULL, obj->size, obj->type, obj->idx.sha1); + sha1_object(data, NULL, obj->size, obj->type, + &obj->idx.oid); free(data); display_progress(progress, i+1); } @@ -1172,7 +1176,8 @@ static void parse_pack_objects(unsigned char *sha1) if (obj->real_type != OBJ_BAD) continue; obj->real_type = obj->type; - sha1_object(NULL, obj, obj->size, obj->type, obj->idx.sha1); + sha1_object(NULL, obj, obj->size, obj->type, + &obj->idx.oid); nr_delays--; } if (nr_delays) @@ -1330,7 +1335,7 @@ static struct object_entry *append_obj_to_pack(struct sha1file *f, obj[1].idx.offset += write_compressed(f, buf, size); obj[0].idx.crc32 = crc32_end(f); sha1flush(f); - hashcpy(obj->idx.sha1, sha1); + hashcpy(obj->idx.oid.hash, sha1); return obj; } @@ -1581,13 +1586,14 @@ static void show_pack_info(int stat_only) if (stat_only) continue; printf("%s %-6s %lu %lu %"PRIuMAX, - sha1_to_hex(obj->idx.sha1), + oid_to_hex(&obj->idx.oid), typename(obj->real_type), obj->size, (unsigned long)(obj[1].idx.offset - obj->idx.offset), (uintmax_t)obj->idx.offset); if (is_delta_type(obj->type)) { struct object_entry *bobj = &objects[obj_stat[i].base_object_no]; - printf(" %u %s", obj_stat[i].delta_depth, sha1_to_hex(bobj->idx.sha1)); + printf(" %u %s", obj_stat[i].delta_depth, + oid_to_hex(&bobj->idx.oid)); } putchar('\n'); } diff --git a/builtin/log.c b/builtin/log.c index 631fbc984f..a440601efe 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -596,7 +596,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) rev.shown_one = 1; if (ret) break; - o = parse_object(t->tagged->oid.hash); + o = parse_object(&t->tagged->oid); if (!o) ret = error(_("Could not read object %s"), oid_to_hex(&t->tagged->oid)); @@ -878,8 +878,8 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids) o2 = rev->pending.objects[1].item; flags1 = o1->flags; flags2 = o2->flags; - c1 = lookup_commit_reference(o1->oid.hash); - c2 = lookup_commit_reference(o2->oid.hash); + c1 = lookup_commit_reference(&o1->oid); + c2 = lookup_commit_reference(&o2->oid); if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING)) die(_("Not a range.")); @@ -1263,7 +1263,7 @@ static struct commit *get_base_commit(const char *base_commit, if (get_oid(upstream, &oid)) die(_("Failed to resolve '%s' as a valid ref."), upstream); - commit = lookup_commit_or_die(oid.hash, "upstream base"); + commit = lookup_commit_or_die(&oid, "upstream base"); base_list = get_merge_bases_many(commit, total, list); /* There should be one and only one merge base. */ if (!base_list || base_list->next) @@ -1819,7 +1819,7 @@ static int add_pending_commit(const char *arg, struct rev_info *revs, int flags) { struct object_id oid; if (get_oid(arg, &oid) == 0) { - struct commit *commit = lookup_commit_reference(oid.hash); + struct commit *commit = lookup_commit_reference(&oid); if (commit) { commit->object.flags |= flags; add_pending_object(revs, &commit->object, arg); diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 61271b52cf..530e6ae7f7 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -414,14 +414,14 @@ static void prune_cache(const char *prefix, size_t prefixlen) void overlay_tree_on_cache(const char *tree_name, const char *prefix) { struct tree *tree; - unsigned char sha1[20]; + struct object_id oid; struct pathspec pathspec; struct cache_entry *last_stage0 = NULL; int i; - if (get_sha1(tree_name, sha1)) + if (get_oid(tree_name, &oid)) die("tree-ish %s not found.", tree_name); - tree = parse_tree_indirect(sha1); + tree = parse_tree_indirect(&oid); if (!tree) die("bad tree-ish %s", tree_name); diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index d7ebeb4ce6..ee7b293b11 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -119,7 +119,7 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base, int cmd_ls_tree(int argc, const char **argv, const char *prefix) { - unsigned char sha1[20]; + struct object_id oid; struct tree *tree; int i, full_tree = 0; const struct option ls_tree_options[] = { @@ -164,7 +164,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) if (argc < 1) usage_with_options(ls_tree_usage, ls_tree_options); - if (get_sha1(argv[0], sha1)) + if (get_oid(argv[0], &oid)) die("Not a valid object name %s", argv[0]); /* @@ -180,7 +180,7 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) for (i = 0; i < pathspec.nr; i++) pathspec.items[i].nowildcard_len = pathspec.items[i].len; pathspec.has_wildcard = 0; - tree = parse_tree_indirect(sha1); + tree = parse_tree_indirect(&oid); if (!tree) die("not a tree object"); return !!read_tree_recursive(tree, "", 0, 0, &pathspec, show_tree, NULL); diff --git a/builtin/merge-base.c b/builtin/merge-base.c index 8ed96391c1..0c36a70ad8 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -41,7 +41,7 @@ static struct commit *get_commit_reference(const char *arg) if (get_oid(arg, &revkey)) die("Not a valid object name %s", arg); - r = lookup_commit_reference(revkey.hash); + r = lookup_commit_reference(&revkey); if (!r) die("Not a valid commit name %s", arg); @@ -120,7 +120,7 @@ static void add_one_commit(struct object_id *oid, struct rev_collect *revs) if (is_null_oid(oid)) return; - commit = lookup_commit(oid->hash); + commit = lookup_commit(oid); if (!commit || (commit->object.flags & TMP_MARK) || parse_commit(commit)) @@ -168,7 +168,7 @@ static int handle_fork_point(int argc, const char **argv) if (get_oid(commitname, &oid)) die("Not a valid object name: '%s'", commitname); - derived = lookup_commit_reference(oid.hash); + derived = lookup_commit_reference(&oid); memset(&revs, 0, sizeof(revs)); revs.initial = 1; for_each_reflog_ent(refname, collect_one_reflog_ent, &revs); diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 5b7ab9b967..bad6735c76 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -161,14 +161,14 @@ static int both_empty(struct name_entry *a, struct name_entry *b) return !(a->oid || b->oid); } -static struct merge_list *create_entry(unsigned stage, unsigned mode, const unsigned char *sha1, const char *path) +static struct merge_list *create_entry(unsigned stage, unsigned mode, const struct object_id *oid, const char *path) { struct merge_list *res = xcalloc(1, sizeof(*res)); res->stage = stage; res->path = path; res->mode = mode; - res->blob = lookup_blob(sha1); + res->blob = lookup_blob(oid); return res; } @@ -188,8 +188,8 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s return; path = traverse_path(info, result); - orig = create_entry(2, ours->mode, ours->oid->hash, path); - final = create_entry(0, result->mode, result->oid->hash, path); + orig = create_entry(2, ours->mode, ours->oid, path); + final = create_entry(0, result->mode, result->oid, path); final->link = orig; @@ -239,7 +239,7 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info path = entry->path; else path = traverse_path(info, n); - link = create_entry(stage, n->mode, n->oid->hash, path); + link = create_entry(stage, n->mode, n->oid, path); link->link = entry; return link; } diff --git a/builtin/merge.c b/builtin/merge.c index 703827f006..a4a098f40f 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -605,13 +605,13 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head, opts.verbose_update = 1; opts.trivial_merges_only = 1; opts.merge = 1; - trees[nr_trees] = parse_tree_indirect(common->hash); + trees[nr_trees] = parse_tree_indirect(common); if (!trees[nr_trees++]) return -1; - trees[nr_trees] = parse_tree_indirect(head->hash); + trees[nr_trees] = parse_tree_indirect(head); if (!trees[nr_trees++]) return -1; - trees[nr_trees] = parse_tree_indirect(one->hash); + trees[nr_trees] = parse_tree_indirect(one); if (!trees[nr_trees++]) return -1; opts.fn = threeway_merge; @@ -1123,7 +1123,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) if (!branch || is_null_oid(&head_oid)) head_commit = NULL; else - head_commit = lookup_commit_or_die(head_oid.hash, "HEAD"); + head_commit = lookup_commit_or_die(&head_oid, "HEAD"); init_diff_ui_defaults(); git_config(git_merge_config, NULL); @@ -1372,8 +1372,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix) goto done; } - if (checkout_fast_forward(head_commit->object.oid.hash, - commit->object.oid.hash, + if (checkout_fast_forward(&head_commit->object.oid, + &commit->object.oid, overwrite_ignore)) { ret = 1; goto done; diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 4437475017..1bf4cc4ebb 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -114,7 +114,7 @@ struct name_ref_data { static struct tip_table { struct tip_table_entry { - unsigned char sha1[20]; + struct object_id oid; const char *refname; } *table; int nr; @@ -122,13 +122,13 @@ static struct tip_table { int sorted; } tip_table; -static void add_to_tip_table(const unsigned char *sha1, const char *refname, +static void add_to_tip_table(const struct object_id *oid, const char *refname, int shorten_unambiguous) { refname = name_ref_abbrev(refname, shorten_unambiguous); ALLOC_GROW(tip_table.table, tip_table.nr + 1, tip_table.alloc); - hashcpy(tip_table.table[tip_table.nr].sha1, sha1); + oidcpy(&tip_table.table[tip_table.nr].oid, oid); tip_table.table[tip_table.nr].refname = xstrdup(refname); tip_table.nr++; tip_table.sorted = 0; @@ -137,12 +137,12 @@ static void add_to_tip_table(const unsigned char *sha1, const char *refname, static int tipcmp(const void *a_, const void *b_) { const struct tip_table_entry *a = a_, *b = b_; - return hashcmp(a->sha1, b->sha1); + return oidcmp(&a->oid, &b->oid); } static int name_ref(const char *path, const struct object_id *oid, int flags, void *cb_data) { - struct object *o = parse_object(oid->hash); + struct object *o = parse_object(oid); struct name_ref_data *data = cb_data; int can_abbreviate_output = data->tags_only && data->name_only; int deref = 0; @@ -194,13 +194,13 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo return 0; } - add_to_tip_table(oid->hash, path, can_abbreviate_output); + add_to_tip_table(oid, path, can_abbreviate_output); while (o && o->type == OBJ_TAG) { struct tag *t = (struct tag *) o; if (!t->tagged) break; /* broken repository */ - o = parse_object(t->tagged->oid.hash); + o = parse_object(&t->tagged->oid); deref = 1; taggerdate = t->date; } @@ -216,7 +216,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo static const unsigned char *nth_tip_table_ent(size_t ix, void *table_) { struct tip_table_entry *table = table_; - return table[ix].sha1; + return table[ix].oid.hash; } static const char *get_exact_ref_match(const struct object *o) @@ -301,9 +301,9 @@ static void name_rev_line(char *p, struct name_ref_data *data) #define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f')) if (!ishex(*p)) forty = 0; - else if (++forty == 40 && + else if (++forty == GIT_SHA1_HEXSZ && !ishex(*(p+1))) { - unsigned char sha1[40]; + struct object_id oid; const char *name = NULL; char c = *(p+1); int p_len = p - p_start + 1; @@ -311,9 +311,9 @@ static void name_rev_line(char *p, struct name_ref_data *data) forty = 0; *(p+1) = 0; - if (!get_sha1(p - 39, sha1)) { + if (!get_oid(p - (GIT_SHA1_HEXSZ - 1), &oid)) { struct object *o = - lookup_object(sha1); + lookup_object(oid.hash); if (o) name = get_rev_name(o, &buf); } @@ -323,7 +323,7 @@ static void name_rev_line(char *p, struct name_ref_data *data) continue; if (data->name_only) - printf("%.*s%s", p_len - 40, p_start, name); + printf("%.*s%s", p_len - GIT_SHA1_HEXSZ, p_start, name); else printf("%.*s (%s)", p_len, p_start, name); p_start = p + 1; @@ -374,18 +374,18 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) cutoff = 0; for (; argc; argc--, argv++) { - unsigned char sha1[20]; + struct object_id oid; struct object *object; struct commit *commit; - if (get_sha1(*argv, sha1)) { + if (get_oid(*argv, &oid)) { fprintf(stderr, "Could not get sha1 for %s. Skipping.\n", *argv); continue; } commit = NULL; - object = parse_object(sha1); + object = parse_object(&oid); if (object) { struct object *peeled = deref_tag(object, *argv, 0); if (peeled && peeled->type == OBJ_COMMIT) diff --git a/builtin/notes.c b/builtin/notes.c index 7b891471c4..f2847c41e0 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -706,7 +706,7 @@ static int merge_commit(struct notes_merge_options *o) if (get_oid("NOTES_MERGE_PARTIAL", &oid)) die(_("failed to read ref NOTES_MERGE_PARTIAL")); - else if (!(partial = lookup_commit_reference(oid.hash))) + else if (!(partial = lookup_commit_reference(&oid))) die(_("could not find commit from NOTES_MERGE_PARTIAL.")); else if (parse_commit(partial)) die(_("could not parse commit from NOTES_MERGE_PARTIAL.")); diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 9b4ba8a80d..82555e410a 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -106,12 +106,14 @@ static void *get_delta(struct object_entry *entry) void *buf, *base_buf, *delta_buf; enum object_type type; - buf = read_sha1_file(entry->idx.sha1, &type, &size); + buf = read_sha1_file(entry->idx.oid.hash, &type, &size); if (!buf) - die("unable to read %s", sha1_to_hex(entry->idx.sha1)); - base_buf = read_sha1_file(entry->delta->idx.sha1, &type, &base_size); + die("unable to read %s", oid_to_hex(&entry->idx.oid)); + base_buf = read_sha1_file(entry->delta->idx.oid.hash, &type, + &base_size); if (!base_buf) - die("unable to read %s", sha1_to_hex(entry->delta->idx.sha1)); + die("unable to read %s", + oid_to_hex(&entry->delta->idx.oid)); delta_buf = diff_delta(base_buf, base_size, buf, size, &delta_size, 0); if (!delta_buf || delta_size != entry->delta_size) @@ -249,12 +251,14 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent if (!usable_delta) { if (entry->type == OBJ_BLOB && entry->size > big_file_threshold && - (st = open_istream(entry->idx.sha1, &type, &size, NULL)) != NULL) + (st = open_istream(entry->idx.oid.hash, &type, &size, NULL)) != NULL) buf = NULL; else { - buf = read_sha1_file(entry->idx.sha1, &type, &size); + buf = read_sha1_file(entry->idx.oid.hash, &type, + &size); if (!buf) - die(_("unable to read %s"), sha1_to_hex(entry->idx.sha1)); + die(_("unable to read %s"), + oid_to_hex(&entry->idx.oid)); } /* * make sure no cached delta data remains from a @@ -322,7 +326,7 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent return 0; } sha1write(f, header, hdrlen); - sha1write(f, entry->delta->idx.sha1, 20); + sha1write(f, entry->delta->idx.oid.hash, 20); hdrlen += 20; } else { if (limit && hdrlen + datalen + 20 >= limit) { @@ -334,7 +338,7 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent sha1write(f, header, hdrlen); } if (st) { - datalen = write_large_blob_data(st, f, entry->idx.sha1); + datalen = write_large_blob_data(st, f, entry->idx.oid.hash); close_istream(st); } else { sha1write(f, buf, datalen); @@ -369,7 +373,8 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry, datalen = revidx[1].offset - offset; if (!pack_to_stdout && p->index_version > 1 && check_pack_crc(p, &w_curs, offset, datalen, revidx->nr)) { - error("bad packed object CRC for %s", sha1_to_hex(entry->idx.sha1)); + error("bad packed object CRC for %s", + oid_to_hex(&entry->idx.oid)); unuse_pack(&w_curs); return write_no_reuse_object(f, entry, limit, usable_delta); } @@ -379,7 +384,8 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry, if (!pack_to_stdout && p->index_version == 1 && check_pack_inflate(p, &w_curs, offset, datalen, entry->size)) { - error("corrupt packed object for %s", sha1_to_hex(entry->idx.sha1)); + error("corrupt packed object for %s", + oid_to_hex(&entry->idx.oid)); unuse_pack(&w_curs); return write_no_reuse_object(f, entry, limit, usable_delta); } @@ -404,7 +410,7 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry, return 0; } sha1write(f, header, hdrlen); - sha1write(f, entry->delta->idx.sha1, 20); + sha1write(f, entry->delta->idx.oid.hash, 20); hdrlen += 20; reused_delta++; } else { @@ -509,7 +515,7 @@ static enum write_one_status write_one(struct sha1file *f, recursing = (e->idx.offset == 1); if (recursing) { warning("recursive delta detected for object %s", - sha1_to_hex(e->idx.sha1)); + oid_to_hex(&e->idx.oid)); return WRITE_ONE_RECURSIVE; } else if (e->idx.offset || e->preferred_base) { /* offset is non zero if object is written already. */ @@ -1432,7 +1438,7 @@ static void check_object(struct object_entry *entry) ofs += 1; if (!ofs || MSB(ofs, 7)) { error("delta base offset overflow in pack for %s", - sha1_to_hex(entry->idx.sha1)); + oid_to_hex(&entry->idx.oid)); goto give_up; } c = buf[used_0++]; @@ -1441,7 +1447,7 @@ static void check_object(struct object_entry *entry) ofs = entry->in_pack_offset - ofs; if (ofs <= 0 || ofs >= entry->in_pack_offset) { error("delta base offset out of bound for %s", - sha1_to_hex(entry->idx.sha1)); + oid_to_hex(&entry->idx.oid)); goto give_up; } if (reuse_delta && !entry->preferred_base) { @@ -1498,7 +1504,7 @@ static void check_object(struct object_entry *entry) unuse_pack(&w_curs); } - entry->type = sha1_object_info(entry->idx.sha1, &entry->size); + entry->type = sha1_object_info(entry->idx.oid.hash, &entry->size); /* * The error condition is checked in prepare_pack(). This is * to permit a missing preferred base object to be ignored @@ -1514,7 +1520,7 @@ static int pack_offset_sort(const void *_a, const void *_b) /* avoid filesystem trashing with loose objects */ if (!a->in_pack && !b->in_pack) - return hashcmp(a->idx.sha1, b->idx.sha1); + return oidcmp(&a->idx.oid, &b->idx.oid); if (a->in_pack < b->in_pack) return -1; @@ -1560,7 +1566,8 @@ static void drop_reused_delta(struct object_entry *entry) * And if that fails, the error will be recorded in entry->type * and dealt with in prepare_pack(). */ - entry->type = sha1_object_info(entry->idx.sha1, &entry->size); + entry->type = sha1_object_info(entry->idx.oid.hash, + &entry->size); } } @@ -1852,26 +1859,29 @@ static int try_delta(struct unpacked *trg, struct unpacked *src, /* Load data if not already done */ if (!trg->data) { read_lock(); - trg->data = read_sha1_file(trg_entry->idx.sha1, &type, &sz); + trg->data = read_sha1_file(trg_entry->idx.oid.hash, &type, + &sz); read_unlock(); if (!trg->data) die("object %s cannot be read", - sha1_to_hex(trg_entry->idx.sha1)); + oid_to_hex(&trg_entry->idx.oid)); if (sz != trg_size) die("object %s inconsistent object length (%lu vs %lu)", - sha1_to_hex(trg_entry->idx.sha1), sz, trg_size); + oid_to_hex(&trg_entry->idx.oid), sz, + trg_size); *mem_usage += sz; } if (!src->data) { read_lock(); - src->data = read_sha1_file(src_entry->idx.sha1, &type, &sz); + src->data = read_sha1_file(src_entry->idx.oid.hash, &type, + &sz); read_unlock(); if (!src->data) { if (src_entry->preferred_base) { static int warned = 0; if (!warned++) warning("object %s cannot be read", - sha1_to_hex(src_entry->idx.sha1)); + oid_to_hex(&src_entry->idx.oid)); /* * Those objects are not included in the * resulting pack. Be resilient and ignore @@ -1881,11 +1891,12 @@ static int try_delta(struct unpacked *trg, struct unpacked *src, return 0; } die("object %s cannot be read", - sha1_to_hex(src_entry->idx.sha1)); + oid_to_hex(&src_entry->idx.oid)); } if (sz != src_size) die("object %s inconsistent object length (%lu vs %lu)", - sha1_to_hex(src_entry->idx.sha1), sz, src_size); + oid_to_hex(&src_entry->idx.oid), sz, + src_size); *mem_usage += sz; } if (!src->index) { @@ -2337,7 +2348,7 @@ static void add_tag_chain(const struct object_id *oid) if (packlist_find(&to_pack, oid->hash, NULL)) return; - tag = lookup_tag(oid->hash); + tag = lookup_tag(oid); while (1) { if (!tag || parse_tag(tag) || !tag->tagged) die("unable to pack objects reachable from tag %s", @@ -2406,7 +2417,7 @@ static void prepare_pack(int window, int depth) nr_deltas++; if (entry->type < 0) die("unable to get type of object %s", - sha1_to_hex(entry->idx.sha1)); + oid_to_hex(&entry->idx.oid)); } else { if (entry->type < 0) { /* @@ -2777,10 +2788,10 @@ static void get_object_list(int ac, const char **av) continue; } if (starts_with(line, "--shallow ")) { - unsigned char sha1[20]; - if (get_sha1_hex(line + 10, sha1)) + struct object_id oid; + if (get_oid_hex(line + 10, &oid)) die("not an SHA-1 '%s'", line + 10); - register_shallow(sha1); + register_shallow(&oid); use_bitmap_index = 0; continue; } diff --git a/builtin/prune.c b/builtin/prune.c index 8dcfecde0f..f0e2bff04c 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -123,11 +123,12 @@ int cmd_prune(int argc, const char **argv, const char *prefix) die(_("cannot prune in a precious-objects repo")); while (argc--) { - unsigned char sha1[20]; + struct object_id oid; const char *name = *argv++; - if (!get_sha1(name, sha1)) { - struct object *object = parse_object_or_die(sha1, name); + if (!get_oid(name, &oid)) { + struct object *object = parse_object_or_die(&oid, + name); add_pending_object(&revs, object, ""); } else diff --git a/builtin/pull.c b/builtin/pull.c index dd1a4a94e4..318c273eb3 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -523,7 +523,7 @@ static int pull_into_void(const struct object_id *merge_head, * index/worktree changes that the user already made on the unborn * branch. */ - if (checkout_fast_forward(EMPTY_TREE_SHA1_BIN, merge_head->hash, 0)) + if (checkout_fast_forward(&empty_tree_oid, merge_head, 0)) return 1; if (update_ref("initial pull", "HEAD", merge_head->hash, curr_head->hash, 0, UPDATE_REFS_DIE_ON_ERR)) @@ -698,10 +698,10 @@ static int get_octopus_merge_base(struct object_id *merge_base, { struct commit_list *revs = NULL, *result; - commit_list_insert(lookup_commit_reference(curr_head->hash), &revs); - commit_list_insert(lookup_commit_reference(merge_head->hash), &revs); + commit_list_insert(lookup_commit_reference(curr_head), &revs); + commit_list_insert(lookup_commit_reference(merge_head), &revs); if (!is_null_oid(fork_point)) - commit_list_insert(lookup_commit_reference(fork_point->hash), &revs); + commit_list_insert(lookup_commit_reference(fork_point), &revs); result = reduce_heads(get_octopus_merge_bases(revs)); free_commit_list(revs); @@ -839,7 +839,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix) "fast-forwarding your working tree from\n" "commit %s."), oid_to_hex(&orig_head)); - if (checkout_fast_forward(orig_head.hash, curr_head.hash, 0)) + if (checkout_fast_forward(&orig_head, &curr_head, 0)) die(_("Cannot fast-forward your working tree.\n" "After making sure that you saved anything precious from\n" "$ git diff %s\n" @@ -865,9 +865,9 @@ int cmd_pull(int argc, const char **argv, const char *prefix) struct commit_list *list = NULL; struct commit *merge_head, *head; - head = lookup_commit_reference(orig_head.hash); + head = lookup_commit_reference(&orig_head); commit_list_insert(head, &list); - merge_head = lookup_commit_reference(merge_heads.oid[0].hash); + merge_head = lookup_commit_reference(&merge_heads.oid[0]); if (is_descendant_of(merge_head, list)) { /* we can fast-forward this without invoking rebase */ opt_ff = "--ff-only"; diff --git a/builtin/read-tree.c b/builtin/read-tree.c index 23e212ee8c..6d45175f6a 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -23,13 +23,13 @@ static int read_empty; static struct tree *trees[MAX_UNPACK_TREES]; static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT; -static int list_tree(unsigned char *sha1) +static int list_tree(struct object_id *oid) { struct tree *tree; if (nr_trees >= MAX_UNPACK_TREES) die("I cannot read more than %d trees", MAX_UNPACK_TREES); - tree = parse_tree_indirect(sha1); + tree = parse_tree_indirect(oid); if (!tree) return -1; trees[nr_trees++] = tree; @@ -121,7 +121,7 @@ static struct lock_file lock_file; int cmd_read_tree(int argc, const char **argv, const char *unused_prefix) { int i, stage = 0; - unsigned char sha1[20]; + struct object_id oid; struct tree_desc t[MAX_UNPACK_TREES]; struct unpack_trees_options opts; int prefix_set = 0; @@ -204,9 +204,9 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix) for (i = 0; i < argc; i++) { const char *arg = argv[i]; - if (get_sha1(arg, sha1)) + if (get_oid(arg, &oid)) die("Not a valid object name %s", arg); - if (list_tree(sha1) < 0) + if (list_tree(&oid) < 0) die("failed to unpack tree object %s", arg); stage++; } diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 1b29975c52..eb8b64bfce 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -900,7 +900,7 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si) * not lose these new roots.. */ for (i = 0; i < extra.nr; i++) - register_shallow(extra.oid[i].hash); + register_shallow(&extra.oid[i]); si->shallow_ref[cmd->index] = 0; oid_array_clear(&extra); @@ -1100,8 +1100,8 @@ static const char *update(struct command *cmd, struct shallow_info *si) struct object *old_object, *new_object; struct commit *old_commit, *new_commit; - old_object = parse_object(old_oid->hash); - new_object = parse_object(new_oid->hash); + old_object = parse_object(old_oid); + new_object = parse_object(new_oid); if (!old_object || !new_object || old_object->type != OBJ_COMMIT || @@ -1124,7 +1124,7 @@ static const char *update(struct command *cmd, struct shallow_info *si) if (is_null_oid(new_oid)) { struct strbuf err = STRBUF_INIT; - if (!parse_object(old_oid->hash)) { + if (!parse_object(old_oid)) { old_oid = NULL; if (ref_exists(name)) { rp_warning("Allowing deletion of corrupt ref."); diff --git a/builtin/reflog.c b/builtin/reflog.c index 4228d9ff4d..920c16dac0 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -55,14 +55,14 @@ struct collect_reflog_cb { #define STUDYING (1u<<11) #define REACHABLE (1u<<12) -static int tree_is_complete(const unsigned char *sha1) +static int tree_is_complete(const struct object_id *oid) { struct tree_desc desc; struct name_entry entry; int complete; struct tree *tree; - tree = lookup_tree(sha1); + tree = lookup_tree(oid); if (!tree) return 0; if (tree->object.flags & SEEN) @@ -73,7 +73,7 @@ static int tree_is_complete(const unsigned char *sha1) if (!tree->buffer) { enum object_type type; unsigned long size; - void *data = read_sha1_file(sha1, &type, &size); + void *data = read_sha1_file(oid->hash, &type, &size); if (!data) { tree->object.flags |= INCOMPLETE; return 0; @@ -85,7 +85,7 @@ static int tree_is_complete(const unsigned char *sha1) complete = 1; while (tree_entry(&desc, &entry)) { if (!has_sha1_file(entry.oid->hash) || - (S_ISDIR(entry.mode) && !tree_is_complete(entry.oid->hash))) { + (S_ISDIR(entry.mode) && !tree_is_complete(entry.oid))) { tree->object.flags |= INCOMPLETE; complete = 0; } @@ -126,7 +126,7 @@ static int commit_is_complete(struct commit *commit) struct commit_list *parent; c = (struct commit *)study.objects[--study.nr].item; - if (!c->object.parsed && !parse_object(c->object.oid.hash)) + if (!c->object.parsed && !parse_object(&c->object.oid)) c->object.flags |= INCOMPLETE; if (c->object.flags & INCOMPLETE) { @@ -152,7 +152,7 @@ static int commit_is_complete(struct commit *commit) for (i = 0; i < found.nr; i++) { struct commit *c = (struct commit *)found.objects[i].item; - if (!tree_is_complete(c->tree->object.oid.hash)) { + if (!tree_is_complete(&c->tree->object.oid)) { is_incomplete = 1; c->object.flags |= INCOMPLETE; } @@ -186,13 +186,13 @@ static int commit_is_complete(struct commit *commit) return !is_incomplete; } -static int keep_entry(struct commit **it, unsigned char *sha1) +static int keep_entry(struct commit **it, struct object_id *oid) { struct commit *commit; - if (is_null_sha1(sha1)) + if (is_null_oid(oid)) return 1; - commit = lookup_commit_reference_gently(sha1, 1); + commit = lookup_commit_reference_gently(oid, 1); if (!commit) return 0; @@ -251,17 +251,17 @@ static void mark_reachable(struct expire_reflog_policy_cb *cb) cb->mark_list = leftover; } -static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit, unsigned char *sha1) +static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit, struct object_id *oid) { /* * We may or may not have the commit yet - if not, look it * up using the supplied sha1. */ if (!commit) { - if (is_null_sha1(sha1)) + if (is_null_oid(oid)) return 0; - commit = lookup_commit_reference_gently(sha1, 1); + commit = lookup_commit_reference_gently(oid, 1); /* Not a commit -- keep it */ if (!commit) @@ -283,7 +283,7 @@ static int unreachable(struct expire_reflog_policy_cb *cb, struct commit *commit /* * Return true iff the specified reflog entry should be expired. */ -static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1, +static int should_expire_reflog_ent(struct object_id *ooid, struct object_id *noid, const char *email, timestamp_t timestamp, int tz, const char *message, void *cb_data) { @@ -295,13 +295,13 @@ static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1, old = new = NULL; if (cb->cmd.stalefix && - (!keep_entry(&old, osha1) || !keep_entry(&new, nsha1))) + (!keep_entry(&old, ooid) || !keep_entry(&new, noid))) return 1; if (timestamp < cb->cmd.expire_unreachable) { if (cb->unreachable_expire_kind == UE_ALWAYS) return 1; - if (unreachable(cb, old, osha1) || unreachable(cb, new, nsha1)) + if (unreachable(cb, old, ooid) || unreachable(cb, new, noid)) return 1; } @@ -318,7 +318,7 @@ static int push_tip_to_list(const char *refname, const struct object_id *oid, struct commit *tip_commit; if (flags & REF_ISSYMREF) return 0; - tip_commit = lookup_commit_reference_gently(oid->hash, 1); + tip_commit = lookup_commit_reference_gently(oid, 1); if (!tip_commit) return 0; commit_list_insert(tip_commit, list); @@ -326,7 +326,7 @@ static int push_tip_to_list(const char *refname, const struct object_id *oid, } static void reflog_expiry_prepare(const char *refname, - const unsigned char *sha1, + const struct object_id *oid, void *cb_data) { struct expire_reflog_policy_cb *cb = cb_data; @@ -335,7 +335,7 @@ static void reflog_expiry_prepare(const char *refname, cb->tip_commit = NULL; cb->unreachable_expire_kind = UE_HEAD; } else { - cb->tip_commit = lookup_commit_reference_gently(sha1, 1); + cb->tip_commit = lookup_commit_reference_gently(oid, 1); if (!cb->tip_commit) cb->unreachable_expire_kind = UE_ALWAYS; else diff --git a/builtin/replace.c b/builtin/replace.c index ab17668f43..c921bc976f 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -328,7 +328,7 @@ static void replace_parents(struct strbuf *buf, int argc, const char **argv) struct object_id oid; if (get_oid(argv[i], &oid) < 0) die(_("Not a valid object name: '%s'"), argv[i]); - lookup_commit_or_die(oid.hash, argv[i]); + lookup_commit_or_die(&oid, argv[i]); strbuf_addf(&new_parents, "parent %s\n", oid_to_hex(&oid)); } @@ -355,7 +355,7 @@ static void check_one_mergetag(struct commit *commit, int i; hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), tag_oid.hash); - tag = lookup_tag(tag_oid.hash); + tag = lookup_tag(&tag_oid); if (!tag) die(_("bad mergetag in commit '%s'"), ref); if (parse_tag_buffer(tag, extra->value, extra->len)) @@ -394,7 +394,7 @@ static int create_graft(int argc, const char **argv, int force) if (get_oid(old_ref, &old) < 0) die(_("Not a valid object name: '%s'"), old_ref); - commit = lookup_commit_or_die(old.hash, old_ref); + commit = lookup_commit_or_die(&old, old_ref); buffer = get_commit_buffer(commit, &size); strbuf_add(&buf, buffer, size); diff --git a/builtin/reset.c b/builtin/reset.c index 5ce27fcaed..0afe1df250 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -105,7 +105,7 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet) return -1; if (reset_type == MIXED || reset_type == HARD) { - tree = parse_tree_indirect(oid->hash); + tree = parse_tree_indirect(oid); prime_cache_tree(&the_index, tree); } @@ -175,7 +175,7 @@ static int read_from_tree(const struct pathspec *pathspec, opt.format_callback = update_index_from_diff; opt.format_callback_data = &intent_to_add; - if (do_diff_cache(tree_oid->hash, &opt)) + if (do_diff_cache(tree_oid, &opt)) return 1; diffcore_std(&opt); diff_flush(&opt); @@ -333,7 +333,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) struct commit *commit; if (get_sha1_committish(rev, oid.hash)) die(_("Failed to resolve '%s' as a valid revision."), rev); - commit = lookup_commit_reference(oid.hash); + commit = lookup_commit_reference(&oid); if (!commit) die(_("Could not parse object '%s'."), rev); oidcpy(&oid, &commit->object.oid); @@ -341,7 +341,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) struct tree *tree; if (get_sha1_treeish(rev, oid.hash)) die(_("Failed to resolve '%s' as a valid tree."), rev); - tree = parse_tree_indirect(oid.hash); + tree = parse_tree_indirect(&oid); if (!tree) die(_("Could not parse object '%s'."), rev); oidcpy(&oid, &tree->object.oid); @@ -410,7 +410,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) update_ref_status = reset_refs(rev, &oid); if (reset_type == HARD && !update_ref_status && !quiet) - print_new_head_line(lookup_commit_reference(oid.hash)); + print_new_head_line(lookup_commit_reference(&oid)); } if (!pathspec.nr) remove_branch_state(); diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 3b292c99bd..718c6059c9 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -181,7 +181,7 @@ static void finish_object(struct object *obj, const char *name, void *cb_data) 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(obj->oid.hash); + parse_object(&obj->oid); } static void show_object(struct object *obj, const char *name, void *cb_data) diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index b450900243..efdc14473b 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -121,7 +121,7 @@ static void show_with_type(int type, const char *arg) } /* Output a revision, only if filter allows it */ -static void show_rev(int type, const unsigned char *sha1, const char *name) +static void show_rev(int type, const struct object_id *oid, const char *name) { if (!(filter & DO_REVS)) return; @@ -129,10 +129,10 @@ static void show_rev(int type, const unsigned char *sha1, const char *name) if ((symbolic || abbrev_ref) && name) { if (symbolic == SHOW_SYMBOLIC_FULL || abbrev_ref) { - unsigned char discard[20]; + struct object_id discard; char *full; - switch (dwim_ref(name, strlen(name), discard, &full)) { + switch (dwim_ref(name, strlen(name), discard.hash, &full)) { case 0: /* * Not found -- not a ref. We could @@ -158,9 +158,9 @@ static void show_rev(int type, const unsigned char *sha1, const char *name) } } else if (abbrev) - show_with_type(type, find_unique_abbrev(sha1, abbrev)); + show_with_type(type, find_unique_abbrev(oid->hash, abbrev)); else - show_with_type(type, sha1_to_hex(sha1)); + show_with_type(type, oid_to_hex(oid)); } /* Output a flag, only if filter allows it. */ @@ -180,11 +180,11 @@ static int show_default(void) const char *s = def; if (s) { - unsigned char sha1[20]; + struct object_id oid; def = NULL; - if (!get_sha1(s, sha1)) { - show_rev(NORMAL, sha1, s); + if (!get_oid(s, &oid)) { + show_rev(NORMAL, &oid, s); return 1; } } @@ -195,19 +195,19 @@ static int show_reference(const char *refname, const struct object_id *oid, int { if (ref_excluded(ref_excludes, refname)) return 0; - show_rev(NORMAL, oid->hash, refname); + show_rev(NORMAL, oid, refname); return 0; } static int anti_reference(const char *refname, const struct object_id *oid, int flag, void *cb_data) { - show_rev(REVERSED, oid->hash, refname); + show_rev(REVERSED, oid, refname); return 0; } static int show_abbrev(const struct object_id *oid, void *cb_data) { - show_rev(NORMAL, oid->hash, NULL); + show_rev(NORMAL, oid, NULL); return 0; } @@ -242,8 +242,8 @@ static int show_file(const char *arg, int output_prefix) static int try_difference(const char *arg) { char *dotdot; - unsigned char sha1[20]; - unsigned char end[20]; + struct object_id oid; + struct object_id end; const char *next; const char *this; int symmetric; @@ -273,18 +273,18 @@ static int try_difference(const char *arg) return 0; } - if (!get_sha1_committish(this, sha1) && !get_sha1_committish(next, end)) { - show_rev(NORMAL, end, next); - show_rev(symmetric ? NORMAL : REVERSED, sha1, this); + if (!get_sha1_committish(this, oid.hash) && !get_sha1_committish(next, end.hash)) { + show_rev(NORMAL, &end, next); + show_rev(symmetric ? NORMAL : REVERSED, &oid, this); if (symmetric) { struct commit_list *exclude; struct commit *a, *b; - a = lookup_commit_reference(sha1); - b = lookup_commit_reference(end); + a = lookup_commit_reference(&oid); + b = lookup_commit_reference(&end); exclude = get_merge_bases(a, b); while (exclude) { struct commit *commit = pop_commit(&exclude); - show_rev(REVERSED, commit->object.oid.hash, NULL); + show_rev(REVERSED, &commit->object.oid, NULL); } } *dotdot = '.'; @@ -297,7 +297,7 @@ static int try_difference(const char *arg) static int try_parent_shorthands(const char *arg) { char *dotdot; - unsigned char sha1[20]; + struct object_id oid; struct commit *commit; struct commit_list *parents; int parent_number; @@ -327,12 +327,12 @@ static int try_parent_shorthands(const char *arg) return 0; *dotdot = 0; - if (get_sha1_committish(arg, sha1)) { + if (get_sha1_committish(arg, oid.hash)) { *dotdot = '^'; return 0; } - commit = lookup_commit_reference(sha1); + commit = lookup_commit_reference(&oid); if (exclude_parent && exclude_parent > commit_list_count(commit->parents)) { *dotdot = '^'; @@ -340,7 +340,7 @@ static int try_parent_shorthands(const char *arg) } if (include_rev) - show_rev(NORMAL, sha1, arg); + show_rev(NORMAL, &oid, arg); for (parents = commit->parents, parent_number = 1; parents; parents = parents->next, parent_number++) { @@ -352,7 +352,7 @@ static int try_parent_shorthands(const char *arg) if (symbolic) name = xstrfmt("%s^%d", arg, parent_number); show_rev(include_parents ? NORMAL : REVERSED, - parents->item->object.oid.hash, name); + &parents->item->object.oid, name); free(name); } @@ -571,7 +571,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) int did_repo_setup = 0; int has_dashdash = 0; int output_prefix = 0; - unsigned char sha1[20]; + struct object_id oid; unsigned int flags = 0; const char *name = NULL; struct object_context unused; @@ -910,11 +910,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) name++; type = REVERSED; } - if (!get_sha1_with_context(name, flags, sha1, &unused)) { + if (!get_sha1_with_context(name, flags, oid.hash, &unused)) { if (verify) revs_count++; else - show_rev(type, sha1, name); + show_rev(type, &oid, name); continue; } if (verify) @@ -929,7 +929,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) strbuf_release(&buf); if (verify) { if (revs_count == 1) { - show_rev(type, sha1, name); + show_rev(type, &oid, name); return 0; } else if (revs_count == 0 && show_default()) return 0; diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 8860f429b0..4a6cc6f490 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -358,7 +358,7 @@ static void sort_ref_range(int bottom, int top) static int append_ref(const char *refname, const struct object_id *oid, int allow_dups) { - struct commit *commit = lookup_commit_reference_gently(oid->hash, 1); + struct commit *commit = lookup_commit_reference_gently(oid, 1); int i; if (!commit) @@ -816,7 +816,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) MAX_REVS), MAX_REVS); if (get_sha1(ref_name[num_rev], revkey.hash)) die(_("'%s' is not a valid ref."), ref_name[num_rev]); - commit = lookup_commit_reference(revkey.hash); + commit = lookup_commit_reference(&revkey); if (!commit) die(_("cannot find commit %s (%s)"), ref_name[num_rev], oid_to_hex(&revkey)); diff --git a/builtin/tag.c b/builtin/tag.c index bdf1e88e93..1f74a56db7 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -66,7 +66,7 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, con } typedef int (*each_tag_name_fn)(const char *name, const char *ref, - const unsigned char *sha1, const void *cb_data); + const struct object_id *oid, const void *cb_data); static int for_each_tag_name(const char **argv, each_tag_name_fn fn, const void *cb_data) @@ -74,17 +74,17 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn, const char **p; struct strbuf ref = STRBUF_INIT; int had_error = 0; - unsigned char sha1[20]; + struct object_id oid; for (p = argv; *p; p++) { strbuf_reset(&ref); strbuf_addf(&ref, "refs/tags/%s", *p); - if (read_ref(ref.buf, sha1)) { + if (read_ref(ref.buf, oid.hash)) { error(_("tag '%s' not found."), *p); had_error = 1; continue; } - if (fn(*p, ref.buf, sha1, cb_data)) + if (fn(*p, ref.buf, &oid, cb_data)) had_error = 1; } strbuf_release(&ref); @@ -92,16 +92,16 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn, } static int delete_tag(const char *name, const char *ref, - const unsigned char *sha1, const void *cb_data) + const struct object_id *oid, const void *cb_data) { - if (delete_ref(NULL, ref, sha1, 0)) + if (delete_ref(NULL, ref, oid->hash, 0)) return 1; - printf(_("Deleted tag '%s' (was %s)\n"), name, find_unique_abbrev(sha1, DEFAULT_ABBREV)); + printf(_("Deleted tag '%s' (was %s)\n"), name, find_unique_abbrev(oid->hash, DEFAULT_ABBREV)); return 0; } static int verify_tag(const char *name, const char *ref, - const unsigned char *sha1, const void *cb_data) + const struct object_id *oid, const void *cb_data) { int flags; const char *fmt_pretty = cb_data; @@ -110,11 +110,11 @@ static int verify_tag(const char *name, const char *ref, if (fmt_pretty) flags = GPG_VERIFY_OMIT_STATUS; - if (gpg_verify_tag(sha1, name, flags)) + if (gpg_verify_tag(oid->hash, name, flags)) return -1; if (fmt_pretty) - pretty_print_ref(name, sha1, fmt_pretty); + pretty_print_ref(name, oid->hash, fmt_pretty); return 0; } @@ -182,13 +182,13 @@ static int git_tag_config(const char *var, const char *value, void *cb) return git_default_config(var, value, cb); } -static void write_tag_body(int fd, const unsigned char *sha1) +static void write_tag_body(int fd, const struct object_id *oid) { unsigned long size; enum object_type type; char *buf, *sp; - buf = read_sha1_file(sha1, &type, &size); + buf = read_sha1_file(oid->hash, &type, &size); if (!buf) return; /* skip header */ @@ -204,11 +204,11 @@ static void write_tag_body(int fd, const unsigned char *sha1) free(buf); } -static int build_tag_object(struct strbuf *buf, int sign, unsigned char *result) +static int build_tag_object(struct strbuf *buf, int sign, struct object_id *result) { if (sign && do_sign(buf) < 0) return error(_("unable to sign the tag")); - if (write_sha1_file(buf->buf, buf->len, tag_type, result) < 0) + if (write_sha1_file(buf->buf, buf->len, tag_type, result->hash) < 0) return error(_("unable to write tag file")); return 0; } @@ -223,15 +223,15 @@ struct create_tag_options { } cleanup_mode; }; -static void create_tag(const unsigned char *object, const char *tag, +static void create_tag(const struct object_id *object, const char *tag, struct strbuf *buf, struct create_tag_options *opt, - unsigned char *prev, unsigned char *result) + struct object_id *prev, struct object_id *result) { enum object_type type; struct strbuf header = STRBUF_INIT; char *path = NULL; - type = sha1_object_info(object, NULL); + type = sha1_object_info(object->hash, NULL); if (type <= OBJ_NONE) die(_("bad object type.")); @@ -240,7 +240,7 @@ static void create_tag(const unsigned char *object, const char *tag, "type %s\n" "tag %s\n" "tagger %s\n\n", - sha1_to_hex(object), + oid_to_hex(object), typename(type), tag, git_committer_info(IDENT_STRICT)); @@ -254,7 +254,7 @@ static void create_tag(const unsigned char *object, const char *tag, if (fd < 0) die_errno(_("could not create file '%s'"), path); - if (!is_null_sha1(prev)) { + if (!is_null_oid(prev)) { write_tag_body(fd, prev); } else { struct strbuf buf = STRBUF_INIT; @@ -296,7 +296,7 @@ static void create_tag(const unsigned char *object, const char *tag, } } -static void create_reflog_msg(const unsigned char *sha1, struct strbuf *sb) +static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb) { enum object_type type; struct commit *c; @@ -310,17 +310,17 @@ static void create_reflog_msg(const unsigned char *sha1, struct strbuf *sb) strbuf_addstr(sb, rla); } else { strbuf_addstr(sb, "tag: tagging "); - strbuf_add_unique_abbrev(sb, sha1, DEFAULT_ABBREV); + strbuf_add_unique_abbrev(sb, oid->hash, DEFAULT_ABBREV); } strbuf_addstr(sb, " ("); - type = sha1_object_info(sha1, NULL); + type = sha1_object_info(oid->hash, NULL); switch (type) { default: strbuf_addstr(sb, "object of unknown type"); break; case OBJ_COMMIT: - if ((buf = read_sha1_file(sha1, &type, &size)) != NULL) { + if ((buf = read_sha1_file(oid->hash, &type, &size)) != NULL) { subject_len = find_commit_subject(buf, &subject_start); strbuf_insert(sb, sb->len, subject_start, subject_len); } else { @@ -328,7 +328,7 @@ static void create_reflog_msg(const unsigned char *sha1, struct strbuf *sb) } free(buf); - if ((c = lookup_commit_reference(sha1)) != NULL) + if ((c = lookup_commit_reference(oid)) != NULL) strbuf_addf(sb, ", %s", show_date(c->date, 0, DATE_MODE(SHORT))); break; case OBJ_TREE: @@ -378,7 +378,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) struct strbuf buf = STRBUF_INIT; struct strbuf ref = STRBUF_INIT; struct strbuf reflog_msg = STRBUF_INIT; - unsigned char object[20], prev[20]; + struct object_id object, prev; const char *object_ref, *tag; struct create_tag_options opt; char *cleanup_arg = NULL; @@ -528,14 +528,14 @@ int cmd_tag(int argc, const char **argv, const char *prefix) if (argc > 2) die(_("too many params")); - if (get_sha1(object_ref, object)) + if (get_oid(object_ref, &object)) die(_("Failed to resolve '%s' as a valid ref."), object_ref); if (strbuf_check_tag_ref(&ref, tag)) die(_("'%s' is not a valid tag name."), tag); - if (read_ref(ref.buf, prev)) - hashclr(prev); + if (read_ref(ref.buf, prev.hash)) + oidclr(&prev); else if (!force) die(_("tag '%s' already exists"), tag); @@ -550,24 +550,24 @@ int cmd_tag(int argc, const char **argv, const char *prefix) else die(_("Invalid cleanup mode %s"), cleanup_arg); - create_reflog_msg(object, &reflog_msg); + create_reflog_msg(&object, &reflog_msg); if (create_tag_object) { if (force_sign_annotate && !annotate) opt.sign = 1; - create_tag(object, tag, &buf, &opt, prev, object); + create_tag(&object, tag, &buf, &opt, &prev, &object); } transaction = ref_transaction_begin(&err); if (!transaction || - ref_transaction_update(transaction, ref.buf, object, prev, + ref_transaction_update(transaction, ref.buf, object.hash, prev.hash, create_reflog ? REF_FORCE_CREATE_REFLOG : 0, reflog_msg.buf, &err) || ref_transaction_commit(transaction, &err)) die("%s", err.buf); ref_transaction_free(transaction); - if (force && !is_null_sha1(prev) && hashcmp(prev, object)) - printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev, DEFAULT_ABBREV)); + if (force && !is_null_oid(&prev) && oidcmp(&prev, &object)) + printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev.hash, DEFAULT_ABBREV)); strbuf_release(&err); strbuf_release(&buf); diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 4532aa0831..8bc9997767 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -127,7 +127,7 @@ static void *get_data(unsigned long size) } struct delta_info { - unsigned char base_sha1[20]; + struct object_id base_oid; unsigned nr; off_t base_offset; unsigned long size; @@ -137,13 +137,13 @@ struct delta_info { static struct delta_info *delta_list; -static void add_delta_to_list(unsigned nr, unsigned const char *base_sha1, +static void add_delta_to_list(unsigned nr, const struct object_id *base_oid, off_t base_offset, void *delta, unsigned long size) { struct delta_info *info = xmalloc(sizeof(*info)); - hashcpy(info->base_sha1, base_sha1); + oidcpy(&info->base_oid, base_oid); info->base_offset = base_offset; info->size = size; info->delta = delta; @@ -154,7 +154,7 @@ static void add_delta_to_list(unsigned nr, unsigned const char *base_sha1, struct obj_info { off_t offset; - unsigned char sha1[20]; + struct object_id oid; struct object *obj; }; @@ -170,9 +170,9 @@ static unsigned nr_objects; */ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf) { - unsigned char sha1[20]; + struct object_id oid; - if (write_sha1_file(obj_buf->buffer, obj_buf->size, typename(obj->type), sha1) < 0) + if (write_sha1_file(obj_buf->buffer, obj_buf->size, typename(obj->type), oid.hash) < 0) die("failed to write object %s", oid_to_hex(&obj->oid)); obj->flags |= FLAG_WRITTEN; } @@ -237,19 +237,19 @@ static void write_object(unsigned nr, enum object_type type, void *buf, unsigned long size) { if (!strict) { - if (write_sha1_file(buf, size, typename(type), obj_list[nr].sha1) < 0) + if (write_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash) < 0) die("failed to write object"); added_object(nr, type, buf, size); free(buf); obj_list[nr].obj = NULL; } else if (type == OBJ_BLOB) { struct blob *blob; - if (write_sha1_file(buf, size, typename(type), obj_list[nr].sha1) < 0) + if (write_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash) < 0) die("failed to write object"); added_object(nr, type, buf, size); free(buf); - blob = lookup_blob(obj_list[nr].sha1); + blob = lookup_blob(&obj_list[nr].oid); if (blob) blob->object.flags |= FLAG_WRITTEN; else @@ -258,9 +258,10 @@ static void write_object(unsigned nr, enum object_type type, } else { struct object *obj; int eaten; - hash_sha1_file(buf, size, typename(type), obj_list[nr].sha1); + hash_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash); added_object(nr, type, buf, size); - obj = parse_object_buffer(obj_list[nr].sha1, type, size, buf, &eaten); + obj = parse_object_buffer(&obj_list[nr].oid, type, size, buf, + &eaten); if (!obj) die("invalid %s", typename(type)); add_object_buffer(obj, buf, size); @@ -296,7 +297,7 @@ static void added_object(unsigned nr, enum object_type type, struct delta_info *info; while ((info = *p) != NULL) { - if (!hashcmp(info->base_sha1, obj_list[nr].sha1) || + if (!oidcmp(&info->base_oid, &obj_list[nr].oid) || info->base_offset == obj_list[nr].offset) { *p = info->next; p = &delta_list; @@ -320,12 +321,12 @@ static void unpack_non_delta_entry(enum object_type type, unsigned long size, free(buf); } -static int resolve_against_held(unsigned nr, const unsigned char *base, +static int resolve_against_held(unsigned nr, const struct object_id *base, void *delta_data, unsigned long delta_size) { struct object *obj; struct obj_buffer *obj_buffer; - obj = lookup_object(base); + obj = lookup_object(base->hash); if (!obj) return 0; obj_buffer = lookup_object_buffer(obj); @@ -341,25 +342,25 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size, { void *delta_data, *base; unsigned long base_size; - unsigned char base_sha1[20]; + struct object_id base_oid; if (type == OBJ_REF_DELTA) { - hashcpy(base_sha1, fill(20)); - use(20); + hashcpy(base_oid.hash, fill(GIT_SHA1_RAWSZ)); + use(GIT_SHA1_RAWSZ); delta_data = get_data(delta_size); if (dry_run || !delta_data) { free(delta_data); return; } - if (has_sha1_file(base_sha1)) + if (has_object_file(&base_oid)) ; /* Ok we have this one */ - else if (resolve_against_held(nr, base_sha1, + else if (resolve_against_held(nr, &base_oid, delta_data, delta_size)) return; /* we are done */ else { /* cannot resolve yet --- queue it */ - hashclr(obj_list[nr].sha1); - add_delta_to_list(nr, base_sha1, 0, delta_data, delta_size); + oidclr(&obj_list[nr].oid); + add_delta_to_list(nr, &base_oid, 0, delta_data, delta_size); return; } } else { @@ -399,8 +400,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size, } else if (base_offset > obj_list[mid].offset) { lo = mid + 1; } else { - hashcpy(base_sha1, obj_list[mid].sha1); - base_found = !is_null_sha1(base_sha1); + oidcpy(&base_oid, &obj_list[mid].oid); + base_found = !is_null_oid(&base_oid); break; } } @@ -409,19 +410,19 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size, * The delta base object is itself a delta that * has not been resolved yet. */ - hashclr(obj_list[nr].sha1); - add_delta_to_list(nr, null_sha1, base_offset, delta_data, delta_size); + oidclr(&obj_list[nr].oid); + add_delta_to_list(nr, &null_oid, base_offset, delta_data, delta_size); return; } } - if (resolve_against_held(nr, base_sha1, delta_data, delta_size)) + if (resolve_against_held(nr, &base_oid, delta_data, delta_size)) return; - base = read_sha1_file(base_sha1, &type, &base_size); + base = read_sha1_file(base_oid.hash, &type, &base_size); if (!base) { error("failed to read delta-pack base object %s", - sha1_to_hex(base_sha1)); + oid_to_hex(&base_oid)); if (!recover) exit(1); has_errors = 1; @@ -505,7 +506,7 @@ static void unpack_all(void) int cmd_unpack_objects(int argc, const char **argv, const char *prefix) { int i; - unsigned char sha1[20]; + struct object_id oid; check_replace_refs = 0; @@ -566,12 +567,12 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix) git_SHA1_Init(&ctx); unpack_all(); git_SHA1_Update(&ctx, buffer, offset); - git_SHA1_Final(sha1, &ctx); + git_SHA1_Final(oid.hash, &ctx); if (strict) write_rest(); - if (hashcmp(fill(20), sha1)) + if (hashcmp(fill(GIT_SHA1_RAWSZ), oid.hash)) die("final sha1 did not match"); - use(20); + use(GIT_SHA1_RAWSZ); /* Write the last part of the buffer to stdout */ while (len) { diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c index 38bedf8f9f..05b734e6d1 100644 --- a/builtin/verify-commit.c +++ b/builtin/verify-commit.c @@ -18,14 +18,14 @@ static const char * const verify_commit_usage[] = { NULL }; -static int run_gpg_verify(const unsigned char *sha1, const char *buf, unsigned long size, unsigned flags) +static int run_gpg_verify(const struct object_id *oid, const char *buf, unsigned long size, unsigned flags) { struct signature_check signature_check; int ret; memset(&signature_check, 0, sizeof(signature_check)); - ret = check_commit_signature(lookup_commit(sha1), &signature_check); + ret = check_commit_signature(lookup_commit(oid), &signature_check); print_signature_buffer(&signature_check, flags); signature_check_clear(&signature_check); @@ -35,22 +35,22 @@ static int run_gpg_verify(const unsigned char *sha1, const char *buf, unsigned l static int verify_commit(const char *name, unsigned flags) { enum object_type type; - unsigned char sha1[20]; + struct object_id oid; char *buf; unsigned long size; int ret; - if (get_sha1(name, sha1)) + if (get_oid(name, &oid)) return error("commit '%s' not found.", name); - buf = read_sha1_file(sha1, &type, &size); + buf = read_sha1_file(oid.hash, &type, &size); if (!buf) return error("%s: unable to read file.", name); if (type != OBJ_COMMIT) return error("%s: cannot verify a non-commit object of type %s.", name, typename(type)); - ret = run_gpg_verify(sha1, buf, size, flags); + ret = run_gpg_verify(&oid, buf, size, flags); free(buf); return ret; diff --git a/bulk-checkin.c b/bulk-checkin.c index ddb6070c4c..5be7ce5c73 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -69,7 +69,7 @@ static int already_written(struct bulk_checkin_state *state, unsigned char sha1[ /* Might want to keep the list sorted */ for (i = 0; i < state->nr_written; i++) - if (!hashcmp(state->written[i]->sha1, sha1)) + if (!hashcmp(state->written[i]->oid.hash, sha1)) return 1; /* This is a new object we need to keep */ @@ -242,7 +242,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state, state->offset = checkpoint.offset; free(idx); } else { - hashcpy(idx->sha1, result_sha1); + hashcpy(idx->oid.hash, result_sha1); ALLOC_GROW(state->written, state->nr_written + 1, state->alloc_written); @@ -12,11 +12,11 @@ static const char bundle_signature[] = "# v2 git bundle\n"; -static void add_to_ref_list(const unsigned char *sha1, const char *name, +static void add_to_ref_list(const struct object_id *oid, const char *name, struct ref_list *list) { ALLOC_GROW(list->list, list->nr + 1, list->alloc); - hashcpy(list->list[list->nr].sha1, sha1); + oidcpy(&list->list[list->nr].oid, oid); list->list[list->nr].name = xstrdup(name); list->nr++; } @@ -40,8 +40,9 @@ static int parse_bundle_header(int fd, struct bundle_header *header, /* The bundle header ends with an empty line */ while (!strbuf_getwholeline_fd(&buf, fd, '\n') && buf.len && buf.buf[0] != '\n') { - unsigned char sha1[20]; + struct object_id oid; int is_prereq = 0; + const char *p; if (*buf.buf == '-') { is_prereq = 1; @@ -54,9 +55,9 @@ static int parse_bundle_header(int fd, struct bundle_header *header, * Prerequisites have object name that is optionally * followed by SP and subject line. */ - if (get_sha1_hex(buf.buf, sha1) || - (buf.len > 40 && !isspace(buf.buf[40])) || - (!is_prereq && buf.len <= 40)) { + if (parse_oid_hex(buf.buf, &oid, &p) || + (*p && !isspace(*p)) || + (!is_prereq && !*p)) { if (report_path) error(_("unrecognized header: %s%s (%d)"), (is_prereq ? "-" : ""), buf.buf, (int)buf.len); @@ -64,9 +65,9 @@ static int parse_bundle_header(int fd, struct bundle_header *header, break; } else { if (is_prereq) - add_to_ref_list(sha1, "", &header->prerequisites); + add_to_ref_list(&oid, "", &header->prerequisites); else - add_to_ref_list(sha1, buf.buf + 41, &header->references); + add_to_ref_list(&oid, p + 1, &header->references); } } @@ -115,7 +116,7 @@ static int list_refs(struct ref_list *r, int argc, const char **argv) if (j == argc) continue; } - printf("%s %s\n", sha1_to_hex(r->list[i].sha1), + printf("%s %s\n", oid_to_hex(&r->list[i].oid), r->list[i].name); } return 0; @@ -141,7 +142,7 @@ int verify_bundle(struct bundle_header *header, int verbose) init_revisions(&revs, NULL); for (i = 0; i < p->nr; i++) { struct ref_list_entry *e = p->list + i; - struct object *o = parse_object(e->sha1); + struct object *o = parse_object(&e->oid); if (o) { o->flags |= PREREQ_MARK; add_pending_object(&revs, o, e->name); @@ -149,7 +150,7 @@ int verify_bundle(struct bundle_header *header, int verbose) } if (++ret == 1) error("%s", message); - error("%s %s", sha1_to_hex(e->sha1), e->name); + error("%s %s", oid_to_hex(&e->oid), e->name); } if (revs.pending.nr != p->nr) return ret; @@ -285,16 +286,18 @@ static int compute_and_write_prerequisites(int bundle_fd, return -1; rls_fout = xfdopen(rls.out, "r"); while (strbuf_getwholeline(&buf, rls_fout, '\n') != EOF) { - unsigned char sha1[20]; + struct object_id oid; if (buf.len > 0 && buf.buf[0] == '-') { write_or_die(bundle_fd, buf.buf, buf.len); - if (!get_sha1_hex(buf.buf + 1, sha1)) { - struct object *object = parse_object_or_die(sha1, buf.buf); + if (!get_oid_hex(buf.buf + 1, &oid)) { + struct object *object = parse_object_or_die(&oid, + buf.buf); object->flags |= UNINTERESTING; add_pending_object(revs, object, buf.buf); } - } else if (!get_sha1_hex(buf.buf, sha1)) { - struct object *object = parse_object_or_die(sha1, buf.buf); + } else if (!get_oid_hex(buf.buf, &oid)) { + struct object *object = parse_object_or_die(&oid, + buf.buf); object->flags |= SHOWN; } } @@ -366,7 +369,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs) * in terms of a tag (e.g. v2.0 from the range * "v1.0..v2.0")? */ - struct commit *one = lookup_commit_reference(oid.hash); + struct commit *one = lookup_commit_reference(&oid); struct object *obj; if (e->item == &(one->object)) { @@ -378,7 +381,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs) * end up triggering "empty bundle" * error. */ - obj = parse_object_or_die(oid.hash, e->name); + obj = parse_object_or_die(&oid, e->name); obj->flags |= SHOWN; add_pending_object(revs, obj, e->name); } @@ -1,10 +1,12 @@ #ifndef BUNDLE_H #define BUNDLE_H +#include "cache.h" + struct ref_list { unsigned int nr, alloc; struct ref_list_entry { - unsigned char sha1[20]; + struct object_id oid; char *name; } *list; }; diff --git a/cache-tree.c b/cache-tree.c index 34baa6d85a..ec23d8c03d 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -225,7 +225,7 @@ int cache_tree_fully_valid(struct cache_tree *it) int i; if (!it) return 0; - if (it->entry_count < 0 || !has_sha1_file(it->sha1)) + if (it->entry_count < 0 || !has_sha1_file(it->oid.hash)) return 0; for (i = 0; i < it->subtree_nr; i++) { if (!cache_tree_fully_valid(it->down[i]->cache_tree)) @@ -253,7 +253,7 @@ static int update_one(struct cache_tree *it, *skip_count = 0; - if (0 <= it->entry_count && has_sha1_file(it->sha1)) + if (0 <= it->entry_count && has_sha1_file(it->oid.hash)) return it->entry_count; /* @@ -340,7 +340,7 @@ static int update_one(struct cache_tree *it, die("cache-tree.c: '%.*s' in '%s' not found", entlen, path + baselen, path); i += sub->count; - sha1 = sub->cache_tree->sha1; + sha1 = sub->cache_tree->oid.hash; mode = S_IFDIR; contains_ita = sub->cache_tree->entry_count < 0; if (contains_ita) { @@ -404,12 +404,13 @@ static int update_one(struct cache_tree *it, unsigned char sha1[20]; hash_sha1_file(buffer.buf, buffer.len, tree_type, sha1); if (has_sha1_file(sha1)) - hashcpy(it->sha1, sha1); + hashcpy(it->oid.hash, sha1); else to_invalidate = 1; } else if (dryrun) - hash_sha1_file(buffer.buf, buffer.len, tree_type, it->sha1); - else if (write_sha1_file(buffer.buf, buffer.len, tree_type, it->sha1)) { + hash_sha1_file(buffer.buf, buffer.len, tree_type, + it->oid.hash); + else if (write_sha1_file(buffer.buf, buffer.len, tree_type, it->oid.hash)) { strbuf_release(&buffer); return -1; } @@ -419,7 +420,7 @@ static int update_one(struct cache_tree *it, #if DEBUG fprintf(stderr, "cache-tree update-one (%d ent, %d subtree) %s\n", it->entry_count, it->subtree_nr, - sha1_to_hex(it->sha1)); + oid_to_hex(&it->oid)); #endif return i; } @@ -459,14 +460,14 @@ static void write_one(struct strbuf *buffer, struct cache_tree *it, if (0 <= it->entry_count) fprintf(stderr, "cache-tree <%.*s> (%d ent, %d subtree) %s\n", pathlen, path, it->entry_count, it->subtree_nr, - sha1_to_hex(it->sha1)); + oid_to_hex(&it->oid)); else fprintf(stderr, "cache-tree <%.*s> (%d subtree) invalid\n", pathlen, path, it->subtree_nr); #endif if (0 <= it->entry_count) { - strbuf_add(buffer, it->sha1, 20); + strbuf_add(buffer, it->oid.hash, 20); } for (i = 0; i < it->subtree_nr; i++) { struct cache_tree_sub *down = it->down[i]; @@ -523,7 +524,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p) if (0 <= it->entry_count) { if (size < 20) goto free_return; - hashcpy(it->sha1, (const unsigned char*)buf); + hashcpy(it->oid.hash, (const unsigned char*)buf); buf += 20; size -= 20; } @@ -532,7 +533,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p) if (0 <= it->entry_count) fprintf(stderr, "cache-tree <%s> (%d ent, %d subtree) %s\n", *buffer, it->entry_count, subtree_nr, - sha1_to_hex(it->sha1)); + oid_to_hex(&it->oid)); else fprintf(stderr, "cache-tree <%s> (%d subtrees) invalid\n", *buffer, subtree_nr); @@ -643,10 +644,10 @@ int write_index_as_tree(unsigned char *sha1, struct index_state *index_state, co subtree = cache_tree_find(index_state->cache_tree, prefix); if (!subtree) return WRITE_TREE_PREFIX_ERROR; - hashcpy(sha1, subtree->sha1); + hashcpy(sha1, subtree->oid.hash); } else - hashcpy(sha1, index_state->cache_tree->sha1); + hashcpy(sha1, index_state->cache_tree->oid.hash); if (0 <= newfd) rollback_lock_file(lock_file); @@ -665,7 +666,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree) struct name_entry entry; int cnt; - hashcpy(it->sha1, tree->object.oid.hash); + oidcpy(&it->oid, &tree->object.oid); init_tree_desc(&desc, tree->buffer, tree->size); cnt = 0; while (tree_entry(&desc, &entry)) { @@ -673,7 +674,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree) cnt++; else { struct cache_tree_sub *sub; - struct tree *subtree = lookup_tree(entry.oid->hash); + struct tree *subtree = lookup_tree(entry.oid); if (!subtree->object.parsed) parse_tree(subtree); sub = cache_tree_sub(it, entry.path); @@ -720,7 +721,7 @@ int cache_tree_matches_traversal(struct cache_tree *root, it = find_cache_tree_from_traversal(root, info); it = cache_tree_find(it, ent->path); - if (it && it->entry_count > 0 && !hashcmp(ent->oid->hash, it->sha1)) + if (it && it->entry_count > 0 && !oidcmp(ent->oid, &it->oid)) return it->entry_count; return 0; } diff --git a/cache-tree.h b/cache-tree.h index 41c574663a..f7b9cab7ee 100644 --- a/cache-tree.h +++ b/cache-tree.h @@ -1,6 +1,7 @@ #ifndef CACHE_TREE_H #define CACHE_TREE_H +#include "cache.h" #include "tree.h" #include "tree-walk.h" @@ -15,7 +16,7 @@ struct cache_tree_sub { struct cache_tree { int entry_count; /* negative means "invalid" */ - unsigned char sha1[20]; + struct object_id oid; int subtree_nr; int subtree_alloc; struct cache_tree_sub **down; @@ -2198,8 +2198,8 @@ struct commit_list; int try_merge_command(const char *strategy, size_t xopts_nr, const char **xopts, struct commit_list *common, const char *head_arg, struct commit_list *remotes); -int checkout_fast_forward(const unsigned char *from, - const unsigned char *to, +int checkout_fast_forward(const struct object_id *from, + const struct object_id *to, int overwrite_ignore); @@ -18,38 +18,38 @@ int save_commit_buffer = 1; const char *commit_type = "commit"; -struct commit *lookup_commit_reference_gently(const unsigned char *sha1, +struct commit *lookup_commit_reference_gently(const struct object_id *oid, int quiet) { - struct object *obj = deref_tag(parse_object(sha1), NULL, 0); + struct object *obj = deref_tag(parse_object(oid), NULL, 0); if (!obj) return NULL; return object_as_type(obj, OBJ_COMMIT, quiet); } -struct commit *lookup_commit_reference(const unsigned char *sha1) +struct commit *lookup_commit_reference(const struct object_id *oid) { - return lookup_commit_reference_gently(sha1, 0); + return lookup_commit_reference_gently(oid, 0); } -struct commit *lookup_commit_or_die(const unsigned char *sha1, const char *ref_name) +struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name) { - struct commit *c = lookup_commit_reference(sha1); + struct commit *c = lookup_commit_reference(oid); if (!c) die(_("could not parse %s"), ref_name); - if (hashcmp(sha1, c->object.oid.hash)) { + if (oidcmp(oid, &c->object.oid)) { warning(_("%s %s is not a commit!"), - ref_name, sha1_to_hex(sha1)); + ref_name, oid_to_hex(oid)); } return c; } -struct commit *lookup_commit(const unsigned char *sha1) +struct commit *lookup_commit(const struct object_id *oid) { - struct object *obj = lookup_object(sha1); + struct object *obj = lookup_object(oid->hash); if (!obj) - return create_object(sha1, alloc_commit_node()); + return create_object(oid->hash, alloc_commit_node()); return object_as_type(obj, OBJ_COMMIT, 0); } @@ -60,7 +60,7 @@ struct commit *lookup_commit_reference_by_name(const char *name) if (get_sha1_committish(name, oid.hash)) return NULL; - commit = lookup_commit_reference(oid.hash); + commit = lookup_commit_reference(&oid); if (parse_commit(commit)) return NULL; return commit; @@ -216,9 +216,9 @@ int for_each_commit_graft(each_commit_graft_fn fn, void *cb_data) return ret; } -int unregister_shallow(const unsigned char *sha1) +int unregister_shallow(const struct object_id *oid) { - int pos = commit_graft_pos(sha1); + int pos = commit_graft_pos(oid->hash); if (pos < 0) return -1; if (pos + 1 < commit_graft_nr) @@ -331,7 +331,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s if (get_sha1_hex(bufptr + 5, parent.hash) < 0) return error("bad tree pointer in commit %s", oid_to_hex(&item->object.oid)); - item->tree = lookup_tree(parent.hash); + item->tree = lookup_tree(&parent); bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */ pptr = &item->parents; @@ -350,7 +350,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s */ if (graft && (graft->nr_parent < 0 || grafts_replace_parents)) continue; - new_parent = lookup_commit(parent.hash); + new_parent = lookup_commit(&parent); if (new_parent) pptr = &commit_list_insert(new_parent, pptr)->next; } @@ -358,7 +358,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s int i; struct commit *new_parent; for (i = 0; i < graft->nr_parent; i++) { - new_parent = lookup_commit(graft->parent[i].hash); + new_parent = lookup_commit(&graft->parent[i]); if (!new_parent) continue; pptr = &commit_list_insert(new_parent, pptr)->next; @@ -562,7 +562,7 @@ void clear_commit_marks_for_object_array(struct object_array *a, unsigned mark) for (i = 0; i < a->nr; i++) { object = a->objects[i].item; - commit = lookup_commit_reference_gently(object->oid.hash, 1); + commit = lookup_commit_reference_gently(&object->oid, 1); if (commit) clear_commit_marks(commit, mark); } @@ -1589,7 +1589,7 @@ struct commit *get_merge_parent(const char *name) struct object_id oid; if (get_sha1(name, oid.hash)) return NULL; - obj = parse_object(oid.hash); + obj = parse_object(&oid); commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT); if (commit && !commit->util) set_merge_remote_desc(commit, name, obj); @@ -45,18 +45,18 @@ enum decoration_type { void add_name_decoration(enum decoration_type type, const char *name, struct object *obj); const struct name_decoration *get_name_decoration(const struct object *obj); -struct commit *lookup_commit(const unsigned char *sha1); -struct commit *lookup_commit_reference(const unsigned char *sha1); -struct commit *lookup_commit_reference_gently(const unsigned char *sha1, +struct commit *lookup_commit(const struct object_id *oid); +struct commit *lookup_commit_reference(const struct object_id *oid); +struct commit *lookup_commit_reference_gently(const struct object_id *oid, int quiet); struct commit *lookup_commit_reference_by_name(const char *name); /* - * Look up object named by "sha1", dereference tag as necessary, - * get a commit and return it. If "sha1" does not dereference to + * Look up object named by "oid", dereference tag as necessary, + * get a commit and return it. If "oid" does not dereference to * a commit, use ref_name to report an error and die. */ -struct commit *lookup_commit_or_die(const unsigned char *sha1, const char *ref_name); +struct commit *lookup_commit_or_die(const struct object_id *oid, const char *ref_name); int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size); int parse_commit_gently(struct commit *item, int quiet_on_missing); @@ -263,8 +263,8 @@ extern struct commit_list *get_merge_bases_many_dirty(struct commit *one, int n, struct oid_array; struct ref; -extern int register_shallow(const unsigned char *sha1); -extern int unregister_shallow(const unsigned char *sha1); +extern int register_shallow(const struct object_id *oid); +extern int unregister_shallow(const struct object_id *oid); extern int for_each_commit_graft(each_commit_graft_fn, void *); extern int is_repository_shallow(void); extern struct commit_list *get_shallow_commits(struct object_array *heads, diff --git a/diff-lib.c b/diff-lib.c index 52447466b5..2982bf055a 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -478,7 +478,7 @@ static int oneway_diff(const struct cache_entry * const *src, } static int diff_cache(struct rev_info *revs, - const unsigned char *tree_sha1, + const struct object_id *tree_oid, const char *tree_name, int cached) { @@ -486,10 +486,10 @@ static int diff_cache(struct rev_info *revs, struct tree_desc t; struct unpack_trees_options opts; - tree = parse_tree_indirect(tree_sha1); + tree = parse_tree_indirect(tree_oid); if (!tree) return error("bad tree object %s", - tree_name ? tree_name : sha1_to_hex(tree_sha1)); + tree_name ? tree_name : oid_to_hex(tree_oid)); memset(&opts, 0, sizeof(opts)); opts.head_idx = 1; opts.index_only = cached; @@ -512,7 +512,7 @@ int run_diff_index(struct rev_info *revs, int cached) struct object_array_entry *ent; ent = revs->pending.objects; - if (diff_cache(revs, ent->item->oid.hash, ent->name, cached)) + if (diff_cache(revs, &ent->item->oid, ent->name, cached)) exit(128); diff_set_mnemonic_prefix(&revs->diffopt, "c/", cached ? "i/" : "w/"); @@ -522,7 +522,7 @@ int run_diff_index(struct rev_info *revs, int cached) return 0; } -int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt) +int do_diff_cache(const struct object_id *tree_oid, struct diff_options *opt) { struct rev_info revs; @@ -530,7 +530,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt) copy_pathspec(&revs.prune_data, &opt->pathspec); revs.diffopt = *opt; - if (diff_cache(&revs, tree_sha1, NULL, 1)) + if (diff_cache(&revs, tree_oid, NULL, 1)) exit(128); return 0; } @@ -5244,7 +5244,7 @@ size_t fill_textconv(struct userdiff_driver *driver, if (driver->textconv_cache && df->oid_valid) { *outbuf = notes_cache_get(driver->textconv_cache, - df->oid.hash, + &df->oid, &size); if (*outbuf) return size; @@ -5256,7 +5256,7 @@ size_t fill_textconv(struct userdiff_driver *driver, if (driver->textconv_cache && df->oid_valid) { /* ignore errors, as we might be in a readonly repository */ - notes_cache_put(driver->textconv_cache, df->oid.hash, *outbuf, + notes_cache_put(driver->textconv_cache, &df->oid, *outbuf, size); /* * we could save up changes and flush them all at the end, @@ -354,7 +354,7 @@ extern const char *diff_aligned_abbrev(const struct object_id *sha1, int); extern int run_diff_files(struct rev_info *revs, unsigned int option); extern int run_diff_index(struct rev_info *revs, int cached); -extern int do_diff_cache(const unsigned char *, struct diff_options *); +extern int do_diff_cache(const struct object_id *, struct diff_options *); extern int diff_flush_patch_id(struct diff_options *, unsigned char *, int); extern int diff_result_code(struct diff_options *, int); diff --git a/fast-import.c b/fast-import.c index cf58f875b8..e69d219682 100644 --- a/fast-import.c +++ b/fast-import.c @@ -226,7 +226,7 @@ struct tree_entry { struct atom_str *name; struct tree_entry_ms { uint16_t mode; - unsigned char sha1[20]; + struct object_id oid; } versions[2]; }; @@ -252,19 +252,19 @@ struct branch { unsigned active : 1; unsigned delete : 1; unsigned pack_id : PACK_ID_BITS; - unsigned char sha1[20]; + struct object_id oid; }; struct tag { struct tag *next_tag; const char *name; unsigned int pack_id; - unsigned char sha1[20]; + struct object_id oid; }; struct hash_list { struct hash_list *next; - unsigned char sha1[20]; + struct object_id oid; }; typedef enum { @@ -386,13 +386,15 @@ static void write_branch_report(FILE *rpt, struct branch *b) fputs(" active", rpt); if (b->branch_tree.tree) fputs(" loaded", rpt); - if (is_null_sha1(b->branch_tree.versions[1].sha1)) + if (is_null_oid(&b->branch_tree.versions[1].oid)) fputs(" dirty", rpt); fputc('\n', rpt); - fprintf(rpt, " tip commit : %s\n", sha1_to_hex(b->sha1)); - fprintf(rpt, " old tree : %s\n", sha1_to_hex(b->branch_tree.versions[0].sha1)); - fprintf(rpt, " cur tree : %s\n", sha1_to_hex(b->branch_tree.versions[1].sha1)); + fprintf(rpt, " tip commit : %s\n", oid_to_hex(&b->oid)); + fprintf(rpt, " old tree : %s\n", + oid_to_hex(&b->branch_tree.versions[0].oid)); + fprintf(rpt, " cur tree : %s\n", + oid_to_hex(&b->branch_tree.versions[1].oid)); fprintf(rpt, " commit clock: %" PRIuMAX "\n", b->last_commit); fputs(" last pack : ", rpt); @@ -470,7 +472,7 @@ static void write_crash_report(const char *err) fputs("Annotated Tags\n", rpt); fputs("--------------\n", rpt); for (tg = first_tag; tg; tg = tg->next_tag) { - fputs(sha1_to_hex(tg->sha1), rpt); + fputs(oid_to_hex(&tg->oid), rpt); fputc(' ', rpt); fputs(tg->name, rpt); fputc('\n', rpt); @@ -555,7 +557,7 @@ static void alloc_objects(unsigned int cnt) alloc_count += cnt; } -static struct object_entry *new_object(unsigned char *sha1) +static struct object_entry *new_object(struct object_id *oid) { struct object_entry *e; @@ -563,32 +565,32 @@ static struct object_entry *new_object(unsigned char *sha1) alloc_objects(object_entry_alloc); e = blocks->next_free++; - hashcpy(e->idx.sha1, sha1); + oidcpy(&e->idx.oid, oid); return e; } -static struct object_entry *find_object(unsigned char *sha1) +static struct object_entry *find_object(struct object_id *oid) { - unsigned int h = sha1[0] << 8 | sha1[1]; + unsigned int h = oid->hash[0] << 8 | oid->hash[1]; struct object_entry *e; for (e = object_table[h]; e; e = e->next) - if (!hashcmp(sha1, e->idx.sha1)) + if (!oidcmp(oid, &e->idx.oid)) return e; return NULL; } -static struct object_entry *insert_object(unsigned char *sha1) +static struct object_entry *insert_object(struct object_id *oid) { - unsigned int h = sha1[0] << 8 | sha1[1]; + unsigned int h = oid->hash[0] << 8 | oid->hash[1]; struct object_entry *e = object_table[h]; while (e) { - if (!hashcmp(sha1, e->idx.sha1)) + if (!oidcmp(oid, &e->idx.oid)) return e; e = e->next; } - e = new_object(sha1); + e = new_object(oid); e->next = object_table[h]; e->idx.offset = 0; object_table[h] = e; @@ -876,7 +878,7 @@ static struct tree_content *dup_tree_content(struct tree_content *s) a = s->entries[i]; b = new_tree_entry(); memcpy(b, a, sizeof(*a)); - if (a->tree && is_null_sha1(b->versions[1].sha1)) + if (a->tree && is_null_oid(&b->versions[1].oid)) b->tree = dup_tree_content(a->tree); else b->tree = NULL; @@ -1005,17 +1007,17 @@ static void end_packfile(void) clear_delta_base_cache(); if (object_count) { struct packed_git *new_p; - unsigned char cur_pack_sha1[20]; + struct object_id cur_pack_oid; char *idx_name; int i; struct branch *b; struct tag *t; close_pack_windows(pack_data); - sha1close(pack_file, cur_pack_sha1, 0); + sha1close(pack_file, cur_pack_oid.hash, 0); fixup_pack_header_footer(pack_data->pack_fd, pack_data->sha1, pack_data->pack_name, object_count, - cur_pack_sha1, pack_size); + cur_pack_oid.hash, pack_size); if (object_count <= unpack_limit) { if (!loosen_small_pack(pack_data)) { @@ -1041,12 +1043,14 @@ static void end_packfile(void) for (i = 0; i < branch_table_sz; i++) { for (b = branch_table[i]; b; b = b->table_next_branch) { if (b->pack_id == pack_id) - fprintf(pack_edges, " %s", sha1_to_hex(b->sha1)); + fprintf(pack_edges, " %s", + oid_to_hex(&b->oid)); } } for (t = first_tag; t; t = t->next_tag) { if (t->pack_id == pack_id) - fprintf(pack_edges, " %s", sha1_to_hex(t->sha1)); + fprintf(pack_edges, " %s", + oid_to_hex(&t->oid)); } fputc('\n', pack_edges); fflush(pack_edges); @@ -1079,13 +1083,13 @@ static int store_object( enum object_type type, struct strbuf *dat, struct last_object *last, - unsigned char *sha1out, + struct object_id *oidout, uintmax_t mark) { void *out, *delta; struct object_entry *e; unsigned char hdr[96]; - unsigned char sha1[20]; + struct object_id oid; unsigned long hdrlen, deltalen; git_SHA_CTX c; git_zstream s; @@ -1095,17 +1099,17 @@ static int store_object( git_SHA1_Init(&c); git_SHA1_Update(&c, hdr, hdrlen); git_SHA1_Update(&c, dat->buf, dat->len); - git_SHA1_Final(sha1, &c); - if (sha1out) - hashcpy(sha1out, sha1); + git_SHA1_Final(oid.hash, &c); + if (oidout) + oidcpy(oidout, &oid); - e = insert_object(sha1); + e = insert_object(&oid); if (mark) insert_mark(mark, e); if (e->idx.offset) { duplicate_count_by_type[type]++; return 1; - } else if (find_sha1_pack(sha1, packed_git)) { + } else if (find_sha1_pack(oid.hash, packed_git)) { e->type = type; e->pack_id = MAX_PACK_ID; e->idx.offset = 1; /* just not zero! */ @@ -1218,13 +1222,13 @@ static void truncate_pack(struct sha1file_checkpoint *checkpoint) pack_size = checkpoint->offset; } -static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark) +static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark) { size_t in_sz = 64 * 1024, out_sz = 64 * 1024; unsigned char *in_buf = xmalloc(in_sz); unsigned char *out_buf = xmalloc(out_sz); struct object_entry *e; - unsigned char sha1[20]; + struct object_id oid; unsigned long hdrlen; off_t offset; git_SHA_CTX c; @@ -1287,12 +1291,12 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark) } } git_deflate_end(&s); - git_SHA1_Final(sha1, &c); + git_SHA1_Final(oid.hash, &c); - if (sha1out) - hashcpy(sha1out, sha1); + if (oidout) + oidcpy(oidout, &oid); - e = insert_object(sha1); + e = insert_object(&oid); if (mark) insert_mark(mark, e); @@ -1301,7 +1305,7 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark) duplicate_count_by_type[OBJ_BLOB]++; truncate_pack(&checkpoint); - } else if (find_sha1_pack(sha1, packed_git)) { + } else if (find_sha1_pack(oid.hash, packed_git)) { e->type = OBJ_BLOB; e->pack_id = MAX_PACK_ID; e->idx.offset = 1; /* just not zero! */ @@ -1385,7 +1389,7 @@ static const char *get_mode(const char *str, uint16_t *modep) static void load_tree(struct tree_entry *root) { - unsigned char *sha1 = root->versions[1].sha1; + struct object_id *oid = &root->versions[1].oid; struct object_entry *myoe; struct tree_content *t; unsigned long size; @@ -1393,22 +1397,22 @@ static void load_tree(struct tree_entry *root) const char *c; root->tree = t = new_tree_content(8); - if (is_null_sha1(sha1)) + if (is_null_oid(oid)) return; - myoe = find_object(sha1); + myoe = find_object(oid); if (myoe && myoe->pack_id != MAX_PACK_ID) { if (myoe->type != OBJ_TREE) - die("Not a tree: %s", sha1_to_hex(sha1)); + die("Not a tree: %s", oid_to_hex(oid)); t->delta_depth = myoe->depth; buf = gfi_unpack_entry(myoe, &size); if (!buf) - die("Can't load tree %s", sha1_to_hex(sha1)); + die("Can't load tree %s", oid_to_hex(oid)); } else { enum object_type type; - buf = read_sha1_file(sha1, &type, &size); + buf = read_sha1_file(oid->hash, &type, &size); if (!buf || type != OBJ_TREE) - die("Can't load tree %s", sha1_to_hex(sha1)); + die("Can't load tree %s", oid_to_hex(oid)); } c = buf; @@ -1422,13 +1426,13 @@ static void load_tree(struct tree_entry *root) e->tree = NULL; c = get_mode(c, &e->versions[1].mode); if (!c) - die("Corrupt mode in %s", sha1_to_hex(sha1)); + die("Corrupt mode in %s", oid_to_hex(oid)); e->versions[0].mode = e->versions[1].mode; e->name = to_atom(c, strlen(c)); c += e->name->str_len + 1; - hashcpy(e->versions[0].sha1, (unsigned char *)c); - hashcpy(e->versions[1].sha1, (unsigned char *)c); - c += 20; + hashcpy(e->versions[0].oid.hash, (unsigned char *)c); + hashcpy(e->versions[1].oid.hash, (unsigned char *)c); + c += GIT_SHA1_RAWSZ; } free(buf); } @@ -1475,7 +1479,7 @@ static void mktree(struct tree_content *t, int v, struct strbuf *b) strbuf_addf(b, "%o %s%c", (unsigned int)(e->versions[v].mode & ~NO_DELTA), e->name->str_dat, '\0'); - strbuf_add(b, e->versions[v].sha1, 20); + strbuf_add(b, e->versions[v].oid.hash, GIT_SHA1_RAWSZ); } } @@ -1486,7 +1490,7 @@ static void store_tree(struct tree_entry *root) struct last_object lo = { STRBUF_INIT, 0, 0, /* no_swap */ 1 }; struct object_entry *le = NULL; - if (!is_null_sha1(root->versions[1].sha1)) + if (!is_null_oid(&root->versions[1].oid)) return; if (!root->tree) @@ -1499,7 +1503,7 @@ static void store_tree(struct tree_entry *root) } if (!(root->versions[0].mode & NO_DELTA)) - le = find_object(root->versions[0].sha1); + le = find_object(&root->versions[0].oid); if (S_ISDIR(root->versions[0].mode) && le && le->pack_id == pack_id) { mktree(t, 0, &old_tree); lo.data = old_tree; @@ -1508,14 +1512,14 @@ static void store_tree(struct tree_entry *root) } mktree(t, 1, &new_tree); - store_object(OBJ_TREE, &new_tree, &lo, root->versions[1].sha1, 0); + store_object(OBJ_TREE, &new_tree, &lo, &root->versions[1].oid, 0); t->delta_depth = lo.depth; for (i = 0, j = 0, del = 0; i < t->entry_count; i++) { struct tree_entry *e = t->entries[i]; if (e->versions[1].mode) { e->versions[0].mode = e->versions[1].mode; - hashcpy(e->versions[0].sha1, e->versions[1].sha1); + oidcpy(&e->versions[0].oid, &e->versions[1].oid); t->entries[j++] = e; } else { release_tree_entry(e); @@ -1527,14 +1531,14 @@ static void store_tree(struct tree_entry *root) static void tree_content_replace( struct tree_entry *root, - const unsigned char *sha1, + const struct object_id *oid, const uint16_t mode, struct tree_content *newtree) { if (!S_ISDIR(mode)) die("Root cannot be a non-directory"); - hashclr(root->versions[0].sha1); - hashcpy(root->versions[1].sha1, sha1); + oidclr(&root->versions[0].oid); + oidcpy(&root->versions[1].oid, oid); if (root->tree) release_tree_content_recursive(root->tree); root->tree = newtree; @@ -1543,7 +1547,7 @@ static void tree_content_replace( static int tree_content_set( struct tree_entry *root, const char *p, - const unsigned char *sha1, + const struct object_id *oid, const uint16_t mode, struct tree_content *subtree) { @@ -1568,10 +1572,10 @@ static int tree_content_set( if (!*slash1) { if (!S_ISDIR(mode) && e->versions[1].mode == mode - && !hashcmp(e->versions[1].sha1, sha1)) + && !oidcmp(&e->versions[1].oid, oid)) return 0; e->versions[1].mode = mode; - hashcpy(e->versions[1].sha1, sha1); + oidcpy(&e->versions[1].oid, oid); if (e->tree) release_tree_content_recursive(e->tree); e->tree = subtree; @@ -1592,7 +1596,7 @@ static int tree_content_set( if (S_ISDIR(e->versions[0].mode)) e->versions[0].mode |= NO_DELTA; - hashclr(root->versions[1].sha1); + oidclr(&root->versions[1].oid); return 1; } if (!S_ISDIR(e->versions[1].mode)) { @@ -1601,8 +1605,8 @@ static int tree_content_set( } if (!e->tree) load_tree(e); - if (tree_content_set(e, slash1 + 1, sha1, mode, subtree)) { - hashclr(root->versions[1].sha1); + if (tree_content_set(e, slash1 + 1, oid, mode, subtree)) { + oidclr(&root->versions[1].oid); return 1; } return 0; @@ -1614,18 +1618,18 @@ static int tree_content_set( e = new_tree_entry(); e->name = to_atom(p, n); e->versions[0].mode = 0; - hashclr(e->versions[0].sha1); + oidclr(&e->versions[0].oid); t->entries[t->entry_count++] = e; if (*slash1) { e->tree = new_tree_content(8); e->versions[1].mode = S_IFDIR; - tree_content_set(e, slash1 + 1, sha1, mode, subtree); + tree_content_set(e, slash1 + 1, oid, mode, subtree); } else { e->tree = subtree; e->versions[1].mode = mode; - hashcpy(e->versions[1].sha1, sha1); + oidcpy(&e->versions[1].oid, oid); } - hashclr(root->versions[1].sha1); + oidclr(&root->versions[1].oid); return 1; } @@ -1670,7 +1674,7 @@ static int tree_content_remove( if (tree_content_remove(e, slash1 + 1, backup_leaf, 0)) { for (n = 0; n < e->tree->entry_count; n++) { if (e->tree->entries[n]->versions[1].mode) { - hashclr(root->versions[1].sha1); + oidclr(&root->versions[1].oid); return 1; } } @@ -1689,8 +1693,8 @@ del_entry: release_tree_content_recursive(e->tree); e->tree = NULL; e->versions[1].mode = 0; - hashclr(e->versions[1].sha1); - hashclr(root->versions[1].sha1); + oidclr(&e->versions[1].oid); + oidclr(&root->versions[1].oid); return 1; } @@ -1735,7 +1739,7 @@ static int tree_content_get( found_entry: memcpy(leaf, e, sizeof(*leaf)); - if (e->tree && is_null_sha1(e->versions[1].sha1)) + if (e->tree && is_null_oid(&e->versions[1].oid)) leaf->tree = dup_tree_content(e->tree); else leaf->tree = NULL; @@ -1746,34 +1750,35 @@ static int update_branch(struct branch *b) { static const char *msg = "fast-import"; struct ref_transaction *transaction; - unsigned char old_sha1[20]; + struct object_id old_oid; struct strbuf err = STRBUF_INIT; - if (is_null_sha1(b->sha1)) { + if (is_null_oid(&b->oid)) { if (b->delete) delete_ref(NULL, b->name, NULL, 0); return 0; } - if (read_ref(b->name, old_sha1)) - hashclr(old_sha1); - if (!force_update && !is_null_sha1(old_sha1)) { + if (read_ref(b->name, old_oid.hash)) + oidclr(&old_oid); + if (!force_update && !is_null_oid(&old_oid)) { struct commit *old_cmit, *new_cmit; - old_cmit = lookup_commit_reference_gently(old_sha1, 0); - new_cmit = lookup_commit_reference_gently(b->sha1, 0); + old_cmit = lookup_commit_reference_gently(&old_oid, 0); + new_cmit = lookup_commit_reference_gently(&b->oid, 0); if (!old_cmit || !new_cmit) return error("Branch %s is missing commits.", b->name); if (!in_merge_bases(old_cmit, new_cmit)) { warning("Not updating %s" " (new tip %s does not contain %s)", - b->name, sha1_to_hex(b->sha1), sha1_to_hex(old_sha1)); + b->name, oid_to_hex(&b->oid), + oid_to_hex(&old_oid)); return -1; } } transaction = ref_transaction_begin(&err); if (!transaction || - ref_transaction_update(transaction, b->name, b->sha1, old_sha1, + ref_transaction_update(transaction, b->name, b->oid.hash, old_oid.hash, 0, msg, &err) || ref_transaction_commit(transaction, &err)) { ref_transaction_free(transaction); @@ -1815,7 +1820,7 @@ static void dump_tags(void) strbuf_addf(&ref_name, "refs/tags/%s", t->name); if (ref_transaction_update(transaction, ref_name.buf, - t->sha1, NULL, 0, msg, &err)) { + t->oid.hash, NULL, 0, msg, &err)) { failure |= error("%s", err.buf); goto cleanup; } @@ -1844,7 +1849,7 @@ static void dump_marks_helper(FILE *f, for (k = 0; k < 1024; k++) { if (m->data.marked[k]) fprintf(f, ":%" PRIuMAX " %s\n", base + k, - sha1_to_hex(m->data.marked[k]->idx.sha1)); + oid_to_hex(&m->data.marked[k]->idx.oid)); } } } @@ -1893,7 +1898,7 @@ static void read_marks(void) while (fgets(line, sizeof(line), f)) { uintmax_t mark; char *end; - unsigned char sha1[20]; + struct object_id oid; struct object_entry *e; end = strchr(line, '\n'); @@ -1902,14 +1907,14 @@ static void read_marks(void) *end = 0; mark = strtoumax(line + 1, &end, 10); if (!mark || end == line + 1 - || *end != ' ' || get_sha1_hex(end + 1, sha1)) + || *end != ' ' || get_oid_hex(end + 1, &oid)) die("corrupt mark line: %s", line); - e = find_object(sha1); + e = find_object(&oid); if (!e) { - enum object_type type = sha1_object_info(sha1, NULL); + enum object_type type = sha1_object_info(oid.hash, NULL); if (type < 0) - die("object not found: %s", sha1_to_hex(sha1)); - e = insert_object(sha1); + die("object not found: %s", oid_to_hex(&oid)); + e = insert_object(&oid); e->type = type; e->pack_id = MAX_PACK_ID; e->idx.offset = 1; /* just not zero! */ @@ -2117,21 +2122,21 @@ static char *parse_ident(const char *buf) static void parse_and_store_blob( struct last_object *last, - unsigned char *sha1out, + struct object_id *oidout, uintmax_t mark) { static struct strbuf buf = STRBUF_INIT; uintmax_t len; if (parse_data(&buf, big_file_threshold, &len)) - store_object(OBJ_BLOB, &buf, last, sha1out, mark); + store_object(OBJ_BLOB, &buf, last, oidout, mark); else { if (last) { strbuf_release(&last->data); last->offset = 0; last->depth = 0; } - stream_blob(len, sha1out, mark); + stream_blob(len, oidout, mark); skip_optional_lf(); } } @@ -2207,21 +2212,21 @@ static void construct_path_with_fanout(const char *hex_sha1, path[i++] = '/'; fanout--; } - memcpy(path + i, hex_sha1 + j, 40 - j); - path[i + 40 - j] = '\0'; + memcpy(path + i, hex_sha1 + j, GIT_SHA1_HEXSZ - j); + path[i + GIT_SHA1_HEXSZ - j] = '\0'; } static uintmax_t do_change_note_fanout( struct tree_entry *orig_root, struct tree_entry *root, - char *hex_sha1, unsigned int hex_sha1_len, + char *hex_oid, unsigned int hex_oid_len, char *fullpath, unsigned int fullpath_len, unsigned char fanout) { struct tree_content *t; struct tree_entry *e, leaf; - unsigned int i, tmp_hex_sha1_len, tmp_fullpath_len; + unsigned int i, tmp_hex_oid_len, tmp_fullpath_len; uintmax_t num_notes = 0; - unsigned char sha1[20]; + struct object_id oid; char realpath[60]; if (!root->tree) @@ -2230,7 +2235,7 @@ static uintmax_t do_change_note_fanout( for (i = 0; t && i < t->entry_count; i++) { e = t->entries[i]; - tmp_hex_sha1_len = hex_sha1_len + e->name->str_len; + tmp_hex_oid_len = hex_oid_len + e->name->str_len; tmp_fullpath_len = fullpath_len; /* @@ -2242,12 +2247,12 @@ static uintmax_t do_change_note_fanout( * of 2 chars. */ if (!e->versions[1].mode || - tmp_hex_sha1_len > 40 || + tmp_hex_oid_len > GIT_SHA1_HEXSZ || e->name->str_len % 2) continue; /* This _may_ be a note entry, or a subdir containing notes */ - memcpy(hex_sha1 + hex_sha1_len, e->name->str_dat, + memcpy(hex_oid + hex_oid_len, e->name->str_dat, e->name->str_len); if (tmp_fullpath_len) fullpath[tmp_fullpath_len++] = '/'; @@ -2256,14 +2261,14 @@ static uintmax_t do_change_note_fanout( tmp_fullpath_len += e->name->str_len; fullpath[tmp_fullpath_len] = '\0'; - if (tmp_hex_sha1_len == 40 && !get_sha1_hex(hex_sha1, sha1)) { + if (tmp_hex_oid_len == GIT_SHA1_HEXSZ && !get_oid_hex(hex_oid, &oid)) { /* This is a note entry */ if (fanout == 0xff) { /* Counting mode, no rename */ num_notes++; continue; } - construct_path_with_fanout(hex_sha1, fanout, realpath); + construct_path_with_fanout(hex_oid, fanout, realpath); if (!strcmp(fullpath, realpath)) { /* Note entry is in correct location */ num_notes++; @@ -2274,13 +2279,13 @@ static uintmax_t do_change_note_fanout( if (!tree_content_remove(orig_root, fullpath, &leaf, 0)) die("Failed to remove path %s", fullpath); tree_content_set(orig_root, realpath, - leaf.versions[1].sha1, + &leaf.versions[1].oid, leaf.versions[1].mode, leaf.tree); } else if (S_ISDIR(e->versions[1].mode)) { /* This is a subdir that may contain note entries */ num_notes += do_change_note_fanout(orig_root, e, - hex_sha1, tmp_hex_sha1_len, + hex_oid, tmp_hex_oid_len, fullpath, tmp_fullpath_len, fanout); } @@ -2293,8 +2298,14 @@ static uintmax_t do_change_note_fanout( static uintmax_t change_note_fanout(struct tree_entry *root, unsigned char fanout) { - char hex_sha1[40], path[60]; - return do_change_note_fanout(root, root, hex_sha1, 0, path, 0, fanout); + /* + * The size of path is due to one slash between every two hex digits, + * plus the terminating NUL. Note that there is no slash at the end, so + * the number of slashes is one less than half the number of hex + * characters. + */ + char hex_oid[GIT_MAX_HEXSZ], path[GIT_MAX_HEXSZ + (GIT_MAX_HEXSZ / 2) - 1 + 1]; + return do_change_note_fanout(root, root, hex_oid, 0, path, 0, fanout); } /* @@ -2355,7 +2366,7 @@ static void file_change_m(const char *p, struct branch *b) static struct strbuf uq = STRBUF_INIT; const char *endp; struct object_entry *oe; - unsigned char sha1[20]; + struct object_id oid; uint16_t mode, inline_data = 0; p = get_mode(p, &mode); @@ -2378,15 +2389,14 @@ static void file_change_m(const char *p, struct branch *b) if (*p == ':') { oe = find_mark(parse_mark_ref_space(&p)); - hashcpy(sha1, oe->idx.sha1); + oidcpy(&oid, &oe->idx.oid); } else if (skip_prefix(p, "inline ", &p)) { inline_data = 1; oe = NULL; /* not used with inline_data, but makes gcc happy */ } else { - if (get_sha1_hex(p, sha1)) + if (parse_oid_hex(p, &oid, &p)) die("Invalid dataref: %s", command_buf.buf); - oe = find_object(sha1); - p += 40; + oe = find_object(&oid); if (*p++ != ' ') die("Missing space after SHA1: %s", command_buf.buf); } @@ -2399,7 +2409,7 @@ static void file_change_m(const char *p, struct branch *b) } /* Git does not track empty, non-toplevel directories. */ - if (S_ISDIR(mode) && !hashcmp(sha1, EMPTY_TREE_SHA1_BIN) && *p) { + if (S_ISDIR(mode) && is_empty_tree_oid(&oid) && *p) { tree_content_remove(&b->branch_tree, p, NULL, 0); return; } @@ -2426,12 +2436,12 @@ static void file_change_m(const char *p, struct branch *b) p = uq.buf; } read_next_command(); - parse_and_store_blob(&last_blob, sha1, 0); + parse_and_store_blob(&last_blob, &oid, 0); } else { enum object_type expected = S_ISDIR(mode) ? OBJ_TREE: OBJ_BLOB; enum object_type type = oe ? oe->type : - sha1_object_info(sha1, NULL); + sha1_object_info(oid.hash, NULL); if (type < 0) die("%s not found: %s", S_ISDIR(mode) ? "Tree" : "Blob", @@ -2443,10 +2453,10 @@ static void file_change_m(const char *p, struct branch *b) } if (!*p) { - tree_content_replace(&b->branch_tree, sha1, mode, NULL); + tree_content_replace(&b->branch_tree, &oid, mode, NULL); return; } - tree_content_set(&b->branch_tree, p, sha1, mode, NULL); + tree_content_set(&b->branch_tree, p, &oid, mode, NULL); } static void file_change_d(const char *p, struct branch *b) @@ -2504,13 +2514,13 @@ static void file_change_cr(const char *s, struct branch *b, int rename) die("Path %s not in branch", s); if (!*d) { /* C "path/to/subdir" "" */ tree_content_replace(&b->branch_tree, - leaf.versions[1].sha1, + &leaf.versions[1].oid, leaf.versions[1].mode, leaf.tree); return; } tree_content_set(&b->branch_tree, d, - leaf.versions[1].sha1, + &leaf.versions[1].oid, leaf.versions[1].mode, leaf.tree); } @@ -2520,7 +2530,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa static struct strbuf uq = STRBUF_INIT; struct object_entry *oe; struct branch *s; - unsigned char sha1[20], commit_sha1[20]; + struct object_id oid, commit_oid; char path[60]; uint16_t inline_data = 0; unsigned char new_fanout; @@ -2545,15 +2555,14 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa /* <dataref> or 'inline' */ if (*p == ':') { oe = find_mark(parse_mark_ref_space(&p)); - hashcpy(sha1, oe->idx.sha1); + oidcpy(&oid, &oe->idx.oid); } else if (skip_prefix(p, "inline ", &p)) { inline_data = 1; oe = NULL; /* not used with inline_data, but makes gcc happy */ } else { - if (get_sha1_hex(p, sha1)) + if (parse_oid_hex(p, &oid, &p)) die("Invalid dataref: %s", command_buf.buf); - oe = find_object(sha1); - p += 40; + oe = find_object(&oid); if (*p++ != ' ') die("Missing space after SHA1: %s", command_buf.buf); } @@ -2561,19 +2570,19 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa /* <commit-ish> */ s = lookup_branch(p); if (s) { - if (is_null_sha1(s->sha1)) + if (is_null_oid(&s->oid)) die("Can't add a note on empty branch."); - hashcpy(commit_sha1, s->sha1); + oidcpy(&commit_oid, &s->oid); } else if (*p == ':') { uintmax_t commit_mark = parse_mark_ref_eol(p); struct object_entry *commit_oe = find_mark(commit_mark); if (commit_oe->type != OBJ_COMMIT) die("Mark :%" PRIuMAX " not a commit", commit_mark); - hashcpy(commit_sha1, commit_oe->idx.sha1); - } else if (!get_sha1(p, commit_sha1)) { + oidcpy(&commit_oid, &commit_oe->idx.oid); + } else if (!get_oid(p, &commit_oid)) { unsigned long size; - char *buf = read_object_with_reference(commit_sha1, - commit_type, &size, commit_sha1); + char *buf = read_object_with_reference(commit_oid.hash, + commit_type, &size, commit_oid.hash); if (!buf || size < 46) die("Not a valid commit: %s", p); free(buf); @@ -2586,13 +2595,13 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa p = uq.buf; } read_next_command(); - parse_and_store_blob(&last_blob, sha1, 0); + parse_and_store_blob(&last_blob, &oid, 0); } else if (oe) { if (oe->type != OBJ_BLOB) die("Not a blob (actually a %s): %s", typename(oe->type), command_buf.buf); - } else if (!is_null_sha1(sha1)) { - enum object_type type = sha1_object_info(sha1, NULL); + } else if (!is_null_oid(&oid)) { + enum object_type type = sha1_object_info(oid.hash, NULL); if (type < 0) die("Blob not found: %s", command_buf.buf); if (type != OBJ_BLOB) @@ -2600,50 +2609,51 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa typename(type), command_buf.buf); } - construct_path_with_fanout(sha1_to_hex(commit_sha1), *old_fanout, path); + construct_path_with_fanout(oid_to_hex(&commit_oid), *old_fanout, path); if (tree_content_remove(&b->branch_tree, path, NULL, 0)) b->num_notes--; - if (is_null_sha1(sha1)) + if (is_null_oid(&oid)) return; /* nothing to insert */ b->num_notes++; new_fanout = convert_num_notes_to_fanout(b->num_notes); - construct_path_with_fanout(sha1_to_hex(commit_sha1), new_fanout, path); - tree_content_set(&b->branch_tree, path, sha1, S_IFREG | 0644, NULL); + construct_path_with_fanout(oid_to_hex(&commit_oid), new_fanout, path); + tree_content_set(&b->branch_tree, path, &oid, S_IFREG | 0644, NULL); } static void file_change_deleteall(struct branch *b) { release_tree_content_recursive(b->branch_tree.tree); - hashclr(b->branch_tree.versions[0].sha1); - hashclr(b->branch_tree.versions[1].sha1); + oidclr(&b->branch_tree.versions[0].oid); + oidclr(&b->branch_tree.versions[1].oid); load_tree(&b->branch_tree); b->num_notes = 0; } static void parse_from_commit(struct branch *b, char *buf, unsigned long size) { - if (!buf || size < 46) - die("Not a valid commit: %s", sha1_to_hex(b->sha1)); + if (!buf || size < GIT_SHA1_HEXSZ + 6) + die("Not a valid commit: %s", oid_to_hex(&b->oid)); if (memcmp("tree ", buf, 5) - || get_sha1_hex(buf + 5, b->branch_tree.versions[1].sha1)) - die("The commit %s is corrupt", sha1_to_hex(b->sha1)); - hashcpy(b->branch_tree.versions[0].sha1, - b->branch_tree.versions[1].sha1); + || get_oid_hex(buf + 5, &b->branch_tree.versions[1].oid)) + die("The commit %s is corrupt", oid_to_hex(&b->oid)); + oidcpy(&b->branch_tree.versions[0].oid, + &b->branch_tree.versions[1].oid); } static void parse_from_existing(struct branch *b) { - if (is_null_sha1(b->sha1)) { - hashclr(b->branch_tree.versions[0].sha1); - hashclr(b->branch_tree.versions[1].sha1); + if (is_null_oid(&b->oid)) { + oidclr(&b->branch_tree.versions[0].oid); + oidclr(&b->branch_tree.versions[1].oid); } else { unsigned long size; char *buf; - buf = read_object_with_reference(b->sha1, - commit_type, &size, b->sha1); + buf = read_object_with_reference(b->oid.hash, + commit_type, &size, + b->oid.hash); parse_from_commit(b, buf, size); free(buf); } @@ -2653,28 +2663,28 @@ static int parse_from(struct branch *b) { const char *from; struct branch *s; - unsigned char sha1[20]; + struct object_id oid; if (!skip_prefix(command_buf.buf, "from ", &from)) return 0; - hashcpy(sha1, b->branch_tree.versions[1].sha1); + oidcpy(&oid, &b->branch_tree.versions[1].oid); s = lookup_branch(from); if (b == s) die("Can't create a branch from itself: %s", b->name); else if (s) { - unsigned char *t = s->branch_tree.versions[1].sha1; - hashcpy(b->sha1, s->sha1); - hashcpy(b->branch_tree.versions[0].sha1, t); - hashcpy(b->branch_tree.versions[1].sha1, t); + struct object_id *t = &s->branch_tree.versions[1].oid; + oidcpy(&b->oid, &s->oid); + oidcpy(&b->branch_tree.versions[0].oid, t); + oidcpy(&b->branch_tree.versions[1].oid, t); } else if (*from == ':') { uintmax_t idnum = parse_mark_ref_eol(from); struct object_entry *oe = find_mark(idnum); if (oe->type != OBJ_COMMIT) die("Mark :%" PRIuMAX " not a commit", idnum); - if (hashcmp(b->sha1, oe->idx.sha1)) { - hashcpy(b->sha1, oe->idx.sha1); + if (oidcmp(&b->oid, &oe->idx.oid)) { + oidcpy(&b->oid, &oe->idx.oid); if (oe->pack_id != MAX_PACK_ID) { unsigned long size; char *buf = gfi_unpack_entry(oe, &size); @@ -2683,15 +2693,15 @@ static int parse_from(struct branch *b) } else parse_from_existing(b); } - } else if (!get_sha1(from, b->sha1)) { + } else if (!get_oid(from, &b->oid)) { parse_from_existing(b); - if (is_null_sha1(b->sha1)) + if (is_null_oid(&b->oid)) b->delete = 1; } else die("Invalid ref name or SHA1 expression: %s", from); - if (b->branch_tree.tree && hashcmp(sha1, b->branch_tree.versions[1].sha1)) { + if (b->branch_tree.tree && oidcmp(&oid, &b->branch_tree.versions[1].oid)) { release_tree_content_recursive(b->branch_tree.tree); b->branch_tree.tree = NULL; } @@ -2711,17 +2721,17 @@ static struct hash_list *parse_merge(unsigned int *count) n = xmalloc(sizeof(*n)); s = lookup_branch(from); if (s) - hashcpy(n->sha1, s->sha1); + oidcpy(&n->oid, &s->oid); else if (*from == ':') { uintmax_t idnum = parse_mark_ref_eol(from); struct object_entry *oe = find_mark(idnum); if (oe->type != OBJ_COMMIT) die("Mark :%" PRIuMAX " not a commit", idnum); - hashcpy(n->sha1, oe->idx.sha1); - } else if (!get_sha1(from, n->sha1)) { + oidcpy(&n->oid, &oe->idx.oid); + } else if (!get_oid(from, &n->oid)) { unsigned long size; - char *buf = read_object_with_reference(n->sha1, - commit_type, &size, n->sha1); + char *buf = read_object_with_reference(n->oid.hash, + commit_type, &size, n->oid.hash); if (!buf || size < 46) die("Not a valid commit: %s", from); free(buf); @@ -2808,17 +2818,19 @@ static void parse_new_commit(const char *arg) /* build the tree and the commit */ store_tree(&b->branch_tree); - hashcpy(b->branch_tree.versions[0].sha1, - b->branch_tree.versions[1].sha1); + oidcpy(&b->branch_tree.versions[0].oid, + &b->branch_tree.versions[1].oid); strbuf_reset(&new_data); strbuf_addf(&new_data, "tree %s\n", - sha1_to_hex(b->branch_tree.versions[1].sha1)); - if (!is_null_sha1(b->sha1)) - strbuf_addf(&new_data, "parent %s\n", sha1_to_hex(b->sha1)); + oid_to_hex(&b->branch_tree.versions[1].oid)); + if (!is_null_oid(&b->oid)) + strbuf_addf(&new_data, "parent %s\n", + oid_to_hex(&b->oid)); while (merge_list) { struct hash_list *next = merge_list->next; - strbuf_addf(&new_data, "parent %s\n", sha1_to_hex(merge_list->sha1)); + strbuf_addf(&new_data, "parent %s\n", + oid_to_hex(&merge_list->oid)); free(merge_list); merge_list = next; } @@ -2831,7 +2843,7 @@ static void parse_new_commit(const char *arg) free(author); free(committer); - if (!store_object(OBJ_COMMIT, &new_data, NULL, b->sha1, next_mark)) + if (!store_object(OBJ_COMMIT, &new_data, NULL, &b->oid, next_mark)) b->pack_id = pack_id; b->last_commit = object_count_by_type[OBJ_COMMIT]; } @@ -2844,7 +2856,7 @@ static void parse_new_tag(const char *arg) struct branch *s; struct tag *t; uintmax_t from_mark = 0; - unsigned char sha1[20]; + struct object_id oid; enum object_type type; const char *v; @@ -2863,20 +2875,20 @@ static void parse_new_tag(const char *arg) die("Expected from command, got %s", command_buf.buf); s = lookup_branch(from); if (s) { - if (is_null_sha1(s->sha1)) + if (is_null_oid(&s->oid)) die("Can't tag an empty branch."); - hashcpy(sha1, s->sha1); + oidcpy(&oid, &s->oid); type = OBJ_COMMIT; } else if (*from == ':') { struct object_entry *oe; from_mark = parse_mark_ref_eol(from); oe = find_mark(from_mark); type = oe->type; - hashcpy(sha1, oe->idx.sha1); - } else if (!get_sha1(from, sha1)) { - struct object_entry *oe = find_object(sha1); + oidcpy(&oid, &oe->idx.oid); + } else if (!get_oid(from, &oid)) { + struct object_entry *oe = find_object(&oid); if (!oe) { - type = sha1_object_info(sha1, NULL); + type = sha1_object_info(oid.hash, NULL); if (type < 0) die("Not a valid object: %s", from); } else @@ -2902,7 +2914,7 @@ static void parse_new_tag(const char *arg) "object %s\n" "type %s\n" "tag %s\n", - sha1_to_hex(sha1), typename(type), t->name); + oid_to_hex(&oid), typename(type), t->name); if (tagger) strbuf_addf(&new_data, "tagger %s\n", tagger); @@ -2910,7 +2922,7 @@ static void parse_new_tag(const char *arg) strbuf_addbuf(&new_data, &msg); free(tagger); - if (store_object(OBJ_TAG, &new_data, NULL, t->sha1, 0)) + if (store_object(OBJ_TAG, &new_data, NULL, &t->oid, 0)) t->pack_id = MAX_PACK_ID; else t->pack_id = pack_id; @@ -2922,9 +2934,9 @@ static void parse_reset_branch(const char *arg) b = lookup_branch(arg); if (b) { - hashclr(b->sha1); - hashclr(b->branch_tree.versions[0].sha1); - hashclr(b->branch_tree.versions[1].sha1); + oidclr(&b->oid); + oidclr(&b->branch_tree.versions[0].oid); + oidclr(&b->branch_tree.versions[1].oid); if (b->branch_tree.tree) { release_tree_content_recursive(b->branch_tree.tree); b->branch_tree.tree = NULL; @@ -2944,7 +2956,7 @@ static void cat_blob_write(const char *buf, unsigned long size) die_errno("Write to frontend failed"); } -static void cat_blob(struct object_entry *oe, unsigned char sha1[20]) +static void cat_blob(struct object_entry *oe, struct object_id *oid) { struct strbuf line = STRBUF_INIT; unsigned long size; @@ -2952,7 +2964,7 @@ static void cat_blob(struct object_entry *oe, unsigned char sha1[20]) char *buf; if (!oe || oe->pack_id == MAX_PACK_ID) { - buf = read_sha1_file(sha1, &type, &size); + buf = read_sha1_file(oid->hash, &type, &size); } else { type = oe->type; buf = gfi_unpack_entry(oe, &size); @@ -2963,19 +2975,19 @@ static void cat_blob(struct object_entry *oe, unsigned char sha1[20]) */ if (type <= 0) { strbuf_reset(&line); - strbuf_addf(&line, "%s missing\n", sha1_to_hex(sha1)); + strbuf_addf(&line, "%s missing\n", oid_to_hex(oid)); cat_blob_write(line.buf, line.len); strbuf_release(&line); free(buf); return; } if (!buf) - die("Can't read object %s", sha1_to_hex(sha1)); + die("Can't read object %s", oid_to_hex(oid)); if (type != OBJ_BLOB) die("Object %s is a %s but a blob was expected.", - sha1_to_hex(sha1), typename(type)); + oid_to_hex(oid), typename(type)); strbuf_reset(&line); - strbuf_addf(&line, "%s %s %lu\n", sha1_to_hex(sha1), + strbuf_addf(&line, "%s %s %lu\n", oid_to_hex(oid), typename(type), size); cat_blob_write(line.buf, line.len); strbuf_release(&line); @@ -2992,7 +3004,7 @@ static void cat_blob(struct object_entry *oe, unsigned char sha1[20]) static void parse_get_mark(const char *p) { struct object_entry *oe = oe; - char output[42]; + char output[GIT_MAX_HEXSZ + 2]; /* get-mark SP <object> LF */ if (*p != ':') @@ -3002,43 +3014,43 @@ static void parse_get_mark(const char *p) if (!oe) die("Unknown mark: %s", command_buf.buf); - xsnprintf(output, sizeof(output), "%s\n", sha1_to_hex(oe->idx.sha1)); - cat_blob_write(output, 41); + xsnprintf(output, sizeof(output), "%s\n", oid_to_hex(&oe->idx.oid)); + cat_blob_write(output, GIT_SHA1_HEXSZ + 1); } static void parse_cat_blob(const char *p) { struct object_entry *oe = oe; - unsigned char sha1[20]; + struct object_id oid; /* cat-blob SP <object> LF */ if (*p == ':') { oe = find_mark(parse_mark_ref_eol(p)); if (!oe) die("Unknown mark: %s", command_buf.buf); - hashcpy(sha1, oe->idx.sha1); + oidcpy(&oid, &oe->idx.oid); } else { - if (get_sha1_hex(p, sha1)) + if (parse_oid_hex(p, &oid, &p)) die("Invalid dataref: %s", command_buf.buf); - if (p[40]) + if (*p) die("Garbage after SHA1: %s", command_buf.buf); - oe = find_object(sha1); + oe = find_object(&oid); } - cat_blob(oe, sha1); + cat_blob(oe, &oid); } static struct object_entry *dereference(struct object_entry *oe, - unsigned char sha1[20]) + struct object_id *oid) { unsigned long size; char *buf = NULL; if (!oe) { - enum object_type type = sha1_object_info(sha1, NULL); + enum object_type type = sha1_object_info(oid->hash, NULL); if (type < 0) - die("object not found: %s", sha1_to_hex(sha1)); + die("object not found: %s", oid_to_hex(oid)); /* cache it! */ - oe = insert_object(sha1); + oe = insert_object(oid); oe->type = type; oe->pack_id = MAX_PACK_ID; oe->idx.offset = 1; @@ -3057,49 +3069,48 @@ static struct object_entry *dereference(struct object_entry *oe, buf = gfi_unpack_entry(oe, &size); } else { enum object_type unused; - buf = read_sha1_file(sha1, &unused, &size); + buf = read_sha1_file(oid->hash, &unused, &size); } if (!buf) - die("Can't load object %s", sha1_to_hex(sha1)); + die("Can't load object %s", oid_to_hex(oid)); /* Peel one layer. */ switch (oe->type) { case OBJ_TAG: - if (size < 40 + strlen("object ") || - get_sha1_hex(buf + strlen("object "), sha1)) + if (size < GIT_SHA1_HEXSZ + strlen("object ") || + get_oid_hex(buf + strlen("object "), oid)) die("Invalid SHA1 in tag: %s", command_buf.buf); break; case OBJ_COMMIT: - if (size < 40 + strlen("tree ") || - get_sha1_hex(buf + strlen("tree "), sha1)) + if (size < GIT_SHA1_HEXSZ + strlen("tree ") || + get_oid_hex(buf + strlen("tree "), oid)) die("Invalid SHA1 in commit: %s", command_buf.buf); } free(buf); - return find_object(sha1); + return find_object(oid); } static struct object_entry *parse_treeish_dataref(const char **p) { - unsigned char sha1[20]; + struct object_id oid; struct object_entry *e; if (**p == ':') { /* <mark> */ e = find_mark(parse_mark_ref_space(p)); if (!e) die("Unknown mark: %s", command_buf.buf); - hashcpy(sha1, e->idx.sha1); + oidcpy(&oid, &e->idx.oid); } else { /* <sha1> */ - if (get_sha1_hex(*p, sha1)) + if (parse_oid_hex(*p, &oid, p)) die("Invalid dataref: %s", command_buf.buf); - e = find_object(sha1); - *p += 40; + e = find_object(&oid); if (*(*p)++ != ' ') die("Missing space after tree-ish: %s", command_buf.buf); } while (!e || e->type != OBJ_TREE) - e = dereference(e, sha1); + e = dereference(e, &oid); return e; } @@ -3143,8 +3154,8 @@ static void parse_ls(const char *p, struct branch *b) } else { struct object_entry *e = parse_treeish_dataref(&p); root = new_tree_entry(); - hashcpy(root->versions[1].sha1, e->idx.sha1); - if (!is_null_sha1(root->versions[1].sha1)) + oidcpy(&root->versions[1].oid, &e->idx.oid); + if (!is_null_oid(&root->versions[1].oid)) root->versions[1].mode = S_IFDIR; load_tree(root); } @@ -3166,7 +3177,7 @@ static void parse_ls(const char *p, struct branch *b) if (S_ISDIR(leaf.versions[1].mode)) store_tree(&leaf); - print_ls(leaf.versions[1].mode, leaf.versions[1].sha1, p); + print_ls(leaf.versions[1].mode, leaf.versions[1].oid.hash, p); if (leaf.tree) release_tree_content_recursive(leaf.tree); if (!b || root != &b->branch_tree) diff --git a/fetch-pack.c b/fetch-pack.c index 5f15dd2c39..44fa047bf4 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -78,7 +78,7 @@ static void cache_one_alternate(const char *refname, void *vcache) { struct alternate_object_cache *cache = vcache; - struct object *obj = parse_object(oid->hash); + struct object *obj = parse_object(oid); if (!obj || (obj->flags & ALTERNATE)) return; @@ -118,9 +118,9 @@ static void rev_list_push(struct commit *commit, int mark) } } -static int rev_list_insert_ref(const char *refname, const unsigned char *sha1) +static int rev_list_insert_ref(const char *refname, const struct object_id *oid) { - struct object *o = deref_tag(parse_object(sha1), refname, 0); + struct object *o = deref_tag(parse_object(oid), refname, 0); if (o && o->type == OBJ_COMMIT) rev_list_push((struct commit *)o, SEEN); @@ -131,13 +131,13 @@ static int rev_list_insert_ref(const char *refname, const unsigned char *sha1) static int rev_list_insert_ref_oid(const char *refname, const struct object_id *oid, int flag, void *cb_data) { - return rev_list_insert_ref(refname, oid->hash); + return rev_list_insert_ref(refname, oid); } static int clear_marks(const char *refname, const struct object_id *oid, int flag, void *cb_data) { - struct object *o = deref_tag(parse_object(oid->hash), refname, 0); + struct object *o = deref_tag(parse_object(oid), refname, 0); if (o && o->type == OBJ_COMMIT) clear_commit_marks((struct commit *)o, @@ -183,7 +183,7 @@ static void mark_common(struct commit *commit, Get the next rev to send, ignoring the common. */ -static const unsigned char *get_rev(void) +static const struct object_id *get_rev(void) { struct commit *commit = NULL; @@ -222,7 +222,7 @@ static const unsigned char *get_rev(void) } } - return commit->object.oid.hash; + return &commit->object.oid; } enum ack_type { @@ -251,7 +251,7 @@ static void consume_shallow_list(struct fetch_pack_args *args, int fd) } } -static enum ack_type get_ack(int fd, unsigned char *result_sha1) +static enum ack_type get_ack(int fd, struct object_id *result_oid) { int len; char *line = packet_read_line(fd, &len); @@ -262,7 +262,7 @@ static enum ack_type get_ack(int fd, unsigned char *result_sha1) if (!strcmp(line, "NAK")) return NAK; if (skip_prefix(line, "ACK ", &arg)) { - if (!get_sha1_hex(arg, result_sha1)) { + if (!get_oid_hex(arg, result_oid)) { arg += 40; len -= arg - line; if (len < 1) @@ -293,7 +293,7 @@ static void send_request(struct fetch_pack_args *args, static void insert_one_alternate_object(struct object *obj) { - rev_list_insert_ref(NULL, obj->oid.hash); + rev_list_insert_ref(NULL, &obj->oid); } #define INITIAL_FLUSH 16 @@ -317,12 +317,12 @@ static int next_flush(struct fetch_pack_args *args, int count) } static int find_common(struct fetch_pack_args *args, - int fd[2], unsigned char *result_sha1, + int fd[2], struct object_id *result_oid, struct ref *refs) { int fetching; int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval; - const unsigned char *sha1; + const struct object_id *oid; unsigned in_vain = 0; int got_continue = 0; int got_ready = 0; @@ -340,7 +340,7 @@ static int find_common(struct fetch_pack_args *args, fetching = 0; for ( ; refs ; refs = refs->next) { - unsigned char *remote = refs->old_oid.hash; + struct object_id *remote = &refs->old_oid; const char *remote_hex; struct object *o; @@ -354,12 +354,12 @@ static int find_common(struct fetch_pack_args *args, * interested in the case we *know* the object is * reachable and we have already scanned it. */ - if (((o = lookup_object(remote)) != NULL) && + if (((o = lookup_object(remote->hash)) != NULL) && (o->flags & COMPLETE)) { continue; } - remote_hex = sha1_to_hex(remote); + remote_hex = oid_to_hex(remote); if (!fetching) { struct strbuf c = STRBUF_INIT; if (multi_ack == 2) strbuf_addstr(&c, " multi_ack_detailed"); @@ -410,25 +410,25 @@ static int find_common(struct fetch_pack_args *args, if (args->deepen) { char *line; const char *arg; - unsigned char sha1[20]; + struct object_id oid; send_request(args, fd[1], &req_buf); while ((line = packet_read_line(fd[0], NULL))) { if (skip_prefix(line, "shallow ", &arg)) { - if (get_sha1_hex(arg, sha1)) + if (get_oid_hex(arg, &oid)) die(_("invalid shallow line: %s"), line); - register_shallow(sha1); + register_shallow(&oid); continue; } if (skip_prefix(line, "unshallow ", &arg)) { - if (get_sha1_hex(arg, sha1)) + if (get_oid_hex(arg, &oid)) die(_("invalid unshallow line: %s"), line); - if (!lookup_object(sha1)) + if (!lookup_object(oid.hash)) die(_("object not found: %s"), line); /* make sure that it is parsed as shallow */ - if (!parse_object(sha1)) + if (!parse_object(&oid)) die(_("error in object: %s"), line); - if (unregister_shallow(sha1)) + if (unregister_shallow(&oid)) die(_("no shallow found: %s"), line); continue; } @@ -447,9 +447,9 @@ static int find_common(struct fetch_pack_args *args, flushes = 0; retval = -1; - while ((sha1 = get_rev())) { - packet_buf_write(&req_buf, "have %s\n", sha1_to_hex(sha1)); - print_verbose(args, "have %s", sha1_to_hex(sha1)); + while ((oid = get_rev())) { + packet_buf_write(&req_buf, "have %s\n", oid_to_hex(oid)); + print_verbose(args, "have %s", oid_to_hex(oid)); in_vain++; if (flush_at <= ++count) { int ack; @@ -469,10 +469,10 @@ static int find_common(struct fetch_pack_args *args, consume_shallow_list(args, fd[0]); do { - ack = get_ack(fd[0], result_sha1); + ack = get_ack(fd[0], result_oid); if (ack) print_verbose(args, _("got %s %d %s"), "ack", - ack, sha1_to_hex(result_sha1)); + ack, oid_to_hex(result_oid)); switch (ack) { case ACK: flushes = 0; @@ -483,9 +483,9 @@ static int find_common(struct fetch_pack_args *args, case ACK_ready: case ACK_continue: { struct commit *commit = - lookup_commit(result_sha1); + lookup_commit(result_oid); if (!commit) - die(_("invalid commit %s"), sha1_to_hex(result_sha1)); + die(_("invalid commit %s"), oid_to_hex(result_oid)); if (args->stateless_rpc && ack == ACK_common && !(commit->object.flags & COMMON)) { @@ -493,7 +493,7 @@ static int find_common(struct fetch_pack_args *args, * on the next RPC request so the peer knows * it is in common with us. */ - const char *hex = sha1_to_hex(result_sha1); + const char *hex = oid_to_hex(result_oid); packet_buf_write(&req_buf, "have %s\n", hex); state_len = req_buf.len; /* @@ -538,10 +538,10 @@ done: if (!got_ready || !no_done) consume_shallow_list(args, fd[0]); while (flushes || multi_ack) { - int ack = get_ack(fd[0], result_sha1); + int ack = get_ack(fd[0], result_oid); if (ack) { print_verbose(args, _("got %s (%d) %s"), "ack", - ack, sha1_to_hex(result_sha1)); + ack, oid_to_hex(result_oid)); if (ack == ACK) return 0; multi_ack = 1; @@ -555,16 +555,16 @@ done: static struct commit_list *complete; -static int mark_complete(const unsigned char *sha1) +static int mark_complete(const struct object_id *oid) { - struct object *o = parse_object(sha1); + struct object *o = parse_object(oid); while (o && o->type == OBJ_TAG) { struct tag *t = (struct tag *) o; if (!t->tagged) break; /* broken repository */ o->flags |= COMPLETE; - o = parse_object(t->tagged->oid.hash); + o = parse_object(&t->tagged->oid); } if (o && o->type == OBJ_COMMIT) { struct commit *commit = (struct commit *)o; @@ -579,7 +579,7 @@ static int mark_complete(const unsigned char *sha1) static int mark_complete_oid(const char *refname, const struct object_id *oid, int flag, void *cb_data) { - return mark_complete(oid->hash); + return mark_complete(oid); } static void mark_recent_complete_commits(struct fetch_pack_args *args, @@ -637,14 +637,15 @@ static void filter_refs(struct fetch_pack_args *args, /* Append unmatched requests to the list */ for (i = 0; i < nr_sought; i++) { - unsigned char sha1[20]; + struct object_id oid; + const char *p; ref = sought[i]; if (ref->match_status != REF_NOT_MATCHED) continue; - if (get_sha1_hex(ref->name, sha1) || - ref->name[40] != '\0' || - hashcmp(sha1, ref->old_oid.hash)) + if (parse_oid_hex(ref->name, &oid, &p) || + *p != '\0' || + oidcmp(&oid, &ref->old_oid)) continue; if ((allow_unadvertised_object_request & @@ -661,7 +662,7 @@ static void filter_refs(struct fetch_pack_args *args, static void mark_alternate_complete(struct object *obj) { - mark_complete(obj->oid.hash); + mark_complete(&obj->oid); } static int everything_local(struct fetch_pack_args *args, @@ -680,7 +681,7 @@ static int everything_local(struct fetch_pack_args *args, if (!has_object_file(&ref->old_oid)) continue; - o = parse_object(ref->old_oid.hash); + o = parse_object(&ref->old_oid); if (!o) continue; @@ -724,17 +725,17 @@ static int everything_local(struct fetch_pack_args *args, filter_refs(args, refs, sought, nr_sought); for (retval = 1, ref = *refs; ref ; ref = ref->next) { - const unsigned char *remote = ref->old_oid.hash; + const struct object_id *remote = &ref->old_oid; struct object *o; - o = lookup_object(remote); + o = lookup_object(remote->hash); if (!o || !(o->flags & COMPLETE)) { retval = 0; - print_verbose(args, "want %s (%s)", sha1_to_hex(remote), + print_verbose(args, "want %s (%s)", oid_to_hex(remote), ref->name); continue; } - print_verbose(args, _("already have %s (%s)"), sha1_to_hex(remote), + print_verbose(args, _("already have %s (%s)"), oid_to_hex(remote), ref->name); } return retval; @@ -873,7 +874,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args, char **pack_lockfile) { struct ref *ref = copy_ref_list(orig_ref); - unsigned char sha1[20]; + struct object_id oid; const char *agent_feature; int agent_len; @@ -945,7 +946,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args, packet_flush(fd[1]); goto all_done; } - if (find_common(args, fd, sha1, ref) < 0) + if (find_common(args, fd, &oid, ref) < 0) if (!args->keep_pack) /* When cloning, it is not unusual to have * no common commit. @@ -358,14 +358,14 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op continue; if (S_ISDIR(entry.mode)) { - obj = &lookup_tree(entry.oid->hash)->object; + obj = &lookup_tree(entry.oid)->object; if (name) put_object_name(options, obj, "%s%s/", name, entry.path); result = options->walk(obj, OBJ_TREE, data, options); } else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode)) { - obj = &lookup_blob(entry.oid->hash)->object; + obj = &lookup_blob(entry.oid)->object; if (name) put_object_name(options, obj, "%s%s", name, entry.path); @@ -461,7 +461,7 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options) return -1; if (obj->type == OBJ_NONE) - parse_object(obj->oid.hash); + parse_object(&obj->oid); switch (obj->type) { case OBJ_BLOB: diff --git a/http-backend.c b/http-backend.c index d6ea607533..ba5ff1aa29 100644 --- a/http-backend.c +++ b/http-backend.c @@ -431,7 +431,7 @@ static int show_text_ref(const char *name, const struct object_id *oid, { const char *name_nons = strip_namespace(name); struct strbuf *buf = cb_data; - struct object *o = parse_object(oid->hash); + struct object *o = parse_object(oid); if (!o) return 0; diff --git a/http-push.c b/http-push.c index f0e3108f71..67c4d4b472 100644 --- a/http-push.c +++ b/http-push.c @@ -718,13 +718,13 @@ static int fetch_indices(void) return ret; } -static void one_remote_object(const unsigned char *sha1) +static void one_remote_object(const struct object_id *oid) { struct object *obj; - obj = lookup_object(sha1); + obj = lookup_object(oid->hash); if (!obj) - obj = parse_object(sha1); + obj = parse_object(oid); /* Ignore remote objects that don't exist locally */ if (!obj) @@ -1013,26 +1013,26 @@ static void remote_ls(const char *path, int flags, void *userData); /* extract hex from sharded "xx/x{40}" filename */ -static int get_sha1_hex_from_objpath(const char *path, unsigned char *sha1) +static int get_oid_hex_from_objpath(const char *path, struct object_id *oid) { - char hex[40]; + char hex[GIT_MAX_HEXSZ]; - if (strlen(path) != 41) + if (strlen(path) != GIT_SHA1_HEXSZ + 1) return -1; memcpy(hex, path, 2); path += 2; path++; /* skip '/' */ - memcpy(hex, path, 38); + memcpy(hex, path, GIT_SHA1_HEXSZ - 2); - return get_sha1_hex(hex, sha1); + return get_oid_hex(hex, oid); } static void process_ls_object(struct remote_ls_ctx *ls) { unsigned int *parent = (unsigned int *)ls->userData; const char *path = ls->dentry_name; - unsigned char sha1[20]; + struct object_id oid; if (!strcmp(ls->path, ls->dentry_name) && (ls->flags & IS_DIR)) { remote_dir_exists[*parent] = 1; @@ -1040,10 +1040,10 @@ static void process_ls_object(struct remote_ls_ctx *ls) } if (!skip_prefix(path, "objects/", &path) || - get_sha1_hex_from_objpath(path, sha1)) + get_oid_hex_from_objpath(path, &oid)) return; - one_remote_object(sha1); + one_remote_object(&oid); } static void process_ls_ref(struct remote_ls_ctx *ls) @@ -1312,10 +1312,10 @@ static struct object_list **process_tree(struct tree *tree, while (tree_entry(&desc, &entry)) switch (object_type(entry.mode)) { case OBJ_TREE: - p = process_tree(lookup_tree(entry.oid->hash), p); + p = process_tree(lookup_tree(entry.oid), p); break; case OBJ_BLOB: - p = process_blob(lookup_blob(entry.oid->hash), p); + p = process_blob(lookup_blob(entry.oid), p); break; default: /* Subproject commit - not in this repository */ @@ -1462,7 +1462,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls) return; } - o = parse_object(ref->old_oid.hash); + o = parse_object(&ref->old_oid); if (!o) { fprintf(stderr, "Unable to parse object %s for remote ref %s\n", @@ -1536,7 +1536,7 @@ static int remote_exists(const char *path) return ret; } -static void fetch_symref(const char *path, char **symref, unsigned char *sha1) +static void fetch_symref(const char *path, char **symref, struct object_id *oid) { char *url = xstrfmt("%s%s", repo->url, path); struct strbuf buffer = STRBUF_INIT; @@ -1549,7 +1549,7 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1) free(*symref); *symref = NULL; - hashclr(sha1); + oidclr(oid); if (buffer.len == 0) return; @@ -1561,16 +1561,17 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1) if (skip_prefix(buffer.buf, "ref: ", &name)) { *symref = xmemdupz(name, buffer.len - (name - buffer.buf)); } else { - get_sha1_hex(buffer.buf, sha1); + get_oid_hex(buffer.buf, oid); } strbuf_release(&buffer); } -static int verify_merge_base(unsigned char *head_sha1, struct ref *remote) +static int verify_merge_base(struct object_id *head_oid, struct ref *remote) { - struct commit *head = lookup_commit_or_die(head_sha1, "HEAD"); - struct commit *branch = lookup_commit_or_die(remote->old_oid.hash, remote->name); + struct commit *head = lookup_commit_or_die(head_oid, "HEAD"); + struct commit *branch = lookup_commit_or_die(&remote->old_oid, + remote->name); return in_merge_bases(branch, head); } @@ -1579,7 +1580,7 @@ static int delete_remote_branch(const char *pattern, int force) { struct ref *refs = remote_refs; struct ref *remote_ref = NULL; - unsigned char head_sha1[20]; + struct object_id head_oid; char *symref = NULL; int match; int patlen = strlen(pattern); @@ -1610,7 +1611,7 @@ static int delete_remote_branch(const char *pattern, int force) * Remote HEAD must be a symref (not exactly foolproof; a remote * symlink to a symref will look like a symref) */ - fetch_symref("HEAD", &symref, head_sha1); + fetch_symref("HEAD", &symref, &head_oid); if (!symref) return error("Remote HEAD is not a symref"); @@ -1619,7 +1620,7 @@ static int delete_remote_branch(const char *pattern, int force) if (!strcmp(remote_ref->name, symref)) return error("Remote branch %s is the current HEAD", remote_ref->name); - fetch_symref(symref, &symref, head_sha1); + fetch_symref(symref, &symref, &head_oid); } /* Run extra sanity checks if delete is not forced */ @@ -1627,10 +1628,10 @@ static int delete_remote_branch(const char *pattern, int force) /* Remote HEAD must resolve to a known object */ if (symref) return error("Remote HEAD symrefs too deep"); - if (is_null_sha1(head_sha1)) + if (is_null_oid(&head_oid)) return error("Unable to resolve remote HEAD"); - if (!has_sha1_file(head_sha1)) - return error("Remote HEAD resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", sha1_to_hex(head_sha1)); + if (!has_object_file(&head_oid)) + return error("Remote HEAD resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", oid_to_hex(&head_oid)); /* Remote branch must resolve to a known object */ if (is_null_oid(&remote_ref->old_oid)) @@ -1640,7 +1641,7 @@ static int delete_remote_branch(const char *pattern, int force) return error("Remote branch %s resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", remote_ref->name, oid_to_hex(&remote_ref->old_oid)); /* Remote branch must be an ancestor of remote HEAD */ - if (!verify_merge_base(head_sha1, remote_ref)) { + if (!verify_merge_base(&head_oid, remote_ref)) { return error("The branch '%s' is not an ancestor " "of your current HEAD.\n" "If you are sure you want to delete it," diff --git a/list-objects.c b/list-objects.c index f3ca6aafb7..b3931fa434 100644 --- a/list-objects.c +++ b/list-objects.c @@ -110,7 +110,7 @@ static void process_tree(struct rev_info *revs, if (S_ISDIR(entry.mode)) process_tree(revs, - lookup_tree(entry.oid->hash), + lookup_tree(entry.oid), show, base, entry.path, cb_data); else if (S_ISGITLINK(entry.mode)) @@ -119,7 +119,7 @@ static void process_tree(struct rev_info *revs, cb_data); else process_blob(revs, - lookup_blob(entry.oid->hash), + lookup_blob(entry.oid), show, base, entry.path, cb_data); } diff --git a/log-tree.c b/log-tree.c index 4618dd04ca..a4ec11c2bf 100644 --- a/log-tree.c +++ b/log-tree.c @@ -105,13 +105,13 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid, warning("invalid replace ref %s", refname); return 0; } - obj = parse_object(original_oid.hash); + obj = parse_object(&original_oid); if (obj) add_name_decoration(DECORATION_GRAFTED, "replaced", obj); return 0; } - obj = parse_object(oid->hash); + obj = parse_object(oid); if (!obj) return 0; @@ -132,7 +132,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid, if (!obj) break; if (!obj->parsed) - parse_object(obj->oid.hash); + parse_object(&obj->oid); add_name_decoration(DECORATION_REF_TAG, refname, obj); } return 0; @@ -140,7 +140,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid, static int add_graft_decoration(const struct commit_graft *graft, void *cb_data) { - struct commit *commit = lookup_commit(graft->oid.hash); + struct commit *commit = lookup_commit(&graft->oid); if (!commit) return 0; add_name_decoration(DECORATION_GRAFTED, "grafted", &commit->object); @@ -184,7 +184,7 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d { const struct name_decoration *list, *head = NULL; const char *branch_name = NULL; - unsigned char unused[20]; + struct object_id unused; int rru_flags; /* First find HEAD */ @@ -197,7 +197,7 @@ static const struct name_decoration *current_pointed_by_HEAD(const struct name_d return NULL; /* Now resolve and find the matching current branch */ - branch_name = resolve_ref_unsafe("HEAD", 0, unused, &rru_flags); + branch_name = resolve_ref_unsafe("HEAD", 0, unused.hash, &rru_flags); if (!(rru_flags & REF_ISSYMREF)) return NULL; @@ -456,13 +456,13 @@ static void show_signature(struct rev_info *opt, struct commit *commit) strbuf_release(&signature); } -static int which_parent(const unsigned char *sha1, const struct commit *commit) +static int which_parent(const struct object_id *oid, const struct commit *commit) { int nth; const struct commit_list *parent; for (nth = 0, parent = commit->parents; parent; parent = parent->next) { - if (!hashcmp(parent->item->object.oid.hash, sha1)) + if (!oidcmp(&parent->item->object.oid, oid)) return nth; nth++; } @@ -481,14 +481,14 @@ static void show_one_mergetag(struct commit *commit, void *data) { struct rev_info *opt = (struct rev_info *)data; - unsigned char sha1[20]; + struct object_id oid; struct tag *tag; struct strbuf verify_message; int status, nth; size_t payload_size, gpg_message_offset; - hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), sha1); - tag = lookup_tag(sha1); + hash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), oid.hash); + tag = lookup_tag(&oid); if (!tag) return; /* error message already given */ @@ -500,7 +500,7 @@ static void show_one_mergetag(struct commit *commit, &commit->parents->next->item->object.oid)) strbuf_addf(&verify_message, "merged tag '%s'\n", tag->tag); - else if ((nth = which_parent(tag->tagged->oid.hash, commit)) < 0) + else if ((nth = which_parent(&tag->tagged->oid, commit)) < 0) strbuf_addf(&verify_message, "tag %s names a non-parent %s\n", tag->tag, tag->tagged->oid.hash); else @@ -536,7 +536,7 @@ void show_log(struct rev_info *opt) struct strbuf msgbuf = STRBUF_INIT; struct log_info *log = opt->loginfo; struct commit *commit = log->commit, *parent = log->parent; - int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40; + int abbrev_commit = opt->abbrev_commit ? opt->abbrev : GIT_SHA1_HEXSZ; const char *extra_headers = opt->extra_headers; struct pretty_print_context ctx = {0}; diff --git a/merge-recursive.c b/merge-recursive.c index 62decd51cc..ae5238d82c 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -67,7 +67,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two, } if (!oidcmp(&two->object.oid, &shifted)) return two; - return lookup_tree(shifted.hash); + return lookup_tree(&shifted); } static struct commit *make_virtual_commit(struct tree *tree, const char *comment) @@ -304,7 +304,7 @@ struct tree *write_tree_from_memory(struct merge_options *o) return NULL; } - result = lookup_tree(active_cache_tree->sha1); + result = lookup_tree(&active_cache_tree->oid); return result; } @@ -994,11 +994,11 @@ static int merge_file_1(struct merge_options *o, return ret; result->clean = (merge_status == 0); } else if (S_ISGITLINK(a->mode)) { - result->clean = merge_submodule(result->oid.hash, + result->clean = merge_submodule(&result->oid, one->path, - one->oid.hash, - a->oid.hash, - b->oid.hash, + &one->oid, + &a->oid, + &b->oid, !o->call_depth); } else if (S_ISLNK(a->mode)) { oidcpy(&result->oid, &a->oid); @@ -2042,7 +2042,7 @@ int merge_recursive(struct merge_options *o, /* if there is no common ancestor, use an empty tree */ struct tree *tree; - tree = lookup_tree(EMPTY_TREE_SHA1_BIN); + tree = lookup_tree(&empty_tree_oid); merged_common_ancestors = make_virtual_commit(tree, "ancestor"); } @@ -2103,7 +2103,7 @@ static struct commit *get_ref(const struct object_id *oid, const char *name) { struct object *object; - object = deref_tag(parse_object(oid->hash), name, strlen(name)); + object = deref_tag(parse_object(oid), name, strlen(name)); if (!object) return NULL; if (object->type == OBJ_TREE) @@ -44,8 +44,8 @@ int try_merge_command(const char *strategy, size_t xopts_nr, return ret; } -int checkout_fast_forward(const unsigned char *head, - const unsigned char *remote, +int checkout_fast_forward(const struct object_id *head, + const struct object_id *remote, int overwrite_ignore) { struct tree *trees[MAX_UNPACK_TREES]; diff --git a/notes-cache.c b/notes-cache.c index 5dfc5cbd08..2843e98576 100644 --- a/notes-cache.c +++ b/notes-cache.c @@ -5,16 +5,16 @@ static int notes_cache_match_validity(const char *ref, const char *validity) { - unsigned char sha1[20]; + struct object_id oid; struct commit *commit; struct pretty_print_context pretty_ctx; struct strbuf msg = STRBUF_INIT; int ret; - if (read_ref(ref, sha1) < 0) + if (read_ref(ref, oid.hash) < 0) return 0; - commit = lookup_commit_reference_gently(sha1, 1); + commit = lookup_commit_reference_gently(&oid, 1); if (!commit) return 0; @@ -46,8 +46,7 @@ void notes_cache_init(struct notes_cache *c, const char *name, int notes_cache_write(struct notes_cache *c) { - unsigned char tree_sha1[20]; - unsigned char commit_sha1[20]; + struct object_id tree_oid, commit_oid; if (!c || !c->tree.initialized || !c->tree.update_ref || !*c->tree.update_ref) @@ -55,19 +54,19 @@ int notes_cache_write(struct notes_cache *c) if (!c->tree.dirty) return 0; - if (write_notes_tree(&c->tree, tree_sha1)) + if (write_notes_tree(&c->tree, tree_oid.hash)) return -1; - if (commit_tree(c->validity, strlen(c->validity), tree_sha1, NULL, - commit_sha1, NULL, NULL) < 0) + if (commit_tree(c->validity, strlen(c->validity), tree_oid.hash, NULL, + commit_oid.hash, NULL, NULL) < 0) return -1; - if (update_ref("update notes cache", c->tree.update_ref, commit_sha1, + if (update_ref("update notes cache", c->tree.update_ref, commit_oid.hash, NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0) return -1; return 0; } -char *notes_cache_get(struct notes_cache *c, unsigned char key_sha1[20], +char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid, size_t *outsize) { const unsigned char *value_sha1; @@ -75,7 +74,7 @@ char *notes_cache_get(struct notes_cache *c, unsigned char key_sha1[20], char *value; unsigned long size; - value_sha1 = get_note(&c->tree, key_sha1); + value_sha1 = get_note(&c->tree, key_oid->hash); if (!value_sha1) return NULL; value = read_sha1_file(value_sha1, &type, &size); @@ -84,12 +83,12 @@ char *notes_cache_get(struct notes_cache *c, unsigned char key_sha1[20], return value; } -int notes_cache_put(struct notes_cache *c, unsigned char key_sha1[20], +int notes_cache_put(struct notes_cache *c, struct object_id *key_oid, const char *data, size_t size) { - unsigned char value_sha1[20]; + struct object_id value_oid; - if (write_sha1_file(data, size, "blob", value_sha1) < 0) + if (write_sha1_file(data, size, "blob", value_oid.hash) < 0) return -1; - return add_note(&c->tree, key_sha1, value_sha1, NULL); + return add_note(&c->tree, key_oid->hash, value_oid.hash, NULL); } diff --git a/notes-cache.h b/notes-cache.h index 356f88fb3c..aeeee8409d 100644 --- a/notes-cache.h +++ b/notes-cache.h @@ -12,9 +12,9 @@ void notes_cache_init(struct notes_cache *c, const char *name, const char *validity); int notes_cache_write(struct notes_cache *c); -char *notes_cache_get(struct notes_cache *c, unsigned char sha1[20], size_t +char *notes_cache_get(struct notes_cache *c, struct object_id *oid, size_t *outsize); -int notes_cache_put(struct notes_cache *c, unsigned char sha1[20], +int notes_cache_put(struct notes_cache *c, struct object_id *oid, const char *data, size_t size); #endif /* NOTES_CACHE_H */ diff --git a/notes-merge.c b/notes-merge.c index 32caaaff74..6244f6af9c 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -535,7 +535,7 @@ int notes_merge(struct notes_merge_options *o, struct notes_tree *local_tree, unsigned char *result_sha1) { - unsigned char local_sha1[20], remote_sha1[20]; + struct object_id local_oid, remote_oid; struct commit *local, *remote; struct commit_list *bases = NULL; const unsigned char *base_sha1, *base_tree_sha1; @@ -549,46 +549,46 @@ int notes_merge(struct notes_merge_options *o, o->local_ref, o->remote_ref); /* Dereference o->local_ref into local_sha1 */ - if (read_ref_full(o->local_ref, 0, local_sha1, NULL)) + if (read_ref_full(o->local_ref, 0, local_oid.hash, NULL)) die("Failed to resolve local notes ref '%s'", o->local_ref); else if (!check_refname_format(o->local_ref, 0) && - is_null_sha1(local_sha1)) + is_null_oid(&local_oid)) local = NULL; /* local_sha1 == null_sha1 indicates unborn ref */ - else if (!(local = lookup_commit_reference(local_sha1))) + else if (!(local = lookup_commit_reference(&local_oid))) die("Could not parse local commit %s (%s)", - sha1_to_hex(local_sha1), o->local_ref); - trace_printf("\tlocal commit: %.7s\n", sha1_to_hex(local_sha1)); + oid_to_hex(&local_oid), o->local_ref); + trace_printf("\tlocal commit: %.7s\n", oid_to_hex(&local_oid)); /* Dereference o->remote_ref into remote_sha1 */ - if (get_sha1(o->remote_ref, remote_sha1)) { + if (get_oid(o->remote_ref, &remote_oid)) { /* * Failed to get remote_sha1. If o->remote_ref looks like an * unborn ref, perform the merge using an empty notes tree. */ if (!check_refname_format(o->remote_ref, 0)) { - hashclr(remote_sha1); + oidclr(&remote_oid); remote = NULL; } else { die("Failed to resolve remote notes ref '%s'", o->remote_ref); } - } else if (!(remote = lookup_commit_reference(remote_sha1))) { + } else if (!(remote = lookup_commit_reference(&remote_oid))) { die("Could not parse remote commit %s (%s)", - sha1_to_hex(remote_sha1), o->remote_ref); + oid_to_hex(&remote_oid), o->remote_ref); } - trace_printf("\tremote commit: %.7s\n", sha1_to_hex(remote_sha1)); + trace_printf("\tremote commit: %.7s\n", oid_to_hex(&remote_oid)); if (!local && !remote) die("Cannot merge empty notes ref (%s) into empty notes ref " "(%s)", o->remote_ref, o->local_ref); if (!local) { /* result == remote commit */ - hashcpy(result_sha1, remote_sha1); + hashcpy(result_sha1, remote_oid.hash); goto found_result; } if (!remote) { /* result == local commit */ - hashcpy(result_sha1, local_sha1); + hashcpy(result_sha1, local_oid.hash); goto found_result; } assert(local && remote); diff --git a/notes-utils.c b/notes-utils.c index 24a33616a4..325ff3daa3 100644 --- a/notes-utils.c +++ b/notes-utils.c @@ -7,18 +7,18 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents, const char *msg, size_t msg_len, unsigned char *result_sha1) { - unsigned char tree_sha1[20]; + struct object_id tree_oid; assert(t->initialized); - if (write_notes_tree(t, tree_sha1)) + if (write_notes_tree(t, tree_oid.hash)) die("Failed to write notes tree to database"); if (!parents) { /* Deduce parent commit from t->ref */ - unsigned char parent_sha1[20]; - if (!read_ref(t->ref, parent_sha1)) { - struct commit *parent = lookup_commit(parent_sha1); + struct object_id parent_oid; + if (!read_ref(t->ref, parent_oid.hash)) { + struct commit *parent = lookup_commit(&parent_oid); if (parse_commit(parent)) die("Failed to find/parse commit %s", t->ref); commit_list_insert(parent, &parents); @@ -26,14 +26,14 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents, /* else: t->ref points to nothing, assume root/orphan commit */ } - if (commit_tree(msg, msg_len, tree_sha1, parents, result_sha1, NULL, NULL)) + if (commit_tree(msg, msg_len, tree_oid.hash, parents, result_sha1, NULL, NULL)) die("Failed to commit notes tree to database"); } void commit_notes(struct notes_tree *t, const char *msg) { struct strbuf buf = STRBUF_INIT; - unsigned char commit_sha1[20]; + struct object_id commit_oid; if (!t) t = &default_notes_tree; @@ -46,9 +46,9 @@ void commit_notes(struct notes_tree *t, const char *msg) strbuf_addstr(&buf, msg); strbuf_complete_line(&buf); - create_notes_commit(t, NULL, buf.buf, buf.len, commit_sha1); + create_notes_commit(t, NULL, buf.buf, buf.len, commit_oid.hash); strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */ - update_ref(buf.buf, t->update_ref, commit_sha1, NULL, 0, + update_ref(buf.buf, t->update_ref, commit_oid.hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR); strbuf_release(&buf); @@ -180,21 +180,21 @@ struct object *lookup_unknown_object(const unsigned char *sha1) return obj; } -struct object *parse_object_buffer(const unsigned char *sha1, enum object_type type, unsigned long size, void *buffer, int *eaten_p) +struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p) { struct object *obj; *eaten_p = 0; obj = NULL; if (type == OBJ_BLOB) { - struct blob *blob = lookup_blob(sha1); + struct blob *blob = lookup_blob(oid); if (blob) { if (parse_blob_buffer(blob, buffer, size)) return NULL; obj = &blob->object; } } else if (type == OBJ_TREE) { - struct tree *tree = lookup_tree(sha1); + struct tree *tree = lookup_tree(oid); if (tree) { obj = &tree->object; if (!tree->buffer) @@ -206,7 +206,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t } } } else if (type == OBJ_COMMIT) { - struct commit *commit = lookup_commit(sha1); + struct commit *commit = lookup_commit(oid); if (commit) { if (parse_commit_buffer(commit, buffer, size)) return NULL; @@ -217,54 +217,54 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t obj = &commit->object; } } else if (type == OBJ_TAG) { - struct tag *tag = lookup_tag(sha1); + struct tag *tag = lookup_tag(oid); if (tag) { if (parse_tag_buffer(tag, buffer, size)) return NULL; obj = &tag->object; } } else { - warning("object %s has unknown type id %d", sha1_to_hex(sha1), type); + warning("object %s has unknown type id %d", oid_to_hex(oid), type); obj = NULL; } return obj; } -struct object *parse_object_or_die(const unsigned char *sha1, +struct object *parse_object_or_die(const struct object_id *oid, const char *name) { - struct object *o = parse_object(sha1); + struct object *o = parse_object(oid); if (o) return o; - die(_("unable to parse object: %s"), name ? name : sha1_to_hex(sha1)); + die(_("unable to parse object: %s"), name ? name : oid_to_hex(oid)); } -struct object *parse_object(const unsigned char *sha1) +struct object *parse_object(const struct object_id *oid) { unsigned long size; enum object_type type; int eaten; - const unsigned char *repl = lookup_replace_object(sha1); + const unsigned char *repl = lookup_replace_object(oid->hash); void *buffer; struct object *obj; - obj = lookup_object(sha1); + obj = lookup_object(oid->hash); if (obj && obj->parsed) return obj; if ((obj && obj->type == OBJ_BLOB) || - (!obj && has_sha1_file(sha1) && - sha1_object_info(sha1, NULL) == OBJ_BLOB)) { + (!obj && has_object_file(oid) && + sha1_object_info(oid->hash, NULL) == OBJ_BLOB)) { if (check_sha1_signature(repl, NULL, 0, NULL) < 0) { - error("sha1 mismatch %s", sha1_to_hex(repl)); + error("sha1 mismatch %s", oid_to_hex(oid)); return NULL; } - parse_blob_buffer(lookup_blob(sha1), NULL, 0); - return lookup_object(sha1); + parse_blob_buffer(lookup_blob(oid), NULL, 0); + return lookup_object(oid->hash); } - buffer = read_sha1_file(sha1, &type, &size); + buffer = read_sha1_file(oid->hash, &type, &size); if (buffer) { if (check_sha1_signature(repl, buffer, size, typename(type)) < 0) { free(buffer); @@ -272,7 +272,7 @@ struct object *parse_object(const unsigned char *sha1) return NULL; } - obj = parse_object_buffer(sha1, type, size, buffer, &eaten); + obj = parse_object_buffer(oid, type, size, buffer, &eaten); if (!eaten) free(buffer); return obj; @@ -89,20 +89,20 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet); * * Returns NULL if the object is missing or corrupt. */ -struct object *parse_object(const unsigned char *sha1); +struct object *parse_object(const struct object_id *oid); /* * Like parse_object, but will die() instead of returning NULL. If the * "name" parameter is not NULL, it is included in the error message - * (otherwise, the sha1 hex is given). + * (otherwise, the hex object ID is given). */ -struct object *parse_object_or_die(const unsigned char *sha1, const char *name); +struct object *parse_object_or_die(const struct object_id *oid, const char *name); /* Given the result of read_sha1_file(), returns the object after * parsing it. eaten_p indicates if the object has a borrowed copy * of buffer and the caller should not free() it. */ -struct object *parse_object_buffer(const unsigned char *sha1, enum object_type type, unsigned long size, void *buffer, int *eaten_p); +struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p); /** Returns the object, with potentially excess memory allocated. **/ struct object *lookup_unknown_object(const unsigned char *sha1); diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index e313f4f2bc..8e47a96b3b 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -73,7 +73,8 @@ void bitmap_writer_build_type_index(struct pack_idx_entry **index, break; default: - real_type = sha1_object_info(entry->idx.sha1, NULL); + real_type = sha1_object_info(entry->idx.oid.hash, + NULL); break; } @@ -96,7 +97,8 @@ void bitmap_writer_build_type_index(struct pack_idx_entry **index, default: die("Missing type information for %s (%d/%d)", - sha1_to_hex(entry->idx.sha1), real_type, entry->type); + oid_to_hex(&entry->idx.oid), real_type, + entry->type); } } } @@ -459,7 +461,7 @@ static inline void dump_bitmap(struct sha1file *f, struct ewah_bitmap *bitmap) static const unsigned char *sha1_access(size_t pos, void *table) { struct pack_idx_entry **index = table; - return index[pos]->sha1; + return index[pos]->oid.hash; } static void write_selected_commits_v1(struct sha1file *f, diff --git a/pack-bitmap.c b/pack-bitmap.c index 39bcc16846..a3ac3dccd4 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -673,7 +673,7 @@ int prepare_bitmap_walk(struct rev_info *revs) struct object *object = pending_e[i].item; if (object->type == OBJ_NONE) - parse_object_or_die(object->oid.hash, NULL); + parse_object_or_die(&object->oid, NULL); while (object->type == OBJ_TAG) { struct tag *tag = (struct tag *) object; @@ -685,7 +685,7 @@ int prepare_bitmap_walk(struct rev_info *revs) if (!tag->tagged) die("bad tag"); - object = parse_object_or_die(tag->tagged->oid.hash, NULL); + object = parse_object_or_die(&tag->tagged->oid, NULL); } if (object->flags & UNINTERESTING) diff --git a/pack-check.c b/pack-check.c index 27f70d345f..e1fcb228fa 100644 --- a/pack-check.c +++ b/pack-check.c @@ -5,7 +5,10 @@ struct idx_entry { off_t offset; - const unsigned char *sha1; + union idx_entry_object { + const unsigned char *hash; + struct object_id *oid; + } oid; unsigned int nr; }; @@ -51,7 +54,7 @@ static int verify_packfile(struct packed_git *p, off_t index_size = p->index_size; const unsigned char *index_base = p->index_data; git_SHA_CTX ctx; - unsigned char sha1[20], *pack_sig; + unsigned char hash[GIT_MAX_RAWSZ], *pack_sig; off_t offset = 0, pack_sig_ofs = 0; uint32_t nr_objects, i; int err = 0; @@ -71,9 +74,9 @@ static int verify_packfile(struct packed_git *p, remaining -= (unsigned int)(offset - pack_sig_ofs); git_SHA1_Update(&ctx, in, remaining); } while (offset < pack_sig_ofs); - git_SHA1_Final(sha1, &ctx); + git_SHA1_Final(hash, &ctx); pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL); - if (hashcmp(sha1, pack_sig)) + if (hashcmp(hash, pack_sig)) err = error("%s SHA1 checksum mismatch", p->pack_name); if (hashcmp(index_base + index_size - 40, pack_sig)) @@ -90,8 +93,8 @@ static int verify_packfile(struct packed_git *p, entries[nr_objects].offset = pack_sig_ofs; /* first sort entries by pack offset, since unpacking them is more efficient that way */ for (i = 0; i < nr_objects; i++) { - entries[i].sha1 = nth_packed_object_sha1(p, i); - if (!entries[i].sha1) + entries[i].oid.hash = nth_packed_object_sha1(p, i); + if (!entries[i].oid.hash) die("internal error pack-check nth-packed-object"); entries[i].offset = nth_packed_object_offset(p, i); entries[i].nr = i; @@ -112,7 +115,7 @@ static int verify_packfile(struct packed_git *p, if (check_pack_crc(p, w_curs, offset, len, nr)) err = error("index CRC mismatch for object %s " "from %s at offset %"PRIuMAX"", - sha1_to_hex(entries[i].sha1), + oid_to_hex(entries[i].oid.oid), p->pack_name, (uintmax_t)offset); } @@ -135,14 +138,14 @@ static int verify_packfile(struct packed_git *p, if (data_valid && !data) err = error("cannot unpack %s from %s at offset %"PRIuMAX"", - sha1_to_hex(entries[i].sha1), p->pack_name, + oid_to_hex(entries[i].oid.oid), p->pack_name, (uintmax_t)entries[i].offset); - else if (check_sha1_signature(entries[i].sha1, data, size, typename(type))) + else if (check_sha1_signature(entries[i].oid.hash, data, size, typename(type))) err = error("packed %s from %s is corrupt", - sha1_to_hex(entries[i].sha1), p->pack_name); + oid_to_hex(entries[i].oid.oid), p->pack_name); else if (fn) { int eaten = 0; - err |= fn(entries[i].sha1, type, size, data, &eaten); + err |= fn(entries[i].oid.oid, type, size, data, &eaten); if (eaten) data = NULL; } diff --git a/pack-objects.c b/pack-objects.c index 6398a8aa96..9558d13834 100644 --- a/pack-objects.c +++ b/pack-objects.c @@ -14,7 +14,7 @@ static uint32_t locate_object_entry_hash(struct packing_data *pdata, while (pdata->index[i] > 0) { uint32_t pos = pdata->index[i] - 1; - if (!hashcmp(sha1, pdata->objects[pos].idx.sha1)) { + if (!hashcmp(sha1, pdata->objects[pos].idx.oid.hash)) { *found = 1; return i; } @@ -53,7 +53,9 @@ static void rehash_objects(struct packing_data *pdata) for (i = 0; i < pdata->nr_objects; i++) { int found; - uint32_t ix = locate_object_entry_hash(pdata, entry->idx.sha1, &found); + uint32_t ix = locate_object_entry_hash(pdata, + entry->idx.oid.hash, + &found); if (found) die("BUG: Duplicate object in hash"); @@ -98,7 +100,7 @@ struct object_entry *packlist_alloc(struct packing_data *pdata, new_entry = pdata->objects + pdata->nr_objects++; memset(new_entry, 0, sizeof(*new_entry)); - hashcpy(new_entry->idx.sha1, sha1); + hashcpy(new_entry->idx.oid.hash, sha1); if (pdata->index_size * 3 <= pdata->nr_objects * 4) rehash_objects(pdata); diff --git a/pack-write.c b/pack-write.c index fa97b72559..a333ec6754 100644 --- a/pack-write.c +++ b/pack-write.c @@ -13,7 +13,7 @@ static int sha1_compare(const void *_a, const void *_b) { struct pack_idx_entry *a = *(struct pack_idx_entry **)_a; struct pack_idx_entry *b = *(struct pack_idx_entry **)_b; - return hashcmp(a->sha1, b->sha1); + return oidcmp(&a->oid, &b->oid); } static int cmp_uint32(const void *a_, const void *b_) @@ -103,7 +103,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec struct pack_idx_entry **next = list; while (next < last) { struct pack_idx_entry *obj = *next; - if (obj->sha1[0] != i) + if (obj->oid.hash[0] != i) break; next++; } @@ -122,11 +122,11 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec uint32_t offset = htonl(obj->offset); sha1write(f, &offset, 4); } - sha1write(f, obj->sha1, 20); + sha1write(f, obj->oid.hash, 20); if ((opts->flags & WRITE_IDX_STRICT) && - (i && !hashcmp(list[-2]->sha1, obj->sha1))) + (i && !oidcmp(&list[-2]->oid, &obj->oid))) die("The same object %s appears twice in the pack", - sha1_to_hex(obj->sha1)); + oid_to_hex(&obj->oid)); } if (index_version >= 2) { @@ -67,7 +67,7 @@ struct pack_idx_header { * Common part of object structure used for write_idx_file */ struct pack_idx_entry { - unsigned char sha1[20]; + struct object_id oid; uint32_t crc32; off_t offset; }; @@ -75,7 +75,7 @@ struct pack_idx_entry { struct progress; /* Note, the data argument could be NULL if object type is blob */ -typedef int (*verify_fn)(const unsigned char*, enum object_type, unsigned long, void*, int*); +typedef int (*verify_fn)(const struct object_id *, enum object_type, unsigned long, void*, int*); extern const char *write_idx_file(const char *index_name, struct pack_idx_entry **objects, int nr_objects, const struct pack_idx_option *, const unsigned char *sha1); extern int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, unsigned int nr); diff --git a/parse-options-cb.c b/parse-options-cb.c index a6810f295c..c6679cb2cd 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -80,14 +80,14 @@ int parse_opt_verbosity_cb(const struct option *opt, const char *arg, int parse_opt_commits(const struct option *opt, const char *arg, int unset) { - unsigned char sha1[20]; + struct object_id oid; struct commit *commit; if (!arg) return -1; - if (get_sha1(arg, sha1)) + if (get_oid(arg, &oid)) return error("malformed object name %s", arg); - commit = lookup_commit_reference(sha1); + commit = lookup_commit_reference(&oid); if (!commit) return error("no such commit %s", arg); commit_list_insert(commit, opt->value); @@ -1137,7 +1137,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */ /* these depend on the commit */ if (!commit->object.parsed) - parse_object(commit->object.oid.hash); + parse_object(&commit->object.oid); switch (placeholder[0]) { case 'H': /* commit hash */ diff --git a/reachable.c b/reachable.c index 682418f5d2..c62efbfd43 100644 --- a/reachable.c +++ b/reachable.c @@ -33,7 +33,7 @@ static int add_one_ref(const char *path, const struct object_id *oid, return 0; } - object = parse_object_or_die(oid->hash, path); + object = parse_object_or_die(oid, path); add_pending_object(revs, object, ""); return 0; @@ -82,13 +82,13 @@ static void add_recent_object(const struct object_id *oid, switch (type) { case OBJ_TAG: case OBJ_COMMIT: - obj = parse_object_or_die(oid->hash, NULL); + obj = parse_object_or_die(oid, NULL); break; case OBJ_TREE: - obj = (struct object *)lookup_tree(oid->hash); + obj = (struct object *)lookup_tree(oid); break; case OBJ_BLOB: - obj = (struct object *)lookup_blob(oid->hash); + obj = (struct object *)lookup_blob(oid); break; default: die("unknown object type for %s: %s", diff --git a/ref-filter.c b/ref-filter.c index 1fc5e9970d..6cc93dcd9f 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -677,13 +677,13 @@ int verify_ref_format(const char *format) * by the "struct object" representation, set *eaten as well---it is a * signal from parse_object_buffer to us not to free the buffer. */ -static void *get_obj(const unsigned char *sha1, struct object **obj, unsigned long *sz, int *eaten) +static void *get_obj(const struct object_id *oid, struct object **obj, unsigned long *sz, int *eaten) { enum object_type type; - void *buf = read_sha1_file(sha1, &type, sz); + void *buf = read_sha1_file(oid->hash, &type, sz); if (buf) - *obj = parse_object_buffer(sha1, type, *sz, buf, eaten); + *obj = parse_object_buffer(oid, type, *sz, buf, eaten); else *obj = NULL; return buf; @@ -1293,7 +1293,7 @@ static void populate_value(struct ref_array_item *ref) struct object *obj; int eaten, i; unsigned long size; - const unsigned char *tagged; + const struct object_id *tagged; ref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value)); @@ -1366,14 +1366,14 @@ static void populate_value(struct ref_array_item *ref) v->s = xstrdup(buf + 1); } continue; - } else if (!deref && grab_objectname(name, ref->objectname, v, atom)) { + } else if (!deref && grab_objectname(name, ref->objectname.hash, v, atom)) { continue; } else if (!strcmp(name, "HEAD")) { const char *head; - unsigned char sha1[20]; + struct object_id oid; head = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, - sha1, NULL); + oid.hash, NULL); if (head && !strcmp(ref->refname, head)) v->s = "*"; else @@ -1415,13 +1415,13 @@ static void populate_value(struct ref_array_item *ref) return; need_obj: - buf = get_obj(ref->objectname, &obj, &size, &eaten); + buf = get_obj(&ref->objectname, &obj, &size, &eaten); if (!buf) die(_("missing object %s for %s"), - sha1_to_hex(ref->objectname), ref->refname); + oid_to_hex(&ref->objectname), ref->refname); if (!obj) die(_("parse_object_buffer failed on %s for %s"), - sha1_to_hex(ref->objectname), ref->refname); + oid_to_hex(&ref->objectname), ref->refname); grab_values(ref->value, 0, obj, buf, size); if (!eaten) @@ -1438,7 +1438,7 @@ static void populate_value(struct ref_array_item *ref) * If it is a tag object, see if we use a value that derefs * the object, and if we do grab the object it refers to. */ - tagged = ((struct tag *)obj)->tagged->oid.hash; + tagged = &((struct tag *)obj)->tagged->oid; /* * NEEDSWORK: This derefs tag only once, which @@ -1449,10 +1449,10 @@ static void populate_value(struct ref_array_item *ref) buf = get_obj(tagged, &obj, &size, &eaten); if (!buf) die(_("missing object %s for %s"), - sha1_to_hex(tagged), ref->refname); + oid_to_hex(tagged), ref->refname); if (!obj) die(_("parse_object_buffer failed on %s for %s"), - sha1_to_hex(tagged), ref->refname); + oid_to_hex(tagged), ref->refname); grab_values(ref->value, 1, obj, buf, size); if (!eaten) free(buf); @@ -1687,7 +1687,7 @@ static const struct object_id *match_points_at(struct oid_array *points_at, if (oid_array_lookup(points_at, oid) >= 0) return oid; - obj = parse_object(oid->hash); + obj = parse_object(oid); if (!obj) die(_("malformed object at '%s'"), refname); if (obj->type == OBJ_TAG) @@ -1704,7 +1704,7 @@ static struct ref_array_item *new_ref_array_item(const char *refname, { struct ref_array_item *ref; FLEX_ALLOC_STR(ref, refname, refname); - hashcpy(ref->objectname, objectname); + hashcpy(ref->objectname.hash, objectname); ref->flag = flag; return ref; @@ -1782,7 +1782,7 @@ static int ref_filter_handler(const char *refname, const struct object_id *oid, * non-commits early. The actual filtering is done later. */ if (filter->merge_commit || filter->with_commit || filter->no_commit || filter->verbose) { - commit = lookup_commit_reference_gently(oid->hash, 1); + commit = lookup_commit_reference_gently(oid, 1); if (!commit) return 0; /* We perform the filtering for the '--contains' option... */ @@ -2090,7 +2090,7 @@ int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset) int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset) { struct ref_filter *rf = opt->value; - unsigned char sha1[20]; + struct object_id oid; int no_merged = starts_with(opt->long_name, "no"); if (rf->merge) { @@ -2105,10 +2105,10 @@ int parse_opt_merge_filter(const struct option *opt, const char *arg, int unset) ? REF_FILTER_MERGED_OMIT : REF_FILTER_MERGED_INCLUDE; - if (get_sha1(arg, sha1)) + if (get_oid(arg, &oid)) die(_("malformed object name %s"), arg); - rf->merge_commit = lookup_commit_reference_gently(sha1, 0); + rf->merge_commit = lookup_commit_reference_gently(&oid, 0); if (!rf->merge_commit) return opterror(opt, "must point to a commit", 0); diff --git a/ref-filter.h b/ref-filter.h index c20167aa3c..6552024f09 100644 --- a/ref-filter.h +++ b/ref-filter.h @@ -34,7 +34,7 @@ struct ref_sorting { }; struct ref_array_item { - unsigned char objectname[20]; + struct object_id objectname; int flag; unsigned int kind; const char *symref; diff --git a/reflog-walk.c b/reflog-walk.c index 3ca5ed8415..70905011ee 100644 --- a/reflog-walk.c +++ b/reflog-walk.c @@ -238,13 +238,13 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit) do { reflog = &commit_reflog->reflogs->items[commit_reflog->recno]; commit_reflog->recno--; - logobj = parse_object(reflog->ooid.hash); + logobj = parse_object(&reflog->ooid); } while (commit_reflog->recno && (logobj && logobj->type != OBJ_COMMIT)); - if (!logobj && commit_reflog->recno >= 0 && is_null_sha1(reflog->ooid.hash)) { + if (!logobj && commit_reflog->recno >= 0 && is_null_oid(&reflog->ooid)) { /* a root commit, but there are still more entries to show */ reflog = &commit_reflog->reflogs->items[commit_reflog->recno]; - logobj = parse_object(reflog->noid.hash); + logobj = parse_object(&reflog->noid); } if (!logobj || logobj->type != OBJ_COMMIT) { @@ -883,9 +883,9 @@ struct ref_update *ref_transaction_add_update( update->flags = flags; if (flags & REF_HAVE_NEW) - hashcpy(update->new_sha1, new_sha1); + hashcpy(update->new_oid.hash, new_sha1); if (flags & REF_HAVE_OLD) - hashcpy(update->old_sha1, old_sha1); + hashcpy(update->old_oid.hash, old_sha1); update->msg = xstrdup_or_null(msg); return update; } @@ -602,10 +602,10 @@ enum expire_reflog_flags { * unlocked again. */ typedef void reflog_expiry_prepare_fn(const char *refname, - const unsigned char *sha1, + const struct object_id *oid, void *cb_data); -typedef int reflog_expiry_should_prune_fn(unsigned char *osha1, - unsigned char *nsha1, +typedef int reflog_expiry_should_prune_fn(struct object_id *ooid, + struct object_id *noid, const char *email, timestamp_t timestamp, int tz, const char *message, void *cb_data); diff --git a/refs/files-backend.c b/refs/files-backend.c index 4925e698d8..cb1f528cbe 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -195,27 +195,15 @@ static const char PACKED_REFS_HEADER[] = * Return a pointer to the refname within the line (null-terminated), * or NULL if there was a problem. */ -static const char *parse_ref_line(struct strbuf *line, unsigned char *sha1) +static const char *parse_ref_line(struct strbuf *line, struct object_id *oid) { const char *ref; - /* - * 42: the answer to everything. - * - * In this case, it happens to be the answer to - * 40 (length of sha1 hex representation) - * +1 (space in between hex and name) - * +1 (newline at the end of the line) - */ - if (line->len <= 42) + if (parse_oid_hex(line->buf, oid, &ref) < 0) return NULL; - - if (get_sha1_hex(line->buf, sha1) < 0) - return NULL; - if (!isspace(line->buf[40])) + if (!isspace(*ref++)) return NULL; - ref = line->buf + 41; if (isspace(*ref)) return NULL; @@ -260,7 +248,7 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir) enum { PEELED_NONE, PEELED_TAGS, PEELED_FULLY } peeled = PEELED_NONE; while (strbuf_getwholeline(&line, f, '\n') != EOF) { - unsigned char sha1[20]; + struct object_id oid; const char *refname; const char *traits; @@ -273,17 +261,17 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir) continue; } - refname = parse_ref_line(&line, sha1); + refname = parse_ref_line(&line, &oid); if (refname) { int flag = REF_ISPACKED; if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) { if (!refname_is_safe(refname)) die("packed refname is dangerous: %s", refname); - hashclr(sha1); + oidclr(&oid); flag |= REF_BAD_NAME | REF_ISBROKEN; } - last = create_ref_entry(refname, sha1, flag, 0); + last = create_ref_entry(refname, &oid, flag, 0); if (peeled == PEELED_FULLY || (peeled == PEELED_TAGS && starts_with(refname, "refs/tags/"))) last->flag |= REF_KNOWS_PEELED; @@ -294,8 +282,8 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir) line.buf[0] == '^' && line.len == PEELED_LINE_LENGTH && line.buf[PEELED_LINE_LENGTH - 1] == '\n' && - !get_sha1_hex(line.buf + 1, sha1)) { - hashcpy(last->u.value.peeled.hash, sha1); + !get_oid_hex(line.buf + 1, &oid)) { + oidcpy(&last->u.value.peeled, &oid); /* * Regardless of what the file header said, * we definitely know the value of *this* @@ -404,14 +392,14 @@ static struct ref_dir *get_packed_refs(struct files_ref_store *refs) * commit_packed_refs(). */ static void add_packed_ref(struct files_ref_store *refs, - const char *refname, const unsigned char *sha1) + const char *refname, const struct object_id *oid) { struct packed_ref_cache *packed_ref_cache = get_packed_ref_cache(refs); if (!packed_ref_cache->lock) die("internal error: packed refs not locked"); add_ref_entry(get_packed_ref_dir(packed_ref_cache), - create_ref_entry(refname, sha1, REF_ISPACKED, 1)); + create_ref_entry(refname, oid, REF_ISPACKED, 1)); } /* @@ -444,7 +432,7 @@ static void loose_fill_ref_dir(struct ref_store *ref_store, strbuf_add(&refname, dirname, dirnamelen); while ((de = readdir(d)) != NULL) { - unsigned char sha1[20]; + struct object_id oid; struct stat st; int flag; @@ -465,10 +453,10 @@ static void loose_fill_ref_dir(struct ref_store *ref_store, if (!refs_resolve_ref_unsafe(&refs->base, refname.buf, RESOLVE_REF_READING, - sha1, &flag)) { - hashclr(sha1); + oid.hash, &flag)) { + oidclr(&oid); flag |= REF_ISBROKEN; - } else if (is_null_sha1(sha1)) { + } else if (is_null_oid(&oid)) { /* * It is so astronomically unlikely * that NULL_SHA1 is the SHA-1 of an @@ -484,11 +472,11 @@ static void loose_fill_ref_dir(struct ref_store *ref_store, REFNAME_ALLOW_ONELEVEL)) { if (!refname_is_safe(refname.buf)) die("loose refname is dangerous: %s", refname.buf); - hashclr(sha1); + oidclr(&oid); flag |= REF_BAD_NAME | REF_ISBROKEN; } add_entry_to_dir(dir, - create_ref_entry(refname.buf, sha1, flag, 0)); + create_ref_entry(refname.buf, &oid, flag, 0)); } strbuf_setlen(&refname, dirnamelen); strbuf_setlen(&path, path_baselen); @@ -1526,7 +1514,7 @@ static int files_pack_refs(struct ref_store *ref_store, unsigned int flags) packed_entry->flag = REF_ISPACKED; oidcpy(&packed_entry->u.value.oid, iter->oid); } else { - packed_entry = create_ref_entry(iter->refname, iter->oid->hash, + packed_entry = create_ref_entry(iter->refname, iter->oid, REF_ISPACKED, 0); add_ref_entry(packed_refs, packed_entry); } @@ -1709,10 +1697,10 @@ static int rename_tmp_log(struct files_ref_store *refs, const char *newrefname) } static int write_ref_to_lockfile(struct ref_lock *lock, - const unsigned char *sha1, struct strbuf *err); + const struct object_id *oid, struct strbuf *err); static int commit_ref_update(struct files_ref_store *refs, struct ref_lock *lock, - const unsigned char *sha1, const char *logmsg, + const struct object_id *oid, const char *logmsg, struct strbuf *err); static int files_rename_ref(struct ref_store *ref_store, @@ -1721,7 +1709,7 @@ static int files_rename_ref(struct ref_store *ref_store, { struct files_ref_store *refs = files_downcast(ref_store, REF_STORE_WRITE, "rename_ref"); - unsigned char sha1[20], orig_sha1[20]; + struct object_id oid, orig_oid; int flag = 0, logmoved = 0; struct ref_lock *lock; struct stat loginfo; @@ -1743,7 +1731,7 @@ static int files_rename_ref(struct ref_store *ref_store, if (!refs_resolve_ref_unsafe(&refs->base, oldrefname, RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE, - orig_sha1, &flag)) { + orig_oid.hash, &flag)) { ret = error("refname %s not found", oldrefname); goto out; } @@ -1765,21 +1753,21 @@ static int files_rename_ref(struct ref_store *ref_store, } if (refs_delete_ref(&refs->base, logmsg, oldrefname, - orig_sha1, REF_NODEREF)) { + orig_oid.hash, REF_NODEREF)) { error("unable to delete old %s", oldrefname); goto rollback; } /* - * Since we are doing a shallow lookup, sha1 is not the - * correct value to pass to delete_ref as old_sha1. But that - * doesn't matter, because an old_sha1 check wouldn't add to + * Since we are doing a shallow lookup, oid is not the + * correct value to pass to delete_ref as old_oid. But that + * doesn't matter, because an old_oid check wouldn't add to * the safety anyway; we want to delete the reference whatever * its current value. */ if (!refs_read_ref_full(&refs->base, newrefname, RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE, - sha1, NULL) && + oid.hash, NULL) && refs_delete_ref(&refs->base, NULL, newrefname, NULL, REF_NODEREF)) { if (errno == EISDIR) { @@ -1812,10 +1800,10 @@ static int files_rename_ref(struct ref_store *ref_store, strbuf_release(&err); goto rollback; } - hashcpy(lock->old_oid.hash, orig_sha1); + oidcpy(&lock->old_oid, &orig_oid); - if (write_ref_to_lockfile(lock, orig_sha1, &err) || - commit_ref_update(refs, lock, orig_sha1, logmsg, &err)) { + if (write_ref_to_lockfile(lock, &orig_oid, &err) || + commit_ref_update(refs, lock, &orig_oid, logmsg, &err)) { error("unable to write current sha1 into %s: %s", newrefname, err.buf); strbuf_release(&err); goto rollback; @@ -1835,8 +1823,8 @@ static int files_rename_ref(struct ref_store *ref_store, flag = log_all_ref_updates; log_all_ref_updates = LOG_REFS_NONE; - if (write_ref_to_lockfile(lock, orig_sha1, &err) || - commit_ref_update(refs, lock, orig_sha1, NULL, &err)) { + if (write_ref_to_lockfile(lock, &orig_oid, &err) || + commit_ref_update(refs, lock, &orig_oid, NULL, &err)) { error("unable to write current sha1 into %s: %s", oldrefname, err.buf); strbuf_release(&err); } @@ -1986,8 +1974,8 @@ static int files_create_reflog(struct ref_store *ref_store, return 0; } -static int log_ref_write_fd(int fd, const unsigned char *old_sha1, - const unsigned char *new_sha1, +static int log_ref_write_fd(int fd, const struct object_id *old_oid, + const struct object_id *new_oid, const char *committer, const char *msg) { int msglen, written; @@ -1998,8 +1986,8 @@ static int log_ref_write_fd(int fd, const unsigned char *old_sha1, maxlen = strlen(committer) + msglen + 100; logrec = xmalloc(maxlen); len = xsnprintf(logrec, maxlen, "%s %s %s\n", - sha1_to_hex(old_sha1), - sha1_to_hex(new_sha1), + oid_to_hex(old_oid), + oid_to_hex(new_oid), committer); if (msglen) len += copy_reflog_msg(logrec + len - 1, msg) - 1; @@ -2013,8 +2001,8 @@ static int log_ref_write_fd(int fd, const unsigned char *old_sha1, } static int files_log_ref_write(struct files_ref_store *refs, - const char *refname, const unsigned char *old_sha1, - const unsigned char *new_sha1, const char *msg, + const char *refname, const struct object_id *old_oid, + const struct object_id *new_oid, const char *msg, int flags, struct strbuf *err) { int logfd, result; @@ -2031,7 +2019,7 @@ static int files_log_ref_write(struct files_ref_store *refs, if (logfd < 0) return 0; - result = log_ref_write_fd(logfd, old_sha1, new_sha1, + result = log_ref_write_fd(logfd, old_oid, new_oid, git_committer_info(0), msg); if (result) { struct strbuf sb = STRBUF_INIT; @@ -2063,29 +2051,29 @@ static int files_log_ref_write(struct files_ref_store *refs, * return -1. */ static int write_ref_to_lockfile(struct ref_lock *lock, - const unsigned char *sha1, struct strbuf *err) + const struct object_id *oid, struct strbuf *err) { static char term = '\n'; struct object *o; int fd; - o = parse_object(sha1); + o = parse_object(oid); if (!o) { strbuf_addf(err, "trying to write ref '%s' with nonexistent object %s", - lock->ref_name, sha1_to_hex(sha1)); + lock->ref_name, oid_to_hex(oid)); unlock_ref(lock); return -1; } if (o->type != OBJ_COMMIT && is_branch(lock->ref_name)) { strbuf_addf(err, "trying to write non-commit object %s to branch '%s'", - sha1_to_hex(sha1), lock->ref_name); + oid_to_hex(oid), lock->ref_name); unlock_ref(lock); return -1; } fd = get_lock_file_fd(lock->lk); - if (write_in_full(fd, sha1_to_hex(sha1), 40) != 40 || + if (write_in_full(fd, oid_to_hex(oid), GIT_SHA1_HEXSZ) != GIT_SHA1_HEXSZ || write_in_full(fd, &term, 1) != 1 || close_ref(lock) < 0) { strbuf_addf(err, @@ -2103,14 +2091,14 @@ static int write_ref_to_lockfile(struct ref_lock *lock, */ static int commit_ref_update(struct files_ref_store *refs, struct ref_lock *lock, - const unsigned char *sha1, const char *logmsg, + const struct object_id *oid, const char *logmsg, struct strbuf *err) { files_assert_main_repository(refs, "commit_ref_update"); clear_loose_ref_cache(refs); if (files_log_ref_write(refs, lock->ref_name, - lock->old_oid.hash, sha1, + &lock->old_oid, oid, logmsg, 0, err)) { char *old_msg = strbuf_detach(err, NULL); strbuf_addf(err, "cannot update the ref '%s': %s", @@ -2133,18 +2121,18 @@ static int commit_ref_update(struct files_ref_store *refs, * check with HEAD only which should cover 99% of all usage * scenarios (even 100% of the default ones). */ - unsigned char head_sha1[20]; + struct object_id head_oid; int head_flag; const char *head_ref; head_ref = refs_resolve_ref_unsafe(&refs->base, "HEAD", RESOLVE_REF_READING, - head_sha1, &head_flag); + head_oid.hash, &head_flag); if (head_ref && (head_flag & REF_ISSYMREF) && !strcmp(head_ref, lock->ref_name)) { struct strbuf log_err = STRBUF_INIT; if (files_log_ref_write(refs, "HEAD", - lock->old_oid.hash, sha1, + &lock->old_oid, oid, logmsg, 0, &log_err)) { error("%s", log_err.buf); strbuf_release(&log_err); @@ -2182,12 +2170,12 @@ static void update_symref_reflog(struct files_ref_store *refs, const char *target, const char *logmsg) { struct strbuf err = STRBUF_INIT; - unsigned char new_sha1[20]; + struct object_id new_oid; if (logmsg && !refs_read_ref_full(&refs->base, target, - RESOLVE_REF_READING, new_sha1, NULL) && - files_log_ref_write(refs, refname, lock->old_oid.hash, - new_sha1, logmsg, 0, &err)) { + RESOLVE_REF_READING, new_oid.hash, NULL) && + files_log_ref_write(refs, refname, &lock->old_oid, + &new_oid, logmsg, 0, &err)) { error("%s", err.buf); strbuf_release(&err); } @@ -2589,7 +2577,7 @@ static int split_head_update(struct ref_update *update, new_update = ref_transaction_add_update( transaction, "HEAD", update->flags | REF_LOG_ONLY | REF_NODEREF, - update->new_sha1, update->old_sha1, + update->new_oid.hash, update->old_oid.hash, update->msg); item->util = new_update; @@ -2646,7 +2634,7 @@ static int split_symref_update(struct files_ref_store *refs, new_update = ref_transaction_add_update( transaction, referent, new_flags, - update->new_sha1, update->old_sha1, + update->new_oid.hash, update->old_oid.hash, update->msg); new_update->parent_update = update; @@ -2685,10 +2673,10 @@ static int check_old_oid(struct ref_update *update, struct object_id *oid, struct strbuf *err) { if (!(update->flags & REF_HAVE_OLD) || - !hashcmp(oid->hash, update->old_sha1)) + !oidcmp(oid, &update->old_oid)) return 0; - if (is_null_sha1(update->old_sha1)) + if (is_null_oid(&update->old_oid)) strbuf_addf(err, "cannot lock ref '%s': " "reference already exists", original_update_refname(update)); @@ -2696,13 +2684,13 @@ static int check_old_oid(struct ref_update *update, struct object_id *oid, strbuf_addf(err, "cannot lock ref '%s': " "reference is missing but expected %s", original_update_refname(update), - sha1_to_hex(update->old_sha1)); + oid_to_hex(&update->old_oid)); else strbuf_addf(err, "cannot lock ref '%s': " "is at %s but expected %s", original_update_refname(update), oid_to_hex(oid), - sha1_to_hex(update->old_sha1)); + oid_to_hex(&update->old_oid)); return -1; } @@ -2729,13 +2717,13 @@ static int lock_ref_for_update(struct files_ref_store *refs, { struct strbuf referent = STRBUF_INIT; int mustexist = (update->flags & REF_HAVE_OLD) && - !is_null_sha1(update->old_sha1); + !is_null_oid(&update->old_oid); int ret; struct ref_lock *lock; files_assert_main_repository(refs, "lock_ref_for_update"); - if ((update->flags & REF_HAVE_NEW) && is_null_sha1(update->new_sha1)) + if ((update->flags & REF_HAVE_NEW) && is_null_oid(&update->new_oid)) update->flags |= REF_DELETING; if (head_ref) { @@ -2817,12 +2805,12 @@ static int lock_ref_for_update(struct files_ref_store *refs, !(update->flags & REF_DELETING) && !(update->flags & REF_LOG_ONLY)) { if (!(update->type & REF_ISSYMREF) && - !hashcmp(lock->old_oid.hash, update->new_sha1)) { + !oidcmp(&lock->old_oid, &update->new_oid)) { /* * The reference already has the desired * value, so we don't need to write it. */ - } else if (write_ref_to_lockfile(lock, update->new_sha1, + } else if (write_ref_to_lockfile(lock, &update->new_oid, err)) { char *write_err = strbuf_detach(err, NULL); @@ -2957,8 +2945,8 @@ static int files_transaction_commit(struct ref_store *ref_store, update->flags & REF_LOG_ONLY) { if (files_log_ref_write(refs, lock->ref_name, - lock->old_oid.hash, - update->new_sha1, + &lock->old_oid, + &update->new_oid, update->msg, update->flags, err)) { char *old_msg = strbuf_detach(err, NULL); @@ -3107,7 +3095,7 @@ static int files_initial_transaction_commit(struct ref_store *ref_store, struct ref_update *update = transaction->updates[i]; if ((update->flags & REF_HAVE_OLD) && - !is_null_sha1(update->old_sha1)) + !is_null_oid(&update->old_oid)) die("BUG: initial ref transaction with old_sha1 set"); if (refs_verify_refname_available(&refs->base, update->refname, &affected_refnames, NULL, @@ -3128,8 +3116,9 @@ static int files_initial_transaction_commit(struct ref_store *ref_store, struct ref_update *update = transaction->updates[i]; if ((update->flags & REF_HAVE_NEW) && - !is_null_sha1(update->new_sha1)) - add_packed_ref(refs, update->refname, update->new_sha1); + !is_null_oid(&update->new_oid)) + add_packed_ref(refs, update->refname, + &update->new_oid); } if (commit_packed_refs(refs)) { @@ -3163,7 +3152,7 @@ static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid, if (cb->flags & EXPIRE_REFLOGS_REWRITE) ooid = &cb->last_kept_oid; - if ((*cb->should_prune_fn)(ooid->hash, noid->hash, email, timestamp, tz, + if ((*cb->should_prune_fn)(ooid, noid, email, timestamp, tz, message, policy_cb)) { if (!cb->newlog) printf("would prune %s", message); @@ -3200,6 +3189,7 @@ static int files_reflog_expire(struct ref_store *ref_store, int status = 0; int type; struct strbuf err = STRBUF_INIT; + struct object_id oid; memset(&cb, 0, sizeof(cb)); cb.flags = flags; @@ -3249,7 +3239,9 @@ static int files_reflog_expire(struct ref_store *ref_store, } } - (*prepare_fn)(refname, sha1, cb.policy_cb); + hashcpy(oid.hash, sha1); + + (*prepare_fn)(refname, &oid, cb.policy_cb); refs_for_each_reflog_ent(ref_store, refname, expire_reflog_ent, &cb); (*cleanup_fn)(cb.policy_cb); diff --git a/refs/ref-cache.c b/refs/ref-cache.c index 6059362f1d..6b11d9cd12 100644 --- a/refs/ref-cache.c +++ b/refs/ref-cache.c @@ -32,7 +32,7 @@ struct ref_dir *get_ref_dir(struct ref_entry *entry) } struct ref_entry *create_ref_entry(const char *refname, - const unsigned char *sha1, int flag, + const struct object_id *oid, int flag, int check_name) { struct ref_entry *ref; @@ -41,7 +41,7 @@ struct ref_entry *create_ref_entry(const char *refname, check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) die("Reference has invalid format: '%s'", refname); FLEX_ALLOC_STR(ref, name, refname); - hashcpy(ref->u.value.oid.hash, sha1); + oidcpy(&ref->u.value.oid, oid); oidclr(&ref->u.value.peeled); ref->flag = flag; return ref; diff --git a/refs/ref-cache.h b/refs/ref-cache.h index ffdc54f3f0..1f65e2f9ed 100644 --- a/refs/ref-cache.h +++ b/refs/ref-cache.h @@ -185,7 +185,7 @@ struct ref_entry *create_dir_entry(struct ref_cache *cache, int incomplete); struct ref_entry *create_ref_entry(const char *refname, - const unsigned char *sha1, int flag, + const struct object_id *oid, int flag, int check_name); /* diff --git a/refs/refs-internal.h b/refs/refs-internal.h index 12cf4e4718..b6b291cf00 100644 --- a/refs/refs-internal.h +++ b/refs/refs-internal.h @@ -130,13 +130,13 @@ struct ref_update { /* * If (flags & REF_HAVE_NEW), set the reference to this value: */ - unsigned char new_sha1[20]; + struct object_id new_oid; /* * If (flags & REF_HAVE_OLD), check that the reference * previously had this value: */ - unsigned char old_sha1[20]; + struct object_id old_oid; /* * One or more of REF_HAVE_NEW, REF_HAVE_OLD, REF_NODEREF, @@ -1296,7 +1296,7 @@ static void add_to_tips(struct tips *tips, const struct object_id *oid) if (is_null_oid(oid)) return; - commit = lookup_commit_reference_gently(oid->hash, 1); + commit = lookup_commit_reference_gently(oid, 1); if (!commit || (commit->object.flags & TMP_MARK)) return; commit->object.flags |= TMP_MARK; @@ -1358,7 +1358,8 @@ static void add_missing_tags(struct ref *src, struct ref **dst, struct ref ***ds if (is_null_oid(&ref->new_oid)) continue; - commit = lookup_commit_reference_gently(ref->new_oid.hash, 1); + commit = lookup_commit_reference_gently(&ref->new_oid, + 1); if (!commit) /* not pushing a commit, which is not an error */ continue; @@ -1585,8 +1586,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror, reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS; else if (!has_object_file(&ref->old_oid)) reject_reason = REF_STATUS_REJECT_FETCH_FIRST; - else if (!lookup_commit_reference_gently(ref->old_oid.hash, 1) || - !lookup_commit_reference_gently(ref->new_oid.hash, 1)) + else if (!lookup_commit_reference_gently(&ref->old_oid, 1) || + !lookup_commit_reference_gently(&ref->new_oid, 1)) reject_reason = REF_STATUS_REJECT_NEEDS_FORCE; else if (!ref_newer(&ref->new_oid, &ref->old_oid)) reject_reason = REF_STATUS_REJECT_NONFASTFORWARD; @@ -1953,12 +1954,12 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid) * Both new and old must be commit-ish and new is descendant of * old. Otherwise we require --force. */ - o = deref_tag(parse_object(old_oid->hash), NULL, 0); + o = deref_tag(parse_object(old_oid), NULL, 0); if (!o || o->type != OBJ_COMMIT) return 0; old = (struct commit *) o; - o = deref_tag(parse_object(new_oid->hash), NULL, 0); + o = deref_tag(parse_object(new_oid), NULL, 0); if (!o || o->type != OBJ_COMMIT) return 0; new = (struct commit *) o; @@ -2009,13 +2010,13 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs, /* Cannot stat if what we used to build on no longer exists */ if (read_ref(base, oid.hash)) return -1; - theirs = lookup_commit_reference(oid.hash); + theirs = lookup_commit_reference(&oid); if (!theirs) return -1; if (read_ref(branch->refname, oid.hash)) return -1; - ours = lookup_commit_reference(oid.hash); + ours = lookup_commit_reference(&oid); if (!ours) return -1; diff --git a/revision.c b/revision.c index 8a8c1789c7..9c67cb6026 100644 --- a/revision.c +++ b/revision.c @@ -59,10 +59,10 @@ static void mark_tree_contents_uninteresting(struct tree *tree) while (tree_entry(&desc, &entry)) { switch (object_type(entry.mode)) { case OBJ_TREE: - mark_tree_uninteresting(lookup_tree(entry.oid->hash)); + mark_tree_uninteresting(lookup_tree(entry.oid)); break; case OBJ_BLOB: - mark_blob_uninteresting(lookup_blob(entry.oid->hash)); + mark_blob_uninteresting(lookup_blob(entry.oid)); break; default: /* Subproject commit - not in this repository */ @@ -177,23 +177,23 @@ void add_pending_object(struct rev_info *revs, void add_head_to_pending(struct rev_info *revs) { - unsigned char sha1[20]; + struct object_id oid; struct object *obj; - if (get_sha1("HEAD", sha1)) + if (get_oid("HEAD", &oid)) return; - obj = parse_object(sha1); + obj = parse_object(&oid); if (!obj) return; add_pending_object(revs, obj, "HEAD"); } static struct object *get_reference(struct rev_info *revs, const char *name, - const unsigned char *sha1, + const struct object_id *oid, unsigned int flags) { struct object *object; - object = parse_object(sha1); + object = parse_object(oid); if (!object) { if (revs->ignore_missing) return object; @@ -203,10 +203,10 @@ static struct object *get_reference(struct rev_info *revs, const char *name, return object; } -void add_pending_sha1(struct rev_info *revs, const char *name, - const unsigned char *sha1, unsigned int flags) +void add_pending_oid(struct rev_info *revs, const char *name, + const struct object_id *oid, unsigned int flags) { - struct object *object = get_reference(revs, name, sha1, flags); + struct object *object = get_reference(revs, name, oid, flags); add_pending_object(revs, object, name); } @@ -228,7 +228,7 @@ static struct commit *handle_commit(struct rev_info *revs, add_pending_object(revs, object, tag->tag); if (!tag->tagged) die("bad tag"); - object = parse_object(tag->tagged->oid.hash); + object = parse_object(&tag->tagged->oid); if (!object) { if (flags & UNINTERESTING) return NULL; @@ -1157,9 +1157,9 @@ static int handle_one_ref(const char *path, const struct object_id *oid, if (ref_excluded(cb->all_revs->ref_excludes, path)) return 0; - object = get_reference(cb->all_revs, path, oid->hash, cb->all_flags); + object = get_reference(cb->all_revs, path, oid, cb->all_flags); add_rev_cmdline(cb->all_revs, object, path, REV_CMD_REF, cb->all_flags); - add_pending_sha1(cb->all_revs, path, oid->hash, cb->all_flags); + add_pending_oid(cb->all_revs, path, oid, cb->all_flags); return 0; } @@ -1200,7 +1200,7 @@ static void handle_one_reflog_commit(struct object_id *oid, void *cb_data) { struct all_refs_cb *cb = cb_data; if (!is_null_oid(oid)) { - struct object *o = parse_object(oid->hash); + struct object *o = parse_object(oid); if (o) { o->flags |= cb->all_flags; /* ??? CMDLINEFLAGS ??? */ @@ -1249,7 +1249,7 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs, int i; if (it->entry_count >= 0) { - struct tree *tree = lookup_tree(it->sha1); + struct tree *tree = lookup_tree(&it->oid); add_pending_object_with_path(revs, &tree->object, "", 040000, path->buf); } @@ -1275,7 +1275,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned flags) if (S_ISGITLINK(ce->ce_mode)) continue; - blob = lookup_blob(ce->oid.hash); + blob = lookup_blob(&ce->oid); if (!blob) die("unable to add index blob to traversal"); add_pending_object_with_path(revs, &blob->object, "", @@ -1292,7 +1292,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned flags) static int add_parents_only(struct rev_info *revs, const char *arg_, int flags, int exclude_parent) { - unsigned char sha1[20]; + struct object_id oid; struct object *it; struct commit *commit; struct commit_list *parents; @@ -1303,17 +1303,17 @@ static int add_parents_only(struct rev_info *revs, const char *arg_, int flags, flags ^= UNINTERESTING | BOTTOM; arg++; } - if (get_sha1_committish(arg, sha1)) + if (get_sha1_committish(arg, oid.hash)) return 0; while (1) { - it = get_reference(revs, arg, sha1, 0); + it = get_reference(revs, arg, &oid, 0); if (!it && revs->ignore_missing) return 0; if (it->type != OBJ_TAG) break; if (!((struct tag*)it)->tagged) return 0; - hashcpy(sha1, ((struct tag*)it)->tagged->oid.hash); + oidcpy(&oid, &((struct tag*)it)->tagged->oid); } if (it->type != OBJ_COMMIT) return 0; @@ -1389,16 +1389,16 @@ static void prepare_show_merge(struct rev_info *revs) { struct commit_list *bases; struct commit *head, *other; - unsigned char sha1[20]; + struct object_id oid; const char **prune = NULL; int i, prune_num = 1; /* counting terminating NULL */ - if (get_sha1("HEAD", sha1)) + if (get_oid("HEAD", &oid)) die("--merge without HEAD?"); - head = lookup_commit_or_die(sha1, "HEAD"); - if (get_sha1("MERGE_HEAD", sha1)) + head = lookup_commit_or_die(&oid, "HEAD"); + if (get_oid("MERGE_HEAD", &oid)) die("--merge without MERGE_HEAD?"); - other = lookup_commit_or_die(sha1, "MERGE_HEAD"); + other = lookup_commit_or_die(&oid, "MERGE_HEAD"); add_pending_object(revs, &head->object, "HEAD"); add_pending_object(revs, &other->object, "MERGE_HEAD"); bases = get_merge_bases(head, other); @@ -1434,7 +1434,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi struct object_context oc; char *dotdot; struct object *object; - unsigned char sha1[20]; + struct object_id oid; int local_flags; const char *arg = arg_; int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME; @@ -1444,7 +1444,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi dotdot = strstr(arg, ".."); if (dotdot) { - unsigned char from_sha1[20]; + struct object_id from_oid; const char *next = dotdot + 2; const char *this = arg; int symmetric = *next == '.'; @@ -1470,8 +1470,8 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi return -1; } } - if (!get_sha1_committish(this, from_sha1) && - !get_sha1_committish(next, sha1)) { + if (!get_sha1_committish(this, from_oid.hash) && + !get_sha1_committish(next, oid.hash)) { struct object *a_obj, *b_obj; if (!cant_be_filename) { @@ -1479,8 +1479,8 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi verify_non_filename(revs->prefix, arg); } - a_obj = parse_object(from_sha1); - b_obj = parse_object(sha1); + a_obj = parse_object(&from_oid); + b_obj = parse_object(&oid); if (!a_obj || !b_obj) { missing: if (revs->ignore_missing) @@ -1500,10 +1500,10 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi a = (a_obj->type == OBJ_COMMIT ? (struct commit *)a_obj - : lookup_commit_reference(a_obj->oid.hash)); + : lookup_commit_reference(&a_obj->oid)); b = (b_obj->type == OBJ_COMMIT ? (struct commit *)b_obj - : lookup_commit_reference(b_obj->oid.hash)); + : lookup_commit_reference(&b_obj->oid)); if (!a || !b) goto missing; exclude = get_merge_bases(a, b); @@ -1568,11 +1568,11 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi if (revarg_opt & REVARG_COMMITTISH) get_sha1_flags = GET_SHA1_COMMITTISH; - if (get_sha1_with_context(arg, get_sha1_flags, sha1, &oc)) + if (get_sha1_with_context(arg, get_sha1_flags, oid.hash, &oc)) return revs->ignore_missing ? 0 : -1; if (!cant_be_filename) verify_non_filename(revs->prefix, arg); - object = get_reference(revs, arg, sha1, flags ^ local_flags); + object = get_reference(revs, arg, &oid, flags ^ local_flags); add_rev_cmdline(revs, object, arg_, REV_CMD_REV, flags ^ local_flags); add_pending_object_with_mode(revs, object, arg, oc.mode); return 0; @@ -2287,12 +2287,12 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s if (revs->show_merge) prepare_show_merge(revs); if (revs->def && !revs->pending.nr && !got_rev_arg) { - unsigned char sha1[20]; + struct object_id oid; struct object *object; struct object_context oc; - if (get_sha1_with_context(revs->def, 0, sha1, &oc)) + if (get_sha1_with_context(revs->def, 0, oid.hash, &oc)) diagnose_missing_default(revs->def); - object = get_reference(revs, revs->def, sha1, 0); + object = get_reference(revs, revs->def, &oid, 0); add_pending_object_with_mode(revs, object, revs->def, oc.mode); } diff --git a/revision.h b/revision.h index 0d9e68b36e..a91dd3d5d9 100644 --- a/revision.h +++ b/revision.h @@ -263,9 +263,9 @@ extern void show_object_with_name(FILE *, struct object *, const char *); extern void add_pending_object(struct rev_info *revs, struct object *obj, const char *name); -extern void add_pending_sha1(struct rev_info *revs, - const char *name, const unsigned char *sha1, - unsigned int flags); +extern void add_pending_oid(struct rev_info *revs, + const char *name, const struct object_id *oid, + unsigned int flags); extern void add_head_to_pending(struct rev_info *); extern void add_reflogs_to_pending(struct rev_info *, unsigned int flags); diff --git a/sequencer.c b/sequencer.c index 0fa3fb14f7..9dfedbc243 100644 --- a/sequencer.c +++ b/sequencer.c @@ -344,7 +344,7 @@ static int read_oneliner(struct strbuf *buf, static struct tree *empty_tree(void) { - return lookup_tree(EMPTY_TREE_SHA1_BIN); + return lookup_tree(&empty_tree_oid); } static int error_dirty_index(struct replay_opts *opts) @@ -374,7 +374,7 @@ static void update_abort_safety_file(void) write_file(git_path_abort_safety_file(), "%s", ""); } -static int fast_forward_to(const unsigned char *to, const unsigned char *from, +static int fast_forward_to(const struct object_id *to, const struct object_id *from, int unborn, struct replay_opts *opts) { struct ref_transaction *transaction; @@ -390,7 +390,7 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from, transaction = ref_transaction_begin(&err); if (!transaction || ref_transaction_update(transaction, "HEAD", - to, unborn ? null_sha1 : from, + to->hash, unborn ? null_sha1 : from->hash, 0, sb.buf, &err) || ref_transaction_commit(transaction, &err)) { ref_transaction_free(transaction); @@ -426,7 +426,7 @@ void append_conflicts_hint(struct strbuf *msgbuf) static int do_recursive_merge(struct commit *base, struct commit *next, const char *base_label, const char *next_label, - unsigned char *head, struct strbuf *msgbuf, + struct object_id *head, struct strbuf *msgbuf, struct replay_opts *opts) { struct merge_options o; @@ -482,13 +482,13 @@ static int do_recursive_merge(struct commit *base, struct commit *next, static int is_index_unchanged(void) { - unsigned char head_sha1[20]; + struct object_id head_oid; struct commit *head_commit; - if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_sha1, NULL)) + if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL)) return error(_("could not resolve HEAD commit\n")); - head_commit = lookup_commit(head_sha1); + head_commit = lookup_commit(&head_oid); /* * If head_commit is NULL, check_commit, called from @@ -508,7 +508,8 @@ static int is_index_unchanged(void) if (cache_tree_update(&the_index, 0)) return error(_("unable to update cache tree\n")); - return !hashcmp(active_cache_tree->sha1, head_commit->tree->object.oid.hash); + return !oidcmp(&active_cache_tree->oid, + &head_commit->tree->object.oid); } static int write_author_script(const char *message) @@ -834,13 +835,13 @@ static int update_squash_messages(enum todo_command command, strbuf_splice(&buf, 0, eol - buf.buf, header.buf, header.len); strbuf_release(&header); } else { - unsigned char head[20]; + struct object_id head; struct commit *head_commit; const char *head_message, *body; - if (get_sha1("HEAD", head)) + if (get_oid("HEAD", &head)) return error(_("need a HEAD to fixup")); - if (!(head_commit = lookup_commit_reference(head))) + if (!(head_commit = lookup_commit_reference(&head))) return error(_("could not read HEAD")); if (!(head_message = get_commit_buffer(head_commit, NULL))) return error(_("could not read HEAD's commit message")); @@ -934,7 +935,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit, { unsigned int flags = opts->edit ? EDIT_MSG : 0; const char *msg_file = opts->edit ? NULL : git_path_merge_msg(); - unsigned char head[20]; + struct object_id head; struct commit *base, *next, *parent; const char *base_label, *next_label; struct commit_message msg = { NULL, NULL, NULL, NULL }; @@ -948,12 +949,12 @@ static int do_pick_commit(enum todo_command command, struct commit *commit, * that represents the "current" state for merge-recursive * to work on. */ - if (write_cache_as_tree(head, 0, NULL)) + if (write_cache_as_tree(head.hash, 0, NULL)) return error(_("your index file is unmerged.")); } else { - unborn = get_sha1("HEAD", head); + unborn = get_oid("HEAD", &head); if (unborn) - hashcpy(head, EMPTY_TREE_SHA1_BIN); + oidcpy(&head, &empty_tree_oid); if (index_differs_from(unborn ? EMPTY_TREE_SHA1_HEX : "HEAD", 0, 0)) return error_dirty_index(opts); } @@ -989,11 +990,11 @@ static int do_pick_commit(enum todo_command command, struct commit *commit, oid_to_hex(&commit->object.oid)); if (opts->allow_ff && !is_fixup(command) && - ((parent && !hashcmp(parent->object.oid.hash, head)) || + ((parent && !oidcmp(&parent->object.oid, &head)) || (!parent && unborn))) { if (is_rebase_i(opts)) write_author_script(msg.message); - res = fast_forward_to(commit->object.oid.hash, head, unborn, + res = fast_forward_to(&commit->object.oid, &head, unborn, opts); if (res || command != TODO_REWORD) goto leave; @@ -1081,7 +1082,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit, res = -1; else if (!opts->strategy || !strcmp(opts->strategy, "recursive") || command == TODO_REVERT) { res = do_recursive_merge(base, next, base_label, next_label, - head, &msgbuf, opts); + &head, &msgbuf, opts); if (res < 0) return res; res |= write_message(msgbuf.buf, msgbuf.len, @@ -1097,7 +1098,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit, commit_list_insert(next, &remotes); res |= try_merge_command(opts->strategy, opts->xopts_nr, (const char **)opts->xopts, - common, sha1_to_hex(head), remotes); + common, oid_to_hex(&head), remotes); free_commit_list(common); free_commit_list(remotes); } @@ -1222,7 +1223,7 @@ static struct todo_item *append_new_todo(struct todo_list *todo_list) static int parse_insn_line(struct todo_item *item, const char *bol, char *eol) { - unsigned char commit_sha1[20]; + struct object_id commit_oid; char *end_of_object_name; int i, saved, status, padding; @@ -1271,7 +1272,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol) end_of_object_name = (char *) bol + strcspn(bol, " \t\n"); saved = *end_of_object_name; *end_of_object_name = '\0'; - status = get_sha1(bol, commit_sha1); + status = get_oid(bol, &commit_oid); *end_of_object_name = saved; item->arg = end_of_object_name + strspn(end_of_object_name, " \t"); @@ -1280,7 +1281,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol) if (status < 0) return -1; - item->commit = lookup_commit_reference(commit_sha1); + item->commit = lookup_commit_reference(&commit_oid); return !item->commit; } @@ -2281,7 +2282,7 @@ static int single_pick(struct commit *cmit, struct replay_opts *opts) int sequencer_pick_revisions(struct replay_opts *opts) { struct todo_list todo_list = TODO_LIST_INIT; - unsigned char sha1[20]; + struct object_id oid; int i, res; assert(opts->revs); @@ -2289,16 +2290,16 @@ int sequencer_pick_revisions(struct replay_opts *opts) return -1; for (i = 0; i < opts->revs->pending.nr; i++) { - unsigned char sha1[20]; + struct object_id oid; const char *name = opts->revs->pending.objects[i].name; /* This happens when using --stdin. */ if (!strlen(name)) continue; - if (!get_sha1(name, sha1)) { - if (!lookup_commit_reference_gently(sha1, 1)) { - enum object_type type = sha1_object_info(sha1, NULL); + if (!get_oid(name, &oid)) { + if (!lookup_commit_reference_gently(&oid, 1)) { + enum object_type type = sha1_object_info(oid.hash, NULL); return error(_("%s: can't cherry-pick a %s"), name, typename(type)); } @@ -2335,9 +2336,9 @@ int sequencer_pick_revisions(struct replay_opts *opts) if (walk_revs_populate_todo(&todo_list, opts) || create_seq_dir() < 0) return -1; - if (get_sha1("HEAD", sha1) && (opts->action == REPLAY_REVERT)) + if (get_oid("HEAD", &oid) && (opts->action == REPLAY_REVERT)) return error(_("can't revert as initial commit")); - if (save_head(sha1_to_hex(sha1))) + if (save_head(oid_to_hex(&oid))) return -1; if (save_opts(opts)) return -1; diff --git a/server-info.c b/server-info.c index f6c1a3dfb0..6f865b73a3 100644 --- a/server-info.c +++ b/server-info.c @@ -53,7 +53,7 @@ static int add_info_ref(const char *path, const struct object_id *oid, int flag, void *cb_data) { FILE *fp = cb_data; - struct object *o = parse_object(oid->hash); + struct object *o = parse_object(oid); if (!o) return -1; diff --git a/sha1_name.c b/sha1_name.c index 35c1e2a9e3..389276e9d3 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -241,7 +241,7 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da return 0; /* We need to do this the hard way... */ - obj = deref_tag(parse_object(oid->hash), NULL, 0); + obj = deref_tag(parse_object(oid), NULL, 0); if (obj && obj->type == OBJ_COMMIT) return 1; return 0; @@ -265,7 +265,7 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_ return 0; /* We need to do this the hard way... */ - obj = deref_tag(parse_object(oid->hash), NULL, 0); + obj = deref_tag(parse_object(oid), NULL, 0); if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT)) return 1; return 0; @@ -354,14 +354,14 @@ static int show_ambiguous_object(const struct object_id *oid, void *data) type = sha1_object_info(oid->hash, NULL); if (type == OBJ_COMMIT) { - struct commit *commit = lookup_commit(oid->hash); + struct commit *commit = lookup_commit(oid); if (commit) { struct pretty_print_context pp = {0}; pp.date_mode.type = DATE_SHORT; format_commit_message(commit, " %ad - %s", &desc, &pp); } } else if (type == OBJ_TAG) { - struct tag *tag = lookup_tag(oid->hash); + struct tag *tag = lookup_tag(oid); if (!parse_tag(tag) && tag->tag) strbuf_addf(&desc, " %s", tag->tag); } @@ -722,14 +722,14 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1, static int get_parent(const char *name, int len, unsigned char *result, int idx) { - unsigned char sha1[20]; - int ret = get_sha1_1(name, len, sha1, GET_SHA1_COMMITTISH); + struct object_id oid; + int ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH); struct commit *commit; struct commit_list *p; if (ret) return ret; - commit = lookup_commit_reference(sha1); + commit = lookup_commit_reference(&oid); if (parse_commit(commit)) return -1; if (!idx) { @@ -750,14 +750,14 @@ static int get_parent(const char *name, int len, static int get_nth_ancestor(const char *name, int len, unsigned char *result, int generation) { - unsigned char sha1[20]; + struct object_id oid; struct commit *commit; int ret; - ret = get_sha1_1(name, len, sha1, GET_SHA1_COMMITTISH); + ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH); if (ret) return ret; - commit = lookup_commit_reference(sha1); + commit = lookup_commit_reference(&oid); if (!commit) return -1; @@ -776,7 +776,7 @@ struct object *peel_to_type(const char *name, int namelen, if (name && !namelen) namelen = strlen(name); while (1) { - if (!o || (!o->parsed && !parse_object(o->oid.hash))) + if (!o || (!o->parsed && !parse_object(&o->oid))) return NULL; if (expected_type == OBJ_ANY || o->type == expected_type) return o; @@ -798,7 +798,7 @@ struct object *peel_to_type(const char *name, int namelen, static int peel_onion(const char *name, int len, unsigned char *sha1, unsigned lookup_flags) { - unsigned char outer[20]; + struct object_id outer; const char *sp; unsigned int expected_type = 0; struct object *o; @@ -846,15 +846,15 @@ static int peel_onion(const char *name, int len, unsigned char *sha1, else if (expected_type == OBJ_TREE) lookup_flags |= GET_SHA1_TREEISH; - if (get_sha1_1(name, sp - name - 2, outer, lookup_flags)) + if (get_sha1_1(name, sp - name - 2, outer.hash, lookup_flags)) return -1; - o = parse_object(outer); + o = parse_object(&outer); if (!o) return -1; if (!expected_type) { o = deref_tag(o, name, sp - name - 2); - if (!o || (!o->parsed && !parse_object(o->oid.hash))) + if (!o || (!o->parsed && !parse_object(&o->oid))) return -1; hashcpy(sha1, o->oid.hash); return 0; @@ -981,7 +981,7 @@ static int handle_one_ref(const char *path, const struct object_id *oid, int flag, void *cb_data) { struct commit_list **list = cb_data; - struct object *object = parse_object(oid->hash); + struct object *object = parse_object(oid); if (!object) return 0; if (object->type == OBJ_TAG) { @@ -1027,7 +1027,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1, int matches; commit = pop_most_recent_commit(&list, ONELINE_SEEN); - if (!parse_object(commit->object.oid.hash)) + if (!parse_object(&commit->object.oid)) continue; buf = get_commit_buffer(commit, NULL); p = strstr(buf, "\n\n"); @@ -1136,13 +1136,13 @@ int get_oid_mb(const char *name, struct object_id *oid) } if (st) return st; - one = lookup_commit_reference_gently(oid_tmp.hash, 0); + one = lookup_commit_reference_gently(&oid_tmp, 0); if (!one) return -1; if (get_sha1_committish(dots[3] ? (dots + 3) : "HEAD", oid_tmp.hash)) return -1; - two = lookup_commit_reference_gently(oid_tmp.hash, 0); + two = lookup_commit_reference_gently(&oid_tmp, 0); if (!two) return -1; mbs = get_merge_bases(one, two); @@ -27,13 +27,13 @@ void set_alternate_shallow_file(const char *path, int override) alternate_shallow_file = xstrdup_or_null(path); } -int register_shallow(const unsigned char *sha1) +int register_shallow(const struct object_id *oid) { struct commit_graft *graft = xmalloc(sizeof(struct commit_graft)); - struct commit *commit = lookup_commit(sha1); + struct commit *commit = lookup_commit(oid); - hashcpy(graft->oid.hash, sha1); + oidcpy(&graft->oid, oid); graft->nr_parent = -1; if (commit && commit->object.parsed) commit->parents = NULL; @@ -65,10 +65,10 @@ int is_repository_shallow(void) is_shallow = 1; while (fgets(buf, sizeof(buf), fp)) { - unsigned char sha1[20]; - if (get_sha1_hex(buf, sha1)) + struct object_id oid; + if (get_oid_hex(buf, &oid)) die("bad shallow line: %s", buf); - register_shallow(sha1); + register_shallow(&oid); } fclose(fp); return is_shallow; @@ -241,7 +241,7 @@ static int write_one_shallow(const struct commit_graft *graft, void *cb_data) if (graft->nr_parent != -1) return 0; if (data->flags & SEEN_ONLY) { - struct commit *c = lookup_commit(graft->oid.hash); + struct commit *c = lookup_commit(&graft->oid); if (!c || !(c->object.flags & SEEN)) { if (data->flags & VERBOSE) printf("Removing %s from .git/shallow\n", @@ -466,7 +466,7 @@ static uint32_t *paint_alloc(struct paint_info *info) * UNINTERESTING or BOTTOM is hit. Set the id-th bit in ref_bitmap for * all walked commits. */ -static void paint_down(struct paint_info *info, const unsigned char *sha1, +static void paint_down(struct paint_info *info, const struct object_id *oid, unsigned int id) { unsigned int i, nr; @@ -475,7 +475,7 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1, size_t bitmap_size = st_mult(sizeof(uint32_t), bitmap_nr); uint32_t *tmp = xmalloc(bitmap_size); /* to be freed before return */ uint32_t *bitmap = paint_alloc(info); - struct commit *c = lookup_commit_reference_gently(sha1, 1); + struct commit *c = lookup_commit_reference_gently(oid, 1); if (!c) return; memset(bitmap, 0, bitmap_size); @@ -531,7 +531,7 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1, static int mark_uninteresting(const char *refname, const struct object_id *oid, int flags, void *cb_data) { - struct commit *commit = lookup_commit_reference_gently(oid->hash, 1); + struct commit *commit = lookup_commit_reference_gently(oid, 1); if (!commit) return 0; commit->object.flags |= UNINTERESTING; @@ -599,18 +599,18 @@ void assign_shallow_commits_to_refs(struct shallow_info *info, /* Mark potential bottoms so we won't go out of bound */ for (i = 0; i < nr_shallow; i++) { - struct commit *c = lookup_commit(oid[shallow[i]].hash); + struct commit *c = lookup_commit(&oid[shallow[i]]); c->object.flags |= BOTTOM; } for (i = 0; i < ref->nr; i++) - paint_down(&pi, ref->oid[i].hash, i); + paint_down(&pi, ref->oid + i, i); if (used) { int bitmap_size = ((pi.nr_bits + 31) / 32) * sizeof(uint32_t); memset(used, 0, sizeof(*used) * info->shallow->nr); for (i = 0; i < nr_shallow; i++) { - const struct commit *c = lookup_commit(oid[shallow[i]].hash); + const struct commit *c = lookup_commit(&oid[shallow[i]]); uint32_t **map = ref_bitmap_at(&pi.ref_bitmap, c); if (*map) used[shallow[i]] = xmemdupz(*map, bitmap_size); @@ -641,7 +641,7 @@ static int add_ref(const char *refname, const struct object_id *oid, { struct commit_array *ca = cb_data; ALLOC_GROW(ca->commits, ca->nr + 1, ca->alloc); - ca->commits[ca->nr] = lookup_commit_reference_gently(oid->hash, 1); + ca->commits[ca->nr] = lookup_commit_reference_gently(oid, 1); if (ca->commits[ca->nr]) ca->nr++; return 0; @@ -679,7 +679,7 @@ static void post_assign_shallow(struct shallow_info *info, for (i = dst = 0; i < info->nr_theirs; i++) { if (i != dst) info->theirs[dst] = info->theirs[i]; - c = lookup_commit(oid[info->theirs[i]].hash); + c = lookup_commit(&oid[info->theirs[i]]); bitmap = ref_bitmap_at(ref_bitmap, c); if (!*bitmap) continue; @@ -700,7 +700,7 @@ static void post_assign_shallow(struct shallow_info *info, for (i = dst = 0; i < info->nr_ours; i++) { if (i != dst) info->ours[dst] = info->ours[i]; - c = lookup_commit(oid[info->ours[i]].hash); + c = lookup_commit(&oid[info->ours[i]]); bitmap = ref_bitmap_at(ref_bitmap, c); if (!*bitmap) continue; @@ -722,7 +722,7 @@ static void post_assign_shallow(struct shallow_info *info, int delayed_reachability_test(struct shallow_info *si, int c) { if (si->need_reachability_test[c]) { - struct commit *commit = lookup_commit(si->shallow->oid[c].hash); + struct commit *commit = lookup_commit(&si->shallow->oid[c]); if (!si->commits) { struct commit_array ca; diff --git a/submodule.c b/submodule.c index 5bb7e7a033..9d5ec5f084 100644 --- a/submodule.c +++ b/submodule.c @@ -447,8 +447,8 @@ static void show_submodule_header(FILE *f, const char *path, * Attempt to lookup the commit references, and determine if this is * a fast forward or fast backwards update. */ - *left = lookup_commit_reference(one->hash); - *right = lookup_commit_reference(two->hash); + *left = lookup_commit_reference(one); + *right = lookup_commit_reference(two); /* * Warn about missing commits in the submodule project, but only if @@ -723,7 +723,7 @@ static int check_has_commit(const struct object_id *oid, void *data) { int *has_commit = data; - if (!lookup_commit_reference(oid->hash)) + if (!lookup_commit_reference(oid)) *has_commit = 0; return 0; @@ -1584,9 +1584,9 @@ static void print_commit(struct commit *commit) #define MERGE_WARNING(path, msg) \ warning("Failed to merge submodule %s (%s)", path, msg); -int merge_submodule(unsigned char result[20], const char *path, - const unsigned char base[20], const unsigned char a[20], - const unsigned char b[20], int search) +int merge_submodule(struct object_id *result, const char *path, + const struct object_id *base, const struct object_id *a, + const struct object_id *b, int search) { struct commit *commit_base, *commit_a, *commit_b; int parent_count; @@ -1595,14 +1595,14 @@ int merge_submodule(unsigned char result[20], const char *path, int i; /* store a in result in case we fail */ - hashcpy(result, a); + oidcpy(result, a); /* we can not handle deletion conflicts */ - if (is_null_sha1(base)) + if (is_null_oid(base)) return 0; - if (is_null_sha1(a)) + if (is_null_oid(a)) return 0; - if (is_null_sha1(b)) + if (is_null_oid(b)) return 0; if (add_submodule_odb(path)) { @@ -1626,11 +1626,11 @@ int merge_submodule(unsigned char result[20], const char *path, /* Case #1: a is contained in b or vice versa */ if (in_merge_bases(commit_a, commit_b)) { - hashcpy(result, b); + oidcpy(result, b); return 1; } if (in_merge_bases(commit_b, commit_a)) { - hashcpy(result, a); + oidcpy(result, a); return 1; } diff --git a/submodule.h b/submodule.h index 1277480add..89c2ed2191 100644 --- a/submodule.h +++ b/submodule.h @@ -84,10 +84,10 @@ extern int submodule_uses_gitfile(const char *path); #define SUBMODULE_REMOVAL_IGNORE_UNTRACKED (1<<1) #define SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED (1<<2) extern int bad_to_remove_submodule(const char *path, unsigned flags); -extern int merge_submodule(unsigned char result[20], const char *path, - const unsigned char base[20], - const unsigned char a[20], - const unsigned char b[20], int search); +extern int merge_submodule(struct object_id *result, const char *path, + const struct object_id *base, + const struct object_id *a, + const struct object_id *b, int search); extern int find_unpushed_submodules(struct oid_array *commits, const char *remotes_name, struct string_list *needs_pushing); diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c index 7af116d49e..ebf3aab22d 100644 --- a/t/helper/test-dump-cache-tree.c +++ b/t/helper/test-dump-cache-tree.c @@ -10,7 +10,7 @@ static void dump_one(struct cache_tree *it, const char *pfx, const char *x) "invalid", x, pfx, it->subtree_nr); else printf("%s %s%s (%d entries, %d subtrees)\n", - sha1_to_hex(it->sha1), x, pfx, + oid_to_hex(&it->oid), x, pfx, it->entry_count, it->subtree_nr); } @@ -32,7 +32,7 @@ static int dump_cache_tree(struct cache_tree *it, } else { dump_one(it, pfx, ""); - if (hashcmp(it->sha1, ref->sha1) || + if (oidcmp(&it->oid, &ref->oid) || ref->entry_count != it->entry_count || ref->subtree_nr != it->subtree_nr) { /* claims to be valid but is lying */ diff --git a/t/helper/test-match-trees.c b/t/helper/test-match-trees.c index e939502863..356d8edef1 100644 --- a/t/helper/test-match-trees.c +++ b/t/helper/test-match-trees.c @@ -12,10 +12,10 @@ int cmd_main(int ac, const char **av) die("cannot parse %s as an object name", av[1]); if (get_oid(av[2], &hash2)) die("cannot parse %s as an object name", av[2]); - one = parse_tree_indirect(hash1.hash); + one = parse_tree_indirect(&hash1); if (!one) die("not a tree-ish %s", av[1]); - two = parse_tree_indirect(hash2.hash); + two = parse_tree_indirect(&hash2); if (!two) die("not a tree-ish %s", av[2]); @@ -66,7 +66,7 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen) { while (o && o->type == OBJ_TAG) if (((struct tag *)o)->tagged) - o = parse_object(((struct tag *)o)->tagged->oid.hash); + o = parse_object(&((struct tag *)o)->tagged->oid); else o = NULL; if (!o && warn) { @@ -80,7 +80,7 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen) struct object *deref_tag_noverify(struct object *o) { while (o && o->type == OBJ_TAG) { - o = parse_object(o->oid.hash); + o = parse_object(&o->oid); if (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged) o = ((struct tag *)o)->tagged; else @@ -89,11 +89,11 @@ struct object *deref_tag_noverify(struct object *o) return o; } -struct tag *lookup_tag(const unsigned char *sha1) +struct tag *lookup_tag(const struct object_id *oid) { - struct object *obj = lookup_object(sha1); + struct object *obj = lookup_object(oid->hash); if (!obj) - return create_object(sha1, alloc_tag_node()); + return create_object(oid->hash, alloc_tag_node()); return object_as_type(obj, OBJ_TAG, 0); } @@ -116,7 +116,7 @@ static timestamp_t parse_tag_date(const char *buf, const char *tail) int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) { - unsigned char sha1[20]; + struct object_id oid; char type[20]; const char *bufptr = data; const char *tail = bufptr + size; @@ -126,11 +126,10 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) return 0; item->object.parsed = 1; - if (size < 64) + if (size < GIT_SHA1_HEXSZ + 24) return -1; - if (memcmp("object ", bufptr, 7) || get_sha1_hex(bufptr + 7, sha1) || bufptr[47] != '\n') + if (memcmp("object ", bufptr, 7) || parse_oid_hex(bufptr + 7, &oid, &bufptr) || *bufptr++ != '\n') return -1; - bufptr += 48; /* "object " + sha1 + "\n" */ if (!starts_with(bufptr, "type ")) return -1; @@ -143,13 +142,13 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size) bufptr = nl + 1; if (!strcmp(type, blob_type)) { - item->tagged = &lookup_blob(sha1)->object; + item->tagged = &lookup_blob(&oid)->object; } else if (!strcmp(type, tree_type)) { - item->tagged = &lookup_tree(sha1)->object; + item->tagged = &lookup_tree(&oid)->object; } else if (!strcmp(type, commit_type)) { - item->tagged = &lookup_commit(sha1)->object; + item->tagged = &lookup_commit(&oid)->object; } else if (!strcmp(type, tag_type)) { - item->tagged = &lookup_tag(sha1)->object; + item->tagged = &lookup_tag(&oid)->object; } else { error("Unknown type %s", type); item->tagged = NULL; @@ -12,7 +12,7 @@ struct tag { timestamp_t date; }; -extern struct tag *lookup_tag(const unsigned char *sha1); +extern struct tag *lookup_tag(const struct object_id *oid); extern int parse_tag_buffer(struct tag *item, const void *data, unsigned long size); extern int parse_tag(struct tag *item); extern struct object *deref_tag(struct object *, const char *, int); diff --git a/transport.c b/transport.c index 4d33138a75..9bfcf870f9 100644 --- a/transport.c +++ b/transport.c @@ -87,7 +87,7 @@ static struct ref *get_refs_from_bundle(struct transport *transport, int for_pus for (i = 0; i < data->header.references.nr; i++) { struct ref_list_entry *e = data->header.references.list + i; struct ref *ref = alloc_ref(e->name); - hashcpy(ref->old_oid.hash, e->sha1); + oidcpy(&ref->old_oid, &e->oid); ref->next = result; result = ref; } @@ -58,7 +58,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base, { struct tree_desc desc; struct name_entry entry; - unsigned char sha1[20]; + struct object_id oid; int len, oldlen = base->len; enum interesting retval = entry_not_interesting; @@ -87,11 +87,11 @@ static int read_tree_1(struct tree *tree, struct strbuf *base, } if (S_ISDIR(entry.mode)) - hashcpy(sha1, entry.oid->hash); + oidcpy(&oid, entry.oid); else if (S_ISGITLINK(entry.mode)) { struct commit *commit; - commit = lookup_commit(entry.oid->hash); + commit = lookup_commit(entry.oid); if (!commit) die("Commit %s in submodule path %s%s not found", oid_to_hex(entry.oid), @@ -102,7 +102,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base, oid_to_hex(entry.oid), base->buf, entry.path); - hashcpy(sha1, commit->tree->object.oid.hash); + oidcpy(&oid, &commit->tree->object.oid); } else continue; @@ -110,7 +110,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base, len = tree_entry_len(&entry); strbuf_add(base, entry.path, len); strbuf_addch(base, '/'); - retval = read_tree_1(lookup_tree(sha1), + retval = read_tree_1(lookup_tree(&oid), base, stage, pathspec, fn, context); strbuf_setlen(base, oldlen); @@ -184,11 +184,11 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match) return 0; } -struct tree *lookup_tree(const unsigned char *sha1) +struct tree *lookup_tree(const struct object_id *oid) { - struct object *obj = lookup_object(sha1); + struct object *obj = lookup_object(oid->hash); if (!obj) - return create_object(sha1, alloc_tree_node()); + return create_object(oid->hash, alloc_tree_node()); return object_as_type(obj, OBJ_TREE, 0); } @@ -232,9 +232,9 @@ void free_tree_buffer(struct tree *tree) tree->object.parsed = 0; } -struct tree *parse_tree_indirect(const unsigned char *sha1) +struct tree *parse_tree_indirect(const struct object_id *oid) { - struct object *obj = parse_object(sha1); + struct object *obj = parse_object(oid); do { if (!obj) return NULL; @@ -247,6 +247,6 @@ struct tree *parse_tree_indirect(const unsigned char *sha1) else return NULL; if (!obj->parsed) - parse_object(obj->oid.hash); + parse_object(&obj->oid); } while (1); } @@ -12,7 +12,7 @@ struct tree { unsigned long size; }; -struct tree *lookup_tree(const unsigned char *sha1); +struct tree *lookup_tree(const struct object_id *oid); int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size); @@ -24,7 +24,7 @@ static inline int parse_tree(struct tree *tree) void free_tree_buffer(struct tree *tree); /* Parses and returns the tree in the given ent, chasing tags and commits. */ -struct tree *parse_tree_indirect(const unsigned char *sha1); +struct tree *parse_tree_indirect(const struct object_id *oid); #define READ_TREE_RECURSIVE 1 typedef int (*read_tree_fn_t)(const unsigned char *, struct strbuf *, const char *, unsigned int, int, void *); diff --git a/upload-pack.c b/upload-pack.c index 97da13e6a5..5330c02c14 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -286,19 +286,19 @@ static void create_pack_file(void) die("git upload-pack: %s", abort_msg); } -static int got_sha1(const char *hex, unsigned char *sha1) +static int got_oid(const char *hex, struct object_id *oid) { struct object *o; int we_knew_they_have = 0; - if (get_sha1_hex(hex, sha1)) + if (get_oid_hex(hex, oid)) die("git upload-pack: expected SHA1 object, got '%s'", hex); - if (!has_sha1_file(sha1)) + if (!has_object_file(oid)) return -1; - o = parse_object(sha1); + o = parse_object(oid); if (!o) - die("oops (%s)", sha1_to_hex(sha1)); + die("oops (%s)", oid_to_hex(oid)); if (o->type == OBJ_COMMIT) { struct commit_list *parents; struct commit *commit = (struct commit *)o; @@ -334,7 +334,7 @@ static int reachable(struct commit *want) break; } if (!commit->object.parsed) - parse_object(commit->object.oid.hash); + parse_object(&commit->object.oid); if (commit->object.flags & REACHABLE) continue; commit->object.flags |= REACHABLE; @@ -382,8 +382,8 @@ static int ok_to_give_up(void) static int get_common_commits(void) { - unsigned char sha1[20]; - char last_hex[41]; + struct object_id oid; + char last_hex[GIT_MAX_HEXSZ + 1]; int got_common = 0; int got_other = 0; int sent_ready = 0; @@ -416,11 +416,11 @@ static int get_common_commits(void) continue; } if (skip_prefix(line, "have ", &arg)) { - switch (got_sha1(arg, sha1)) { + switch (got_oid(arg, &oid)) { case -1: /* they have what we do not */ got_other = 1; if (multi_ack && ok_to_give_up()) { - const char *hex = sha1_to_hex(sha1); + const char *hex = oid_to_hex(&oid); if (multi_ack == 2) { sent_ready = 1; packet_write_fmt(1, "ACK %s ready\n", hex); @@ -430,7 +430,7 @@ static int get_common_commits(void) break; default: got_common = 1; - memcpy(last_hex, sha1_to_hex(sha1), 41); + memcpy(last_hex, oid_to_hex(&oid), 41); if (multi_ack == 2) packet_write_fmt(1, "ACK %s common\n", last_hex); else if (multi_ack) @@ -492,7 +492,7 @@ static int do_reachable_revlist(struct child_process *cmd, goto error; namebuf[0] = '^'; - namebuf[41] = '\n'; + namebuf[GIT_SHA1_HEXSZ + 1] = '\n'; for (i = get_max_object_index(); 0 < i; ) { o = get_indexed_object(--i); if (!o) @@ -502,10 +502,10 @@ static int do_reachable_revlist(struct child_process *cmd, if (!is_our_ref(o)) continue; memcpy(namebuf + 1, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ); - if (write_in_full(cmd->in, namebuf, 42) < 0) + if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 2) < 0) goto error; } - namebuf[40] = '\n'; + namebuf[GIT_SHA1_HEXSZ] = '\n'; for (i = 0; i < src->nr; i++) { o = src->objects[i].item; if (is_our_ref(o)) { @@ -516,7 +516,7 @@ static int do_reachable_revlist(struct child_process *cmd, if (reachable && o->type == OBJ_COMMIT) o->flags |= TMP_MARK; memcpy(namebuf, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ); - if (write_in_full(cmd->in, namebuf, 41) < 0) + if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 1) < 0) goto error; } close(cmd->in); @@ -642,7 +642,7 @@ static void send_shallow(struct commit_list *result) if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) { packet_write_fmt(1, "shallow %s", oid_to_hex(&object->oid)); - register_shallow(object->oid.hash); + register_shallow(&object->oid); shallow_nr++; } result = result->next; @@ -667,7 +667,7 @@ static void send_unshallow(const struct object_array *shallows) * parse and add the parents to the want list, then * re-register it. */ - unregister_shallow(object->oid.hash); + unregister_shallow(&object->oid); object->parsed = 0; parse_commit_or_die((struct commit *)object); parents = ((struct commit *)object)->parents; @@ -679,7 +679,7 @@ static void send_unshallow(const struct object_array *shallows) add_object_array(object, NULL, &extra_edge_obj); } /* make sure commit traversal conforms to client */ - register_shallow(object->oid.hash); + register_shallow(&object->oid); } } @@ -742,7 +742,7 @@ static void receive_needs(void) for (;;) { struct object *o; const char *features; - unsigned char sha1_buf[20]; + struct object_id oid_buf; char *line = packet_read_line(0, NULL); const char *arg; @@ -751,15 +751,15 @@ static void receive_needs(void) break; if (skip_prefix(line, "shallow ", &arg)) { - unsigned char sha1[20]; + struct object_id oid; struct object *object; - if (get_sha1_hex(arg, sha1)) + if (get_oid_hex(arg, &oid)) die("invalid shallow line: %s", line); - object = parse_object(sha1); + object = parse_object(&oid); if (!object) continue; if (object->type != OBJ_COMMIT) - die("invalid shallow object %s", sha1_to_hex(sha1)); + die("invalid shallow object %s", oid_to_hex(&oid)); if (!(object->flags & CLIENT_SHALLOW)) { object->flags |= CLIENT_SHALLOW; add_object_array(object, NULL, &shallows); @@ -785,8 +785,8 @@ static void receive_needs(void) } if (skip_prefix(line, "deepen-not ", &arg)) { char *ref = NULL; - unsigned char sha1[20]; - if (expand_ref(arg, strlen(arg), sha1, &ref) != 1) + struct object_id oid; + if (expand_ref(arg, strlen(arg), oid.hash, &ref) != 1) die("git upload-pack: ambiguous deepen-not: %s", line); string_list_append(&deepen_not, ref); free(ref); @@ -794,7 +794,7 @@ static void receive_needs(void) continue; } if (!skip_prefix(line, "want ", &arg) || - get_sha1_hex(arg, sha1_buf)) + get_oid_hex(arg, &oid_buf)) die("git upload-pack: protocol error, " "expected to get sha, not '%s'", line); @@ -821,13 +821,13 @@ static void receive_needs(void) if (parse_feature_request(features, "include-tag")) use_include_tag = 1; - o = parse_object(sha1_buf); + o = parse_object(&oid_buf); if (!o) { packet_write_fmt(1, "ERR upload-pack: not our ref %s", - sha1_to_hex(sha1_buf)); + oid_to_hex(&oid_buf)); die("git upload-pack: not our ref %s", - sha1_to_hex(sha1_buf)); + oid_to_hex(&oid_buf)); } if (!(o->flags & WANTED)) { o->flags |= WANTED; @@ -883,7 +883,7 @@ static void receive_needs(void) if (shallows.nr > 0) { int i; for (i = 0; i < shallows.nr; i++) - register_shallow(shallows.objects[i].item->oid.hash); + register_shallow(&shallows.objects[i].item->oid); } shallow_nr += shallows.nr; @@ -47,12 +47,12 @@ static int process_tree(struct walker *walker, struct tree *tree) if (S_ISGITLINK(entry.mode)) continue; if (S_ISDIR(entry.mode)) { - struct tree *tree = lookup_tree(entry.oid->hash); + struct tree *tree = lookup_tree(entry.oid); if (tree) obj = &tree->object; } else { - struct blob *blob = lookup_blob(entry.oid->hash); + struct blob *blob = lookup_blob(entry.oid); if (blob) obj = &blob->object; } @@ -180,7 +180,7 @@ static int loop(struct walker *walker) } } if (!obj->type) - parse_object(obj->oid.hash); + parse_object(&obj->oid); if (process_object(walker, obj)) return -1; } @@ -206,7 +206,7 @@ static int interpret_target(struct walker *walker, char *target, unsigned char * static int mark_complete(const char *path, const struct object_id *oid, int flag, void *cb_data) { - struct commit *commit = lookup_commit_reference_gently(oid->hash, 1); + struct commit *commit = lookup_commit_reference_gently(oid, 1); if (commit) { commit->object.flags |= COMPLETE; diff --git a/wt-status.c b/wt-status.c index f55f587111..5db53775ab 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1428,7 +1428,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state) /* sha1 is a commit? match without further lookup */ (!oidcmp(&cb.noid, &oid) || /* perhaps sha1 is a tag, try to dereference to a commit */ - ((commit = lookup_commit_reference_gently(oid.hash, 1)) != NULL && + ((commit = lookup_commit_reference_gently(&oid, 1)) != NULL && !oidcmp(&cb.noid, &commit->object.oid)))) { const char *from = ref; if (!skip_prefix(from, "refs/tags/", &from)) |