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

[PATCH 2/2] completion: suppress unwanted unescaping of `read`

From
Koichi Murase <myoga.murase@gmail.com>
Date
Apr 20, 2023, 07:46 UTC
Message-ID
<20230420074616.1642742-2-myoga.murase@gmail.com>
In-Reply-To
<20230420074616.1642742-1-myoga.murase@gmail.com>
From: Edwin Kofler <edwin@kofler.dev>

The function `__git_eread`, that reads the first line from the file, calls the `read` builtin without passing the flag option `-r`. When the `read` builtin is called without the flag `-r`, it processes the backslash escaping in the text that it reads. We usually do not want to process backslashes of the input but want to read the raw contents.

To make it read the first line as is, pass the flag `-r` to the `read` builtin in the function `__git_eread`.

Signed-off-by: Edwin Kofler <edwin@kofler.dev>
Signed-off-by: Koichi Murase <myoga.murase@gmail.com>
---
 contrib/completion/git-prompt.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 9c10690a22..49dd69bb84 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -298,7 +298,7 @@ __git_ps1_colorize_gitstring ()
 # variable, in that order.
 __git_eread ()
 {
-	test -r "$1" && IFS=$'\r\n' read "$2" <"$1"
+	test -r "$1" && IFS=$'\r\n' read -r "$2" <"$1"
 }
 
 # see if a cherry-pick or revert is in progress, if the user has committed a
-- 
2.39.0
Previous: Koichi MuraseNext: Junio C Hamano
Message 2 of 10 in “completion: quote arguments of test and [”
  1. 1/2 completion: quote arguments of test and [Koichi Murase, Apr 20, 2023
  2. 2/2 completion: suppress unwanted unescaping of `read`Koichi Murase, Apr 20, 2023
  3. Junio C HamanoApr 20, 2023
  4. Koichi MuraseApr 20, 2023
  5. completion: suppress unwanted unescaping of `read`Koichi Murase, Apr 20, 2023
  6. Junio C HamanoApr 20, 2023
  7. Felipe ContrerasApr 24, 2023
  8. Junio C HamanoApr 20, 2023
  9. Koichi MuraseApr 20, 2023
  10. Felipe ContrerasApr 24, 2023

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.