[PATCH] gitk: add Update menu item.
Update will redraw the commits if any commits have been added to any of the selected heads. The new commits appear on the top. Signed-off-by: Sven Verdoolaege <skimo@kotnet.org> Signed-off-by: Paul Mackerras <paulus@samba.org>
Sven Verdoolaege committed
Nov 29, 2005 at 22:15 UTC
b5c2f30689d66761ce4e8a5e69c9924c0c389233
1 file changed
+142
-34
gitk
+142
-34
@@ -16,8 +16,24 @@ proc gitdir {} {
16
}
17
}
18
19
+proc parse_args {rargs} {
20
+ global parsed_args
21
+
22
+ if [catch {
23
+ set parse_args [concat --default HEAD $rargs]
24
+ set parsed_args [split [eval exec git-rev-parse $parse_args] "\n"]
25
+ }] {
26
+ # if git-rev-parse failed for some reason...
27
+ if {$rargs == {}} {
28
+ set rargs HEAD
29
+ }
30
+ set parsed_args $rargs
31
+ }
32
+ return $parsed_args
33
+}
34
+
35
proc getcommits {rargs} {
20
- global commits commfd phase canv mainfont env
36
+ global oldcommits commits commfd phase canv mainfont env
37
global startmsecs nextupdate ncmupdate
38
global ctext maincursor textcursor leftover gitencoding
39
@@ -27,21 +43,13 @@ proc getcommits {rargs} {
43
error_popup "Cannot find the git directory \"$gitdir\"."
44
exit 1
45
}
46
+ set oldcommits {}
47
set commits {}
48
set phase getcommits
49
set startmsecs [clock clicks -milliseconds]
50
set nextupdate [expr {$startmsecs + 100}]
51
set ncmupdate 1
35
- if [catch {
36
- set parse_args [concat --default HEAD $rargs]
37
- set parsed_args [split [eval exec git-rev-parse $parse_args] "\n"]
38
- }] {
39
- # if git-rev-parse failed for some reason...
40
- if {$rargs == {}} {
41
- set rargs HEAD
42
- }
43
- set parsed_args $rargs
44
- }
52
+ set parsed_args [parse_args $rargs]
53
if [catch {
54
set commfd [open "|git-rev-list --header --topo-order --parents $parsed_args" r]
55
} err] {
@@ -59,9 +67,10 @@ proc getcommits {rargs} {
67
}
68
69
proc getcommitlines {commfd} {
62
- global commits parents cdate children
70
+ global oldcommits commits parents cdate children nchildren
71
global commitlisted phase nextupdate
72
global stopped redisplaying leftover
73
+ global canv
74
75
set stuff [read $commfd]
76
if {$stuff == {}} {
@@ -119,10 +128,18 @@ proc getcommitlines {commfd} {
128
set id [lindex $ids 0]
129
set olds [lrange $ids 1 end]
130
set cmit [string range $cmit [expr {$j + 1}] end]
131
+ if {$phase == "updatecommits"} {
132
+ $canv delete all
133
+ set oldcommits $commits
134
+ set commits {}
135
+ unset children
136
+ unset nchildren
137
+ set phase getcommits
138
+ }
139
lappend commits $id
140
set commitlisted($id) 1
141
parsecommit $id $cmit 1 [lrange $ids 1 end]
125
- drawcommit $id
142
+ drawcommit $id 1
143
if {[clock clicks -milliseconds] >= $nextupdate} {
144
doupdate 1
145
}
@@ -132,7 +149,7 @@ proc getcommitlines {commfd} {
149
set stopped 0
150
set phase "getcommits"
151
foreach id $commits {
135
- drawcommit $id
152
+ drawcommit $id 1
153
if {$stopped} break
154
if {[clock clicks -milliseconds] >= $nextupdate} {
155
doupdate 1
@@ -168,16 +185,9 @@ proc readcommit {id} {
185
parsecommit $id $contents 0 {}
186
}
187
171
-proc parsecommit {id contents listed olds} {
172
- global commitinfo children nchildren parents nparents cdate ncleft
188
+proc updatechildren {id olds} {
189
+ global children nchildren parents nparents ncleft
190
174
- set inhdr 1
175
- set comment {}
176
- set headline {}
177
- set auname {}
178
- set audate {}
179
- set comname {}
180
- set comdate {}
191
if {![info exists nchildren($id)]} {
192
set children($id) {}
193
set nchildren($id) 0
@@ -196,6 +206,19 @@ proc parsecommit {id contents listed olds} {
206
incr ncleft($p)
207
}
208
}
209
+}
210
+
211
+proc parsecommit {id contents listed olds} {
212
+ global commitinfo cdate
213
+
214
+ set inhdr 1
215
+ set comment {}
216
+ set headline {}
217
+ set auname {}
218
+ set audate {}
219
+ set comname {}
220
+ set comdate {}
221
+ updatechildren $id $olds
222
set hdrend [string first "\n\n" $contents]
223
if {$hdrend < 0} {
224
# should never happen...
@@ -243,6 +266,9 @@ proc readrefs {} {
266
global tagids idtags headids idheads tagcontents
267
global otherrefids idotherrefs
268
269
+ foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
270
+ catch {unset $v}
271
+ }
272
set refd [open [list | git-ls-remote [gitdir]] r]
273
while {0 <= [set n [gets $refd line]]} {
274
if {![regexp {^([0-9a-f]{40}) refs/([^^]*)$} $line \
@@ -292,7 +318,7 @@ proc error_popup msg {
318
tkwait window $w
319
}
320
295
-proc makewindow {} {
321
+proc makewindow {rargs} {
322
global canv canv2 canv3 linespc charspc ctext cflist textfont
323
global findtype findtypemenu findloc findstring fstring geometry
324
global entries sha1entry sha1string sha1but
@@ -302,6 +328,7 @@ proc makewindow {} {
328
menu .bar
329
.bar add cascade -label "File" -menu .bar.file
330
menu .bar.file
331
+ .bar.file add command -label "Update" -command [list updatecommits $rargs]
332
.bar.file add command -label "Reread references" -command rereadrefs
333
.bar.file add command -label "Quit" -command doquit
334
menu .bar.edit
@@ -1412,8 +1439,9 @@ proc decidenext {{noread 0}} {
1439
return $level
1440
}
1441
1415
-proc drawcommit {id} {
1442
+proc drawcommit {id reading} {
1443
global phase todo nchildren datemode nextupdate revlistorder
1444
+ global numcommits ncmupdate displayorder todo onscreen
1445
global numcommits ncmupdate displayorder todo onscreen parents
1446
1447
if {$phase != "incrdraw"} {
@@ -1451,20 +1479,29 @@ proc drawcommit {id} {
1479
}
1480
}
1481
}
1454
- drawmore 1
1482
+ drawmore $reading
1483
}
1484
1485
proc finishcommits {} {
1458
- global phase
1486
+ global phase oldcommits commits
1487
global canv mainfont ctext maincursor textcursor
1488
+ global parents
1489
1461
- if {$phase != "incrdraw"} {
1490
+ if {$phase == "incrdraw" || $phase == "removecommits"} {
1491
+ foreach id $oldcommits {
1492
+ lappend commits $id
1493
+ updatechildren $id $parents($id)
1494
+ drawcommit $id 0
1495
+ }
1496
+ set oldcommits {}
1497
+ drawrest
1498
+ } elseif {$phase == "updatecommits"} {
1499
+ set phase {}
1500
+ } else {
1501
$canv delete all
1502
$canv create text 3 3 -anchor nw -text "No commits selected" \
1503
-font $mainfont -tags textitems
1504
set phase {}
1466
- } else {
1467
- drawrest
1505
}
1506
. config -cursor $maincursor
1507
settextcursor $textcursor
@@ -3578,9 +3615,6 @@ proc rereadrefs {} {
3615
set ref($id) [listrefs $id]
3616
}
3617
}
3581
- foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
3582
- catch {unset $v}
3583
- }
3618
readrefs
3619
set refids [lsort -unique [concat $refids [array names idtags] \
3620
[array names idheads] [array names idotherrefs]]]
@@ -3592,6 +3626,80 @@ proc rereadrefs {} {
3626
}
3627
}
3628
3629
+proc updatecommits {rargs} {
3630
+ global commitlisted commfd phase
3631
+ global startmsecs nextupdate ncmupdate
3632
+ global idtags idheads idotherrefs
3633
+ global leftover
3634
+ global parsed_args
3635
+ global canv
3636
+ global oldcommits commits
3637
+ global parents nchildren children ncleft
3638
+
3639
+ set old_args $parsed_args
3640
+ parse_args $rargs
3641
+
3642
+ foreach id $old_args {
3643
+ if {![regexp {^[0-9a-f]{40}$} $id]} continue
3644
+ if {[info exists oldref($id)]} continue
3645
+ set oldref($id) $id
3646
+ lappend ignoreold "^$id"
3647
+ }
3648
+ foreach id $parsed_args {
3649
+ if {![regexp {^[0-9a-f]{40}$} $id]} continue
3650
+ if {[info exists ref($id)]} continue
3651
+ set ref($id) $id
3652
+ lappend ignorenew "^$id"
3653
+ }
3654
+
3655
+ foreach a $old_args {
3656
+ if {![info exists ref($a)]} {
3657
+ lappend ignorenew $a
3658
+ }
3659
+ }
3660
+
3661
+ set phase updatecommits
3662
+ set removed_commits [split [eval exec git-rev-list $ignorenew] "\n" ]
3663
+ if {[llength $removed_commits] > 0} {
3664
+ $canv delete all
3665
+ set oldcommits {}
3666
+ foreach c $commits {
3667
+ if {[lsearch $c $removed_commits] < 0} {
3668
+ lappend oldcommits $c
3669
+ } else {
3670
+ unset commitlisted($c)
3671
+ }
3672
+ }
3673
+ set commits {}
3674
+ unset children
3675
+ unset nchildren
3676
+ set phase removecommits
3677
+ }
3678
+
3679
+ set args {}
3680
+ foreach a $parsed_args {
3681
+ if {![info exists oldref($a)]} {
3682
+ lappend args $a
3683
+ }
3684
+ }
3685
+
3686
+ readrefs
3687
+ if [catch {
3688
+ set commfd [open "|git-rev-list --header --topo-order --parents $ignoreold $args" r]
3689
+ } err] {
3690
+ puts stderr "Error executing git-rev-list: $err"
3691
+ exit 1
3692
+ }
3693
+ set startmsecs [clock clicks -milliseconds]
3694
+ set nextupdate [expr $startmsecs + 100]
3695
+ set ncmupdate 1
3696
+ set leftover {}
3697
+ fconfigure $commfd -blocking 0 -translation lf
3698
+ fileevent $commfd readable [list getcommitlines $commfd]
3699
+ . config -cursor watch
3700
+ settextcursor watch
3701
+}
3702
+
3703
proc showtag {tag isnew} {
3704
global ctext cflist tagcontents tagids linknum
3705
@@ -3738,6 +3846,6 @@ set redisplaying 0
3846
set stuffsaved 0
3847
set patchnum 0
3848
setcoords
3741
-makewindow
3849
+makewindow $revtreeargs
3850
readrefs
3851
getcommits $revtreeargs