@@ -90,6 +90,15 @@ proc dorunq {} {
9090 }
9191}
9292
93+ proc reg_instance {fd} {
94+ global commfd leftover loginstance
95+
96+ set i [incr loginstance]
97+ set commfd($i ) $fd
98+ set leftover($i ) {}
99+ return $i
100+ }
101+
93102proc unmerged_files {files} {
94103 global nr_unmerged
95104
@@ -294,11 +303,11 @@ proc parseviewrevs {view revs} {
294303# Start off a git log process and arrange to read its output
295304proc start_rev_list {view} {
296305 global startmsecs commitidx viewcomplete curview
297- global commfd leftover tclencoding
306+ global tclencoding
298307 global viewargs viewargscmd viewfiles vfilelimit
299308 global showlocalchanges commitinterest
300- global viewactive loginstance viewinstances vmergeonly
301- global pending_select mainheadid
309+ global viewactive viewinstances vmergeonly
310+ global mainheadid
302311 global vcanopt vflags vrevs vorigargs
303312
304313 set startmsecs [clock clicks -milliseconds]
@@ -354,10 +363,8 @@ proc start_rev_list {view} {
354363 error_popup " [ mc " Error executing git log:" ] $err "
355364 return 0
356365 }
357- set i [incr loginstance ]
366+ set i [reg_instance $fd ]
358367 set viewinstances($view ) [list $i ]
359- set commfd($i ) $fd
360- set leftover($i ) {}
361368 if {$showlocalchanges && $mainheadid ne {}} {
362369 lappend commitinterest($mainheadid ) {dodiffindex}
363370 }
@@ -367,36 +374,63 @@ proc start_rev_list {view} {
367374 }
368375 filerun $fd [list getcommitlines $fd $i $view 0]
369376 nowbusy $view [mc " Reading" ]
370- if {$view == $curview } {
371- set pending_select $mainheadid
372- }
373377 set viewcomplete($view ) 0
374378 set viewactive($view ) 1
375379 return 1
376380}
377381
378- proc stop_rev_list {view } {
379- global commfd viewinstances leftover
382+ proc stop_instance {inst } {
383+ global commfd leftover
380384
381- foreach inst $viewinstances($view) {
382- set fd $commfd($inst)
383- catch {
384- set pid [pid $fd ]
385+ set fd $commfd($inst)
386+ catch {
387+ set pid [pid $fd ]
388+
389+ if {$::tcl_platform(platform) eq {windows}} {
390+ exec kill -f $pid
391+ } else {
385392 exec kill $pid
386393 }
387- catch {close $fd }
388- nukefile $fd
389- unset commfd($inst )
390- unset leftover($inst )
394+ }
395+ catch {close $fd }
396+ nukefile $fd
397+ unset commfd($inst )
398+ unset leftover($inst )
399+ }
400+
401+ proc stop_backends {} {
402+ global commfd
403+
404+ foreach inst [array names commfd] {
405+ stop_instance $inst
406+ }
407+ }
408+
409+ proc stop_rev_list {view} {
410+ global viewinstances
411+
412+ foreach inst $viewinstances($view) {
413+ stop_instance $inst
391414 }
392415 set viewinstances($view ) {}
393416}
394417
395- proc getcommits {} {
418+ proc reset_pending_select {selid} {
419+ global pending_select mainheadid
420+
421+ if {$selid ne {}} {
422+ set pending_select $selid
423+ } else {
424+ set pending_select $mainheadid
425+ }
426+ }
427+
428+ proc getcommits {selid} {
396429 global canv curview need_redisplay viewactive
397430
398431 initlayout
399432 if {[start_rev_list $curview ]} {
433+ reset_pending_select $selid
400434 show_status [mc " Reading commits..." ]
401435 set need_redisplay 1
402436 } else {
@@ -406,8 +440,8 @@ proc getcommits {} {
406440
407441proc updatecommits {} {
408442 global curview vcanopt vorigargs vfilelimit viewinstances
409- global viewactive viewcomplete loginstance tclencoding
410- global startmsecs commfd showneartags showlocalchanges leftover
443+ global viewactive viewcomplete tclencoding
444+ global startmsecs showneartags showlocalchanges
411445 global mainheadid pending_select
412446 global isworktree
413447 global varcid vposids vnegids vflags vrevs
@@ -468,18 +502,16 @@ proc updatecommits {} {
468502 if {$viewactive($view) == 0} {
469503 set startmsecs [clock clicks -milliseconds]
470504 }
471- set i [incr loginstance ]
505+ set i [reg_instance $fd ]
472506 lappend viewinstances($view ) $i
473- set commfd($i ) $fd
474- set leftover($i ) {}
475507 fconfigure $fd -blocking 0 -translation lf -eofchar {}
476508 if {$tclencoding != {}} {
477509 fconfigure $fd -encoding $tclencoding
478510 }
479511 filerun $fd [list getcommitlines $fd $i $view 1]
480512 incr viewactive($view )
481513 set viewcomplete($view ) 0
482- set pending_select $mainheadid
514+ reset_pending_select {}
483515 nowbusy $view " Reading"
484516 if {$showneartags } {
485517 getallcommits
@@ -491,6 +523,11 @@ proc reloadcommits {} {
491523 global showneartags treediffs commitinterest cached_commitrow
492524 global targetid
493525
526+ set selid {}
527+ if {$selectedline ne {}} {
528+ set selid $currentid
529+ }
530+
494531 if {!$viewcomplete($curview) } {
495532 stop_rev_list $curview
496533 }
@@ -509,7 +546,7 @@ proc reloadcommits {} {
509546 catch {unset cached_commitrow}
510547 catch {unset targetid}
511548 setcanvscroll
512- getcommits
549+ getcommits $selid
513550 return 0
514551}
515552
@@ -1469,8 +1506,15 @@ proc chewcommits {} {
14691506 global numcommits startmsecs
14701507
14711508 if {[info exists pending_select]} {
1472- set row [first_real_row]
1473- selectline $row 1
1509+ update
1510+ reset_pending_select {}
1511+
1512+ if {[commitinview $pending_select $curview ]} {
1513+ selectline [rowofcommit $pending_select ] 1
1514+ } else {
1515+ set row [first_real_row]
1516+ selectline $row 1
1517+ }
14741518 }
14751519 if {$commitidx($curview) > 0} {
14761520 # set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
@@ -2103,6 +2147,7 @@ proc makewindow {} {
21032147 bind . <$M1B -minus> {incrfont -1}
21042148 bind . <$M1B -KP_Subtract> {incrfont -1}
21052149 wm protocol . WM_DELETE_WINDOW doquit
2150+ bind . <Destroy> {stop_backends}
21062151 bind . <Button-1> " click %W"
21072152 bind $fstring <Key-Return> {dofind 1 1}
21082153 bind $sha1entry <Key-Return> gotocommit
@@ -3300,10 +3345,7 @@ proc showview {n} {
33003345
33013346 run refill_reflist
33023347 if {![info exists viewcomplete($n )]} {
3303- if {$selid ne {}} {
3304- set pending_select $selid
3305- }
3306- getcommits
3348+ getcommits $selid
33073349 return
33083350 }
33093351
@@ -3337,18 +3379,18 @@ proc showview {n} {
33373379 drawvisible
33383380 if {$row ne {}} {
33393381 selectline $row 0
3340- } elseif {$mainheadid ne {} && [commitinview $mainheadid $curview ]} {
3341- selectline [rowofcommit $mainheadid ] 1
33423382 } elseif {!$viewcomplete($n) } {
3343- if {$selid ne {}} {
3344- set pending_select $selid
3345- } else {
3346- set pending_select $mainheadid
3347- }
3383+ reset_pending_select $selid
33483384 } else {
3349- set row [first_real_row]
3350- if {$row < $numcommits } {
3351- selectline $row 0
3385+ reset_pending_select {}
3386+
3387+ if {[commitinview $pending_select $curview ]} {
3388+ selectline [rowofcommit $pending_select ] 1
3389+ } else {
3390+ set row [first_real_row]
3391+ if {$row < $numcommits } {
3392+ selectline $row 0
3393+ }
33523394 }
33533395 }
33543396 if {!$viewcomplete($n) } {
@@ -4011,6 +4053,7 @@ proc layoutmore {} {
40114053 }
40124054 if {[info exists pending_select] &&
40134055 [commitinview $pending_select $curview ]} {
4056+ update
40144057 selectline [rowofcommit $pending_select ] 1
40154058 }
40164059 drawvisible
@@ -4048,10 +4091,11 @@ proc dodiffindex {} {
40484091 incr lserial
40494092 set fd [open " |git diff-index --cached HEAD" r]
40504093 fconfigure $fd -blocking 0
4051- filerun $fd [list readdiffindex $fd $lserial ]
4094+ set i [reg_instance $fd ]
4095+ filerun $fd [list readdiffindex $fd $lserial $i ]
40524096}
40534097
4054- proc readdiffindex {fd serial} {
4098+ proc readdiffindex {fd serial inst } {
40554099 global mainheadid nullid nullid2 curview commitinfo commitdata lserial
40564100
40574101 set isdiff 1
@@ -4062,7 +4106,7 @@ proc readdiffindex {fd serial} {
40624106 set isdiff 0
40634107 }
40644108 # we only need to see one line and we don't really care what it says...
4065- close $fd
4109+ stop_instance $inst
40664110
40674111 if {$serial != $lserial } {
40684112 return 0
@@ -4071,7 +4115,8 @@ proc readdiffindex {fd serial} {
40714115 # now see if there are any local changes not checked in to the index
40724116 set fd [open " |git diff-files" r]
40734117 fconfigure $fd -blocking 0
4074- filerun $fd [list readdifffiles $fd $serial ]
4118+ set i [reg_instance $fd ]
4119+ filerun $fd [list readdifffiles $fd $serial $i ]
40754120
40764121 if {$isdiff && ![commitinview $nullid2 $curview ]} {
40774122 # add the line for the changes in the index to the graph
@@ -4088,7 +4133,7 @@ proc readdiffindex {fd serial} {
40884133 return 0
40894134}
40904135
4091- proc readdifffiles {fd serial} {
4136+ proc readdifffiles {fd serial inst } {
40924137 global mainheadid nullid nullid2 curview
40934138 global commitinfo commitdata lserial
40944139
@@ -4100,7 +4145,7 @@ proc readdifffiles {fd serial} {
41004145 set isdiff 0
41014146 }
41024147 # we only need to see one line and we don't really care what it says...
4103- close $fd
4148+ stop_instance $inst
41044149
41054150 if {$serial != $lserial } {
41064151 return 0
@@ -6430,9 +6475,10 @@ proc diffcmd {ids flags} {
64306475proc gettreediffs {ids} {
64316476 global treediff treepending
64326477
6478+ if {[catch {set gdtf [open [diffcmd $ids {--no-commit-id}] r]}]} return
6479+
64336480 set treepending $ids
64346481 set treediff {}
6435- if {[catch {set gdtf [open [diffcmd $ids {--no-commit-id}] r]}]} return
64366482 fconfigure $gdtf -blocking 0
64376483 filerun $gdtf [list gettreediffline $gdtf $ids ]
64386484}
@@ -9945,4 +9991,4 @@ if {[info exists permviews]} {
99459991 addviewmenu $n
99469992 }
99479993}
9948- getcommits
9994+ getcommits {}
0 commit comments