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 field trck_spec
; # array of specifications
16 constructor new
{path
{title
{}}} {
17 global all_heads current_branch
22 labelframe $w -text $title
26 bind $w <Destroy
> [cb _delete
%W
]
28 if {$all_heads ne
{}} {
29 set c_head
$current_branch
30 radiobutton $w.head_r
\
31 -text {Local Branch
:} \
34 eval tk_optionMenu $w.head_m
@c_head
$all_heads
35 grid $w.head_r
$w.head_m
-sticky w
39 trace add
variable @c_head write
[cb _select head
]
42 set trck_list
[all_tracking_branches
]
43 if {$trck_list ne
{}} {
45 foreach spec
$trck_list {
46 set txt
[lindex $spec 0]
47 regsub ^refs
/(heads
/|remotes
/)?
$txt {} txt
48 set trck_spec
($txt) $spec
51 set nam
[lsort -unique $nam]
53 radiobutton $w.trck_r
\
54 -text {Tracking Branch
:} \
57 eval tk_optionMenu $w.trck_m
@c_trck
$nam
58 grid $w.trck_r
$w.trck_m
-sticky w
60 set c_trck
[lindex $nam 0]
64 trace add
variable @c_trck write
[cb _select trck
]
68 set all_tags
[load_all_tags
]
69 if {$all_tags ne
{}} {
70 set c_tag
[lindex $all_tags 0]
71 radiobutton $w.tag_r
\
75 eval tk_optionMenu $w.tag_m
@c_tag
$all_tags
76 grid $w.tag_r
$w.tag_m
-sticky w
80 trace add
variable @c_tag write
[cb _select tag
]
83 radiobutton $w.expr_r
\
84 -text {Revision Expression
:} \
91 -textvariable @c_expr
\
93 -validatecommand [cb _validate
%d
%S
]
94 grid $w.expr_r
$w.expr_t
-sticky we
-padx {0 5}
99 grid columnconfigure
$w 1 -weight 1
104 if {[winfo exists
$w.none_r
]} {
105 $w.none_r configure
-text $text
109 radiobutton $w.none_r
\
114 grid $w.none_r
-sticky we
-padx {0 5} -columnspan 2
115 if {$revtype eq
{}} {
122 head
{ return $c_head }
123 trck
{ return $c_trck }
124 tag
{ return $c_tag }
125 expr { return $c_expr }
127 default { error "unknown type of revision" }
131 method get_tracking_branch
{} {
132 if {$revtype eq
{trck
}} {
133 return $trck_spec($c_trck)
141 head
{ return refs
/heads
/$c_head }
142 trck
{ return [lindex $trck_spec($c_trck) 0] }
143 tag
{ return refs
/tags
/$c_tag }
144 expr { return $c_expr }
146 default { error "unknown type of revision" }
150 method get_commit
{} {
151 if {$revtype eq
{none
}} {
154 return [git rev-parse
--verify "[get_expr $this]^0"]
157 method _validate
{d S
} {
159 if {[regexp {\s
} $S]} {
162 if {[string length
$S] > 0} {
169 method _select
{value args
} {
173 method _delete
{current
} {
174 if {$current eq
$w} {