hgmerge
changeset 1434 696851b1bba9
parent 839 9c918287d10b
child 1647 64a1169c927d
equal deleted inserted replaced
1433:70a3b6a505c6 1434:696851b1bba9
    13 
    13 
    14 if [ -z "$EDITOR" ]; then
    14 if [ -z "$EDITOR" ]; then
    15     EDITOR="vi"
    15     EDITOR="vi"
    16 fi
    16 fi
    17 
    17 
       
    18 # find decent versions of our utilities, insisting on the GNU versions where we
       
    19 # need to
       
    20 DIFF3=gdiff3
       
    21 DIFF=gdiff
       
    22 PATCH=gpatch
       
    23 
       
    24 type $DIFF3 >/dev/null 2>&1 || DIFF3=diff3
       
    25 type $DIFF  >/dev/null 2>&1 || DIFF=diff
       
    26 type $PATCH  >/dev/null 2>&1 || PATCH=patch
       
    27 $DIFF3 --version >/dev/null 2>&1 || DIFF3=
       
    28 
    18 # Back up our file
    29 # Back up our file
    19 cp "$LOCAL" "$LOCAL.orig"
    30 cp "$LOCAL" "$LOCAL.orig"
    20 
    31 
    21 # Attempt to do a non-interactive merge
    32 # Attempt to do a non-interactive merge
    22 if type merge > /dev/null 2>&1; then
    33 if type merge > /dev/null 2>&1; then
    23     merge "$LOCAL" "$BASE" "$OTHER" 2> /dev/null && exit 0
    34     merge "$LOCAL" "$BASE" "$OTHER" 2> /dev/null && exit 0
    24     cp "$LOCAL.orig" "$LOCAL"
    35     cp "$LOCAL.orig" "$LOCAL"
    25 elif type diff3 > /dev/null 2>&1; then
    36 elif [ -n "$DIFF3" ]; then
    26     diff3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" && exit 0
    37     echo $DIFF3 -m "$LOCAL.orig" "$BASE" "$OTHER"
       
    38     $DIFF3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" && exit 0
       
    39     if [ $? -eq 2 ]; then
       
    40         echo "$DIFF3 failed! Exiting." 1>&2
       
    41         cp "$LOCAL.orig" "$LOCAL"
       
    42         exit 1
       
    43     fi
    27     cp "$LOCAL.orig" "$LOCAL"
    44     cp "$LOCAL.orig" "$LOCAL"
    28 fi
    45 fi
    29 
    46 
    30 if [ -n "$DISPLAY" ]; then
    47 if [ -n "$DISPLAY" ]; then
    31     # try using kdiff3, which is fairly nice
    48     # try using kdiff3, which is fairly nice
    46     echo "conflicts detected in $LOCAL"
    63     echo "conflicts detected in $LOCAL"
    47     merge "$LOCAL" "$BASE" "$OTHER" 2>/dev/null || $EDITOR "$LOCAL"
    64     merge "$LOCAL" "$BASE" "$OTHER" 2>/dev/null || $EDITOR "$LOCAL"
    48     exit 0
    65     exit 0
    49 fi
    66 fi
    50 
    67 
    51 if type diff3 > /dev/null 2>&1; then
    68 if [ -n "$DIFF3" ]; then
    52     echo "conflicts detected in $LOCAL"
    69     echo "conflicts detected in $LOCAL"
    53     diff3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" || $EDITOR "$LOCAL"
    70     $DIFF3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" || {
    54     exit 0
    71         case $? in
       
    72             1)
       
    73                 $EDITOR "$LOCAL" ;;
       
    74             2)  echo "$DIFF3 failed! Exiting." 1>&2
       
    75                 cp "$LOCAL.orig" "$LOCAL"
       
    76                 exit 1 ;;
       
    77         esac
       
    78         exit 0
       
    79     }
    55 fi
    80 fi
    56 
    81 
    57 HGTMP=""
    82 HGTMP=""
    58 cleanup_exit() {
    83 cleanup_exit() {
    59     rm -rf "$HGTMP"
    84     rm -rf "$HGTMP"
    60 }
    85 }
    61 
    86 
    62 # attempt to manually merge with diff and patch
    87 # attempt to manually merge with diff and patch
    63 if type diff > /dev/null 2>&1 && type patch > /dev/null 2>&1; then
    88 if [ -n "$DIFF" -a -n "$PATCH" ]; then
    64     # Remove temporary files even if we get interrupted
    89     # Remove temporary files even if we get interrupted
    65     trap "cleanup_exit" 0 # normal exit
    90     trap "cleanup_exit" 0 # normal exit
    66     trap "exit 1" 1 2 3 6 15 # HUP INT QUIT ABRT TERM
    91     trap "exit 1" 1 2 3 6 15 # HUP INT QUIT ABRT TERM
    67 
    92 
    68     HGTMP="${TMPDIR-/tmp}/hgmerge.$RANDOM.$RANDOM.$RANDOM.$$"
    93     HGTMP="${TMPDIR-/tmp}/hgmerge.$RANDOM.$RANDOM.$RANDOM.$$"
    69     (umask 077 && mkdir "$HGTMP") || {
    94     (umask 077 && mkdir "$HGTMP") || {
    70 	echo "Could not create temporary directory! Exiting." 1>&2
    95 	echo "Could not create temporary directory! Exiting." 1>&2
    71 	exit 1
    96 	exit 1
    72     }
    97     }
    73 
    98 
    74     diff -u "$BASE" "$OTHER" > "$HGTMP/diff"
    99     $DIFF -u "$BASE" "$OTHER" > "$HGTMP/diff" || :
    75     if patch "$LOCAL" < "$HGTMP/diff"; then
   100     if $PATCH "$LOCAL" < "$HGTMP/diff"; then
    76 	exit 0
   101 	exit 0
    77     else
   102     else
    78 	# If rejects are empty after using the editor, merge was ok
   103 	# If rejects are empty after using the editor, merge was ok
    79 	$EDITOR "$LOCAL" "$LOCAL.rej" && test -s "$LOCAL.rej" || exit 0
   104 	$EDITOR "$LOCAL" "$LOCAL.rej" && test -s "$LOCAL.rej" || exit 0
    80     fi
   105     fi