mergetools/p4merge: Honor $TMPDIR for the /dev/null placeholder

Use $TMPDIR when creating the /dev/null placeholder for p4merge. This prevents users from finding a seemingly random untracked file in their worktree. This is different than what mergetool does with $LOCAL and $REMOTE because those files exist to aid users when resolving merges. p4merge's /dev/null placeholder is not helpful in that situation so it is sensible to keep it out of the worktree. Reported-by: Jeremy Morton <admin@game-point.net> Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

David Aguilar committed Dec 26, 2012 at 16:45 UTC 950b5680bdacd3eaa4a528f4dc2d5652f1beb88d
1 file changed +13 -14
mergetools/p4merge
+13 -14
@@ -1,29 +1,21 @@
1 diff_cmd () {
2 + empty_file=
3 +
4 # p4merge does not like /dev/null
3 - rm_local=
4 - rm_remote=
5 if test "/dev/null" = "$LOCAL"
6 then
7 - LOCAL="./p4merge-dev-null.LOCAL.$$"
8 - >"$LOCAL"
9 - rm_local=true
7 + LOCAL="$(create_empty_file)"
8 fi
9 if test "/dev/null" = "$REMOTE"
10 then
13 - REMOTE="./p4merge-dev-null.REMOTE.$$"
14 - >"$REMOTE"
15 - rm_remote=true
11 + REMOTE="$(create_empty_file)"
12 fi
13
14 "$merge_tool_path" "$LOCAL" "$REMOTE"
15
20 - if test -n "$rm_local"
21 - then
22 - rm -f "$LOCAL"
23 - fi
24 - if test -n "$rm_remote"
16 + if test -n "$empty_file"
17 then
26 - rm -f "$REMOTE"
18 + rm -f "$empty_file"
19 fi
20 }
21
@@ -33,3 +25,10 @@ merge_cmd () {
25 "$merge_tool_path" "$BASE" "$LOCAL" "$REMOTE" "$MERGED"
26 check_unchanged
27 }
28 +
29 +create_empty_file () {
30 + empty_file="${TMPDIR:-/tmp}/git-difftool-p4merge-empty-file.$$"
31 + >"$empty_file"
32 +
33 + printf "$empty_file"
34 +}