Merge strategy 'applyreject'
RFC 1/1 Merge strategy 'applyreject'
Any thoughts on something like the following?
I was talking with Jakub Narebski on #git today about using a diff/apply pipeline as a merge strategy.
I was talking about implementing this within the merge-recur driver as an alternative to invoking the RCS 'merge' program. The idea would be to take the current branch's file and try to apply the diff of merge_base and the other branch to it. If that has any rejects then try the other direction (apply diff of merge_base and current to other) and leave the user with whichever one resulted in the smallest number of rejected lines.
But that's a little bit more work, this is a quick hack. :-)
-- >8 --
Create merge strategy 'applyreject'.
The applyreject merge strategy is a two head merge strategy which performs the merge by obtaining the diff between the common base and the branch being merged and applies it to the current branch using git-apply --reject. Consequently any failures are written to .rej files, rather than using the RCS <<<<<<< ======= >>>>>>> format.
--- .gitignore | 1 + Makefile | 1 + git-merge-applyreject.sh | 26 ++++++++++++++++++++++++++ git-merge.sh | 2 +- 4 files changed, 29 insertions(+), 1 deletions(-)
.gitignore +1 -0
@@ -56,6 +56,7 @@ git-ls-tree git-mailinfo git-mailsplit git-merge +git-merge-applyreject git-merge-base git-merge-index git-merge-tree
Makefile +1 -0
@@ -161,6 +161,7 @@ SCRIPT_SH = \ git-tag.sh git-verify-tag.sh \ git-applymbox.sh git-applypatch.sh git-am.sh \ git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \ + git-merge-applyreject.sh \ git-merge-resolve.sh git-merge-ours.sh \ git-lost-found.sh git-quiltimport.sh
git-merge-applyreject.sh new file +26 -0
@@ -0,0 +1,26 @@ +#!/bin/sh +# +# Simple merge strategy which produces reject files on failed merges. +# Only handles two heads and one merge base, thus the command line +# parameters must be: base -- head1 head2 + +base="$1"; shift; [ -z "$base" ] && exit 2 +while [ $# -gt 2 -a "X$1" != "X--" ] +do + shift +done +if [ "X$1" = "X--" ] +then + shift +else + exit 2 +fi +current="$1"; shift; [ -z "$current" ] && exit 2 +incoming="$1"; shift; [ -z "$incoming" ] && exit 2 +[ $# -gt 0 ] && exit 2 + +git-read-tree --reset $current || exit 2 +git-update-index --refresh 2>/dev/null +git-diff --binary -M $base $incoming \ + | git-apply --index --reject --verbose +[ $? = 0 ] || exit 1
git-merge.sh +1 -1
@@ -9,7 +9,7 @@ USAGE='[-n] [--no-commit] [--squash] [-s LF=' ' -all_strategies='recursive recur octopus resolve stupid ours' +all_strategies='recursive recur octopus resolve stupid ours applyreject' case "${GIT_USE_RECUR_FOR_RECURSIVE}" in '') default_twohead_strategies=recursive ;;
Signature · 1 line
1.4.2.gc52f
Dear diary, on Wed, Sep 13, 2006 at 11:08:17PM CEST, I got a letter where Shawn Pearce <[email protected]> said that...
Quoted 7 lines
Create merge strategy 'applyreject'.
The applyreject merge strategy is a two head merge strategy which performs the merge by obtaining the diff between the common base and the branch being merged and applies it to the current branch using git-apply --reject. Consequently any failures are written to .rej files, rather than using the RCS <<<<<<< ======= >>>>>>> format.
So, it's essentially the same as the classic resolve strategy, just handling rejects differently? I think that should be more obvious from its name, perhaps resolve-rej?
.rej files, what a nuisance to handle those... :)
Signature · 4 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ Snow falling on Perl. White noise covering line noise. Hides all the bugs too. -- J. Putnam
Quoted 10 lines · Petr Baudis
Dear diary, on Wed, Sep 13, 2006 at 11:08:17PM CEST, I got a letter where Shawn Pearce <[email protected]> said that...
Quoted 7 lines
Create merge strategy 'applyreject'.
The applyreject merge strategy is a two head merge strategy which performs the merge by obtaining the diff between the common base and the branch being merged and applies it to the current branch using git-apply --reject. Consequently any failures are written to .rej files, rather than using the RCS <<<<<<< ======= >>>>>>> format.
Quoted 3 lines
So, it's essentially the same as the classic resolve strategy, just handling rejects differently? I think that should be more obvious from its name, perhaps resolve-rej?
Unfortunately. More ideally it would be a configurable feature of merge-recur that gets used rather than invoking the RCS merge. This is just a quick and dirty 3 line shell script to propose the concept.
Quoted 1 line
.rej files, what a nuisance to handle those... :)
A matter of opinion. :)
Signature · 1 line
Shawn.
Quoted 10 lines · Petr Baudis
Dear diary, on Wed, Sep 13, 2006 at 11:08:17PM CEST, I got a letter where Shawn Pearce <[email protected]> said that...
Quoted 7 lines
Create merge strategy 'applyreject'.
The applyreject merge strategy is a two head merge strategy which performs the merge by obtaining the diff between the common base and the branch being merged and applies it to the current branch using git-apply --reject. Consequently any failures are written to .rej files, rather than using the RCS <<<<<<< ======= >>>>>>> format.
Quoted 5 lines
So, it's essentially the same as the classic resolve strategy, just handling rejects differently? I think that should be more obvious from its name, perhaps resolve-rej?
.rej files, what a nuisance to handle those... :)
You were who asked for "apply --reject", weren't you?
I am not interested in this merge strategy myself. Having said that, if it is cleanly done, I do not have much objection adding it for other people's use, at least in principle.
Quoted 16 lines · Junio C Hamano
Quoted 14 lines · Petr Baudis
Dear diary, on Wed, Sep 13, 2006 at 11:08:17PM CEST, I got a letter where Shawn Pearce <[email protected]> said that...
Quoted 7 lines
Create merge strategy 'applyreject'.
The applyreject merge strategy is a two head merge strategy which performs the merge by obtaining the diff between the common base and the branch being merged and applies it to the current branch using git-apply --reject. Consequently any failures are written to .rej files, rather than using the RCS <<<<<<< ======= >>>>>>> format.
So, it's essentially the same as the classic resolve strategy, just handling rejects differently? I think that should be more obvious from its name, perhaps resolve-rej?
Quoted 7 lines
Quoted 1 line
.rej files, what a nuisance to handle those... :)
You were who asked for "apply --reject", weren't you?
I am not interested in this merge strategy myself. Having said that, if it is cleanly done, I do not have much objection adding it for other people's use, at least in principle.
I'll clean it up, document it and and resubmit the patch if others want it as a top-level merge strategy.
But I don't really want this as a merge strategy in its own right. I want it as part of merge-recur, so I can drop into my .git/config file:
[merge-recursive]
conflictFormat = rejects
(for example) and not deal with the RCS merge program. This however will require some hacking in merge-recursive.c and apply.c but I think its workable.
Signature · 1 line
Shawn.
Quoted 2 lines · Shawn Pearce
But I don't really want this as a merge strategy in its own right. I want it as part of merge-recur (...)
Wouldn't it be better to have pluggable way to deal with conflicts, be it diff3/merge with conflict markers, .rej files, or invoking graphical merge tool (vimdiff, Emacs Emerge, xxdiff, Meld, KDiff3)?
Signature · 3 lines
Jakub Narebski Warsaw, Poland ShadeHawk on #git
Quoted 8 lines · Jakub Narebski
Quoted 2 lines · Shawn Pearce
But I don't really want this as a merge strategy in its own right. I want it as part of merge-recur (...)
Wouldn't it be better to have pluggable way to deal with conflicts, be it diff3/merge with conflict markers, .rej files, or invoking graphical merge tool (vimdiff, Emacs Emerge, xxdiff, Meld, KDiff3)?
Yes. :-)
Right now I think the user could just "plug in" their own "merge" program earlier in PATH than the real one. :-)
It would be nice to get the speed of being able to just run the xdiff code and the Git apply code directly on the file blobs in memory, without forking, but I think pluggable file content merging programs is a very good idea, for lots of different reasons.
Signature · 1 line
Shawn.
Dear diary, on Wed, Sep 13, 2006 at 11:43:04PM CEST, I got a letter where Junio C Hamano <[email protected]> said that...
Quoted 4 lines
Quoted 1 line · Petr Baudis
.rej files, what a nuisance to handle those... :)
You were who asked for "apply --reject", weren't you?
Yes, but the point of that was obviously different. (It's a nuisance, but only when compared to the conflict markers (yes, a matter of opinion of course).)
Thanks for it, BTW!
Signature · 4 lines
Petr "Pasky" Baudis Stuff: http://pasky.or.cz/ Snow falling on Perl. White noise covering line noise. Hides all the bugs too. -- J. Putnam
Quoted 8 lines · Shawn Pearce
-- >8 --
Create merge strategy 'applyreject'.The applyreject merge strategy is a two head merge strategy which performs the merge by obtaining the diff between the common base and the branch being merged and applies it to the current branch using git-apply --reject. Consequently any failures are written to .rej files, rather than using the RCS <<<<<<< ======= >>>>>>> format.
Nice.
Quoted 6 lines
--- .gitignore | 1 + Makefile | 1 + git-merge-applyreject.sh | 26 ++++++++++++++++++++++++++ git-merge.sh | 2 +- 4 files changed, 29 insertions(+), 1 deletions(-)
But where documentation (Documentation/merge-strategies.txt)?
git-merge-applyreject.sh line 5
Quoted 5 lines
git-merge-applyreject.sh new file +5
-0+#!/bin/sh +# +# Simple merge strategy which produces reject files on failed merges. +# Only handles two heads and one merge base, thus the command line +# parameters must be: base -- head1 head2
We can always get the base using git-merge-base, so the arguments could be either "base -- head1 head2", or just "head1 head2".
Does "git pull -s applyreject . head2" works (when on head1) with this patch? Does the unified driver git-merge works correctly?
git-merge-applyreject.sh line 25
Quoted 2 lines
git-merge-applyreject.sh new file +2
-0+git-diff --binary -M $base $incoming \ + | git-apply --index --reject --verbose
--index or --cached?
Signature · 3 lines
Jakub Narebski Warsaw, Poland ShadeHawk on #git
Quoted 8 lines · Jakub Narebski
Quoted 6 lines
--- .gitignore | 1 + Makefile | 1 + git-merge-applyreject.sh | 26 ++++++++++++++++++++++++++ git-merge.sh | 2 +- 4 files changed, 29 insertions(+), 1 deletions(-)But where documentation (
Documentation/merge-strategies.txt)?
If its interesting I'll document it. I just threw it together and tossed it out there to see what others thought of the general idea.
Quoted 8 lines
git-merge-applyreject.sh line 5
Quoted 5 lines
git-merge-applyreject.sh new file +5
-0+#!/bin/sh +# +# Simple merge strategy which produces reject files on failed merges. +# Only handles two heads and one merge base, thus the command line +# parameters must be: base -- head1 head2We can always get the base using git-merge-base, so the arguments could be either "base -- head1 head2", or just "head1 head2".
Actually the merge driver (git-merge.sh) feeds us the arguments like that.
Quoted 2 lines
Does "git pull -s applyreject . head2" works (when on head1) with this patch? Does the unified driver git-merge works correctly?
Yes. That's how I tested it.
Quoted 4 lines
git-merge-applyreject.sh line 25
Quoted 2 lines
git-merge-applyreject.sh new file +2
-0+git-diff --binary -M $base $incoming \ + | git-apply --index --reject --verbose--index or --cached?
I believe that --index is correct. I want to patch the file in the working directory, not the one that's currently in the index. I also want to update the index if the patch applied cleanly.
Signature · 1 line
Shawn.