From: Junio C Hamano <gitster@pobox.com>
To: <rsbecker@nexbridge.com>
Cc: <git@vger.kernel.org>
Subject: Re: [BUG] git 2.44.0-rc0 t0080.1 Breaks on NonStop x86 and ia64
Date: Sat, 10 Feb 2024 18:05:57 -0800 [thread overview]
Message-ID: <xmqqbk8nbvqy.fsf@gitster.g> (raw)
In-Reply-To: <000401da5c4c$fd4ad260$f7e07720$@nexbridge.com> (rsbecker@nexbridge.com's message of "Sat, 10 Feb 2024 13:14:24 -0500")
<rsbecker@nexbridge.com> writes:
> The diff appears to have failed because of an assumption of how paths are
> resolved during compilation. The assumption is that files remain partially
> qualified, which is not the case in all C compilers. This is c99. My
> experience with gcc is that it qualifies names differently than other
> compilers.
I just found this bit of gem in t/unit-tests/test-lib.c. I guess
Visual C falls into the same category as yours, while GCC and Clang
are from different camps?
The easiest way forward may be to build on top of it, perhaps like
so, to generalize the make_relative() to cover your case, too?
t/unit-tests/test-lib.c | 63 +++++++++++++++++++++++++++++++++++++------------
1 file changed, 48 insertions(+), 15 deletions(-)
diff --git c/t/unit-tests/test-lib.c w/t/unit-tests/test-lib.c
index 7bf9dfdb95..69dbe1bbc7 100644
--- c/t/unit-tests/test-lib.c
+++ w/t/unit-tests/test-lib.c
@@ -21,45 +21,78 @@ static struct {
.result = RESULT_NONE,
};
-#ifndef _MSC_VER
-#define make_relative(location) location
-#else
+#include "dir.h"
/*
* Visual C interpolates the absolute Windows path for `__FILE__`,
* but we want to see relative paths, as verified by t0080.
+ * There are other compilers that do the same, and are not for
+ * Windows.
*/
-#include "dir.h"
-
static const char *make_relative(const char *location)
{
static char prefix[] = __FILE__, buf[PATH_MAX], *p;
static size_t prefix_len;
+ static int need_bs_to_fs = -1;
- if (!prefix_len) {
+ /* one-time preparation */
+ if (need_bs_to_fs < 0) {
size_t len = strlen(prefix);
- const char *needle = "\\t\\unit-tests\\test-lib.c";
+ char needle[] = "t\\unit-tests\\test-lib.c";
size_t needle_len = strlen(needle);
- if (len < needle_len || strcmp(needle, prefix + len - needle_len))
+ if (len < needle_len)
+ die("unexpected prefix '%s'", prefix);
+
+ /*
+ * The path could be relative (t/unit-tests/test-lib.c)
+ * or full (/home/user/git/t/unit-tests/test-lib.c).
+ * Check the slash between "t" and "unit-tests".
+ */
+ prefix_len = len - needle_len;
+ if (prefix[prefix_len + 1] == '/') {
+ /* Oh, we're not Windows */
+ for (size_t i = 0; i < needle_len; i++)
+ if (needle[i] == '\\')
+ needle[i] = '/';
+ need_bs_to_fs = 0;
+ } else {
+ need_bs_to_fs = 1;
+ }
+
+ /*
+ * prefix_len == 0 if the compiler gives paths relative
+ * to the root of the working tree. Otherwise, we want
+ * to see that we did find the needle[] at a directory
+ * boundary.
+ */
+ if (fspathcmp(needle, prefix + prefix_len) ||
+ (prefix_len &&
+ prefix[prefix_len - 1] != '/' &&
+ prefix[prefix_len - 1] != '\\'))
die("unexpected suffix of '%s'", prefix);
- /* let it end in a directory separator */
- prefix_len = len - needle_len + 1;
}
+ /*
+ * If our compiler gives relative paths and we do not need
+ * to munge directory separator, we can return location as-is.
+ */
+ if (!prefix_len && !need_bs_to_fs)
+ return location;
+
/* Does it not start with the expected prefix? */
if (fspathncmp(location, prefix, prefix_len))
return location;
strlcpy(buf, location + prefix_len, sizeof(buf));
/* convert backslashes to forward slashes */
- for (p = buf; *p; p++)
- if (*p == '\\')
- *p = '/';
-
+ if (need_bs_to_fs) {
+ for (p = buf; *p; p++)
+ if (*p == '\\')
+ *p = '/';
+ }
return buf;
}
-#endif
static void msg_with_prefix(const char *prefix, const char *format, va_list ap)
{
next prev parent reply other threads:[~2024-02-11 2:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-10 18:14 [BUG] git 2.44.0-rc0 t0080.1 Breaks on NonStop x86 and ia64 rsbecker
2024-02-10 23:22 ` rsbecker
2024-02-11 2:05 ` Junio C Hamano [this message]
2024-02-11 2:47 ` rsbecker
2024-02-12 16:05 ` rsbecker
2024-02-12 16:43 ` Junio C Hamano
2024-02-12 17:59 ` rsbecker
2024-02-12 19:02 ` Junio C Hamano
2024-02-12 19:26 ` rsbecker
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=xmqqbk8nbvqy.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=rsbecker@nexbridge.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 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.