Size: 2203
Comment:
|
Size: 2309
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 3: | Line 3: |
[http://www.gnu.org/software/emacs/ Emacs] is bundled with an elisp program called Ediff which purpose is to help developers to visually apply patches. One of the various ediff commands is well suited to three way merging and can be used as a [:MergeProgram:merger program] with ["Mercurial"]. | [[http://www.gnu.org/software/emacs/|Emacs]] is bundled with an elisp program called Ediff which purpose is to help developers to visually apply patches. One of the various ediff commands is well suited to three way merging and can be used as a [[MergeProgram|merger program]] with [[Mercurial]]. |
Line 7: | Line 7: |
So to use [http://www.gnu.org/software/emacs/ Emacs] as ["Mercurial"] merger program, dump the following content into a file in your PATH (don't forget to turn on the execute bit): | So to use [[http://www.gnu.org/software/emacs/|Emacs]] as [[Mercurial]] merger program, dump the following content into a file in your PATH (don't forget to turn on the execute bit): |
Line 13: | Line 13: |
LOCAL=$1 BASE=$2 OTHER=$3 |
LOCAL="$1" BASE="$2" OTHER="$3" |
Line 17: | Line 17: |
BACKUP=$LOCAL.orig | BACKUP="$LOCAL.orig" |
Line 19: | Line 19: |
Rm () { if [ -f $BACKUP ]; then rm -f $BACKUP else : fi } |
|
Line 30: | Line 21: |
cp $BACKUP $LOCAL | cp "$BACKUP" "$LOCAL" |
Line 35: | Line 26: |
Rm Exit $? |
exit $? |
Line 40: | Line 30: |
cp $LOCAL $BACKUP | cp "$LOCAL" "$BACKUP" |
Line 44: | Line 34: |
if merge $LOCAL $BASE $OTHER 2> /dev/null; then | if merge "$LOCAL" "$BASE" "$OTHER" 2> /dev/null; then |
Line 50: | Line 40: |
if diff3 -m $BACKUP $BASE $OTHER > $LOCAL ; then | if diff3 -m "$BACKUP" "$BASE" "$OTHER" > "$LOCAL" ; then |
Line 67: | Line 57: |
''Considering Mercurial is now able to premerge before running the merge tool and even does it by default (see hgrc(5)), I feel that attempts of merge with merge and diff3 are not needed anymore.`` |
|
Line 73: | Line 67: |
Don't forget to add an entry in your hgrc file (either ~/.hgrc or the local working copy .hg/hgrc) to point ["Mercurial"] at your merge command (let's call it emacs-merge) | Don't forget to add an entry in your hgrc file (either ~/.hgrc or the local working copy .hg/hgrc) to point [[Mercurial]] at your merge command (let's call it emacs-merge) |
Using Emacs as a merger program
Emacs is bundled with an elisp program called Ediff which purpose is to help developers to visually apply patches. One of the various ediff commands is well suited to three way merging and can be used as a merger program with Mercurial.
Wrapping Emacs+Ediff call in a script
So to use Emacs as Mercurial merger program, dump the following content into a file in your PATH (don't forget to turn on the execute bit):
#!/bin/sh set -e # bail out quickly on failure LOCAL="$1" BASE="$2" OTHER="$3" BACKUP="$LOCAL.orig" Restore () { cp "$BACKUP" "$LOCAL" } ExitOK () { exit $? } # Back up our file cp "$LOCAL" "$BACKUP" # Attempt to do a non-interactive merge if which merge > /dev/null 2>&1 ; then if merge "$LOCAL" "$BASE" "$OTHER" 2> /dev/null; then # success! ExitOK fi Restore elif which diff3 > /dev/null 2>&1 ; then if diff3 -m "$BACKUP" "$BASE" "$OTHER" > "$LOCAL" ; then # success ExitOK fi Restore fi if emacs -q --no-site-file --eval "(ediff-merge-with-ancestor \"$BACKUP\" \"$OTHER\" \"$BASE\" nil \"$LOCAL\")" then ExitOK fi echo "emacs-merge: failed to merge files" exit 1 # End of file
Considering Mercurial is now able to premerge before running the merge tool and even does it by default (see hgrc(5)), I feel that attempts of merge with merge and diff3 are not needed anymore.
This script tries first to automatically merge the files using the RCS merge program or the diff3 program. If the automatic merger fails merging the files because of a conflict or, neither merge nor diff3 are available on the system, then emacs is launched to let the developer resolve the conflicts.
Don't forget to add an entry in your hgrc file (either ~/.hgrc or the local working copy .hg/hgrc) to point Mercurial at your merge command (let's call it emacs-merge) How the script works
Enabling the script usage