{"thread":{"id":"13491","subject":"[user confusion] git-config error messages","startedAt":"2008-05-12T14:16:37Z","lastAt":"2008-05-12T22:10:13Z","messageCount":3,"participants":["Ingo Molnar","Alex Riesen","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"76709","messageId":"20080512141636.GA29590@elte.hu","threadId":"13491","inReplyTo":null,"subject":"[user confusion] git-config error messages","fromName":"Ingo Molnar","fromEmail":"mingo@elte.hu","sentAt":"2008-05-12T14:16:37Z","receivedAt":"2008-05-12T14:16:37Z","isPatch":false,"sender":{"key":"mingo@elte.hu","avatar":null},"body":"\nok, i thought i'd share this stupid little episode of user error.\nI wanted to enable git-rerere:\n\n $ git-config --add rerere.enabled true\n could not lock config file\n\n #\n # Hm, do remember this option incorrectly? And what lock file?\n #\n\n $ git-config --add rerere.enabled=1\n key does not contain a section: --add\n\n #\n # What section? What key?\n #\n\n $ git-config --add rerere.enabled=true\n key does not contain a section: --add\n\n #\n # Huh? Ok, lets try strace:\n #\n\n $ strace -f git-config --add rerere.enabled true 2>&1 | grep \\\\.lock\n open(\".git/config.lock\", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0666) = -1 ENOENT (No such file or directory)\n\n #\n # Ah, stupid me! I forgot to cd into the Git repository and it tries to \n # access .git. And i wanted the --global option anyway. So the Git \n # error messages led me on the completely wrong path.\n #\n"},{"id":"76798","messageId":"20080512214104.GA12294@steel.home","threadId":"13491","inReplyTo":"20080512141636.GA29590@elte.hu","subject":"[PATCH] Improve reporting of errors in config file routines","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2008-05-12T21:41:04Z","receivedAt":"2008-05-12T21:41:04Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Signed-off-by: Alex Riesen <raa.lkml@gmail.com>\n---\n\nIngo Molnar, Mon, May 12, 2008 16:16:37 +0200:\n>  #\n>  # Ah, stupid me! I forgot to cd into the Git repository and it tries to \n>  # access .git. And i wanted the --global option anyway. So the Git \n>  # error messages led me on the completely wrong path.\n>  #\n\nI hope this can improve situation a little. I have this patch in my\ntree for quite a while, but never came around to send it.\nIngo's report reminded me about it.\n\n config.c |   35 ++++++++++++++++-------------------\n 1 files changed, 16 insertions(+), 19 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex 4d00ebc..0e22c7a 100644\n--- a/config.c\n+++ b/config.c\n@@ -627,11 +627,9 @@ static int store_aux(const char* key, const char* value)\n \tcase KEY_SEEN:\n \t\tif (matches(key, value)) {\n \t\t\tif (store.seen == 1 && store.multi_replace == 0) {\n-\t\t\t\tfprintf(stderr,\n-\t\t\t\t\t\"Warning: %s has multiple values\\n\",\n-\t\t\t\t\tkey);\n+\t\t\t\twarning(\"%s has multiple values\", key);\n \t\t\t} else if (store.seen >= MAX_MATCHES) {\n-\t\t\t\tfprintf(stderr, \"Too many matches\\n\");\n+\t\t\t\terror(\"too many matches for %s\", key);\n \t\t\t\treturn 1;\n \t\t\t}\n \n@@ -681,9 +679,9 @@ static int store_aux(const char* key, const char* value)\n \treturn 0;\n }\n \n-static int write_error(void)\n+static int write_error(const char *filename)\n {\n-\tfprintf(stderr, \"Failed to write new configuration file\\n\");\n+\terror(\"failed to write new configuration file %s\", filename);\n \n \t/* Same error code as \"failed to rename\". */\n \treturn 4;\n@@ -842,7 +840,7 @@ int git_config_set_multivar(const char* key, const char* value,\n \t */\n \n \tif (last_dot == NULL) {\n-\t\tfprintf(stderr, \"key does not contain a section: %s\\n\", key);\n+\t\terror(\"key does not contain a section: %s\", key);\n \t\tret = 2;\n \t\tgoto out_free;\n \t}\n@@ -862,14 +860,14 @@ int git_config_set_multivar(const char* key, const char* value,\n \t\t/* Leave the extended basename untouched.. */\n \t\tif (!dot || i > store.baselen) {\n \t\t\tif (!iskeychar(c) || (i == store.baselen+1 && !isalpha(c))) {\n-\t\t\t\tfprintf(stderr, \"invalid key: %s\\n\", key);\n+\t\t\t\terror(\"invalid key: %s\", key);\n \t\t\t\tfree(store.key);\n \t\t\t\tret = 1;\n \t\t\t\tgoto out_free;\n \t\t\t}\n \t\t\tc = tolower(c);\n \t\t} else if (c == '\\n') {\n-\t\t\tfprintf(stderr, \"invalid key (newline): %s\\n\", key);\n+\t\t\terror(\"invalid key (newline): %s\", key);\n \t\t\tfree(store.key);\n \t\t\tret = 1;\n \t\t\tgoto out_free;\n@@ -885,7 +883,7 @@ int git_config_set_multivar(const char* key, const char* value,\n \tlock = xcalloc(sizeof(struct lock_file), 1);\n \tfd = hold_lock_file_for_update(lock, config_filename, 0);\n \tif (fd < 0) {\n-\t\tfprintf(stderr, \"could not lock config file\\n\");\n+\t\terror(\"could not lock config file %s\", config_filename);\n \t\tfree(store.key);\n \t\tret = -1;\n \t\tgoto out_free;\n@@ -932,8 +930,7 @@ int git_config_set_multivar(const char* key, const char* value,\n \t\t\tstore.value_regex = (regex_t*)xmalloc(sizeof(regex_t));\n \t\t\tif (regcomp(store.value_regex, value_regex,\n \t\t\t\t\tREG_EXTENDED)) {\n-\t\t\t\tfprintf(stderr, \"Invalid pattern: %s\\n\",\n-\t\t\t\t\tvalue_regex);\n+\t\t\t\terror(\"invalid pattern: %s\", value_regex);\n \t\t\t\tfree(store.value_regex);\n \t\t\t\tret = 6;\n \t\t\t\tgoto out_free;\n@@ -951,7 +948,7 @@ int git_config_set_multivar(const char* key, const char* value,\n \t\t * existing config file.\n \t\t */\n \t\tif (git_config_from_file(store_aux, config_filename)) {\n-\t\t\tfprintf(stderr, \"invalid config file\\n\");\n+\t\t\terror(\"invalid config file %s\", config_filename);\n \t\t\tfree(store.key);\n \t\t\tif (store.value_regex != NULL) {\n \t\t\t\tregfree(store.value_regex);\n@@ -1030,7 +1027,7 @@ int git_config_set_multivar(const char* key, const char* value,\n \t}\n \n \tif (commit_lock_file(lock) < 0) {\n-\t\tfprintf(stderr, \"Cannot commit config file!\\n\");\n+\t\terror(\"could not commit config file %s\", config_filename);\n \t\tret = 4;\n \t\tgoto out_free;\n \t}\n@@ -1051,7 +1048,7 @@ out_free:\n \treturn ret;\n \n write_err_out:\n-\tret = write_error();\n+\tret = write_error(lock->filename);\n \tgoto out_free;\n \n }\n@@ -1101,7 +1098,7 @@ int git_config_rename_section(const char *old_name, const char *new_name)\n \tconfig_filename = xstrdup(config_filename);\n \tout_fd = hold_lock_file_for_update(lock, config_filename, 0);\n \tif (out_fd < 0) {\n-\t\tret = error(\"Could not lock config file!\");\n+\t\tret = error(\"could not lock config file %s\", config_filename);\n \t\tgoto out;\n \t}\n \n@@ -1125,7 +1122,7 @@ int git_config_rename_section(const char *old_name, const char *new_name)\n \t\t\t\t}\n \t\t\t\tstore.baselen = strlen(new_name);\n \t\t\t\tif (!store_write_section(out_fd, new_name)) {\n-\t\t\t\t\tret = write_error();\n+\t\t\t\t\tret = write_error(lock->filename);\n \t\t\t\t\tgoto out;\n \t\t\t\t}\n \t\t\t\tcontinue;\n@@ -1136,14 +1133,14 @@ int git_config_rename_section(const char *old_name, const char *new_name)\n \t\t\tcontinue;\n \t\tlength = strlen(buf);\n \t\tif (write_in_full(out_fd, buf, length) != length) {\n-\t\t\tret = write_error();\n+\t\t\tret = write_error(lock->filename);\n \t\t\tgoto out;\n \t\t}\n \t}\n \tfclose(config_file);\n  unlock_and_out:\n \tif (commit_lock_file(lock) < 0)\n-\t\t\tret = error(\"Cannot commit config file!\");\n+\t\tret = error(\"could not commit config file %s\", config_filename);\n  out:\n \tfree(config_filename);\n \treturn ret;\n-- \n1.5.5.1.242.gf371f\n"},{"id":"76801","messageId":"7vmymvxjga.fsf@gitster.siamese.dyndns.org","threadId":"13491","inReplyTo":"20080512214104.GA12294@steel.home","subject":"Re: [PATCH] Improve reporting of errors in config file routines","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-05-12T22:10:13Z","receivedAt":"2008-05-12T22:10:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Looks good, thanks.\n"}]}