Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use get_oid() instead of spawning a new process
Use get_oid() instead of spawning a new process. Quote from Dscho: > +static int module_summary(int argc, const char **argv, const char *prefix) > +{ > + struct summary_cb info = SUMMARY_CB_INIT; > + int cached = 0; > + int for_status = 0; > + 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; > + int ret; > + > + struct option module_summary_options[] = { > + OPT__QUIET(&quiet, N_("Suppress output of summarising submodules")), > + OPT_BOOL(0, "cached", &cached, > + N_("Use the commit stored in the index instead of the submodule HEAD")), > + OPT_BOOL(0, "files", &files, > + N_("To compare the commit in the index with that in the submodule HEAD")), > + OPT_BOOL(0, "for-status", &for_status, > + N_("Skip submodules with 'ignore_config' value set to 'all'")), > + OPT_INTEGER('n', "summary-limit", &summary_limit, > + N_("Limit the summary size")), > + OPT_END() > + }; > + > + const char *const git_submodule_helper_usage[] = { > + N_("git submodule--helper summary [<options>] [commit] [--] [<path>]"), > + NULL > + }; > + > + argc = parse_options(argc, argv, prefix, module_summary_options, > + git_submodule_helper_usage, 0); > + > + 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); Oy. Why not simply call `get_oid()`? No need to spawn a new process. ------------------------------------------------------ After suggestions from my mentors and doing some digging on a follow-up mail from Johannes, I figured it out. The problem I faced was that I was using a 'struct object_id *' instead of just a 'struct object_id' due to which the assignments and if-statement checks were not coming out to be very proper. After looking at Dscho's mail, I realised that it will be better to use the latter struct type since almost everywhere we use this and the helper functions work better with this. I did some digging in cache.h to try finding other auxiliary functions to help me. First I tried to use the oidclr() function to clear the object_id to NULL in case of when a '--files' is passed but that wasn't the right function to use (something I realised after concentrating on the definition of the function really hard). So here we are, with the fix. All tests pass.
- Loading branch information