git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Dennis Kaarsemaker <dennis@kaarsemaker.net>
To: git@vger.kernel.org
Cc: Dennis Kaarsemaker <dennis@kaarsemaker.net>
Subject: [PATCH 2/2] diff --no-index: support reading from pipes
Date: Fri, 11 Nov 2016 21:19:58 +0100	[thread overview]
Message-ID: <20161111201958.2175-3-dennis@kaarsemaker.net> (raw)
In-Reply-To: <20161111201958.2175-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 +++++++++++--
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/diff-no-index.c b/diff-no-index.c
index 15811c2..487dbf5 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 1eaf604..c599efb 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
-- 
2.10.1-449-gab0f84c


  parent reply	other threads:[~2016-11-11 20:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-11 20:19 [RFC/PATCH 0/2] git diff <(command1) <(command2) Dennis Kaarsemaker
2016-11-11 20:19 ` [PATCH 1/2] diff --no-index: add option to follow symlinks Dennis Kaarsemaker
2016-11-11 20:19 ` Dennis Kaarsemaker [this message]
2016-11-11 21:27 ` [RFC/PATCH 0/2] git diff <(command1) <(command2) Junio C Hamano
2016-11-11 23:14   ` Jacob Keller
2016-11-12 10:08     ` Johannes Schindelin
2016-11-14  3:14       ` Junio C Hamano
2016-11-14 15:31       ` Michael J Gruber
2016-11-14 16:40         ` Johannes Schindelin
2016-11-14 18:01         ` Junio C Hamano
2016-11-14 20:23           ` Michael J Gruber
2016-11-14 21:10             ` Junio C Hamano
2016-11-16  9:50               ` Johannes Schindelin
2016-11-16 18:29                 ` Junio C Hamano
2016-11-16 18:37                   ` Junio C Hamano
2016-11-12  6:11   ` Dennis Kaarsemaker
2016-11-12  7:06     ` Jeff King
2016-11-11 23:15 ` Jacob Keller

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=20161111201958.2175-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).