@@ -63,28 +63,28 @@ You should complete the current commit before starting a merge. Doing so will h
6363 return 1
6464}
6565
66- proc _visualize {w} {
67- set revs {}
66+ proc _refs {w list } {
67+ set r {}
6868 foreach i [$w .source.l curselection] {
69- lappend revs [ $w .source.l get $i ]
69+ lappend r [ lindex [ lindex $list $i ] 0 ]
7070 }
71+ return $r
72+ }
73+
74+ proc _visualize {w list} {
75+ set revs [_refs $w $list ]
7176 if {$revs eq {}} return
7277 lappend revs --not HEAD
7378 do_gitk $revs
7479}
7580
76- proc _start {w} {
81+ proc _start {w list } {
7782 global HEAD ui_status_value current_branch
7883
7984 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
8888
8989 if {$revcnt == 0} {
9090 return
@@ -163,6 +163,36 @@ proc dialog {} {
163163
164164 if {![_can_merge]} return
165165
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+
166196 set w .merge_setup
167197 toplevel $w
168198 wm geometry $w " +[ winfo rootx .] +[ winfo rooty .] "
@@ -174,10 +204,10 @@ proc dialog {} {
174204
175205 frame $w .buttons
176206 button $w .buttons.visualize -text Visualize \
177- -command [namespace code [list _visualize $w ]]
207+ -command [namespace code [list _visualize $w $to_show ]]
178208 pack $w .buttons.visualize -side left
179209 button $w .buttons.create -text Merge \
180- -command [namespace code [list _start $w ]]
210+ -command [namespace code [list _start $w $to_show ]]
181211 pack $w .buttons.create -side right
182212 button $w .buttons.cancel -text {Cancel} \
183213 -command [list destroy $w ]
@@ -188,47 +218,26 @@ proc dialog {} {
188218 listbox $w .source.l \
189219 -height 10 \
190220 -width 70 \
221+ -font font_diff \
191222 -selectmode extended \
192223 -yscrollcommand [list $w .source.sby set]
193224 scrollbar $w .source.sby -command [list $w .source.l yview]
194225 pack $w .source.sby -side right -fill y
195226 pack $w .source.l -side left -fill both -expand 1
196227 pack $w .source -fill both -expand 1 -pady 5 -padx 5
197228
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] ..."
223233 }
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]) ]
229238 }
230239
231- bind $w <Visibility> " grab $w "
240+ bind $w <Visibility> " grab $w ; focus $w .source.l "
232241 bind $w <Key-Escape> " unlock_index;destroy $w "
233242 bind $w <Destroy> unlock_index
234243 wm title $w " [ appname] ([ reponame] ): Merge"
0 commit comments