##// END OF EJS Templates
Remove usage of ${par:-word}, which and mktemp. Quote filenames.
Thomas Arendsen Hein -
r795:cd0ad12d default
parent child Browse files
Show More
@@ -7,34 +7,36 b''
7
7
8 set -e # bail out quickly on failure
8 set -e # bail out quickly on failure
9
9
10 LOCAL=$1
10 LOCAL="$1"
11 BASE=$2
11 BASE="$2"
12 OTHER=$3
12 OTHER="$3"
13
13
14 EDITOR="${EDITOR:-vi}"
14 if [ -z "$EDITOR" ]; then
15 EDITOR="vi"
16 fi
15
17
16 # Back up our file
18 # Back up our file
17 cp $LOCAL $LOCAL.orig
19 cp "$LOCAL" "$LOCAL.orig"
18
20
19 # Attempt to do a non-interactive merge
21 # Attempt to do a non-interactive merge
20 if which merge > /dev/null ; then
22 if type merge > /dev/null ; then
21 if merge $LOCAL $BASE $OTHER 2> /dev/null; then
23 if merge "$LOCAL" "$BASE" "$OTHER" 2> /dev/null; then
22 # success!
24 # success!
23 exit 0
25 exit 0
24 fi
26 fi
25 cp $LOCAL.orig $LOCAL
27 cp "$LOCAL.orig" "$LOCAL"
26 elif which diff3 > /dev/null ; then
28 elif type diff3 > /dev/null ; then
27 if diff3 -m $LOCAL.orig $BASE $OTHER > $LOCAL ; then
29 if diff3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" ; then
28 # success
30 # success
29 exit 0
31 exit 0
30 fi
32 fi
31 cp $LOCAL.orig $LOCAL
33 cp "$LOCAL.orig" "$LOCAL"
32 fi
34 fi
33
35
34 if [ -n "$DISPLAY" ]; then
36 if [ -n "$DISPLAY" ]; then
35 # try using kdiff3, which is fairly nice
37 # try using kdiff3, which is fairly nice
36 if which kdiff3 > /dev/null ; then
38 if type kdiff3 > /dev/null ; then
37 if kdiff3 --auto $BASE $LOCAL $OTHER -o $LOCAL ; then
39 if kdiff3 --auto "$BASE" "$LOCAL" "$OTHER" -o "$LOCAL" ; then
38 exit 0
40 exit 0
39 else
41 else
40 exit 1
42 exit 1
@@ -42,8 +44,8 b' if [ -n "$DISPLAY" ]; then'
42 fi
44 fi
43
45
44 # try using tkdiff, which is a bit less sophisticated
46 # try using tkdiff, which is a bit less sophisticated
45 if which tkdiff > /dev/null ; then
47 if type tkdiff > /dev/null ; then
46 if tkdiff $LOCAL $OTHER -a $BASE -o $LOCAL ; then
48 if tkdiff "$LOCAL" "$OTHER" -a "$BASE" -o "$LOCAL" ; then
47 exit 0
49 exit 0
48 else
50 else
49 exit 1
51 exit 1
@@ -52,30 +54,43 b' if [ -n "$DISPLAY" ]; then'
52 fi
54 fi
53
55
54 # Attempt to do a merge with $EDITOR
56 # Attempt to do a merge with $EDITOR
55 if which merge > /dev/null ; then
57 if type merge > /dev/null ; then
56 echo "conflicts detected in $LOCAL"
58 echo "conflicts detected in $LOCAL"
57 merge $LOCAL $BASE $OTHER 2>/dev/null || $EDITOR $LOCAL
59 merge "$LOCAL" "$BASE" "$OTHER" 2>/dev/null || $EDITOR "$LOCAL"
58 exit 0
60 exit 0
59 fi
61 fi
60
62
61 if which diff3 > /dev/null ; then
63 if type diff3 > /dev/null ; then
62 echo "conflicts detected in $LOCAL"
64 echo "conflicts detected in $LOCAL"
63 diff3 -m $LOCAL.orig $BASE $OTHER > $LOCAL || $EDITOR $LOCAL
65 diff3 -m "$LOCAL.orig" "$BASE" "$OTHER" > "$LOCAL" || $EDITOR "$LOCAL"
64 exit 0
66 exit 0
65 fi
67 fi
66
68
69 HGTMP=""
70 cleanup_exit() {
71 rm -rf "$HGTMP"
72 exit $1
73 }
74
67 # attempt to manually merge with diff and patch
75 # attempt to manually merge with diff and patch
68 if which diff > /dev/null ; then
76 if type diff > /dev/null ; then
69 if which patch > /dev/null ; then
77 if type patch > /dev/null ; then
70 T=`mktemp`
78 # Remove temporary files even if we get interrupted
71 diff -u $BASE $OTHER > $T
79 trap "cleanup_exit 1" TERM KILL INT QUIT ABRT
72 if patch $LOCAL < $T ; then
80
73 exit 0
81 HGTMP="${TMPDIR-/tmp}/hgmerge.$RANDOM.$RANDOM.$RANDOM.$$"
82 (umask 077 && mkdir "$HGTMP") || {
83 echo "Could not create temporary directory! Exiting." 1>&2
84 exit 1
85 }
86
87 diff -u "$BASE" "$OTHER" > "$HGTMP/diff"
88 if patch "$LOCAL" < "$HGTMP/diff" ; then
89 cleanup_exit 0
74 else
90 else
75 $EDITOR $LOCAL $LOCAL.rej
91 $EDITOR "$LOCAL" "$LOCAL.rej"
76 fi
92 fi
77 rm $T
93 cleanup_exit 1
78 exit 1
79 fi
94 fi
80 fi
95 fi
81
96
General Comments 0
You need to be logged in to leave comments. Login now