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

Re: [PATCH/RFC][GSoC] make "git diff --no-index $directory $file" DWIM better.

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 15, 2015, 20:17 UTC
Message-ID
<xmqqpp8at3qf.fsf@gitster.dls.corp.google.com>
In-Reply-To
<CAHLaBN+93mp6PQmtfjOHSvfW7iwDXwPitGQ5W1am9KBm9EZV2Q@mail.gmail.com>
Yurii Shevtsov <ungetch@gmail.com> writes:
> Changes 'git diff --no-index $directory $file' behaviour.
> Now it is transformed to 'git diff --no-index $directory/&file $file'
> instead of throwing an error.

Is this asymmetric? Shouldn't "git diff --no-index $file $directory" behave the same way, i.e. turned into "$file $directory/$file"?

If you intended the patch to do so, perhaps
    "git diff --no-index directory/ file" used to error out, saying
    that you cannot compare a directory and a file (with the
    parameters swapped, "git diff --no-index file directory/" failed
    the same way).
    With normal "diff", "diff D/ F" acts as if it were told to
    compare D/F and F (when D/F exists---if there isn't, then it
    shows a creation of F), and behaving the same way would be more
    natural to the users.
or something?
Show 30 quoted lines
> Signed-off-by: Yurii Shevtsov <ungetch <at> gmail.com>
> ---
>  diff-no-index.c |   21 +++++++++++++++++++--
>  1 files changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/diff-no-index.c b/diff-no-index.c
> index 265709b..4e71b36 100644
> --- a/diff-no-index.c
> +++ b/diff-no-index.c
> @@ -97,8 +97,25 @@ 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 strbuf dirnfile;
> +               const char *dir, *file;
> +               char *filename;
> +               int ret = 0;
> +
> +               dir = S_ISDIR(mode1) ? name1 : name2;
> +               file = (dir == name1) ? name2 : name1;
> +               strbuf_init(&dirnfile, strlen(name1) + strlen(name2) + 2);
> +               strbuf_addstr(&dirnfile, dir);
> +               if (dirnfile.buf[dirnfile.len - 1] != '/')
> +                       strbuf_addch(&dirnfile, '/');
> +               filename = strrchr(file, '/');
> +               strbuf_addstr(&dirnfile, filename ? (filename + 1) : file);
> +               ret = queue_diff(o, dirnfile.buf, file);

Hmm, it appears that you are turning "diff F D/" into "diff D/F F", which is the other way around here, or am I mis-reading queue_diff().

Does queue_diff() do the right thing when D/F does not exist (not a rhetorical question; I just did not check it myself)?

Previous: Eric SunshineNext: t.gummerer@gmail.com
Message 10 of 13 in “[GSoC] make "git diff --no-index $directory $file" DWIM better.”
  1. [GSoC] make "git diff --no-index $directory $file" DWIM better.Yurii Shevtsov, Mar 15, 2015
  2. Matthieu MoyMar 15, 2015
  3. Junio C HamanoMar 16, 2015
  4. Yurii ShevtsovMar 16, 2015
  5. Junio C HamanoMar 16, 2015
  6. Yurii ShevtsovMar 16, 2015
  7. Junio C HamanoMar 16, 2015
  8. t.gummerer@gmail.comMar 15, 2015
  9. Eric SunshineMar 15, 2015
  10. Junio C HamanoMar 15, 2015
  11. t.gummerer@gmail.comMar 15, 2015
  12. Eric SunshineMar 15, 2015
  13. Junio C HamanoMar 15, 2015

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.