Skip to content

Commit b136617

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 d44acf7 commit b136617

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

gitk-git/gitk

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,14 +406,16 @@ proc start_rev_list {view} {
406406
if {$revs eq {}} {
407407
return 0
408408
}
409-
set args [concat $vflags($view) $revs]
409+
set args $vflags($view)
410410
} else {
411+
set revs {}
411412
set args $vorigargs($view)
412413
}
413414

414415
if {[catch {
415416
set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \
416-
--parents --boundary $args "--" $files] r]
417+
--parents --boundary $args --stdin \
418+
"<<[join [concat $revs "--" $files] "\\n"]"] r]
417419
} err]} {
418420
error_popup "[mc "Error executing git log:"] $err"
419421
return 0
@@ -555,13 +557,19 @@ proc updatecommits {} {
555557
set revs $newrevs
556558
set vposids($view) [lsort -unique [concat $oldpos $vposids($view)]]
557559
}
558-
set args [concat $vflags($view) $revs --not $oldpos]
560+
set args $vflags($view)
561+
foreach r $oldpos {
562+
lappend revs "^$r"
563+
}
559564
} else {
565+
set revs {}
560566
set args $vorigargs($view)
561567
}
562568
if {[catch {
563569
set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \
564-
--parents --boundary $args "--" $vfilelimit($view)] r]
570+
--parents --boundary $args --stdin \
571+
"<<[join [concat $revs "--" \
572+
$vfilelimit($view)] "\\n"]"] r]
565573
} err]} {
566574
error_popup "[mc "Error executing git log:"] $err"
567575
return
@@ -10168,10 +10176,16 @@ proc getallcommits {} {
1016810176
foreach id $seeds {
1016910177
lappend ids "^$id"
1017010178
}
10179+
lappend ids "--"
1017110180
}
1017210181
}
1017310182
if {$ids ne {}} {
10174-
set fd [open [concat $cmd $ids] r]
10183+
if {$ids eq "--all"} {
10184+
set cmd [concat $cmd "--all"]
10185+
} else {
10186+
set cmd [concat $cmd --stdin "<<[join $ids "\\n"]"]
10187+
}
10188+
set fd [open $cmd r]
1017510189
fconfigure $fd -blocking 0
1017610190
incr allcommits
1017710191
nowbusy allcommits

0 commit comments

Comments
 (0)