2011-08-18 11:23:46 +04:00
|
|
|
diff_cmd () {
|
2012-12-27 04:45:29 +04:00
|
|
|
empty_file=
|
|
|
|
|
2012-10-11 07:22:36 +04:00
|
|
|
# p4merge does not like /dev/null
|
|
|
|
if test "/dev/null" = "$LOCAL"
|
|
|
|
then
|
2012-12-27 04:45:29 +04:00
|
|
|
LOCAL="$(create_empty_file)"
|
2012-10-11 07:22:36 +04:00
|
|
|
fi
|
|
|
|
if test "/dev/null" = "$REMOTE"
|
|
|
|
then
|
2012-12-27 04:45:29 +04:00
|
|
|
REMOTE="$(create_empty_file)"
|
2012-10-11 07:22:36 +04:00
|
|
|
fi
|
|
|
|
|
2011-08-18 11:23:46 +04:00
|
|
|
"$merge_tool_path" "$LOCAL" "$REMOTE"
|
2012-10-11 07:22:36 +04:00
|
|
|
|
2012-12-27 04:45:29 +04:00
|
|
|
if test -n "$empty_file"
|
2012-10-11 07:22:36 +04:00
|
|
|
then
|
2012-12-27 04:45:29 +04:00
|
|
|
rm -f "$empty_file"
|
2012-10-11 07:22:36 +04:00
|
|
|
fi
|
2011-08-18 11:23:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
merge_cmd () {
|
|
|
|
touch "$BACKUP"
|
mergetools/p4merge: create a base if none available
Originally, with no base, Git gave P4Merge $LOCAL as a dummy base:
p4merge "$LOCAL" "$LOCAL" "$REMOTE" "$MERGED"
Commit 0a0ec7bd changed this to:
p4merge "empty file" "$LOCAL" "$REMOTE" "$MERGED"
to avoid the problem of being unable to save in some circumstances with
similar inputs.
Unfortunately this approach produces much worse results on differing
inputs. P4Merge really regards the blank file as the base, and once you
have just a couple of differences between the two branches you end up
with one a massive full-file conflict. The 3-way diff is not readable,
and you have to invoke "difftool MERGE_HEAD HEAD" manually to get a
useful view.
The original approach appears to have invoked special 2-way merge
behaviour in P4Merge that occurs only if the base filename is "" or
equal to the left input. You get a good visual comparison, and it does
not auto-resolve differences. (Normally if one branch matched the base,
it would autoresolve to the other branch).
But there appears to be no way of getting this 2-way behaviour and being
able to reliably save. Having base==left appears to be triggering other
assumptions. There are tricks the user can use to force the save icon
on, but it's not intuitive.
So we now follow a suggestion given in the original patch's discussion:
generate a virtual base, consisting of the lines common to the two
branches. This is the same as the technique used in resolve and octopus
merges, so we relocate that code to a shared function.
Note that if there are no differences at the same location, this
technique can lead to automatic resolution without conflict, combining
everything from the 2 files. As with the other merges using this
technique, we assume the user will inspect the result before saving.
Signed-off-by: Kevin Bracey <kevin@bracey.fi>
Reviewed-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-03-13 05:12:21 +04:00
|
|
|
if ! $base_present
|
|
|
|
then
|
|
|
|
cp -- "$LOCAL" "$BASE"
|
|
|
|
create_virtual_base "$BASE" "$REMOTE"
|
|
|
|
fi
|
mergetools/p4merge: swap LOCAL and REMOTE
Reverse LOCAL and REMOTE when invoking P4Merge as a mergetool, so that
the incoming branch is now in the left-hand, blue triangle pane, and the
current branch is in the right-hand, green circle pane.
This change makes use of P4Merge consistent with its built-in help, its
reference documentation, and Perforce itself. But most importantly, it
makes merge results clearer. P4Merge is not totally symmetrical between
left and right; despite changing a few text labels from "theirs/ours" to
"left/right" when invoked manually, it still retains its original
Perforce "theirs/ours" viewpoint.
Most obviously, in the result pane P4Merge shows changes that are common
to both branches in green. This is on the basis of the current branch
being green, as it is when invoked from Perforce; it means that lines in
the result are blue if and only if they are being changed by the merge,
making the resulting diff clearer.
Note that P4Merge now shows "ours" on the right for both diff and merge,
unlike other diff/mergetools, which always have REMOTE on the right.
But observe that REMOTE is the working tree (ie "ours") for a diff,
while it's another branch (ie "theirs") for a merge.
Ours and theirs are reversed for a rebase - see "git help rebase".
However, this does produce the desired "show the results of this commit"
effect in P4Merge - changes that remain in the rebased commit (in your
branch, but not in the new base) appear in blue; changes that do not
appear in the rebased commit (from the new base, or common to both) are
in green. If Perforce had rebase, they'd probably not swap ours/theirs,
but make P4Merge show common changes in blue, picking out our changes in
green. We can't do that, so this is next best.
Signed-off-by: Kevin Bracey <kevin@bracey.fi>
Reviewed-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-03-13 05:12:20 +04:00
|
|
|
"$merge_tool_path" "$BASE" "$REMOTE" "$LOCAL" "$MERGED"
|
2011-08-18 11:23:46 +04:00
|
|
|
check_unchanged
|
|
|
|
}
|
2012-12-27 04:45:29 +04:00
|
|
|
|
|
|
|
create_empty_file () {
|
|
|
|
empty_file="${TMPDIR:-/tmp}/git-difftool-p4merge-empty-file.$$"
|
|
|
|
>"$empty_file"
|
|
|
|
|
2013-02-10 05:21:25 +04:00
|
|
|
printf "%s" "$empty_file"
|
2012-12-27 04:45:29 +04:00
|
|
|
}
|