@matheusbsbs / matheus-bagliano / commits / 3b4db3c1a3
Fork 0

git-gui: Improve the display of merge conflicts.

If a file has a merge conflict we want it to show up in the 'Changed But Not Updated' file list rather than the 'Changes To Be Committed' file list. This way the user can mostly ignore the left side (the HEAD<->index comparsion) while resolving a merge and instead focus on the merge conflicts, which are just shown on the right hand side. This requires detecting the U state in the index side and drawing it as though it were _, then forcing the working directory side to have a U state. We have to delay this until presentation time as we don't want to change our internal state data to be different from what Git is telling us (I tried, the patch for that was ugly and didn't work). When showing a working directory diff and its a merge conflict we don't want to use diff-files as this would wind up showing any automatically merged hunks obtained from MERGE_HEAD in the diff. These are not usually very interesting as they were completed by the system. Instead we just want to see the conflicts. Fortunately the diff porcelain-ish frontend (aka 'git diff') detects the case of an unmerged file and generates a --cc diff against HEAD and MERGE_HEAD. So we now force any working directory diff with an index state of 'U' to go through that difference path. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jan 21, 2007 at 12:30 UTC 3b4db3c1a3b9be66b46d8bd64560ee3f14f1084d
1 file changed +37 -10
git-gui.sh
+37 -10
@@ -654,7 +654,11 @@ proc show_diff {path w {lno {}}} {
654 lappend cmd diff-index
655 lappend cmd --cached
656 } elseif {$w eq $ui_workdir} {
657 - lappend cmd diff-files
657 + if {[string index $m 0] eq {U}} {
658 + lappend cmd diff
659 + } else {
660 + lappend cmd diff-files
661 + }
662 }
663
664 lappend cmd -p
@@ -1293,12 +1297,20 @@ proc display_file {path state} {
1297 set new_m [lindex $s 0]
1298 set icon_name [lindex $s 1]
1299
1300 + set s [string index $new_m 0]
1301 + if {$s eq {U}} {
1302 + set s _
1303 + }
1304 display_file_helper $ui_index $path $icon_name \
1297 - [string index $old_m 0] \
1298 - [string index $new_m 0]
1305 + [string index $old_m 0] $s
1306 +
1307 + if {[string index $new_m 0] eq {U}} {
1308 + set s U
1309 + } else {
1310 + set s [string index $new_m 1]
1311 + }
1312 display_file_helper $ui_workdir $path $icon_name \
1300 - [string index $old_m 1] \
1301 - [string index $new_m 1]
1313 + [string index $old_m 1] $s
1314
1315 if {$new_m eq {__}} {
1316 unset file_states($path)
@@ -1338,13 +1350,20 @@ proc display_all_files {} {
1350 set m [lindex $s 0]
1351 set icon_name [lindex $s 1]
1352
1341 - if {[string index $m 0] ne {_}} {
1353 + set s [string index $m 0]
1354 + if {$s ne {U} && $s ne {_}} {
1355 display_all_files_helper $ui_index $path \
1343 - $icon_name [string index $m 0]
1356 + $icon_name $s
1357 }
1345 - if {[string index $m 1] ne {_}} {
1358 +
1359 + if {[string index $m 0] eq {U}} {
1360 + set s U
1361 + } else {
1362 + set s [string index $m 1]
1363 + }
1364 + if {$s ne {_}} {
1365 display_all_files_helper $ui_workdir $path \
1347 - $icon_name [string index $m 1]
1366 + $icon_name $s
1367 }
1368 }
1369
@@ -1479,7 +1498,13 @@ proc write_update_index {fd pathList totalCnt batch msg after} {
1498 ?D {set new D_}
1499 _O -
1500 AM {set new A_}
1482 - U_ -
1501 + U? {
1502 + if {[file exists $path]} {
1503 + set new M_
1504 + } else {
1505 + set new D_
1506 + }
1507 + }
1508 ?M {set new M_}
1509 ?? {continue}
1510 }
@@ -2244,6 +2269,7 @@ set all_icons(U$ui_index) file_merge
2269 set all_icons(_$ui_workdir) file_plain
2270 set all_icons(M$ui_workdir) file_mod
2271 set all_icons(D$ui_workdir) file_question
2272 +set all_icons(U$ui_workdir) file_merge
2273 set all_icons(O$ui_workdir) file_plain
2274
2275 set max_status_desc 0
@@ -2265,6 +2291,7 @@ foreach i {
2291 {DO "Staged for removal, still present"}
2292
2293 {U_ "Requires merge resolution"}
2294 + {UU "Requires merge resolution"}
2295 {UM "Requires merge resolution"}
2296 {UD "Requires merge resolution"}
2297 } {