diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index bd9515059e828d..d46739e7b947b0 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1260,7 +1260,7 @@ static const char *get_diff_cmd(enum diff_cmd diff_cmd) } } -static int compute_summary_module_list(char *head, +static int compute_summary_module_list(struct object_id *head_oid, struct summary_cb *info, enum diff_cmd diff_cmd) { @@ -1273,8 +1273,8 @@ static int compute_summary_module_list(char *head, argv_array_push(&diff_args, "--cached"); argv_array_pushl(&diff_args, "--ignore-submodules=dirty", "--raw", NULL); - if (head) - argv_array_push(&diff_args, head); + if (head_oid) + argv_array_push(&diff_args, oid_to_hex(head_oid)); argv_array_push(&diff_args, "--"); if (info->argc) argv_array_pushv(&diff_args, info->argv); @@ -1291,7 +1291,7 @@ static int compute_summary_module_list(char *head, rev.diffopt.format_callback_data = &list; if (!info->cached) { - if (diff_cmd == DIFF_INDEX) + if (diff_cmd == DIFF_INDEX) setup_work_tree(); if (read_cache_preload(&rev.diffopt.pathspec) < 0) { perror("read_cache_preload"); @@ -1318,9 +1318,8 @@ static int module_summary(int argc, const char **argv, const char *prefix) int quiet = 0; int files = 0; int summary_limit = -1; - struct child_process cp_rev = CHILD_PROCESS_INIT; - struct strbuf sb = STRBUF_INIT; enum diff_cmd diff_cmd = DIFF_INDEX; + struct object_id head_oid; int ret; struct option module_summary_options[] = { @@ -1347,25 +1346,21 @@ static int module_summary(int argc, const char **argv, const char *prefix) if (!summary_limit) return 0; - cp_rev.git_cmd = 1; - argv_array_pushl(&cp_rev.args, "rev-parse", "-q", "--verify", - argc ? argv[0] : "HEAD", NULL); - - if (!capture_command(&cp_rev, &sb, 0)) { - strbuf_strip_suffix(&sb, "\n"); + if (!get_oid(argc ? argv[0] : "HEAD", &head_oid)) { if (argc) { argv++; argc--; } } else if (!argc || !strcmp(argv[0], "HEAD")) { /* before the first commit: compare with an empty tree */ - strbuf_addstr(&sb, oid_to_hex(the_hash_algo->empty_tree)); + oidcpy(&head_oid, the_hash_algo->empty_tree); if (argc) { argv++; argc--; } } else { - strbuf_addstr(&sb, "HEAD"); + if (get_oid("HEAD", &head_oid)) + die(_("could not fetch a revision for HEAD")); } if (files) { @@ -1383,9 +1378,8 @@ static int module_summary(int argc, const char **argv, const char *prefix) info.quiet = quiet; info.summary_limit = summary_limit; - ret = compute_summary_module_list((diff_cmd == DIFF_FILES) ? NULL : sb.buf, - &info, diff_cmd); - strbuf_release(&sb); + ret = compute_summary_module_list((diff_cmd == DIFF_INDEX) ? &head_oid : NULL, + &info, diff_cmd); return ret; }