git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] use local cloning if insteadOf makes a local URL
@ 2014-07-17  7:09 Michael Barabanov
  2014-07-17 17:23 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Michael Barabanov @ 2014-07-17  7:09 UTC (permalink / raw)
  To: git; +Cc: gitster

Move the is_local logic to the place where origin remote has been setup and
check if the remote url can be used to do local cloning.

This saves a lot of space (and time) in some of the mirroring scenarios that
involve insteadOf rewrites.

Signed-off-by: Michael Barabanov <michael.barabanov@windriver.com>
---
 builtin/clone.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/builtin/clone.c b/builtin/clone.c
index f0dabec..bbd169c 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -799,18 +799,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		die(_("repository '%s' does not exist"), repo_name);
 	else
 		repo = repo_name;
-	is_local = option_local != 0 && path && !is_bundle;
-	if (is_local) {
-		if (option_depth)
-			warning(_("--depth is ignored in local clones; use file:// instead."));
-		if (!access(mkpath("%s/shallow", path), F_OK)) {
-			if (option_local > 0)
-				warning(_("source repository is shallow, ignoring --local"));
-			is_local = 0;
-		}
-	}
-	if (option_local > 0 && !is_local)
-		warning(_("--local is ignored"));
 
 	/* no need to be strict, transport_set_option() will validate it again */
 	if (option_depth && atoi(option_depth) < 1)
@@ -903,6 +891,19 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
 	remote = remote_get(option_origin);
 	transport = transport_get(remote, remote->url[0]);
+	path = get_repo_path(remote->url[0], &is_bundle);
+	is_local = option_local != 0 && path && !is_bundle;
+	if (is_local) {
+		if (option_depth)
+			warning(_("--depth is ignored in local clones; use file:// instead."));
+		if (!access(mkpath("%s/shallow", path), F_OK)) {
+			if (option_local > 0)
+				warning(_("source repository is shallow, ignoring --local"));
+			is_local = 0;
+		}
+	}
+	if (option_local > 0 && !is_local)
+		warning(_("--local is ignored"));
 	transport->cloning = 1;
 
 	if (!transport->get_refs_list || (!is_local && !transport->fetch))
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] use local cloning if insteadOf makes a local URL
  2014-07-17  7:09 [PATCH] use local cloning if insteadOf makes a local URL Michael Barabanov
@ 2014-07-17 17:23 ` Junio C Hamano
  2014-07-17 18:41   ` Michael Barabanov
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2014-07-17 17:23 UTC (permalink / raw)
  To: Michael Barabanov; +Cc: git

Michael Barabanov <michael.barabanov@windriver.com> writes:
> Move the is_local logic to the place where origin remote has been setup and
> check if the remote url can be used to do local cloning.
>
> This saves a lot of space (and time) in some of the mirroring scenarios that
> involve insteadOf rewrites.
>
> Signed-off-by: Michael Barabanov <michael.barabanov@windriver.com>
> ---

Strictly speaking, this change introduces a regression to those who
would rather use --no-local if they knew the are cloning from a
local copy, but they can rewrite their insteadOf to use file:// URL
as a workaround.

The code change looked OK from a cursory read, modulo possibly
introducing a new memory leak on the old value of "path" (I didn't
check carefully).

Thanks.

>  builtin/clone.c | 25 +++++++++++++------------
>  1 file changed, 13 insertions(+), 12 deletions(-)
>
> diff --git a/builtin/clone.c b/builtin/clone.c
> index f0dabec..bbd169c 100644
> --- a/builtin/clone.c
> +++ b/builtin/clone.c
> @@ -799,18 +799,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
>  		die(_("repository '%s' does not exist"), repo_name);
>  	else
>  		repo = repo_name;
> -	is_local = option_local != 0 && path && !is_bundle;
> -	if (is_local) {
> -		if (option_depth)
> -			warning(_("--depth is ignored in local clones; use file:// instead."));
> -		if (!access(mkpath("%s/shallow", path), F_OK)) {
> -			if (option_local > 0)
> -				warning(_("source repository is shallow, ignoring --local"));
> -			is_local = 0;
> -		}
> -	}
> -	if (option_local > 0 && !is_local)
> -		warning(_("--local is ignored"));
>  
>  	/* no need to be strict, transport_set_option() will validate it again */
>  	if (option_depth && atoi(option_depth) < 1)
> @@ -903,6 +891,19 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
>  
>  	remote = remote_get(option_origin);
>  	transport = transport_get(remote, remote->url[0]);
> +	path = get_repo_path(remote->url[0], &is_bundle);
> +	is_local = option_local != 0 && path && !is_bundle;
> +	if (is_local) {
> +		if (option_depth)
> +			warning(_("--depth is ignored in local clones; use file:// instead."));
> +		if (!access(mkpath("%s/shallow", path), F_OK)) {
> +			if (option_local > 0)
> +				warning(_("source repository is shallow, ignoring --local"));
> +			is_local = 0;
> +		}
> +	}
> +	if (option_local > 0 && !is_local)
> +		warning(_("--local is ignored"));
>  	transport->cloning = 1;
>  
>  	if (!transport->get_refs_list || (!is_local && !transport->fetch))

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] use local cloning if insteadOf makes a local URL
  2014-07-17 17:23 ` Junio C Hamano
@ 2014-07-17 18:41   ` Michael Barabanov
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Barabanov @ 2014-07-17 18:41 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git



On 07/17/2014 10:23 AM, Junio C Hamano wrote:
> Michael Barabanov <michael.barabanov@windriver.com> writes:
>> Move the is_local logic to the place where origin remote has been setup and
>> check if the remote url can be used to do local cloning.
>>
>> This saves a lot of space (and time) in some of the mirroring scenarios that
>> involve insteadOf rewrites.
>>
>> Signed-off-by: Michael Barabanov <michael.barabanov@windriver.com>
>> ---
>
> Strictly speaking, this change introduces a regression to those who
> would rather use --no-local if they knew the are cloning from a
> local copy, but they can rewrite their insteadOf to use file:// URL
> as a workaround.

Plus --no-local still works on command line, even if rewritten URL ends 
up to be local.

>
> The code change looked OK from a cursory read, modulo possibly
> introducing a new memory leak on the old value of "path" (I didn't
> check carefully).

In fact, I couldn't find where original "path" is freed anyway.
Memory will be freed when the clone process exits of course.

Michael.

>
> Thanks.
>
>>  builtin/clone.c | 25 +++++++++++++------------
>>  1 file changed, 13 insertions(+), 12 deletions(-)
>>
>> diff --git a/builtin/clone.c b/builtin/clone.c
>> index f0dabec..bbd169c 100644
>> --- a/builtin/clone.c
>> +++ b/builtin/clone.c
>> @@ -799,18 +799,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
>>  		die(_("repository '%s' does not exist"), repo_name);
>>  	else
>>  		repo = repo_name;
>> -	is_local = option_local != 0 && path && !is_bundle;
>> -	if (is_local) {
>> -		if (option_depth)
>> -			warning(_("--depth is ignored in local clones; use file:// instead."));
>> -		if (!access(mkpath("%s/shallow", path), F_OK)) {
>> -			if (option_local > 0)
>> -				warning(_("source repository is shallow, ignoring --local"));
>> -			is_local = 0;
>> -		}
>> -	}
>> -	if (option_local > 0 && !is_local)
>> -		warning(_("--local is ignored"));
>>
>>  	/* no need to be strict, transport_set_option() will validate it again */
>>  	if (option_depth && atoi(option_depth) < 1)
>> @@ -903,6 +891,19 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
>>
>>  	remote = remote_get(option_origin);
>>  	transport = transport_get(remote, remote->url[0]);
>> +	path = get_repo_path(remote->url[0], &is_bundle);
>> +	is_local = option_local != 0 && path && !is_bundle;
>> +	if (is_local) {
>> +		if (option_depth)
>> +			warning(_("--depth is ignored in local clones; use file:// instead."));
>> +		if (!access(mkpath("%s/shallow", path), F_OK)) {
>> +			if (option_local > 0)
>> +				warning(_("source repository is shallow, ignoring --local"));
>> +			is_local = 0;
>> +		}
>> +	}
>> +	if (option_local > 0 && !is_local)
>> +		warning(_("--local is ignored"));
>>  	transport->cloning = 1;
>>
>>  	if (!transport->get_refs_list || (!is_local && !transport->fetch))
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-07-17 18:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-17  7:09 [PATCH] use local cloning if insteadOf makes a local URL Michael Barabanov
2014-07-17 17:23 ` Junio C Hamano
2014-07-17 18:41   ` Michael Barabanov

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).