git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Kuleshov <kuleshovmail@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: "git @ vger . kernel . org" <git@vger.kernel.org>,
	Alexander Kuleshov <kuleshovmail@gmail.com>
Subject: [PATCH] exec_cmd.c: use find_last_dir_sep() for code simplification
Date: Fri, 19 Feb 2016 14:44:48 +0600	[thread overview]
Message-ID: <1455871488-10460-1-git-send-email-kuleshovmail@gmail.com> (raw)

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

             reply	other threads:[~2016-02-19  8:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-19  8:44 Alexander Kuleshov [this message]
2016-02-19 21:28 ` [PATCH] exec_cmd.c: use find_last_dir_sep() for code simplification Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1455871488-10460-1-git-send-email-kuleshovmail@gmail.com \
    --to=kuleshovmail@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).