1 # git-gui revision chooser
2 # Copyright (C) 2006, 2007 Shawn Pearce
6 field w ; # our megawidget path
7 field revtype {}; # type of revision chosen
9 field c_head {}; # selected local branch head
10 field c_trck {}; # selected tracking branch
11 field c_tag {}; # selected tag
12 field c_expr {}; # current revision expression
14 constructor new {path {title {}}} {
15 global all_heads current_branch
20 labelframe $w -text $title
24 bind $w <Destroy> [cb _delete %W]
26 if {$all_heads ne {}} {
27 set c_head $current_branch
28 radiobutton $w.head_r \
29 -text {Local Branch:} \
32 eval tk_optionMenu $w.head_m @c_head $all_heads
33 grid $w.head_r $w.head_m -sticky w
37 trace add variable @c_head write [cb _select head]
40 set all_trackings [all_tracking_branches]
41 if {$all_trackings ne {}} {
42 set c_trck [lindex $all_trackings 0]
43 radiobutton $w.trck_r \
44 -text {Tracking Branch:} \
47 eval tk_optionMenu $w.trck_m @c_trck $all_trackings
48 grid $w.trck_r $w.trck_m -sticky w
52 trace add variable @c_trck write [cb _select trck]
55 set all_tags [load_all_tags]
56 if {$all_tags ne {}} {
57 set c_tag [lindex $all_tags 0]
58 radiobutton $w.tag_r \
62 eval tk_optionMenu $w.tag_m @c_tag $all_tags
63 grid $w.tag_r $w.tag_m -sticky w
67 trace add variable @c_tag write [cb _select tag]
70 radiobutton $w.expr_r \
71 -text {Revision Expression:} \
78 -textvariable @c_expr \
80 -validatecommand [cb _validate %d %S]
81 grid $w.expr_r $w.expr_t -sticky we -padx {0 5}
86 grid columnconfigure $w 1 -weight 1
91 if {[winfo exists $w.none_r]} {
92 $w.none_r configure -text $text
96 radiobutton $w.none_r \
101 grid $w.none_r -sticky we -padx {0 5} -columnspan 2
102 if {$revtype eq {}} {
109 head { return $c_head }
110 trck { return $c_trck }
111 tag { return $c_tag }
112 expr { return $c_expr }
114 default { error "unknown type of revision" }
118 method get_commit {} {
119 if {$revtype eq {none}} {
123 return [git rev-parse --verify "${rev}^0"]
126 method _validate {d S} {
128 if {[regexp {\s} $S]} {
131 if {[string length $S] > 0} {
138 method _select {value args} {
142 method _delete {current} {
143 if {$current eq $w} {