From: Phillip Wood Date: Sun, 11 Feb 2024 11:03:55 GMT Subject: Re: [PATCH] unit-tests: do show relative file paths on non-Windows, too Message-ID: <6872b42d-8763-44dc-9502-2362d1ed80a7@gmail.com> In-Reply-To: Hi Junio On 11/02/2024 08:57, Junio C Hamano wrote: > There are compilers other than Visual C that want to show absolute > paths. Generalize the helper introduced by a2c5e294 (unit-tests: do > show relative file paths, 2023-09-25) so that it can also work with > a path that uses slash as the directory separator, and becomes > almost no-op once one-time preparation finds out that we are using a > compiler that already gives relative paths. Incidentally, this also > should do the right thing on Windows with a compiler that shows > relative paths but with backslash as the directory separator (if > such a thing exists and is used to build git). > > Reported-by: Randall S. Becker > Signed-off-by: Junio C Hamano > --- > > * Another change I made, which is not described in the proposed > commit log message, is that we now use fspathcmp() instead of > strcmp() to precompute the prefix length using a known needle[] > string, to be consistent with the runtime check done for each and > every path. > > This is a belated follow-up on Thanks for putting this together - I was about to sit down and write something similar when I saw your patch. I've left one comment below but I don't think it is worth a re-roll, this looks good to me. > + /* > + * 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] != '\\')) We know which separator we're expecting so we could replace the last two comparisons with prefix[prefix_len -1] != needle[1] but as I say I'm not sure that is worth re-rolling for Best Wishes Phillip