From 4549162e8d623d69ea48745fce3709e5133ce043 Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Wed, 13 Mar 2013 03:12:21 +0200 Subject: 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 Reviewed-by: David Aguilar Signed-off-by: Junio C Hamano --- git-merge-one-file.sh | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'git-merge-one-file.sh') diff --git a/git-merge-one-file.sh b/git-merge-one-file.sh index f612cb847a..0f164e54c1 100755 --- a/git-merge-one-file.sh +++ b/git-merge-one-file.sh @@ -104,30 +104,22 @@ case "${1:-.}${2:-.}${3:-.}" in ;; esac - src2=`git-unpack-file $3` + src1=$(git-unpack-file $2) + src2=$(git-unpack-file $3) case "$1" in '') echo "Added $4 in both, but differently." - # This extracts OUR file in $orig, and uses git apply to - # remove lines that are unique to ours. - orig=`git-unpack-file $2` - sz0=`wc -c <"$orig"` - @@DIFF@@ -u -La/$orig -Lb/$orig $orig $src2 | git apply --no-add - sz1=`wc -c <"$orig"` - - # If we do not have enough common material, it is not - # worth trying two-file merge using common subsections. - expr $sz0 \< $sz1 \* 2 >/dev/null || : >$orig + orig=$(git-unpack-file $2) + create_virtual_base "$orig" "$src2" ;; *) echo "Auto-merging $4" - orig=`git-unpack-file $1` + orig=$(git-unpack-file $1) ;; esac # Be careful for funny filename such as "-L" in "$4", which # would confuse "merge" greatly. - src1=`git-unpack-file $2` git merge-file "$src1" "$orig" "$src2" ret=$? msg= -- cgit v1.2.3 From 530333cfe851b68a3635ee5bcfe707799dab9b83 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 25 Mar 2013 10:48:24 -0700 Subject: merge-one-file: remove stale comment The "funny filename" comment was from b539c5e8fbd3 (git-merge-one: new merge world order., 2005-12-07) where the removed code just before that new comment ended with: merge "$4" "$orig" "$src2" (yes, we used to use "merge" program from the RCS suite). The comment refers to one of the bad side effect the old code used to have and warns against such a practice, i.e. it was talking about the code that no longer existed. Signed-off-by: Junio C Hamano --- git-merge-one-file.sh | 2 -- 1 file changed, 2 deletions(-) (limited to 'git-merge-one-file.sh') diff --git a/git-merge-one-file.sh b/git-merge-one-file.sh index 0f164e54c1..57fad733ba 100755 --- a/git-merge-one-file.sh +++ b/git-merge-one-file.sh @@ -118,8 +118,6 @@ case "${1:-.}${2:-.}${3:-.}" in ;; esac - # Be careful for funny filename such as "-L" in "$4", which - # would confuse "merge" greatly. git merge-file "$src1" "$orig" "$src2" ret=$? msg= -- cgit v1.2.3 From 333ea38db95c77fad8b18daa80bbf0f96fee556c Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Sun, 24 Mar 2013 14:26:23 +0200 Subject: git-merge-one-file: style cleanup Update style to match Documentation/CodingGuidelines. Signed-off-by: Kevin Bracey Signed-off-by: Junio C Hamano --- git-merge-one-file.sh | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'git-merge-one-file.sh') diff --git a/git-merge-one-file.sh b/git-merge-one-file.sh index 57fad733ba..c90b9ffd31 100755 --- a/git-merge-one-file.sh +++ b/git-merge-one-file.sh @@ -27,7 +27,7 @@ SUBDIRECTORY_OK=Yes cd_to_toplevel require_work_tree -if ! test "$#" -eq 7 +if test $# != 7 then echo "$LONG_USAGE" exit 1 @@ -38,7 +38,8 @@ case "${1:-.}${2:-.}${3:-.}" in # Deleted in both or deleted in one and unchanged in the other # "$1.." | "$1.$1" | "$1$1.") - if [ "$2" ]; then + if test -n "$2" + then echo "Removing $4" else # read-tree checked that index matches HEAD already, @@ -48,7 +49,8 @@ case "${1:-.}${2:-.}${3:-.}" in # we do not have it in the index, though. exec git update-index --remove -- "$4" fi - if test -f "$4"; then + if test -f "$4" + then rm -f -- "$4" && rmdir -p "$(expr "z$4" : 'z\(.*\)/')" 2>/dev/null || : fi && @@ -78,7 +80,8 @@ case "${1:-.}${2:-.}${3:-.}" in # Added in both, identically (check for same permissions). # ".$3$2") - if [ "$6" != "$7" ]; then + if test "$6" != "$7" + then echo "ERROR: File $4 added identically in both branches," echo "ERROR: but permissions conflict $6->$7." exit 1 @@ -121,7 +124,8 @@ case "${1:-.}${2:-.}${3:-.}" in git merge-file "$src1" "$orig" "$src2" ret=$? msg= - if [ $ret -ne 0 ]; then + if test $ret != 0 + then msg='content conflict' fi @@ -130,18 +134,22 @@ case "${1:-.}${2:-.}${3:-.}" in git checkout-index -f --stage=2 -- "$4" && cat "$src1" >"$4" || exit 1 rm -f -- "$orig" "$src1" "$src2" - if [ "$6" != "$7" ]; then - if [ -n "$msg" ]; then + if test "$6" != "$7" + then + if test -n "$msg" + then msg="$msg, " fi msg="${msg}permissions conflict: $5->$6,$7" ret=1 fi - if [ "$1" = '' ]; then + if test -z "$1" + then ret=1 fi - if [ $ret -ne 0 ]; then + if test $ret != 0 + then echo "ERROR: $msg in $4" exit 1 fi -- cgit v1.2.3 From d401acf7036cf01d93d138239edf87a59f9627b4 Mon Sep 17 00:00:00 2001 From: Kevin Bracey Date: Sun, 24 Mar 2013 14:26:24 +0200 Subject: git-merge-one-file: send "ERROR:" messages to stderr Signed-off-by: Kevin Bracey Signed-off-by: Junio C Hamano --- git-merge-one-file.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'git-merge-one-file.sh') diff --git a/git-merge-one-file.sh b/git-merge-one-file.sh index c90b9ffd31..a93d0b4cd3 100755 --- a/git-merge-one-file.sh +++ b/git-merge-one-file.sh @@ -69,7 +69,7 @@ case "${1:-.}${2:-.}${3:-.}" in echo "Adding $4" if test -f "$4" then - echo "ERROR: untracked $4 is overwritten by the merge." + echo "ERROR: untracked $4 is overwritten by the merge." >&2 exit 1 fi git update-index --add --cacheinfo "$7" "$3" "$4" && @@ -82,8 +82,8 @@ case "${1:-.}${2:-.}${3:-.}" in ".$3$2") if test "$6" != "$7" then - echo "ERROR: File $4 added identically in both branches," - echo "ERROR: but permissions conflict $6->$7." + echo "ERROR: File $4 added identically in both branches," >&2 + echo "ERROR: but permissions conflict $6->$7." >&2 exit 1 fi echo "Adding $4" @@ -98,11 +98,11 @@ case "${1:-.}${2:-.}${3:-.}" in case ",$6,$7," in *,120000,*) - echo "ERROR: $4: Not merging symbolic link changes." + echo "ERROR: $4: Not merging symbolic link changes." >&2 exit 1 ;; *,160000,*) - echo "ERROR: $4: Not merging conflicting submodule changes." + echo "ERROR: $4: Not merging conflicting submodule changes." >&2 exit 1 ;; esac @@ -150,14 +150,14 @@ case "${1:-.}${2:-.}${3:-.}" in if test $ret != 0 then - echo "ERROR: $msg in $4" + echo "ERROR: $msg in $4" >&2 exit 1 fi exec git update-index -- "$4" ;; *) - echo "ERROR: $4: Not handling case $1 -> $2 -> $3" + echo "ERROR: $4: Not handling case $1 -> $2 -> $3" >&2 ;; esac exit 1 -- cgit v1.2.3 From 4fa5c0591a7b5c71c8ccf71d8401c3337b7867ad Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 25 Mar 2013 10:05:13 -0700 Subject: merge-one-file: force content conflict for "both sides added" case Historically, we tried to be lenient to "both sides added, slightly differently" case and as long as the files can be merged using a made-up common ancestor cleanly, since f7d24bbefb06 (merge with /dev/null as base, instead of punting O==empty case, 2005-11-07). This was later further refined to use a better made-up common file with fd66dbf5297a (merge-one-file: use empty- or common-base condintionally in two-stage merge., 2005-11-10), but the spirit has been the same. But the original fix in f7d24bbefb06 to avoid punting on "both sides added" case had a code to unconditionally error out the merge. When this triggers, even though the content-level merge can be done cleanly, we end up not saying "content conflict" in the message, but still issue the error message, showing "ERROR: in ". Move that "always fail for add/add conflict" logic a bit higher to fix this. Signed-off-by: Junio C Hamano --- git-merge-one-file.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'git-merge-one-file.sh') diff --git a/git-merge-one-file.sh b/git-merge-one-file.sh index a93d0b4cd3..7e82facf91 100755 --- a/git-merge-one-file.sh +++ b/git-merge-one-file.sh @@ -124,9 +124,10 @@ case "${1:-.}${2:-.}${3:-.}" in git merge-file "$src1" "$orig" "$src2" ret=$? msg= - if test $ret != 0 + if test $ret != 0 || test -z "$1" then msg='content conflict' + ret=1 fi # Create the working tree file, using "our tree" version from the @@ -143,10 +144,6 @@ case "${1:-.}${2:-.}${3:-.}" in msg="${msg}permissions conflict: $5->$6,$7" ret=1 fi - if test -z "$1" - then - ret=1 - fi if test $ret != 0 then -- cgit v1.2.3