Show More
@@ -1,56 +1,56 b'' | |||||
1 | #!/bin/sh |
|
1 | #!/bin/sh | |
2 | # |
|
2 | # | |
3 | # This is an example of using HGEDITOR to create of diff to review the |
|
3 | # This is an example of using HGEDITOR to create of diff to review the | |
4 | # changes while commiting. |
|
4 | # changes while commiting. | |
5 |
|
5 | |||
6 | # If you want to pass your favourite editor some other parameters |
|
6 | # If you want to pass your favourite editor some other parameters | |
7 | # only for Mercurial, modify this: |
|
7 | # only for Mercurial, modify this: | |
8 | case "${EDITOR}" in |
|
8 | case "${EDITOR}" in | |
9 | "") |
|
9 | "") | |
10 | EDITOR="vi" |
|
10 | EDITOR="vi" | |
11 | ;; |
|
11 | ;; | |
12 | emacs) |
|
12 | emacs) | |
13 | EDITOR="$EDITOR -nw" |
|
13 | EDITOR="$EDITOR -nw" | |
14 | ;; |
|
14 | ;; | |
15 | gvim|vim) |
|
15 | gvim|vim) | |
16 | EDITOR="$EDITOR -f -o" |
|
16 | EDITOR="$EDITOR -f -o" | |
17 | ;; |
|
17 | ;; | |
18 | esac |
|
18 | esac | |
19 |
|
19 | |||
20 |
|
20 | |||
21 | HGTMP="" |
|
21 | HGTMP="" | |
22 | cleanup_exit() { |
|
22 | cleanup_exit() { | |
23 | rm -rf "$HGTMP" |
|
23 | rm -rf "$HGTMP" | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | # Remove temporary files even if we get interrupted |
|
26 | # Remove temporary files even if we get interrupted | |
27 | trap "cleanup_exit" 0 # normal exit |
|
27 | trap "cleanup_exit" 0 # normal exit | |
28 | trap "exit 255" HUP INT QUIT ABRT TERM |
|
28 | trap "exit 255" HUP INT QUIT ABRT TERM | |
29 |
|
29 | |||
30 | HGTMP="${TMPDIR-/tmp}/hgeditor.$RANDOM.$RANDOM.$RANDOM.$$" |
|
30 | HGTMP=$(mktemp -d ${TMPDIR-/tmp}/hgeditor.XXXXXX) | |
31 | (umask 077 && mkdir "$HGTMP") || { |
|
31 | [ x$HGTMP != x -a -d $HGTMP ] || { | |
32 |
|
|
32 | echo "Could not create temporary directory! Exiting." 1>&2 | |
33 |
|
|
33 | exit 1 | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | ( |
|
36 | ( | |
37 | grep '^HG: changed' "$1" | cut -b 13- | while read changed; do |
|
37 | grep '^HG: changed' "$1" | cut -b 13- | while read changed; do | |
38 | "$HG" diff "$changed" >> "$HGTMP/diff" |
|
38 | "$HG" diff "$changed" >> "$HGTMP/diff" | |
39 | done |
|
39 | done | |
40 | ) |
|
40 | ) | |
41 |
|
41 | |||
42 | cat "$1" > "$HGTMP/msg" |
|
42 | cat "$1" > "$HGTMP/msg" | |
43 |
|
43 | |||
44 | MD5=$(which md5sum 2>/dev/null) || \ |
|
44 | MD5=$(which md5sum 2>/dev/null) || \ | |
45 | MD5=$(which md5 2>/dev/null) |
|
45 | MD5=$(which md5 2>/dev/null) | |
46 | [ -x "${MD5}" ] && CHECKSUM=`${MD5} "$HGTMP/msg"` |
|
46 | [ -x "${MD5}" ] && CHECKSUM=`${MD5} "$HGTMP/msg"` | |
47 | if [ -s "$HGTMP/diff" ]; then |
|
47 | if [ -s "$HGTMP/diff" ]; then | |
48 | $EDITOR "$HGTMP/msg" "$HGTMP/diff" || exit $? |
|
48 | $EDITOR "$HGTMP/msg" "$HGTMP/diff" || exit $? | |
49 | else |
|
49 | else | |
50 | $EDITOR "$HGTMP/msg" || exit $? |
|
50 | $EDITOR "$HGTMP/msg" || exit $? | |
51 | fi |
|
51 | fi | |
52 | [ -x "${MD5}" ] && (echo "$CHECKSUM" | ${MD5} -c >/dev/null 2>&1 && exit 13) |
|
52 | [ -x "${MD5}" ] && (echo "$CHECKSUM" | ${MD5} -c >/dev/null 2>&1 && exit 13) | |
53 |
|
53 | |||
54 | mv "$HGTMP/msg" "$1" |
|
54 | mv "$HGTMP/msg" "$1" | |
55 |
|
55 | |||
56 | exit $? |
|
56 | exit $? |
General Comments 0
You need to be logged in to leave comments.
Login now