public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Stefan Beller <sbeller@google•com>
Cc: git@vger•kernel.org, sunshine@sunshineco•com,
	jacob.keller@gmail•com, norio.nomura@gmail•com
Subject: Re: [PATCH 1/2] submodule--helper, module_clone: always operate on absolute paths
Date: Fri, 01 Apr 2016 12:18:23 -0700	[thread overview]
Message-ID: <xmqq7fghi1ds.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <1459469849-9643-2-git-send-email-sbeller@google.com> (Stefan Beller's message of "Thu, 31 Mar 2016 17:17:28 -0700")

Stefan Beller <sbeller@google•com> writes:

> +	char *sm_gitdir_rel, *p, *path = NULL;
> +	const char *sm_gitdir;
>  	struct strbuf rel_path = STRBUF_INIT;
>  	struct strbuf sb = STRBUF_INIT;
>  
> @@ -198,7 +199,14 @@ static int module_clone(int argc, const char **argv, const char *prefix)
>  		die(_("submodule--helper: unspecified or empty --path"));
>  
>  	strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
> -	sm_gitdir = strbuf_detach(&sb, NULL);
> +	sm_gitdir_rel = strbuf_detach(&sb, NULL);
> +	sm_gitdir = absolute_path(sm_gitdir_rel);

With this change, sm_gitdir will always be absolute, which means the
parameter to clone_submodule() call (immedately after this hunk)
will now be always absolute.  I do not think "git clone" called from
there will leave anything in the resulting repository that depends
on the --separate-git-dir=<dir> being relative or absolute, so this
change should not cause us new problems.

By the way, this line is the last use of sm_gitdir_rel before it
gets freed.  I wonder

	sm_gitdir = absolute_path(sb.buf);

would be sufficient.  We can lose the variable, and free() on it at
the end of this function, and an extra allocation if we can do so.

> +	if (!is_absolute_path(path)) {
> +		strbuf_addf(&sb, "%s/%s", get_git_work_tree(), path);
> +		path = strbuf_detach(&sb, 0);
> +	} else
> +		path = xstrdup(path);
>  
>  	if (!file_exists(sm_gitdir)) {
>  		if (safe_create_leading_directories_const(sm_gitdir) < 0)

Other than that, looks good to me.

Thanks.

  reply	other threads:[~2016-04-01 19:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-01  0:17 [PATCHv3 0/2] Fix relative path issues in recursive submodules Stefan Beller
2016-04-01  0:17 ` [PATCH 1/2] submodule--helper, module_clone: always operate on absolute paths Stefan Beller
2016-04-01 19:18   ` Junio C Hamano [this message]
2016-04-01 19:30     ` Junio C Hamano
2016-04-01 20:09       ` Eric Sunshine
2016-04-01 20:39       ` Junio C Hamano
2016-04-01  0:17 ` [PATCH 2/2] submodule--helper, module_clone: catch fprintf failure Stefan Beller
2016-04-01 14:41 ` [PATCHv3 0/2] Fix relative path issues in recursive submodules Ramsay Jones
2016-04-12 15:58   ` Stefan Beller
2016-04-13 19:21     ` Ramsay Jones
2016-04-13 20:34       ` Stefan Beller
2016-04-13 22:23         ` Junio C Hamano
2016-04-13 22:30           ` Stefan Beller
2016-04-13 22:45             ` Junio C Hamano
2016-04-13 21:03       ` Junio C Hamano

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=xmqq7fghi1ds.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=jacob.keller@gmail$(echo .)com \
    --cc=norio.nomura@gmail$(echo .)com \
    --cc=sbeller@google$(echo .)com \
    --cc=sunshine@sunshineco$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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