Merge master.kernel.org:/pub/scm/gitk/gitk
[git/git.git] / git-external-diff-script
1 #!/bin/sh
2 # Copyright (C) 2005 Junio C Hamano
3 #
4 # This script is designed to emulate what the built-in diff driver
5 # does when set as GIT_EXTERNAL_SCRIPT.
6
7 case "$#" in
8 1)
9 echo "* Unmerged path $1"
10 exit 0 ;;
11 *)
12 name1="$1" tmp1="$2" hex1="$3" mode1="$4" tmp2="$5" hex2="$6" mode2="$7"
13 case "$#" in
14 7)
15 name2="$name1" ;;
16 9)
17 name2="$8" xfrm_msg="$9" ;;
18 esac ;;
19 esac
20
21 show_create () {
22 name_="$1" tmp_="$2" hex_="$3" mode_="$4"
23 echo "diff --git a/$name_ b/$name_"
24 echo "new file mode $mode_"
25 diff ${GIT_DIFF_OPTS-'-pu'} -L /dev/null -L "b/$name_" /dev/null "$tmp_"
26 }
27
28 show_delete () {
29 name_="$1" tmp_="$2" hex_="$3" mode_="$4"
30 echo "diff --git a/$name_ b/$name_"
31 echo "deleted file mode $mode_"
32 diff ${GIT_DIFF_OPTS-'-pu'} -L "a/$name_" -L /dev/null "$tmp_" /dev/null
33 }
34
35 case "$mode1" in
36 120*) type1=l ;;
37 100*) type1=f ;;
38 .) show_create "$name2" "$tmp2" "$hex2" "$mode2"
39 exit 0 ;;
40 esac
41 case "$mode2" in
42 120*) type2=l ;;
43 100*) type2=f ;;
44 .) show_delete "$name1" "$tmp1" "$hex1" "$mode1"
45 exit 0 ;;
46 esac
47
48 if test "$type1" != "$type2"
49 then
50 show_delete "$name1" "$tmp1" "$hex1" "$mode1"
51 show_create "$name2" "$tmp2" "$hex2" "$mode2"
52 exit 0
53 fi
54
55 echo diff --git "a/$name1" "b/$name2"
56 if test "$mode1" != "$mode2"
57 then
58 echo "old mode $mode1"
59 echo "new mode $mode2"
60 if test "$xfrm_msg" != ""
61 then
62 echo "$xfrm_msg"
63 fi
64 fi
65 diff ${GIT_DIFF_OPTS-'-pu'} -L "a/$name1" -L "b/$name2" "$tmp1" "$tmp2"
66 exit 0
67