diff options
Diffstat (limited to 'builtin')
39 files changed, 300 insertions, 334 deletions
diff --git a/builtin/am.c b/builtin/am.c index f1a25ab6ad..9fb42fdd71 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1441,7 +1441,7 @@ static void get_commit_info(struct am_state *state, struct commit *commit) assert(!state->msg); msg = strstr(buffer, "\n\n"); if (!msg) - die(_("unable to parse commit %s"), sha1_to_hex(commit->object.sha1)); + die(_("unable to parse commit %s"), oid_to_hex(&commit->object.oid)); state->msg = xstrdup(msg + 2); state->msg_len = strlen(state->msg); } diff --git a/builtin/blame.c b/builtin/blame.c index 83612f5b64..1df13cf7f4 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -506,7 +506,7 @@ static int fill_blob_sha1_and_mode(struct origin *origin) { if (!is_null_sha1(origin->blob_sha1)) return 0; - if (get_tree_entry(origin->commit->object.sha1, + if (get_tree_entry(origin->commit->object.oid.hash, origin->path, origin->blob_sha1, &origin->mode)) goto error_out; @@ -557,11 +557,11 @@ static struct origin *find_origin(struct scoreboard *sb, PATHSPEC_LITERAL_PATH, "", paths); diff_setup_done(&diff_opts); - if (is_null_sha1(origin->commit->object.sha1)) - do_diff_cache(parent->tree->object.sha1, &diff_opts); + if (is_null_oid(&origin->commit->object.oid)) + do_diff_cache(parent->tree->object.oid.hash, &diff_opts); else - diff_tree_sha1(parent->tree->object.sha1, - origin->commit->tree->object.sha1, + diff_tree_sha1(parent->tree->object.oid.hash, + origin->commit->tree->object.oid.hash, "", &diff_opts); diffcore_std(&diff_opts); @@ -627,11 +627,11 @@ static struct origin *find_rename(struct scoreboard *sb, diff_opts.single_follow = origin->path; diff_setup_done(&diff_opts); - if (is_null_sha1(origin->commit->object.sha1)) - do_diff_cache(parent->tree->object.sha1, &diff_opts); + if (is_null_oid(&origin->commit->object.oid)) + do_diff_cache(parent->tree->object.oid.hash, &diff_opts); else - diff_tree_sha1(parent->tree->object.sha1, - origin->commit->tree->object.sha1, + diff_tree_sha1(parent->tree->object.oid.hash, + origin->commit->tree->object.oid.hash, "", &diff_opts); diffcore_std(&diff_opts); @@ -977,8 +977,8 @@ static void pass_blame_to_parent(struct scoreboard *sb, if (diff_hunks(&file_p, &file_o, 0, blame_chunk_cb, &d)) die("unable to generate diff (%s -> %s)", - sha1_to_hex(parent->commit->object.sha1), - sha1_to_hex(target->commit->object.sha1)); + oid_to_hex(&parent->commit->object.oid), + oid_to_hex(&target->commit->object.oid)); /* The rest are the same as the parent */ blame_chunk(&d.dstq, &d.srcq, INT_MAX, d.offset, INT_MAX, parent); *d.dstq = NULL; @@ -1126,7 +1126,7 @@ static void find_copy_in_blob(struct scoreboard *sb, memset(split, 0, sizeof(struct blame_entry [3])); if (diff_hunks(file_p, &file_o, 1, handle_split_cb, &d)) die("unable to generate diff (%s)", - sha1_to_hex(parent->commit->object.sha1)); + oid_to_hex(&parent->commit->object.oid)); /* remainder, if any, all match the preimage */ handle_split(sb, ent, d.tlno, d.plno, ent->num_lines, parent, split); } @@ -1275,11 +1275,11 @@ static void find_copy_in_parent(struct scoreboard *sb, && (!porigin || strcmp(target->path, porigin->path)))) DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER); - if (is_null_sha1(target->commit->object.sha1)) - do_diff_cache(parent->tree->object.sha1, &diff_opts); + if (is_null_oid(&target->commit->object.oid)) + do_diff_cache(parent->tree->object.oid.hash, &diff_opts); else - diff_tree_sha1(parent->tree->object.sha1, - target->commit->tree->object.sha1, + diff_tree_sha1(parent->tree->object.oid.hash, + target->commit->tree->object.oid.hash, "", &diff_opts); if (!DIFF_OPT_TST(&diff_opts, FIND_COPIES_HARDER)) @@ -1690,7 +1690,7 @@ static void get_commit_info(struct commit *commit, if (len) strbuf_add(&ret->summary, subject, len); else - strbuf_addf(&ret->summary, "(%s)", sha1_to_hex(commit->object.sha1)); + strbuf_addf(&ret->summary, "(%s)", oid_to_hex(&commit->object.oid)); unuse_commit_buffer(commit, message); } @@ -1733,7 +1733,7 @@ static int emit_one_suspect_detail(struct origin *suspect, int repeat) printf("boundary\n"); if (suspect->previous) { struct origin *prev = suspect->previous; - printf("previous %s ", sha1_to_hex(prev->commit->object.sha1)); + printf("previous %s ", oid_to_hex(&prev->commit->object.oid)); write_name_quoted(prev->path, stdout, '\n'); } @@ -1752,7 +1752,7 @@ static void found_guilty_entry(struct blame_entry *ent) struct origin *suspect = ent->suspect; printf("%s %d %d %d\n", - sha1_to_hex(suspect->commit->object.sha1), + oid_to_hex(&suspect->commit->object.oid), ent->s_lno + 1, ent->lno + 1, ent->num_lines); emit_one_suspect_detail(suspect, 0); write_filename_info(suspect->path); @@ -1882,7 +1882,7 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent, struct origin *suspect = ent->suspect; char hex[GIT_SHA1_HEXSZ + 1]; - sha1_to_hex_r(hex, suspect->commit->object.sha1); + sha1_to_hex_r(hex, suspect->commit->object.oid.hash); printf("%s %d %d %d\n", hex, ent->s_lno + 1, @@ -1922,7 +1922,7 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt) int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP); get_commit_info(suspect->commit, &ci, 1); - sha1_to_hex_r(hex, suspect->commit->object.sha1); + sha1_to_hex_r(hex, suspect->commit->object.oid.hash); cp = nth_line(sb, ent->lno); for (cnt = 0; cnt < ent->num_lines; cnt++) { @@ -2077,7 +2077,7 @@ static int read_ancestry(const char *graft_file) static int update_auto_abbrev(int auto_abbrev, struct origin *suspect) { - const char *uniq = find_unique_abbrev(suspect->commit->object.sha1, + const char *uniq = find_unique_abbrev(suspect->commit->object.oid.hash, auto_abbrev); int len = strlen(uniq); if (auto_abbrev < len) @@ -2153,7 +2153,7 @@ static void sanity_check_refcnt(struct scoreboard *sb) if (ent->suspect->refcnt <= 0) { fprintf(stderr, "%s in %s has negative refcnt %d\n", ent->suspect->path, - sha1_to_hex(ent->suspect->commit->object.sha1), + oid_to_hex(&ent->suspect->commit->object.oid), ent->suspect->refcnt); baa = 1; } @@ -2216,7 +2216,7 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path) struct commit_list *parents; for (parents = work_tree->parents; parents; parents = parents->next) { - const unsigned char *commit_sha1 = parents->item->object.sha1; + const unsigned char *commit_sha1 = parents->item->object.oid.hash; unsigned char blob_sha1[20]; unsigned mode; @@ -2310,7 +2310,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt, strbuf_addstr(&msg, "tree 0000000000000000000000000000000000000000\n"); for (parent = commit->parents; parent; parent = parent->next) strbuf_addf(&msg, "parent %s\n", - sha1_to_hex(parent->item->object.sha1)); + oid_to_hex(&parent->item->object.oid)); strbuf_addf(&msg, "author %s\n" "committer %s\n\n" @@ -2402,10 +2402,12 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt, return commit; } -static struct object_array_entry *find_single_final(struct rev_info *revs) +static struct commit *find_single_final(struct rev_info *revs, + const char **name_p) { int i; - struct object_array_entry *found = NULL; + struct commit *found = NULL; + const char *name = NULL; for (i = 0; i < revs->pending.nr; i++) { struct object *obj = revs->pending.objects[i].item; @@ -2417,22 +2419,20 @@ static struct object_array_entry *find_single_final(struct rev_info *revs) die("Non commit %s?", revs->pending.objects[i].name); if (found) die("More than one commit to dig from %s and %s?", - revs->pending.objects[i].name, - found->name); - found = &(revs->pending.objects[i]); + revs->pending.objects[i].name, name); + found = (struct commit *)obj; + name = revs->pending.objects[i].name; } + if (name_p) + *name_p = name; return found; } static char *prepare_final(struct scoreboard *sb) { - struct object_array_entry *found = find_single_final(sb->revs); - if (found) { - sb->final = (struct commit *) found->item; - return xstrdup(found->name); - } else { - return NULL; - } + const char *name; + sb->final = find_single_final(sb->revs, &name); + return xstrdup_or_null(name); } static char *prepare_initial(struct scoreboard *sb) @@ -2720,11 +2720,9 @@ parse_done: die("Cannot use --contents with final commit object name"); if (reverse && revs.first_parent_only) { - struct object_array_entry *entry = find_single_final(sb.revs); - if (!entry) + final_commit = find_single_final(sb.revs, NULL); + if (!final_commit) die("--reverse and --first-parent together require specified latest commit"); - else - final_commit = (struct commit*) entry->item; } /* @@ -2740,7 +2738,7 @@ parse_done: sb.revs->children.name = "children"; while (c->parents && - hashcmp(c->object.sha1, sb.final->object.sha1)) { + oidcmp(&c->object.oid, &sb.final->object.oid)) { struct commit_list *l = xcalloc(1, sizeof(*l)); l->item = c; @@ -2750,11 +2748,11 @@ parse_done: c = c->parents->item; } - if (hashcmp(c->object.sha1, sb.final->object.sha1)) + if (oidcmp(&c->object.oid, &sb.final->object.oid)) die("--reverse --first-parent together require range along first-parent chain"); } - if (is_null_sha1(sb.final->object.sha1)) { + if (is_null_oid(&sb.final->object.oid)) { o = sb.final->util; sb.final_buf = xmemdupz(o->file.ptr, o->file.size); sb.final_buf_size = o->file.size; diff --git a/builtin/branch.c b/builtin/branch.c index b99a436ef3..3f6c825db1 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -349,7 +349,7 @@ static void add_verbose_info(struct strbuf *out, struct ref_array_item *item, fill_tracking_info(&stat, refname, filter->verbose > 1); strbuf_addf(out, " %s %s%s", - find_unique_abbrev(item->commit->object.sha1, filter->abbrev), + find_unique_abbrev(item->commit->object.oid.hash, filter->abbrev), stat.buf, sub); strbuf_release(&stat); strbuf_release(&subject); diff --git a/builtin/checkout.c b/builtin/checkout.c index e346f521b0..e8110a9243 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -56,8 +56,8 @@ static int post_checkout_hook(struct commit *old, struct commit *new, int changed) { return run_hook_le(NULL, "post-checkout", - sha1_to_hex(old ? old->object.sha1 : null_sha1), - sha1_to_hex(new ? new->object.sha1 : null_sha1), + sha1_to_hex(old ? old->object.oid.hash : null_sha1), + sha1_to_hex(new ? new->object.oid.hash : null_sha1), changed ? "1" : "0", NULL); /* "new" can be NULL when checking out from the index before a commit exists. */ @@ -401,7 +401,7 @@ static void describe_detached_head(const char *msg, struct commit *commit) if (!parse_commit(commit)) pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb); fprintf(stderr, "%s %s... %s\n", msg, - find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV), sb.buf); + find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf); strbuf_release(&sb); } @@ -510,10 +510,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.sha1 : + old->commit->object.oid.hash : EMPTY_TREE_SHA1_BIN); init_tree_desc(&trees[0], tree->buffer, tree->size); - tree = parse_tree_indirect(new->commit->object.sha1); + tree = parse_tree_indirect(new->commit->object.oid.hash); init_tree_desc(&trees[1], tree->buffer, tree->size); ret = unpack_trees(2, trees, &topts); @@ -641,7 +641,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts, old_desc = old->name; if (!old_desc && old->commit) - old_desc = sha1_to_hex(old->commit->object.sha1); + old_desc = oid_to_hex(&old->commit->object.oid); reflog_msg = getenv("GIT_REFLOG_ACTION"); if (!reflog_msg) @@ -653,7 +653,7 @@ static void update_refs_for_switch(const struct checkout_opts *opts, if (!strcmp(new->name, "HEAD") && !new->path && !opts->force_detach) { /* Nothing to do. */ } else if (opts->force_detach || !new->path) { /* No longer on any branch. */ - update_ref(msg.buf, "HEAD", new->commit->object.sha1, NULL, + update_ref(msg.buf, "HEAD", new->commit->object.oid.hash, NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR); if (!opts->quiet) { if (old->path && advice_detached_head) @@ -704,7 +704,7 @@ static void describe_one_orphan(struct strbuf *sb, struct commit *commit) { strbuf_addstr(sb, " "); strbuf_addstr(sb, - find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV)); + find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV)); strbuf_addch(sb, ' '); if (!parse_commit(commit)) pp_commit_easy(CMIT_FMT_ONELINE, commit, sb); @@ -762,7 +762,7 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs) " git branch <new-branch-name> %s\n\n", /* Give ngettext() the count */ lost), - find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV)); + find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV)); } /* @@ -780,10 +780,10 @@ static void orphaned_commit_warning(struct commit *old, struct commit *new) setup_revisions(0, NULL, &revs, NULL); object->flags &= ~UNINTERESTING; - add_pending_object(&revs, object, sha1_to_hex(object->sha1)); + add_pending_object(&revs, object, oid_to_hex(&object->oid)); for_each_ref(add_pending_uninteresting_ref, &revs); - add_pending_sha1(&revs, "HEAD", new->object.sha1, UNINTERESTING); + add_pending_sha1(&revs, "HEAD", new->object.oid.hash, UNINTERESTING); refs = revs.pending; revs.leak_pending = 1; diff --git a/builtin/clone.c b/builtin/clone.c index caae43e7a3..a0b3cd9e56 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -559,7 +559,7 @@ static void write_remote_refs(const struct ref *local_refs) for (r = local_refs; r; r = r->next) { if (!r->peer_ref) continue; - if (ref_transaction_create(t, r->peer_ref->name, r->old_sha1, + if (ref_transaction_create(t, r->peer_ref->name, r->old_oid.hash, 0, NULL, &err)) die("%s", err.buf); } @@ -579,9 +579,9 @@ static void write_followtags(const struct ref *refs, const char *msg) continue; if (ends_with(ref->name, "^{}")) continue; - if (!has_sha1_file(ref->old_sha1)) + if (!has_object_file(&ref->old_oid)) continue; - update_ref(msg, ref->name, ref->old_sha1, + update_ref(msg, ref->name, ref->old_oid.hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR); } } @@ -601,7 +601,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20]) if (!ref) return -1; - hashcpy(sha1, ref->old_sha1); + hashcpy(sha1, ref->old_oid.hash); *rm = ref->next; return 0; } @@ -650,14 +650,14 @@ static void update_head(const struct ref *our, const struct ref *remote, /* Local default branch link */ create_symref("HEAD", our->name, NULL); if (!option_bare) { - update_ref(msg, "HEAD", our->old_sha1, NULL, 0, + update_ref(msg, "HEAD", our->old_oid.hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR); install_branch_config(0, head, option_origin, our->name); } } else if (our) { - struct commit *c = lookup_commit_reference(our->old_sha1); + struct commit *c = lookup_commit_reference(our->old_oid.hash); /* --branch specifies a non-branch (i.e. tags), detach HEAD */ - update_ref(msg, "HEAD", c->object.sha1, + update_ref(msg, "HEAD", c->object.oid.hash, NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR); } else if (remote) { /* @@ -665,7 +665,7 @@ static void update_head(const struct ref *our, const struct ref *remote, * HEAD points to a branch but we don't know which one. * Detach HEAD in all these cases. */ - update_ref(msg, "HEAD", remote->old_sha1, + update_ref(msg, "HEAD", remote->old_oid.hash, NULL, REF_NODEREF, UPDATE_REFS_DIE_ON_ERR); } } @@ -1016,7 +1016,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) * remote HEAD check. */ for (ref = refs; ref; ref = ref->next) - if (is_null_sha1(ref->old_sha1)) { + if (is_null_oid(&ref->old_oid)) { complete_refs_before_fetch = 0; break; } diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index 8747c0f2fb..3feeffeab1 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -16,11 +16,11 @@ static const char *sign_commit; static void new_parent(struct commit *parent, struct commit_list **parents_p) { - unsigned char *sha1 = parent->object.sha1; + struct object_id *oid = &parent->object.oid; struct commit_list *parents; for (parents = *parents_p; parents; parents = parents->next) { if (parents->item == parent) { - error("duplicate parent %s ignored", sha1_to_hex(sha1)); + error("duplicate parent %s ignored", oid_to_hex(oid)); return; } parents_p = &parents->next; diff --git a/builtin/commit.c b/builtin/commit.c index dca09e2c3b..d054f84960 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -32,6 +32,7 @@ #include "sequencer.h" #include "notes-utils.h" #include "mailmap.h" +#include "sigchain.h" static const char * const builtin_commit_usage[] = { N_("git commit [<options>] [--] <pathspec>..."), @@ -299,7 +300,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.sha1); + tree = parse_tree_indirect(current_head->object.oid.hash); if (!tree) die(_("failed to unpack HEAD tree object")); parse_tree(tree); @@ -1537,8 +1538,10 @@ static int run_rewrite_hook(const unsigned char *oldsha1, return code; n = snprintf(buf, sizeof(buf), "%s %s\n", sha1_to_hex(oldsha1), sha1_to_hex(newsha1)); + sigchain_push(SIGPIPE, SIG_IGN); write_in_full(proc.in, buf, n); close(proc.in); + sigchain_pop(SIGPIPE); return finish_command(&proc); } @@ -1766,7 +1769,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) if (!transaction || ref_transaction_update(transaction, "HEAD", sha1, current_head - ? current_head->object.sha1 : null_sha1, + ? current_head->object.oid.hash : null_sha1, 0, sb.buf, &err) || ref_transaction_commit(transaction, &err)) { rollback_index_files(); @@ -1793,10 +1796,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix) cfg = init_copy_notes_for_rewrite("amend"); if (cfg) { /* we are amending, so current_head is not NULL */ - copy_note_for_rewrite(cfg, current_head->object.sha1, sha1); + copy_note_for_rewrite(cfg, current_head->object.oid.hash, sha1); finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'"); } - run_rewrite_hook(current_head->object.sha1, sha1); + run_rewrite_hook(current_head->object.oid.hash, sha1); } if (!quiet) print_summary(prefix, sha1, !current_head); diff --git a/builtin/describe.c b/builtin/describe.c index 7df554326b..8a25abe0a0 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -252,14 +252,14 @@ static void describe(const char *arg, int last_one) if (!cmit) die(_("%s is not a valid '%s' object"), arg, commit_type); - n = find_commit_name(cmit->object.sha1); + n = find_commit_name(cmit->object.oid.hash); if (n && (tags || all || n->prio == 2)) { /* * Exact match to an existing ref. */ display_name(n); if (longformat) - show_suffix(0, n->tag ? n->tag->tagged->sha1 : sha1); + show_suffix(0, n->tag ? n->tag->tagged->oid.hash : sha1); if (dirty) printf("%s", dirty); printf("\n"); @@ -267,7 +267,7 @@ static void describe(const char *arg, int last_one) } if (!max_candidates) - die(_("no tag exactly matches '%s'"), sha1_to_hex(cmit->object.sha1)); + die(_("no tag exactly matches '%s'"), oid_to_hex(&cmit->object.oid)); if (debug) fprintf(stderr, _("searching to describe %s\n"), arg); @@ -317,7 +317,7 @@ static void describe(const char *arg, int last_one) if (annotated_cnt && !list) { if (debug) fprintf(stderr, _("finished search at %s\n"), - sha1_to_hex(c->object.sha1)); + oid_to_hex(&c->object.oid)); break; } while (parents) { @@ -334,9 +334,9 @@ static void describe(const char *arg, int last_one) } if (!match_cnt) { - const unsigned char *sha1 = cmit->object.sha1; + struct object_id *oid = &cmit->object.oid; if (always) { - printf("%s", find_unique_abbrev(sha1, abbrev)); + printf("%s", find_unique_abbrev(oid->hash, abbrev)); if (dirty) printf("%s", dirty); printf("\n"); @@ -345,11 +345,11 @@ static void describe(const char *arg, int last_one) if (unannotated_cnt) die(_("No annotated tags can describe '%s'.\n" "However, there were unannotated tags: try --tags."), - sha1_to_hex(sha1)); + oid_to_hex(oid)); else die(_("No tags can describe '%s'.\n" "Try --always, or create some tags."), - sha1_to_hex(sha1)); + oid_to_hex(oid)); } qsort(all_matches, match_cnt, sizeof(all_matches[0]), compare_pt); @@ -374,13 +374,13 @@ static void describe(const char *arg, int last_one) _("more than %i tags found; listed %i most recent\n" "gave up search at %s\n"), max_candidates, max_candidates, - sha1_to_hex(gave_up_on->object.sha1)); + oid_to_hex(&gave_up_on->object.oid)); } } display_name(all_matches[0].name); if (abbrev) - show_suffix(all_matches[0].depth, cmit->object.sha1); + show_suffix(all_matches[0].depth, cmit->object.oid.hash); if (dirty) printf("%s", dirty); printf("\n"); diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index 12b683d021..2a12b81e06 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -49,9 +49,9 @@ static int stdin_diff_trees(struct tree *tree1, char *line, int len) tree2 = lookup_tree(sha1); if (!tree2 || parse_tree(tree2)) return -1; - printf("%s %s\n", sha1_to_hex(tree1->object.sha1), - sha1_to_hex(tree2->object.sha1)); - diff_tree_sha1(tree1->object.sha1, tree2->object.sha1, + printf("%s %s\n", oid_to_hex(&tree1->object.oid), + oid_to_hex(&tree2->object.oid)); + diff_tree_sha1(tree1->object.oid.hash, tree2->object.oid.hash, "", &log_tree_opt.diffopt); log_tree_diff_flush(&log_tree_opt); return 0; @@ -139,7 +139,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) break; case 1: tree1 = opt->pending.objects[0].item; - diff_tree_commit_sha1(tree1->sha1); + diff_tree_commit_sha1(tree1->oid.hash); break; case 2: tree1 = opt->pending.objects[0].item; @@ -149,8 +149,8 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) tree2 = tree1; tree1 = tmp; } - diff_tree_sha1(tree1->sha1, - tree2->sha1, + diff_tree_sha1(tree1->oid.hash, + tree2->oid.hash, "", &opt->diffopt); log_tree_diff_flush(opt); break; diff --git a/builtin/diff.c b/builtin/diff.c index 4326fa56bf..ed0acca91f 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -175,8 +175,8 @@ static int builtin_diff_tree(struct rev_info *revs, */ if (ent1->item->flags & UNINTERESTING) swap = 1; - sha1[swap] = ent0->item->sha1; - sha1[1 - swap] = ent1->item->sha1; + sha1[swap] = ent0->item->oid.hash; + sha1[1 - swap] = ent1->item->oid.hash; diff_tree_sha1(sha1[0], sha1[1], "", &revs->diffopt); log_tree_diff_flush(revs); return 0; @@ -196,8 +196,8 @@ static int builtin_diff_combined(struct rev_info *revs, if (!revs->dense_combined_merges && !revs->combine_merges) revs->dense_combined_merges = revs->combine_merges = 1; for (i = 1; i < ents; i++) - sha1_array_append(&parents, ent[i].item->sha1); - diff_tree_combined(ent[0].item->sha1, &parents, + sha1_array_append(&parents, ent[i].item->oid.hash); + diff_tree_combined(ent[0].item->oid.hash, &parents, revs->dense_combined_merges, revs); sha1_array_clear(&parents); return 0; @@ -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->sha1); + obj = parse_object(obj->oid.hash); 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].sha1, obj->sha1); + hashcpy(blob[blobs].sha1, obj->oid.hash); blob[blobs].name = name; blob[blobs].mode = entry->mode; blobs++; diff --git a/builtin/fast-export.c b/builtin/fast-export.c index d23f3beba9..d9ac5d8410 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -544,13 +544,13 @@ static void handle_commit(struct commit *commit, struct rev_info *rev) author = strstr(commit_buffer, "\nauthor "); if (!author) die ("Could not find author in commit %s", - sha1_to_hex(commit->object.sha1)); + oid_to_hex(&commit->object.oid)); author++; author_end = strchrnul(author, '\n'); committer = strstr(author_end, "\ncommitter "); if (!committer) die ("Could not find committer in commit %s", - sha1_to_hex(commit->object.sha1)); + oid_to_hex(&commit->object.oid)); committer++; committer_end = strchrnul(committer, '\n'); message = strstr(committer_end, "\n\n"); @@ -562,11 +562,11 @@ static void handle_commit(struct commit *commit, struct rev_info *rev) get_object_mark(&commit->parents->item->object) != 0 && !full_tree) { parse_commit_or_die(commit->parents->item); - diff_tree_sha1(commit->parents->item->tree->object.sha1, - commit->tree->object.sha1, "", &rev->diffopt); + diff_tree_sha1(commit->parents->item->tree->object.oid.hash, + commit->tree->object.oid.hash, "", &rev->diffopt); } else - diff_root_tree_sha1(commit->tree->object.sha1, + diff_root_tree_sha1(commit->tree->object.oid.hash, "", &rev->diffopt); /* Export the referenced blobs, and remember the marks. */ @@ -661,13 +661,13 @@ static void handle_tag(const char *name, struct tag *tag) } if (tagged->type == OBJ_TREE) { warning("Omitting tag %s,\nsince tags of trees (or tags of tags of trees, etc.) are not supported.", - sha1_to_hex(tag->object.sha1)); + oid_to_hex(&tag->object.oid)); return; } - buf = read_sha1_file(tag->object.sha1, &type, &size); + buf = read_sha1_file(tag->object.oid.hash, &type, &size); if (!buf) - die ("Could not read tag %s", sha1_to_hex(tag->object.sha1)); + die ("Could not read tag %s", oid_to_hex(&tag->object.oid)); message = memmem(buf, size, "\n\n", 2); if (message) { message += 2; @@ -706,16 +706,16 @@ static void handle_tag(const char *name, struct tag *tag) case ABORT: die ("Encountered signed tag %s; use " "--signed-tags=<mode> to handle it.", - sha1_to_hex(tag->object.sha1)); + oid_to_hex(&tag->object.oid)); case WARN: warning ("Exporting signed tag %s", - sha1_to_hex(tag->object.sha1)); + oid_to_hex(&tag->object.oid)); /* fallthru */ case VERBATIM: break; case WARN_STRIP: warning ("Stripping signature from tag %s", - sha1_to_hex(tag->object.sha1)); + oid_to_hex(&tag->object.oid)); /* fallthru */ case STRIP: message_size = signature + 1 - message; @@ -731,14 +731,14 @@ static void handle_tag(const char *name, struct tag *tag) case ABORT: die ("Tag %s tags unexported object; use " "--tag-of-filtered-object=<mode> to handle it.", - sha1_to_hex(tag->object.sha1)); + oid_to_hex(&tag->object.oid)); case DROP: /* Ignore this tag altogether */ return; case REWRITE: if (tagged->type != OBJ_COMMIT) { die ("Tag %s tags unexported %s!", - sha1_to_hex(tag->object.sha1), + oid_to_hex(&tag->object.oid), typename(tagged->type)); } p = (struct commit *)tagged; @@ -751,7 +751,7 @@ static void handle_tag(const char *name, struct tag *tag) break; if (!p->parents) die ("Can't find replacement commit for tag %s\n", - sha1_to_hex(tag->object.sha1)); + oid_to_hex(&tag->object.oid)); p = p->parents->item; } tagged_mark = get_object_mark(&p->object); @@ -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.sha1); + parse_object(tag->object.oid.hash); string_list_append(&extra_refs, full_name)->util = tag; tag = (struct tag *)tag->tagged; } @@ -828,7 +828,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info) case OBJ_COMMIT: break; case OBJ_BLOB: - export_blob(commit->object.sha1); + export_blob(commit->object.oid.hash); continue; default: /* OBJ_TAG (nested tags) is already handled */ warning("Tag points to object of unexpected type %s, skipping.", @@ -888,7 +888,7 @@ static void export_marks(char *file) if (deco->base && deco->base->type == 1) { mark = ptr_to_mark(deco->decoration); if (fprintf(f, ":%"PRIu32" %s\n", mark, - sha1_to_hex(deco->base->sha1)) < 0) { + oid_to_hex(&deco->base->oid)) < 0) { e = 1; break; } diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index 4a6b340ab6..cf3019e05b 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -14,12 +14,14 @@ static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc, const char *name, int namelen) { struct ref *ref = xcalloc(1, sizeof(*ref) + namelen + 1); - unsigned char sha1[20]; - - if (namelen > 41 && name[40] == ' ' && !get_sha1_hex(name, sha1)) { - hashcpy(ref->old_sha1, sha1); - name += 41; - namelen -= 41; + struct object_id oid; + const int chunksz = GIT_SHA1_HEXSZ + 1; + + if (namelen > chunksz && name[chunksz - 1] == ' ' && + !get_oid_hex(name, &oid)) { + oidcpy(&ref->old_oid, &oid); + name += chunksz; + namelen -= chunksz; } memcpy(ref->name, name, namelen); @@ -210,7 +212,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix) while (ref) { printf("%s %s\n", - sha1_to_hex(ref->old_sha1), ref->name); + oid_to_hex(&ref->old_oid), ref->name); ref = ref->next; } diff --git a/builtin/fetch.c b/builtin/fetch.c index ed84963a57..c85f3471d4 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -196,7 +196,7 @@ static int will_fetch(struct ref **head, const unsigned char *sha1) { struct ref *rm = *head; while (rm) { - if (!hashcmp(rm->old_sha1, sha1)) + if (!hashcmp(rm->old_oid.hash, sha1)) return 1; rm = rm->next; } @@ -224,8 +224,8 @@ static void find_non_local_tags(struct transport *transport, * as one to ignore by setting util to NULL. */ if (ends_with(ref->name, "^{}")) { - if (item && !has_sha1_file(ref->old_sha1) && - !will_fetch(head, ref->old_sha1) && + if (item && !has_object_file(&ref->old_oid) && + !will_fetch(head, ref->old_oid.hash) && !has_sha1_file(item->util) && !will_fetch(head, item->util)) item->util = NULL; @@ -251,7 +251,7 @@ static void find_non_local_tags(struct transport *transport, continue; item = string_list_insert(&remote_refs, ref->name); - item->util = (void *)ref->old_sha1; + item->util = (void *)&ref->old_oid; } string_list_clear(&existing_refs, 1); @@ -273,7 +273,7 @@ static void find_non_local_tags(struct transport *transport, { struct ref *rm = alloc_ref(item->string); rm->peer_ref = alloc_ref(item->string); - hashcpy(rm->old_sha1, item->util); + oidcpy(&rm->old_oid, item->util); **tail = rm; *tail = &rm->next; } @@ -419,8 +419,8 @@ static int s_update_ref(const char *action, transaction = ref_transaction_begin(&err); if (!transaction || ref_transaction_update(transaction, ref->name, - ref->new_sha1, - check_old ? ref->old_sha1 : NULL, + ref->new_oid.hash, + check_old ? ref->old_oid.hash : NULL, 0, msg, &err)) goto fail; @@ -453,11 +453,11 @@ 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_sha1, NULL); + type = sha1_object_info(ref->new_oid.hash, NULL); if (type < 0) - die(_("object %s not found"), sha1_to_hex(ref->new_sha1)); + die(_("object %s not found"), oid_to_hex(&ref->new_oid)); - if (!hashcmp(ref->old_sha1, ref->new_sha1)) { + if (!oidcmp(&ref->old_oid, &ref->new_oid)) { if (verbosity > 0) strbuf_addf(display, "= %-*s %-*s -> %s", TRANSPORT_SUMMARY(_("[up to date]")), @@ -468,7 +468,7 @@ static int update_local_ref(struct ref *ref, if (current_branch && !strcmp(ref->name, current_branch->name) && !(update_head_ok || is_bare_repository()) && - !is_null_sha1(ref->old_sha1)) { + !is_null_oid(&ref->old_oid)) { /* * If this is the head, and it's not okay to update * the head, and the old value of the head isn't empty... @@ -480,7 +480,7 @@ static int update_local_ref(struct ref *ref, return 1; } - if (!is_null_sha1(ref->old_sha1) && + if (!is_null_oid(&ref->old_oid) && starts_with(ref->name, "refs/tags/")) { int r; r = s_update_ref("updating tag", ref, 0); @@ -492,8 +492,8 @@ static int update_local_ref(struct ref *ref, return r; } - current = lookup_commit_reference_gently(ref->old_sha1, 1); - updated = lookup_commit_reference_gently(ref->new_sha1, 1); + current = lookup_commit_reference_gently(ref->old_oid.hash, 1); + updated = lookup_commit_reference_gently(ref->new_oid.hash, 1); if (!current || !updated) { const char *msg; const char *what; @@ -517,7 +517,7 @@ static int update_local_ref(struct ref *ref, if ((recurse_submodules != RECURSE_SUBMODULES_OFF) && (recurse_submodules != RECURSE_SUBMODULES_ON)) - check_for_new_submodule_commits(ref->new_sha1); + check_for_new_submodule_commits(ref->new_oid.hash); r = s_update_ref(msg, ref, 0); strbuf_addf(display, "%c %-*s %-*s -> %s%s", r ? '!' : '*', @@ -530,12 +530,12 @@ 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.sha1, DEFAULT_ABBREV); + strbuf_add_unique_abbrev(&quickref, current->object.oid.hash, DEFAULT_ABBREV); strbuf_addstr(&quickref, ".."); - strbuf_add_unique_abbrev(&quickref, ref->new_sha1, DEFAULT_ABBREV); + strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash, DEFAULT_ABBREV); if ((recurse_submodules != RECURSE_SUBMODULES_OFF) && (recurse_submodules != RECURSE_SUBMODULES_ON)) - check_for_new_submodule_commits(ref->new_sha1); + check_for_new_submodule_commits(ref->new_oid.hash); r = s_update_ref("fast-forward", ref, 1); strbuf_addf(display, "%c %-*s %-*s -> %s%s", r ? '!' : ' ', @@ -547,12 +547,12 @@ 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.sha1, DEFAULT_ABBREV); + strbuf_add_unique_abbrev(&quickref, current->object.oid.hash, DEFAULT_ABBREV); strbuf_addstr(&quickref, "..."); - strbuf_add_unique_abbrev(&quickref, ref->new_sha1, DEFAULT_ABBREV); + strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash, DEFAULT_ABBREV); if ((recurse_submodules != RECURSE_SUBMODULES_OFF) && (recurse_submodules != RECURSE_SUBMODULES_ON)) - check_for_new_submodule_commits(ref->new_sha1); + check_for_new_submodule_commits(ref->new_oid.hash); r = s_update_ref("forced-update", ref, 1); strbuf_addf(display, "%c %-*s %-*s -> %s (%s)", r ? '!' : '+', @@ -580,7 +580,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20]) if (!ref) return -1; /* end of the list */ *rm = ref->next; - hashcpy(sha1, ref->old_sha1); + hashcpy(sha1, ref->old_oid.hash); return 0; } @@ -631,7 +631,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, continue; } - commit = lookup_commit_reference_gently(rm->old_sha1, 1); + commit = lookup_commit_reference_gently(rm->old_oid.hash, 1); if (!commit) rm->fetch_head_status = FETCH_HEAD_NOT_FOR_MERGE; @@ -640,8 +640,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, if (rm->peer_ref) { ref = alloc_ref(rm->peer_ref->name); - hashcpy(ref->old_sha1, rm->peer_ref->old_sha1); - hashcpy(ref->new_sha1, rm->old_sha1); + oidcpy(&ref->old_oid, &rm->peer_ref->old_oid); + oidcpy(&ref->new_oid, &rm->old_oid); ref->force = rm->peer_ref->force; } @@ -686,7 +686,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name, /* fall-through */ case FETCH_HEAD_MERGE: fprintf(fp, "%s\t%s\t%s", - sha1_to_hex(rm->old_sha1), + oid_to_hex(&rm->old_oid), merge_status_marker, note.buf); for (i = 0; i < url_len; ++i) @@ -928,7 +928,7 @@ static int do_fetch(struct transport *transport, rm->peer_ref->name); if (peer_item) { struct object_id *old_oid = peer_item->util; - hashcpy(rm->peer_ref->old_sha1, old_oid->hash); + oidcpy(&rm->peer_ref->old_oid, old_oid); } } } diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index 846004b833..e5658c320e 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -378,7 +378,7 @@ static void shortlog(const char *name, if (!sb.len) string_list_append(&subjects, - sha1_to_hex(commit->object.sha1)); + oid_to_hex(&commit->object.oid)); else string_list_append(&subjects, strbuf_detach(&sb, NULL)); } @@ -568,7 +568,7 @@ static void find_merge_parents(struct merge_parents *result, if (!parent) continue; commit_list_insert(parent, &parents); - add_merge_parent(result, obj->sha1, parent->object.sha1); + add_merge_parent(result, obj->oid.hash, parent->object.oid.hash); } head_commit = lookup_commit(head); if (head_commit) @@ -578,7 +578,7 @@ static void find_merge_parents(struct merge_parents *result, while (parents) { struct commit *cmit = pop_commit(&parents); for (i = 0; i < result->nr; i++) - if (!hashcmp(result->item[i].commit, cmit->object.sha1)) + if (!hashcmp(result->item[i].commit, cmit->object.oid.hash)) result->item[i].used = 1; } diff --git a/builtin/fsck.c b/builtin/fsck.c index 8b8bb42c51..55eac756f7 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -67,7 +67,7 @@ static void objreport(struct object *obj, const char *msg_type, const char *err) { fprintf(stderr, "%s in %s %s: %s\n", - msg_type, typename(obj->type), sha1_to_hex(obj->sha1), err); + msg_type, typename(obj->type), oid_to_hex(&obj->oid), err); } static int objerror(struct object *obj, const char *err) @@ -97,7 +97,7 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt if (!obj) { /* ... these references to parent->fld are safe here */ printf("broken link from %7s %s\n", - typename(parent->type), sha1_to_hex(parent->sha1)); + typename(parent->type), oid_to_hex(&parent->oid)); printf("broken link from %7s %s\n", (type == OBJ_ANY ? "unknown" : typename(type)), "unknown"); errors_found |= ERROR_REACHABLE; @@ -112,11 +112,11 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt return 0; obj->flags |= REACHABLE; if (!(obj->flags & HAS_OBJ)) { - if (parent && !has_sha1_file(obj->sha1)) { + if (parent && !has_object_file(&obj->oid)) { printf("broken link from %7s %s\n", - typename(parent->type), sha1_to_hex(parent->sha1)); + typename(parent->type), oid_to_hex(&parent->oid)); printf(" to %7s %s\n", - typename(obj->type), sha1_to_hex(obj->sha1)); + typename(obj->type), oid_to_hex(&obj->oid)); errors_found |= ERROR_REACHABLE; } return 1; @@ -186,11 +186,11 @@ static void check_reachable_object(struct object *obj) * do a full fsck */ if (!(obj->flags & HAS_OBJ)) { - if (has_sha1_pack(obj->sha1)) + if (has_sha1_pack(obj->oid.hash)) return; /* it is in pack - forget about it */ - if (connectivity_only && has_sha1_file(obj->sha1)) + if (connectivity_only && has_object_file(&obj->oid)) return; - printf("missing %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1)); + printf("missing %s %s\n", typename(obj->type), oid_to_hex(&obj->oid)); errors_found |= ERROR_REACHABLE; return; } @@ -215,7 +215,7 @@ static void check_unreachable_object(struct object *obj) * since this is something that is prunable. */ if (show_unreachable) { - printf("unreachable %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1)); + printf("unreachable %s %s\n", typename(obj->type), oid_to_hex(&obj->oid)); return; } @@ -234,11 +234,11 @@ static void check_unreachable_object(struct object *obj) if (!obj->used) { if (show_dangling) printf("dangling %s %s\n", typename(obj->type), - sha1_to_hex(obj->sha1)); + oid_to_hex(&obj->oid)); if (write_lost_and_found) { char *filename = git_pathdup("lost-found/%s/%s", obj->type == OBJ_COMMIT ? "commit" : "other", - sha1_to_hex(obj->sha1)); + oid_to_hex(&obj->oid)); FILE *f; if (safe_create_leading_directories_const(filename)) { @@ -249,10 +249,10 @@ static void check_unreachable_object(struct object *obj) if (!(f = fopen(filename, "w"))) die_errno("Could not open '%s'", filename); if (obj->type == OBJ_BLOB) { - if (stream_blob_to_fd(fileno(f), obj->sha1, NULL, 1)) + if (stream_blob_to_fd(fileno(f), obj->oid.hash, NULL, 1)) die_errno("Could not write '%s'", filename); } else - fprintf(f, "%s\n", sha1_to_hex(obj->sha1)); + fprintf(f, "%s\n", oid_to_hex(&obj->oid)); if (fclose(f)) die_errno("Could not finish '%s'", filename); @@ -271,7 +271,7 @@ static void check_unreachable_object(struct object *obj) static void check_object(struct object *obj) { if (verbose) - fprintf(stderr, "Checking %s\n", sha1_to_hex(obj->sha1)); + fprintf(stderr, "Checking %s\n", oid_to_hex(&obj->oid)); if (obj->flags & REACHABLE) check_reachable_object(obj); @@ -307,7 +307,7 @@ static int fsck_obj(struct object *obj) if (verbose) fprintf(stderr, "Checking %s %s\n", - typename(obj->type), sha1_to_hex(obj->sha1)); + typename(obj->type), oid_to_hex(&obj->oid)); if (fsck_walk(obj, NULL, &fsck_obj_options)) objerror(obj, "broken links"); @@ -326,15 +326,15 @@ static int fsck_obj(struct object *obj) free_commit_buffer(commit); if (!commit->parents && show_root) - printf("root %s\n", sha1_to_hex(commit->object.sha1)); + printf("root %s\n", oid_to_hex(&commit->object.oid)); } if (obj->type == OBJ_TAG) { struct tag *tag = (struct tag *) obj; if (show_tags && tag->tagged) { - printf("tagged %s %s", typename(tag->tagged->type), sha1_to_hex(tag->tagged->sha1)); - printf(" (%s) in %s\n", tag->tag, sha1_to_hex(tag->object.sha1)); + printf("tagged %s %s", typename(tag->tagged->type), oid_to_hex(&tag->tagged->oid)); + printf(" (%s) in %s\n", tag->tag, oid_to_hex(&tag->object.oid)); } } diff --git a/builtin/grep.c b/builtin/grep.c index d04f4400d9..4229cae390 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -459,7 +459,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec, struct object *obj, const char *name, const char *path) { if (obj->type == OBJ_BLOB) - return grep_sha1(opt, obj->sha1, name, 0, path); + return grep_sha1(opt, obj->oid.hash, name, 0, path); if (obj->type == OBJ_COMMIT || obj->type == OBJ_TREE) { struct tree_desc tree; void *data; @@ -468,12 +468,12 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec, int hit, len; grep_read_lock(); - data = read_object_with_reference(obj->sha1, tree_type, + data = read_object_with_reference(obj->oid.hash, tree_type, &size, NULL); grep_read_unlock(); if (!data) - die(_("unable to read tree (%s)"), sha1_to_hex(obj->sha1)); + die(_("unable to read tree (%s)"), oid_to_hex(&obj->oid)); len = name ? strlen(name) : 0; strbuf_init(&base, PATH_MAX + len + 1); @@ -612,11 +612,6 @@ static int pattern_callback(const struct option *opt, const char *arg, return 0; } -static int help_callback(const struct option *opt, const char *arg, int unset) -{ - return -1; -} - int cmd_grep(int argc, const char **argv, const char *prefix) { int hit = 0; @@ -738,18 +733,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix) PARSE_OPT_OPTARG, NULL, (intptr_t)default_pager }, OPT_BOOL(0, "ext-grep", &external_grep_allowed__ignored, N_("allow calling of grep(1) (ignored by this build)")), - { OPTION_CALLBACK, 0, "help-all", NULL, NULL, N_("show usage"), - PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, help_callback }, OPT_END() }; - /* - * 'git grep -h', unlike 'git grep -h <pattern>', is a request - * to show usage information and exit. - */ - if (argc == 2 && !strcmp(argv[1], "-h")) - usage_with_options(grep_usage, options); - init_grep_defaults(); git_config(grep_cmd_config, NULL); grep_init(&opt, prefix); @@ -766,8 +752,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix) */ argc = parse_options(argc, argv, prefix, options, grep_usage, PARSE_OPT_KEEP_DASHDASH | - PARSE_OPT_STOP_AT_NON_OPTION | - PARSE_OPT_NO_INTERNAL_HELP); + PARSE_OPT_STOP_AT_NON_OPTION); grep_commit_pattern_type(pattern_type_arg, &opt); if (use_index && !startup_info->have_repository) diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 1ad1bde696..6a01509587 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -199,7 +199,7 @@ static int mark_link(struct object *obj, int type, void *data, struct fsck_optio return -1; if (type != OBJ_ANY && obj->type != type) - die(_("object type mismatch at %s"), sha1_to_hex(obj->sha1)); + die(_("object type mismatch at %s"), oid_to_hex(&obj->oid)); obj->flags |= FLAG_LINK; return 0; @@ -217,13 +217,13 @@ static unsigned check_object(struct object *obj) if (!(obj->flags & FLAG_CHECKED)) { unsigned long size; - int type = sha1_object_info(obj->sha1, &size); + int type = sha1_object_info(obj->oid.hash, &size); if (type <= 0) die(_("did not receive expected object %s"), - sha1_to_hex(obj->sha1)); + oid_to_hex(&obj->oid)); if (type != obj->type) die(_("object %s: expected type %s, found %s"), - sha1_to_hex(obj->sha1), + oid_to_hex(&obj->oid), typename(obj->type), typename(type)); obj->flags |= FLAG_CHECKED; return 1; @@ -842,7 +842,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry, fsck_object(obj, buf, size, &fsck_options)) die(_("Error in object")); if (fsck_walk(obj, NULL, &fsck_options)) - die(_("Not all child objects of %s are reachable"), sha1_to_hex(obj->sha1)); + die(_("Not all child objects of %s are reachable"), oid_to_hex(&obj->oid)); if (obj->type == OBJ_TREE) { struct tree *item = (struct tree *) obj; diff --git a/builtin/init-db.c b/builtin/init-db.c index f59f40768e..07229d60f1 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -24,18 +24,6 @@ static int init_shared_repository = -1; static const char *init_db_template_dir; static const char *git_link; -static void safe_create_dir(const char *dir, int share) -{ - if (mkdir(dir, 0777) < 0) { - if (errno != EEXIST) { - perror(dir); - exit(1); - } - } - else if (share && adjust_shared_perm(dir)) - die(_("Could not make %s writable by group"), dir); -} - static void copy_templates_1(struct strbuf *path, struct strbuf *template, DIR *dir) { diff --git a/builtin/log.c b/builtin/log.c index dda671d975..069bd3a909 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -552,7 +552,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) const char *name = objects[i].name; switch (o->type) { case OBJ_BLOB: - ret = show_blob_object(o->sha1, &rev, name); + ret = show_blob_object(o->oid.hash, &rev, name); break; case OBJ_TAG: { struct tag *t = (struct tag *)o; @@ -563,14 +563,14 @@ int cmd_show(int argc, const char **argv, const char *prefix) diff_get_color_opt(&rev.diffopt, DIFF_COMMIT), t->tag, diff_get_color_opt(&rev.diffopt, DIFF_RESET)); - ret = show_tag_object(o->sha1, &rev); + ret = show_tag_object(o->oid.hash, &rev); rev.shown_one = 1; if (ret) break; - o = parse_object(t->tagged->sha1); + o = parse_object(t->tagged->oid.hash); if (!o) ret = error(_("Could not read object %s"), - sha1_to_hex(t->tagged->sha1)); + oid_to_hex(&t->tagged->oid)); objects[i].item = o; i--; break; @@ -830,8 +830,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->sha1); - c2 = lookup_commit_reference(o2->sha1); + c1 = lookup_commit_reference(o1->oid.hash); + c2 = lookup_commit_reference(o2->oid.hash); if ((flags1 & UNINTERESTING) == (flags2 & UNINTERESTING)) die(_("Not a range.")); @@ -896,8 +896,8 @@ static void add_branch_description(struct strbuf *buf, const char *branch_name) static char *find_branch_name(struct rev_info *rev) { int i, positive = -1; - unsigned char branch_sha1[20]; - const unsigned char *tip_sha1; + struct object_id branch_oid; + const struct object_id *tip_oid; const char *ref, *v; char *full_ref, *branch = NULL; @@ -912,10 +912,10 @@ static char *find_branch_name(struct rev_info *rev) if (positive < 0) return NULL; ref = rev->cmdline.rev[positive].name; - tip_sha1 = rev->cmdline.rev[positive].item->sha1; - if (dwim_ref(ref, strlen(ref), branch_sha1, &full_ref) && + tip_oid = &rev->cmdline.rev[positive].item->oid; + if (dwim_ref(ref, strlen(ref), branch_oid.hash, &full_ref) && skip_prefix(full_ref, "refs/heads/", &v) && - !hashcmp(tip_sha1, branch_sha1)) + !oidcmp(tip_oid, &branch_oid)) branch = xstrdup(v); free(full_ref); return branch; @@ -993,8 +993,8 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, diff_setup_done(&opts); - diff_tree_sha1(origin->tree->object.sha1, - head->tree->object.sha1, + diff_tree_sha1(origin->tree->object.oid.hash, + head->tree->object.oid.hash, "", &opts); diffcore_std(&opts); diff_flush(&opts); @@ -1443,7 +1443,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) /* Don't say anything if head and upstream are the same. */ if (rev.pending.nr == 2) { struct object_array_entry *o = rev.pending.objects; - if (hashcmp(o[0].item->sha1, o[1].item->sha1) == 0) + if (oidcmp(&o[0].item->oid, &o[1].item->oid) == 0) return 0; } get_patch_ids(&rev, &ids); @@ -1550,7 +1550,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) string_list_append(rev.ref_message_ids, rev.message_id); } - gen_message_id(&rev, sha1_to_hex(commit->object.sha1)); + gen_message_id(&rev, oid_to_hex(&commit->object.oid)); } if (!use_stdout && @@ -1612,12 +1612,12 @@ static void print_commit(char sign, struct commit *commit, int verbose, { if (!verbose) { printf("%c %s\n", sign, - find_unique_abbrev(commit->object.sha1, abbrev)); + find_unique_abbrev(commit->object.oid.hash, abbrev)); } else { struct strbuf buf = STRBUF_INIT; pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf); printf("%c %s %s\n", sign, - find_unique_abbrev(commit->object.sha1, abbrev), + find_unique_abbrev(commit->object.oid.hash, abbrev), buf.buf); strbuf_release(&buf); } @@ -1675,7 +1675,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix) /* Don't say anything if head and upstream are the same. */ if (revs.pending.nr == 2) { struct object_array_entry *o = revs.pending.objects; - if (hashcmp(o[0].item->sha1, o[1].item->sha1) == 0) + if (oidcmp(&o[0].item->oid, &o[1].item->oid) == 0) return 0; } diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index a31024900b..fa65a8448a 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -125,7 +125,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) continue; if (!tail_match(pattern, ref->name)) continue; - printf("%s %s\n", sha1_to_hex(ref->old_sha1), ref->name); + printf("%s %s\n", oid_to_hex(&ref->old_oid), ref->name); status = 0; /* we found something */ } return status; diff --git a/builtin/merge-base.c b/builtin/merge-base.c index 08a8217890..a8911626c2 100644 --- a/builtin/merge-base.c +++ b/builtin/merge-base.c @@ -16,7 +16,7 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all) return 1; while (result) { - printf("%s\n", sha1_to_hex(result->item->object.sha1)); + printf("%s\n", oid_to_hex(&result->item->object.oid)); if (!show_all) return 0; result = result->next; @@ -62,7 +62,7 @@ static int handle_independent(int count, const char **args) return 1; while (result) { - printf("%s\n", sha1_to_hex(result->item->object.sha1)); + printf("%s\n", oid_to_hex(&result->item->object.oid)); result = result->next; } return 0; @@ -83,7 +83,7 @@ static int handle_octopus(int count, const char **args, int show_all) return 1; while (result) { - printf("%s\n", sha1_to_hex(result->item->object.sha1)); + printf("%s\n", oid_to_hex(&result->item->object.oid)); if (!show_all) return 0; result = result->next; @@ -196,7 +196,7 @@ static int handle_fork_point(int argc, const char **argv) goto cleanup_return; } - printf("%s\n", sha1_to_hex(bases->item->object.sha1)); + printf("%s\n", oid_to_hex(&bases->item->object.oid)); cleanup_return: free_commit_list(bases); diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 2a4aafec6a..d4f0cbd451 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.sha1, &type, size); + return read_sha1_file(entry->blob->object.oid.hash, &type, size); base = NULL; if (entry->stage == 1) { base = entry->blob; @@ -82,7 +82,7 @@ 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.sha1, &type, size); + return read_sha1_file(entry->blob->object.oid.hash, &type, size); entry = entry->link; } return NULL; @@ -130,7 +130,7 @@ static void show_result_list(struct merge_list *entry) do { struct merge_list *link = entry->link; static const char *desc[4] = { "result", "base", "our", "their" }; - printf(" %-6s %o %s %s\n", desc[entry->stage], entry->mode, sha1_to_hex(entry->blob->object.sha1), entry->path); + printf(" %-6s %o %s %s\n", desc[entry->stage], entry->mode, oid_to_hex(&entry->blob->object.oid), entry->path); entry = link; } while (entry); } diff --git a/builtin/merge.c b/builtin/merge.c index bbf3110f88..15bf95b3ac 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -365,7 +365,7 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead while ((commit = get_revision(&rev)) != NULL) { strbuf_addch(&out, '\n'); strbuf_addf(&out, "commit %s\n", - sha1_to_hex(commit->object.sha1)); + oid_to_hex(&commit->object.oid)); pretty_print_commit(&ctx, commit, &out); } if (write_in_full(fd, out.buf, out.len) != out.len) @@ -380,7 +380,7 @@ static void finish(struct commit *head_commit, const unsigned char *new_head, const char *msg) { struct strbuf reflog_message = STRBUF_INIT; - const unsigned char *head = head_commit->object.sha1; + const unsigned char *head = head_commit->object.oid.hash; if (!msg) strbuf_addstr(&reflog_message, getenv("GIT_REFLOG_ACTION")); @@ -497,7 +497,7 @@ static void merge_name(const char *remote, struct strbuf *msg) if (ref_exists(truname.buf)) { strbuf_addf(msg, "%s\t\tbranch '%s'%s of .\n", - sha1_to_hex(remote_head->object.sha1), + sha1_to_hex(remote_head->object.oid.hash), truname.buf + 11, (early ? " (early part)" : "")); strbuf_release(&truname); @@ -511,7 +511,7 @@ static void merge_name(const char *remote, struct strbuf *msg) desc = merge_remote_util(remote_head); if (desc && desc->obj && desc->obj->type == OBJ_TAG) { strbuf_addf(msg, "%s\t\t%s '%s'\n", - sha1_to_hex(desc->obj->sha1), + sha1_to_hex(desc->obj->oid.hash), typename(desc->obj->type), remote); goto cleanup; @@ -519,7 +519,7 @@ static void merge_name(const char *remote, struct strbuf *msg) } strbuf_addf(msg, "%s\t\tcommit '%s'\n", - sha1_to_hex(remote_head->object.sha1), remote); + sha1_to_hex(remote_head->object.oid.hash), remote); cleanup: strbuf_release(&buf); strbuf_release(&bname); @@ -892,7 +892,7 @@ static struct commit *is_old_style_invocation(int argc, const char **argv, second_token = lookup_commit_reference_gently(second_sha1, 0); if (!second_token) die(_("'%s' is not a commit"), argv[1]); - if (hashcmp(second_token->object.sha1, head)) + if (hashcmp(second_token->object.oid.hash, head)) return NULL; } return second_token; @@ -958,14 +958,14 @@ static void write_merge_state(struct commit_list *remoteheads) struct strbuf buf = STRBUF_INIT; for (j = remoteheads; j; j = j->next) { - unsigned const char *sha1; + struct object_id *oid; struct commit *c = j->item; if (c->util && merge_remote_util(c)->obj) { - sha1 = merge_remote_util(c)->obj->sha1; + oid = &merge_remote_util(c)->obj->oid; } else { - sha1 = c->object.sha1; + oid = &c->object.oid; } - strbuf_addf(&buf, "%s\n", sha1_to_hex(sha1)); + strbuf_addf(&buf, "%s\n", oid_to_hex(oid)); } filename = git_path_merge_head(); fd = open(filename, O_WRONLY | O_CREAT, 0666); @@ -1274,8 +1274,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix) die(_("%s - not something we can merge"), argv[0]); if (remoteheads->next) die(_("Can merge only exactly one commit into empty head")); - read_empty(remote_head->object.sha1, 0); - update_ref("initial pull", "HEAD", remote_head->object.sha1, + read_empty(remote_head->object.oid.hash, 0); + update_ref("initial pull", "HEAD", remote_head->object.oid.hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR); goto done; } @@ -1289,7 +1289,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) * additional safety measure to check for it. */ if (!have_message && - is_old_style_invocation(argc, argv, head_commit->object.sha1)) { + is_old_style_invocation(argc, argv, head_commit->object.oid.hash)) { warning("old-style 'git merge <msg> HEAD <commit>' is deprecated."); strbuf_addstr(&merge_msg, argv[0]); head_arg = argv[1]; @@ -1323,7 +1323,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.sha1, DEFAULT_ABBREV); + find_unique_abbrev_r(hex, commit->object.oid.hash, DEFAULT_ABBREV); switch (signature_check.result) { case 'G': break; @@ -1353,7 +1353,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) for (p = remoteheads; p; p = p->next) { struct commit *commit = p->item; strbuf_addf(&buf, "GITHEAD_%s", - sha1_to_hex(commit->object.sha1)); + sha1_to_hex(commit->object.oid.hash)); setenv(buf.buf, merge_remote_util(commit)->name, 1); strbuf_reset(&buf); if (fast_forward != FF_ONLY && @@ -1393,7 +1393,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) free(list); } - update_ref("updating ORIG_HEAD", "ORIG_HEAD", head_commit->object.sha1, + update_ref("updating ORIG_HEAD", "ORIG_HEAD", head_commit->object.oid.hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR); if (remoteheads && !common) @@ -1409,16 +1409,16 @@ int cmd_merge(int argc, const char **argv, const char *prefix) goto done; } else if (fast_forward != FF_NO && !remoteheads->next && !common->next && - !hashcmp(common->item->object.sha1, head_commit->object.sha1)) { + !hashcmp(common->item->object.oid.hash, head_commit->object.oid.hash)) { /* Again the most common case of merging one remote. */ struct strbuf msg = STRBUF_INIT; struct commit *commit; if (verbosity >= 0) { char from[GIT_SHA1_HEXSZ + 1], to[GIT_SHA1_HEXSZ + 1]; - find_unique_abbrev_r(from, head_commit->object.sha1, + find_unique_abbrev_r(from, head_commit->object.oid.hash, DEFAULT_ABBREV); - find_unique_abbrev_r(to, remoteheads->item->object.sha1, + find_unique_abbrev_r(to, remoteheads->item->object.oid.hash, DEFAULT_ABBREV); printf(_("Updating %s..%s\n"), from, to); } @@ -1432,14 +1432,14 @@ int cmd_merge(int argc, const char **argv, const char *prefix) goto done; } - if (checkout_fast_forward(head_commit->object.sha1, - commit->object.sha1, + if (checkout_fast_forward(head_commit->object.oid.hash, + commit->object.oid.hash, overwrite_ignore)) { ret = 1; goto done; } - finish(head_commit, remoteheads, commit->object.sha1, msg.buf); + finish(head_commit, remoteheads, commit->object.oid.hash, msg.buf); drop_save(); goto done; } else if (!remoteheads->next && common->next) @@ -1458,9 +1458,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix) /* See if it is really trivial. */ git_committer_info(IDENT_STRICT); printf(_("Trying really trivial in-index merge...\n")); - if (!read_tree_trivial(common->item->object.sha1, - head_commit->object.sha1, - remoteheads->item->object.sha1)) { + if (!read_tree_trivial(common->item->object.oid.hash, + head_commit->object.oid.hash, + remoteheads->item->object.oid.hash)) { ret = merge_trivial(head_commit, remoteheads); goto done; } @@ -1483,8 +1483,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix) * HEAD^^" would be missed. */ common_one = get_merge_bases(head_commit, j->item); - if (hashcmp(common_one->item->object.sha1, - j->item->object.sha1)) { + if (hashcmp(common_one->item->object.oid.hash, + j->item->object.oid.hash)) { up_to_date = 0; break; } @@ -1520,7 +1520,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) int ret; if (i) { printf(_("Rewinding the tree to pristine...\n")); - restore_state(head_commit->object.sha1, stash); + restore_state(head_commit->object.oid.hash, stash); } if (use_strategies_nr != 1) printf(_("Trying merge strategy %s...\n"), @@ -1586,7 +1586,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) * it up. */ if (!best_strategy) { - restore_state(head_commit->object.sha1, stash); + restore_state(head_commit->object.oid.hash, stash); if (use_strategies_nr > 1) fprintf(stderr, _("No merge strategy handled the merge.\n")); @@ -1599,7 +1599,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) ; /* We already have its result in the working tree. */ else { printf(_("Rewinding the tree to pristine...\n")); - restore_state(head_commit->object.sha1, stash); + restore_state(head_commit->object.oid.hash, stash); printf(_("Using the %s to prepare resolving by hand.\n"), best_strategy); try_merge_strategy(best_strategy, common, remoteheads, diff --git a/builtin/name-rev.c b/builtin/name-rev.c index 0377fc1142..092e03c3cc 100644 --- a/builtin/name-rev.c +++ b/builtin/name-rev.c @@ -162,7 +162,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo struct tag *t = (struct tag *) o; if (!t->tagged) break; /* broken repository */ - o = parse_object(t->tagged->sha1); + o = parse_object(t->tagged->oid.hash); deref = 1; } if (o && o->type == OBJ_COMMIT) { @@ -193,7 +193,7 @@ static const char *get_exact_ref_match(const struct object *o) tip_table.sorted = 1; } - found = sha1_pos(o->sha1, tip_table.table, tip_table.nr, + found = sha1_pos(o->oid.hash, tip_table.table, tip_table.nr, nth_tip_table_ent); if (0 <= found) return tip_table.table[found].refname; @@ -232,19 +232,19 @@ static void show_name(const struct object *obj, int always, int allow_undefined, int name_only) { const char *name; - const unsigned char *sha1 = obj->sha1; + const struct object_id *oid = &obj->oid; if (!name_only) - printf("%s ", caller_name ? caller_name : sha1_to_hex(sha1)); + printf("%s ", caller_name ? caller_name : oid_to_hex(oid)); name = get_rev_name(obj); if (name) printf("%s\n", name); else if (allow_undefined) printf("undefined\n"); else if (always) - printf("%s\n", find_unique_abbrev(sha1, DEFAULT_ABBREV)); + printf("%s\n", find_unique_abbrev(oid->hash, DEFAULT_ABBREV)); else - die("cannot describe '%s'", sha1_to_hex(sha1)); + die("cannot describe '%s'", oid_to_hex(oid)); } static char const * const name_rev_usage[] = { diff --git a/builtin/notes.c b/builtin/notes.c index 515cebbeb8..52aa9af74b 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -707,7 +707,7 @@ static int merge_commit(struct notes_merge_options *o) die("Could not parse commit from NOTES_MERGE_PARTIAL."); if (partial->parents) - hashcpy(parent_sha1, partial->parents->item->object.sha1); + hashcpy(parent_sha1, partial->parents->item->object.oid.hash); else hashclr(parent_sha1); diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 1c63f8f28c..4dae5b11c2 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -2277,7 +2277,7 @@ static void read_object_list_from_stdin(void) static void show_commit(struct commit *commit, void *data) { - add_object_entry(commit->object.sha1, OBJ_COMMIT, NULL, 0); + add_object_entry(commit->object.oid.hash, OBJ_COMMIT, NULL, 0); commit->object.flags |= OBJECT_ADDED; if (write_bitmap_index) @@ -2291,7 +2291,7 @@ static void show_object(struct object *obj, char *name = path_name(path, last); add_preferred_base_object(name); - add_object_entry(obj->sha1, obj->type, name, 0); + add_object_entry(obj->oid.hash, obj->type, name, 0); obj->flags |= OBJECT_ADDED; /* @@ -2303,7 +2303,7 @@ static void show_object(struct object *obj, static void show_edge(struct commit *commit) { - add_preferred_base(commit->object.sha1); + add_preferred_base(commit->object.oid.hash); } struct in_pack_object { @@ -2319,7 +2319,7 @@ struct in_pack { static void mark_in_pack_object(struct object *object, struct packed_git *p, struct in_pack *in_pack) { - in_pack->array[in_pack->nr].offset = find_pack_entry_one(object->sha1, p); + in_pack->array[in_pack->nr].offset = find_pack_entry_one(object->oid.hash, p); in_pack->array[in_pack->nr].object = object; in_pack->nr++; } @@ -2338,7 +2338,7 @@ static int ofscmp(const void *a_, const void *b_) else if (a->offset > b->offset) return 1; else - return hashcmp(a->object->sha1, b->object->sha1); + return oidcmp(&a->object->oid, &b->object->oid); } static void add_objects_in_unpacked_packs(struct rev_info *revs) @@ -2376,7 +2376,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs) ofscmp); for (i = 0; i < in_pack.nr; i++) { struct object *o = in_pack.array[i].object; - add_object_entry(o->sha1, o->type, "", 0); + add_object_entry(o->oid.hash, o->type, "", 0); } } free(in_pack.array); @@ -2484,12 +2484,12 @@ static void record_recent_object(struct object *obj, const char *last, void *data) { - sha1_array_append(&recent_objects, obj->sha1); + sha1_array_append(&recent_objects, obj->oid.hash); } static void record_recent_commit(struct commit *commit, void *data) { - sha1_array_append(&recent_objects, commit->object.sha1); + sha1_array_append(&recent_objects, commit->object.oid.hash); } static void get_object_list(int ac, const char **av) diff --git a/builtin/pull.c b/builtin/pull.c index bf3fd3f9c8..5145fc60a0 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -743,7 +743,7 @@ static int get_octopus_merge_base(unsigned char *merge_base, if (!result) return 1; - hashcpy(merge_base, result->item->object.sha1); + hashcpy(merge_base, result->item->object.oid.hash); return 0; } diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index f06f70a75f..ca38131873 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -246,7 +246,7 @@ static void show_one_alternate_sha1(const unsigned char sha1[20], void *unused) static void collect_one_alternate_ref(const struct ref *ref, void *data) { struct sha1_array *sa = data; - sha1_array_append(sa, ref->old_sha1); + sha1_array_append(sa, ref->old_oid.hash); } static void write_head_info(void) diff --git a/builtin/reflog.c b/builtin/reflog.c index cf1145e635..f39960e5e4 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -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.sha1)) + if (!c->object.parsed && !parse_object(c->object.oid.hash)) 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.sha1)) { + if (!tree_is_complete(c->tree->object.oid.hash)) { is_incomplete = 1; c->object.flags |= INCOMPLETE; } diff --git a/builtin/remote.c b/builtin/remote.c index e4c3ea130c..6694cf20ef 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -401,7 +401,7 @@ static int get_push_ref_states(const struct ref *remote_refs, if (!ref->peer_ref) continue; - hashcpy(ref->new_sha1, ref->peer_ref->new_sha1); + oidcpy(&ref->new_oid, &ref->peer_ref->new_oid); item = string_list_append(&states->push, abbrev_branch(ref->peer_ref->name)); @@ -410,14 +410,14 @@ static int get_push_ref_states(const struct ref *remote_refs, info->forced = ref->force; info->dest = xstrdup(abbrev_branch(ref->name)); - if (is_null_sha1(ref->new_sha1)) { + if (is_null_oid(&ref->new_oid)) { info->status = PUSH_STATUS_DELETE; - } else if (!hashcmp(ref->old_sha1, ref->new_sha1)) + } else if (!oidcmp(&ref->old_oid, &ref->new_oid)) info->status = PUSH_STATUS_UPTODATE; - else if (is_null_sha1(ref->old_sha1)) + else if (is_null_oid(&ref->old_oid)) info->status = PUSH_STATUS_CREATE; - else if (has_sha1_file(ref->old_sha1) && - ref_newer(ref->new_sha1, ref->old_sha1)) + else if (has_object_file(&ref->old_oid) && + ref_newer(&ref->new_oid, &ref->old_oid)) info->status = PUSH_STATUS_FASTFORWARD; else info->status = PUSH_STATUS_OUTOFDATE; diff --git a/builtin/replace.c b/builtin/replace.c index 6b3c469a33..748c6ca954 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -358,10 +358,10 @@ static void check_one_mergetag(struct commit *commit, /* iterate over new parents */ for (i = 1; i < mergetag_data->argc; i++) { - unsigned char sha1[20]; - if (get_sha1(mergetag_data->argv[i], sha1) < 0) + struct object_id oid; + if (get_sha1(mergetag_data->argv[i], oid.hash) < 0) die(_("Not a valid object name: '%s'"), mergetag_data->argv[i]); - if (!hashcmp(tag->tagged->sha1, sha1)) + if (!oidcmp(&tag->tagged->oid, &oid)) return; /* found */ } diff --git a/builtin/reset.c b/builtin/reset.c index c503e75a59..092c3a5399 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -96,7 +96,7 @@ static void print_new_head_line(struct commit *commit) const char *hex, *body; const char *msg; - hex = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV); + hex = find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV); printf(_("HEAD is now at %s"), hex); msg = logmsg_reencode(commit, NULL, get_log_output_encoding()); body = strstr(msg, "\n\n"); @@ -269,7 +269,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) int reset_type = NONE, update_ref_status = 0, quiet = 0; int patch_mode = 0, unborn; const char *rev; - unsigned char sha1[20]; + struct object_id oid; struct pathspec pathspec; int intent_to_add = 0; const struct option options[] = { @@ -295,26 +295,26 @@ int cmd_reset(int argc, const char **argv, const char *prefix) PARSE_OPT_KEEP_DASHDASH); parse_args(&pathspec, argv, prefix, patch_mode, &rev); - unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", sha1); + unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", oid.hash); if (unborn) { /* reset on unborn branch: treat as reset to empty tree */ - hashcpy(sha1, EMPTY_TREE_SHA1_BIN); + hashcpy(oid.hash, EMPTY_TREE_SHA1_BIN); } else if (!pathspec.nr) { struct commit *commit; - if (get_sha1_committish(rev, sha1)) + if (get_sha1_committish(rev, oid.hash)) die(_("Failed to resolve '%s' as a valid revision."), rev); - commit = lookup_commit_reference(sha1); + commit = lookup_commit_reference(oid.hash); if (!commit) die(_("Could not parse object '%s'."), rev); - hashcpy(sha1, commit->object.sha1); + oidcpy(&oid, &commit->object.oid); } else { struct tree *tree; - if (get_sha1_treeish(rev, sha1)) + if (get_sha1_treeish(rev, oid.hash)) die(_("Failed to resolve '%s' as a valid tree."), rev); - tree = parse_tree_indirect(sha1); + tree = parse_tree_indirect(oid.hash); if (!tree) die(_("Could not parse object '%s'."), rev); - hashcpy(sha1, tree->object.sha1); + oidcpy(&oid, &tree->object.oid); } if (patch_mode) { @@ -357,15 +357,15 @@ int cmd_reset(int argc, const char **argv, const char *prefix) hold_locked_index(lock, 1); if (reset_type == MIXED) { int flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN; - if (read_from_tree(&pathspec, sha1, intent_to_add)) + if (read_from_tree(&pathspec, oid.hash, intent_to_add)) return 1; if (get_git_work_tree()) refresh_index(&the_index, flags, NULL, NULL, _("Unstaged changes after reset:")); } else { - int err = reset_index(sha1, reset_type, quiet); + int err = reset_index(oid.hash, reset_type, quiet); if (reset_type == KEEP && !err) - err = reset_index(sha1, MIXED, quiet); + err = reset_index(oid.hash, MIXED, quiet); if (err) die(_("Could not reset index file to revision '%s'."), rev); } @@ -377,10 +377,10 @@ int cmd_reset(int argc, const char **argv, const char *prefix) if (!pathspec.nr && !unborn) { /* Any resets without paths update HEAD to the head being * switched to, saving the previous head in ORIG_HEAD before. */ - update_ref_status = reset_refs(rev, sha1); + update_ref_status = reset_refs(rev, oid.hash); if (reset_type == HARD && !update_ref_status && !quiet) - print_new_head_line(lookup_commit_reference(sha1)); + print_new_head_line(lookup_commit_reference(oid.hash)); } if (!pathspec.nr) remove_branch_state(); diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 491d298fa2..3aa89a1a3c 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -81,14 +81,14 @@ 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.sha1, revs->abbrev), + fputs(find_unique_abbrev(commit->object.oid.hash, revs->abbrev), stdout); else - fputs(sha1_to_hex(commit->object.sha1), stdout); + fputs(oid_to_hex(&commit->object.oid), stdout); if (revs->print_parents) { struct commit_list *parents = commit->parents; while (parents) { - printf(" %s", sha1_to_hex(parents->item->object.sha1)); + printf(" %s", oid_to_hex(&parents->item->object.oid)); parents = parents->next; } } @@ -97,7 +97,7 @@ static void show_commit(struct commit *commit, void *data) children = lookup_decoration(&revs->children, &commit->object); while (children) { - printf(" %s", sha1_to_hex(children->item->object.sha1)); + printf(" %s", oid_to_hex(&children->item->object.oid)); children = children->next; } } @@ -182,10 +182,10 @@ static void finish_object(struct object *obj, void *cb_data) { struct rev_list_info *info = cb_data; - if (obj->type == OBJ_BLOB && !has_sha1_file(obj->sha1)) - die("missing blob object '%s'", sha1_to_hex(obj->sha1)); + if (obj->type == OBJ_BLOB && !has_object_file(&obj->oid)) + die("missing blob object '%s'", oid_to_hex(&obj->oid)); if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT) - parse_object(obj->sha1); + parse_object(obj->oid.hash); } static void show_object(struct object *obj, @@ -201,7 +201,7 @@ static void show_object(struct object *obj, static void show_edge(struct commit *commit) { - printf("-%s\n", sha1_to_hex(commit->object.sha1)); + printf("-%s\n", oid_to_hex(&commit->object.oid)); } static void print_var_str(const char *var, const char *val) @@ -242,7 +242,7 @@ static int show_bisect_vars(struct rev_list_info *info, int reaches, int all) cnt = reaches; if (revs->commits) - sha1_to_hex_r(hex, revs->commits->item->object.sha1); + sha1_to_hex_r(hex, revs->commits->item->object.oid.hash); if (flags & BISECT_SHOW_ALL) { traverse_commit_list(revs, show_commit, show_object, info); diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index e92a782f77..7e074aad40 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -282,7 +282,7 @@ static int try_difference(const char *arg) exclude = get_merge_bases(a, b); while (exclude) { struct commit *commit = pop_commit(&exclude); - show_rev(REVERSED, commit->object.sha1, NULL); + show_rev(REVERSED, commit->object.oid.hash, NULL); } } *dotdot = '.'; @@ -319,7 +319,7 @@ static int try_parent_shorthands(const char *arg) commit = lookup_commit_reference(sha1); for (parents = commit->parents; parents; parents = parents->next) show_rev(parents_only ? NORMAL : REVERSED, - parents->item->object.sha1, arg); + parents->item->object.oid.hash, arg); *dotdot = '^'; return 1; diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 007cc66a03..35ebd17f80 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -129,7 +129,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit) } if (!author) { warning(_("Missing author: %s"), - sha1_to_hex(commit->object.sha1)); + oid_to_hex(&commit->object.oid)); return; } if (log->user_format) { diff --git a/builtin/show-branch.c b/builtin/show-branch.c index e17744bc0d..25669357e9 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -291,7 +291,7 @@ static void show_one_commit(struct commit *commit, int no_name) } else printf("[%s] ", - find_unique_abbrev(commit->object.sha1, + find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV)); } puts(pretty_str); @@ -496,7 +496,7 @@ static int show_merge_base(struct commit_list *seen, int num_rev) int flags = commit->object.flags & all_mask; if (!(flags & UNINTERESTING) && ((flags & all_revs) == all_revs)) { - puts(sha1_to_hex(commit->object.sha1)); + puts(oid_to_hex(&commit->object.oid)); exit_status = 0; commit->object.flags |= UNINTERESTING; } @@ -516,7 +516,7 @@ static int show_independent(struct commit **rev, unsigned int flag = rev_mask[i]; if (commit->object.flags == flag) - puts(sha1_to_hex(commit->object.sha1)); + puts(oid_to_hex(&commit->object.oid)); commit->object.flags |= UNINTERESTING; } return 0; @@ -867,7 +867,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) head_len, ref_name[i], head_oid.hash, - rev[i]->object.sha1); + rev[i]->object.oid.hash); if (extra < 0) printf("%c [%s] ", is_head ? '*' : ' ', ref_name[i]); diff --git a/builtin/show-ref.c b/builtin/show-ref.c index 264c392007..6d4e669002 100644 --- a/builtin/show-ref.c +++ b/builtin/show-ref.c @@ -161,11 +161,6 @@ static int exclude_existing_callback(const struct option *opt, const char *arg, return 0; } -static int help_callback(const struct option *opt, const char *arg, int unset) -{ - return -1; -} - static const struct option show_ref_options[] = { OPT_BOOL(0, "tags", &tags_only, N_("only show tags (can be combined with heads)")), OPT_BOOL(0, "heads", &heads_only, N_("only show heads (can be combined with tags)")), @@ -186,18 +181,13 @@ static const struct option show_ref_options[] = { { OPTION_CALLBACK, 0, "exclude-existing", &exclude_existing_arg, N_("pattern"), N_("show refs from stdin that aren't in local repository"), PARSE_OPT_OPTARG | PARSE_OPT_NONEG, exclude_existing_callback }, - { OPTION_CALLBACK, 0, "help-all", NULL, NULL, N_("show usage"), - PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, help_callback }, OPT_END() }; int cmd_show_ref(int argc, const char **argv, const char *prefix) { - if (argc == 2 && !strcmp(argv[1], "-h")) - usage_with_options(show_ref_usage, show_ref_options); - argc = parse_options(argc, argv, prefix, show_ref_options, - show_ref_usage, PARSE_OPT_NO_INTERNAL_HELP); + show_ref_usage, 0); if (exclude_arg) return exclude_existing(exclude_existing_arg); diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c index 7c3e79c48d..875e7ed998 100644 --- a/builtin/unpack-objects.c +++ b/builtin/unpack-objects.c @@ -46,7 +46,7 @@ static void add_object_buffer(struct object *object, char *buffer, unsigned long obj->buffer = buffer; obj->size = size; if (add_decoration(&obj_decorate, object, obj)) - die("object %s tried to add buffer twice!", sha1_to_hex(object->sha1)); + die("object %s tried to add buffer twice!", oid_to_hex(&object->oid)); } /* @@ -170,7 +170,7 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf) unsigned char sha1[20]; if (write_sha1_file(obj_buf->buffer, obj_buf->size, typename(obj->type), sha1) < 0) - die("failed to write object %s", sha1_to_hex(obj->sha1)); + die("failed to write object %s", oid_to_hex(&obj->oid)); obj->flags |= FLAG_WRITTEN; } @@ -194,7 +194,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->sha1, &size); + int type = sha1_object_info(obj->oid.hash, &size); if (type != obj->type || type <= 0) die("object of unexpected type"); obj->flags |= FLAG_WRITTEN; @@ -203,12 +203,12 @@ static int check_object(struct object *obj, int type, void *data, struct fsck_op obj_buf = lookup_object_buffer(obj); if (!obj_buf) - die("Whoops! Cannot find object '%s'", sha1_to_hex(obj->sha1)); + die("Whoops! Cannot find object '%s'", oid_to_hex(&obj->oid)); if (fsck_object(obj, obj_buf->buffer, obj_buf->size, &fsck_options)) die("Error in object"); fsck_options.walk = check_object; if (fsck_walk(obj, NULL, &fsck_options)) - die("Error on reachable objects of %s", sha1_to_hex(obj->sha1)); + die("Error on reachable objects of %s", oid_to_hex(&obj->oid)); write_cached_object(obj, obj_buf); return 0; } diff --git a/builtin/worktree.c b/builtin/worktree.c index d281f6d887..475b9581a5 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -277,7 +277,7 @@ static int add_worktree(const char *path, const char *refname, if (commit) argv_array_pushl(&cp.args, "update-ref", "HEAD", - sha1_to_hex(commit->object.sha1), NULL); + oid_to_hex(&commit->object.oid), NULL); else argv_array_pushl(&cp.args, "symbolic-ref", "HEAD", symref.buf, NULL); |