builtin/commit: convert to struct object_id

Convert most leaf functions to use struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Feb 20, 2017 at 00:10 UTC 8066df4194a1b108d2a7200008c39a1dcfebd8df
1 file changed +23 -23
builtin/commit.c
+23 -23
@@ -496,7 +496,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
496 static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn,
497 struct wt_status *s)
498 {
499 - unsigned char sha1[20];
499 + struct object_id oid;
500
501 if (s->relative_paths)
502 s->prefix = prefix;
@@ -509,9 +509,9 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
509 s->index_file = index_file;
510 s->fp = fp;
511 s->nowarn = nowarn;
512 - s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
512 + s->is_initial = get_sha1(s->reference, oid.hash) ? 1 : 0;
513 if (!s->is_initial)
514 - hashcpy(s->sha1_commit, sha1);
514 + hashcpy(s->sha1_commit, oid.hash);
515 s->status_format = status_format;
516 s->ignore_submodule_arg = ignore_submodule_arg;
517
@@ -885,7 +885,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
885 commitable = run_status(s->fp, index_file, prefix, 1, s);
886 s->use_color = saved_color_setting;
887 } else {
888 - unsigned char sha1[20];
888 + struct object_id oid;
889 const char *parent = "HEAD";
890
891 if (!active_nr && read_cache() < 0)
@@ -894,7 +894,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
894 if (amend)
895 parent = "HEAD^1";
896
897 - if (get_sha1(parent, sha1)) {
897 + if (get_sha1(parent, oid.hash)) {
898 int i, ita_nr = 0;
899
900 for (i = 0; i < active_nr; i++)
@@ -1332,7 +1332,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1332 {
1333 static struct wt_status s;
1334 int fd;
1335 - unsigned char sha1[20];
1335 + struct object_id oid;
1336 static struct option builtin_status_options[] = {
1337 OPT__VERBOSE(&verbose, N_("be verbose")),
1338 OPT_SET_INT('s', "short", &status_format,
@@ -1382,9 +1382,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1382
1383 fd = hold_locked_index(&index_lock, 0);
1384
1385 - s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
1385 + s.is_initial = get_sha1(s.reference, oid.hash) ? 1 : 0;
1386 if (!s.is_initial)
1387 - hashcpy(s.sha1_commit, sha1);
1387 + hashcpy(s.sha1_commit, oid.hash);
1388
1389 s.ignore_submodule_arg = ignore_submodule_arg;
1390 s.status_format = status_format;
@@ -1418,19 +1418,19 @@ static const char *implicit_ident_advice(void)
1418
1419 }
1420
1421 -static void print_summary(const char *prefix, const unsigned char *sha1,
1421 +static void print_summary(const char *prefix, const struct object_id *oid,
1422 int initial_commit)
1423 {
1424 struct rev_info rev;
1425 struct commit *commit;
1426 struct strbuf format = STRBUF_INIT;
1427 - unsigned char junk_sha1[20];
1427 + struct object_id junk_oid;
1428 const char *head;
1429 struct pretty_print_context pctx = {0};
1430 struct strbuf author_ident = STRBUF_INIT;
1431 struct strbuf committer_ident = STRBUF_INIT;
1432
1433 - commit = lookup_commit(sha1);
1433 + commit = lookup_commit(oid->hash);
1434 if (!commit)
1435 die(_("couldn't look up newly created commit"));
1436 if (parse_commit(commit))
@@ -1477,7 +1477,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
1477 rev.diffopt.break_opt = 0;
1478 diff_setup_done(&rev.diffopt);
1479
1480 - head = resolve_ref_unsafe("HEAD", 0, junk_sha1, NULL);
1480 + head = resolve_ref_unsafe("HEAD", 0, junk_oid.hash, NULL);
1481 if (!strcmp(head, "HEAD"))
1482 head = _("detached HEAD");
1483 else
@@ -1522,8 +1522,8 @@ static int git_commit_config(const char *k, const char *v, void *cb)
1522 return git_status_config(k, v, s);
1523 }
1524
1525 -static int run_rewrite_hook(const unsigned char *oldsha1,
1526 - const unsigned char *newsha1)
1525 +static int run_rewrite_hook(const struct object_id *oldoid,
1526 + const struct object_id *newoid)
1527 {
1528 struct child_process proc = CHILD_PROCESS_INIT;
1529 const char *argv[3];
@@ -1544,7 +1544,7 @@ static int run_rewrite_hook(const unsigned char *oldsha1,
1544 code = start_command(&proc);
1545 if (code)
1546 return code;
1547 - strbuf_addf(&sb, "%s %s\n", sha1_to_hex(oldsha1), sha1_to_hex(newsha1));
1547 + strbuf_addf(&sb, "%s %s\n", oid_to_hex(oldoid), oid_to_hex(newoid));
1548 sigchain_push(SIGPIPE, SIG_IGN);
1549 write_in_full(proc.in, sb.buf, sb.len);
1550 close(proc.in);
@@ -1636,7 +1636,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1636 struct strbuf author_ident = STRBUF_INIT;
1637 const char *index_file, *reflog_msg;
1638 char *nl;
1639 - unsigned char sha1[20];
1639 + struct object_id oid;
1640 struct commit_list *parents = NULL;
1641 struct stat statbuf;
1642 struct commit *current_head = NULL;
@@ -1651,10 +1651,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1651 status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
1652 s.colopts = 0;
1653
1654 - if (get_sha1("HEAD", sha1))
1654 + if (get_sha1("HEAD", oid.hash))
1655 current_head = NULL;
1656 else {
1657 - current_head = lookup_commit_or_die(sha1, "HEAD");
1657 + current_head = lookup_commit_or_die(oid.hash, "HEAD");
1658 if (parse_commit(current_head))
1659 die(_("could not parse HEAD commit"));
1660 }
@@ -1759,7 +1759,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1759 }
1760
1761 if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->sha1,
1762 - parents, sha1, author_ident.buf, sign_commit, extra)) {
1762 + parents, oid.hash, author_ident.buf, sign_commit, extra)) {
1763 rollback_index_files();
1764 die(_("failed to write commit object"));
1765 }
@@ -1776,7 +1776,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1776
1777 transaction = ref_transaction_begin(&err);
1778 if (!transaction ||
1779 - ref_transaction_update(transaction, "HEAD", sha1,
1779 + ref_transaction_update(transaction, "HEAD", oid.hash,
1780 current_head
1781 ? current_head->object.oid.hash : null_sha1,
1782 0, sb.buf, &err) ||
@@ -1805,13 +1805,13 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1805 cfg = init_copy_notes_for_rewrite("amend");
1806 if (cfg) {
1807 /* we are amending, so current_head is not NULL */
1808 - copy_note_for_rewrite(cfg, current_head->object.oid.hash, sha1);
1808 + copy_note_for_rewrite(cfg, current_head->object.oid.hash, oid.hash);
1809 finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'");
1810 }
1811 - run_rewrite_hook(current_head->object.oid.hash, sha1);
1811 + run_rewrite_hook(&current_head->object.oid, &oid);
1812 }
1813 if (!quiet)
1814 - print_summary(prefix, sha1, !current_head);
1814 + print_summary(prefix, &oid, !current_head);
1815
1816 strbuf_release(&err);
1817 return 0;