@matheusbsbs / matheus-bagliano / commits / 349f92e3a2
Fork 0

git-gui: Show all possible branches for merge

Johannes Sixt pointed out that git-gui was randomly selecting which branch (or tag!) it will show in the merge dialog when more than one ref points at the same commit. This can be a problem for the user if they want to merge a branch, but the ref that git-gui selected to display was actually a tag that points at the commit at the tip of that branch. Since the user is looking for the branch, and not the tag, its confusing to not find it, and worse, merging the tag causes git-merge to generate a different message than if the branch was selected. While I am in here and am messing around I have changed the for-each-ref usage to take advantage of its --tcl formatting, and to fetch the subject line of the commit (or tag) we are looking at. This way we could present the subject line in the UI to the user, given them an even better chance to select the correct branch. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed May 2, 2007 at 14:25 UTC 349f92e3a25216b6f79c58044d74b61c89de20b8
1 file changed +13 -7
lib/merge.tcl
+13 -7
@@ -195,17 +195,22 @@ proc dialog {} {
195 pack $w.source.l -side left -fill both -expand 1
196 pack $w.source -fill both -expand 1 -pady 5 -padx 5
197
198 - set cmd [list git for-each-ref]
199 - lappend cmd {--format=%(objectname) %(*objectname) %(refname)}
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 [split $line { }]
207 - set sha1([lindex $line 0]) [lindex $line 2]
208 - set sha1([lindex $line 1]) [lindex $line 2]
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
@@ -213,8 +218,9 @@ proc dialog {} {
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
216 - regsub ^refs/(heads|remotes|tags)/ $ref {} ref
217 - lappend to_show $ref
221 + foreach n $ref {
222 + lappend to_show $n
223 + }
224 }
225 close $fr_fd
226