]> git.ipfire.org Git - thirdparty/git.git/commit
diff --no-index: support reading from named pipes
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Wed, 5 Jul 2023 19:49:30 +0000 (20:49 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 5 Jul 2023 21:00:28 +0000 (14:00 -0700)
commit1e3f26542a6ecd3006c2c0d5ccc0bae4a700f7e5
tree59fff55e60a00dc17ca295ceeba7084532789731
parentdf521462f01b61314c9c18a4b58a53db0cd7bf3c
diff --no-index: support reading from named pipes

In some shells, such as bash and zsh, it's possible to use a command
substitution to provide the output of a command as a file argument to
another process, like so:

  diff -u <(printf "a\nb\n") <(printf "a\nc\n")

However, this syntax does not produce useful results with "git diff
--no-index". On macOS, the arguments to the command are named pipes
under /dev/fd, and git diff doesn't know how to handle a named pipe. On
Linux, the arguments are symlinks to pipes, so git diff "helpfully"
diffs these symlinks, comparing their targets like "pipe:[1234]" and
"pipe:[5678]".

To address this "diff --no-index" is changed so that if a path given on
the commandline is a named pipe or a symbolic link that resolves to a
named pipe then we read the data to diff from that pipe. This is
implemented by generalizing the code that already exists to handle
reading from stdin when the user passes the path "-".

If the user tries to compare a named pipe to a directory then we die as
we do when trying to compare stdin to a directory.

As process substitution is not support by POSIX this change is tested by
using a pipe and a symbolic link to a pipe.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff-no-index.c
t/t4053-diff-no-index.sh