From: Dennis Kaarsemaker <dennis@kaarsemaker.net>
To: git@vger.kernel.org
Cc: Dennis Kaarsemaker <dennis@kaarsemaker.net>
Subject: [PATCH v2 2/2] diff --no-index: support reading from pipes
Date: Fri, 13 Jan 2017 11:20:21 +0100 [thread overview]
Message-ID: <20170113102021.6054-3-dennis@kaarsemaker.net> (raw)
In-Reply-To: <20170113102021.6054-1-dennis@kaarsemaker.net>
diff <(command1) <(command2) provides useful output, let's make it
possible for git to do the same.
Signed-off-by: Dennis Kaarsemaker <dennis@kaarsemaker.net>
---
diff-no-index.c | 8 ++++++++
diff.c | 13 +++++++++++--
t/t4053-diff-no-index.sh | 10 ++++++++++
t/test-lib.sh | 4 ++++
4 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/diff-no-index.c b/diff-no-index.c
index 826fe97ffc..2123da435b 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -83,6 +83,14 @@ static struct diff_filespec *noindex_filespec(const char *name, int mode)
name = "/dev/null";
s = alloc_filespec(name);
fill_filespec(s, null_sha1, 0, mode);
+ /*
+ * In --no-index mode, we support reading from pipes. canon_mode, called by
+ * fill_filespec, gets confused by this and thinks we now have subprojects.
+ * Detect this and tell the rest of the diff machinery to treat pipes as
+ * normal files.
+ */
+ if (S_ISGITLINK(s->mode))
+ s->mode = S_IFREG | ce_permissions(mode);
if (name == file_from_standard_input)
populate_from_stdin(s);
return s;
diff --git a/diff.c b/diff.c
index 2fc0226338..bb04eab331 100644
--- a/diff.c
+++ b/diff.c
@@ -2839,9 +2839,18 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
fd = open(s->path, O_RDONLY);
if (fd < 0)
goto err_empty;
- s->data = xmmap(NULL, s->size, PROT_READ, MAP_PRIVATE, fd, 0);
+ if (!S_ISREG(st.st_mode)) {
+ struct strbuf sb = STRBUF_INIT;
+ strbuf_read(&sb, fd, 0);
+ s->size = sb.len;
+ s->data = strbuf_detach(&sb, NULL);
+ s->should_free = 1;
+ }
+ else {
+ s->data = xmmap(NULL, s->size, PROT_READ, MAP_PRIVATE, fd, 0);
+ s->should_munmap = 1;
+ }
close(fd);
- s->should_munmap = 1;
/*
* Convert from working tree format to canonical git format
diff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh
index c6046fef19..ba343566c0 100755
--- a/t/t4053-diff-no-index.sh
+++ b/t/t4053-diff-no-index.sh
@@ -157,4 +157,14 @@ test_expect_success SYMLINKS 'diff --no-index --no-dereference does not follow s
test_cmp expect actual
'
+test_expect_success PROCESS_SUBSTITUTION 'diff --no-index works on fifos' '
+ cat >expect <<\EOF
+ @@ -1 +1 @@
+ -1
+ +2
+ EOF
+ test_expect_code 1 git diff --no-index <(echo 1) <(echo 2) | tail -n +5 > actual &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 11562bde10..78f3d24651 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -1128,3 +1128,7 @@ build_option () {
test_lazy_prereq LONG_IS_64BIT '
test 8 -le "$(build_option sizeof-long)"
'
+
+test_lazy_prereq PROCESS_SUBSTITUTION '
+ eval "foo=<(echo test)" 2>/dev/null
+'
--
2.11.0-234-gaf85957
next prev parent reply other threads:[~2017-01-13 10:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-13 10:20 [PATCH v2 0/2] diff --no-index: support symlinks and pipes Dennis Kaarsemaker
2017-01-13 10:20 ` [PATCH v2 1/2] diff --no-index: follow symlinks Dennis Kaarsemaker
2017-01-13 23:37 ` Junio C Hamano
2017-01-13 10:20 ` Dennis Kaarsemaker [this message]
2017-01-13 23:24 ` [PATCH v2 2/2] diff --no-index: support reading from pipes 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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170113102021.6054-3-dennis@kaarsemaker.net \
--to=dennis@kaarsemaker.net \
--cc=git@vger.kernel.org \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).