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

Re: Implementing branch attributes in git config

From
sean <seanlkml@sympatico.ca>
Date
May 9, 2006, 22:09 UTC
Message-ID
<BAYC1-PASMTP04D623089E043F1C792A37AEA90@CEZ.ICE>
In-Reply-To
<BAYC1-PASMTP02C02EAC2F64AC00BB5801AEA90@CEZ.ICE>

On Tue, 9 May 2006 15:44:59 -0400 sean <seanlkml@sympatico.ca> wrote:

Show 16 quoted lines
> On Tue, 9 May 2006 12:24:02 -0700 (PDT)
> Linus Torvalds <torvalds@osdl.org> wrote:
> 
> > NOTE! This patch could be applied right now, and to all the branches (to
> > make 1.x, 1.2.x and 1.3.x all support the _syntax_). Even if nothing 
> > actually uses it.
> > 
> > It just makes the syntax be
> > 
> > 	[section<space>+"<randomstring>"]
> > 
> > where the only rule for "randomstring" is that it can't contain a newline, 
> > and if you really want to insert a double-quote, you do it with \".
> 
> Lightly tested here.  Looks good.
> 
Linus,

I really tried to like your patch ;o) But it breaks the repo-config command line and causes mixing of some branches using old style [branch.xyz] and new style [branch "XYZ"] which just doesn't seem to be the right thing to do.

The following patch produced for sake of discussion just allows section headers to contain whatever characters are needed to get the job done.

git-repo-config works properly with no further need of change. Section headers become case sensitive but key identifiers within sections do not. AFAIK there should be no backward compatibility issues with regard to case sensitivity. All tests pass after having been fixed up to remove the assumption that section names are case insensitive.

The syntax is:
  [<random string>]
Here's how your example would look in this style:
  [email.torvalds@osdl.org]
        name = Linus Torvalds
And there's no strange syntax needed with repo-config to set and get it:
  $ git repo-config email.torvalds@osdl.org.name
  Linus Torvalds
and just to show that key names are still case insensitive:
  $ git repo-config email.torvalds@osdl.org.NAME
  Linus Torvalds

Setting new sections is unambiguous from the command line and doesn't have to decide whether to use the [branch "<string>"] or [branch.section.name] format.

  $ git repo-config branch.branch.x y
  $ git repo-config branch.WonkKY.x y
  $ git repo-config --get-regexp branch.\*
  branch.branch.x y
  branch.WonkKY.x y
  [email.torvalds@osdl.org]
        name = Linus Torvalds
  [branch.branch]
        x = y
  [branch.WonkKY]
        x = y

Sean ---

 config.c               |   11 +++++++----
 repo-config.c          |    8 ++++----
 t/t1300-repo-config.sh |   38 ++++++++++++++++++++++----------------
 3 files changed, 33 insertions(+), 24 deletions(-)
diff --git a/config.c b/config.c
index 0f518c9..5d19ae9 100644
--- a/config.c
+++ b/config.c
@@ -144,11 +144,14 @@ static int get_base_var(char *name)
 			return -1;
 		if (c == ']')
 			return baselen;
-		if (!isalnum(c) && c != '.')
-			return -1;
+		if (c == '\\') {
+			c = get_next_char();
+			if (c == '\n')
+				return -1;
+		}
 		if (baselen > MAXNAME / 2)
 			return -1;
-		name[baselen++] = tolower(c);
+		name[baselen++] = c;
 	}
 }
 
@@ -455,7 +458,7 @@ int git_config_set_multivar(const char* 
 			ret = 1;
 			goto out_free;
 		} else
-			store.key[i] = tolower(key[i]);
+			store.key[i] = key[i];
 	store.key[i] = 0;
 
 	/*
diff --git a/repo-config.c b/repo-config.c
index 63eda1b..ba5fbd6 100644
--- a/repo-config.c
+++ b/repo-config.c
@@ -65,11 +65,11 @@ static int show_config(const char* key_,
 static int get_value(const char* key_, const char* regex_)
 {
 	int i;
+	char *tl;
 
-	key = malloc(strlen(key_)+1);
-	for (i = 0; key_[i]; i++)
-		key[i] = tolower(key_[i]);
-	key[i] = 0;
+	key = strdup(key_);
+	for (tl=key+strlen(key)-1; tl >= key && *tl != '.'; --tl)
+		*tl = tolower(*tl);
 
 	if (use_key_regexp) {
 		key_regexp = (regex_t*)malloc(sizeof(regex_t));
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 7090ea9..f341206 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -23,6 +23,7 @@ git-repo-config Core.Movie BadPhysics
 cat > expect << EOF
 [core]
 	penguin = little blue
+[Core]
 	Movie = BadPhysics
 EOF
 
@@ -33,6 +34,7 @@ git-repo-config Cores.WhatEver Second
 cat > expect << EOF
 [core]
 	penguin = little blue
+[Core]
 	Movie = BadPhysics
 [Cores]
 	WhatEver = Second
@@ -45,10 +47,12 @@ git-repo-config CORE.UPPERCASE true
 cat > expect << EOF
 [core]
 	penguin = little blue
+[Core]
 	Movie = BadPhysics
-	UPPERCASE = true
 [Cores]
 	WhatEver = Second
+[CORE]
+	UPPERCASE = true
 EOF
 
 test_expect_success 'similar section' 'cmp .git/config expect'
@@ -62,11 +66,13 @@ test_expect_success 'replace with non-ma
 cat > expect << EOF
 [core]
 	penguin = very blue
-	Movie = BadPhysics
-	UPPERCASE = true
 	penguin = kingpin
+[Core]
+	Movie = BadPhysics
 [Cores]
 	WhatEver = Second
+[CORE]
+	UPPERCASE = true
 EOF
 
 test_expect_success 'non-match result' 'cmp .git/config expect'
@@ -130,7 +136,7 @@ EOF
 
 test_expect_success 'really mean test' 'cmp .git/config expect'
 
-git-repo-config nextsection.nonewline wow
+git-repo-config nextSection.nonewline wow
 
 cat > expect << EOF
 [beta] ; silly comment # another comment
@@ -160,7 +166,7 @@ EOF
 
 test_expect_success 'unset' 'cmp .git/config expect'
 
-git-repo-config nextsection.NoNewLine "wow2 for me" "for me$"
+git-repo-config nextSection.NoNewLine "wow2 for me" "for me$"
 
 cat > expect << EOF
 [beta] ; silly comment # another comment
@@ -176,18 +182,18 @@ EOF
 test_expect_success 'multivar' 'cmp .git/config expect'
 
 test_expect_success 'non-match' \
-	'git-repo-config --get nextsection.nonewline !for'
+	'git-repo-config --get nextSection.nonewline !for'
 
 test_expect_success 'non-match value' \
-	'test wow = $(git-repo-config --get nextsection.nonewline !for)'
+	'test wow = $(git-repo-config --get nextSection.nonewline !for)'
 
 test_expect_failure 'ambiguous get' \
-	'git-repo-config --get nextsection.nonewline'
+	'git-repo-config --get nextSection.nonewline'
 
 test_expect_success 'get multivar' \
-	'git-repo-config --get-all nextsection.nonewline'
+	'git-repo-config --get-all nextSection.nonewline'
 
-git-repo-config nextsection.nonewline "wow3" "wow$"
+git-repo-config nextSection.nonewline "wow3" "wow$"
 
 cat > expect << EOF
 [beta] ; silly comment # another comment
@@ -202,15 +208,15 @@ EOF
 
 test_expect_success 'multivar replace' 'cmp .git/config expect'
 
-test_expect_failure 'ambiguous value' 'git-repo-config nextsection.nonewline'
+test_expect_failure 'ambiguous value' 'git-repo-config nextSection.nonewline'
 
 test_expect_failure 'ambiguous unset' \
-	'git-repo-config --unset nextsection.nonewline'
+	'git-repo-config --unset nextSection.nonewline'
 
 test_expect_failure 'invalid unset' \
-	'git-repo-config --unset somesection.nonewline'
+	'git-repo-config --unset someSection.nonewline'
 
-git-repo-config --unset nextsection.nonewline "wow3$"
+git-repo-config --unset nextSection.nonewline "wow3$"
 
 cat > expect << EOF
 [beta] ; silly comment # another comment
@@ -249,7 +255,7 @@ test_expect_success 'hierarchical sectio
 
 cat > expect << EOF
 beta.noindent=sillyValue
-nextsection.nonewline=wow2 for me
+nextSection.nonewline=wow2 for me
 123456.a123=987
 1.2.3.alpha=beta
 EOF
@@ -259,7 +265,7 @@ test_expect_success 'working --list' \
 
 cat > expect << EOF
 beta.noindent sillyValue
-nextsection.nonewline wow2 for me
+nextSection.nonewline wow2 for me
 EOF
 
 test_expect_success '--get-regexp' \
Previous: seanNext: Junio C Hamano
Message 49 of 75 in “Implementing branch attributes in git config”
  1. Pavel RoskinMay 7, 2006
  2. Junio C HamanoMay 7, 2006
  3. Johannes SchindelinMay 8, 2006
  4. Linus TorvaldsMay 8, 2006
  5. Linus TorvaldsMay 8, 2006
  6. Linus TorvaldsMay 8, 2006
  7. Johannes SchindelinMay 8, 2006
  8. Pavel RoskinMay 8, 2006
  9. Johannes SchindelinMay 8, 2006
  10. Pavel RoskinMay 8, 2006
  11. Junio C HamanoMay 8, 2006
  12. Johannes SchindelinMay 8, 2006
  13. Pavel RoskinMay 8, 2006
  14. seanMay 8, 2006
  15. Linus TorvaldsMay 8, 2006
  16. Pavel RoskinMay 8, 2006
  17. seanMay 8, 2006
  18. Pavel RoskinMay 8, 2006
  19. Linus TorvaldsMay 8, 2006
  20. Junio C HamanoMay 8, 2006
  21. seanMay 8, 2006
  22. Johannes SchindelinMay 8, 2006
  23. seanMay 8, 2006
  24. Junio C HamanoMay 8, 2006
  25. seanMay 8, 2006
  26. Daniel BarkalowMay 8, 2006
  27. seanMay 8, 2006
  28. Johannes SchindelinMay 8, 2006
  29. seanMay 9, 2006
  30. Johannes SchindelinMay 9, 2006
  31. Linus TorvaldsMay 9, 2006
  32. seanMay 9, 2006
  33. Junio C HamanoMay 9, 2006
  34. Linus TorvaldsMay 9, 2006
  35. Junio C HamanoMay 9, 2006
  36. Linus TorvaldsMay 9, 2006
  37. Junio C HamanoMay 9, 2006
  38. Linus TorvaldsMay 9, 2006
  39. seanMay 9, 2006
  40. Linus TorvaldsMay 9, 2006
  41. seanMay 9, 2006
  42. Linus TorvaldsMay 9, 2006
  43. Jakub NarebskiMay 9, 2006
  44. Johannes SchindelinMay 9, 2006
  45. Linus TorvaldsMay 9, 2006
  46. Junio C HamanoMay 9, 2006
  47. Linus TorvaldsMay 9, 2006
  48. seanMay 9, 2006
  49. seanMay 9, 2006
  50. Junio C HamanoMay 9, 2006
  51. seanMay 9, 2006
  52. Linus TorvaldsMay 10, 2006
  53. seanMay 10, 2006
  54. Linus TorvaldsMay 10, 2006
  55. Martin LanghoffMay 10, 2006
  56. Johannes SchindelinMay 10, 2006
  57. Linus TorvaldsMay 10, 2006
  58. Jakub NarebskiMay 10, 2006
  59. Martin LanghoffMay 10, 2006
  60. Linus TorvaldsMay 10, 2006
  61. Linus TorvaldsMay 11, 2006
  62. Jeff KingMay 11, 2006
  63. Jeff KingMay 11, 2006
  64. Martin LanghoffMay 11, 2006
  65. Johannes SchindelinMay 11, 2006
  66. Nicolas PitreMay 11, 2006
  67. Jakub NarebskiMay 11, 2006
  68. seanMay 10, 2006
  69. Junio C HamanoMay 11, 2006
  70. Martin WaitzMay 9, 2006
  71. Johannes SchindelinMay 9, 2006
  72. Johannes SchindelinMay 8, 2006
  73. Pavel RoskinMay 9, 2006
  74. seanMay 9, 2006
  75. Pavel RoskinMay 9, 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.