git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] unit-tests: do show relative file paths on non-Windows, too

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Feb 11, 2024, 11:03 UTC
Message-ID
<6872b42d-8763-44dc-9502-2362d1ed80a7@gmail.com>
In-Reply-To
<xmqqttmf9y46.fsf@gitster.g>
Hi Junio
On 11/02/2024 08:57, Junio C Hamano wrote:
Show 21 quoted lines
> 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@nexbridge.com>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
> 
>   * 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@gmail.com>

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.

Show 10 quoted lines
> +		/*
> +		 * 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
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 of 9 in “unit-tests: do show relative file paths on non-Windows, too”
  1. unit-tests: do show relative file paths on non-Windows, tooJunio C Hamano, Feb 11, 2024
  2. Phillip WoodFeb 11, 2024
  3. unit-tests: do show relative file paths on non-Windows, tooJunio C Hamano, Feb 11, 2024
  4. Phillip WoodFeb 12, 2024
  5. Junio C HamanoFeb 12, 2024
  6. Phillip WoodFeb 13, 2024
  7. Junio C HamanoFeb 13, 2024
  8. Johannes SchindelinFeb 13, 2024
  9. Junio C HamanoFeb 13, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.