Skip to contentSkip to conversation

mergetool: reorder vim/gvim buffers in three-way diffs

PATCH In review Dickson Wong 4 participants 12 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mergetool: reorder vim/gvim buffers in three-way diffs

When invoking default (g)vimdiff three-way merge, the merged file is loaded as the first buffer but moved to the bottom as the fourth window. This causes a disconnect between vim commands that operate on window positions (e.g. CTRL-W_w) and those that operate on buffer index (e.g. do/dp).

This change reorders the buffers to have the same index as windows while keeping the cursor default to the merged result as the bottom window.

---
 mergetools/vimdiff | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mergetools/vimdiff +2 -2
index 1ddfbfc..74ea6d5 100644
@@ -2,22 +2,22 @@ diff_cmd () {
 	"$merge_tool_path" -R -f -d \
 		-c 'wincmd l' -c 'cd $GIT_PREFIX' "$LOCAL" "$REMOTE"
 }
 
 merge_cmd () {
 	touch "$BACKUP"
 	case "$1" in
 	gvimdiff|vimdiff)
 		if $base_present
 		then
-			"$merge_tool_path" -f -d -c 'wincmd J' \
-				"$MERGED" "$LOCAL" "$BASE" "$REMOTE"
+			"$merge_tool_path" -f -d -c '4wincmd w | wincmd J' \
+				"$LOCAL" "$BASE" "$REMOTE" "$MERGED"
 		else
 			"$merge_tool_path" -f -d -c 'wincmd l' \
 				"$LOCAL" "$MERGED" "$REMOTE"
 		fi
 		;;
 	gvimdiff2|vimdiff2)
 		"$merge_tool_path" -f -d -c 'wincmd l' \
 			"$LOCAL" "$MERGED" "$REMOTE"
 		;;
 	gvimdiff3|vimdiff3)
Signature · 1 line
2.6.2
#1 lore raw
Quoted 11 lines · Dickson Wong

When invoking default (g)vimdiff three-way merge, the merged file is loaded as the first buffer but moved to the bottom as the fourth window. This causes a disconnect between vim commands that operate on window positions (e.g. CTRL-W_w) and those that operate on buffer index (e.g. do/dp).

This change reorders the buffers to have the same index as windows while keeping the cursor default to the merged result as the bottom window.

---

David, I unfortunately do not use 'mergetools' myself and certainly not vimdiff.

Opinions?

Quoted 32 lines
 mergetools/vimdiff | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mergetools/vimdiff +2 -2
index 1ddfbfc..74ea6d5 100644
@@ -2,22 +2,22 @@ diff_cmd () {
 	"$merge_tool_path" -R -f -d \
 		-c 'wincmd l' -c 'cd $GIT_PREFIX' "$LOCAL" "$REMOTE"
 }
 
 merge_cmd () {
 	touch "$BACKUP"
 	case "$1" in
 	gvimdiff|vimdiff)
 		if $base_present
 		then
-			"$merge_tool_path" -f -d -c 'wincmd J' \
-				"$MERGED" "$LOCAL" "$BASE" "$REMOTE"
+			"$merge_tool_path" -f -d -c '4wincmd w | wincmd J' \
+				"$LOCAL" "$BASE" "$REMOTE" "$MERGED"
 		else
 			"$merge_tool_path" -f -d -c 'wincmd l' \
 				"$LOCAL" "$MERGED" "$REMOTE"
 		fi
 		;;
 	gvimdiff2|vimdiff2)
 		"$merge_tool_path" -f -d -c 'wincmd l' \
 			"$LOCAL" "$MERGED" "$REMOTE"
 		;;
 	gvimdiff3|vimdiff3)
#2 lore raw
Quoted 11 lines · Junio C Hamano
Quoted 9 lines · Dickson Wong

When invoking default (g)vimdiff three-way merge, the merged file is loaded as the first buffer but moved to the bottom as the fourth window. This causes a disconnect between vim commands that operate on window positions (e.g. CTRL-W_w) and those that operate on buffer index (e.g. do/dp).

This change reorders the buffers to have the same index as windows while keeping the cursor default to the merged result as the bottom window.

Quoted 7 lines
Quoted 2 lines

---

David, I unfortunately do not use 'mergetools' myself and certainly not vimdiff.

Opinions?

Second call for help. Any comments on this from anybody other than the author that I missed to support this change?

Quoted 33 lines
Quoted 33 lines
 mergetools/vimdiff | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mergetools/vimdiff +2 -2
index 1ddfbfc..74ea6d5 100644
@@ -2,22 +2,22 @@ diff_cmd () {
 	"$merge_tool_path" -R -f -d \
 		-c 'wincmd l' -c 'cd $GIT_PREFIX' "$LOCAL" "$REMOTE"
 }
 
 merge_cmd () {
 	touch "$BACKUP"
 	case "$1" in
 	gvimdiff|vimdiff)
 		if $base_present
 		then
-			"$merge_tool_path" -f -d -c 'wincmd J' \
-				"$MERGED" "$LOCAL" "$BASE" "$REMOTE"
+			"$merge_tool_path" -f -d -c '4wincmd w | wincmd J' \
+				"$LOCAL" "$BASE" "$REMOTE" "$MERGED"
 		else
 			"$merge_tool_path" -f -d -c 'wincmd l' \
 				"$LOCAL" "$MERGED" "$REMOTE"
 		fi
 		;;
 	gvimdiff2|vimdiff2)
 		"$merge_tool_path" -f -d -c 'wincmd l' \
 			"$LOCAL" "$MERGED" "$REMOTE"
 		;;
 	gvimdiff3|vimdiff3)
#3 lore raw

Junio C Hamano venit, vidit, dixit 09.02.2016 23:25:

Quoted 16 lines
Quoted 14 lines · Junio C Hamano
Quoted 11 lines · Dickson Wong

When invoking default (g)vimdiff three-way merge, the merged file is loaded as the first buffer but moved to the bottom as the fourth window. This causes a disconnect between vim commands that operate on window positions (e.g. CTRL-W_w) and those that operate on buffer index (e.g. do/dp).

This change reorders the buffers to have the same index as windows while keeping the cursor default to the merged result as the bottom window.

---

Quoted 8 lines
Quoted 4 lines

David, I unfortunately do not use 'mergetools' myself and certainly not vimdiff.

Opinions?

Second call for help. Any comments on this from anybody other than the author that I missed to support this change?

OK, applied it (on top of next), looks sane and improves the situation for the majority of people who read left to right, then top down and assign buffers 1 2 3 4 "mentally" to local base remote merge windows based on that. Their expectation is met now. Thanks!

(Also, the other vim variants don't need a corresponding change.)

Michael

Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
 mergetools/vimdiff | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mergetools/vimdiff +2 -2
index 1ddfbfc..74ea6d5 100644
@@ -2,22 +2,22 @@ diff_cmd () {
 	"$merge_tool_path" -R -f -d \
 		-c 'wincmd l' -c 'cd $GIT_PREFIX' "$LOCAL" "$REMOTE"
 }
 
 merge_cmd () {
 	touch "$BACKUP"
 	case "$1" in
 	gvimdiff|vimdiff)
 		if $base_present
 		then
-			"$merge_tool_path" -f -d -c 'wincmd J' \
-				"$MERGED" "$LOCAL" "$BASE" "$REMOTE"
+			"$merge_tool_path" -f -d -c '4wincmd w | wincmd J' \
+				"$LOCAL" "$BASE" "$REMOTE" "$MERGED"
 		else
 			"$merge_tool_path" -f -d -c 'wincmd l' \
 				"$LOCAL" "$MERGED" "$REMOTE"
 		fi
 		;;
 	gvimdiff2|vimdiff2)
 		"$merge_tool_path" -f -d -c 'wincmd l' \
 			"$LOCAL" "$MERGED" "$REMOTE"
 		;;
 	gvimdiff3|vimdiff3)
#4 lore raw
Quoted 7 lines · Michael J Gruber
Quoted 2 lines

Second call for help. Any comments on this from anybody other than the author that I missed to support this change?

OK, applied it (on top of next), looks sane and improves the situation for the majority of people who read left to right, then top down and assign buffers 1 2 3 4 "mentally" to local base remote merge windows based on that. Their expectation is met now. Thanks!

Thanks.

Does this mean that I should warn in the release notes that some existing users might get their expectation broken but we are going ahead anyway because we think most people read left to right and then top down? I am OK with saying that--I just wanted to make sure we know that it is what we are doing.

Quoted 1 line

(Also, the other vim variants don't need a corresponding change.)

A stupid question while I am here. What are these different variants? When reviewing this patch for the first time I tried to find where they are documented, but didn't spot anything.

I can see from the code that vimdiff2 variant does not do anything special when it is doing a 3-way merge, but vimdiff3 variant does behave differently when it has $BASE. It does not need a change like this because it already arranges and numbers the windows sensibly (in other words, we can label this patch as aligning the behaviour of vimdiff to that of vimdiff3)?

Thanks.

Quoted 35 lines

Michael

Quoted 33 lines
Quoted 33 lines
Quoted 33 lines
 mergetools/vimdiff | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mergetools/vimdiff +2 -2
index 1ddfbfc..74ea6d5 100644
@@ -2,22 +2,22 @@ diff_cmd () {
 	"$merge_tool_path" -R -f -d \
 		-c 'wincmd l' -c 'cd $GIT_PREFIX' "$LOCAL" "$REMOTE"
 }
 
 merge_cmd () {
 	touch "$BACKUP"
 	case "$1" in
 	gvimdiff|vimdiff)
 		if $base_present
 		then
-			"$merge_tool_path" -f -d -c 'wincmd J' \
-				"$MERGED" "$LOCAL" "$BASE" "$REMOTE"
+			"$merge_tool_path" -f -d -c '4wincmd w | wincmd J' \
+				"$LOCAL" "$BASE" "$REMOTE" "$MERGED"
 		else
 			"$merge_tool_path" -f -d -c 'wincmd l' \
 				"$LOCAL" "$MERGED" "$REMOTE"
 		fi
 		;;
 	gvimdiff2|vimdiff2)
 		"$merge_tool_path" -f -d -c 'wincmd l' \
 			"$LOCAL" "$MERGED" "$REMOTE"
 		;;
 	gvimdiff3|vimdiff3)
#5 lore raw

Junio C Hamano venit, vidit, dixit 10.02.2016 18:45:

Quoted 10 lines
Quoted 7 lines · Michael J Gruber
Quoted 2 lines

Second call for help. Any comments on this from anybody other than the author that I missed to support this change?

OK, applied it (on top of next), looks sane and improves the situation for the majority of people who read left to right, then top down and assign buffers 1 2 3 4 "mentally" to local base remote merge windows based on that. Their expectation is met now. Thanks!

Quoted 7 lines

Thanks.

Does this mean that I should warn in the release notes that some existing users might get their expectation broken but we are going ahead anyway because we think most people read left to right and then top down? I am OK with saying that--I just wanted to make sure we know that it is what we are doing.

I would claim that anyone who notices the difference in buffer numbering would be positively surprised.

Quoted 8 lines
Quoted 1 line

(Also, the other vim variants don't need a corresponding change.)

A stupid question while I am here. What are these different variants? When reviewing this patch for the first time I tried to find where they are documented, but didn't spot anything.

I can see from the code that vimdiff2 variant does not do anything special when it is doing a 3-way merge,

It is "vimdiff" without the base window.

Quoted 5 lines

but vimdiff3 variant does
behave differently when it has $BASE. It does not need a change like this because it already arranges and numbers the windows sensibly (in other words, we can label this patch as aligning the behaviour of vimdiff to that of vimdiff3)?

git log mergetools/vimdiff3
commit 7c147b77d34f072c40b912fafba499727921fa6e

Author: Felipe Contreras <[email protected]>
Date:   Sun Apr 20 19:24:20 2014 -0500

mergetools: add vimdiff3 mode

It's similar to the default, except that the other windows are hidden. This ensures that removed/added colors are still visible on the main merge window, but the other windows not visible.

Specially useful with merge.conflictstyle=diff3.

I have to say I'm still not sure what it is about (even after trying it out, even with the conflictstyle config)).

In any case, the buffer numbering is not the same (it is local remote base merge) but it doesn't matter in this case because only one window is displayed, so there is no visual association.

Michael

#6 lore raw
Quoted 8 lines · Michael J Gruber
Quoted 5 lines

Does this mean that I should warn in the release notes that some existing users might get their expectation broken but we are going ahead anyway because we think most people read left to right and then top down? I am OK with saying that--I just wanted to make sure we know that it is what we are doing.

I would claim that anyone who notices the difference in buffer numbering would be positively surprised.

Thanks. I, being a non-user of vim, was wondering if people who had their own user-defined commands (macros? and possibly short-cut keys to invoke them) built around the old (and odd) numbering need to adjust--in which case we may need to forewarn.

Quoted 3 lines

In any case, the buffer numbering is not the same (it is local remote base merge) but it doesn't matter in this case because only one window is displayed, so there is no visual association.

OK, thanks.

Acked-by
#7 lore raw
Quoted 16 lines · Junio C Hamano
Quoted 8 lines · Michael J Gruber
Quoted 5 lines

Does this mean that I should warn in the release notes that some existing users might get their expectation broken but we are going ahead anyway because we think most people read left to right and then top down? I am OK with saying that--I just wanted to make sure we know that it is what we are doing.

I would claim that anyone who notices the difference in buffer numbering would be positively surprised.

Thanks. I, being a non-user of vim, was wondering if people who had their own user-defined commands (macros? and possibly short-cut keys to invoke them) built around the old (and odd) numbering need to adjust--in which case we may need to forewarn.

Quoted 5 lines
Quoted 3 lines

In any case, the buffer numbering is not the same (it is local remote base merge) but it doesn't matter in this case because only one window is displayed, so there is no visual association.

OK, thanks.

Sorry for not noticing this thread earlier.
The change and the rationale sound good to me.

FWIW,

ciao,

Signature · 1 line
David
#9 lore raw
In reply to Junio C Hamano

Thanks for looking into the patch.

Quoted 5 lines

Thanks. I, being a non-user of vim, was wondering if people who had their own user-defined commands (macros? and possibly short-cut keys to invoke them) built around the old (and odd) numbering need to adjust--in which case we may need to forewarn.

Vim buffers are not reorderable and windows are always numbered from top-left to bottom-right. However, I can see someone who is familiar with the old behavior issue a "CTRL-W_K" command to move the merged window from the bottom to the top, making the merged window the first window and consistent with buffer indexes. If they use this command after the patch, the indexes would no longer be consistent. The command would most likely be issued manually and not through a vim startup script.

#10 lore raw
Quoted 1 line · Dickson Wong

Thanks for looking into the patch.

No. Thank _you_ for contributing ;-)

Quoted 7 lines

Vim buffers are not reorderable and windows are always numbered from top-left to bottom-right. However, I can see someone who is familiar with the old behavior issue a "CTRL-W_K" command to move the merged window from the bottom to the top, making the merged window the first window and consistent with buffer indexes. If they use this command after the patch, the indexes would no longer be consistent. The command would most likely be issued manually and not through a vim startup script.

So it should suffice to mention it in the release notes as one bullet item that describes one positive change, among all other updates described in a simlar way. And there is no special "warnings for existing users" necessary, I would say.

Thanks.

#11 lore raw
Quoted 4 lines · Junio C Hamano

So it should suffice to mention it in the release notes as one bullet item that describes one positive change, among all other updates described in a simlar way. And there is no special "warnings for existing users" necessary, I would say.

It's unlikely anyone would move the merged window to the top as a preference only without being aware of the original inconsistency. If someone has been using a workaround, it would be fairly obvious as to what has changed, and definitely more so than when they first encountered the original behavior. Any adjustments to the new behavior would probably be a workflow change rather than a system configuration or scripting change.

#8 lore raw
In reply to David Aguilar
Quoted 21 lines · David Aguilar
Quoted 20 lines · Junio C Hamano
Quoted 8 lines · Michael J Gruber
Quoted 5 lines

Does this mean that I should warn in the release notes that some existing users might get their expectation broken but we are going ahead anyway because we think most people read left to right and then top down? I am OK with saying that--I just wanted to make sure we know that it is what we are doing.

I would claim that anyone who notices the difference in buffer numbering would be positively surprised.

Thanks. I, being a non-user of vim, was wondering if people who had their own user-defined commands (macros? and possibly short-cut keys to invoke them) built around the old (and odd) numbering need to adjust--in which case we may need to forewarn.

Quoted 3 lines

In any case, the buffer numbering is not the same (it is local remote base merge) but it doesn't matter in this case because only one window is displayed, so there is no visual association.

Quoted 8 lines
Quoted 1 line

OK, thanks.

Sorry for not noticing this thread earlier.
The change and the rationale sound good to me.

FWIW,

Thanks all. Will merge to 'next' and then to 'master' shortly.