gitk: Recompute ancestor/descendent heads/tags when rereading refs
We weren't updating the desc_heads, desc_tags and anc_tags arrays when rereading the set of heads/tags/etc. The tricky thing to get right here is restarting the computation correctly when we are only half-way through it. Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras committed
Aug 2, 2006 at 09:38 UTC
cec7bece83a42918457819b526c49c7d55f795c5
1 file changed
+85
-47
gitk
+85
-47
@@ -4932,7 +4932,7 @@ proc domktag {} {
4932
4933
proc redrawtags {id} {
4934
global canv linehtag commitrow idpos selectedline curview
4935
- global mainfont
4935
+ global mainfont canvxmax
4936
4937
if {![info exists commitrow($curview,$id)]} return
4938
drawcmitrow $commitrow($curview,$id)
@@ -5020,8 +5020,9 @@ proc wrcomcan {} {
5020
5021
# Stuff for finding nearby tags
5022
proc getallcommits {} {
5023
- global allcstart allcommits allcfd
5023
+ global allcstart allcommits allcfd allids
5024
5025
+ set allids {}
5026
set fd [open [concat | git rev-list --all --topo-order --parents] r]
5027
set allcfd $fd
5028
fconfigure $fd -blocking 0
@@ -5105,10 +5106,52 @@ proc combine_atags {l1 l2} {
5106
return $res
5107
}
5108
5109
+proc forward_pass {id children} {
5110
+ global idtags desc_tags idheads desc_heads alldtags tagisdesc
5111
+
5112
+ set dtags {}
5113
+ set dheads {}
5114
+ foreach child $children {
5115
+ if {[info exists idtags($child)]} {
5116
+ set ctags [list $child]
5117
+ } else {
5118
+ set ctags $desc_tags($child)
5119
+ }
5120
+ if {$dtags eq {}} {
5121
+ set dtags $ctags
5122
+ } elseif {$ctags ne $dtags} {
5123
+ set dtags [combine_dtags $dtags $ctags]
5124
+ }
5125
+ set cheads $desc_heads($child)
5126
+ if {$dheads eq {}} {
5127
+ set dheads $cheads
5128
+ } elseif {$cheads ne $dheads} {
5129
+ set dheads [lsort -unique [concat $dheads $cheads]]
5130
+ }
5131
+ }
5132
+ set desc_tags($id) $dtags
5133
+ if {[info exists idtags($id)]} {
5134
+ set adt $dtags
5135
+ foreach tag $dtags {
5136
+ set adt [concat $adt $alldtags($tag)]
5137
+ }
5138
+ set adt [lsort -unique $adt]
5139
+ set alldtags($id) $adt
5140
+ foreach tag $adt {
5141
+ set tagisdesc($id,$tag) -1
5142
+ set tagisdesc($tag,$id) 1
5143
+ }
5144
+ }
5145
+ if {[info exists idheads($id)]} {
5146
+ lappend dheads $id
5147
+ }
5148
+ set desc_heads($id) $dheads
5149
+}
5150
+
5151
proc getallclines {fd} {
5152
global allparents allchildren allcommits allcstart
5110
- global desc_tags anc_tags idtags alldtags tagisdesc allids
5111
- global desc_heads idheads
5153
+ global desc_tags anc_tags idtags tagisdesc allids
5154
+ global desc_heads idheads travindex
5155
5156
while {[gets $fd line] >= 0} {
5157
set id [lindex $line 0]
@@ -5123,43 +5166,7 @@ proc getallclines {fd} {
5166
}
5167
# compute nearest tagged descendents as we go
5168
# also compute descendent heads
5126
- set dtags {}
5127
- set dheads {}
5128
- foreach child $allchildren($id) {
5129
- if {[info exists idtags($child)]} {
5130
- set ctags [list $child]
5131
- } else {
5132
- set ctags $desc_tags($child)
5133
- }
5134
- if {$dtags eq {}} {
5135
- set dtags $ctags
5136
- } elseif {$ctags ne $dtags} {
5137
- set dtags [combine_dtags $dtags $ctags]
5138
- }
5139
- set cheads $desc_heads($child)
5140
- if {$dheads eq {}} {
5141
- set dheads $cheads
5142
- } elseif {$cheads ne $dheads} {
5143
- set dheads [lsort -unique [concat $dheads $cheads]]
5144
- }
5145
- }
5146
- set desc_tags($id) $dtags
5147
- if {[info exists idtags($id)]} {
5148
- set adt $dtags
5149
- foreach tag $dtags {
5150
- set adt [concat $adt $alldtags($tag)]
5151
- }
5152
- set adt [lsort -unique $adt]
5153
- set alldtags($id) $adt
5154
- foreach tag $adt {
5155
- set tagisdesc($id,$tag) -1
5156
- set tagisdesc($tag,$id) 1
5157
- }
5158
- }
5159
- if {[info exists idheads($id)]} {
5160
- lappend dheads $id
5161
- }
5162
- set desc_heads($id) $dheads
5169
+ forward_pass $id $allchildren($id)
5170
if {[clock clicks -milliseconds] - $allcstart >= 50} {
5171
fileevent $fd readable {}
5172
after idle restartgetall $fd
@@ -5167,7 +5174,9 @@ proc getallclines {fd} {
5174
}
5175
}
5176
if {[eof $fd]} {
5170
- after idle restartatags [llength $allids]
5177
+ set travindex [llength $allids]
5178
+ set allcommits "traversing"
5179
+ after idle restartatags
5180
if {[catch {close $fd} err]} {
5181
error_popup "Error reading full commit graph: $err.\n\
5182
Results may be incomplete."
@@ -5176,10 +5185,11 @@ proc getallclines {fd} {
5185
}
5186
5187
# walk backward through the tree and compute nearest tagged ancestors
5179
-proc restartatags {i} {
5180
- global allids allparents idtags anc_tags t0
5188
+proc restartatags {} {
5189
+ global allids allparents idtags anc_tags travindex
5190
5191
set t0 [clock clicks -milliseconds]
5192
+ set i $travindex
5193
while {[incr i -1] >= 0} {
5194
set id [lindex $allids $i]
5195
set atags {}
@@ -5197,17 +5207,41 @@ proc restartatags {i} {
5207
}
5208
set anc_tags($id) $atags
5209
if {[clock clicks -milliseconds] - $t0 >= 50} {
5200
- after idle restartatags $i
5210
+ set travindex $i
5211
+ after idle restartatags
5212
return
5213
}
5214
}
5215
set allcommits "done"
5216
+ set travindex 0
5217
notbusy allcommits
5218
dispneartags
5219
}
5220
5221
+proc changedrefs {} {
5222
+ global desc_heads desc_tags anc_tags allcommits allids
5223
+ global allchildren allparents idtags travindex
5224
+
5225
+ if {![info exists allcommits]} return
5226
+ catch {unset desc_heads}
5227
+ catch {unset desc_tags}
5228
+ catch {unset anc_tags}
5229
+ catch {unset alldtags}
5230
+ catch {unset tagisdesc}
5231
+ foreach id $allids {
5232
+ forward_pass $id $allchildren($id)
5233
+ }
5234
+ if {$allcommits ne "reading"} {
5235
+ set travindex [llength $allids]
5236
+ if {$allcommits ne "traversing"} {
5237
+ set allcommits "traversing"
5238
+ after idle restartatags
5239
+ }
5240
+ }
5241
+}
5242
+
5243
proc rereadrefs {} {
5210
- global idtags idheads idotherrefs
5244
+ global idtags idheads idotherrefs mainhead
5245
5246
set refids [concat [array names idtags] \
5247
[array names idheads] [array names idotherrefs]]
@@ -5216,12 +5250,16 @@ proc rereadrefs {} {
5250
set ref($id) [listrefs $id]
5251
}
5252
}
5253
+ set oldmainhead $mainhead
5254
readrefs
5255
+ changedrefs
5256
set refids [lsort -unique [concat $refids [array names idtags] \
5257
[array names idheads] [array names idotherrefs]]]
5258
foreach id $refids {
5259
set v [listrefs $id]
5224
- if {![info exists ref($id)] || $ref($id) != $v} {
5260
+ if {![info exists ref($id)] || $ref($id) != $v ||
5261
+ ($id eq $oldmainhead && $id ne $mainhead) ||
5262
+ ($id eq $mainhead && $id ne $oldmainhead)} {
5263
redrawtags $id
5264
}
5265
}