{"thread":{"id":"41444","subject":"[PATCH] exec_cmd.c: use find_last_dir_sep() for code simplification","startedAt":"2016-02-19T08:44:48Z","lastAt":"2016-02-19T21:28:15Z","messageCount":2,"participants":["Alexander Kuleshov","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"278622","messageId":"1455871488-10460-1-git-send-email-kuleshovmail@gmail.com","threadId":"41444","inReplyTo":null,"subject":"[PATCH] exec_cmd.c: use find_last_dir_sep() for code simplification","fromName":"Alexander Kuleshov","fromEmail":"kuleshovmail@gmail.com","sentAt":"2016-02-19T08:44:48Z","receivedAt":"2016-02-19T08:44:48Z","isPatch":true,"sender":{"key":"kuleshovmail@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2699235?v=4"},"body":"We are trying to extract dirname from argv0 in the git_extract_argv0_path().\nBut in the same time, the <git-compat-util.h> provides find_last_dir_sep()\nto get dirname from a given path.  Let's use it instead of loop for the code\nsimplification.\n\nSigned-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n---\n exec_cmd.c | 6 ++----\n 1 file changed, 2 insertions(+), 4 deletions(-)\n\ndiff --git a/exec_cmd.c b/exec_cmd.c\nindex e85f0fd..680b257 100644\n--- a/exec_cmd.c\n+++ b/exec_cmd.c\n@@ -43,12 +43,10 @@ const char *git_extract_argv0_path(const char *argv0)\n \n \tif (!argv0 || !*argv0)\n \t\treturn NULL;\n-\tslash = argv0 + strlen(argv0);\n \n-\twhile (argv0 <= slash && !is_dir_sep(*slash))\n-\t\tslash--;\n+\tslash = find_last_dir_sep(argv0);\n \n-\tif (slash >= argv0) {\n+\tif (slash) {\n \t\targv0_path = xstrndup(argv0, slash - argv0);\n \t\treturn slash + 1;\n \t}\n-- \n2.4.4.764.g5dbb725.dirty\n"},{"id":"278704","messageId":"xmqqlh6gbdao.fsf@gitster.mtv.corp.google.com","threadId":"41444","inReplyTo":"1455871488-10460-1-git-send-email-kuleshovmail@gmail.com","subject":"Re: [PATCH] exec_cmd.c: use find_last_dir_sep() for code simplification","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-02-19T21:28:15Z","receivedAt":"2016-02-19T21:28:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexander Kuleshov <kuleshovmail@gmail.com> writes:\n\n> We are trying to extract dirname from argv0 in the git_extract_argv0_path().\n> But in the same time, the <git-compat-util.h> provides find_last_dir_sep()\n> to get dirname from a given path.  Let's use it instead of loop for the code\n> simplification.\n>\n> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n> ---\n\nLooks correct.  Thanks.\n\n>  exec_cmd.c | 6 ++----\n>  1 file changed, 2 insertions(+), 4 deletions(-)\n>\n> diff --git a/exec_cmd.c b/exec_cmd.c\n> index e85f0fd..680b257 100644\n> --- a/exec_cmd.c\n> +++ b/exec_cmd.c\n> @@ -43,12 +43,10 @@ const char *git_extract_argv0_path(const char *argv0)\n>  \n>  \tif (!argv0 || !*argv0)\n>  \t\treturn NULL;\n> -\tslash = argv0 + strlen(argv0);\n>  \n> -\twhile (argv0 <= slash && !is_dir_sep(*slash))\n> -\t\tslash--;\n> +\tslash = find_last_dir_sep(argv0);\n>  \n> -\tif (slash >= argv0) {\n> +\tif (slash) {\n>  \t\targv0_path = xstrndup(argv0, slash - argv0);\n>  \t\treturn slash + 1;\n>  \t}\n"}]}