Skip to contentSkip to conversation

git-mergetool: wrap tools with 3 files only to use the BASE file instead of MERGED

DISCUSSION Jonathan Nieder 4 participants 7 messages Jun 15, 2016 1 message not in the archive

lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

(+cc: some relevant people)
Hi,

Tanguy Ortolo wrote[1]:

Quoted 22 lines

git-mergetool ideally uses tools that work with 4 files: BASE, LOCAL, REMOTE, which are the usual original and two new version of the file, and MERGED, which is where the tool is supposed to write the result of the merge.

The problem is that most tools, at least graphical ones, specifically meld, can only work with three files, as they save the result to the original file.

git-mergetool currently handles this situation by passing MERGED LOCAL REMOTE to the tool. This could be fine, but unfortunately MERGE contains the conflicts, formatted for manual resolution, so it is not really appropriate as an original file.

I think it would be better to wrap such merge tools by:
1. passing them BASE LOCAL REMOTE;
2. checking whether or not BASE hase been modified:
* if it has, then copying it to MERGED,
* if it has not, exiting with return code 1 (merge failed).
This check can be by either saving and comparing the mdate, or perhaps the SHA-1 hash of the BASE file.

Quoted 3 lines

If this sounds good enough, I can dive into git-mergetoo--lib and implement it. In the meantime, here is an example of a custom merge tool that wraps meld for that purpose.

I think you forgot to include the example. Anyway, at first glance it sounds like a sensible idea. David et al: thoughts?

Regards,
Jonathan

[1] http://bugs.debian.org/637355

#2 lore raw

Jonathan Nieder, 2011-08-10 11:12 UTC-0500:

Quoted 1 line

I think you forgot to include the example.

Yes, sorry. Here it is.

Signature · 1 line
Tanguy Ortolo

#! /bin/sh

BASE="$1"
LOCAL="$2"
REMOTE="$3"
MERGED="$4"

MTIME_BEFORE="$(stat --format='%Y' "$BASE")"
meld "$LOCAL" "$BASE" "$REMOTE"
MTIME_AFTER="$(stat --format="%Y" "$BASE")"

if [ "$MTIME_BEFORE" != "$MTIME_AFTER" ]
then
# The base file was modified, which means the user saved it cp "$BASE" "$MERGED"
else
# The user did not save the file: merge failed exit 1
fi

#3 lore raw
In reply to Jonathan Nieder
Quoted 8 lines · Jonathan Nieder
Quoted 8 lines

I think it would be better to wrap such merge tools by:
1. passing them BASE LOCAL REMOTE;
2. checking whether or not BASE hase been modified:
   * if it has, then copying it to MERGED,
   * if it has not, exiting with return code 1 (merge failed). This check can be by either saving and comparing the mdate, or perhaps the SHA-1 hash of the BASE file.

Quoted 6 lines
Quoted 3 lines

If this sounds good enough, I can dive into git-mergetoo--lib and implement it. In the meantime, here is an example of a custom merge tool that wraps meld for that purpose.

I think you forgot to include the example.  Anyway, at first glance it sounds like a sensible idea.  David et al: thoughts?

Sounds sensible to me, too. (Although I'm not affected, as fortunately the GUI merge tools I've been using so far, namely ECMerge and Beyond Compare 3, both allow to specify a separate merge output.)

Signature · 1 line
Sebastian Schuberth
#4 lore raw
In reply to Jonathan Nieder
Quoted 27 lines · Jonathan Nieder

(+cc: some relevant people)
Hi,

Tanguy Ortolo wrote[1]:

Quoted 22 lines

git-mergetool ideally uses tools that work with 4 files: BASE, LOCAL, REMOTE, which are the usual original and two new version of the file, and MERGED, which is where the tool is supposed to write the result of the merge.

The problem is that most tools, at least graphical ones, specifically meld, can only work with three files, as they save the result to the original file.

git-mergetool currently handles this situation by passing MERGED LOCAL REMOTE to the tool. This could be fine, but unfortunately MERGE contains the conflicts, formatted for manual resolution, so it is not really appropriate as an original file.

I think it would be better to wrap such merge tools by:
1. passing them BASE LOCAL REMOTE;
2. checking whether or not BASE hase been modified:
* if it has, then copying it to MERGED,
* if it has not, exiting with return code 1 (merge failed).
This check can be by either saving and comparing the mdate, or perhaps the SHA-1 hash of the BASE file.

Quoted 6 lines
Quoted 3 lines

If this sounds good enough, I can dive into git-mergetoo--lib and implement it. In the meantime, here is an example of a custom merge tool that wraps meld for that purpose.

I think you forgot to include the example. Anyway, at first glance it sounds like a sensible idea. David et al: thoughts?

I think it sounds like a good thing for certain tools. Sebastian mentioned it being fine in ecmerge and bc3. xxdiff also lets you specify the output file, so it probably wouldn't need it either, I think.

If the patch touches individual tools that need it, e.g. meld, I say go for it.

Quoted 4 lines

Regards,
Jonathan

[1] http://bugs.debian.org/637355

cheers,

Signature · 1 line
					David
#5 lore raw
Quoted 4 lines · David Aguilar

I think it sounds like a good thing for certain tools. Sebastian mentioned it being fine in ecmerge and bc3. xxdiff also lets you specify the output file, so it probably wouldn't need it either, I think.

At the risk of taking away the itch for a good feature: meld joined the crowd of tools with -o to specify an output file in v1.5.0.

http://thread.gmane.org/gmane.comp.gnome.meld.general/1270

#6 lore raw
Quoted 11 lines · Jonathan Nieder
Quoted 4 lines · David Aguilar

I think it sounds like a good thing for certain tools. Sebastian mentioned it being fine in ecmerge and bc3. xxdiff also lets you specify the output file, so it probably wouldn't need it either, I think.

At the risk of taking away the itch for a good feature: meld joined the crowd of tools with -o to specify an output file in v1.5.0.

http://thread.gmane.org/gmane.comp.gnome.meld.general/1270

What's the best way to use this and not break existing users?

meld v1.5.0 was released in December.
We could parse meld --version and use the new --output flag on newer setups, leaving old setups alone. That's a lot of code to carry around but it's nicest to users.

Here's another idea..
mergetool--lib has vimdiff and vimdiff2. Maybe we can add a new meld3 tool that uses the --output flag? Users with older setups are unaffected. Documentation is changed to mention meld v1.5.0 and the meld3 tool. New users have to configure :-/

Alternatively, rename the existing meld to meld2 and let the new style call take over the current meld tool. Older setups with new git that use meld can adjust their config.

(and the final option: refactor mergetool--lib into separate
files. Yes, we should do that too! ;-))

what do you think?

Signature · 1 line
					David
#7 lore raw
Quoted 6 lines · David Aguilar

What's the best way to use this and not break existing users?

meld v1.5.0 was released in December.
We could parse meld --version and use the new --output flag on newer setups, leaving old setups alone.  That's a lot of code to carry around but it's nicest to users.

I'd definitely prefer this solution, as it's the most convenient for users.

Signature · 1 line
Sebastian Schuberth