git-gui: Include commit id/subject in merge choices
When merging branches using our local merge feature it can be handy to know the first few digits of the commit the ref points at as well as the short description of the branch name. Unfortunately I'm unable to use three listboxes in a row, as Tcl freaks out and refuses to let me have a selection in more than one of them at any given point in time. So instead we use a fixed width font in the existing listbox and organize the data into three columns. Not nearly as nice looking, but users can continue to use the listbox's features. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
May 3, 2007 at 18:21 UTC
1fc4ba86f80c1365943abac54679dd1924a6737b
1 file changed
+54
-45
lib/merge.tcl
+54
-45
@@ -63,28 +63,28 @@ You should complete the current commit before starting a merge. Doing so will h
63
return 1
64
}
65
66
-proc _visualize {w} {
67
- set revs {}
66
+proc _refs {w list} {
67
+ set r {}
68
foreach i [$w.source.l curselection] {
69
- lappend revs [$w.source.l get $i]
69
+ lappend r [lindex [lindex $list $i] 0]
70
}
71
+ return $r
72
+}
73
+
74
+proc _visualize {w list} {
75
+ set revs [_refs $w $list]
76
if {$revs eq {}} return
77
lappend revs --not HEAD
78
do_gitk $revs
79
}
80
76
-proc _start {w} {
81
+proc _start {w list} {
82
global HEAD ui_status_value current_branch
83
84
set cmd [list git merge]
80
- set names {}
81
- set revcnt 0
82
- foreach i [$w.source.l curselection] {
83
- set b [$w.source.l get $i]
84
- lappend cmd $b
85
- lappend names $b
86
- incr revcnt
87
- }
85
+ set names [_refs $w $list]
86
+ set revcnt [llength $names]
87
+ append cmd { } $names
88
89
if {$revcnt == 0} {
90
return
@@ -163,6 +163,36 @@ proc dialog {} {
163
164
if {![_can_merge]} return
165
166
+ set fmt {list %(objectname) %(*objectname) %(refname) %(subject)}
167
+ set cmd [list git for-each-ref --tcl --format=$fmt]
168
+ lappend cmd refs/heads
169
+ lappend cmd refs/remotes
170
+ lappend cmd refs/tags
171
+ set fr_fd [open "| $cmd" r]
172
+ fconfigure $fr_fd -translation binary
173
+ while {[gets $fr_fd line] > 0} {
174
+ set line [eval $line]
175
+ set ref [lindex $line 2]
176
+ regsub ^refs/(heads|remotes|tags)/ $ref {} ref
177
+ set subj($ref) [lindex $line 3]
178
+ lappend sha1([lindex $line 0]) $ref
179
+ if {[lindex $line 1] ne {}} {
180
+ lappend sha1([lindex $line 1]) $ref
181
+ }
182
+ }
183
+ close $fr_fd
184
+
185
+ set to_show {}
186
+ set fr_fd [open "| git rev-list --all --not HEAD"]
187
+ while {[gets $fr_fd line] > 0} {
188
+ if {[catch {set ref $sha1($line)}]} continue
189
+ foreach n $ref {
190
+ lappend to_show [list $n $line]
191
+ }
192
+ }
193
+ close $fr_fd
194
+ set to_show [lsort -unique $to_show]
195
+
196
set w .merge_setup
197
toplevel $w
198
wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
@@ -174,10 +204,10 @@ proc dialog {} {
204
205
frame $w.buttons
206
button $w.buttons.visualize -text Visualize \
177
- -command [namespace code [list _visualize $w]]
207
+ -command [namespace code [list _visualize $w $to_show]]
208
pack $w.buttons.visualize -side left
209
button $w.buttons.create -text Merge \
180
- -command [namespace code [list _start $w]]
210
+ -command [namespace code [list _start $w $to_show]]
211
pack $w.buttons.create -side right
212
button $w.buttons.cancel -text {Cancel} \
213
-command [list destroy $w]
@@ -188,6 +218,7 @@ proc dialog {} {
218
listbox $w.source.l \
219
-height 10 \
220
-width 70 \
221
+ -font font_diff \
222
-selectmode extended \
223
-yscrollcommand [list $w.source.sby set]
224
scrollbar $w.source.sby -command [list $w.source.l yview]
@@ -195,40 +226,18 @@ proc dialog {} {
226
pack $w.source.l -side left -fill both -expand 1
227
pack $w.source -fill both -expand 1 -pady 5 -padx 5
228
198
- set fmt {list %(objectname) %(*objectname) %(refname) %(subject)}
199
- set cmd [list git for-each-ref --tcl --format=$fmt]
200
- lappend cmd refs/heads
201
- lappend cmd refs/remotes
202
- lappend cmd refs/tags
203
- set fr_fd [open "| $cmd" r]
204
- fconfigure $fr_fd -translation binary
205
- while {[gets $fr_fd line] > 0} {
206
- set line [eval $line]
207
- set ref [lindex $line 2]
208
- regsub ^refs/(heads|remotes|tags)/ $ref {} ref
209
- set subj($ref) [lindex $line 3]
210
- lappend sha1([lindex $line 0]) $ref
211
- if {[lindex $line 1] ne {}} {
212
- lappend sha1([lindex $line 1]) $ref
213
- }
214
- }
215
- close $fr_fd
216
-
217
- set to_show {}
218
- set fr_fd [open "| git rev-list --all --not HEAD"]
219
- while {[gets $fr_fd line] > 0} {
220
- if {[catch {set ref $sha1($line)}]} continue
221
- foreach n $ref {
222
- lappend to_show $n
229
+ foreach ref $to_show {
230
+ set n [lindex $ref 0]
231
+ if {[string length $n] > 20} {
232
+ set n "[string range $n 0 16]..."
233
}
224
- }
225
- close $fr_fd
226
-
227
- foreach ref [lsort -unique $to_show] {
228
- $w.source.l insert end $ref
234
+ $w.source.l insert end [format {%s %-20s %s} \
235
+ [string range [lindex $ref 1] 0 5] \
236
+ $n \
237
+ $subj([lindex $ref 0])]
238
}
239
231
- bind $w <Visibility> "grab $w"
240
+ bind $w <Visibility> "grab $w; focus $w.source.l"
241
bind $w <Key-Escape> "unlock_index;destroy $w"
242
bind $w <Destroy> unlock_index
243
wm title $w "[appname] ([reponame]): Merge"