{"thread":{"id":"8123","subject":"[BUG] git config gets confused","startedAt":"2007-05-12T23:52:31Z","lastAt":"2007-05-13T10:46:50Z","messageCount":3,"participants":["Frank Lichtenheld","Junio C Hamano","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"41985","messageId":"20070512235230.GE7184@planck.djpig.de","threadId":"8123","inReplyTo":null,"subject":"[BUG] git config gets confused","fromName":"Frank Lichtenheld","fromEmail":"frank@lichtenheld.de","sentAt":"2007-05-12T23:52:31Z","receivedAt":"2007-05-12T23:52:31Z","isPatch":false,"sender":{"key":"frank@lichtenheld.de","avatar":"https://gravatar.com/avatar/b9f1d4b120e138f157c9e480d0818197c474628923786adb98f30017cdb99c3c?d=mp&s=160"},"body":"While working on test cases for git-cvsserver, especially the config\nfile handling I noticed the following bug in git-config:\n\n$ git-config gitcvs.enabled true\n$ git-config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite\n$ git-config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite\n\nexpected result:\n\n[gitcvs]\n        enabled = true\n        dbname = %Ggitcvs2.%a.%m.sqlite\n[gitcvs \"ext\"]\n        dbname = %Ggitcvs1.%a.%m.sqlite\n\nactual result:\n\n[gitcvs]\n        enabled = true\n[gitcvs \"ext\"]\n        dbname = %Ggitcvs1.%a.%m.sqlite\n        dbname = %Ggitcvs2.%a.%m.sqlite\n\nGruesse,\n-- \nFrank Lichtenheld <frank@lichtenheld.de>\nwww: http://www.djpig.de/\n"},{"id":"41998","messageId":"7vtzuhtjj6.fsf@assigned-by-dhcp.cox.net","threadId":"8123","inReplyTo":"20070512235230.GE7184@planck.djpig.de","subject":"Re: [BUG] git config gets confused","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-05-13T04:49:33Z","receivedAt":"2007-05-13T04:49:33Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Frank Lichtenheld <frank@lichtenheld.de> writes:\n\n> While working on test cases for git-cvsserver, especially the config\n> file handling I noticed the following bug in git-config:\n>\n> $ git-config gitcvs.enabled true\n> $ git-config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite\n> $ git-config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite\n>\n> expected result:\n>\n> [gitcvs]\n>         enabled = true\n>         dbname = %Ggitcvs2.%a.%m.sqlite\n> [gitcvs \"ext\"]\n>         dbname = %Ggitcvs1.%a.%m.sqlite\n>\n> actual result:\n>\n> [gitcvs]\n>         enabled = true\n> [gitcvs \"ext\"]\n>         dbname = %Ggitcvs1.%a.%m.sqlite\n>         dbname = %Ggitcvs2.%a.%m.sqlite\n\nOh, boy.\n\nWhy am I not surprised by another bug in config writer?\n\nDscho, does this look good?\n\n-- >8 --\ngit-config: do not forget \"a.b.var\" already ends \"a.var\" section.\n\nEarlier code tried to be half-careful and knew the logic that\nseeing \"a.var\" after seeing \"a.b.var\" is a sign of the previous\n\"a.b.\" section has ended, but forgot it has to handle the other\nway.  Seeing \"a.b.var\" after seeing \"a.var\" is a sign that \"a.\"\nsection has ended, so a new \"a.var2\" variable should be added\nbefore the location \"a.b.var\" appears.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n config.c |   26 ++++++++++++++++++++++----\n 1 files changed, 22 insertions(+), 4 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex 70d1055..70e6e7e 100644\n--- a/config.c\n+++ b/config.c\n@@ -451,6 +451,9 @@ static int matches(const char* key, const char* value)\n \n static int store_aux(const char* key, const char* value)\n {\n+\tconst char *ep;\n+\tsize_t section_len;\n+\n \tswitch (store.state) {\n \tcase KEY_SEEN:\n \t\tif (matches(key, value)) {\n@@ -468,12 +471,27 @@ static int store_aux(const char* key, const char* value)\n \t\t}\n \t\tbreak;\n \tcase SECTION_SEEN:\n-\t\tif (strncmp(key, store.key, store.baselen+1)) {\n+\t\t/*\n+\t\t * What we are looking for is in store.key (both\n+\t\t * section and var), and its section part is baselen\n+\t\t * long.  We found key (again, both section and var).\n+\t\t * We would want to know if this key is in the same\n+\t\t * section as what we are looking for.\n+\t\t */\n+\t\tep = strrchr(key, '.');\n+\t\tsection_len = ep - key;\n+\n+\t\tif ((section_len != store.baselen) ||\n+\t\t    memcmp(key, store.key, section_len+1)) {\n \t\t\tstore.state = SECTION_END_SEEN;\n \t\t\tbreak;\n-\t\t} else\n-\t\t\t/* do not increment matches: this is no match */\n-\t\t\tstore.offset[store.seen] = ftell(config_file);\n+\t\t}\n+\n+\t\t/*\n+\t\t * Do not increment matches: this is no match, but we\n+\t\t * just made sure we are in the desired section.\n+\t\t */\n+\t\tstore.offset[store.seen] = ftell(config_file);\n \t\t/* fallthru */\n \tcase SECTION_END_SEEN:\n \tcase START:\n"},{"id":"42013","messageId":"Pine.LNX.4.64.0705131243020.6410@racer.site","threadId":"8123","inReplyTo":"7vtzuhtjj6.fsf@assigned-by-dhcp.cox.net","subject":"Re: [BUG] git config gets confused","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-05-13T10:46:50Z","receivedAt":"2007-05-13T10:46:50Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 12 May 2007, Junio C Hamano wrote:\n\n> Oh, boy.\n> \n> Why am I not surprised by another bug in config writer?\n> \n> Dscho, does this look good?\n\nYes, it does. This part of the config writer dates slightly prior to our \nallowing hierarchical section names, which explains this bug, methinks.\n\nCiao,\nDscho\n"}]}