On Wed, Jun 2, 2021 at 3:13 PM Atharva Raykar <raykar.ath@xxxxxxxxx> wrote: > +static void show_fetch_remotes(FILE *output, const char *sm_name, const char *git_dir_path) > +{ > + struct child_process cp_remote = CHILD_PROCESS_INIT; > + struct strbuf sb_remote_out = STRBUF_INIT; > + > + cp_remote.git_cmd = 1; > + strvec_pushf(&cp_remote.env_array, > + "GIT_DIR=%s", git_dir_path); > + strvec_push(&cp_remote.env_array, "GIT_WORK_TREE=."); > + strvec_pushl(&cp_remote.args, "remote", "-v", NULL); > + if (!capture_command(&cp_remote, &sb_remote_out, 0)) { > + char *line; > + char *begin = sb_remote_out.buf; > + char *end = sb_remote_out.buf + sb_remote_out.len; > + while (begin != end && (line = get_next_line(begin, end))) { > + char *name, *url, *tail; > + name = parse_token(&begin, line); > + url = parse_token(&begin, line); > + tail = parse_token(&begin, line); Sorry for not replying to your earlier message, but I think it's a bit better to save a line with: char *name = parse_token(&begin, line); char *url = parse_token(&begin, line); char *tail = parse_token(&begin, line); > + if (!memcmp(tail, "(fetch)", 7)) > + fprintf(output, " %s\t%s\n", name, url); > + free(url); > + free(name); > + free(tail); > + } > + } > + > + strbuf_release(&sb_remote_out); > +} > + > +static int add_submodule(const struct add_data *info) > +{ > + char *submod_gitdir_path; > + /* perhaps the path already exists and is already a git repo, else clone it */ > + if (is_directory(info->sm_path)) { > + printf("sm_path=%s\n", info->sm_path); I don't see which shell code the above printf(...) instruction is replacing. That's why I asked if it's some debugging leftover. [...] > + if (info->dissociate) > + strvec_push(&clone_args, "--dissociate"); > + if (info->depth >= 0) > + strvec_pushf(&clone_args, "--depth=%d", info->depth); It's ok if there is a blank line here. > + if (module_clone(clone_args.nr, clone_args.v, info->prefix)) { > + strvec_clear(&clone_args); > + return -1; > + } > + strvec_clear(&clone_args); > +static int add_clone(int argc, const char **argv, const char *prefix) > +{ > + const char *branch = NULL, *sm_path = NULL; > + const char *wt_prefix = NULL, *realrepo = NULL; > + const char *reference = NULL, *sm_name = NULL; > + int force = 0, quiet = 0, dissociate = 0, depth = -1, progress = 0; > + struct add_data info = ADD_DATA_INIT; Maybe: s/info/add_data/ Also it seems that in many cases it's a bit wasteful to use new variables for option parsing and then to copy them into the add_data struct when the field of the add_data struct could be used directly for option parsing... > + struct option options[] = { > + OPT_STRING('b', "branch", &branch, ...for example, here maybe `&add_data.branch` could be used instead of `&branch`... > + N_("branch"), > + N_("branch of repository to checkout on cloning")), [...] > + info.branch = branch; ...so that the above line would not be needed.