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 <rsbecker@xxxxxxxxxxxxx> Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> --- * 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 <f0b804129e8a21449cbb6f346473d3570182ddfa.1695640837.git.gitgitgadget@xxxxxxxxx>
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