git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] exec_cmd.c: use find_last_dir_sep() for code simplification

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 19, 2016, 21:28 UTC
Message-ID
<xmqqlh6gbdao.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<1455871488-10460-1-git-send-email-kuleshovmail@gmail.com>
Alexander Kuleshov <kuleshovmail@gmail.com> writes:
Show 7 quoted lines
> 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.
Show 22 quoted lines
>  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;
>  	}
Previous: Alexander Kuleshov
Message 2 of 2 in “exec_cmd.c: use find_last_dir_sep() for code simplification”
  1. exec_cmd.c: use find_last_dir_sep() for code simplificationAlexander Kuleshov, Feb 19, 2016
  2. Junio C HamanoFeb 19, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.