Skip to content

Commit 3eeb419

Browse files
author
Junio C Hamano
committed
2 parents 0b42769 + 232475d commit 3eeb419

File tree

1 file changed

+102
-68
lines changed

1 file changed

+102
-68
lines changed

gitk

Lines changed: 102 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ proc getcommits {rargs} {
6060

6161
proc getcommitlines {commfd} {
6262
global commits parents cdate children
63-
global commitlisted phase commitinfo nextupdate
63+
global commitlisted phase nextupdate
6464
global stopped redisplaying leftover
6565

6666
set stuff [read $commfd]
@@ -196,42 +196,41 @@ proc parsecommit {id contents listed olds} {
196196
incr ncleft($p)
197197
}
198198
}
199-
foreach line [split $contents "\n"] {
200-
if {$inhdr} {
201-
if {$line == {}} {
202-
set inhdr 0
203-
} else {
204-
set tag [lindex $line 0]
205-
if {$tag == "author"} {
206-
set x [expr {[llength $line] - 2}]
207-
set audate [lindex $line $x]
208-
set auname [lrange $line 1 [expr {$x - 1}]]
209-
} elseif {$tag == "committer"} {
210-
set x [expr {[llength $line] - 2}]
211-
set comdate [lindex $line $x]
212-
set comname [lrange $line 1 [expr {$x - 1}]]
213-
}
214-
}
215-
} else {
216-
if {$comment == {}} {
217-
set headline [string trim $line]
218-
} else {
219-
append comment "\n"
220-
}
221-
if {!$listed} {
222-
# git-rev-list indents the comment by 4 spaces;
223-
# if we got this via git-cat-file, add the indentation
224-
append comment " "
225-
}
226-
append comment $line
199+
set hdrend [string first "\n\n" $contents]
200+
if {$hdrend < 0} {
201+
# should never happen...
202+
set hdrend [string length $contents]
203+
}
204+
set header [string range $contents 0 [expr {$hdrend - 1}]]
205+
set comment [string range $contents [expr {$hdrend + 2}] end]
206+
foreach line [split $header "\n"] {
207+
set tag [lindex $line 0]
208+
if {$tag == "author"} {
209+
set audate [lindex $line end-1]
210+
set auname [lrange $line 1 end-2]
211+
} elseif {$tag == "committer"} {
212+
set comdate [lindex $line end-1]
213+
set comname [lrange $line 1 end-2]
227214
}
228215
}
229-
if {$audate != {}} {
230-
set audate [clock format $audate -format "%Y-%m-%d %H:%M:%S"]
216+
set headline {}
217+
# take the first line of the comment as the headline
218+
set i [string first "\n" $comment]
219+
if {$i >= 0} {
220+
set headline [string trim [string range $comment 0 $i]]
221+
}
222+
if {!$listed} {
223+
# git-rev-list indents the comment by 4 spaces;
224+
# if we got this via git-cat-file, add the indentation
225+
set newcomment {}
226+
foreach line [split $comment "\n"] {
227+
append newcomment " "
228+
append newcomment $line
229+
}
230+
set comment $newcomment
231231
}
232232
if {$comdate != {}} {
233233
set cdate($id) $comdate
234-
set comdate [clock format $comdate -format "%Y-%m-%d %H:%M:%S"]
235234
}
236235
set commitinfo($id) [list $headline $auname $audate \
237236
$comname $comdate $comment]
@@ -683,7 +682,7 @@ Use and redistribute under the terms of the GNU General Public License} \
683682
}
684683

685684
proc assigncolor {id} {
686-
global commitinfo colormap commcolors colors nextcolor
685+
global colormap commcolors colors nextcolor
687686
global parents nparents children nchildren
688687
global cornercrossings crossings
689688

@@ -783,10 +782,12 @@ proc bindline {t id} {
783782
$canv bind $t <Button-1> "lineclick %x %y $id 1"
784783
}
785784

786-
proc drawlines {id xtra} {
785+
proc drawlines {id xtra delold} {
787786
global mainline mainlinearrow sidelines lthickness colormap canv
788787

789-
$canv delete lines.$id
788+
if {$delold} {
789+
$canv delete lines.$id
790+
}
790791
if {[info exists mainline($id)]} {
791792
set t [$canv create line $mainline($id) \
792793
-width [expr {($xtra + 1) * $lthickness}] \
@@ -858,7 +859,7 @@ proc drawcommitline {level} {
858859
set mainline($id) [trimdiagstart $mainline($id)]
859860
}
860861
}
861-
drawlines $id 0
862+
drawlines $id 0 0
862863
set orad [expr {$linespc / 3}]
863864
set t [$canv create oval [expr $x - $orad] [expr $y1 - $orad] \
864865
[expr $x + $orad - 1] [expr $y1 + $orad - 1] \
@@ -878,6 +879,7 @@ proc drawcommitline {level} {
878879
set headline [lindex $commitinfo($id) 0]
879880
set name [lindex $commitinfo($id) 1]
880881
set date [lindex $commitinfo($id) 2]
882+
set date [formatdate $date]
881883
set linehtag($lineno) [$canv create text $xt $y1 -anchor w \
882884
-text $headline -font $mainfont ]
883885
$canv bind $linehtag($lineno) <Button-3> "rowmenu %X %Y $id"
@@ -1446,8 +1448,8 @@ proc decidenext {{noread 0}} {
14461448
}
14471449

14481450
proc drawcommit {id} {
1449-
global phase todo nchildren datemode nextupdate
1450-
global numcommits ncmupdate displayorder todo onscreen
1451+
global phase todo nchildren datemode nextupdate revlistorder
1452+
global numcommits ncmupdate displayorder todo onscreen parents
14511453

14521454
if {$phase != "incrdraw"} {
14531455
set phase incrdraw
@@ -1459,19 +1461,29 @@ proc drawcommit {id} {
14591461
lappend todo $id
14601462
set onscreen($id) 0
14611463
}
1462-
set level [decidenext 1]
1463-
if {$level == {} || $id != [lindex $todo $level]} {
1464-
return
1465-
}
1466-
while 1 {
1467-
lappend displayorder [lindex $todo $level]
1468-
if {[updatetodo $level $datemode]} {
1469-
set level [decidenext 1]
1470-
if {$level == {}} break
1464+
if {$revlistorder} {
1465+
set level [lsearch -exact $todo $id]
1466+
if {$level < 0} {
1467+
error_popup "oops, $id isn't in todo"
1468+
return
14711469
}
1472-
set id [lindex $todo $level]
1473-
if {![info exists commitlisted($id)]} {
1474-
break
1470+
lappend displayorder $id
1471+
updatetodo $level 0
1472+
} else {
1473+
set level [decidenext 1]
1474+
if {$level == {} || $id != [lindex $todo $level]} {
1475+
return
1476+
}
1477+
while 1 {
1478+
lappend displayorder [lindex $todo $level]
1479+
if {[updatetodo $level $datemode]} {
1480+
set level [decidenext 1]
1481+
if {$level == {}} break
1482+
}
1483+
set id [lindex $todo $level]
1484+
if {![info exists commitlisted($id)]} {
1485+
break
1486+
}
14751487
}
14761488
}
14771489
drawmore 1
@@ -1523,21 +1535,23 @@ proc drawrest {} {
15231535
global phase stopped redisplaying selectedline
15241536
global datemode todo displayorder
15251537
global numcommits ncmupdate
1526-
global nextupdate startmsecs
1527-
1528-
set level [decidenext]
1529-
if {$level >= 0} {
1530-
set phase drawgraph
1531-
while 1 {
1532-
lappend displayorder [lindex $todo $level]
1533-
set hard [updatetodo $level $datemode]
1534-
if {$hard} {
1535-
set level [decidenext]
1536-
if {$level < 0} break
1538+
global nextupdate startmsecs revlistorder
1539+
1540+
if {!$revlistorder} {
1541+
set level [decidenext]
1542+
if {$level >= 0} {
1543+
set phase drawgraph
1544+
while 1 {
1545+
lappend displayorder [lindex $todo $level]
1546+
set hard [updatetodo $level $datemode]
1547+
if {$hard} {
1548+
set level [decidenext]
1549+
if {$level < 0} break
1550+
}
15371551
}
15381552
}
1539-
drawmore 0
15401553
}
1554+
drawmore 0
15411555
set phase {}
15421556
set drawmsecs [expr [clock clicks -milliseconds] - $startmsecs]
15431557
#puts "overall $drawmsecs ms for $numcommits commits"
@@ -2146,8 +2160,10 @@ proc selectline {l isnew} {
21462160
$ctext mark set fmark.0 0.0
21472161
$ctext mark gravity fmark.0 left
21482162
set info $commitinfo($id)
2149-
$ctext insert end "Author: [lindex $info 1] [lindex $info 2]\n"
2150-
$ctext insert end "Committer: [lindex $info 3] [lindex $info 4]\n"
2163+
set date [formatdate [lindex $info 2]]
2164+
$ctext insert end "Author: [lindex $info 1] $date\n"
2165+
set date [formatdate [lindex $info 4]]
2166+
$ctext insert end "Committer: [lindex $info 3] $date\n"
21512167
if {[info exists idtags($id)]} {
21522168
$ctext insert end "Tags:"
21532169
foreach tag $idtags($id) {
@@ -3226,7 +3242,7 @@ proc lineclick {x y id isnew} {
32263242
normalline
32273243
$canv delete hover
32283244
# draw this line thicker than normal
3229-
drawlines $id 1
3245+
drawlines $id 1 1
32303246
set thickerline $id
32313247
if {$isnew} {
32323248
set ymax [lindex [$canv cget -scrollregion] 3]
@@ -3255,7 +3271,8 @@ proc lineclick {x y id isnew} {
32553271
set info $commitinfo($id)
32563272
$ctext insert end "\n\t[lindex $info 0]\n"
32573273
$ctext insert end "\tAuthor:\t[lindex $info 1]\n"
3258-
$ctext insert end "\tDate:\t[lindex $info 2]\n"
3274+
set date [formatdate [lindex $info 2]]
3275+
$ctext insert end "\tDate:\t$date\n"
32593276
if {[info exists children($id)]} {
32603277
$ctext insert end "\nChildren:"
32613278
set i 0
@@ -3267,7 +3284,8 @@ proc lineclick {x y id isnew} {
32673284
$ctext tag bind link$i <1> [list selbyid $child]
32683285
$ctext insert end "\n\t[lindex $info 0]"
32693286
$ctext insert end "\n\tAuthor:\t[lindex $info 1]"
3270-
$ctext insert end "\n\tDate:\t[lindex $info 2]\n"
3287+
set date [formatdate [lindex $info 2]]
3288+
$ctext insert end "\n\tDate:\t$date\n"
32713289
}
32723290
}
32733291
$ctext conf -state disabled
@@ -3278,7 +3296,7 @@ proc lineclick {x y id isnew} {
32783296
proc normalline {} {
32793297
global thickerline
32803298
if {[info exists thickerline]} {
3281-
drawlines $thickerline 0
3299+
drawlines $thickerline 0 1
32823300
unset thickerline
32833301
}
32843302
}
@@ -3650,6 +3668,20 @@ proc doquit {} {
36503668
destroy .
36513669
}
36523670

3671+
proc formatdate {d} {
3672+
global hours nhours tfd
3673+
3674+
set hr [expr {$d / 3600}]
3675+
set ms [expr {$d % 3600}]
3676+
if {![info exists hours($hr)]} {
3677+
set hours($hr) [clock format $d -format "%Y-%m-%d %H"]
3678+
set nhours($hr) 0
3679+
}
3680+
incr nhours($hr)
3681+
set minsec [format "%.2d:%.2d" [expr {$ms/60}] [expr {$ms%60}]]
3682+
return "$hours($hr):$minsec"
3683+
}
3684+
36533685
# defaults...
36543686
set datemode 0
36553687
set boldnames 0
@@ -3662,6 +3694,7 @@ set findmergefiles 0
36623694
set gaudydiff 0
36633695
set maxgraphpct 50
36643696
set maxwidth 16
3697+
set revlistorder 0
36653698

36663699
set colors {green red blue magenta darkgrey brown orange}
36673700

@@ -3678,6 +3711,7 @@ foreach arg $argv {
36783711
"^$" { }
36793712
"^-b" { set boldnames 1 }
36803713
"^-d" { set datemode 1 }
3714+
"^-r" { set revlistorder 1 }
36813715
default {
36823716
lappend revtreeargs $arg
36833717
}

0 commit comments

Comments
 (0)