Skip to content

Commit

Permalink
gitk: Escape file paths before piping to git log
Browse files Browse the repository at this point in the history
Fixes #2293

Signed-off-by: Nico Rieck <nico.rieck@gmail.com>
  • Loading branch information
gix authored and Git for Windows Build Agent committed May 5, 2023
1 parent 13f60aa commit 3fdbe33
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions gitk-git/gitk
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,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
Expand Down Expand Up @@ -549,7 +559,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
Expand Down Expand Up @@ -703,7 +714,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
Expand Down

0 comments on commit 3fdbe33

Please sign in to comment.