{"thread":{"id":"44981","subject":"PATCH 1/2] abspath: add absolute_pathdup()","startedAt":"2017-01-26T17:48:47Z","lastAt":"2017-01-27T18:20:26Z","messageCount":6,"participants":["René Scharfe","Brandon Williams","Johannes Schindelin","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"310332","messageId":"d94d742d-1247-ac35-c081-7db1f2178d34@web.de","threadId":"44981","inReplyTo":null,"subject":"PATCH 1/2] abspath: add absolute_pathdup()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-01-26T17:47:45Z","receivedAt":"2017-01-26T17:48:47Z","isPatch":false,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Add a function that returns a buffer containing the absolute path of its\nargument and a semantic patch for its intended use.  It avoids an extra\nstring copy to a static buffer.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n abspath.c                                | 7 +++++++\n cache.h                                  | 1 +\n contrib/coccinelle/xstrdup_or_null.cocci | 6 ++++++\n 3 files changed, 14 insertions(+)\n\ndiff --git a/abspath.c b/abspath.c\nindex fce40fddcc..2f0c26e0e2 100644\n--- a/abspath.c\n+++ b/abspath.c\n@@ -239,6 +239,13 @@ const char *absolute_path(const char *path)\n \treturn sb.buf;\n }\n \n+char *absolute_pathdup(const char *path)\n+{\n+\tstruct strbuf sb = STRBUF_INIT;\n+\tstrbuf_add_absolute_path(&sb, path);\n+\treturn strbuf_detach(&sb, NULL);\n+}\n+\n /*\n  * Unlike prefix_path, this should be used if the named file does\n  * not have to interact with index entry; i.e. name of a random file\ndiff --git a/cache.h b/cache.h\nindex 00a029af36..d7b7a8cd7a 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1069,6 +1069,7 @@ const char *real_path(const char *path);\n const char *real_path_if_valid(const char *path);\n char *real_pathdup(const char *path);\n const char *absolute_path(const char *path);\n+char *absolute_pathdup(const char *path);\n const char *remove_leading_path(const char *in, const char *prefix);\n const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);\n int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);\ndiff --git a/contrib/coccinelle/xstrdup_or_null.cocci b/contrib/coccinelle/xstrdup_or_null.cocci\nindex 3fceef132b..8e05d1ca4b 100644\n--- a/contrib/coccinelle/xstrdup_or_null.cocci\n+++ b/contrib/coccinelle/xstrdup_or_null.cocci\n@@ -5,3 +5,9 @@ expression V;\n - if (E)\n -    V = xstrdup(E);\n + V = xstrdup_or_null(E);\n+\n+@@\n+expression E;\n+@@\n+- xstrdup(absolute_path(E))\n++ absolute_pathdup(E)\n-- \n2.11.0\n\n"},{"id":"310333","messageId":"d15fdbb9-2a21-eeab-1fee-4a1553bd3bcb@web.de","threadId":"44981","inReplyTo":"d94d742d-1247-ac35-c081-7db1f2178d34@web.de","subject":"[PATCH 2/2] use absolute_pathdup()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-01-26T17:54:23Z","receivedAt":"2017-01-26T17:54:57Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Apply the symantic patch for converting callers that duplicate the\nresult of absolute_path() to call absolute_pathdup() instead, which\navoids an extra string copy to a static buffer.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n builtin/clone.c             | 4 ++--\n builtin/submodule--helper.c | 2 +-\n worktree.c                  | 2 +-\n 3 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 5ef81927a6..3f63edbbf9 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -170,7 +170,7 @@ static char *get_repo_path(const char *repo, int *is_bundle)\n \n \tstrbuf_addstr(&path, repo);\n \traw = get_repo_path_1(&path, is_bundle);\n-\tcanon = raw ? xstrdup(absolute_path(raw)) : NULL;\n+\tcanon = raw ? absolute_pathdup(raw) : NULL;\n \tstrbuf_release(&path);\n \treturn canon;\n }\n@@ -894,7 +894,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \n \tpath = get_repo_path(repo_name, &is_bundle);\n \tif (path)\n-\t\trepo = xstrdup(absolute_path(repo_name));\n+\t\trepo = absolute_pathdup(repo_name);\n \telse if (!strchr(repo_name, ':'))\n \t\tdie(_(\"repository '%s' does not exist\"), repo_name);\n \telse\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 74614a951e..899dc334e3 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -626,7 +626,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)\n \t\t\t\t   module_clone_options);\n \n \tstrbuf_addf(&sb, \"%s/modules/%s\", get_git_dir(), name);\n-\tsm_gitdir = xstrdup(absolute_path(sb.buf));\n+\tsm_gitdir = absolute_pathdup(sb.buf);\n \tstrbuf_reset(&sb);\n \n \tif (!is_absolute_path(path)) {\ndiff --git a/worktree.c b/worktree.c\nindex 53b4771c04..d633761575 100644\n--- a/worktree.c\n+++ b/worktree.c\n@@ -145,7 +145,7 @@ static struct worktree *get_linked_worktree(const char *id)\n \n static void mark_current_worktree(struct worktree **worktrees)\n {\n-\tchar *git_dir = xstrdup(absolute_path(get_git_dir()));\n+\tchar *git_dir = absolute_pathdup(get_git_dir());\n \tint i;\n \n \tfor (i = 0; worktrees[i]; i++) {\n-- \n2.11.0\n\n"},{"id":"310343","messageId":"20170126183229.GA3626@google.com","threadId":"44981","inReplyTo":"d94d742d-1247-ac35-c081-7db1f2178d34@web.de","subject":"Re: PATCH 1/2] abspath: add absolute_pathdup()","fromName":"Brandon Williams","fromEmail":"bmwill@google.com","sentAt":"2017-01-26T18:32:29Z","receivedAt":"2017-01-26T18:33:52Z","isPatch":false,"sender":{"key":"bwilliams.eng@gmail.com","avatar":null},"body":"On 01/26, René Scharfe wrote:\n> Add a function that returns a buffer containing the absolute path of its\n> argument and a semantic patch for its intended use.  It avoids an extra\n> string copy to a static buffer.\n> \n> Signed-off-by: Rene Scharfe <l.s.r@web.de>\n> ---\n>  abspath.c                                | 7 +++++++\n>  cache.h                                  | 1 +\n>  contrib/coccinelle/xstrdup_or_null.cocci | 6 ++++++\n>  3 files changed, 14 insertions(+)\n> \n> diff --git a/abspath.c b/abspath.c\n> index fce40fddcc..2f0c26e0e2 100644\n> --- a/abspath.c\n> +++ b/abspath.c\n> @@ -239,6 +239,13 @@ const char *absolute_path(const char *path)\n>  \treturn sb.buf;\n>  }\n>  \n> +char *absolute_pathdup(const char *path)\n> +{\n> +\tstruct strbuf sb = STRBUF_INIT;\n> +\tstrbuf_add_absolute_path(&sb, path);\n> +\treturn strbuf_detach(&sb, NULL);\n> +}\n> +\n>  /*\n>   * Unlike prefix_path, this should be used if the named file does\n>   * not have to interact with index entry; i.e. name of a random file\n> diff --git a/cache.h b/cache.h\n> index 00a029af36..d7b7a8cd7a 100644\n> --- a/cache.h\n> +++ b/cache.h\n> @@ -1069,6 +1069,7 @@ const char *real_path(const char *path);\n>  const char *real_path_if_valid(const char *path);\n>  char *real_pathdup(const char *path);\n>  const char *absolute_path(const char *path);\n> +char *absolute_pathdup(const char *path);\n>  const char *remove_leading_path(const char *in, const char *prefix);\n>  const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);\n>  int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);\n> diff --git a/contrib/coccinelle/xstrdup_or_null.cocci b/contrib/coccinelle/xstrdup_or_null.cocci\n> index 3fceef132b..8e05d1ca4b 100644\n> --- a/contrib/coccinelle/xstrdup_or_null.cocci\n> +++ b/contrib/coccinelle/xstrdup_or_null.cocci\n> @@ -5,3 +5,9 @@ expression V;\n>  - if (E)\n>  -    V = xstrdup(E);\n>  + V = xstrdup_or_null(E);\n> +\n> +@@\n> +expression E;\n> +@@\n> +- xstrdup(absolute_path(E))\n> ++ absolute_pathdup(E)\n> -- \n> 2.11.0\n> \n\nThese two patches look good to me.\n\n-- \nBrandon Williams\n"},{"id":"310389","messageId":"alpine.DEB.2.20.1701271121120.3469@virtualbox","threadId":"44981","inReplyTo":"d15fdbb9-2a21-eeab-1fee-4a1553bd3bcb@web.de","subject":"Re: [PATCH 2/2] use absolute_pathdup()","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2017-01-27T10:21:41Z","receivedAt":"2017-01-27T10:22:05Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi René,\n\nOn Thu, 26 Jan 2017, René Scharfe wrote:\n\n> Apply the symantic patch for converting callers that duplicate the\n\ns/symantic/semantic/\n\nCiao,\nDscho"},{"id":"310409","messageId":"0555c0aa-fcb4-19fb-a533-c451e1e477e3@web.de","threadId":"44981","inReplyTo":"alpine.DEB.2.20.1701271121120.3469@virtualbox","subject":"Re: [PATCH 2/2] use absolute_pathdup()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-01-27T15:39:39Z","receivedAt":"2017-01-27T15:47:08Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Hi Dscho,\n\nAm 27.01.2017 um 11:21 schrieb Johannes Schindelin:\n> On Thu, 26 Jan 2017, René Scharfe wrote:\n>> Apply the symantic patch for converting callers that duplicate the\n>\n> s/symantic/semantic/\n\nthank you!  I wonder where this came from.  And where my spellchecker \nwent without as much as a farewell.  Reinstalled it now..\n\nRené\n"},{"id":"310425","messageId":"xmqqlgtwz7r6.fsf@gitster.mtv.corp.google.com","threadId":"44981","inReplyTo":"0555c0aa-fcb4-19fb-a533-c451e1e477e3@web.de","subject":"Re: [PATCH 2/2] use absolute_pathdup()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-01-27T18:18:37Z","receivedAt":"2017-01-27T18:20:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"René Scharfe <l.s.r@web.de> writes:\n\n> Hi Dscho,\n>\n> Am 27.01.2017 um 11:21 schrieb Johannes Schindelin:\n>> On Thu, 26 Jan 2017, René Scharfe wrote:\n>>> Apply the symantic patch for converting callers that duplicate the\n>>\n>> s/symantic/semantic/\n>\n> thank you!  I wonder where this came from.  And where my spellchecker\n> went without as much as a farewell.  Reinstalled it now..\n>\n> René\n\nThanks.  I've already locally amended this.\n"}]}