git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Daniel Barkalow <barkalow@iabervon.org>
Date
Mar 26, 2008, 05:42 UTC
Message-ID
<alpine.LNX.1.00.0803260130390.19665@iabervon.org>
In-Reply-To
<7vfxuejf9d.fsf@gitster.siamese.dyndns.org>
On Tue, 25 Mar 2008, Junio C Hamano wrote:
Show 10 quoted lines
> 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@iabervon.org>
Date:   Wed Mar 26 01:39:07 2008 -0400
    Support fetching refspecs like "refs/heads/*"
    
    Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
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;
 		}
Previous: Junio C HamanoNext: Junio C Hamano
Message 18 of 20 in “Permit refspec source side to parse as a sha1”
  1. Permit refspec source side to parse as a sha1Daniel Barkalow, Mar 21, 2008
  2. Junio C HamanoMar 21, 2008
  3. Junio C HamanoMar 21, 2008
  4. Daniel BarkalowMar 21, 2008
  5. Junio C HamanoMar 21, 2008
  6. Daniel BarkalowMar 21, 2008
  7. Junio C HamanoMar 21, 2008
  8. Daniel BarkalowMar 21, 2008
  9. remote.c: Fix overtight refspec validationJunio C Hamano, Mar 21, 2008
  10. Daniel BarkalowMar 21, 2008
  11. Junio C HamanoMar 21, 2008
  12. Daniel BarkalowMar 22, 2008
  13. Junio C HamanoMar 22, 2008
  14. Daniel BarkalowMar 22, 2008
  15. Linus TorvaldsMar 26, 2008
  16. Junio C HamanoMar 26, 2008
  17. Junio C HamanoMar 26, 2008
  18. Daniel BarkalowMar 26, 2008
  19. Junio C HamanoMar 26, 2008
  20. Jeff KingMar 26, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.