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

Re: [PATCH] diff --no-index: allow pathspec after --

From
Duy Nguyen <pclouds@gmail.com>
Date
Sep 21, 2014, 09:25 UTC
Message-ID
<CACsJy8BYSTWGLv666OetUC5Td+SF8T2yWrMNC_jXU5Vn9hoESA@mail.gmail.com>
In-Reply-To
<xmqq38blmr6g.fsf@gitster.dls.corp.google.com>
On Sun, Sep 21, 2014 at 1:19 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 28 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Coming back to the command line syntax for the new feature, if I had
>> to choose, I would say
>>
>>       git diff --no-index [-<options>] [--] <path> <path> <pathspec>
>>
>> perhaps?  As we never compare anything other than two things,...
>
> Actually, I am not so sure about this anymore.
>
> It is not entirely fair to say that
>
>         git diff --no-index [--options] A B C D
>
> as comparing A and B while using C and D as pathspec and declare a
> person who expects otherwise a moron.  To a person whose brain is
> not rotten by years of use of Git, "we never compare anything other
> than two things with --no-index" is not a given, I am afraid.
>
> It is equally plausible that the same command line may be asking to
> compare A with B and C with D, i.e. producing
>
>         diff --no-git a/A b/B
>         ...
>         diff --no-git a/C b/D
>         ...
>

Heh.. I wrote something like that [1]. An extension of this is feed all filename pairs via stdin.

[1] http://thread.gmane.org/gmane.comp.version-control.git/188435
Show 10 quoted lines
> It also equally plausible (taking a cue from "mv A B C Dir/") that
> it is comparing A, B and C with D/A, D/B and D/C, respectively,
> producing
>
>         diff --no-git a/A b/D/A
>         ...
>         diff --no-git a/B b/D/B
>         ...
>         diff --no-git a/C b/D/C
>         ...

This mode is weird... In real world, "A" may match to D/some-path/A not just D/A. Which brings it back to the previous mode.

Show 7 quoted lines
> The only unambiguous syntax I can think of that avoids such
> alternative interpretations is something ugly like
>
>     git diff --no-index [-<options>] --src=<path> --dst=<path> [--] <pathspec>
>
> where "src" and "dst" are in line with the existing src/dst-prefix
> options.
Or let the user define a "separator", e.g.

git diff --no-index --pathspec-separator=<sep> [--] <paths...> [<sep> <pathspec>]

Another option is pathspec magic (I'm not entirely sure how it looks like at the implementaiton level yet), --src=<path> could become :(source)path, --dst=path -> :(dst)path and so on..

Show 34 quoted lines
> Perhaps we could declare that this is the "canonical" way to spell
> pathspec-filtered no-index comparison of two directories, but we
> allow the syntax suggested in the message I am responding to as a
> short-hand, but I am not sure if that would fly well.
>
> This --src/--dst thing could lead to even uglier tangent.  We could
> use these options to specify what is compared with what else
>
>     --{src,dst}-path=<directory in the working tree>
>     --{src,dst}-index
>     --{src,dst}-worktree
>     --{src,dst}-tree=<tree object>
>
> which allows us to express funky combinations like
>
>         git diff --src-index --dst-worktree [--] <pathspec>
>         git diff --src-tree=HEAD --dst-index [--] <pathspec>
>         git diff --src-tree=maint --dst-tree=master [--] <pathspec>
>
> The above three would be ugly ways to spell the traditional "short
> hands", e.g.
>
>         git diff [--] <pathspec>
>         git diff --cached [--] <pathspec>
>         git diff maint master [--] <pathspec>
>
> respectively.  And an obvious fallout of the above is this command
> line:
>
>         git diff --src-path=A --dst-path=B [--] <pathspec>
>
> Because this does not involve any index, tree or worktree, it cannot
> be a Git operation, so we know that is --no-index mode; the command
> line does not need to say --no-index anywhere if we go that route.

Sounds a lot like Jeff's "git-put", except with -- syntax instead of a special one, and you only look at the diff, not move any content. Also people who would go with "git diff --no-index A B C D E F..." usually script it, not type it manually. And stdin would fit better than command line arguments.

-- 
Duy
Previous: Junio C Hamano
Message 5 of 5 in “diff --no-index: allow pathspec after --”
  1. diff --no-index: allow pathspec after --Nguyễn Thái Ngọc Duy, Sep 9, 2014
  2. Junio C HamanoSep 18, 2014
  3. Duy NguyenSep 21, 2014
  4. Junio C HamanoSep 21, 2014
  5. Duy NguyenSep 21, 2014

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.