hgmerge
changeset 836 1fe3b14c7044
parent 814 0902ffece4b4
parent 831 232d0616a80a
child 839 9c918287d10b
equal deleted inserted replaced
827:a61728b58dc0 836:1fe3b14c7044
    17 
    17 
    18 # Back up our file
    18 # Back up our file
    19 cp "$LOCAL" "$LOCAL.orig"
    19 cp "$LOCAL" "$LOCAL.orig"
    20 
    20 
    21 # Attempt to do a non-interactive merge
    21 # Attempt to do a non-interactive merge
    22 if type merge > /dev/null ; then
    22 if type merge > /dev/null 2>&1; then
    23     if merge "$LOCAL" "$BASE" "$OTHER" 2> /dev/null; then
    23     merge "$LOCAL" "$BASE" "$OTHER" 2> /dev/null && exit 0
    24 	# success!
       
    25 	exit 0
       
    26     fi
       
    27     cp "$LOCAL.orig" "$LOCAL"
    24     cp "$LOCAL.orig" "$LOCAL"
    28 elif type diff3 > /dev/null ; then
    25 elif type diff3 > /dev/null 2>&1; then
    29     if diff3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" ; then
    26     diff3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" && exit 0
    30 	# success
       
    31 	exit 0
       
    32     fi
       
    33     cp "$LOCAL.orig" "$LOCAL"
    27     cp "$LOCAL.orig" "$LOCAL"
    34 fi
    28 fi
    35 
    29 
    36 if [ -n "$DISPLAY" ]; then
    30 if [ -n "$DISPLAY" ]; then
    37     # try using kdiff3, which is fairly nice
    31     # try using kdiff3, which is fairly nice
    38     if type kdiff3 > /dev/null ; then
    32     if type kdiff3 > /dev/null 2>&1; then
    39 	if kdiff3 --auto "$BASE" "$LOCAL" "$OTHER" -o "$LOCAL" ; then
    33 	kdiff3 --auto "$BASE" "$LOCAL" "$OTHER" -o "$LOCAL" || exit 1
    40 	    exit 0
    34 	exit 0
    41 	else
       
    42 	    exit 1
       
    43 	fi
       
    44     fi
    35     fi
    45 
    36 
    46     # try using tkdiff, which is a bit less sophisticated
    37     # try using tkdiff, which is a bit less sophisticated
    47     if type tkdiff > /dev/null ; then
    38     if type tkdiff > /dev/null 2>&1; then
    48 	if tkdiff "$LOCAL" "$OTHER" -a "$BASE" -o "$LOCAL" ; then
    39 	tkdiff "$LOCAL" "$OTHER" -a "$BASE" -o "$LOCAL" || exit 1
    49 	    exit 0
    40 	exit 0
    50 	else
       
    51 	    exit 1
       
    52 	fi
       
    53     fi
    41     fi
    54 fi
    42 fi
    55 
    43 
    56 # Attempt to do a merge with $EDITOR
    44 # Attempt to do a merge with $EDITOR
    57 if type merge > /dev/null ; then
    45 if type merge > /dev/null 2>&1; then
    58     echo "conflicts detected in $LOCAL"
    46     echo "conflicts detected in $LOCAL"
    59     merge "$LOCAL" "$BASE" "$OTHER" 2>/dev/null || $EDITOR "$LOCAL"
    47     merge "$LOCAL" "$BASE" "$OTHER" 2>/dev/null || $EDITOR "$LOCAL"
    60     exit 0
    48     exit 0
    61 fi
    49 fi
    62 
    50 
    63 if type diff3 > /dev/null ; then
    51 if type diff3 > /dev/null 2>&1; then
    64     echo "conflicts detected in $LOCAL"
    52     echo "conflicts detected in $LOCAL"
    65     diff3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" || $EDITOR "$LOCAL"
    53     diff3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" || $EDITOR "$LOCAL"
    66     exit 0
    54     exit 0
    67 fi
    55 fi
    68 
    56 
    69 HGTMP=""
    57 HGTMP=""
    70 cleanup_exit() {
    58 cleanup_exit() {
    71     rm -rf "$HGTMP"
    59     rm -rf "$HGTMP"
    72     exit $1
       
    73 }
    60 }
    74 
    61 
    75 # attempt to manually merge with diff and patch
    62 # attempt to manually merge with diff and patch
    76 if type diff > /dev/null ; then
    63 if type diff > /dev/null 2>&1 && type patch > /dev/null 2>&1; then
    77     if type patch > /dev/null ; then
    64     # Remove temporary files even if we get interrupted
    78 	# Remove temporary files even if we get interrupted
    65     trap "cleanup_exit" 0 # normal exit
    79 	trap "cleanup_exit 1" TERM KILL INT QUIT ABRT
    66     trap "exit 1" 1 2 3 6 15 # HUP INT QUIT ABRT TERM
    80 
    67 
    81 	HGTMP="${TMPDIR-/tmp}/hgmerge.$RANDOM.$RANDOM.$RANDOM.$$"
    68     HGTMP="${TMPDIR-/tmp}/hgmerge.$RANDOM.$RANDOM.$RANDOM.$$"
    82 	(umask 077 && mkdir "$HGTMP") || {
    69     (umask 077 && mkdir "$HGTMP") || {
    83 	    echo "Could not create temporary directory! Exiting." 1>&2
    70 	echo "Could not create temporary directory! Exiting." 1>&2
    84 	    exit 1
    71 	exit 1
    85 	}
    72     }
    86 
    73 
    87 	diff -u "$BASE" "$OTHER" > "$HGTMP/diff"
    74     diff -u "$BASE" "$OTHER" > "$HGTMP/diff"
    88 	if patch "$LOCAL" < "$HGTMP/diff" ; then
    75     if patch "$LOCAL" < "$HGTMP/diff"; then
    89 	    cleanup_exit 0
    76 	exit 0
    90 	else
    77     else
    91 	    $EDITOR "$LOCAL" "$LOCAL.rej"
    78 	# If rejects are empty after using the editor, merge was ok
    92 	fi
    79 	$EDITOR "$LOCAL" "$LOCAL.rej" && test -s "$LOCAL.rej" || exit 0
    93 	cleanup_exit 1
       
    94     fi
    80     fi
       
    81     exit 1
    95 fi
    82 fi
    96 
    83 
    97 echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!"
    84 echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!"
    98 exit 1
    85 exit 1