git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matteo Bertini <naufraghi@develer.com>
To: git@vger.kernel.org
Cc: Matteo Bertini <matteo@naufraghi.net>,
	normalperson@yhbt.net, gitster@pobox.com,
	Matteo Bertini <naufraghi@develer.com>
Subject: [PATCH 1/4] hash-object.c: Allow distinct file/path in stdin mode too.
Date: Tue, 31 May 2016 17:07:46 +0200	[thread overview]
Message-ID: <20160531150749.24840-2-naufraghi@develer.com> (raw)
In-Reply-To: <20160531150749.24840-1-naufraghi@develer.com>

From: Matteo Bertini <matteo@naufraghi.net>

The hash-object command has the --path option to use a name for the filters
that is different from the file containing the data.

This patch exposes the same functionality for the --stdin-paths, using \t
as separator.

Signed-off-by: Matteo Bertini <naufraghi@develer.com>
---
 builtin/hash-object.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/builtin/hash-object.c b/builtin/hash-object.c
index f7d3567..f74c6bd 100644
--- a/builtin/hash-object.c
+++ b/builtin/hash-object.c
@@ -58,20 +58,45 @@ static void hash_object(const char *path, const char *type, const char *vpath,
 static void hash_stdin_paths(const char *type, int no_filters, unsigned flags,
 			     int literally)
 {
+	int has_path = 0;
 	struct strbuf buf = STRBUF_INIT;
+	struct strbuf path = STRBUF_INIT;
 	struct strbuf unquoted = STRBUF_INIT;
+	struct strbuf **pair;
 
 	while (strbuf_getline(&buf, stdin) != EOF) {
+		pair = strbuf_split_max(&buf, '\t', 2);
+		if (pair[0]) {
+			if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '\t') {
+				strbuf_setlen(pair[0], pair[0]->len - 1);
+			}
+			strbuf_swap(&buf, pair[0]);
+		}
+		if (pair[1]) {
+			strbuf_swap(&path, pair[1]);
+			has_path = 1;
+		}
+		strbuf_list_free(pair);
+
 		if (buf.buf[0] == '"') {
 			strbuf_reset(&unquoted);
 			if (unquote_c_style(&unquoted, buf.buf, NULL))
 				die("line is badly quoted");
 			strbuf_swap(&buf, &unquoted);
 		}
-		hash_object(buf.buf, type, no_filters ? NULL : buf.buf, flags,
-			    literally);
+
+		if (has_path && path.buf[0] == '"') {
+			strbuf_reset(&unquoted);
+			if (unquote_c_style(&unquoted, path.buf, NULL))
+				die("line is badly quoted");
+			strbuf_swap(&path, &unquoted);
+		}
+
+		hash_object(buf.buf, type, no_filters ? NULL : (has_path ? path.buf : buf.buf),
+				  flags, literally);
 	}
 	strbuf_release(&buf);
+	strbuf_release(&path);
 	strbuf_release(&unquoted);
 }
 
-- 
2.9.0.rc0.39.gb9f310b.dirty

  reply	other threads:[~2016-05-31 15:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-31 15:07 [PATCH/RFC 0/4] Add option to enable filters in git-svn Matteo Bertini
2016-05-31 15:07 ` Matteo Bertini [this message]
2016-05-31 15:07 ` [PATCH 2/4] Git.pm: Add $path and $enable_filters arguments to hash_and_insert_object Matteo Bertini
2016-05-31 15:07 ` [PATCH 3/4] SVN/Fetcher.pm: Add svn-remote.<id>.enable-filters to enable the filters Matteo Bertini
2016-05-31 15:07 ` [PATCH 4/4] git-svn.perl: Add git svn init --enable-filters option Matteo Bertini
2016-05-31 15:34 ` [PATCH/RFC 0/4] Add option to enable filters in git-svn Matteo Bertini
2016-05-31 18:12   ` Eric Wong
2016-05-31 20:34     ` Matteo Bertini
2016-06-02 21:13       ` Eric Wong

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160531150749.24840-2-naufraghi@develer.com \
    --to=naufraghi@develer.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=matteo@naufraghi.net \
    --cc=normalperson@yhbt.net \
    /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.
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 NNTP newsgroup(s).