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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 26, 2008, 05:46 UTC
Message-ID
<7vtziughqo.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<alpine.LNX.1.00.0803260130390.19665@iabervon.org>
Daniel Barkalow <barkalow@iabervon.org> writes:
Show 5 quoted lines
> 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.

I agree. refs/*:refs/* could have been useful before --mirror, but refs/* (fetch but not store) is not useful at all, so what I plan to commit looks like this (i.e. "the third time lucky" edition).

-- >8 -- [PATCH] refspec: allow colon-less wildcard "refs/category/*"

"git push --tags elsewhere" is implemented in terms of wildcarded refspec "refs/tags/*" these days, and the user wants to push the tags under the same name to the other branch. This resurrects the support for it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 remote.c |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/remote.c b/remote.c
index 40ed246..04f7521 100644
--- a/remote.c
+++ b/remote.c
@@ -417,17 +417,21 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
 			rhs++;
 			rlen = strlen(rhs);
 			is_glob = (2 <= rlen && !strcmp(rhs + rlen - 2, "/*"));
-			rs[i].dst = xstrndup(rhs, rlen - is_glob * 2);
+			if (is_glob)
+				rlen -= 2;
+			rs[i].dst = xstrndup(rhs, rlen);
 		}
 
 		llen = (rhs ? (rhs - lhs - 1) : strlen(lhs));
-		if (is_glob != (2 <= llen && !memcmp(lhs + llen - 2, "/*", 2)))
-			goto invalid;
-
-		if (is_glob) {
+		if (2 <= llen && !memcmp(lhs + llen - 2, "/*", 2)) {
+			if ((rhs && !is_glob) || (!rhs && fetch))
+				goto invalid;
+			is_glob = 1;
 			llen -= 2;
-			rlen -= 2;
+		} else if (rhs && is_glob) {
+			goto invalid;
 		}
j+
 		rs[i].pattern = is_glob;
 		rs[i].src = xstrndup(lhs, llen);
 
@@ -446,7 +450,7 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
 			}
 			/*
 			 * RHS
-			 * - missing is allowed.
+			 * - missing is ok, and is same as empty.
 			 * - empty is ok; it means not to store.
 			 * - otherwise it must be a valid looking ref.
 			 */
-- 
1.5.5.rc1.128.g340c
Previous: Daniel BarkalowNext: Jeff King
Message 19 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.