git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mergetools/p4merge: Handle "/dev/null"
@ 2012-10-11  3:22 David Aguilar
  2012-10-27  8:47 ` Jeremy Morton
  0 siblings, 1 reply; 3+ messages in thread
From: David Aguilar @ 2012-10-11  3:22 UTC (permalink / raw)
  To: Junio C Hamano, Jeremy Morton; +Cc: git

p4merge does not properly handle the case where "/dev/null"
is passed as a filename.

Workaround it by creating a temporary file for this purpose.

Reported-by: Jeremy Morton <admin@game-point.net>
Signed-off-by: David Aguilar <davvid@gmail.com>
---
Jeremy, can you test this?

 mergetools/p4merge | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/mergetools/p4merge b/mergetools/p4merge
index 1a45c1b..295361a 100644
--- a/mergetools/p4merge
+++ b/mergetools/p4merge
@@ -1,5 +1,30 @@
 diff_cmd () {
+	# p4merge does not like /dev/null
+	rm_local=
+	rm_remote=
+	if test "/dev/null" = "$LOCAL"
+	then
+		LOCAL="./p4merge-dev-null.LOCAL.$$"
+		>"$LOCAL"
+		rm_local=true
+	fi
+	if test "/dev/null" = "$REMOTE"
+	then
+		REMOTE="./p4merge-dev-null.REMOTE.$$"
+		>"$REMOTE"
+		rm_remote=true
+	fi
+
 	"$merge_tool_path" "$LOCAL" "$REMOTE"
+
+	if test -n "$rm_local"
+	then
+		rm -f "$LOCAL"
+	fi
+	if test -n "$rm_remote"
+	then
+		rm -f "$REMOTE"
+	fi
 }
 
 merge_cmd () {
-- 
1.8.0.rc1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mergetools/p4merge: Handle "/dev/null"
  2012-10-11  3:22 [PATCH] mergetools/p4merge: Handle "/dev/null" David Aguilar
@ 2012-10-27  8:47 ` Jeremy Morton
  2012-12-20  4:41   ` David Aguilar
  0 siblings, 1 reply; 3+ messages in thread
From: Jeremy Morton @ 2012-10-27  8:47 UTC (permalink / raw)
  To: David Aguilar; +Cc: Junio C Hamano, git

Sorry to be replying to this so late; I hadn't noticed the post until now!

I've tried putting that code in my p4merge script and yes it does indeed 
work fine.  However, it puts a temporary file in the working directory 
which I'm not sure is a good idea?  If we look at this patch which 
actually solved pretty much the same problem, but when merging and, 
during a merge conflict, a file was created in both branches:
https://github.com/git/git/commit/ec245ba

... it is creating a temp file in a proper temp dir, rather than in the 
working dir.  I think that would be the proper solution here.  However, 
I really want to get this fixed so I'd be happy for this band-aid fix of 
the p4merge script to be checked in until we could get a patch more like 
the aforementioned one, at a later date, to create empty files in a 
proper temp dir and pass them as $LOCAL and $REMOTE.  :-)

-- 
Best regards,
Jeremy Morton (Jez)

On 11/10/2012 04:22, David Aguilar wrote:
> p4merge does not properly handle the case where "/dev/null"
> is passed as a filename.
>
> Workaround it by creating a temporary file for this purpose.
>
> Reported-by: Jeremy Morton<admin@game-point.net>
> Signed-off-by: David Aguilar<davvid@gmail.com>
> ---
> Jeremy, can you test this?
>
>   mergetools/p4merge | 25 +++++++++++++++++++++++++
>   1 file changed, 25 insertions(+)
>
> diff --git a/mergetools/p4merge b/mergetools/p4merge
> index 1a45c1b..295361a 100644
> --- a/mergetools/p4merge
> +++ b/mergetools/p4merge
> @@ -1,5 +1,30 @@
>   diff_cmd () {
> +	# p4merge does not like /dev/null
> +	rm_local=
> +	rm_remote=
> +	if test "/dev/null" = "$LOCAL"
> +	then
> +		LOCAL="./p4merge-dev-null.LOCAL.$$"
> +		>"$LOCAL"
> +		rm_local=true
> +	fi
> +	if test "/dev/null" = "$REMOTE"
> +	then
> +		REMOTE="./p4merge-dev-null.REMOTE.$$"
> +		>"$REMOTE"
> +		rm_remote=true
> +	fi
> +
>   	"$merge_tool_path" "$LOCAL" "$REMOTE"
> +
> +	if test -n "$rm_local"
> +	then
> +		rm -f "$LOCAL"
> +	fi
> +	if test -n "$rm_remote"
> +	then
> +		rm -f "$REMOTE"
> +	fi
>   }
>
>   merge_cmd () {

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mergetools/p4merge: Handle "/dev/null"
  2012-10-27  8:47 ` Jeremy Morton
@ 2012-12-20  4:41   ` David Aguilar
  0 siblings, 0 replies; 3+ messages in thread
From: David Aguilar @ 2012-12-20  4:41 UTC (permalink / raw)
  To: Jeremy Morton; +Cc: Junio C Hamano, git

On Sat, Oct 27, 2012 at 1:47 AM, Jeremy Morton <admin@game-point.net> wrote:
> Sorry to be replying to this so late; I hadn't noticed the post until now!
>
> I've tried putting that code in my p4merge script and yes it does indeed
> work fine.  However, it puts a temporary file in the working directory which
> I'm not sure is a good idea?  If we look at this patch which actually solved
> pretty much the same problem, but when merging and, during a merge conflict,
> a file was created in both branches:
> https://github.com/git/git/commit/ec245ba
>
> ... it is creating a temp file in a proper temp dir, rather than in the
> working dir.  I think that would be the proper solution here.  However, I
> really want to get this fixed so I'd be happy for this band-aid fix of the
> p4merge script to be checked in until we could get a patch more like the
> aforementioned one, at a later date, to create empty files in a proper temp
> dir and pass them as $LOCAL and $REMOTE.  :-)

I had the same thoughts when I wrote it, but I figured that following
the existing pattern used by mergetool for $REMOTE and $LOCAL when
they do exist was simpler as the first step.

I have a patch that fixes this by using mktemp that I will send shortly.
It only does it for the /dev/null file since the existing behavior for
files that do exist is fine.
-- 
David

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-12-20  4:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-11  3:22 [PATCH] mergetools/p4merge: Handle "/dev/null" David Aguilar
2012-10-27  8:47 ` Jeremy Morton
2012-12-20  4:41   ` David Aguilar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).