X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gitk;h=5ebcf3377ebf0baba09386fde57df153f9415191;hb=62b532b080d56e02d8f486e801110456ab0bb380;hp=e190ce6e6ea0c7e2c3f966a329b5d209aa217fb9;hpb=14c9dbd69bfed89011f99278c7f293b0d186ffc7;p=git.git diff --git a/gitk b/gitk index e190ce6e6..5ebcf3377 100755 --- a/gitk +++ b/gitk @@ -37,7 +37,7 @@ proc getcommits {rargs} { set parsed_args $rargs } if [catch { - set commfd [open "|git-rev-list --header --merge-order $parsed_args" r] + set commfd [open "|git-rev-list --header --topo-order $parsed_args" r] } err] { puts stderr "Error executing git-rev-list: $err" exit 1 @@ -60,7 +60,7 @@ proc getcommitlines {commfd} { set stuff [read $commfd] if {$stuff == {}} { if {![eof $commfd]} return - # this works around what is apparently a bug in Tcl... + # set it blocking so we wait for the process to terminate fconfigure $commfd -blocking 1 if {![catch {close $commfd} err]} { after idle finishcommits @@ -273,7 +273,7 @@ proc makewindow {} { global findtype findtypemenu findloc findstring fstring geometry global entries sha1entry sha1string sha1but global maincursor textcursor - global rowctxmenu + global rowctxmenu gaudydiff menu .bar .bar add cascade -label "File" -menu .bar.file @@ -364,11 +364,17 @@ proc makewindow {} { pack $ctext -side left -fill both -expand 1 .ctop.cdet add .ctop.cdet.left - $ctext tag conf filesep -font [concat $textfont bold] - $ctext tag conf hunksep -back blue -fore white - $ctext tag conf d0 -back "#ff8080" - $ctext tag conf d1 -back green - $ctext tag conf found -back yellow + $ctext tag conf filesep -font [concat $textfont bold] -back "#aaaaaa" + if {$gaudydiff} { + $ctext tag conf hunksep -back blue -fore white + $ctext tag conf d0 -back "#ff8080" + $ctext tag conf d1 -back green + } else { + $ctext tag conf hunksep -fore blue + $ctext tag conf d0 -fore red + $ctext tag conf d1 -fore "#00a000" + $ctext tag conf found -back yellow + } frame .ctop.cdet.right set cflist .ctop.cdet.right.cfiles @@ -465,8 +471,10 @@ proc savestuff {w} { if {![winfo viewable .]} return catch { set f [open "~/.gitk-new" w] - puts $f "set mainfont {$mainfont}" - puts $f "set textfont {$textfont}" + puts $f [list set mainfont $mainfont] + puts $f [list set textfont $textfont] + puts $f [list set findmergefiles $findmergefiles] + puts $f [list set gaudydiff $gaudydiff] puts $f "set geometry(width) [winfo width .ctop]" puts $f "set geometry(height) [winfo height .ctop]" puts $f "set geometry(canv1) [expr [winfo width $canv]-2]" @@ -1602,7 +1610,7 @@ proc selectline {l} { global lineid linehtag linentag linedtag global canvy0 linespc parents nparents global cflist currentid sha1entry - global commentend seenfile idtags + global commentend idtags $canv delete hover if {![info exists lineid($l)] || ![info exists linehtag($l)]} return $canv delete secsel @@ -1684,17 +1692,28 @@ proc selectline {l} { $cflist delete 0 end $cflist insert end "Comments" - if {$nparents($id) == 1} { - startdiff [concat $id $parents($id)] - } - catch {unset seenfile} + startdiff $id $parents($id) +} + +proc startdiff {id vs} { + global diffpending diffpindex + global diffindex difffilestart + global curdifftag curtagstart + + set diffpending $vs + set diffpindex 0 + set diffindex 0 + catch {unset difffilestart} + set curdifftag Comments + set curtagstart 0.0 + contdiff [list $id [lindex $vs 0]] } -proc startdiff {ids} { +proc contdiff {ids} { global treediffs diffids treepending + set diffids $ids if {![info exists treediffs($ids)]} { - set diffids $ids if {![info exists treepending]} { gettreediffs $ids } @@ -1712,9 +1731,13 @@ proc selnextline {dir} { } proc addtocflist {ids} { - global treediffs cflist + global treediffs cflist diffpindex + + set colors {black blue green red cyan magenta} + set color [lindex $colors [expr {$diffpindex % [llength $colors]}]] foreach f $treediffs($ids) { $cflist insert end $f + $cflist itemconf end -foreground $color } getblobdiffs $ids } @@ -1741,7 +1764,6 @@ proc gettreediffline {gdtf ids} { if {$ids != $diffids} { gettreediffs $diffids } else { - unset diffids addtocflist $ids } } @@ -1752,8 +1774,8 @@ proc gettreediffline {gdtf ids} { } proc getblobdiffs {ids} { - global diffopts blobdifffd blobdiffids env curdifftag curtagstart - global diffindex difffilestart nextupdate + global diffopts blobdifffd diffids env + global nextupdate diffinhdr set id [lindex $ids 0] set p [lindex $ids 1] @@ -1762,49 +1784,44 @@ proc getblobdiffs {ids} { puts "error getting diffs: $err" return } + set diffinhdr 0 fconfigure $bdf -blocking 0 - set blobdiffids $ids set blobdifffd($ids) $bdf - set curdifftag Comments - set curtagstart 0.0 - set diffindex 0 - catch {unset difffilestart} - fileevent $bdf readable "getblobdiffline $bdf {$ids}" + fileevent $bdf readable [list getblobdiffline $bdf $ids] set nextupdate [expr {[clock clicks -milliseconds] + 100}] } proc getblobdiffline {bdf ids} { - global blobdiffids blobdifffd ctext curdifftag curtagstart seenfile + global diffids blobdifffd ctext curdifftag curtagstart global diffnexthead diffnextnote diffindex difffilestart - global nextupdate + global nextupdate diffpending diffpindex diffinhdr + global gaudydiff set n [gets $bdf line] if {$n < 0} { if {[eof $bdf]} { close $bdf - if {$ids == $blobdiffids && $bdf == $blobdifffd($ids)} { + if {$ids == $diffids && $bdf == $blobdifffd($ids)} { $ctext tag add $curdifftag $curtagstart end - set seenfile($curdifftag) 1 + if {[incr diffpindex] < [llength $diffpending]} { + set id [lindex $ids 0] + set p [lindex $diffpending $diffpindex] + contdiff [list $id $p] + } } } return } - if {$ids != $blobdiffids || $bdf != $blobdifffd($ids)} { + if {$ids != $diffids || $bdf != $blobdifffd($ids)} { return } $ctext conf -state normal - if {[regexp {^---[ \t]+([^/])*/(.*)} $line match s1 fname]} { + if {[regexp {^diff --git a/(.*) b/} $line match fname]} { # start of a new file $ctext insert end "\n" $ctext tag add $curdifftag $curtagstart end - set seenfile($curdifftag) 1 set curtagstart [$ctext index "end - 1c"] set header $fname - if {[info exists diffnexthead]} { - set fname $diffnexthead - set header "$diffnexthead ($diffnextnote)" - unset diffnexthead - } set here [$ctext index "end - 1c"] set difffilestart($diffindex) $here incr diffindex @@ -1816,37 +1833,33 @@ proc getblobdiffline {bdf ids} { set l [expr {(78 - [string length $header]) / 2}] set pad [string range "----------------------------------------" 1 $l] $ctext insert end "$pad $header $pad\n" filesep - } elseif {[string range $line 0 2] == "+++"} { - # no need to do anything with this - } elseif {[regexp {^Created: (.*) \((mode: *[0-7]*)\)} $line match fn m]} { - set diffnexthead $fn - set diffnextnote "created, mode $m" - } elseif {[string range $line 0 8] == "Deleted: "} { - set diffnexthead [string range $line 9 end] - set diffnextnote "deleted" - } elseif {[regexp {^diff --git a/(.*) b/} $line match fn]} { - # save the filename in case the next thing is "new file mode ..." - set diffnexthead $fn - set diffnextnote "modified" - } elseif {[regexp {^new file mode ([0-7]+)} $line match m]} { - set diffnextnote "new file, mode $m" - } elseif {[string range $line 0 11] == "deleted file"} { - set diffnextnote "deleted" + set diffinhdr 1 + } elseif {[regexp {^(---|\+\+\+)} $line]} { + set diffinhdr 0 } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \ $line match f1l f1c f2l f2c rest]} { - $ctext insert end "\t" hunksep - $ctext insert end " $f1l " d0 " $f2l " d1 - $ctext insert end " $rest \n" hunksep + if {$gaudydiff} { + $ctext insert end "\t" hunksep + $ctext insert end " $f1l " d0 " $f2l " d1 + $ctext insert end " $rest \n" hunksep + } else { + $ctext insert end "$line\n" hunksep + } + set diffinhdr 0 } else { set x [string range $line 0 0] if {$x == "-" || $x == "+"} { set tag [expr {$x == "+"}] - set line [string range $line 1 end] + if {$gaudydiff} { + set line [string range $line 1 end] + } $ctext insert end "$line\n" d$tag } elseif {$x == " "} { - set line [string range $line 1 end] + if {$gaudydiff} { + set line [string range $line 1 end] + } $ctext insert end "$line\n" - } elseif {$x == "\\"} { + } elseif {$diffinhdr || $x == "\\"} { # e.g. "\ No newline at end of file" $ctext insert end "$line\n" filesep } else { @@ -1854,7 +1867,6 @@ proc getblobdiffline {bdf ids} { if {$curdifftag != "Comments"} { $ctext insert end "\n" $ctext tag add $curdifftag $curtagstart end - set seenfile($curdifftag) 1 set curtagstart [$ctext index "end - 1c"] set curdifftag Comments } @@ -1882,7 +1894,7 @@ proc nextfile {} { } proc listboxsel {} { - global ctext cflist currentid treediffs seenfile + global ctext cflist currentid treediffs if {![info exists currentid]} return set sel [lsort [$cflist curselection]] if {$sel eq {}} return @@ -1954,18 +1966,35 @@ proc sha1change {n1 n2 op} { proc gotocommit {} { global sha1string currentid idline tagids + global lineid numcommits + if {$sha1string == {} || ([info exists currentid] && $sha1string == $currentid)} return if {[info exists tagids($sha1string)]} { set id $tagids($sha1string) } else { set id [string tolower $sha1string] + if {[regexp {^[0-9a-f]{4,39}$} $id]} { + set matches {} + for {set l 0} {$l < $numcommits} {incr l} { + if {[string match $id* $lineid($l)]} { + lappend matches $lineid($l) + } + } + if {$matches ne {}} { + if {[llength $matches] > 1} { + error_popup "Short SHA1 id $id is ambiguous" + return + } + set id [lindex $matches 0] + } + } } if {[info exists idline($id)]} { selectline $idline($id) return } - if {[regexp {^[0-9a-fA-F]{40}$} $sha1string]} { + if {[regexp {^[0-9a-fA-F]{4,}$} $sha1string]} { set type "SHA1 id" } else { set type "Tag" @@ -2367,6 +2396,7 @@ set wrcomcmd "git-diff-tree --stdin -p --pretty" set mainfont {Helvetica 9} set textfont {Courier 9} set findmergefiles 0 +set gaudydiff 0 set colors {green red blue magenta darkgrey brown orange}