All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Johannes Sixt <j6t@kdbg.org>
Cc: Sergey Andreenko <andreenkosa@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH] diff: don't attempt to strip prefix from absolute Windows paths
Date: Fri, 19 Oct 2018 10:34:23 +0900	[thread overview]
Message-ID: <xmqqa7na4t40.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <ae6fc699-6e09-2979-40dc-9cc49f4f8365@kdbg.org> (Johannes Sixt's message of "Thu, 18 Oct 2018 20:38:25 +0200")

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.

> 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.

>  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.

      parent reply	other threads:[~2018-10-19  1:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-12 18:23 issue: strange `git diff --numstat` behavior Sergey Andreenko
2018-10-13  8:13 ` Junio C Hamano
2018-10-18 18:38   ` [PATCH] diff: don't attempt to strip prefix from absolute Windows paths Johannes Sixt
2018-10-18 18:49     ` Stefan Beller
2018-10-18 19:11       ` Johannes Sixt
2018-10-19 16:58         ` [PATCH v2] " Johannes Sixt
2018-10-19 17:04           ` Stefan Beller
2018-10-19  1:34     ` Junio C Hamano [this message]

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=xmqqa7na4t40.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=andreenkosa@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --subject='Re: [PATCH] diff: don'\''t attempt to strip prefix from absolute Windows paths' \
    /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

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.