{"thread":{"id":"11773","subject":"[PATCH] config.c: Expand $HOME and tilde character in core.excludesfile","startedAt":"2008-01-28T21:49:05Z","lastAt":"2008-01-29T07:51:32Z","messageCount":7,"participants":["Jari Aalto","Johannes Schindelin","Jakub Narebski","Wayne Davison","Miles Bader","David Symonds"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"66760","messageId":"y7a9aaem.fsf@blue.sea.net","threadId":"11773","inReplyTo":null,"subject":"[PATCH] config.c: Expand $HOME and tilde character in core.excludesfile","fromName":"Jari Aalto","fromEmail":"jari.aalto@cante.net","sentAt":"2008-01-28T21:49:05Z","receivedAt":"2008-01-28T21:49:05Z","isPatch":true,"sender":{"key":"jari.aalto@cante.net","avatar":"https://avatars.githubusercontent.com/u/34601?v=4"},"body":"c* str_replace(): New function. Generic replace command.\n* str_replace_home(): New funtion. Substitute $HOME and tilde(~) in string.\n* git_default_config(): Pass core.excludesfile to str_replace_home().\n\nSigned-off-by: Jari Aalto <jari.aalto AT cante.net>\n---\n\n From ac6941f5055b2acdded59627d228bbf03ba0d9fc\n\n config.c |   44 +++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 43 insertions(+), 1 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex 526a3f4..7c91689 100644\n--- a/config.c\n+++ b/config.c\n@@ -309,6 +309,46 @@ int git_config_bool(const char *name, const char *value)\n \treturn git_config_int(name, value) != 0;\n }\n \n+char *str_replace(const char *str, const char *find, const char *replace)\n+{\n+        int maxlen   = strlen(str) + strlen(replace) + 1;\n+        char *start  = strstr(str, find);\n+        char *ptr    = (char *)malloc(maxlen);\n+        int len      = strlen(find);\n+        int llen, rlen;         /* left, right portion length */\n+\n+        if (start == (char *)NULL) {\n+                strcpy( ptr, str);\n+        }\n+        else{\n+                rlen = strlen(start) - strlen(find);\n+                llen = strlen(str) - strlen(start);\n+                strncpy( ptr, str, llen);\n+                strcat( ptr, replace);\n+                strncat( ptr, start + len, rlen); /* Does not add  '\\0' */\n+                strcat( ptr, \"\");   /* Terminate with null string */\n+        }\n+\n+        return ptr;\n+}\n+\n+char *str_replace_home(const char *str)\n+{\n+        char *ret  = xstrdup(str);\n+        char *home = getenv(\"HOME\");\n+\n+        if (home != (char *)NULL ) {\n+                if (strstr(str, \"~\") != NULL) {\n+                        ret = str_replace(str, \"~\", home);\n+                }\n+                else if (strstr(str, \"$HOME\") != NULL) {\n+                        ret = str_replace(str, \"$HOME\", home);\n+                }\n+        }\n+\n+        return ret;\n+}\n+\n int git_default_config(const char *var, const char *value)\n {\n \t/* This needs a better name */\n@@ -447,7 +487,9 @@ int git_default_config(const char *var, const char *value)\n \t\tif (!value)\n \t\t\tdie(\"core.excludesfile without value\");\n \t\texcludes_file = xstrdup(value);\n-\t\treturn 0;\n+                /* expand $HOME and tilde(~) */\n+                excludes_file = str_replace_home(excludes_file);\n+                return 0;\n \t}\n \n \tif (!strcmp(var, \"core.whitespace\")) {\n-- \n1.5.4-rc3.GIT\n"},{"id":"66762","messageId":"alpine.LSU.1.00.0801282225540.23907@racer.site","threadId":"11773","inReplyTo":"y7a9aaem.fsf@blue.sea.net","subject":"Re: [PATCH] config.c: Expand $HOME and tilde character in core.excludesfile","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-01-28T22:28:55Z","receivedAt":"2008-01-28T22:28:55Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 28 Jan 2008, Jari Aalto wrote:\n\n> c* str_replace(): New function. Generic replace command.\n> * str_replace_home(): New funtion. Substitute $HOME and tilde(~) in string.\n> * git_default_config(): Pass core.excludesfile to str_replace_home().\n\nI don't like it.  Not only do you fail to provide an example where this \ncould be useful, you also introduce a memory leak for every excludes \nsetting.\n\nBesides, there is a more fundamental reason to reject this patch: it sets \na path for an excludes file for everybody, but to a file which usually \ndoes not exist.\n\nSo either the user creates that file, in which case you can expect her to \nadjust ~/.gitconfig, too, or it is not created, in which case the setting \nin /etc/gitconfig is useless.\n\nThere is also a third option: there is a file created for every user from \n/etc/skel, but then there can also be a ~/.gitconfig.\n\nCiao,\nDscho\n"},{"id":"66763","messageId":"m3y7a98ttg.fsf@localhost.localdomain","threadId":"11773","inReplyTo":"y7a9aaem.fsf@blue.sea.net","subject":"Re: [PATCH] config.c: Expand $HOME and tilde character in core.excludesfile","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-01-28T22:32:51Z","receivedAt":"2008-01-28T22:32:51Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Jari Aalto <jari.aalto@cante.net> writes:\n\n> * str_replace(): New function. Generic replace command.\n> * str_replace_home(): New function. Substitute $HOME and tilde(~) in string.\n> * git_default_config(): Pass core.excludesfile to str_replace_home().\n> \n> Signed-off-by: Jari Aalto <jari.aalto AT cante.net>\n\nFirst, git project does NOT use GNU ChangeLog convention for it's\ncommit messages.  We rather use descriptive commit messages.\n\nSecond, I'm not sure about str_replace... how it fits with strbufs?\nAFAIK we try to use strbufs whenever possible and feasible, to avoid\nerrors in git.\n\nThird, I agree that it is a good idea, but I'd rather have *full*\nsolution, i.e. for git to expand $HOME (or better yet any\nenvironmental variable) and '~' everywhere, not only for\ncore.excludesfile, but also for --git-dir and GIT_DIR, for\ncore.worktree and --work-tree and GIT_WORK_TREE, and for all other\nconfig variables and enviroment variables.\n\n> ---\n> \n>  From ac6941f5055b2acdded59627d228bbf03ba0d9fc\n\nWhat does it mean? A bit cryptic, don't you think?\n\n\nComments on code below. One thing: we use tabs for indent, not\nspaces.  You use spaces in your code, while context uses tabs.\n\n> +char *str_replace(const char *str, const char *find, const char *replace)\n> +{\n> +        int maxlen   = strlen(str) + strlen(replace) + 1;\n> +        char *start  = strstr(str, find);\n> +        char *ptr    = (char *)malloc(maxlen);\n> +        int len      = strlen(find);\n> +        int llen, rlen;         /* left, right portion length */\n> +\n> +        if (start == (char *)NULL) {\n\nThere is no need to cast NULL. Besides, we write IIRC \"if (!start)\",\nit is common enough idiom.\n\n> +                strcpy( ptr, str);\n\nStyle: no space after opening parenthesis: \"strcpy(ptr, str)\".\nPerformance: I think it would be better to use stpcpy, although I'm\nnot quite sure if here too.\n\n> +        }\n> +        else{\n> +                rlen = strlen(start) - strlen(find);\n> +                llen = strlen(str) - strlen(start);\n> +                strncpy( ptr, str, llen);\n> +                strcat( ptr, replace);\n> +                strncat( ptr, start + len, rlen); /* Does not add  '\\0' */\n> +                strcat( ptr, \"\");   /* Terminate with null string */\n\nPerformance suck here; although this is not time-critical path using\nsequence of strcat is just bad style. And 'strcat( ptr, \"\");' just\ntakes the cake: use \"ptr[len] = '\\0'\", ehere 'len' is calculated\nlength of string.\n\nP.S. Junio, when do you think 1.5.4 would be finally released? We have\nfeature freeze still, isn't it?\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"66766","messageId":"20080128235205.GE8669@blorf.net","threadId":"11773","inReplyTo":"y7a9aaem.fsf@blue.sea.net","subject":"Re: [PATCH] config.c: Expand $HOME and tilde character in core.excludesfile","fromName":"Wayne Davison","fromEmail":"wayne@opencoder.net","sentAt":"2008-01-28T23:52:05Z","receivedAt":"2008-01-28T23:52:05Z","isPatch":true,"sender":{"key":"wayne@opencoder.net","avatar":"https://gravatar.com/avatar/d55d81825271b1bfe65e57e4e04297d4119aa03c6a1c71d2ff2812b9b4be9f45?d=mp&s=160"},"body":"On Mon, Jan 28, 2008 at 11:49:05PM +0200, Jari Aalto wrote:\n> +                        ret = str_replace(str, \"~\", home);\n\nThis would mangle a name with a tilde in it, e.g. \"file.c~\", etc.\n\n> +                        ret = str_replace(str, \"$HOME\", home);\n\nThis would affect similarly named vars, e.g. $HOMER, etc.\n\n> +                strcat( ptr, \"\");   /* Terminate with null string */\n\nCalling strcat() requires a null-terminated string.  Instead, assign a\n'\\0' char at the right position.\n\n..wayne..\n"},{"id":"66809","messageId":"buo7ihtcgtt.fsf@dhapc248.dev.necel.com","threadId":"11773","inReplyTo":"m3y7a98ttg.fsf@localhost.localdomain","subject":"Re: [PATCH] config.c: Expand $HOME and tilde character in core.excludesfile","fromName":"Miles Bader","fromEmail":"miles.bader@necel.com","sentAt":"2008-01-29T05:59:42Z","receivedAt":"2008-01-29T05:59:42Z","isPatch":true,"sender":{"key":"miles.bader@necel.com","avatar":"https://gravatar.com/avatar/be062d4050eb88e04229cbdb60f803e1bd647923a015996c2439e76f23e336a7?d=mp&s=160"},"body":"Jakub Narebski <jnareb@gmail.com> writes:\n> First, git project does NOT use GNU ChangeLog convention for it's\n> commit messages.  We rather use descriptive commit messages.\n\nNot that what Jari wrote had much resemblance to GNU ChangeLog format...\n\n-Miles\n\n-- \nOpposition, n. In politics the party that prevents the Goverment from running\namok by hamstringing it.\n"},{"id":"66817","messageId":"ee77f5c20801282325k3b2c888el7a2a97b78b799803@mail.gmail.com","threadId":"11773","inReplyTo":"buo7ihtcgtt.fsf@dhapc248.dev.necel.com","subject":"Re: [PATCH] config.c: Expand $HOME and tilde character in core.excludesfile","fromName":"David Symonds","fromEmail":"dsymonds@gmail.com","sentAt":"2008-01-29T07:25:08Z","receivedAt":"2008-01-29T07:25:08Z","isPatch":true,"sender":{"key":"dsymonds@gmail.com","avatar":"https://gravatar.com/avatar/b22f5051cbfc11836e36cf7a690e6cde4e225d835e13295ff98d15c7a9ee3c0f?d=mp&s=160"},"body":"On Jan 29, 2008 4:59 PM, Miles Bader <miles.bader@necel.com> wrote:\n> Jakub Narebski <jnareb@gmail.com> writes:\n> > First, git project does NOT use GNU ChangeLog convention for it's\n> > commit messages.  We rather use descriptive commit messages.\n>\n> Not that what Jari wrote had much resemblance to GNU ChangeLog format...\n\nWhat, like http://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html#Style-of-Change-Logs\n? It looked like GNU style to me.\n\n\nDave.\n"},{"id":"66820","messageId":"fc339e4a0801282351r2f592a58ya9fef377be684e3d@mail.gmail.com","threadId":"11773","inReplyTo":"ee77f5c20801282325k3b2c888el7a2a97b78b799803@mail.gmail.com","subject":"Re: [PATCH] config.c: Expand $HOME and tilde character in core.excludesfile","fromName":"Miles Bader","fromEmail":"miles@gnu.org","sentAt":"2008-01-29T07:51:32Z","receivedAt":"2008-01-29T07:51:32Z","isPatch":true,"sender":{"key":"miles@gnu.org","avatar":"https://gravatar.com/avatar/01069b69593af7bff28e2f97afeb3644ae6fe2f5f56cb3a8cf34c5fb8c36efe5?d=mp&s=160"},"body":"On Jan 29, 2008 4:25 PM, David Symonds <dsymonds@gmail.com> wrote:\n> > Not that what Jari wrote had much resemblance to GNU ChangeLog format...\n>\n> What, like http://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html#Style-of-Change-Logs\n> ? It looked like GNU style to me.\n\nNo, all the details are wrong.  Just about the only thing in common\nwith ChangeLog format is that he used asterisks as bullets, and a\ncolon to indicate the descriptive text -- but that's simply what\npeople tend to do when making an itemized list in ascii...\n\n-Miles\n\n-- \nDo not taunt Happy Fun Ball.\n"}]}