git-gui: Display commit/tag/remote info in tooltip of revision picker
Our revision chooser mega-widget now sets up tooltips for itself so that it displays details about a commit (or a tag and the commit it refers to) when the user mouses over that line in the filtered ref list. If the item is from a remote tracking branch then we also show the remote url and what branch on that remote we fetch from, so the user has a clear concept of where that revision data originated. To help the merge dialog I've also added a new constructor that makes the dialog only offer unmerged revisions (those not in HEAD), as this allows users to avoid performing merges only to get "Already up to date" messages back from core Git. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Jul 25, 2007 at 04:13 UTC
844c3f6fe9d4d2bdc4e76f6a3bf3dfe86ce8c544
1 file changed
+230
-6
lib/choose_rev.tcl
+230
-6
@@ -16,8 +16,21 @@ field cur_specs [list]; # list of specs for $revtype
16
field spec_head ; # list of all head specs
17
field spec_trck ; # list of all tracking branch specs
18
field spec_tag ; # list of all tag specs
19
+field tip_data ; # array of tip commit info by refname
20
20
-constructor new {path {title {}}} {
21
+field tooltip_wm {} ; # Current tooltip toplevel, if open
22
+field tooltip_t {} ; # Text widget in $tooltip_wm
23
+field tooltip_timer {} ; # Current timer event for our tooltip
24
+
25
+proc new {path {title {}}} {
26
+ return [_new $path 0 $title]
27
+}
28
+
29
+proc new_unmerged {path {title {}}} {
30
+ return [_new $path 1 $title]
31
+}
32
+
33
+constructor _new {path unmerged_only title} {
34
global current_branch is_detached
35
36
set w $path
@@ -93,6 +106,10 @@ constructor new {path {title {}}} {
106
-yscrollcommand [cb _sb_set $w.list.sby v]
107
pack $w_list -fill both -expand 1
108
grid $w.list -sticky nswe -padx {20 5} -columnspan 2
109
+ bind $w_list <Any-Motion> [cb _show_tooltip @%x,%y]
110
+ bind $w_list <Any-Enter> [cb _hide_tooltip]
111
+ bind $w_list <Any-Leave> [cb _hide_tooltip]
112
+ bind $w_list <Destroy> [cb _hide_tooltip]
113
114
grid columnconfigure $w 1 -weight 1
115
if {$is_detached} {
@@ -105,21 +122,89 @@ constructor new {path {title {}}} {
122
bind $w_filter <Key-Return> [list focus $w_list]\;break
123
bind $w_filter <Key-Down> [list focus $w_list]
124
125
+ set fmt list
126
+ append fmt { %(refname)}
127
+ append fmt { [list}
128
+ append fmt { %(objecttype)}
129
+ append fmt { %(objectname)}
130
+ append fmt { [concat %(taggername) %(authorname)]}
131
+ append fmt { [concat %(taggerdate) %(authordate)]}
132
+ append fmt { %(subject)}
133
+ append fmt {] [list}
134
+ append fmt { %(*objecttype)}
135
+ append fmt { %(*objectname)}
136
+ append fmt { %(*authorname)}
137
+ append fmt { %(*authordate)}
138
+ append fmt { %(*subject)}
139
+ append fmt {]}
140
+ set all_refn [list]
141
+ set fr_fd [git_read for-each-ref \
142
+ --tcl \
143
+ --sort=-taggerdate \
144
+ --format=$fmt \
145
+ refs/heads \
146
+ refs/remotes \
147
+ refs/tags \
148
+ ]
149
+ fconfigure $fr_fd -translation lf -encoding utf-8
150
+ while {[gets $fr_fd line] > 0} {
151
+ set line [eval $line]
152
+ if {[lindex $line 1 0] eq {tag}} {
153
+ if {[lindex $line 2 0] eq {commit}} {
154
+ set sha1 [lindex $line 2 1]
155
+ } else {
156
+ continue
157
+ }
158
+ } elseif {[lindex $line 1 0] eq {commit}} {
159
+ set sha1 [lindex $line 1 1]
160
+ } else {
161
+ continue
162
+ }
163
+ set refn [lindex $line 0]
164
+ set tip_data($refn) [lrange $line 1 end]
165
+ lappend cmt_refn($sha1) $refn
166
+ lappend all_refn $refn
167
+ }
168
+ close $fr_fd
169
+
170
+ if {$unmerged_only} {
171
+ set fr_fd [git_read rev-list --all ^$::HEAD]
172
+ while {[gets $fr_fd sha1] > 0} {
173
+ if {[catch {set rlst $cmt_refn($sha1)}]} continue
174
+ foreach refn $rlst {
175
+ set inc($refn) 1
176
+ }
177
+ }
178
+ close $fr_fd
179
+ } else {
180
+ foreach refn $all_refn {
181
+ set inc($refn) 1
182
+ }
183
+ }
184
+
185
set spec_head [list]
186
foreach name [load_all_heads] {
110
- lappend spec_head [list $name refs/heads/$name]
187
+ set refn refs/heads/$name
188
+ if {[info exists inc($refn)]} {
189
+ lappend spec_head [list $name $refn]
190
+ }
191
}
192
193
set spec_trck [list]
194
foreach spec [all_tracking_branches] {
115
- set name [lindex $spec 0]
116
- regsub ^refs/(heads|remotes)/ $name {} name
117
- lappend spec_trck [concat $name $spec]
195
+ set refn [lindex $spec 0]
196
+ if {[info exists inc($refn)]} {
197
+ regsub ^refs/(heads|remotes)/ $refn {} name
198
+ lappend spec_trck [concat $name $spec]
199
+ }
200
}
201
202
set spec_tag [list]
203
foreach name [load_all_tags] {
122
- lappend spec_tag [list $name refs/tags/$name]
204
+ set refn refs/tags/$name
205
+ if {[info exists inc($refn)]} {
206
+ lappend spec_tag [list $name $refn]
207
+ }
208
}
209
210
if {$is_detached} { set revtype HEAD
@@ -364,4 +449,143 @@ method _sb_set {sb orient first last} {
449
$sb set $first $last
450
}
451
452
+method _show_tooltip {pos} {
453
+ if {$tooltip_wm ne {}} {
454
+ _open_tooltip $this
455
+ } elseif {$tooltip_timer eq {}} {
456
+ set tooltip_timer [after 1000 [cb _open_tooltip]]
457
+ }
458
+}
459
+
460
+method _open_tooltip {} {
461
+ global remote_url
462
+
463
+ set tooltip_timer {}
464
+ set pos_x [winfo pointerx $w_list]
465
+ set pos_y [winfo pointery $w_list]
466
+ if {[winfo containing $pos_x $pos_y] ne $w_list} {
467
+ _hide_tooltip $this
468
+ return
469
+ }
470
+
471
+ set pos @[join [list \
472
+ [expr {$pos_x - [winfo rootx $w_list]}] \
473
+ [expr {$pos_y - [winfo rooty $w_list]}]] ,]
474
+ set lno [$w_list index $pos]
475
+ if {$lno eq {}} {
476
+ _hide_tooltip $this
477
+ return
478
+ }
479
+
480
+ set spec [lindex $cur_specs $lno]
481
+ set refn [lindex $spec 1]
482
+ if {$refn eq {}} {
483
+ _hide_tooltip $this
484
+ return
485
+ }
486
+
487
+ if {$tooltip_wm eq {}} {
488
+ set tooltip_wm [toplevel $w_list.tooltip -borderwidth 1]
489
+ wm overrideredirect $tooltip_wm 1
490
+ wm transient $tooltip_wm [winfo toplevel $w_list]
491
+ set tooltip_t $tooltip_wm.label
492
+ text $tooltip_t \
493
+ -takefocus 0 \
494
+ -highlightthickness 0 \
495
+ -relief flat \
496
+ -borderwidth 0 \
497
+ -wrap none \
498
+ -background lightyellow \
499
+ -foreground black
500
+ $tooltip_t tag conf section_header -font font_uibold
501
+ bind $tooltip_wm <Escape> [cb _hide_tooltip]
502
+ pack $tooltip_t
503
+ } else {
504
+ $tooltip_t conf -state normal
505
+ $tooltip_t delete 0.0 end
506
+ }
507
+
508
+ set data $tip_data($refn)
509
+ if {[lindex $data 0 0] eq {tag}} {
510
+ set tag [lindex $data 0]
511
+ if {[lindex $data 1 0] eq {commit}} {
512
+ set cmit [lindex $data 1]
513
+ } else {
514
+ set cmit {}
515
+ }
516
+ } elseif {[lindex $data 0 0] eq {commit}} {
517
+ set tag {}
518
+ set cmit [lindex $data 0]
519
+ }
520
+
521
+ $tooltip_t insert end "[lindex $spec 0]\n"
522
+
523
+ if {$tag ne {}} {
524
+ $tooltip_t insert end "\n"
525
+ $tooltip_t insert end "tag" section_header
526
+ $tooltip_t insert end " [lindex $tag 1]\n"
527
+ $tooltip_t insert end [lindex $tag 2]
528
+ $tooltip_t insert end " ([lindex $tag 3])\n"
529
+ $tooltip_t insert end [lindex $tag 4]
530
+ $tooltip_t insert end "\n"
531
+ }
532
+
533
+ if {$cmit ne {}} {
534
+ $tooltip_t insert end "\n"
535
+ $tooltip_t insert end "commit" section_header
536
+ $tooltip_t insert end " [lindex $cmit 1]\n"
537
+ $tooltip_t insert end [lindex $cmit 2]
538
+ $tooltip_t insert end " ([lindex $cmit 3])\n"
539
+ $tooltip_t insert end [lindex $cmit 4]
540
+ }
541
+
542
+ if {[llength $spec] > 2} {
543
+ $tooltip_t insert end "\n"
544
+ $tooltip_t insert end "remote" section_header
545
+ $tooltip_t insert end " [lindex $spec 2]\n"
546
+ $tooltip_t insert end "url"
547
+ $tooltip_t insert end " $remote_url([lindex $spec 2])\n"
548
+ $tooltip_t insert end "branch"
549
+ $tooltip_t insert end " [lindex $spec 3]"
550
+ }
551
+
552
+ $tooltip_t conf -state disabled
553
+ _position_tooltip $this
554
+}
555
+
556
+method _position_tooltip {} {
557
+ set max_h [lindex [split [$tooltip_t index end] .] 0]
558
+ set max_w 0
559
+ for {set i 1} {$i <= $max_h} {incr i} {
560
+ set c [lindex [split [$tooltip_t index "$i.0 lineend"] .] 1]
561
+ if {$c > $max_w} {set max_w $c}
562
+ }
563
+ $tooltip_t conf -width $max_w -height $max_h
564
+
565
+ set req_w [winfo reqwidth $tooltip_t]
566
+ set req_h [winfo reqheight $tooltip_t]
567
+ set pos_x [expr {[winfo pointerx .] + 5}]
568
+ set pos_y [expr {[winfo pointery .] + 10}]
569
+
570
+ set g "${req_w}x${req_h}"
571
+ if {$pos_x >= 0} {append g +}
572
+ append g $pos_x
573
+ if {$pos_y >= 0} {append g +}
574
+ append g $pos_y
575
+
576
+ wm geometry $tooltip_wm $g
577
+ raise $tooltip_wm
578
+}
579
+
580
+method _hide_tooltip {} {
581
+ if {$tooltip_wm ne {}} {
582
+ destroy $tooltip_wm
583
+ set tooltip_wm {}
584
+ }
585
+ if {$tooltip_timer ne {}} {
586
+ after cancel $tooltip_timer
587
+ set tooltip_timer {}
588
+ }
589
+}
590
+
591
}