All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] exec_cmd.c: use find_last_dir_sep() for code simplification
@ 2016-02-19  8:44 Alexander Kuleshov
  2016-02-19 21:28 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Kuleshov @ 2016-02-19  8:44 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git @ vger . kernel . org, Alexander Kuleshov

We are trying to extract dirname from argv0 in the git_extract_argv0_path().
But in the same time, the <git-compat-util.h> provides find_last_dir_sep()
to get dirname from a given path.  Let's use it instead of loop for the code
simplification.

Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
---
 exec_cmd.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/exec_cmd.c b/exec_cmd.c
index e85f0fd..680b257 100644
--- a/exec_cmd.c
+++ b/exec_cmd.c
@@ -43,12 +43,10 @@ const char *git_extract_argv0_path(const char *argv0)
 
 	if (!argv0 || !*argv0)
 		return NULL;
-	slash = argv0 + strlen(argv0);
 
-	while (argv0 <= slash && !is_dir_sep(*slash))
-		slash--;
+	slash = find_last_dir_sep(argv0);
 
-	if (slash >= argv0) {
+	if (slash) {
 		argv0_path = xstrndup(argv0, slash - argv0);
 		return slash + 1;
 	}
-- 
2.4.4.764.g5dbb725.dirty

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] exec_cmd.c: use find_last_dir_sep() for code simplification
  2016-02-19  8:44 [PATCH] exec_cmd.c: use find_last_dir_sep() for code simplification Alexander Kuleshov
@ 2016-02-19 21:28 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2016-02-19 21:28 UTC (permalink / raw)
  To: Alexander Kuleshov; +Cc: git @ vger . kernel . org

Alexander Kuleshov <kuleshovmail@gmail.com> writes:

> We are trying to extract dirname from argv0 in the git_extract_argv0_path().
> But in the same time, the <git-compat-util.h> provides find_last_dir_sep()
> to get dirname from a given path.  Let's use it instead of loop for the code
> simplification.
>
> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
> ---

Looks correct.  Thanks.

>  exec_cmd.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/exec_cmd.c b/exec_cmd.c
> index e85f0fd..680b257 100644
> --- a/exec_cmd.c
> +++ b/exec_cmd.c
> @@ -43,12 +43,10 @@ const char *git_extract_argv0_path(const char *argv0)
>  
>  	if (!argv0 || !*argv0)
>  		return NULL;
> -	slash = argv0 + strlen(argv0);
>  
> -	while (argv0 <= slash && !is_dir_sep(*slash))
> -		slash--;
> +	slash = find_last_dir_sep(argv0);
>  
> -	if (slash >= argv0) {
> +	if (slash) {
>  		argv0_path = xstrndup(argv0, slash - argv0);
>  		return slash + 1;
>  	}

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-19 21:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-19  8:44 [PATCH] exec_cmd.c: use find_last_dir_sep() for code simplification Alexander Kuleshov
2016-02-19 21:28 ` Junio C Hamano

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.