Skip to content

Commit fd690c3

Browse files
committed
gitk: prevent overly long command lines
To avoid running into command line limitations, some of Git's commands support the `--stdin` option. Let's use exactly this option in the three rev-list/log invocations in gitk that would otherwise possibly run the danger of trying to invoke a too-long command line. While it is easy to redirect either stdin or stdout in Tcl/Tk scripts, what we need here is both. We need to capture the output, yet we also need to pipe in the revs/files arguments via stdin (because stdin does not have any limit, unlike the command line). To help this, we use the neat Tcl feature where you can capture stdout and at the same time feed a fixed string as stdin to the spawned process. One non-obvious aspect about this change is that the `--stdin` option allows to specify revs, the double-dash, and files, but *no* other options such as `--not`. This is addressed by prefixing the "negative" revs with `^` explicitly rather than relying on the `--not` option (thanks for coming up with that idea, Max!). This fixes #1987 Analysis-and-initial-patch-by: Max Kirillov <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 787bfe4 commit fd690c3

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

gitk-git/gitk

+19-5
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,16 @@ proc start_rev_list {view} {
405405
if {$revs eq {}} {
406406
return 0
407407
}
408-
set args [concat $vflags($view) $revs]
408+
set args $vflags($view)
409409
} else {
410+
set revs {}
410411
set args $vorigargs($view)
411412
}
412413

413414
if {[catch {
414415
set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \
415-
--parents --boundary $args "--" $files] r]
416+
--parents --boundary $args --stdin \
417+
"<<[join [concat $revs "--" $files] "\\n"]"] r]
416418
} err]} {
417419
error_popup "[mc "Error executing git log:"] $err"
418420
return 0
@@ -554,13 +556,19 @@ proc updatecommits {} {
554556
set revs $newrevs
555557
set vposids($view) [lsort -unique [concat $oldpos $vposids($view)]]
556558
}
557-
set args [concat $vflags($view) $revs --not $oldpos]
559+
set args $vflags($view)
560+
foreach r $oldpos {
561+
lappend revs "^$r"
562+
}
558563
} else {
564+
set revs {}
559565
set args $vorigargs($view)
560566
}
561567
if {[catch {
562568
set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \
563-
--parents --boundary $args "--" $vfilelimit($view)] r]
569+
--parents --boundary $args --stdin \
570+
"<<[join [concat $revs "--" \
571+
$vfilelimit($view)] "\\n"]"] r]
564572
} err]} {
565573
error_popup "[mc "Error executing git log:"] $err"
566574
return
@@ -10231,10 +10239,16 @@ proc getallcommits {} {
1023110239
foreach id $seeds {
1023210240
lappend ids "^$id"
1023310241
}
10242+
lappend ids "--"
1023410243
}
1023510244
}
1023610245
if {$ids ne {}} {
10237-
set fd [open [concat $cmd $ids] r]
10246+
if {$ids eq "--all"} {
10247+
set cmd [concat $cmd "--all"]
10248+
} else {
10249+
set cmd [concat $cmd --stdin "<<[join $ids "\\n"]"]
10250+
}
10251+
set fd [open $cmd r]
1023810252
fconfigure $fd -blocking 0
1023910253
incr allcommits
1024010254
nowbusy allcommits

0 commit comments

Comments
 (0)