git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Stefan Beller <sbeller@google.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Eric Sunshine <sunshine@sunshineco.com>,
	"git@vger.kernel.org" <git@vger.kernel.org>,
	Jonathan Nieder <jrnieder@gmail.com>,
	Johannes Schindelin <johannes.schindelin@gmail.com>,
	Jens Lehmann <Jens.Lehmann@web.de>, Jeff King <peff@peff.net>
Subject: Re: [PATCHv5 3/3] submodule: Reimplement `module_clone` shell function in C
Date: Tue, 8 Sep 2015 11:31:17 -0700	[thread overview]
Message-ID: <CAGZ79kYAsNZ1huLrYOvyPtYHKoN4paBGXbY3OMX3SQNMwqCiKA@mail.gmail.com> (raw)
In-Reply-To: <xmqq8u8ni2bv.fsf@gitster.mtv.corp.google.com>

On Thu, Sep 3, 2015 at 3:07 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> +
>> +     cp.no_stdin = 1;
>> +     cp.no_stdout = 1;
>> +     cp.no_stderr = 1;
>
> Output from "git clone" is not shown, regardless of --quiet option?

Removed that.

>> +     argc = parse_options(argc, argv, prefix, module_clone_options,
>> +                          git_submodule_helper_usage, 0);
>> +
>> +     strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
>
> The original says
>
>         base_name=$(dirname "$name")
>
> before doing this %s/modules/%s concatenation.  I do not think we
> intended to allow a slash in submodule name, so this difference may
> be showing that the original was doing an unnecessary thing.

The way I understood the code, this was a workaround of now having
safe_create_leading_directories, which takes the base directory of
a given path and creates that directory. (base_name is only used as an
argument for mkdir -p).

Slashes are already in use for submodule names as the name defaults
to the path if no explicit name is given. And the path may contain slashes
as it may be nested. In Gerrit we have a .gitmodules:
[submodule "plugins/commit-message-length-validator"]
    path = plugins/commit-message-length-validator
    url = ../plugins/commit-message-length-validator
[...

>
>> +     sm_gitdir = strbuf_detach(&sb, NULL);
>> +
>> +     if (!file_exists(sm_gitdir)) {
>> +             if (safe_create_leading_directories_const(sm_gitdir) < 0)
>> +                     die(_("could not create directory '%s'"), sm_gitdir);
>> +             if (clone_submodule(path, sm_gitdir, url, depth, reference, quiet))
>> +                     die(_("clone of '%s' into submodule path '%s' failed"),
>> +                         url, path);
>> +     } else {
>> +             if (safe_create_leading_directories_const(path) < 0)
>> +                     die(_("could not create directory '%s'"), path);
>> +             strbuf_addf(&sb, "%s/index", sm_gitdir);
>> +             if (unlink(sb.buf) < 0)
>> +                     die_errno(_("failed to delete '%s'"), sm_gitdir);
>
> The original says "we do not care if it failed" with
>
>         rm -f "$gitdir/index"
>
> I think the intention of the original is "we do not care if it
> failed because it did not exist." in which case unconditional
> die_errno() here may be something we do not want?

Right, this was a short-circuit reaction from me on Erics comment
to check for the return value of unlink. I think we can use
unlink_or_warn here as that only warns if we cannot remove
an existing file. non existent files are not warned about.

>
>> +             strbuf_reset(&sb);
>> +     }
>> +
>> +     /* Write a .git file in the submodule to redirect to the superproject. */
>> +     if (safe_create_leading_directories_const(path) < 0)
>> +             die(_("could not create directory '%s'"), path);
>> +
>> +     if (path && *path)
>> +             strbuf_addf(&sb, "%s/.git", path);
>> +     else
>> +             strbuf_addf(&sb, ".git");
>> +
>> +     if (safe_create_leading_directories_const(sb.buf) < 0)
>> +             die(_("could not create leading directories of '%s'"), sb.buf);
>> +     submodule_dot_git = fopen(sb.buf, "w");
>> +     if (!submodule_dot_git)
>> +             die_errno(_("cannot open file '%s'"), sb.buf);
>> +
>> +     fprintf(submodule_dot_git, "gitdir: %s\n",
>> +             relative_path(sm_gitdir, path, &rel_path));
>> +     if (fclose(submodule_dot_git))
>> +             die(_("could not close file %s"), sb.buf);
>> +     strbuf_reset(&sb);
>> +     strbuf_reset(&rel_path);
>
> The original seems to go quite a length to make sure symbolic links
> do not fool the comparison between $gitdir and $sm_path, and also it
> makes sure one is not a subpath of the other.  Do we need the same
> level of carefulness, or is textual relative_path() enough?

I think the original was doing an "optimized" version of relative_path()
as we know that they have an anchor at the superproject root directory.

relative_path() seems to deal with the symbolic links just fine, as all
tests pass. (6eafa6d096ce, "submodules: don't stumble over symbolic
links when cloning recursively" did add code as well as testing for symbolic
link problems, Thanks Jens!)

>>               --depth=*)
>> -                     depth=$1
>> +                     depth="$1"
>
> This seems to be an unrelated change.

A leftover from earlier, when I mucked around with --depth and
--reference in the shell scipt.


On Thu, Sep 3, 2015 at 4:17 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
>> +       if (path && *path)
>> +               strbuf_addf(&sb, "%s/.git", path);
>> +       else
>> +               strbuf_addf(&sb, ".git");
>
> Minor: strbuf_addstr(...);

done

  reply	other threads:[~2015-09-08 18:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-02 21:42 [PATCHv5 0/3] submodule--helper: Have some refactoring only patches first Stefan Beller
2015-09-02 21:42 ` [PATCHv5 1/3] submodule: Reimplement `module_list` shell function in C Stefan Beller
2015-09-03 18:57   ` Junio C Hamano
2015-09-03 19:18     ` Stefan Beller
2015-09-02 21:42 ` [PATCHv5 2/3] submodule: Reimplement `module_name` " Stefan Beller
2015-09-02 21:42 ` [PATCHv5 3/3] submodule: Reimplement `module_clone` " Stefan Beller
2015-09-03 22:07   ` Junio C Hamano
2015-09-08 18:31     ` Stefan Beller [this message]
2015-09-08 22:46       ` Junio C Hamano
2015-09-03 23:17   ` Eric Sunshine

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=CAGZ79kYAsNZ1huLrYOvyPtYHKoN4paBGXbY3OMX3SQNMwqCiKA@mail.gmail.com \
    --to=sbeller@google.com \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johannes.schindelin@gmail.com \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).