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

[PATCH 2/4] Add -z option to show-files

From
Junio C Hamano <junkio@cox.net>
Date
Apr 15, 2005, 06:04 UTC
Message-ID
<7vis2oo9sz.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7vr7hco9z7.fsf@assigned-by-dhcp.cox.net>

This adds NUL-terminated output (-z) to show-files. This is necessary for merge-trees script to deal with filenames with embedded newlines.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 show-files.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
Index: show-files.c
===================================================================
--- 6767883b330882bc0e9a7c1e4fd999c0ee97ba3a/show-files.c  (mode:100664 sha1:a9fa6767a418f870a34b39379f417bf37b17ee18)
+++ 21e5e9f7d7dfa81c6519f0204d5a467236c7fdd5/show-files.c  (mode:100664 sha1:c392db8b4edb16675528f86e106e841f42bc74e4)
@@ -14,6 +14,7 @@
 static int show_cached = 0;
 static int show_others = 0;
 static int show_ignored = 0;
+static int line_terminator = '\n';
 
 static const char **dir;
 static int nr_dir;
@@ -105,12 +106,12 @@
 	}
 	if (show_others) {
 		for (i = 0; i < nr_dir; i++)
-			printf("%s\n", dir[i]);
+			printf("%s%c", dir[i], line_terminator);
 	}
 	if (show_cached) {
 		for (i = 0; i < active_nr; i++) {
 			struct cache_entry *ce = active_cache[i];
-			printf("%s\n", ce->name);
+			printf("%s%c", ce->name, line_terminator);
 		}
 	}
 	if (show_deleted) {
@@ -119,7 +120,7 @@
 			struct stat st;
 			if (!stat(ce->name, &st))
 				continue;
-			printf("%s\n", ce->name);
+			printf("%s%c", ce->name, line_terminator);
 		}
 	}
 	if (show_ignored) {
@@ -134,6 +135,11 @@
 	for (i = 1; i < argc; i++) {
 		char *arg = argv[i];
 
+		if (!strcmp(arg, "-z")) {
+			line_terminator = 0;
+			continue;
+		}
+
 		if (!strcmp(arg, "--cached")) {
 			show_cached = 1;
 			continue;
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 5 in “Merging merge-trees changes to pasky-0.4”
  1. 0/4 Merging merge-trees changes to pasky-0.4Junio C Hamano, Apr 15, 2005
  2. 1/4 Add --cacheinfo option to update-cacheJunio C Hamano, Apr 15, 2005
  3. 2/4 Add -z option to show-filesJunio C Hamano, Apr 15, 2005
  4. 3/4 Add -r and -z options to ls-treeJunio C Hamano, Apr 15, 2005
  5. 4/4 Makefile change and merge-trees script itself.Junio C Hamano, Apr 15, 2005

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.