Re: [PATCH] remote.c: Fix overtight refspec validation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 25 Mar 2008, Junio C Hamano wrote:

> This however has unintended side effect of allowing 
> 
> 	[remote "bour"]
>         	url = ../neighbour
>                 fetch = refs/heads/*
> 
> at the syntax level.  I do not know offhand the fetch backends are
> prepared to deal with such wildcard patterns.
> 
> Daniel?

It's not a matter of the backends, which don't implement any of the 
control flow in the fetch direction; it's get_expanded_map(), which needs 
to be told that you can have something match a pattern but not have a 
local tracking ref.

OTOH, the only use for such a pattern is an octopus merge of whatever 
branches a remote happens to have, right? I remember thinking this was a 
non-useful refspec when I was dealing with the fetch code (and then 
forgetting that it was useful for push). It might be better to just 
disallow it in the direction-specific semantic checks.

Here's the patch to make it work, anyway:
----

commit 6a8bcb917e1aa9b3c972f14f618ab573e457ebee
Author: Daniel Barkalow <barkalow@xxxxxxxxxxxx>
Date:   Wed Mar 26 01:39:07 2008 -0400

    Support fetching refspecs like "refs/heads/*"
    
    Signed-off-by: Daniel Barkalow <barkalow@xxxxxxxxxxxx>

diff --git a/remote.c b/remote.c
index a027bca..f8f4b34 100644
--- a/remote.c
+++ b/remote.c
@@ -998,22 +998,24 @@ static struct ref *get_expanded_map(const struct ref *remote_refs,
 	struct ref **tail = &ret;
 
 	int remote_prefix_len = strlen(refspec->src);
-	int local_prefix_len = strlen(refspec->dst);
+	int local_prefix_len = refspec->dst ? strlen(refspec->dst) : 0;
 
 	for (ref = remote_refs; ref; ref = ref->next) {
 		if (strchr(ref->name, '^'))
 			continue; /* a dereference item */
 		if (!prefixcmp(ref->name, refspec->src)) {
-			const char *match;
 			struct ref *cpy = copy_ref(ref);
-			match = ref->name + remote_prefix_len;
-
-			cpy->peer_ref = alloc_ref(local_prefix_len +
-						  strlen(match) + 1);
-			sprintf(cpy->peer_ref->name, "%s%s",
-				refspec->dst, match);
-			if (refspec->force)
-				cpy->peer_ref->force = 1;
+
+			if (refspec->dst) {
+				const char *match = ref->name + 
+					remote_prefix_len;
+				cpy->peer_ref = alloc_ref(local_prefix_len +
+							  strlen(match) + 1);
+				sprintf(cpy->peer_ref->name, "%s%s",
+					refspec->dst, match);
+				if (refspec->force)
+					cpy->peer_ref->force = 1;
+			}
 			*tail = cpy;
 			tail = &cpy->next;
 		}
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux