gitk: escape file paths before piping to git log
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nico Rieck committed
Jan 24, 2023 at 11:23 UTC
7dd272eca153058da2e8d5b9960bbbf0b4f0cbaa
1 file changed
+14
-2
gitk
+14
-2
@@ -353,6 +353,16 @@ proc parseviewrevs {view revs} {
353
return $ret
354
}
355
356
+# Escapes a list of filter paths to be passed to git log via stdin. Note that
357
+# paths must not be quoted.
358
+proc escape_filter_paths {paths} {
359
+ set escaped [list]
360
+ foreach path $paths {
361
+ lappend escaped [string map {\\ \\\\ "\ " "\\\ "} $path]
362
+ }
363
+ return $escaped
364
+}
365
+
366
# Start off a git log process and arrange to read its output
367
proc start_rev_list {view} {
368
global startmsecs commitidx viewcomplete curview
@@ -414,7 +424,8 @@ proc start_rev_list {view} {
424
if {[catch {
425
set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \
426
--parents --boundary $args --stdin \
417
- "<<[join [concat $revs "--" $files] "\\n"]"] r]
427
+ "<<[join [concat $revs "--" \
428
+ [escape_filter_paths $files]] "\\n"]"] r]
429
} err]} {
430
error_popup "[mc "Error executing git log:"] $err"
431
return 0
@@ -568,7 +579,8 @@ proc updatecommits {} {
579
set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \
580
--parents --boundary $args --stdin \
581
"<<[join [concat $revs "--" \
571
- $vfilelimit($view)] "\\n"]"] r]
582
+ [escape_filter_paths \
583
+ $vfilelimit($view)]] "\\n"]"] r]
584
} err]} {
585
error_popup "[mc "Error executing git log:"] $err"
586
return