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

Re: [PATCH] stash: prevent warning about null bytes in input

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 14, 2017, 19:51 UTC
Message-ID
<xmqq7ey6udvl.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170814050801.7158-1-me@ikke.info>
Kevin Daudt <me@ikke.info> writes:
Show 7 quoted lines
> The no_changes function calls the untracked_files function through
> command substitution. untracked_files will return null bytes because it
> runs ls-files with the '-z' option.
>
> Bash since version 4.4 warns about these null bytes. As they are not
> required for the test that is being done, remove null bytes from the
> input.
That's an interesting one ;-)

I wonder if you considered giving an option to untracked_files helper function, though. After all, it has only two callers, and it feels a bit suboptimal to ask the command to do a special thing (i.e. "-z") only to clean it up with a pipe.

IOW, something along the lines of (totally untested)...
 git-stash.sh | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/git-stash.sh b/git-stash.sh
index 9b6c2da7b4..5f09a47f0a 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -43,9 +43,16 @@ no_changes () {
 }
 
 untracked_files () {
+	if test "$1" = "-z"
+	then
+		shift
+		z=-z
+	else
+		z=
+	fi
 	excl_opt=--exclude-standard
 	test "$untracked" = "all" && excl_opt=
-	git ls-files -o -z $excl_opt -- "$@"
+	git ls-files -o $z $excl_opt -- "$@"
 }
 
 clear_stash () {
@@ -114,7 +121,7 @@ create_stash () {
 		# Untracked files are stored by themselves in a parentless commit, for
 		# ease of unpacking later.
 		u_commit=$(
-			untracked_files "$@" | (
+			untracked_files -z "$@" | (
 				GIT_INDEX_FILE="$TMPindex" &&
 				export GIT_INDEX_FILE &&
 				rm -f "$TMPindex" &&
Previous: Kevin DaudtNext: Kevin Daudt
Message 2 of 5 in “stash: prevent warning about null bytes in input”
  1. stash: prevent warning about null bytes in inputKevin Daudt, Aug 14, 2017
  2. Junio C HamanoAug 14, 2017
  3. Kevin DaudtAug 14, 2017
  4. Junio C HamanoAug 14, 2017
  5. stash: prevent warning about null bytes in inputKevin Daudt, Aug 14, 2017

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.