threads / rfc / 27137

RFC patchPass empty file to p4merge where no base is suitable.

Subject: [RFC PATCH] Pass empty file to p4merge where no base is suitable.

## tl;dr

9 messages between Apr 19, 2011 and May 2, 2011. Diffs are folded; open one to read it.

replies: 8people: 2as markdown or json

Ciaran· Apr 19, 2011, 19:46 UTC · lore

Modify the p4merge client command to pass a reference to an empty file instead of the local file when no base revision available.

In the situation where a merge tries to add a file from one branch into a branch that already contains that file (by name), p4merge currently seems to have successfully automatically resolved the 'conflict' when it is opened (correctly if the files differed by just whitespace for example) but leaves the save button disabled. This means the user of the p4merge client cannot commit the resolved changes back to disk and merely exits, leaving the original (merge-conflicted) file in-tact on the disk.

Provide an empty base file to p4merge so that it leaves the save button enabled. This will allow saving of the auto-resolution to disk.

Please note that the empty file is temporarily stored in the location specified as GIT_DIR/.no_base

Signed-off-by: Ciaran Jessup <ciaranj@gmail.com>
---
Thank you to David Aguilar for his feedback previously on this patch,
hopefully I've followed the submission guidelines correctly this time.
 This patch is to improve the interaction of p4merge and git in the
case where merge conflicts have no common ancestor.  For more detailed
discussion please see: http://marc.info/?l=git&m=130190735601527&w=2
(I was unsure if it was ok to repost inline, sorry)
 git-mergetool--lib.sh |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
Show changes to git-mergetool--lib.sh +3 −1
diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index fb3f52b..3e007e9 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -262,7 +262,9 @@ run_merge_tool () {
 			if $base_present; then
 				"$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
 			else
-				"$merge_tool_path" "$LOCAL" "$LOCAL" "$REMOTE" "$MERGED"
+				touch "$GIT_DIR/.no_base"
+				"$merge_tool_path" "$GIT_DIR/.no_base" "$LOCAL" "$REMOTE" "$MERGED"
+				rm "$GIT_DIR/.no_base"
 			fi
 			check_unchanged
 		else
-- 
1.7.4.1
Junio C Hamano· Apr 19, 2011, 21:33 UTC · re: Ciaran · lore

Re: [RFC PATCH] Pass empty file to p4merge where no base is suitable.

Ciaran <ciaranj@gmail.com> writes:
Show 10 quoted lines
> --- a/git-mergetool--lib.sh
> +++ b/git-mergetool--lib.sh
> @@ -262,7 +262,9 @@ run_merge_tool () {
>  			if $base_present; then
>  				"$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
>  			else
> -				"$merge_tool_path" "$LOCAL" "$LOCAL" "$REMOTE" "$MERGED"
> +				touch "$GIT_DIR/.no_base"
> +				"$merge_tool_path" "$GIT_DIR/.no_base" "$LOCAL" "$REMOTE" "$MERGED"
> +				rm "$GIT_DIR/.no_base"

The calling script "git-mergetool.sh" seems to take pains to construct these filenames to have the same .ext, presumably so that the tool can take advantage of it to determine the type of contents and do something intelligent about it (e.g. syntax highlighting).

Does the use of .no_base interfere with that effort?

I suspect that you may be able to simply use "$BASE" for that, no? It will be cleaned up when cleanup_temp_files() is run anyway (warning: I do not use mergetool, and I am writing this only from my cursory looking of the script, so take this with a large grain of salt).

Also, the command to use when you want to get an empty file is not "touch". It is not likely that you would have an existing file there, but the whole point of the updated codepath is to have an empty file, and not a file with recent timestamp, it would be far more sensible to say

	: >"$BASE"
i.e. redirect into the path, with a no-op command.
Junio C Hamano· Apr 19, 2011, 22:01 UTC · re: Junio C Hamano · lore

Re: [RFC PATCH] Pass empty file to p4merge where no base is suitable.

Junio C Hamano <gitster@pobox.com> writes:
Show 8 quoted lines
> Also, the command to use when you want to get an empty file is not "touch".
> It is not likely that you would have an existing file there, but the whole
> point of the updated codepath is to have an empty file, and not a file
> with recent timestamp, it would be far more sensible to say
>
> 	: >"$BASE"
>
> i.e. redirect into the path, with a no-op command.

By the way, you may want to study what git-merge-one-file.sh script does when given a "both sides added, but differently" situation (look for a string "--no-add" in the script). It first tries to see if there are many common material that are added in both sides, and if so tries to use that common material as the "fake" base. If there isn't enough common material, it uses an empty file as the base.

Ciaran· May 1, 2011, 20:47 UTC · re: Junio C Hamano · lore

Re: [RFC PATCH] Pass empty file to p4merge where no base is suitable.

Modify the p4merge client command to pass a reference to an empty file instead of the local file when no base revision available.

In the situation where a merge tries to add a file from one branch into a branch that already contains that file (by name), p4merge currently seems to have successfully automatically resolved the 'conflict' when it is opened (correctly if the files differed by just whitespace for example) but leaves the save button disabled. This means the user of the p4merge client cannot commit the resolved changes back to disk and merely exits, leaving the original (merge-conflicted) file in-tact on the disk.

Provide an empty base file to p4merge so that it leaves the save button enabled. This will allow saving of the auto-resolution to disk.

Please note that the empty file is temporarily stored in the location specified as GIT_DIR/.no_base

Signed-off-by: Ciaran Jessup <ciaranj@gmail.com>
---

Continuation of the thread begun in: http://marc.info/?l=git&m=130190735601527&w=2

Show 6 quoted lines
> The calling script "git-mergetool.sh" seems to take pains to construct
> these filenames to have the same .ext, presumably so that the tool can
> take advantage of it to determine the type of contents and do something
> intelligent about it (e.g. syntax highlighting).
>
> Does the use of .no_base interfere with that effort?

It doesn't appear to (remember this patch just affects the p4merge tool, and no others.)

Show 5 quoted lines
>
> I suspect that you may be able to simply use "$BASE" for that, no?  It
> will be cleaned up when cleanup_temp_files() is run anyway (warning: I do
> not use mergetool, and I am writing this only from my cursory looking of
> the script, so take this with a large grain of salt).
I don't think so, the BASE file isn't created at-all in this scenario afaict.
Show 9 quoted lines
>
> Also, the command to use when you want to get an empty file is not "touch".
> It is not likely that you would have an existing file there, but the whole
> point of the updated codepath is to have an empty file, and not a file
> with recent timestamp, it would be far more sensible to say
>
>        : >"$BASE"
>
> i.e. redirect into the path, with a no-op command.
Ok, my apologies perl isn't a language I'm overly familiar with :)
I've adapted the previous patch to take this on board.  Thank you :)
--
 git-mergetool--lib.sh |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
Show changes to git-mergetool--lib.sh +3 −1
diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index fb3f52b..7b2008f 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -262,7 +262,9 @@ run_merge_tool () {
 			if $base_present; then
 				"$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
 			else
-				"$merge_tool_path" "$LOCAL" "$LOCAL" "$REMOTE" "$MERGED"
+				: > "$GIT_DIR/.no_base"
+				"$merge_tool_path" "$GIT_DIR/.no_base" "$LOCAL" "$REMOTE" "$MERGED"
+				rm "$GIT_DIR/.no_base"
 			fi
 			check_unchanged
 		else
-- 
1.7.4.1
Junio C Hamano· May 1, 2011, 21:54 UTC · re: Ciaran · lore

Re: [RFC PATCH] Pass empty file to p4merge where no base is suitable.

Ciaran <ciaranj@gmail.com> writes:
Show 5 quoted lines
>> I suspect that you may be able to simply use "$BASE" for that, no?  It
>> will be cleaned up when cleanup_temp_files() is run anyway (warning: I do
>> not use mergetool, and I am writing this only from my cursory looking of
>> the script, so take this with a large grain of salt).
> I don't think so, the BASE file isn't created at-all in this scenario afaict.

Hmm, just like $BASE, your .no-base is not created at all in this scenario either, but you create it yourself in your patch, and because you picked a new filename for that temporary file, you also need to worry about cleaning it up.

Why can't that temporary file be "$BASE"? That is what I was asking. Then you would still create an empty file (but see *1*), and can rely on existing codepaths to clean it up.

IOW, wouldn't it be far simpler to turn the part you are patching into these three lines?

	$base_present || >"$BASE"
        "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
        check_unchanged
Show 15 quoted lines
> diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
> index fb3f52b..7b2008f 100644
> --- a/git-mergetool--lib.sh
> +++ b/git-mergetool--lib.sh
> @@ -262,7 +262,9 @@ run_merge_tool () {
>  			if $base_present; then
>  				"$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
>  			else
> -				"$merge_tool_path" "$LOCAL" "$LOCAL" "$REMOTE" "$MERGED"
> +				: > "$GIT_DIR/.no_base"
> +				"$merge_tool_path" "$GIT_DIR/.no_base" "$LOCAL" "$REMOTE" "$MERGED"
> +				rm "$GIT_DIR/.no_base"
>  			fi
>  			check_unchanged
>  		else
[Footnote]
*1* It also may be worth considering to employ the "use either an empty
    file or use the common parts of merged files, whichever makes the
    merge simpler, as a phony base" technique found in git-merge-one-file.
Ciaran· May 1, 2011, 22:08 UTC · re: Junio C Hamano · lore

Re: [RFC PATCH] Pass empty file to p4merge where no base is suitable.

On Sun, May 1, 2011 at 10:54 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 23 quoted lines
> Ciaran <ciaranj@gmail.com> writes:
>
>>> I suspect that you may be able to simply use "$BASE" for that, no?  It
>>> will be cleaned up when cleanup_temp_files() is run anyway (warning: I do
>>> not use mergetool, and I am writing this only from my cursory looking of
>>> the script, so take this with a large grain of salt).
>> I don't think so, the BASE file isn't created at-all in this scenario afaict.
>
> Hmm, just like $BASE, your .no-base is not created at all in this scenario
> either, but you create it yourself in your patch, and because you picked a
> new filename for that temporary file, you also need to worry about
> cleaning it up.
>
> Why can't that temporary file be "$BASE"?  That is what I was asking.
> Then you would still create an empty file (but see *1*), and can rely on
> existing codepaths to clean it up.
>
> IOW, wouldn't it be far simpler to turn the part you are patching into
> these three lines?
>
>        $base_present || >"$BASE"
>        "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
>        check_unchanged

Yes, that is a *much* better solution that solves my issue perfectly ;) Patch to follow.

<!-- Snip -->
Show 6 quoted lines
> [Footnote]
>
> *1* It also may be worth considering to employ the "use either an empty
>    file or use the common parts of merged files, whichever makes the
>    merge simpler, as a phony base" technique found in git-merge-one-file.
>

I did consider your earlier post on this, but it seems that that perforce's merge client is sufficiently smart enough to do this alignment/matching itself, so the effort isn't required (imho) for this client (which is the client that I'm experiencing 'pain' with atm !

Thanks,
- Cj.
Ciaran· May 1, 2011, 22:16 UTC · re: Ciaran · lore

Re: [RFC PATCH] Pass empty file to p4merge where no base is suitable.

Modify the p4merge client command to pass a reference to an empty file instead of the local file when no base revision available.

In the situation where a merge tries to add a file from one branch into a branch that already contains that file (by name), p4merge currently seems to have successfully automatically resolved the 'conflict' when it is opened (correctly if the files differed by just whitespace for example) but leaves the save button disabled. This means the user of the p4merge client cannot commit the resolved changes back to disk and merely exits, leaving the original (merge-conflicted) file intact on the disk.

Provide an empty base file to p4merge so that it leaves the save button enabled. This will allow saving of the auto-resolution to disk.

Signed-off-by: Ciaran Jessup <ciaranj@gmail.com>
---
A hopefully final stab at the patch, which effectively backs out my
version, and implements the suggestions of
Junio C Hamano.
 git-mergetool--lib.sh |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)
Show changes to git-mergetool--lib.sh +3 −6
diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index fb3f52b..4db9212 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -258,12 +258,9 @@ run_merge_tool () {
 		;;
 	p4merge)
 		if merge_mode; then
-		    touch "$BACKUP"
-			if $base_present; then
-				"$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
-			else
-				"$merge_tool_path" "$LOCAL" "$LOCAL" "$REMOTE" "$MERGED"
-			fi
+			touch "$BACKUP"
+			$base_present || >"$BASE"
+			"$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
 			check_unchanged
 		else
 			"$merge_tool_path" "$LOCAL" "$REMOTE"
-- 
1.7.4.1
Junio C Hamano· May 1, 2011, 23:55 UTC · re: Ciaran · lore

Re: [RFC PATCH] Pass empty file to p4merge where no base is suitable.

Ciaran <ciaranj@gmail.com> writes:
Show 18 quoted lines
> diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
> index fb3f52b..4db9212 100644
> --- a/git-mergetool--lib.sh
> +++ b/git-mergetool--lib.sh
> @@ -258,12 +258,9 @@ run_merge_tool () {
>  		;;
>  	p4merge)
>  		if merge_mode; then
> -		    touch "$BACKUP"
> -			if $base_present; then
> -				"$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
> -			else
> -				"$merge_tool_path" "$LOCAL" "$LOCAL" "$REMOTE" "$MERGED"
> -			fi
> +			touch "$BACKUP"
> +			$base_present || >"$BASE"
> +			"$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
>  			check_unchanged
Will queue this version as-is; thanks.

Somebody might want to revisit if that "touch" is still really necessary, though. It is outside the scope of this change, as that has been there before this patch.

Ciaran· May 2, 2011, 00:01 UTC · re: Junio C Hamano · lore

Re: [RFC PATCH] Pass empty file to p4merge where no base is suitable.

On Mon, May 2, 2011 at 12:55 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 22 quoted lines
> Ciaran <ciaranj@gmail.com> writes:
>
>> diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
>> index fb3f52b..4db9212 100644
>> --- a/git-mergetool--lib.sh
>> +++ b/git-mergetool--lib.sh
>> @@ -258,12 +258,9 @@ run_merge_tool () {
>>               ;;
>>       p4merge)
>>               if merge_mode; then
>> -                 touch "$BACKUP"
>> -                     if $base_present; then
>> -                             "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
>> -                     else
>> -                             "$merge_tool_path" "$LOCAL" "$LOCAL" "$REMOTE" "$MERGED"
>> -                     fi
>> +                     touch "$BACKUP"
>> +                     $base_present || >"$BASE"
>> +                     "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
>>                       check_unchanged
>
> Will queue this version as-is; thanks.
Thank you.
Show 5 quoted lines
>
>
> Somebody might want to revisit if that "touch" is still really necessary,
> though.  It is outside the scope of this change, as that has been there
> before this patch.

The only reason my patch touches it was to 'fix' the whitespace (i.e. it was mixed tabs + space chars, where all the other instances of that line aren't)

I did debate backing that change out though :)
- cj.
Show 5 quoted lines
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

← back to recent threads