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

Re: git bug? + question

From
Linus Torvalds <torvalds@osdl.org>
Date
Nov 3, 2006, 16:10 UTC
Message-ID
<Pine.LNX.4.64.0611030741530.25218@g5.osdl.org>
In-Reply-To
<7v3b90gbfv.fsf@assigned-by-dhcp.cox.net>
On Fri, 3 Nov 2006, Junio C Hamano wrote:
> 
> 	[remote."gitster"]

Btw, why the '.'? It doesn't even work with a dot, you have to have a space, which is also a lot more readable..

Also, may I suggest that we just extend the format with a robust default value thing?

It should be reasonably easy to have just the rule:
 - add a new "remote.<remote>.branch" thing that lists multiple simple 
   branches separated by whitespace.
 - a "simple branch" is just a "implicit refspec" for the relationship
   "heads/<name>:remotes/<remote>/<name>"

And then you should be able to write all of your cumbersome config options as a simple

	[remote "gitster"]
		url = gitster.example.com:/home/junio/git.git/
		branch = maint master next +pu
and you're all done. It would imply everything you said.

This would basically require that "git-parse-remote" be re-written as a native builtin, because quite frankly, it would be too damn painful any other way, but it really shouldn't be that nasty. In fact, I think we should have done that long ago, because the shell-code is just horrid for things like this.

For example, for builtin-push (which is currently the only thing that parses "remote" entries in C), you'd just need to do something like the appended.. It would generate the full refspecs from the "branch" config automatically.

		Linus
---
diff --git a/builtin-push.c b/builtin-push.c
index d23974e..805ffa8 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -123,15 +123,33 @@ static int get_remote_config(const char*
 {
 	if (!strncmp(key, "remote.", 7) &&
 	    !strncmp(key + 7, config_repo, config_repo_len)) {
-		if (!strcmp(key + 7 + config_repo_len, ".url")) {
+	    	const char *subkey = key + 7 + config_repo_len;
+		if (!strcmp(subkey, ".url")) {
 			if (config_current_uri < MAX_URI)
 				config_uri[config_current_uri++] = xstrdup(value);
 			else
 				error("more than %d URL's specified, ignoring the rest", MAX_URI);
 		}
-		else if (config_get_refspecs &&
-			 !strcmp(key + 7 + config_repo_len, ".push"))
-			add_refspec(xstrdup(value));
+		else if (config_get_refspecs) {
+			if (!strcmp(subkey, ".push"))
+				add_refspec(xstrdup(value));
+			else if (!strcmp(subkey, ".branch")) {
+				while (isspace(*value))
+					value++;
+				while (*value) {
+					const char *end = value;
+					while (!isspace(*end))
+						end++;
+					add_refspec(xsprintf("heads/%.*s:remotes/%.*s/%.*s",
+						end-value, value,
+						config_repo_len, config_repo,
+						end-value, value));
+					while (isspace(*end))
+						end++;
+					value = end;
+				}
+			}
+		}
 	}
 	return 0;
Previous: Santi BéjarNext: Junio C Hamano
Message 16 of 38 in “git bug? + question”
  1. Miles BaderNov 2, 2006
  2. Junio C HamanoNov 3, 2006
  3. SeanNov 3, 2006
  4. Karl HasselströmNov 3, 2006
  5. Junio C HamanoNov 3, 2006
  6. Andy ParkinsNov 3, 2006
  7. Junio C HamanoNov 3, 2006
  8. Karl HasselströmNov 3, 2006
  9. Josef WeidendorferNov 3, 2006
  10. Jakub NarebskiNov 3, 2006
  11. Josef WeidendorferNov 3, 2006
  12. Junio C HamanoNov 4, 2006
  13. Josef WeidendorferNov 4, 2006
  14. Martin WaitzNov 3, 2006
  15. Santi BéjarNov 3, 2006
  16. Linus TorvaldsNov 3, 2006
  17. Junio C HamanoNov 3, 2006
  18. Andy ParkinsNov 3, 2006
  19. Karl HasselströmNov 3, 2006
  20. SeanNov 3, 2006
  21. Karl HasselströmNov 3, 2006
  22. Shawn PearceNov 3, 2006
  23. SeanNov 3, 2006
  24. Jeff KingNov 3, 2006
  25. Shawn PearceNov 4, 2006
  26. Shawn PearceNov 3, 2006
  27. SeanNov 3, 2006
  28. Junio C HamanoNov 4, 2006
  29. SeanNov 4, 2006
  30. Shawn PearceNov 4, 2006
  31. Josef WeidendorferNov 4, 2006
  32. Shawn PearceNov 4, 2006
  33. Josef WeidendorferNov 6, 2006
  34. Andy WhitcroftNov 6, 2006
  35. Josef WeidendorferNov 6, 2006
  36. Andy WhitcroftNov 6, 2006
  37. Shawn PearceNov 4, 2006
  38. Shawn PearceNov 4, 2006

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.