From 38b471fae0f2b961259201278b24b11262dc7596 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:22 +0000 Subject: builtin/write-tree: convert to struct object_id This is needed to convert parts of the cache-tree code. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/write-tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'builtin') diff --git a/builtin/write-tree.c b/builtin/write-tree.c index bd0a78aa3c..299a121531 100644 --- a/builtin/write-tree.c +++ b/builtin/write-tree.c @@ -19,7 +19,7 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix) { int flags = 0, ret; const char *prefix = NULL; - unsigned char sha1[20]; + struct object_id oid; const char *me = "git-write-tree"; struct option write_tree_options[] = { OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"), @@ -38,10 +38,10 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix) argc = parse_options(argc, argv, unused_prefix, write_tree_options, write_tree_usage, 0); - ret = write_cache_as_tree(sha1, flags, prefix); + ret = write_cache_as_tree(oid.hash, flags, prefix); switch (ret) { case 0: - printf("%s\n", sha1_to_hex(sha1)); + printf("%s\n", oid_to_hex(&oid)); break; case WRITE_TREE_UNREADABLE_INDEX: die("%s: error reading the index", me); -- cgit v1.2.3 From fc5cb99f675b2052f6d6bd3e2520379031b12267 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:23 +0000 Subject: cache-tree: convert write_*_as_tree to object_id Convert write_index_as_tree and write_cache_as_tree to use struct object_id. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/am.c | 8 ++++---- builtin/merge.c | 2 +- builtin/write-tree.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'builtin') diff --git a/builtin/am.c b/builtin/am.c index 1151b5c73a..1bcc3606c5 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1550,7 +1550,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa discard_cache(); read_cache_from(index_path); - if (write_index_as_tree(orig_tree.hash, &the_index, index_path, 0, NULL)) + if (write_index_as_tree(&orig_tree, &the_index, index_path, 0, NULL)) return error(_("Repository lacks necessary blobs to fall back on 3-way merge.")); say(state, stdout, _("Using index info to reconstruct a base tree...")); @@ -1575,7 +1575,7 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa return error(_("Did you hand edit your patch?\n" "It does not apply to blobs recorded in its index.")); - if (write_index_as_tree(their_tree.hash, &the_index, index_path, 0, NULL)) + if (write_index_as_tree(&their_tree, &the_index, index_path, 0, NULL)) return error("could not write tree"); say(state, stdout, _("Falling back to patching base and 3-way merge...")); @@ -1626,7 +1626,7 @@ static void do_commit(const struct am_state *state) if (run_hook_le(NULL, "pre-applypatch", NULL)) exit(1); - if (write_cache_as_tree(tree.hash, 0, NULL)) + if (write_cache_as_tree(&tree, 0, NULL)) die(_("git write-tree failed to write a tree")); if (!get_oid_commit("HEAD", &parent)) { @@ -2004,7 +2004,7 @@ static int clean_index(const struct object_id *head, const struct object_id *rem if (fast_forward_to(head_tree, head_tree, 1)) return -1; - if (write_cache_as_tree(index.hash, 0, NULL)) + if (write_cache_as_tree(&index, 0, NULL)) return -1; index_tree = parse_tree_indirect(&index); diff --git a/builtin/merge.c b/builtin/merge.c index e8d9d4383e..0c7437f536 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -639,7 +639,7 @@ static int read_tree_trivial(struct object_id *common, struct object_id *head, static void write_tree_trivial(struct object_id *oid) { - if (write_cache_as_tree(oid->hash, 0, NULL)) + if (write_cache_as_tree(oid, 0, NULL)) die(_("git write-tree failed to write a tree")); } diff --git a/builtin/write-tree.c b/builtin/write-tree.c index 299a121531..c9d3c544e7 100644 --- a/builtin/write-tree.c +++ b/builtin/write-tree.c @@ -38,7 +38,7 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix) argc = parse_options(argc, argv, unused_prefix, write_tree_options, write_tree_usage, 0); - ret = write_cache_as_tree(oid.hash, flags, prefix); + ret = write_cache_as_tree(&oid, flags, prefix); switch (ret) { case 0: printf("%s\n", oid_to_hex(&oid)); -- cgit v1.2.3 From 5ac913c6eb266e836f91c39c3b03bcbdc06475c6 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:25 +0000 Subject: resolve-undo: convert struct resolve_undo_info to object_id Convert the sha1 member of this struct to be an array of struct object_id instead. This change is needed to convert find_unique_abbrev. Convert some instances of hard-coded constants to use the_hash_algo as well. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/ls-files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 2fc836e330..9df66ba307 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -271,7 +271,7 @@ static void show_ru_info(const struct index_state *istate) if (!ui->mode[i]) continue; printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i], - find_unique_abbrev(ui->sha1[i], abbrev), + find_unique_abbrev(ui->oid[i].hash, abbrev), i + 1); write_name(path); } -- cgit v1.2.3 From df46d77e00e7bbcfe46cc06c071fa5284f96c327 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:26 +0000 Subject: tree: convert read_tree_recursive to struct object_id Convert the callback functions for read_tree_recursive to take a pointer to struct object_id. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/checkout.c | 4 ++-- builtin/log.c | 2 +- builtin/ls-tree.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'builtin') diff --git a/builtin/checkout.c b/builtin/checkout.c index 8f4dfb1046..8eb118201d 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -66,7 +66,7 @@ static int post_checkout_hook(struct commit *old_commit, struct commit *new_comm } -static int update_some(const unsigned char *sha1, struct strbuf *base, +static int update_some(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *context) { int len; @@ -78,7 +78,7 @@ static int update_some(const unsigned char *sha1, struct strbuf *base, len = base->len + strlen(pathname); ce = xcalloc(1, cache_entry_size(len)); - hashcpy(ce->oid.hash, sha1); + oidcpy(&ce->oid, oid); memcpy(ce->name, base->buf, base->len); memcpy(ce->name + base->len, pathname, len - base->len); ce->ce_flags = create_ce_flags(0) | CE_UPDATE; diff --git a/builtin/log.c b/builtin/log.c index 94ee177d56..32a744bfd2 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -541,7 +541,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev) return 0; } -static int show_tree_object(const unsigned char *sha1, +static int show_tree_object(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *context) { diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index ef965408e8..c613dd7b82 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -60,7 +60,7 @@ static int show_recursive(const char *base, int baselen, const char *pathname) return 0; } -static int show_tree(const unsigned char *sha1, struct strbuf *base, +static int show_tree(const struct object_id *oid, struct strbuf *base, const char *pathname, unsigned mode, int stage, void *context) { int retval = 0; @@ -94,7 +94,7 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base, char size_text[24]; if (!strcmp(type, blob_type)) { unsigned long size; - if (sha1_object_info(sha1, &size) == OBJ_BAD) + if (sha1_object_info(oid->hash, &size) == OBJ_BAD) xsnprintf(size_text, sizeof(size_text), "BAD"); else @@ -103,11 +103,11 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base, } else xsnprintf(size_text, sizeof(size_text), "-"); printf("%06o %s %s %7s\t", mode, type, - find_unique_abbrev(sha1, abbrev), + find_unique_abbrev(oid->hash, abbrev), size_text); } else printf("%06o %s %s\t", mode, type, - find_unique_abbrev(sha1, abbrev)); + find_unique_abbrev(oid->hash, abbrev)); } baselen = base->len; strbuf_addstr(base, pathname); -- cgit v1.2.3 From 30e677e0e243ebb29a5f5aeed8c850bbae9020fa Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:28 +0000 Subject: strbuf: convert strbuf_add_unique_abbrev to use struct object_id Convert the declaration and definition of strbuf_add_unique_abbrev to make it take a pointer to struct object_id. Predeclare the struct in strbuf.h, as cache.h includes strbuf.h before it declares the struct, and otherwise the struct declaration would have the wrong scope. Apply the following semantic patch, along with the standard object_id transforms, to adjust the callers: @@ expression E1, E2, E3; @@ - strbuf_add_unique_abbrev(E1, E2.hash, E3); + strbuf_add_unique_abbrev(E1, &E2, E3); @@ expression E1, E2, E3; @@ - strbuf_add_unique_abbrev(E1, E2->hash, E3); + strbuf_add_unique_abbrev(E1, E2, E3); Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/checkout.c | 2 +- builtin/fetch.c | 8 ++++---- builtin/tag.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'builtin') diff --git a/builtin/checkout.c b/builtin/checkout.c index 8eb118201d..5981e1a3ed 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -720,7 +720,7 @@ static int add_pending_uninteresting_ref(const char *refname, static void describe_one_orphan(struct strbuf *sb, struct commit *commit) { strbuf_addstr(sb, " "); - strbuf_add_unique_abbrev(sb, commit->object.oid.hash, DEFAULT_ABBREV); + strbuf_add_unique_abbrev(sb, &commit->object.oid, DEFAULT_ABBREV); strbuf_addch(sb, ' '); if (!parse_commit(commit)) pp_commit_easy(CMIT_FMT_ONELINE, commit, sb); diff --git a/builtin/fetch.c b/builtin/fetch.c index d32d94692c..aeafe63ba6 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -708,9 +708,9 @@ static int update_local_ref(struct ref *ref, if (in_merge_bases(current, updated)) { struct strbuf quickref = STRBUF_INIT; int r; - strbuf_add_unique_abbrev(&quickref, current->object.oid.hash, DEFAULT_ABBREV); + strbuf_add_unique_abbrev(&quickref, ¤t->object.oid, DEFAULT_ABBREV); strbuf_addstr(&quickref, ".."); - strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash, DEFAULT_ABBREV); + strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV); if ((recurse_submodules != RECURSE_SUBMODULES_OFF) && (recurse_submodules != RECURSE_SUBMODULES_ON)) check_for_new_submodule_commits(&ref->new_oid); @@ -723,9 +723,9 @@ static int update_local_ref(struct ref *ref, } else if (force || ref->force) { struct strbuf quickref = STRBUF_INIT; int r; - strbuf_add_unique_abbrev(&quickref, current->object.oid.hash, DEFAULT_ABBREV); + strbuf_add_unique_abbrev(&quickref, ¤t->object.oid, DEFAULT_ABBREV); strbuf_addstr(&quickref, "..."); - strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash, DEFAULT_ABBREV); + strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV); if ((recurse_submodules != RECURSE_SUBMODULES_OFF) && (recurse_submodules != RECURSE_SUBMODULES_ON)) check_for_new_submodule_commits(&ref->new_oid); diff --git a/builtin/tag.c b/builtin/tag.c index 8c493a569f..a5fc6c090f 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -293,7 +293,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb) strbuf_addstr(sb, rla); } else { strbuf_addstr(sb, "tag: tagging "); - strbuf_add_unique_abbrev(sb, oid->hash, DEFAULT_ABBREV); + strbuf_add_unique_abbrev(sb, oid, DEFAULT_ABBREV); } strbuf_addstr(sb, " ("); -- cgit v1.2.3 From aab9583f7b5ea5463eb3f653a0b4ecac7539dc94 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:30 +0000 Subject: Convert find_unique_abbrev* to struct object_id Convert find_unique_abbrev and find_unique_abbrev_r to each take a pointer to struct object_id. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/blame.c | 2 +- builtin/branch.c | 2 +- builtin/checkout.c | 6 +++--- builtin/describe.c | 4 ++-- builtin/log.c | 4 ++-- builtin/ls-files.c | 4 ++-- builtin/ls-tree.c | 4 ++-- builtin/merge.c | 6 +++--- builtin/name-rev.c | 2 +- builtin/receive-pack.c | 8 ++++---- builtin/reset.c | 2 +- builtin/rev-list.c | 2 +- builtin/rev-parse.c | 2 +- builtin/show-branch.c | 2 +- builtin/show-ref.c | 4 ++-- builtin/tag.c | 6 ++++-- builtin/worktree.c | 4 ++-- 17 files changed, 33 insertions(+), 31 deletions(-) (limited to 'builtin') diff --git a/builtin/blame.c b/builtin/blame.c index 9dcb367b90..b980e8a1dd 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -499,7 +499,7 @@ static int read_ancestry(const char *graft_file) static int update_auto_abbrev(int auto_abbrev, struct blame_origin *suspect) { - const char *uniq = find_unique_abbrev(suspect->commit->object.oid.hash, + const char *uniq = find_unique_abbrev(&suspect->commit->object.oid, auto_abbrev); int len = strlen(uniq); if (auto_abbrev < len) diff --git a/builtin/branch.c b/builtin/branch.c index 8dcc2ed058..659deb36f3 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -273,7 +273,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds, bname.buf, (flags & REF_ISBROKEN) ? "broken" : (flags & REF_ISSYMREF) ? target - : find_unique_abbrev(oid.hash, DEFAULT_ABBREV)); + : find_unique_abbrev(&oid, DEFAULT_ABBREV)); } delete_branch_config(bname.buf); diff --git a/builtin/checkout.c b/builtin/checkout.c index 5981e1a3ed..45968c2d85 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -405,10 +405,10 @@ static void describe_detached_head(const char *msg, struct commit *commit) pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb); if (print_sha1_ellipsis()) { fprintf(stderr, "%s %s... %s\n", msg, - find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf); + find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV), sb.buf); } else { fprintf(stderr, "%s %s %s\n", msg, - find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf); + find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV), sb.buf); } strbuf_release(&sb); } @@ -778,7 +778,7 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs) " git branch %s\n\n", /* Give ngettext() the count */ lost), - find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV)); + find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV)); } /* diff --git a/builtin/describe.c b/builtin/describe.c index e4869df7b4..7e6535a8bd 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -285,7 +285,7 @@ static void append_name(struct commit_name *n, struct strbuf *dst) static void append_suffix(int depth, const struct object_id *oid, struct strbuf *dst) { - strbuf_addf(dst, "-%d-g%s", depth, find_unique_abbrev(oid->hash, abbrev)); + strbuf_addf(dst, "-%d-g%s", depth, find_unique_abbrev(oid, abbrev)); } static void describe_commit(struct object_id *oid, struct strbuf *dst) @@ -383,7 +383,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst) if (!match_cnt) { struct object_id *cmit_oid = &cmit->object.oid; if (always) { - strbuf_add_unique_abbrev(dst, cmit_oid->hash, abbrev); + strbuf_add_unique_abbrev(dst, cmit_oid, abbrev); if (suffix) strbuf_addstr(dst, suffix); return; diff --git a/builtin/log.c b/builtin/log.c index 32a744bfd2..411339c1ed 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1873,12 +1873,12 @@ static void print_commit(char sign, struct commit *commit, int verbose, { if (!verbose) { fprintf(file, "%c %s\n", sign, - find_unique_abbrev(commit->object.oid.hash, abbrev)); + find_unique_abbrev(&commit->object.oid, abbrev)); } else { struct strbuf buf = STRBUF_INIT; pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf); fprintf(file, "%c %s %s\n", sign, - find_unique_abbrev(commit->object.oid.hash, abbrev), + find_unique_abbrev(&commit->object.oid, abbrev), buf.buf); strbuf_release(&buf); } diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 9df66ba307..a71f6bd088 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -240,7 +240,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir, printf("%s%06o %s %d\t", tag, ce->ce_mode, - find_unique_abbrev(ce->oid.hash, abbrev), + find_unique_abbrev(&ce->oid, abbrev), ce_stage(ce)); } write_eolinfo(repo->index, ce, fullname); @@ -271,7 +271,7 @@ static void show_ru_info(const struct index_state *istate) if (!ui->mode[i]) continue; printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i], - find_unique_abbrev(ui->oid[i].hash, abbrev), + find_unique_abbrev(&ui->oid[i], abbrev), i + 1); write_name(path); } diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index c613dd7b82..c98253adbb 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -103,11 +103,11 @@ static int show_tree(const struct object_id *oid, struct strbuf *base, } else xsnprintf(size_text, sizeof(size_text), "-"); printf("%06o %s %s %7s\t", mode, type, - find_unique_abbrev(oid->hash, abbrev), + find_unique_abbrev(oid, abbrev), size_text); } else printf("%06o %s %s\t", mode, type, - find_unique_abbrev(oid->hash, abbrev)); + find_unique_abbrev(oid, abbrev)); } baselen = base->len; strbuf_addstr(base, pathname); diff --git a/builtin/merge.c b/builtin/merge.c index 0c7437f536..b4f32105b5 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1327,7 +1327,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) check_commit_signature(commit, &signature_check); - find_unique_abbrev_r(hex, commit->object.oid.hash, DEFAULT_ABBREV); + find_unique_abbrev_r(hex, &commit->object.oid, DEFAULT_ABBREV); switch (signature_check.result) { case 'G': break; @@ -1420,9 +1420,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix) if (verbosity >= 0) { printf(_("Updating %s..%s\n"), - find_unique_abbrev(head_commit->object.oid.hash, + find_unique_abbrev(&head_commit->object.oid, DEFAULT_ABBREV), - find_unique_abbrev(remoteheads->item->object.oid.hash, + find_unique_abbrev(&remoteheads->item->object.oid, DEFAULT_ABBREV)); } strbuf_addstr(&msg, "Fast-forward"); diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 9e088ebd11..387ddf85d2 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -328,7 +328,7 @@ static void show_name(const struct object *obj, else if (allow_undefined) printf("undefined\n"); else if (always) - printf("%s\n", find_unique_abbrev(oid->hash, DEFAULT_ABBREV)); + printf("%s\n", find_unique_abbrev(oid, DEFAULT_ABBREV)); else die("cannot describe '%s'", oid_to_hex(oid)); strbuf_release(&buf); diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 75e7f18ace..2bf7f2d1a3 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1242,11 +1242,11 @@ static void check_aliased_update(struct command *cmd, struct string_list *list) rp_error("refusing inconsistent update between symref '%s' (%s..%s) and" " its target '%s' (%s..%s)", cmd->ref_name, - find_unique_abbrev(cmd->old_oid.hash, DEFAULT_ABBREV), - find_unique_abbrev(cmd->new_oid.hash, DEFAULT_ABBREV), + find_unique_abbrev(&cmd->old_oid, DEFAULT_ABBREV), + find_unique_abbrev(&cmd->new_oid, DEFAULT_ABBREV), dst_cmd->ref_name, - find_unique_abbrev(dst_cmd->old_oid.hash, DEFAULT_ABBREV), - find_unique_abbrev(dst_cmd->new_oid.hash, DEFAULT_ABBREV)); + find_unique_abbrev(&dst_cmd->old_oid, DEFAULT_ABBREV), + find_unique_abbrev(&dst_cmd->new_oid, DEFAULT_ABBREV)); cmd->error_string = dst_cmd->error_string = "inconsistent aliased update"; diff --git a/builtin/reset.c b/builtin/reset.c index 5da0f75de9..7f1c3f02a3 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -109,7 +109,7 @@ static void print_new_head_line(struct commit *commit) struct strbuf buf = STRBUF_INIT; printf(_("HEAD is now at %s"), - find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV)); + find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV)); pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf); if (buf.len > 0) diff --git a/builtin/rev-list.c b/builtin/rev-list.c index d320b6f1e3..2fd72c0be5 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -108,7 +108,7 @@ static void show_commit(struct commit *commit, void *data) if (!revs->graph) fputs(get_revision_mark(revs, commit), stdout); if (revs->abbrev_commit && revs->abbrev) - fputs(find_unique_abbrev(commit->object.oid.hash, revs->abbrev), + fputs(find_unique_abbrev(&commit->object.oid, revs->abbrev), stdout); else fputs(oid_to_hex(&commit->object.oid), stdout); diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index a1e680b5e9..36b2087782 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -159,7 +159,7 @@ static void show_rev(int type, const struct object_id *oid, const char *name) } } else if (abbrev) - show_with_type(type, find_unique_abbrev(oid->hash, abbrev)); + show_with_type(type, find_unique_abbrev(oid, abbrev)); else show_with_type(type, oid_to_hex(oid)); } diff --git a/builtin/show-branch.c b/builtin/show-branch.c index e8a4aa40cb..6c2148b71d 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -292,7 +292,7 @@ static void show_one_commit(struct commit *commit, int no_name) } else printf("[%s] ", - find_unique_abbrev(commit->object.oid.hash, + find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV)); } puts(pretty_str); diff --git a/builtin/show-ref.c b/builtin/show-ref.c index 41e5e71cad..f2eb1a7724 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -29,7 +29,7 @@ static void show_one(const char *refname, const struct object_id *oid) if (quiet) return; - hex = find_unique_abbrev(oid->hash, abbrev); + hex = find_unique_abbrev(oid, abbrev); if (hash_only) printf("%s\n", hex); else @@ -39,7 +39,7 @@ static void show_one(const char *refname, const struct object_id *oid) return; if (!peel_ref(refname, &peeled)) { - hex = find_unique_abbrev(peeled.hash, abbrev); + hex = find_unique_abbrev(&peeled, abbrev); printf("%s %s^{}\n", hex, refname); } } diff --git a/builtin/tag.c b/builtin/tag.c index a5fc6c090f..644e6888be 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -99,7 +99,8 @@ static int delete_tag(const char *name, const char *ref, { if (delete_ref(NULL, ref, oid, 0)) return 1; - printf(_("Deleted tag '%s' (was %s)\n"), name, find_unique_abbrev(oid->hash, DEFAULT_ABBREV)); + printf(_("Deleted tag '%s' (was %s)\n"), name, + find_unique_abbrev(oid, DEFAULT_ABBREV)); return 0; } @@ -558,7 +559,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix) die("%s", err.buf); ref_transaction_free(transaction); if (force && !is_null_oid(&prev) && oidcmp(&prev, &object)) - printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev.hash, DEFAULT_ABBREV)); + printf(_("Updated tag '%s' (was %s)\n"), tag, + find_unique_abbrev(&prev, DEFAULT_ABBREV)); UNLEAK(buf); UNLEAK(ref); diff --git a/builtin/worktree.c b/builtin/worktree.c index 4e7c98758f..3442f257b7 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -498,7 +498,7 @@ static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len) strbuf_addstr(&sb, "(bare)"); else { strbuf_addf(&sb, "%-*s ", abbrev_len, - find_unique_abbrev(wt->head_oid.hash, DEFAULT_ABBREV)); + find_unique_abbrev(&wt->head_oid, DEFAULT_ABBREV)); if (wt->is_detached) strbuf_addstr(&sb, "(detached HEAD)"); else if (wt->head_ref) { @@ -523,7 +523,7 @@ static void measure_widths(struct worktree **wt, int *abbrev, int *maxlen) if (path_len > *maxlen) *maxlen = path_len; - sha1_len = strlen(find_unique_abbrev(wt[i]->head_oid.hash, *abbrev)); + sha1_len = strlen(find_unique_abbrev(&wt[i]->head_oid, *abbrev)); if (sha1_len > *abbrev) *abbrev = sha1_len; } -- cgit v1.2.3 From eedc994f18b608a805b31db0d40c13cce1b970fb Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:34 +0000 Subject: builtin/mktag: convert to struct object_id Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/mktag.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'builtin') diff --git a/builtin/mktag.c b/builtin/mktag.c index beb552847b..65bb41e3cd 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -18,13 +18,13 @@ /* * We refuse to tag something we can't verify. Just because. */ -static int verify_object(const unsigned char *sha1, const char *expected_type) +static int verify_object(const struct object_id *oid, const char *expected_type) { int ret = -1; enum object_type type; unsigned long size; - void *buffer = read_sha1_file(sha1, &type, &size); - const unsigned char *repl = lookup_replace_object(sha1); + void *buffer = read_sha1_file(oid->hash, &type, &size); + const unsigned char *repl = lookup_replace_object(oid->hash); if (buffer) { if (type == type_from_string(expected_type)) @@ -38,8 +38,8 @@ static int verify_tag(char *buffer, unsigned long size) { int typelen; char type[20]; - unsigned char sha1[20]; - const char *object, *type_line, *tag_line, *tagger_line, *lb, *rb; + struct object_id oid; + const char *object, *type_line, *tag_line, *tagger_line, *lb, *rb, *p; size_t len; if (size < 84) @@ -52,11 +52,11 @@ static int verify_tag(char *buffer, unsigned long size) if (memcmp(object, "object ", 7)) return error("char%d: does not start with \"object \"", 0); - if (get_sha1_hex(object + 7, sha1)) + if (parse_oid_hex(object + 7, &oid, &p)) return error("char%d: could not get SHA1 hash", 7); /* Verify type line */ - type_line = object + 48; + type_line = p + 1; if (memcmp(type_line - 1, "\ntype ", 6)) return error("char%d: could not find \"\\ntype \"", 47); @@ -80,8 +80,8 @@ static int verify_tag(char *buffer, unsigned long size) type[typelen] = 0; /* Verify that the object matches */ - if (verify_object(sha1, type)) - return error("char%d: could not verify object %s", 7, sha1_to_hex(sha1)); + if (verify_object(&oid, type)) + return error("char%d: could not verify object %s", 7, oid_to_hex(&oid)); /* Verify the tag-name: we don't allow control characters or spaces in it */ tag_line += 4; -- cgit v1.2.3 From af8caf33d5ac055addff3971747898799c21557c Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:37 +0000 Subject: builtin/index-pack: convert struct ref_delta_entry to object_id Convert this struct to use a member of type object_id. Convert various static functions as well. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/index-pack.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'builtin') diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 59878e70b8..9744175e23 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -58,7 +58,7 @@ struct ofs_delta_entry { }; struct ref_delta_entry { - unsigned char sha1[20]; + struct object_id oid; int obj_no; }; @@ -671,18 +671,18 @@ static void find_ofs_delta_children(off_t offset, *last_index = last; } -static int compare_ref_delta_bases(const unsigned char *sha1, - const unsigned char *sha2, +static int compare_ref_delta_bases(const struct object_id *oid1, + const struct object_id *oid2, enum object_type type1, enum object_type type2) { int cmp = type1 - type2; if (cmp) return cmp; - return hashcmp(sha1, sha2); + return oidcmp(oid1, oid2); } -static int find_ref_delta(const unsigned char *sha1, enum object_type type) +static int find_ref_delta(const struct object_id *oid, enum object_type type) { int first = 0, last = nr_ref_deltas; @@ -691,7 +691,7 @@ static int find_ref_delta(const unsigned char *sha1, enum object_type type) struct ref_delta_entry *delta = &ref_deltas[next]; int cmp; - cmp = compare_ref_delta_bases(sha1, delta->sha1, + cmp = compare_ref_delta_bases(oid, &delta->oid, type, objects[delta->obj_no].type); if (!cmp) return next; @@ -704,11 +704,11 @@ static int find_ref_delta(const unsigned char *sha1, enum object_type type) return -first-1; } -static void find_ref_delta_children(const unsigned char *sha1, +static void find_ref_delta_children(const struct object_id *oid, int *first_index, int *last_index, enum object_type type) { - int first = find_ref_delta(sha1, type); + int first = find_ref_delta(oid, type); int last = first; int end = nr_ref_deltas - 1; @@ -717,9 +717,9 @@ static void find_ref_delta_children(const unsigned char *sha1, *last_index = -1; return; } - while (first > 0 && !hashcmp(ref_deltas[first - 1].sha1, sha1)) + while (first > 0 && !oidcmp(&ref_deltas[first - 1].oid, oid)) --first; - while (last < end && !hashcmp(ref_deltas[last + 1].sha1, sha1)) + while (last < end && !oidcmp(&ref_deltas[last + 1].oid, oid)) ++last; *first_index = first; *last_index = last; @@ -991,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.oid.hash, + find_ref_delta_children(&base->obj->idx.oid, &base->ref_first, &base->ref_last, OBJ_REF_DELTA); @@ -1075,7 +1075,7 @@ static int compare_ref_delta_entry(const void *a, const void *b) const struct ref_delta_entry *delta_a = a; const struct ref_delta_entry *delta_b = b; - return hashcmp(delta_a->sha1, delta_b->sha1); + return oidcmp(&delta_a->oid, &delta_b->oid); } static void resolve_base(struct object_entry *obj) @@ -1141,7 +1141,7 @@ static void parse_pack_objects(unsigned char *hash) ofs_delta++; } else if (obj->type == OBJ_REF_DELTA) { ALLOC_GROW(ref_deltas, nr_ref_deltas + 1, ref_deltas_alloc); - hashcpy(ref_deltas[nr_ref_deltas].sha1, ref_delta_oid.hash); + oidcpy(&ref_deltas[nr_ref_deltas].oid, &ref_delta_oid); ref_deltas[nr_ref_deltas].obj_no = i; nr_ref_deltas++; } else if (!data) { @@ -1373,14 +1373,14 @@ static void fix_unresolved_deltas(struct hashfile *f) if (objects[d->obj_no].real_type != OBJ_REF_DELTA) continue; - base_obj->data = read_sha1_file(d->sha1, &type, &base_obj->size); + base_obj->data = read_sha1_file(d->oid.hash, &type, &base_obj->size); if (!base_obj->data) continue; - if (check_sha1_signature(d->sha1, base_obj->data, + if (check_sha1_signature(d->oid.hash, base_obj->data, base_obj->size, type_name(type))) - die(_("local object %s is corrupt"), sha1_to_hex(d->sha1)); - base_obj->obj = append_obj_to_pack(f, d->sha1, + die(_("local object %s is corrupt"), oid_to_hex(&d->oid)); + base_obj->obj = append_obj_to_pack(f, d->oid.hash, base_obj->data, base_obj->size, type); find_unresolved_deltas(base_obj); display_progress(progress, nr_resolved_deltas); -- cgit v1.2.3 From d61d87bd156a1d49b827d1b26f023fd70febfa06 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:38 +0000 Subject: sha1_file: convert read_loose_object to use struct object_id Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/fsck.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/fsck.c b/builtin/fsck.c index ef78c6c00c..eae018e3fb 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -513,7 +513,7 @@ static struct object *parse_loose_object(const struct object_id *oid, unsigned long size; int eaten; - if (read_loose_object(path, oid->hash, &type, &size, &contents) < 0) + if (read_loose_object(path, oid, &type, &size, &contents) < 0) return NULL; if (!contents && type != OBJ_BLOB) -- cgit v1.2.3 From 17e65451e305b7501fddec35125bf5d39a4cdcac Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:39 +0000 Subject: sha1_file: convert check_sha1_signature to struct object_id Convert this function to take a pointer to struct object_id and rename it check_object_signature. Introduce temporaries to convert the return values of lookup_replace_object and lookup_replace_object_extended into struct object_id. The temporaries are needed because in order to convert lookup_replace_object, open_istream needs to be converted, and open_istream needs check_sha1_signature to be converted, causing a loop of dependencies. The temporaries will be removed in a future patch. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/fast-export.c | 2 +- builtin/index-pack.c | 2 +- builtin/mktag.c | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'builtin') diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 27b2cc138e..9b049e9d08 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -240,7 +240,7 @@ static void export_blob(const struct object_id *oid) buf = read_sha1_file(oid->hash, &type, &size); if (!buf) die ("Could not read blob %s", oid_to_hex(oid)); - if (check_sha1_signature(oid->hash, buf, size, type_name(type)) < 0) + if (check_object_signature(oid, buf, size, type_name(type)) < 0) die("sha1 mismatch in blob %s", oid_to_hex(oid)); object = parse_object_buffer(oid, type, size, buf, &eaten); } diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 9744175e23..b28ebfadd4 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -1377,7 +1377,7 @@ static void fix_unresolved_deltas(struct hashfile *f) if (!base_obj->data) continue; - if (check_sha1_signature(d->oid.hash, base_obj->data, + if (check_object_signature(&d->oid, base_obj->data, base_obj->size, type_name(type))) die(_("local object %s is corrupt"), oid_to_hex(&d->oid)); base_obj->obj = append_obj_to_pack(f, d->oid.hash, diff --git a/builtin/mktag.c b/builtin/mktag.c index 65bb41e3cd..810b24bef3 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -27,8 +27,11 @@ static int verify_object(const struct object_id *oid, const char *expected_type) const unsigned char *repl = lookup_replace_object(oid->hash); if (buffer) { + struct object_id reploid; + hashcpy(reploid.hash, repl); + if (type == type_from_string(expected_type)) - ret = check_sha1_signature(repl, buffer, size, expected_type); + ret = check_object_signature(&reploid, buffer, size, expected_type); free(buffer); } return ret; -- cgit v1.2.3 From ef7b5195f1ee8ceef41fb2f03a46248ad7747d69 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:40 +0000 Subject: streaming: convert open_istream to use struct object_id Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/index-pack.c | 2 +- builtin/pack-objects.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/index-pack.c b/builtin/index-pack.c index b28ebfadd4..ae11d2a610 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -771,7 +771,7 @@ static int check_collison(struct object_entry *entry) memset(&data, 0, sizeof(data)); data.entry = entry; - data.st = open_istream(entry->idx.oid.hash, &type, &size, NULL); + data.st = open_istream(&entry->idx.oid, &type, &size, NULL); if (!data.st) return -1; if (size != entry->size || type != entry->type) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index a197926eaa..8307cc9b04 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -267,7 +267,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent if (!usable_delta) { if (entry->type == OBJ_BLOB && entry->size > big_file_threshold && - (st = open_istream(entry->idx.oid.hash, &type, &size, NULL)) != NULL) + (st = open_istream(&entry->idx.oid, &type, &size, NULL)) != NULL) buf = NULL; else { buf = read_sha1_file(entry->idx.oid.hash, &type, -- cgit v1.2.3 From 83eb08020cbce4f6dff93e6b67ce635a3cd657f0 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:41 +0000 Subject: builtin/mktree: convert to struct object_id Convert this file to use struct object_id. Modify one use of get_sha1_hex into parse_oid_hex; this is safe since we get the data from a strbuf. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/mktree.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'builtin') diff --git a/builtin/mktree.c b/builtin/mktree.c index f5f3c0eea1..e39fe5d423 100644 --- a/builtin/mktree.c +++ b/builtin/mktree.c @@ -10,13 +10,13 @@ static struct treeent { unsigned mode; - unsigned char sha1[20]; + struct object_id oid; int len; char name[FLEX_ARRAY]; } **entries; static int alloc, used; -static void append_to_tree(unsigned mode, unsigned char *sha1, char *path) +static void append_to_tree(unsigned mode, struct object_id *oid, char *path) { struct treeent *ent; size_t len = strlen(path); @@ -26,7 +26,7 @@ static void append_to_tree(unsigned mode, unsigned char *sha1, char *path) FLEX_ALLOC_MEM(ent, name, path, len); ent->mode = mode; ent->len = len; - hashcpy(ent->sha1, sha1); + oidcpy(&ent->oid, oid); ALLOC_GROW(entries, used + 1, alloc); entries[used++] = ent; @@ -54,7 +54,7 @@ static void write_tree(struct object_id *oid) for (i = 0; i < used; i++) { struct treeent *ent = entries[i]; strbuf_addf(&buf, "%o %s%c", ent->mode, ent->name, '\0'); - strbuf_add(&buf, ent->sha1, 20); + strbuf_add(&buf, ent->oid.hash, the_hash_algo->rawsz); } write_object_file(buf.buf, buf.len, tree_type, oid); @@ -69,11 +69,12 @@ static const char *mktree_usage[] = { static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_missing) { char *ptr, *ntr; + const char *p; unsigned mode; enum object_type mode_type; /* object type derived from mode */ enum object_type obj_type; /* object type derived from sha */ char *path, *to_free = NULL; - unsigned char sha1[20]; + struct object_id oid; ptr = buf; /* @@ -85,9 +86,8 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss die("input format error: %s", buf); ptr = ntr + 1; /* type */ ntr = strchr(ptr, ' '); - if (!ntr || buf + len <= ntr + 40 || - ntr[41] != '\t' || - get_sha1_hex(ntr + 1, sha1)) + if (!ntr || parse_oid_hex(ntr + 1, &oid, &p) || + *p != '\t') die("input format error: %s", buf); /* It is perfectly normal if we do not have a commit from a submodule */ @@ -116,12 +116,12 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss } /* Check the type of object identified by sha1 */ - obj_type = sha1_object_info(sha1, NULL); + obj_type = sha1_object_info(oid.hash, NULL); if (obj_type < 0) { if (allow_missing) { ; /* no problem - missing objects are presumed to be of the right type */ } else { - die("entry '%s' object %s is unavailable", path, sha1_to_hex(sha1)); + die("entry '%s' object %s is unavailable", path, oid_to_hex(&oid)); } } else { if (obj_type != mode_type) { @@ -131,11 +131,11 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss * because the new tree entry will never be correct. */ die("entry '%s' object %s is a %s but specified type was (%s)", - path, sha1_to_hex(sha1), type_name(obj_type), type_name(mode_type)); + path, oid_to_hex(&oid), type_name(obj_type), type_name(mode_type)); } } - append_to_tree(mode, sha1, path); + append_to_tree(mode, &oid, path); free(to_free); } -- cgit v1.2.3 From e816caa07b8acb5c8ed2d467666ca819fb80bc58 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:42 +0000 Subject: sha1_file: convert assert_sha1_type to object_id Convert this function to take a pointer to struct object_id and rename it to assert_oid_type. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/commit-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index e5bdf57b1e..ecf42191da 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) usage(commit_tree_usage); if (get_oid_commit(argv[i], &oid)) die("Not a valid object name %s", argv[i]); - assert_sha1_type(oid.hash, OBJ_COMMIT); + assert_oid_type(&oid, OBJ_COMMIT); new_parent(lookup_commit(&oid), &parents); continue; } -- cgit v1.2.3 From abef9020e3df87c441c9a3a95f592fce5fa49bb9 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:46 +0000 Subject: sha1_file: convert sha1_object_info* to object_id Convert sha1_object_info and sha1_object_info_extended to take pointers to struct object_id and rename them to use "oid" instead of "sha1" in their names. Update the declaration and definition and apply the following semantic patch, plus the standard object_id transforms: @@ expression E1, E2; @@ - sha1_object_info(E1.hash, E2) + oid_object_info(&E1, E2) @@ expression E1, E2; @@ - sha1_object_info(E1->hash, E2) + oid_object_info(E1, E2) @@ expression E1, E2, E3; @@ - sha1_object_info_extended(E1.hash, E2, E3) + oid_object_info_extended(&E1, E2, E3) @@ expression E1, E2, E3; @@ - sha1_object_info_extended(E1->hash, E2, E3) + oid_object_info_extended(E1, E2, E3) Signed-off-by: Junio C Hamano --- builtin/blame.c | 2 +- builtin/cat-file.c | 14 +++++++------- builtin/describe.c | 2 +- builtin/fast-export.c | 2 +- builtin/fetch.c | 2 +- builtin/fsck.c | 2 +- builtin/index-pack.c | 4 ++-- builtin/ls-tree.c | 2 +- builtin/mktree.c | 2 +- builtin/pack-objects.c | 7 +++---- builtin/prune.c | 2 +- builtin/replace.c | 10 +++++----- builtin/tag.c | 4 ++-- builtin/unpack-objects.c | 2 +- 14 files changed, 28 insertions(+), 29 deletions(-) (limited to 'builtin') diff --git a/builtin/blame.c b/builtin/blame.c index b980e8a1dd..f1a2fd6702 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -655,7 +655,7 @@ static int is_a_rev(const char *name) if (get_oid(name, &oid)) return 0; - return OBJ_NONE < sha1_object_info(oid.hash, NULL); + return OBJ_NONE < oid_object_info(&oid, NULL); } int cmd_blame(int argc, const char **argv, const char *prefix) diff --git a/builtin/cat-file.c b/builtin/cat-file.c index d90170f070..27f4f235f6 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -77,7 +77,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, switch (opt) { case 't': oi.type_name = &sb; - if (sha1_object_info_extended(oid.hash, &oi, flags) < 0) + if (oid_object_info_extended(&oid, &oi, flags) < 0) die("git cat-file: could not get object info"); if (sb.len) { printf("%s\n", sb.buf); @@ -88,7 +88,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, case 's': oi.sizep = &size; - if (sha1_object_info_extended(oid.hash, &oi, flags) < 0) + if (oid_object_info_extended(&oid, &oi, flags) < 0) die("git cat-file: could not get object info"); printf("%lu\n", size); return 0; @@ -116,7 +116,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, /* else fallthrough */ case 'p': - type = sha1_object_info(oid.hash, NULL); + type = oid_object_info(&oid, NULL); if (type < 0) die("Not a valid object name %s", obj_name); @@ -140,7 +140,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, case 0: if (type_from_string(exp_type) == OBJ_BLOB) { struct object_id blob_oid; - if (sha1_object_info(oid.hash, NULL) == OBJ_TAG) { + if (oid_object_info(&oid, NULL) == OBJ_TAG) { char *buffer = read_sha1_file(oid.hash, &type, &size); const char *target; if (!skip_prefix(buffer, "object ", &target) || @@ -150,7 +150,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, } else oidcpy(&blob_oid, &oid); - if (sha1_object_info(blob_oid.hash, NULL) == OBJ_BLOB) + if (oid_object_info(&blob_oid, NULL) == OBJ_BLOB) return stream_blob_to_fd(1, &blob_oid, NULL, 0); /* * we attempted to dereference a tag to a blob @@ -340,8 +340,8 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt, struct strbuf buf = STRBUF_INIT; if (!data->skip_object_info && - sha1_object_info_extended(data->oid.hash, &data->info, - OBJECT_INFO_LOOKUP_REPLACE) < 0) { + oid_object_info_extended(&data->oid, &data->info, + OBJECT_INFO_LOOKUP_REPLACE) < 0) { printf("%s missing\n", obj_name ? obj_name : oid_to_hex(&data->oid)); fflush(stdout); diff --git a/builtin/describe.c b/builtin/describe.c index 7e6535a8bd..de840f96a4 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -502,7 +502,7 @@ static void describe(const char *arg, int last_one) if (cmit) describe_commit(&oid, &sb); - else if (sha1_object_info(oid.hash, NULL) == OBJ_BLOB) + else if (oid_object_info(&oid, NULL) == OBJ_BLOB) describe_blob(oid, &sb); else die(_("%s is neither a commit nor blob"), arg); diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 9b049e9d08..d75a3a45d3 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -947,7 +947,7 @@ static void import_marks(char *input_file) if (last_idnum < mark) last_idnum = mark; - type = sha1_object_info(oid.hash, NULL); + type = oid_object_info(&oid, NULL); if (type < 0) die("object not found: %s", oid_to_hex(&oid)); diff --git a/builtin/fetch.c b/builtin/fetch.c index aeafe63ba6..90bb659390 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -637,7 +637,7 @@ static int update_local_ref(struct ref *ref, struct branch *current_branch = branch_get(NULL); const char *pretty_ref = prettify_refname(ref->name); - type = sha1_object_info(ref->new_oid.hash, NULL); + type = oid_object_info(&ref->new_oid, NULL); if (type < 0) die(_("object %s not found"), oid_to_hex(&ref->new_oid)); diff --git a/builtin/fsck.c b/builtin/fsck.c index eae018e3fb..0922558683 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -65,7 +65,7 @@ static const char *printable_type(struct object *obj) const char *ret; if (obj->type == OBJ_NONE) { - enum object_type type = sha1_object_info(obj->oid.hash, NULL); + enum object_type type = oid_object_info(&obj->oid, NULL); if (type > 0) object_as_type(obj, type, 0); } diff --git a/builtin/index-pack.c b/builtin/index-pack.c index ae11d2a610..32a98f3102 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -221,7 +221,7 @@ static unsigned check_object(struct object *obj) if (!(obj->flags & FLAG_CHECKED)) { unsigned long size; - int type = sha1_object_info(obj->oid.hash, &size); + int type = oid_object_info(&obj->oid, &size); if (type <= 0) die(_("did not receive expected object %s"), oid_to_hex(&obj->oid)); @@ -810,7 +810,7 @@ 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(oid->hash, &has_size); + has_type = oid_object_info(oid, &has_size); if (has_type < 0) die(_("cannot read existing object info %s"), oid_to_hex(oid)); if (has_type != type || has_size != size) diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index c98253adbb..d44b4f9c27 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -94,7 +94,7 @@ static int show_tree(const struct object_id *oid, struct strbuf *base, char size_text[24]; if (!strcmp(type, blob_type)) { unsigned long size; - if (sha1_object_info(oid->hash, &size) == OBJ_BAD) + if (oid_object_info(oid, &size) == OBJ_BAD) xsnprintf(size_text, sizeof(size_text), "BAD"); else diff --git a/builtin/mktree.c b/builtin/mktree.c index e39fe5d423..263c530315 100644 --- a/builtin/mktree.c +++ b/builtin/mktree.c @@ -116,7 +116,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss } /* Check the type of object identified by sha1 */ - obj_type = sha1_object_info(oid.hash, NULL); + obj_type = oid_object_info(&oid, NULL); if (obj_type < 0) { if (allow_missing) { ; /* no problem - missing objects are presumed to be of the right type */ diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 8307cc9b04..66bc0057fe 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1516,7 +1516,7 @@ static void check_object(struct object_entry *entry) unuse_pack(&w_curs); } - entry->type = sha1_object_info(entry->idx.oid.hash, &entry->size); + entry->type = oid_object_info(&entry->idx.oid, &entry->size); /* * The error condition is checked in prepare_pack(). This is * to permit a missing preferred base object to be ignored @@ -1578,8 +1578,7 @@ 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.oid.hash, - &entry->size); + entry->type = oid_object_info(&entry->idx.oid, &entry->size); } } @@ -2708,7 +2707,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs) static int add_loose_object(const struct object_id *oid, const char *path, void *data) { - enum object_type type = sha1_object_info(oid->hash, NULL); + enum object_type type = oid_object_info(oid, NULL); if (type < 0) { warning("loose object at %s could not be examined", path); diff --git a/builtin/prune.c b/builtin/prune.c index 4394d01c93..38ced18dad 100644 --- a/builtin/prune.c +++ b/builtin/prune.c @@ -50,7 +50,7 @@ static int prune_object(const struct object_id *oid, const char *fullpath, if (st.st_mtime > expire) return 0; if (show_only || verbose) { - enum object_type type = sha1_object_info(oid->hash, NULL); + enum object_type type = oid_object_info(oid, NULL); printf("%s %s\n", oid_to_hex(oid), (type > 0) ? type_name(type) : "unknown"); } diff --git a/builtin/replace.c b/builtin/replace.c index 9f01f3fc7f..19006e52bc 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -53,8 +53,8 @@ static int show_reference(const char *refname, const struct object_id *oid, if (get_oid(refname, &object)) return error("Failed to resolve '%s' as a valid ref.", refname); - obj_type = sha1_object_info(object.hash, NULL); - repl_type = sha1_object_info(oid->hash, NULL); + obj_type = oid_object_info(&object, NULL); + repl_type = oid_object_info(oid, NULL); printf("%s (%s) -> %s (%s)\n", refname, type_name(obj_type), oid_to_hex(oid), type_name(repl_type)); @@ -162,8 +162,8 @@ static int replace_object_oid(const char *object_ref, struct ref_transaction *transaction; struct strbuf err = STRBUF_INIT; - obj_type = sha1_object_info(object->hash, NULL); - repl_type = sha1_object_info(repl->hash, NULL); + obj_type = oid_object_info(object, NULL); + repl_type = oid_object_info(repl, NULL); if (!force && obj_type != repl_type) die("Objects must be of the same type.\n" "'%s' points to a replaced object of type '%s'\n" @@ -290,7 +290,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw) if (get_oid(object_ref, &old_oid) < 0) die("Not a valid object name: '%s'", object_ref); - type = sha1_object_info(old_oid.hash, NULL); + type = oid_object_info(&old_oid, NULL); if (type < 0) die("unable to get object type for %s", oid_to_hex(&old_oid)); diff --git a/builtin/tag.c b/builtin/tag.c index 644e6888be..11a9883d27 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -212,7 +212,7 @@ static void create_tag(const struct object_id *object, const char *tag, struct strbuf header = STRBUF_INIT; char *path = NULL; - type = sha1_object_info(object->hash, NULL); + type = oid_object_info(object, NULL); if (type <= OBJ_NONE) die(_("bad object type.")); @@ -298,7 +298,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb) } strbuf_addstr(sb, " ("); - type = sha1_object_info(oid->hash, NULL); + type = oid_object_info(oid, NULL); switch (type) { default: strbuf_addstr(sb, "object of unknown type"); diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 9f96949bc0..6d553374c0 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -198,7 +198,7 @@ static int check_object(struct object *obj, int type, void *data, struct fsck_op if (!(obj->flags & FLAG_OPEN)) { unsigned long size; - int type = sha1_object_info(obj->oid.hash, &size); + int type = oid_object_info(&obj->oid, &size); if (type != obj->type || type <= 0) die("object of unexpected type"); obj->flags |= FLAG_WRITTEN; -- cgit v1.2.3 From f8ddeff50930d7c330b6f68745631c34e63540bd Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:47 +0000 Subject: builtin/fmt-merge-msg: convert remaining code to object_id We were using the util pointer, which is a pointer to void, as an unsigned char pointer. The pointer actually points to a struct origin_data, which has a struct object_id as its first member, which in turn has an unsigned char array as its first member, so this was valid. Since we want to convert this to struct object_id, simply change the pointer we're using. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/fmt-merge-msg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index 8e8a15ea4a..0bc0dda99c 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -485,10 +485,10 @@ static void fmt_merge_msg_sigs(struct strbuf *out) struct strbuf tagbuf = STRBUF_INIT; for (i = 0; i < origins.nr; i++) { - unsigned char *sha1 = origins.items[i].util; + struct object_id *oid = origins.items[i].util; enum object_type type; unsigned long size, len; - char *buf = read_sha1_file(sha1, &type, &size); + char *buf = read_sha1_file(oid->hash, &type, &size); struct strbuf sig = STRBUF_INIT; if (!buf || type != OBJ_TAG) -- cgit v1.2.3 From e8adba25ff74f2cb95f480a86063190c0fb57ec2 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:48 +0000 Subject: builtin/notes: convert static functions to object_id Convert the remaining static functions to take pointers to struct object_id. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/notes.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'builtin') diff --git a/builtin/notes.c b/builtin/notes.c index 39304ba743..08ab9d7130 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -118,11 +118,11 @@ static int list_each_note(const struct object_id *object_oid, return 0; } -static void copy_obj_to_fd(int fd, const unsigned char *sha1) +static void copy_obj_to_fd(int fd, const struct object_id *oid) { unsigned long size; enum object_type type; - char *buf = read_sha1_file(sha1, &type, &size); + char *buf = read_sha1_file(oid->hash, &type, &size); if (buf) { if (size) write_or_die(fd, buf, size); @@ -162,7 +162,7 @@ static void write_commented_object(int fd, const struct object_id *object) } static void prepare_note_data(const struct object_id *object, struct note_data *d, - const unsigned char *old_note) + const struct object_id *old_note) { if (d->use_editor || !d->given) { int fd; @@ -457,7 +457,7 @@ static int add(int argc, const char **argv, const char *prefix) oid_to_hex(&object)); } - prepare_note_data(&object, &d, note ? note->hash : NULL); + prepare_note_data(&object, &d, note); if (d.buf.len || allow_empty) { write_note_data(&d, &new_note); if (add_note(t, &object, &new_note, combine_notes_overwrite)) @@ -602,7 +602,7 @@ static int append_edit(int argc, const char **argv, const char *prefix) t = init_notes_check(argv[0], NOTES_INIT_WRITABLE); note = get_note(t, &object); - prepare_note_data(&object, &d, edit && note ? note->hash : NULL); + prepare_note_data(&object, &d, edit && note ? note : NULL); if (note && !edit) { /* Append buf to previous note contents */ -- cgit v1.2.3 From 916bc35b29af6e0f4f215dea9c84e4185de0fec4 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:51 +0000 Subject: tree-walk: convert tree entry functions to object_id Convert get_tree_entry and find_tree_entry to take pointers to struct object_id. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/rm.c | 2 +- builtin/update-index.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/rm.c b/builtin/rm.c index 4a2fcca27b..974a7ef5bf 100644 --- a/builtin/rm.c +++ b/builtin/rm.c @@ -178,7 +178,7 @@ static int check_local_mod(struct object_id *head, int index_only) * way as changed from the HEAD. */ if (no_head - || get_tree_entry(head->hash, name, oid.hash, &mode) + || get_tree_entry(head, name, &oid, &mode) || ce->ce_mode != create_ce_mode(mode) || oidcmp(&ce->oid, &oid)) staged_changes = 1; diff --git a/builtin/update-index.c b/builtin/update-index.c index 58d1c2d282..9625d1e10a 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -592,7 +592,7 @@ static struct cache_entry *read_one_ent(const char *which, int size; struct cache_entry *ce; - if (get_tree_entry(ent->hash, path, oid.hash, &mode)) { + if (get_tree_entry(ent, path, &oid, &mode)) { if (which) error("%s: not in %s branch.", path, which); return NULL; -- cgit v1.2.3 From 02f0547eaaeeec3446b77a29593f9233cf94d626 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:52 +0000 Subject: sha1_file: convert read_object_with_reference to object_id Convert read_object_with_reference to take pointers to struct object_id. Update the internals of the function accordingly. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/cat-file.c | 2 +- builtin/grep.c | 4 ++-- builtin/pack-objects.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'builtin') diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 27f4f235f6..4382b4447e 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -159,7 +159,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, * fall-back to the usual case. */ } - buf = read_object_with_reference(oid.hash, exp_type, &size, NULL); + buf = read_object_with_reference(&oid, exp_type, &size, NULL); break; default: diff --git a/builtin/grep.c b/builtin/grep.c index 9a0973e8f1..386a86b66e 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -452,7 +452,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject, object = parse_object_or_die(oid, oid_to_hex(oid)); grep_read_lock(); - data = read_object_with_reference(object->oid.hash, tree_type, + data = read_object_with_reference(&object->oid, tree_type, &size, NULL); grep_read_unlock(); @@ -614,7 +614,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec, int hit, len; grep_read_lock(); - data = read_object_with_reference(obj->oid.hash, tree_type, + data = read_object_with_reference(&obj->oid, tree_type, &size, NULL); grep_read_unlock(); diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 66bc0057fe..a0ccbf6699 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -1351,7 +1351,7 @@ static void add_preferred_base(struct object_id *oid) if (window <= num_preferred_base++) return; - data = read_object_with_reference(oid->hash, tree_type, &size, tree_oid.hash); + data = read_object_with_reference(oid, tree_type, &size, &tree_oid); if (!data) return; -- cgit v1.2.3 From b4f5aca40e6f77cbabcbf4ff003c3cf30a1830c8 Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:53 +0000 Subject: sha1_file: convert read_sha1_file to struct object_id Convert read_sha1_file to take a pointer to struct object_id and rename it read_object_file. Do the same for read_sha1_file_extended. Convert one use in grep.c to use the new function without any other code change, since the pointer being passed is a void pointer that is already initialized with a pointer to struct object_id. Update the declaration and definitions of the modified functions, and apply the following semantic patch to convert the remaining callers: @@ expression E1, E2, E3; @@ - read_sha1_file(E1.hash, E2, E3) + read_object_file(&E1, E2, E3) @@ expression E1, E2, E3; @@ - read_sha1_file(E1->hash, E2, E3) + read_object_file(E1, E2, E3) @@ expression E1, E2, E3, E4; @@ - read_sha1_file_extended(E1.hash, E2, E3, E4) + read_object_file_extended(&E1, E2, E3, E4) @@ expression E1, E2, E3, E4; @@ - read_sha1_file_extended(E1->hash, E2, E3, E4) + read_object_file_extended(E1, E2, E3, E4) Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/cat-file.c | 14 ++++++++------ builtin/difftool.c | 2 +- builtin/fast-export.c | 4 ++-- builtin/fmt-merge-msg.c | 2 +- builtin/grep.c | 2 +- builtin/index-pack.c | 5 +++-- builtin/log.c | 2 +- builtin/merge-tree.c | 5 +++-- builtin/mktag.c | 2 +- builtin/notes.c | 6 +++--- builtin/pack-objects.c | 16 ++++++---------- builtin/reflog.c | 2 +- builtin/tag.c | 4 ++-- builtin/unpack-file.c | 2 +- builtin/unpack-objects.c | 2 +- builtin/verify-commit.c | 2 +- 16 files changed, 36 insertions(+), 36 deletions(-) (limited to 'builtin') diff --git a/builtin/cat-file.c b/builtin/cat-file.c index 4382b4447e..2c46d257cd 100644 --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@ -32,7 +32,7 @@ static int filter_object(const char *path, unsigned mode, { enum object_type type; - *buf = read_sha1_file(oid->hash, &type, size); + *buf = read_object_file(oid, &type, size); if (!*buf) return error(_("cannot read object %s '%s'"), oid_to_hex(oid), path); @@ -130,7 +130,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, if (type == OBJ_BLOB) return stream_blob_to_fd(1, &oid, NULL, 0); - buf = read_sha1_file(oid.hash, &type, &size); + buf = read_object_file(&oid, &type, &size); if (!buf) die("Cannot read object %s", obj_name); @@ -141,7 +141,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name, if (type_from_string(exp_type) == OBJ_BLOB) { struct object_id blob_oid; if (oid_object_info(&oid, NULL) == OBJ_TAG) { - char *buffer = read_sha1_file(oid.hash, &type, &size); + char *buffer = read_object_file(&oid, &type, + &size); const char *target; if (!skip_prefix(buffer, "object ", &target) || get_oid_hex(target, &blob_oid)) @@ -304,8 +305,9 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d enum object_type type; if (!textconv_object(data->rest, 0100644, oid, 1, &contents, &size)) - contents = read_sha1_file(oid->hash, &type, - &size); + contents = read_object_file(oid, + &type, + &size); if (!contents) die("could not convert '%s' %s", oid_to_hex(oid), data->rest); @@ -321,7 +323,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d unsigned long size; void *contents; - contents = read_sha1_file(oid->hash, &type, &size); + contents = read_object_file(oid, &type, &size); if (!contents) die("object %s disappeared", oid_to_hex(oid)); if (type != data->type) diff --git a/builtin/difftool.c b/builtin/difftool.c index bcc79d1888..ee8dce019e 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -306,7 +306,7 @@ static char *get_symlink(const struct object_id *oid, const char *path) } else { enum object_type type; unsigned long size; - data = read_sha1_file(oid->hash, &type, &size); + data = read_object_file(oid, &type, &size); if (!data) die(_("could not read object %s for symlink %s"), oid_to_hex(oid), path); diff --git a/builtin/fast-export.c b/builtin/fast-export.c index d75a3a45d3..a15898d641 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -237,7 +237,7 @@ static void export_blob(const struct object_id *oid) object = (struct object *)lookup_blob(oid); eaten = 0; } else { - buf = read_sha1_file(oid->hash, &type, &size); + buf = read_object_file(oid, &type, &size); if (!buf) die ("Could not read blob %s", oid_to_hex(oid)); if (check_object_signature(oid, buf, size, type_name(type)) < 0) @@ -682,7 +682,7 @@ static void handle_tag(const char *name, struct tag *tag) return; } - buf = read_sha1_file(tag->object.oid.hash, &type, &size); + buf = read_object_file(&tag->object.oid, &type, &size); if (!buf) die ("Could not read tag %s", oid_to_hex(&tag->object.oid)); message = memmem(buf, size, "\n\n", 2); diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index 0bc0dda99c..bd680be687 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -488,7 +488,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out) struct object_id *oid = origins.items[i].util; enum object_type type; unsigned long size, len; - char *buf = read_sha1_file(oid->hash, &type, &size); + char *buf = read_object_file(oid, &type, &size); struct strbuf sig = STRBUF_INIT; if (!buf || type != OBJ_TAG) diff --git a/builtin/grep.c b/builtin/grep.c index 386a86b66e..bf50bab6f8 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -306,7 +306,7 @@ static void *lock_and_read_oid_file(const struct object_id *oid, enum object_typ void *data; grep_read_lock(); - data = read_sha1_file(oid->hash, type, size); + data = read_object_file(oid, type, size); grep_read_unlock(); return data; } diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 32a98f3102..7873e7243f 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -815,7 +815,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry, die(_("cannot read existing object info %s"), oid_to_hex(oid)); if (has_type != type || has_size != size) die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid)); - has_data = read_sha1_file(oid->hash, &has_type, &has_size); + has_data = read_object_file(oid, &has_type, &has_size); read_unlock(); if (!data) data = new_data = get_data_from_pack(obj_entry); @@ -1373,7 +1373,8 @@ static void fix_unresolved_deltas(struct hashfile *f) if (objects[d->obj_no].real_type != OBJ_REF_DELTA) continue; - base_obj->data = read_sha1_file(d->oid.hash, &type, &base_obj->size); + base_obj->data = read_object_file(&d->oid, &type, + &base_obj->size); if (!base_obj->data) continue; diff --git a/builtin/log.c b/builtin/log.c index 411339c1ed..71f68a3e4f 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -518,7 +518,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev) { unsigned long size; enum object_type type; - char *buf = read_sha1_file(oid->hash, &type, &size); + char *buf = read_object_file(oid, &type, &size); int offset = 0; if (!buf) diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index d01ddecf66..32736e0b10 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -60,7 +60,7 @@ static void *result(struct merge_list *entry, unsigned long *size) const char *path = entry->path; if (!entry->stage) - return read_sha1_file(entry->blob->object.oid.hash, &type, size); + return read_object_file(&entry->blob->object.oid, &type, size); base = NULL; if (entry->stage == 1) { base = entry->blob; @@ -82,7 +82,8 @@ static void *origin(struct merge_list *entry, unsigned long *size) enum object_type type; while (entry) { if (entry->stage == 2) - return read_sha1_file(entry->blob->object.oid.hash, &type, size); + return read_object_file(&entry->blob->object.oid, + &type, size); entry = entry->link; } return NULL; diff --git a/builtin/mktag.c b/builtin/mktag.c index 810b24bef3..cfb777b3c8 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -23,7 +23,7 @@ static int verify_object(const struct object_id *oid, const char *expected_type) int ret = -1; enum object_type type; unsigned long size; - void *buffer = read_sha1_file(oid->hash, &type, &size); + void *buffer = read_object_file(oid, &type, &size); const unsigned char *repl = lookup_replace_object(oid->hash); if (buffer) { diff --git a/builtin/notes.c b/builtin/notes.c index 08ab9d7130..5ddfa44cde 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -122,7 +122,7 @@ static void copy_obj_to_fd(int fd, const struct object_id *oid) { unsigned long size; enum object_type type; - char *buf = read_sha1_file(oid->hash, &type, &size); + char *buf = read_object_file(oid, &type, &size); if (buf) { if (size) write_or_die(fd, buf, size); @@ -253,7 +253,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset) if (get_oid(arg, &object)) die(_("failed to resolve '%s' as a valid ref."), arg); - if (!(buf = read_sha1_file(object.hash, &type, &len))) { + if (!(buf = read_object_file(&object, &type, &len))) { free(buf); die(_("failed to read object '%s'."), arg); } @@ -608,7 +608,7 @@ static int append_edit(int argc, const char **argv, const char *prefix) /* Append buf to previous note contents */ unsigned long size; enum object_type type; - char *prev_buf = read_sha1_file(note->hash, &type, &size); + char *prev_buf = read_object_file(note, &type, &size); strbuf_grow(&d.buf, size + 1); if (d.buf.len && prev_buf && size) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index a0ccbf6699..a1d674608a 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -122,11 +122,10 @@ static void *get_delta(struct object_entry *entry) void *buf, *base_buf, *delta_buf; enum object_type type; - buf = read_sha1_file(entry->idx.oid.hash, &type, &size); + buf = read_object_file(&entry->idx.oid, &type, &size); if (!buf) die("unable to read %s", oid_to_hex(&entry->idx.oid)); - base_buf = read_sha1_file(entry->delta->idx.oid.hash, &type, - &base_size); + base_buf = read_object_file(&entry->delta->idx.oid, &type, &base_size); if (!base_buf) die("unable to read %s", oid_to_hex(&entry->delta->idx.oid)); @@ -270,8 +269,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent (st = open_istream(&entry->idx.oid, &type, &size, NULL)) != NULL) buf = NULL; else { - buf = read_sha1_file(entry->idx.oid.hash, &type, - &size); + buf = read_object_file(&entry->idx.oid, &type, &size); if (!buf) die(_("unable to read %s"), oid_to_hex(&entry->idx.oid)); @@ -1190,7 +1188,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid) /* Did not find one. Either we got a bogus request or * we need to read and perhaps cache. */ - data = read_sha1_file(oid->hash, &type, &size); + data = read_object_file(oid, &type, &size); if (!data) return NULL; if (type != OBJ_TREE) { @@ -1870,8 +1868,7 @@ 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.oid.hash, &type, - &sz); + trg->data = read_object_file(&trg_entry->idx.oid, &type, &sz); read_unlock(); if (!trg->data) die("object %s cannot be read", @@ -1884,8 +1881,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src, } if (!src->data) { read_lock(); - src->data = read_sha1_file(src_entry->idx.oid.hash, &type, - &sz); + src->data = read_object_file(&src_entry->idx.oid, &type, &sz); read_unlock(); if (!src->data) { if (src_entry->preferred_base) { diff --git a/builtin/reflog.c b/builtin/reflog.c index ac3dcd7a51..25f7c5ef0b 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -74,7 +74,7 @@ static int tree_is_complete(const struct object_id *oid) if (!tree->buffer) { enum object_type type; unsigned long size; - void *data = read_sha1_file(oid->hash, &type, &size); + void *data = read_object_file(oid, &type, &size); if (!data) { tree->object.flags |= INCOMPLETE; return 0; diff --git a/builtin/tag.c b/builtin/tag.c index 11a9883d27..86450bae05 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -168,7 +168,7 @@ static void write_tag_body(int fd, const struct object_id *oid) enum object_type type; char *buf, *sp; - buf = read_sha1_file(oid->hash, &type, &size); + buf = read_object_file(oid, &type, &size); if (!buf) return; /* skip header */ @@ -304,7 +304,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb) strbuf_addstr(sb, "object of unknown type"); break; case OBJ_COMMIT: - if ((buf = read_sha1_file(oid->hash, &type, &size)) != NULL) { + if ((buf = read_object_file(oid, &type, &size)) != NULL) { subject_len = find_commit_subject(buf, &subject_start); strbuf_insert(sb, sb->len, subject_start, subject_len); } else { diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c index 32e0155577..300eb59657 100644 --- a/builtin/unpack-file.c +++ b/builtin/unpack-file.c @@ -9,7 +9,7 @@ static char *create_temp_file(struct object_id *oid) unsigned long size; int fd; - buf = read_sha1_file(oid->hash, &type, &size); + buf = read_object_file(oid, &type, &size); if (!buf || type != OBJ_BLOB) die("unable to read blob object %s", oid_to_hex(oid)); diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 6d553374c0..af02e1bc6b 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -422,7 +422,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size, if (resolve_against_held(nr, &base_oid, delta_data, delta_size)) return; - base = read_sha1_file(base_oid.hash, &type, &base_size); + base = read_object_file(&base_oid, &type, &base_size); if (!base) { error("failed to read delta-pack base object %s", oid_to_hex(&base_oid)); diff --git a/builtin/verify-commit.c b/builtin/verify-commit.c index 05315ea7c9..dcdaada111 100644 --- a/builtin/verify-commit.c +++ b/builtin/verify-commit.c @@ -44,7 +44,7 @@ static int verify_commit(const char *name, unsigned flags) if (get_oid(name, &oid)) return error("commit '%s' not found.", name); - buf = read_sha1_file(oid.hash, &type, &size); + buf = read_object_file(&oid, &type, &size); if (!buf) return error("%s: unable to read file.", name); if (type != OBJ_COMMIT) -- cgit v1.2.3 From b383a13cc0dbed752b69d7ad249bc857b9d3607b Mon Sep 17 00:00:00 2001 From: "brian m. carlson" Date: Mon, 12 Mar 2018 02:27:54 +0000 Subject: Convert lookup_replace_object to struct object_id Convert both the argument and the return value to be pointers to struct object_id. Update the callers and their internals to deal with the new type. Remove several temporaries which are no longer needed. Signed-off-by: brian m. carlson Signed-off-by: Junio C Hamano --- builtin/mktag.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'builtin') diff --git a/builtin/mktag.c b/builtin/mktag.c index cfb777b3c8..9f5a50a8fd 100644 --- a/builtin/mktag.c +++ b/builtin/mktag.c @@ -24,14 +24,11 @@ static int verify_object(const struct object_id *oid, const char *expected_type) enum object_type type; unsigned long size; void *buffer = read_object_file(oid, &type, &size); - const unsigned char *repl = lookup_replace_object(oid->hash); + const struct object_id *repl = lookup_replace_object(oid); if (buffer) { - struct object_id reploid; - hashcpy(reploid.hash, repl); - if (type == type_from_string(expected_type)) - ret = check_object_signature(&reploid, buffer, size, expected_type); + ret = check_object_signature(repl, buffer, size, expected_type); free(buffer); } return ret; -- cgit v1.2.3