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

Re: [PATCH] diff: don't attempt to strip prefix from absolute Windows paths

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 19, 2018, 01:34 UTC
Message-ID
<xmqqa7na4t40.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<ae6fc699-6e09-2979-40dc-9cc49f4f8365@kdbg.org>
Johannes Sixt <j6t@kdbg.org> writes:
> Use is_absolute_path() to detect Windows style absolute paths.

When cd676a51 ("diff --relative: output paths as relative to the current subdirectory", 2008-02-12) was done, neither "is_dir_sep()" nor "has_dos_drive_prefix()" existed---the latter had to wait until 25fe217b ("Windows: Treat Windows style path names.", 2008-03-05), but we didn't notice that the above code needs to use the Windows aware is_absolute_path() when we applied the change.

Show 6 quoted lines
> One might wonder whether the check for a directory separator that
> is visible in the patch context should be changed from == '/' to
> is_dir_sep() or not. It turns out not to be necessary. That code
> only ever investigates paths that have undergone pathspec
> normalization, after which there are only forward slashes even on
> Windows.
Thanks for carefully explaining.
Show 14 quoted lines
>  static void strip_prefix(int prefix_length, const char **namep, const char **otherp)
>  {
>  	/* Strip the prefix but do not molest /dev/null and absolute paths */
> -	if (*namep && **namep != '/') {
> +	if (*namep && !is_absolute_path(*namep)) {
>  		*namep += prefix_length;
>  		if (**namep == '/')
>  			++*namep;
>  	}
> -	if (*otherp && **otherp != '/') {
> +	if (*otherp && !is_absolute_path(*otherp)) {
>  		*otherp += prefix_length;
>  		if (**otherp == '/')
>  			++*otherp;

When I read the initial report and guessed the root cause without looking at the code, I didn't expect the problematic area to be this isolated and the solution to be this simple.

Nicely done.
Previous: Stefan Beller
Message 8 of 8 in “issue: strange `git diff --numstat` behavior.”
  1. Sergey AndreenkoOct 12, 2018
  2. Junio C HamanoOct 13, 2018
  3. diff: don't attempt to strip prefix from absolute Windows pathsJohannes Sixt, Oct 18, 2018
  4. Stefan BellerOct 18, 2018
  5. Johannes SixtOct 18, 2018
  6. diff: don't attempt to strip prefix from absolute Windows pathsJohannes Sixt, Oct 19, 2018
  7. Stefan BellerOct 19, 2018
  8. Junio C HamanoOct 19, 2018

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.