Subject: Re: [PATCH 4/4] submodule: port submodule subcommand 'summary' from shell to C

From: Shourya Shukla <[email-masked]>
Date: Thu, 16 Jul 2020 00:11:53 +0530

Ignore the above mail I sent, I am a big dimwit. I have tried to do this
and this works

---------------8<--------------
module_summary() {
struct object_id head;
....
....
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 */
		oidcpy(&head_oid, the_hash_algo->empty_tree);
		if (argc) {
			argv++;
			argc--;
		}
	} else {
		get_oid("HEAD", &head_oid);
	}
....
....
ret = compute_summary_module_list((diff_cmd == DIFF_FILES) ? NULL : &head_oid,
					   &info, diff_cmd);
	return ret;
}

compute_summary_module_list() {
....
....
if (head_oid)
		argv_array_push(&diff_args, oid_to_hex(head_oid));
....
....
}
--------------->8--------------

Obviousy I was making the grave mistake of declaring the aforementioned
struct as 'struct object_id *' which caused all these weird errors.

All tests pass now.

BTW in your review of my patch,
https://lore.kernel.org/git/[email-masked]/
you said this:
--------------->8--------------
> +			 */
> +			struct child_process cp_rev_parse = CHILD_PROCESS_INIT;
> +			struct strbuf sb_rev_parse = STRBUF_INIT;
> +
> +			cp_rev_parse.git_cmd = 1;
> +			cp_rev_parse.no_stderr = 1;
> +			cp_rev_parse.dir = p->sm_path;
> +			prepare_submodule_repo_env(&cp_rev_parse.env_array);
> +
> +			argv_array_pushl(&cp_rev_parse.args, "rev-parse",
> +					 "HEAD", NULL);
> +			if (!capture_command(&cp_rev_parse, &sb_rev_parse, 0)) {
> +				strbuf_strip_suffix(&sb_rev_parse, "\n");
> +				get_oid_hex(sb_rev_parse.buf, &p->oid_dst);
> +			}
> +			strbuf_release(&sb_rev_parse);
> +		} else if (S_ISLNK(p->mod_dst) || S_ISREG(p->mod_dst)) {
> +			struct child_process cp_hash_object = CHILD_PROCESS_INIT;
> +			struct strbuf sb_hash_object = STRBUF_INIT;
> +
> +			cp_hash_object.git_cmd = 1;
> +			argv_array_pushl(&cp_hash_object.args, "hash-object",
> +					 p->sm_path, NULL);
> +			if (!capture_command(&cp_hash_object,
> +					     &sb_hash_object, 0)) {
> +				strbuf_strip_suffix(&sb_hash_object, "\n");
> +				get_oid_hex(sb_hash_object.buf, &p->oid_dst);
> +			}
> +			strbuf_release(&sb_hash_object);

It would probably be shorter, less error-prone, and quicker to use
`index_fd()` directly.
--------------->8--------------

What exactly did you mean here and where should the index_fd() be used?

Regards,
Shourya Shukla