# [RFC] Introduce git-xxdiff to invoke xxdiff for manual conflict resolution

9 messages from 2006-08-03 to 2006-08-05. Participants: Martin Langhoff, Junio C Hamano, Martin Langhoff (CatalystIT), Jeff King, Alex Riesen.
Thread: https://gitlist.dev/t/5112

## Martin Langhoff, 2006-08-03 23:53

Subject: [RFC] Introduce git-xxdiff to invoke xxdiff for manual conflict resolution
Message-ID: <11546492331601-git-send-email-martin@catalyst.net.nz>
URL: https://gitlist.dev/e/11546492331601-git-send-email-martin%40catalyst.net.nz

```
This is a bit of a crude but really useful shortcut for conflict resolution.
The name is bad, but git-merge-* is a different 'namespace', and git-resolve is
also taken.

And as different conflict resolvers take different options, it may make sense
to have git-xxdiff, git-sdiff and git-winmerge at least initially.

Signed-off-by: Martin Langhoff <martin@catalyst.net.nz>
---
 Makefile      |    2 +-
 git-xxdiff.sh |   38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 8349e3d..a6f6628 100644
--- a/Makefile
+++ b/Makefile
@@ -145,7 +145,7 @@ SCRIPT_SH = \
 	git-applymbox.sh git-applypatch.sh git-am.sh \
 	git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
 	git-merge-resolve.sh git-merge-ours.sh \
-	git-lost-found.sh git-quiltimport.sh
+	git-lost-found.sh git-quiltimport.sh git-xxdiff.sh
 
 SCRIPT_PERL = \
 	git-archimport.perl git-cvsimport.perl git-relink.perl \
diff --git a/git-xxdiff.sh b/git-xxdiff.sh
new file mode 100755
index 0000000..d562ab2
--- /dev/null
+++ b/git-xxdiff.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+USAGE='<path>'
+SUBDIRECTORY_OK=No
+. git-sh-setup
+
+FILE=$1
+MERGE_HEAD=`git rev-parse MERGE_HEAD`
+
+# Sanity checks
+if test ! -n "$FILE"
+then
+	echo Need a path
+	exit 1
+fi
+
+if test ! -n "$MERGE_HEAD"
+then
+	echo git-xxdiff is only useful during a merge
+fi
+
+git cat-file blob HEAD:$FILE > $FILE~HEAD
+if test $? -gt 0
+then 
+	echo "Error - maybe $FILE is not tracked by git?"
+	exit
+fi
+echo Written $FILE~HEAD
+
+git cat-file blob $MERGE_HEAD:$FILE > $FILE~MERGE_HEAD
+if  test $? -gt 0
+then 
+	echo "Error - maybe $FILE is not tracked by git?"
+	exit
+fi
+echo Written $FILE~MERGE_HEAD
+
+xxdiff -wbB --show-merged-pane --merged-filename $FILE~merged $FILE~HEAD $FILE~MERGE_HEAD
\ No newline at end of file
-- 
1.4.2.rc2.g1869bc-dirty

```

## Junio C Hamano, 2006-08-04 00:01

Subject: Re: [RFC] Introduce git-xxdiff to invoke xxdiff for manual conflict resolution
Message-ID: <7v64h9pdx4.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v64h9pdx4.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <11546492331601-git-send-email-martin@catalyst.net.nz>

```
Martin Langhoff <martin@catalyst.net.nz> writes:

> diff --git a/git-xxdiff.sh b/git-xxdiff.sh
> new file mode 100755
> index 0000000..d562ab2
> --- /dev/null
> +++ b/git-xxdiff.sh
> @@ -0,0 +1,38 @@
> +#!/bin/sh
> +
> +USAGE='<path>'
> +SUBDIRECTORY_OK=No
> +. git-sh-setup
> +
> +FILE=$1
> +MERGE_HEAD=`git rev-parse MERGE_HEAD`
> +
> +# Sanity checks

We can have unmerged index without MERGE_HEAD (for example,
think "rebase --merge" or "am -3"); drop check for that and
instead check for stage 2 ("ours") for the path.

	git cat-file blob :2:$FILE

Can xxdiff take more than one file pairs?

If so you might want to list unmerged paths (ls-files -u) and
iterate through it when no paths are given from the command
line.  If not, you might want to take the first unmerged path
when no paths are given from the command line.

> +xxdiff -wbB --show-merged-pane --merged-filename $FILE~merged $FILE~HEAD $FILE~MERGE_HEAD
> \ No newline at end of file

;-).

```

## Martin Langhoff (CatalystIT), 2006-08-04 00:16

Subject: Re: [RFC] Introduce git-xxdiff to invoke xxdiff for manual conflict resolution
Message-ID: <44D291EF.4020506@catalyst.net.nz>
URL: https://gitlist.dev/e/44D291EF.4020506%40catalyst.net.nz
In-Reply-To: <7v64h9pdx4.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano wrote:

>>diff --git a/git-xxdiff.sh b/git-xxdiff.sh
>>new file mode 100755
>>index 0000000..d562ab2
>>--- /dev/null
>>+++ b/git-xxdiff.sh
>>@@ -0,0 +1,38 @@
>>+#!/bin/sh
>>+
>>+USAGE='<path>'
>>+SUBDIRECTORY_OK=No
>>+. git-sh-setup
>>+
>>+FILE=$1
>>+MERGE_HEAD=`git rev-parse MERGE_HEAD`
>>+
>>+# Sanity checks
> 
> 
> We can have unmerged index without MERGE_HEAD (for example,
> think "rebase --merge" or "am -3"); drop check for that and
> instead check for stage 2 ("ours") for the path.
> 
> 	git cat-file blob :2:$FILE

(didn't know the :$stage: trick, neat)

I did think of using merge stages but I wasn't sure whether all the 
merge strategies followed the same convention. I'll fix up and re-post it.

> Can xxdiff take more than one file pairs?

Not that I can see.

>>+xxdiff -wbB --show-merged-pane --merged-filename $FILE~merged $FILE~HEAD $FILE~MERGE_HEAD
>>\ No newline at end of file
> 
> ;-).

Ouch, yes, I forgot the newline. Grumble.

I am also telling xxdiff to save the merged file as ~merged rather than 
overwriting the merge attempt that git has made. Better safe than sorry.

cheers,

m
-- 
-----------------------------------------------------------------------
Martin @ Catalyst .Net .NZ  Ltd, PO Box 11-053, Manners St,  Wellington
WEB: http://catalyst.net.nz/           PHYS: Level 2, 150-154 Willis St
OFFICE: +64(4)916-7224                              MOB: +64(21)364-017
       Make things as simple as possible, but no simpler - Einstein
-----------------------------------------------------------------------

```

## Martin Langhoff, 2006-08-04 00:37

Subject: [RFC] Introduce git-xxdiff to invoke xxdiff for manual conflict resolution - take 2
Message-ID: <11546518271379-git-send-email-martin@catalyst.net.nz>
URL: https://gitlist.dev/e/11546518271379-git-send-email-martin%40catalyst.net.nz
In-Reply-To: <7v64h9pdx4.fsf@assigned-by-dhcp.cox.net>

```
This is a bit of a crude but really useful shortcut for conflict resolution.
The name is bad, but git-merge-* is a different 'namespace', and git-resolve is
also taken.

And as different conflict resolvers take different options, it may make sense
to have git-xxdiff, git-sdiff and git-winmerge at least initially.

Reposting with some fixes suggested by Junio.

Signed-off-by: Martin Langhoff <martin@catalyst.net.nz>
---

How about this one? ;-)
---
 Makefile      |    2 +-
 git-xxdiff.sh |   33 +++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 8349e3d..a6f6628 100644
--- a/Makefile
+++ b/Makefile
@@ -145,7 +145,7 @@ SCRIPT_SH = \
 	git-applymbox.sh git-applypatch.sh git-am.sh \
 	git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \
 	git-merge-resolve.sh git-merge-ours.sh \
-	git-lost-found.sh git-quiltimport.sh
+	git-lost-found.sh git-quiltimport.sh git-xxdiff.sh
 
 SCRIPT_PERL = \
 	git-archimport.perl git-cvsimport.perl git-relink.perl \
diff --git a/git-xxdiff.sh b/git-xxdiff.sh
new file mode 100755
index 0000000..3dc9876
--- /dev/null
+++ b/git-xxdiff.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+
+USAGE='<path-with-conflict>'
+SUBDIRECTORY_OK=No
+. git-sh-setup
+
+FILE=$1
+
+# Sanity checks
+if test ! -n "$FILE"
+then
+	echo Need a path
+	exit 1
+fi
+
+git cat-file blob :2:$FILE > $FILE~ours
+if test $? -gt 0
+then 
+	echo "Error - $FILE is not tracked by git or does not have a conflict"
+	exit 1
+fi
+echo Written $FILE~ours
+
+git cat-file blob :3:$FILE > $FILE~branch
+if  test $? -gt 0
+then 
+	echo "Error - $FILE is not tracked by git or does not have a conflict"
+	exit 1
+fi
+echo Written $FILE~branch
+echo Resolved file will be saved as $FILE~merged
+
+xxdiff -wbB --show-merged-pane --merged-filename $FILE~merged $FILE~ours $FILE~branch
-- 
1.4.2.rc2.g1869bc-dirty

```

## Martin Langhoff (CatalystIT), 2006-08-04 00:37

Subject: Re: [RFC] Introduce git-xxdiff to invoke xxdiff for manual conflict resolution
Message-ID: <44D296D8.4030200@catalyst.net.nz>
URL: https://gitlist.dev/e/44D296D8.4030200%40catalyst.net.nz
In-Reply-To: <7v64h9pdx4.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano wrote:

> We can have unmerged index without MERGE_HEAD (for example,
> think "rebase --merge" or "am -3"); drop check for that and
> instead check for stage 2 ("ours") for the path.

Reading Documentation/git-read-tree.txt it seems to mean that stage 1 is 
merge base, 1 is ours and 2 is the branch being merged in.

I am confused...

Quote:
> When performing a merge of another
> branch into the current branch, we use the common ancestor tree
> as <tree1>, the current branch head as <tree2>, and the other
> branch head as <tree3>.


m
-- 
-----------------------------------------------------------------------
Martin @ Catalyst .Net .NZ  Ltd, PO Box 11-053, Manners St,  Wellington
WEB: http://catalyst.net.nz/           PHYS: Level 2, 150-154 Willis St
OFFICE: +64(4)916-7224                              MOB: +64(21)364-017
       Make things as simple as possible, but no simpler - Einstein
-----------------------------------------------------------------------

```

## Jeff King, 2006-08-04 03:31

Subject: Re: [RFC] Introduce git-xxdiff to invoke xxdiff for manual conflict resolution
Message-ID: <20060804033144.GB24818@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20060804033144.GB24818%40coredump.intra.peff.net
In-Reply-To: <44D296D8.4030200@catalyst.net.nz>

```
On Fri, Aug 04, 2006 at 12:37:44PM +1200, Martin Langhoff (CatalystIT) wrote:

> >instead check for stage 2 ("ours") for the path.
> Reading Documentation/git-read-tree.txt it seems to mean that stage 1 is 
> merge base, 1 is ours and 2 is the branch being merged in.
> 
> I am confused...
> 
> Quote:
> >When performing a merge of another
> >branch into the current branch, we use the common ancestor tree
> >as <tree1>, the current branch head as <tree2>, and the other
> >branch head as <tree3>.

Look further down:
   OK, this all sounds like a collection of totally nonsensical rules,
   but it's actually exactly what you want in order to do a  fast
   merge.  The different stages  represent the "result tree" (stage 0,
   aka "merged"), the original tree (stage 1, aka "orig"), and the two
   trees you are trying to merge (stage 2 and 3 respectively).

HTH,
-Peff

```

## Martin Langhoff (CatalystIT), 2006-08-04 03:48

Subject: Re: [RFC] Introduce git-xxdiff to invoke xxdiff for manual conflict resolution
Message-ID: <44D2C393.8090508@catalyst.net.nz>
URL: https://gitlist.dev/e/44D2C393.8090508%40catalyst.net.nz
In-Reply-To: <20060804033144.GB24818@coredump.intra.peff.net>

```
Jeff King wrote:

> On Fri, Aug 04, 2006 at 12:37:44PM +1200, Martin Langhoff (CatalystIT) wrote:
> 
> 
>>>instead check for stage 2 ("ours") for the path.
>>
>>Reading Documentation/git-read-tree.txt it seems to mean that stage 1 is 
>>merge base, 1 is ours and 2 is the branch being merged in.
>>
>>I am confused...
>>
>>Quote:
>>
>>>When performing a merge of another
>>>branch into the current branch, we use the common ancestor tree
>>>as <tree1>, the current branch head as <tree2>, and the other
>>>branch head as <tree3>.
> 
> 
> Look further down:
>    OK, this all sounds like a collection of totally nonsensical rules,
>    but it's actually exactly what you want in order to do a  fast
>    merge.  The different stages  represent the "result tree" (stage 0,
>    aka "merged"), the original tree (stage 1, aka "orig"), and the two
>    trees you are trying to merge (stage 2 and 3 respectively).

Grr. I just re-read my own email, and I can't believe how stupid my 
question was. Still, git-xxdiff is doing the right thing, stage 2 is 
"ours" and stage 3 is "branch we are merging in".

cheers,


martin
-- 
-----------------------------------------------------------------------
Martin @ Catalyst .Net .NZ  Ltd, PO Box 11-053, Manners St,  Wellington
WEB: http://catalyst.net.nz/           PHYS: Level 2, 150-154 Willis St
OFFICE: +64(4)916-7224                              MOB: +64(21)364-017
       Make things as simple as possible, but no simpler - Einstein
-----------------------------------------------------------------------

```

## Alex Riesen, 2006-08-04 08:09

Subject: Re: [RFC] Introduce git-xxdiff to invoke xxdiff for manual conflict resolution - take 2
Message-ID: <81b0412b0608040109q683bd628rd9238662e0fdfb0@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0608040109q683bd628rd9238662e0fdfb0%40mail.gmail.com
In-Reply-To: <11546518271379-git-send-email-martin@catalyst.net.nz>

```
On 8/4/06, Martin Langhoff <martin@catalyst.net.nz> wrote:
> This is a bit of a crude but really useful shortcut for conflict resolution.
> The name is bad, but git-merge-* is a different 'namespace', and git-resolve is
> also taken.

git-xxmerge?

```

## Martin Langhoff, 2006-08-05 03:26

Subject: Re: [RFC] Introduce git-xxdiff to invoke xxdiff for manual conflict resolution - take 2
Message-ID: <46a038f90608042026l732cef04u46df9b3429cd04d4@mail.gmail.com>
URL: https://gitlist.dev/e/46a038f90608042026l732cef04u46df9b3429cd04d4%40mail.gmail.com
In-Reply-To: <81b0412b0608040109q683bd628rd9238662e0fdfb0@mail.gmail.com>

```
On 8/4/06, Alex Riesen <raa.lkml@gmail.com> wrote:
> On 8/4/06, Martin Langhoff <martin@catalyst.net.nz> wrote:
> > This is a bit of a crude but really useful shortcut for conflict resolution.
> > The name is bad, but git-merge-* is a different 'namespace', and git-resolve is
> > also taken.
>
> git-xxmerge?

Well, the xx part is taken because it uses xxdiff, so I thought
perhaps we can have trivial git wrappers for many popular mergers. Ie:
git-wiggle, git-sdiff.

We could have a single command with a 'strategy' parameter, say

     git-mergehelper -s [xxdiff|sdiff|wiggle] path/to/file

but separate commands are easier for prototyping IMVHO.

cheers,


martin

```
