{"thread":{"id":"10210","subject":"[PATCH] git-config: handle --file option with relative pathname properly","startedAt":"2007-10-09T12:49:32Z","lastAt":"2007-10-12T12:08:57Z","messageCount":5,"participants":["Gerrit Pape","Johannes Schindelin","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"55264","messageId":"20071009124932.1184.qmail@395d4a80f3eafd.315fe32.mid.smarden.org","threadId":"10210","inReplyTo":null,"subject":"[PATCH] git-config: handle --file option with relative pathname properly","fromName":"Gerrit Pape","fromEmail":"pape@smarden.org","sentAt":"2007-10-09T12:49:32Z","receivedAt":"2007-10-09T12:49:32Z","isPatch":true,"sender":{"key":"pape@smarden.org","avatar":"https://avatars.githubusercontent.com/u/143170252?v=4"},"body":"When calling git-config not from the top level directory of a repository,\nit changes directory before trying to open the config file specified\nthrough the --file option, which then fails if the config file was\nspecified by a relative pathname.  This patch adjusts the pathname to\nthe config file if applicable.\n\nThe problem was noticed by Joey Hess, reported through\n http://bugs.debian.org/445208\n\nSigned-off-by: Gerrit Pape <pape@smarden.org>\n---\n builtin-config.c |    8 ++++++--\n 1 files changed, 6 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 0a605e0..c2708ba 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -165,7 +165,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n {\n \tint nongit = 0;\n \tchar* value;\n-\tsetup_git_directory_gently(&nongit);\n+\tconst char *name = setup_git_directory_gently(&nongit);\n \n \twhile (1 < argc) {\n \t\tif (!strcmp(argv[1], \"--int\"))\n@@ -189,7 +189,11 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\telse if (!strcmp(argv[1], \"--file\") || !strcmp(argv[1], \"-f\")) {\n \t\t\tif (argc < 3)\n \t\t\t\tusage(git_config_set_usage);\n-\t\t\tsetenv(CONFIG_ENVIRONMENT, argv[2], 1);\n+\t\t\tif (argv[2][0] == '/')\n+\t\t\t\tname = argv[2];\n+\t\t\telse\n+\t\t\t\tname = name ? prefix_filename(name, strlen(name), argv[2]) : argv[2];\n+\t\t\tsetenv(CONFIG_ENVIRONMENT, name, 1);\n \t\t\targc--;\n \t\t\targv++;\n \t\t}\n-- \n1.5.3.4\n"},{"id":"55275","messageId":"Pine.LNX.4.64.0710091413500.4174@racer.site","threadId":"10210","inReplyTo":"20071009124932.1184.qmail@395d4a80f3eafd.315fe32.mid.smarden.org","subject":"Re: [PATCH] git-config: handle --file option with relative pathname properly","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-10-09T13:14:33Z","receivedAt":"2007-10-09T13:14:33Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 9 Oct 2007, Gerrit Pape wrote:\n\n> @@ -189,7 +189,11 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n>  \t\telse if (!strcmp(argv[1], \"--file\") || !strcmp(argv[1], \"-f\")) {\n>  \t\t\tif (argc < 3)\n>  \t\t\t\tusage(git_config_set_usage);\n> -\t\t\tsetenv(CONFIG_ENVIRONMENT, argv[2], 1);\n> +\t\t\tif (argv[2][0] == '/')\n\nPlease use is_absolute_path() instead.\n\nCiao,\nDscho\n"},{"id":"55279","messageId":"470B8024.2050106@viscovery.net","threadId":"10210","inReplyTo":"20071009124932.1184.qmail@395d4a80f3eafd.315fe32.mid.smarden.org","subject":"Re: [PATCH] git-config: handle --file option with relative pathname properly","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2007-10-09T13:20:36Z","receivedAt":"2007-10-09T13:20:36Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Gerrit Pape schrieb:\n> @@ -189,7 +189,11 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n>  \t\telse if (!strcmp(argv[1], \"--file\") || !strcmp(argv[1], \"-f\")) {\n>  \t\t\tif (argc < 3)\n>  \t\t\t\tusage(git_config_set_usage);\n> -\t\t\tsetenv(CONFIG_ENVIRONMENT, argv[2], 1);\n> +\t\t\tif (argv[2][0] == '/')\n\nPlease use is_absolute_path() here.\n\n> +\t\t\t\tname = argv[2];\n> +\t\t\telse\n> +\t\t\t\tname = name ? prefix_filename(name, strlen(name), argv[2]) : argv[2];\n\nCan't you avoid this ternary here? There's already an 'if' with the same \n'else' branch.\n\n> +\t\t\tsetenv(CONFIG_ENVIRONMENT, name, 1);\n>  \t\t\targc--;\n>  \t\t\targv++;\n>  \t\t}\n\n-- Hannes\n"},{"id":"55545","messageId":"20071012113251.29941.qmail@7584201f340355.315fe32.mid.smarden.org","threadId":"10210","inReplyTo":"470B8024.2050106@viscovery.net","subject":"[PATCH amend] git-config: handle --file option with relative pathname properly","fromName":"Gerrit Pape","fromEmail":"pape@smarden.org","sentAt":"2007-10-12T11:32:51Z","receivedAt":"2007-10-12T11:32:51Z","isPatch":true,"sender":{"key":"pape@smarden.org","avatar":"https://avatars.githubusercontent.com/u/143170252?v=4"},"body":"When calling git-config not from the top level directory of a repository,\nit changes directory before trying to open the config file specified\nthrough the --file option, which then fails if the config file was\nspecified by a relative pathname.  This patch adjusts the pathname to\nthe config file if applicable.\n\nThe problem was noticed by Joey Hess, reported through\n http://bugs.debian.org/445208\n\nSigned-off-by: Gerrit Pape <pape@smarden.org>\n---\n\nOn Tue, Oct 09, 2007 at 03:20:36PM +0200, Johannes Sixt wrote:\n> Gerrit Pape schrieb:\n> >-                    setenv(CONFIG_ENVIRONMENT, argv[2], 1);\n> >+                    if (argv[2][0] == '/')\n>\n> Please use is_absolute_path() here.\n\nOkay.\n\n> >+                            name = argv[2];\n> >+                    else\n> >+                            name = name ? prefix_filename(name,\n> >strlen(name), argv[2]) : argv[2];\n>\n> Can't you avoid this ternary here? There's already an 'if' with the same\n> 'else' branch.\n\nSure, thanks, Gerrit.\n\n builtin-config.c |    9 +++++++--\n 1 files changed, 7 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 0a605e0..4444d52 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -165,7 +165,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n {\n \tint nongit = 0;\n \tchar* value;\n-\tsetup_git_directory_gently(&nongit);\n+\tconst char *file = setup_git_directory_gently(&nongit);\n \n \twhile (1 < argc) {\n \t\tif (!strcmp(argv[1], \"--int\"))\n@@ -189,7 +189,12 @@ int cmd_config(int argc, const char **argv, const char *prefix)\n \t\telse if (!strcmp(argv[1], \"--file\") || !strcmp(argv[1], \"-f\")) {\n \t\t\tif (argc < 3)\n \t\t\t\tusage(git_config_set_usage);\n-\t\t\tsetenv(CONFIG_ENVIRONMENT, argv[2], 1);\n+\t\t\tif (!is_absolute_path(argv[2]) && file)\n+\t\t\t\tfile = prefix_filename(file, strlen(file),\n+\t\t\t\t\t\t       argv[2]);\n+\t\t\telse\n+\t\t\t\tfile = argv[2];\n+\t\t\tsetenv(CONFIG_ENVIRONMENT, file, 1);\n \t\t\targc--;\n \t\t\targv++;\n \t\t}\n-- \n1.5.3.4\n"},{"id":"55552","messageId":"Pine.LNX.4.64.0710121308040.25221@racer.site","threadId":"10210","inReplyTo":"20071012113251.29941.qmail@7584201f340355.315fe32.mid.smarden.org","subject":"Re: [PATCH amend] git-config: handle --file option with relative pathname properly","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-10-12T12:08:57Z","receivedAt":"2007-10-12T12:08:57Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Fri, 12 Oct 2007, Gerrit Pape wrote:\n\n> -\tsetup_git_directory_gently(&nongit);\n> +\tconst char *file = setup_git_directory_gently(&nongit);\n\nOne last nit (because I did not see it earlier): please call the variable \n\"prefix\", not \"file\".\n\nOther than that, I think your patch is obviously correct.\n\nThanks,\nDscho\n"}]}