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

[PATCH 2/2] gitk: escape file paths before piping to git log

From
NGNico Rieck via GitGitGadget <gitgitgadget@gmail.com>
Date
Jan 24, 2023, 11:23 UTC
Message-ID
<ff22dd238e9ea6c540eb1083d3b56a7bd804580f.1674559397.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1469.git.1674559397.gitgitgadget@gmail.com>
From: Nico Rieck <nico.rieck@gmail.com>

We just started piping the file paths via `stdin` instead of passing them via the command-line, to avoid running into command-line limitations.

However, since we now pipe the file paths, we need to take care of special characters.

This fixes https://github.com/git-for-windows/git/issues/2293
Signed-off-by: Nico Rieck <nico.rieck@gmail.com>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 gitk | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/gitk b/gitk
index 92375ca6a2a..df3ba2ea99b 100755
--- a/gitk
+++ b/gitk
@@ -353,6 +353,16 @@ proc parseviewrevs {view revs} {
     return $ret
 }
 
+# Escapes a list of filter paths to be passed to git log via stdin. Note that
+# paths must not be quoted.
+proc escape_filter_paths {paths} {
+	set escaped [list]
+	foreach path $paths {
+		lappend escaped [string map {\\ \\\\ "\ " "\\\ "} $path]
+	}
+	return $escaped
+}
+
 # Start off a git log process and arrange to read its output
 proc start_rev_list {view} {
     global startmsecs commitidx viewcomplete curview
@@ -414,7 +424,8 @@ proc start_rev_list {view} {
     if {[catch {
         set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \
                         --parents --boundary $args --stdin \
-                        "<<[join [concat $revs "--" $files] "\\n"]"] r]
+                        "<<[join [concat $revs "--" \
+                                [escape_filter_paths $files]] "\\n"]"] r]
     } err]} {
         error_popup "[mc "Error executing git log:"] $err"
         return 0
@@ -568,7 +579,8 @@ proc updatecommits {} {
         set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \
                         --parents --boundary $args --stdin \
                         "<<[join [concat $revs "--" \
-                                $vfilelimit($view)] "\\n"]"] r]
+                                [escape_filter_paths \
+                                        $vfilelimit($view)]] "\\n"]"] r]
     } err]} {
         error_popup "[mc "Error executing git log:"] $err"
         return
-- 
gitgitgadget
Previous: Junio C HamanoNext: Johannes Schindelin
Message 4 of 10 in “gitk: handle long command-lines”
  1. 0/2 gitk: handle long command-linesJohannes Schindelin via GitGitGadget, Jan 24, 2023
  2. 1/2 gitk: prevent overly long command linesJohannes Schindelin via GitGitGadget, Jan 24, 2023
  3. Junio C HamanoJan 24, 2023
  4. 2/2 gitk: escape file paths before piping to git logNico Rieck via GitGitGadget, Jan 24, 2023
  5. Johannes SchindelinMar 27, 2023
  6. Felipe ContrerasMar 27, 2023
  7. Philip OakleyMay 6, 2023
  8. New canonical gitk urlFelipe Contreras, May 7, 2023
  9. Junio C HamanoMay 8, 2023
  10. Felipe ContrerasMay 9, 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.