diff --git a/gitk-git/gitk b/gitk-git/gitk index 2331694bb5..1fa5acb910 100644 --- a/gitk-git/gitk +++ b/gitk-git/gitk @@ -9418,11 +9418,16 @@ proc getallcommits {} { } if {$ids ne {}} { set cmd [concat $cmd $ids] - # XP and later accept up to 8191 characters in the command line - # see http://support.microsoft.com/kb/830473 + # The maximum command line length for the CreateProcess function is 32767 characters, see + # http://blogs.msdn.com/oldnewthing/archive/2003/12/10/56028.aspx + # Be a little conservative in case Tcl adds some more stuff to the command line we do not + # know about and truncate the command line at a SHA1-boundary below 32000 characters. if {[tk windowingsystem] == "win32" && - [string length $cmd] > 8191} { - set cmd [regsub "^(.{1,8191}) .*\$" $cmd "\\1"] + [string length $cmd] > 32000} { + set ndx [string last " " $cmd 32000] + if {$ndx != -1} { + set cmd [string range $cmd 0 $ndx] + } } set fd [open $cmd r] fconfigure $fd -blocking 0