@matheusbsbs / matheus-bagliano / commits / 350a35f0a1
Fork 0

git-gui: Replace merge dialog with our revision picker widget

Now that we only support merging one branch we can offer the user a better user interface experience by allowing them to select the revision they want to merge through our revision picking widget. This change neatly solves the problem of locating a branch out of a sea of 200 tracking branches, and of dealing with very long branch names that all have a common prefix. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jul 25, 2007 at 03:44 UTC 350a35f0a17af071af3f6f76d9fc6f63265b23d2
1 file changed +11 -70
lib/merge.tcl
+11 -70
@@ -4,8 +4,7 @@
4 class merge {
5
6 field w ; # top level window
7 -field w_list ; # widget of available branches
8 -field list ; # list of available branches
7 +field w_rev ; # mega-widget to pick the revision to merge
8
9 method _can_merge {} {
10 global HEAD commit_type file_states
@@ -68,11 +67,10 @@ You should complete the current commit before starting a merge. Doing so will h
67 }
68
69 method _rev {} {
71 - set i [$w_list curselection]
72 - if {$i >= 0} {
73 - return [lindex [lindex $list $i] 0]
70 + if {[catch {$w_rev commit_or_die}]} {
71 + return {}
72 }
75 - return {}
73 + return [$w_rev get]
74 }
75
76 method _visualize {} {
@@ -121,38 +119,6 @@ constructor dialog {} {
119 return
120 }
121
124 - set fmt {list %(objectname) %(*objectname) %(refname) %(subject)}
125 - set fr_fd [git_read for-each-ref \
126 - --tcl \
127 - --format=$fmt \
128 - refs/heads \
129 - refs/remotes \
130 - refs/tags \
131 - ]
132 - fconfigure $fr_fd -translation binary
133 - while {[gets $fr_fd line] > 0} {
134 - set line [eval $line]
135 - set ref [lindex $line 2]
136 - regsub ^refs/(heads|remotes|tags)/ $ref {} ref
137 - set subj($ref) [lindex $line 3]
138 - lappend sha1([lindex $line 0]) $ref
139 - if {[lindex $line 1] ne {}} {
140 - lappend sha1([lindex $line 1]) $ref
141 - }
142 - }
143 - close $fr_fd
144 -
145 - set list [list]
146 - set fr_fd [git_read rev-list --all --not HEAD]
147 - while {[gets $fr_fd line] > 0} {
148 - if {[catch {set ref $sha1($line)}]} continue
149 - foreach n $ref {
150 - lappend list [list $n $line]
151 - }
152 - }
153 - close $fr_fd
154 - set list [lsort -unique $list]
155 -
122 make_toplevel top w
123 wm title $top "[appname] ([reponame]): Merge"
124 if {$top ne {.}} {
@@ -178,39 +144,11 @@ constructor dialog {} {
144 pack $w.buttons.cancel -side right -padx 5
145 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
146
181 - labelframe $w.source -text {Source Branches}
182 - set w_list $w.source.l
183 - listbox $w_list \
184 - -height 10 \
185 - -width 70 \
186 - -font font_diff \
187 - -selectmode browse \
188 - -yscrollcommand [list $w.source.sby set]
189 - scrollbar $w.source.sby -command [list $w_list yview]
190 - pack $w.source.sby -side right -fill y
191 - pack $w_list -side left -fill both -expand 1
192 - pack $w.source -fill both -expand 1 -pady 5 -padx 5
193 -
194 - foreach ref $list {
195 - set n [lindex $ref 0]
196 - if {[string length $n] > 20} {
197 - set n "[string range $n 0 16]..."
198 - }
199 - $w_list insert end [format {%s %-20s %s} \
200 - [string range [lindex $ref 1] 0 5] \
201 - $n \
202 - $subj([lindex $ref 0])]
203 - }
204 -
205 - bind $w_list <Key-K> [list event generate %W <Shift-Key-Up>]
206 - bind $w_list <Key-J> [list event generate %W <Shift-Key-Down>]
207 - bind $w_list <Key-k> [list event generate %W <Key-Up>]
208 - bind $w_list <Key-j> [list event generate %W <Key-Down>]
209 - bind $w_list <Key-h> [list event generate %W <Key-Left>]
210 - bind $w_list <Key-l> [list event generate %W <Key-Right>]
211 - bind $w_list <Key-v> $_visualize
147 + set w_rev [::choose_rev::new_unmerged $w.rev {Revision To Merge}]
148 + pack $w.rev -anchor nw -fill both -expand 1 -pady 5 -padx 5
149
150 bind $w <$M1B-Key-Return> $_start
151 + bind $w <Key-Return> $_start
152 bind $w <Visibility> [cb _visible]
153 bind $w <Key-Escape> [cb _cancel]
154 wm protocol $w WM_DELETE_WINDOW [cb _cancel]
@@ -219,7 +157,10 @@ constructor dialog {} {
157
158 method _visible {} {
159 grab $w
222 - focus $w_list
160 + if {[is_config_true gui.matchtrackingbranch]} {
161 + $w_rev pick_tracking_branch
162 + }
163 + $w_rev focus_filter
164 }
165
166 method _cancel {} {