git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Couder <christian.couder@gmail.com>
To: Atharva Raykar <raykar.ath@gmail.com>
Cc: git <git@vger.kernel.org>, Junio C Hamano <gitster@pobox.com>,
	Shourya Shukla <shouryashukla.oo@gmail.com>,
	Prathamesh Chavan <pc44800@gmail.com>
Subject: Re: [PATCH v2] [GSoC] submodule--helper: introduce add-clone subcommand
Date: Fri, 4 Jun 2021 10:21:02 +0200	[thread overview]
Message-ID: <CAP8UFD01-VJpUEGg3cEG7X=xU0KCv1AEgq2n_qhk=U+rXV5mvA@mail.gmail.com> (raw)
In-Reply-To: <20210602131259.50350-1-raykar.ath@gmail.com>

On Wed, Jun 2, 2021 at 3:13 PM Atharva Raykar <raykar.ath@gmail.com> 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.

  reply	other threads:[~2021-06-04  8:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-28  8:12 [PATCH][GSoC] submodule: introduce add-clone helper for submodule add Atharva Raykar
2021-06-01 22:10 ` Christian Couder
2021-06-02  7:55   ` Atharva Raykar
2021-06-02  8:18     ` Atharva Raykar
2021-06-02 13:12 ` [PATCH v2] [GSoC] submodule--helper: introduce add-clone subcommand Atharva Raykar
2021-06-04  8:21   ` Christian Couder [this message]
2021-06-04  9:47     ` Atharva Raykar
2021-06-04 11:05       ` [PATCH v3] " Atharva Raykar
2021-06-04 11:16         ` Atharva Raykar
2021-06-04 11:37   ` [PATCH v2] " Shourya Shukla
2021-06-04 12:02     ` Atharva Raykar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAP8UFD01-VJpUEGg3cEG7X=xU0KCv1AEgq2n_qhk=U+rXV5mvA@mail.gmail.com' \
    --to=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pc44800@gmail.com \
    --cc=raykar.ath@gmail.com \
    --cc=shouryashukla.oo@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).