sequencer: convert to struct object_id

Convert the remaining instances of unsigned char * to struct object_id. This removes several calls to get_sha1. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Jul 13, 2017 at 23:49 UTC 092bbcdf3b10a73cc24bdf3ba3cc6782a5b0245f
1 file changed +30 -29
sequencer.c
+30 -29
@@ -691,7 +691,7 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
691
692 static int is_original_commit_empty(struct commit *commit)
693 {
694 - const unsigned char *ptree_sha1;
694 + const struct object_id *ptree_oid;
695
696 if (parse_commit(commit))
697 return error(_("could not parse commit %s\n"),
@@ -701,12 +701,12 @@ static int is_original_commit_empty(struct commit *commit)
701 if (parse_commit(parent))
702 return error(_("could not parse parent commit %s\n"),
703 oid_to_hex(&parent->object.oid));
704 - ptree_sha1 = parent->tree->object.oid.hash;
704 + ptree_oid = &parent->tree->object.oid;
705 } else {
706 - ptree_sha1 = EMPTY_TREE_SHA1_BIN; /* commit is root */
706 + ptree_oid = &empty_tree_oid; /* commit is root */
707 }
708
709 - return !hashcmp(ptree_sha1, commit->tree->object.oid.hash);
709 + return !oidcmp(ptree_oid, &commit->tree->object.oid);
710 }
711
712 /*
@@ -896,18 +896,18 @@ static int update_squash_messages(enum todo_command command,
896
897 static void flush_rewritten_pending(void) {
898 struct strbuf buf = STRBUF_INIT;
899 - unsigned char newsha1[20];
899 + struct object_id newoid;
900 FILE *out;
901
902 - if (strbuf_read_file(&buf, rebase_path_rewritten_pending(), 82) > 0 &&
903 - !get_sha1("HEAD", newsha1) &&
902 + if (strbuf_read_file(&buf, rebase_path_rewritten_pending(), (GIT_MAX_HEXSZ + 1) * 2) > 0 &&
903 + !get_oid("HEAD", &newoid) &&
904 (out = fopen_or_warn(rebase_path_rewritten_list(), "a"))) {
905 char *bol = buf.buf, *eol;
906
907 while (*bol) {
908 eol = strchrnul(bol, '\n');
909 fprintf(out, "%.*s %s\n", (int)(eol - bol),
910 - bol, sha1_to_hex(newsha1));
910 + bol, oid_to_hex(&newoid));
911 if (!*eol)
912 break;
913 bol = eol + 1;
@@ -1594,36 +1594,37 @@ static int rollback_is_safe(void)
1594 return !oidcmp(&actual_head, &expected_head);
1595 }
1596
1597 -static int reset_for_rollback(const unsigned char *sha1)
1597 +static int reset_for_rollback(const struct object_id *oid)
1598 {
1599 const char *argv[4]; /* reset --merge <arg> + NULL */
1600
1601 argv[0] = "reset";
1602 argv[1] = "--merge";
1603 - argv[2] = sha1_to_hex(sha1);
1603 + argv[2] = oid_to_hex(oid);
1604 argv[3] = NULL;
1605 return run_command_v_opt(argv, RUN_GIT_CMD);
1606 }
1607
1608 static int rollback_single_pick(void)
1609 {
1610 - unsigned char head_sha1[20];
1610 + struct object_id head_oid;
1611
1612 if (!file_exists(git_path_cherry_pick_head()) &&
1613 !file_exists(git_path_revert_head()))
1614 return error(_("no cherry-pick or revert in progress"));
1615 - if (read_ref_full("HEAD", 0, head_sha1, NULL))
1615 + if (read_ref_full("HEAD", 0, head_oid.hash, NULL))
1616 return error(_("cannot resolve HEAD"));
1617 - if (is_null_sha1(head_sha1))
1617 + if (is_null_oid(&head_oid))
1618 return error(_("cannot abort from a branch yet to be born"));
1619 - return reset_for_rollback(head_sha1);
1619 + return reset_for_rollback(&head_oid);
1620 }
1621
1622 int sequencer_rollback(struct replay_opts *opts)
1623 {
1624 FILE *f;
1625 - unsigned char sha1[20];
1625 + struct object_id oid;
1626 struct strbuf buf = STRBUF_INIT;
1627 + const char *p;
1628
1629 f = fopen(git_path_head_file(), "r");
1630 if (!f && errno == ENOENT) {
@@ -1643,12 +1644,12 @@ int sequencer_rollback(struct replay_opts *opts)
1644 goto fail;
1645 }
1646 fclose(f);
1646 - if (get_sha1_hex(buf.buf, sha1) || buf.buf[40] != '\0') {
1647 + if (parse_oid_hex(buf.buf, &oid, &p) || *p != '\0') {
1648 error(_("stored pre-cherry-pick HEAD file '%s' is corrupt"),
1649 git_path_head_file());
1650 goto fail;
1651 }
1651 - if (is_null_sha1(sha1)) {
1652 + if (is_null_oid(&oid)) {
1653 error(_("cannot abort from a branch yet to be born"));
1654 goto fail;
1655 }
@@ -1658,7 +1659,7 @@ int sequencer_rollback(struct replay_opts *opts)
1659 warning(_("You seem to have moved HEAD. "
1660 "Not rewinding, check your HEAD!"));
1661 } else
1661 - if (reset_for_rollback(sha1))
1662 + if (reset_for_rollback(&oid))
1663 goto fail;
1664 strbuf_release(&buf);
1665 return sequencer_remove_state(opts);
@@ -1788,13 +1789,13 @@ static int make_patch(struct commit *commit, struct replay_opts *opts)
1789
1790 static int intend_to_amend(void)
1791 {
1791 - unsigned char head[20];
1792 + struct object_id head;
1793 char *p;
1794
1794 - if (get_sha1("HEAD", head))
1795 + if (get_oid("HEAD", &head))
1796 return error(_("cannot read HEAD"));
1797
1797 - p = sha1_to_hex(head);
1798 + p = oid_to_hex(&head);
1799 return write_message(p, strlen(p), rebase_path_amend(), 1);
1800 }
1801
@@ -2079,10 +2080,10 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
2080 if (read_oneliner(&head_ref, rebase_path_head_name(), 0) &&
2081 starts_with(head_ref.buf, "refs/")) {
2082 const char *msg;
2082 - unsigned char head[20], orig[20];
2083 + struct object_id head, orig;
2084 int res;
2085
2085 - if (get_sha1("HEAD", head)) {
2086 + if (get_oid("HEAD", &head)) {
2087 res = error(_("cannot read HEAD"));
2088 cleanup_head_ref:
2089 strbuf_release(&head_ref);
@@ -2090,7 +2091,7 @@ cleanup_head_ref:
2091 return res;
2092 }
2093 if (!read_oneliner(&buf, rebase_path_orig_head(), 0) ||
2093 - get_sha1_hex(buf.buf, orig)) {
2094 + get_oid_hex(buf.buf, &orig)) {
2095 res = error(_("could not read orig-head"));
2096 goto cleanup_head_ref;
2097 }
@@ -2101,7 +2102,7 @@ cleanup_head_ref:
2102 }
2103 msg = reflog_message(opts, "finish", "%s onto %s",
2104 head_ref.buf, buf.buf);
2104 - if (update_ref(msg, head_ref.buf, head, orig,
2105 + if (update_ref(msg, head_ref.buf, head.hash, orig.hash,
2106 REF_NODEREF, UPDATE_REFS_MSG_ON_ERR)) {
2107 res = error(_("could not update %s"),
2108 head_ref.buf);
@@ -2205,16 +2206,16 @@ static int commit_staged_changes(struct replay_opts *opts)
2206
2207 if (file_exists(rebase_path_amend())) {
2208 struct strbuf rev = STRBUF_INIT;
2208 - unsigned char head[20], to_amend[20];
2209 + struct object_id head, to_amend;
2210
2210 - if (get_sha1("HEAD", head))
2211 + if (get_oid("HEAD", &head))
2212 return error(_("cannot amend non-existing commit"));
2213 if (!read_oneliner(&rev, rebase_path_amend(), 0))
2214 return error(_("invalid file: '%s'"), rebase_path_amend());
2214 - if (get_sha1_hex(rev.buf, to_amend))
2215 + if (get_oid_hex(rev.buf, &to_amend))
2216 return error(_("invalid contents: '%s'"),
2217 rebase_path_amend());
2217 - if (hashcmp(head, to_amend))
2218 + if (oidcmp(&head, &to_amend))
2219 return error(_("\nYou have uncommitted changes in your "
2220 "working tree. Please, commit them\n"
2221 "first and then run 'git rebase "