list mirror (unofficial, one of many)
 help / color / mirror / Atom feed
From: Jeff King <>
Subject: [PATCH 5/6] prefix_filename: simplify windows #ifdef
Date: Mon, 20 Mar 2017 21:30:41 -0400
Message-ID: <> (raw)
In-Reply-To: <>

The prefix_filename function used to do an early return when
there was no prefix on non-Windows platforms, but always
allocated on Windows so that it could call convert_slashes().

Now that the function always allocates, we can unify the
logic and make convert_slashes() the only conditional part.

Signed-off-by: Jeff King <>
I wondered here if a compiler might complain about the dead assignment
to pfx_len in the is_absolute_path() conditional. On Windows, that's
used as an offset for calling into convert_slashes(), but on other
platforms we never look at it again.

However, neither gcc nor clang complained, so I'm inclined to go with
what I have here.

 abspath.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/abspath.c b/abspath.c
index 4addd1fde..7f1cfe979 100644
--- a/abspath.c
+++ b/abspath.c
@@ -251,18 +251,15 @@ char *prefix_filename(const char *pfx, const char *arg)
 	struct strbuf path = STRBUF_INIT;
 	size_t pfx_len = pfx ? strlen(pfx) : 0;
-	if (!pfx_len || is_absolute_path(arg))
-		return xstrdup(arg);
-	strbuf_add(&path, pfx, pfx_len);
-	strbuf_addstr(&path, arg);
-	/* don't add prefix to absolute paths, but still replace '\' by '/' */
-	if (is_absolute_path(arg))
+	if (!pfx_len)
+		; /* nothing to prefix */
+	else if (is_absolute_path(arg))
 		pfx_len = 0;
-	else if (pfx_len)
+	else
 		strbuf_add(&path, pfx, pfx_len);
 	strbuf_addstr(&path, arg);
 	convert_slashes(path.buf + pfx_len);
 	return strbuf_detach(&path, NULL);

  parent reply	other threads:[~2017-03-21  1:32 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-21  1:18 [PATCH 0/6] prefix_filename cleanups Jeff King
2017-03-21  1:20 ` [PATCH 1/6] hash-object: fix buffer reuse with --path in a subdirectory Jeff King
2017-03-21  1:21 ` [PATCH 2/6] prefix_filename: move docstring to header file Jeff King
2017-03-21  1:22 ` [PATCH 3/6] prefix_filename: drop length parameter Jeff King
2017-03-21  1:28 ` [PATCH 4/6] prefix_filename: return newly allocated string Jeff King
2017-03-21 18:14   ` Junio C Hamano
2017-03-21 18:23     ` Jeff King
2017-03-21 23:32       ` Jeff King
2017-03-21  1:30 ` Jeff King [this message]
2017-03-21  1:31 ` [PATCH 6/6] bundle: use prefix_filename with bundle path Jeff King
2017-03-21 17:53 ` [PATCH 0/6] prefix_filename cleanups 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:

  List information:

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

  git send-email \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ \
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
 note: .onion URLs require Tor:

code repositories for the project(s) associated with this inbox:

AGPL code for this site: git clone