Skip to content

Commit 5aaa6fd

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
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 b5a2304 commit 5aaa6fd

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
@@ -540,14 +540,16 @@ proc start_rev_list {view} {
540540
if {$revs eq {}} {
541541
return 0
542542
}
543-
set args [concat $vflags($view) $revs]
543+
set args $vflags($view)
544544
} else {
545+
set revs {}
545546
set args $vorigargs($view)
546547
}
547548
548549
if {[catch {
549550
set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \
550-
--parents --boundary $args "--" $files] r]
551+
--parents --boundary $args --stdin \
552+
"<<[join [concat $revs "--" $files] "\\n"]"] r]
551553
} err]} {
552554
error_popup "[mc "Error executing git log:"] $err"
553555
return 0
@@ -689,13 +691,19 @@ proc updatecommits {} {
689691
set revs $newrevs
690692
set vposids($view) [lsort -unique [concat $oldpos $vposids($view)]]
691693
}
692-
set args [concat $vflags($view) $revs --not $oldpos]
694+
set args $vflags($view)
695+
foreach r $oldpos {
696+
lappend revs "^$r"
697+
}
693698
} else {
699+
set revs {}
694700
set args $vorigargs($view)
695701
}
696702
if {[catch {
697703
set fd [open [concat | git log --no-color -z --pretty=raw $show_notes \
698-
--parents --boundary $args "--" $vfilelimit($view)] r]
704+
--parents --boundary $args --stdin \
705+
"<<[join [concat $revs "--" \
706+
$vfilelimit($view)] "\\n"]"] r]
699707
} err]} {
700708
error_popup "[mc "Error executing git log:"] $err"
701709
return
@@ -10366,10 +10374,16 @@ proc getallcommits {} {
1036610374
foreach id $seeds {
1036710375
lappend ids "^$id"
1036810376
}
10377+
lappend ids "--"
1036910378
}
1037010379
}
1037110380
if {$ids ne {}} {
10372-
set fd [open [concat $cmd $ids] r]
10381+
if {$ids eq "--all"} {
10382+
set cmd [concat $cmd "--all"]
10383+
} else {
10384+
set cmd [concat $cmd --stdin "<<[join $ids "\\n"]"]
10385+
}
10386+
set fd [open $cmd r]
1037310387
fconfigure $fd -blocking 0
1037410388
incr allcommits
1037510389
nowbusy allcommits

0 commit comments

Comments
 (0)