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

[PATCH 1/4] hash-object.c: Allow distinct file/path in stdin mode too.

From
Matteo Bertini <naufraghi@develer.com>
Date
May 31, 2016, 15:07 UTC
Message-ID
<20160531150749.24840-2-naufraghi@develer.com>
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
Previous: Matteo BertiniNext: Matteo Bertini
Message 2 of 9 in “Add option to enable filters in git-svn”
  1. 0/4 Add option to enable filters in git-svnMatteo Bertini, May 31, 2016
  2. 1/4 hash-object.c: Allow distinct file/path in stdin mode too.Matteo Bertini, May 31, 2016
  3. 2/4 Git.pm: Add $path and $enable_filters arguments to hash_and_insert_object.Matteo Bertini, May 31, 2016
  4. 3/4 SVN/Fetcher.pm: Add svn-remote.<id>.enable-filters to enable the filters.Matteo Bertini, May 31, 2016
  5. 4/4 git-svn.perl: Add git svn init --enable-filters option.Matteo Bertini, May 31, 2016
  6. Matteo BertiniMay 31, 2016
  7. Eric WongMay 31, 2016
  8. Matteo BertiniMay 31, 2016
  9. Eric WongJun 2, 2016

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.