All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [RFC/PATCH] align D/F handling of "diff --no-index" with that of normal Git
Date: Sun, 22 Mar 2015 03:01:12 -0400	[thread overview]
Message-ID: <CAPig+cRQ1i+VJRUKJCqnvh3He9fgvU5FVLCUAGirFVQKjmWa7A@mail.gmail.com> (raw)
In-Reply-To: <xmqqiodtd3b4.fsf@gitster.dls.corp.google.com>

On Sun, Mar 22, 2015 at 1:11 AM, Junio C Hamano <gitster@pobox.com> wrote:
> When a commit changes a path P that used to be a file to a directory
> and create a new path P/X in it, "git show" would say that file P

s/create/creates/

More below...

> was removed and file P/X was created for such a commit.
>
> However, if we compare two directories, D1 and D2, where D1 has a
> file D1/P in it and D2 has a directory D2/P under which there is a
> file D2/P/X, and ask "git diff --no-index D1 D2" to show their
> differences, we simply get a refusal "file/directory conflict".
>
> The "diff --no-index" implementation has an underlying machinery
> that can make it more in line with the normal Git if it wanted to,
> but somehow it is not being exercised.  The only thing we need to
> do, when we see a file P and a directory P/ (or the other way
> around) is to show the removal of a file P and then pretend as if we
> are comparing nothing with a whole directory P/, as the code is
> fully prepared to express a creation of everything in a directory
> (and if the comparison is between a directory P/ and a file P, then
> show the creation of the file and then let the existing code remove
> everything in P/).
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  diff-no-index.c | 23 +++++++++++++++++++++--
>  1 file changed, 21 insertions(+), 2 deletions(-)
>
> diff --git a/diff-no-index.c b/diff-no-index.c
> index 265709b..52e9546 100644
> --- a/diff-no-index.c
> +++ b/diff-no-index.c
> @@ -97,8 +97,27 @@ static int queue_diff(struct diff_options *o,
>         if (get_mode(name1, &mode1) || get_mode(name2, &mode2))
>                 return -1;
>
> -       if (mode1 && mode2 && S_ISDIR(mode1) != S_ISDIR(mode2))
> -               return error("file/directory conflict: %s, %s", name1, name2);
> +       if (mode1 && mode2 && S_ISDIR(mode1) != S_ISDIR(mode2)) {
> +               struct diff_filespec *d1, *d2;
> +
> +               if (S_ISDIR(mode1)) {
> +                       /* 2 is file that is created */
> +                       d1 = noindex_filespec(NULL, 0);
> +                       d2 = noindex_filespec(name2, mode2);
> +                       name2 = NULL;
> +                       mode2 = 0;
> +               } else {
> +                       /* 1 is file that is deleted */
> +                       d1 = noindex_filespec(name1, mode2);
> +                       d2 = noindex_filespec(NULL, 0);
> +                       name1 = NULL;
> +                       mode1 = 0;
> +               }
> +               /* emit that file */
> +               diff_queue(&diff_queued_diff, d1, d2);
> +
> +               /* and then let the entire directory created or deleted */

s/created/be created/

> +       }
>
>         if (S_ISDIR(mode1) || S_ISDIR(mode2)) {
>                 struct strbuf buffer1 = STRBUF_INIT;
> --

  reply	other threads:[~2015-03-22  7:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-22  5:11 [RFC/PATCH] align D/F handling of "diff --no-index" with that of normal Git Junio C Hamano
2015-03-22  7:01 ` Eric Sunshine [this message]
2015-03-22 12:37 ` Ramsay Jones
2015-03-22 17:56   ` Junio C Hamano
2015-03-26  6:20 ` [PATCH v2 0/2] "diff --no-index" updates Junio C Hamano
2015-03-26  6:20   ` [PATCH v2 1/2] diff-no-index: DWIM "diff D F" into "diff D/F F" Junio C Hamano
2015-03-26  6:20   ` [PATCH v2 2/2] diff: align D/F handling of "diff --no-index" with that of normal Git Junio C Hamano

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=CAPig+cRQ1i+VJRUKJCqnvh3He9fgvU5FVLCUAGirFVQKjmWa7A@mail.gmail.com \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.