contrib/git-svn: allow rebuild to work on non-linear remote heads
[alt-git.git] / git-diff.sh
blobdc0dd312bfb83921e1c52849a23ece84a05b5ecd
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
4 # Copyright (c) 2005 Junio C Hamano
6 USAGE='[ --diff-options ] <ent>{0,2} [<path>...]'
7 SUBDIRECTORY_OK='Yes'
8 . git-sh-setup
10 rev=$(git-rev-parse --revs-only --no-flags --sq "$@") || exit
11 flags=$(git-rev-parse --no-revs --flags --sq "$@")
12 files=$(git-rev-parse --no-revs --no-flags --sq "$@")
14 # I often say 'git diff --cached -p' and get scolded by git-diff-files, but
15 # obviously I mean 'git diff --cached -p HEAD' in that case.
16 case "$rev" in
17 '')
18 case " $flags " in
19 *" '--cached' "*)
20 rev='HEAD '
22 esac
23 esac
25 # If we have -[123] --ours --theirs --base, don't do --cc by default.
26 case " $flags " in
27 *" '-"[123]"' "* | *" '--ours' "* | *" '--base' "* | *" '--theirs' "*)
28 cc_or_p=-p ;;
30 cc_or_p=--cc ;;
31 esac
33 # If we do not have --name-status, --name-only, -r, or -c default to --cc.
34 case " $flags " in
35 *" '--name-status' "* | *" '--name-only' "* | *" '-r' "* | *" '-c' "* )
38 flags="$flags'$cc_or_p' " ;;
39 esac
41 # If we do not have -B, -C, -r, nor -p, default to -M.
42 case " $flags " in
43 *" '-"[BCMrp]* | *" '--find-copies-harder' "*)
44 ;; # something like -M50.
46 flags="$flags'-M' " ;;
47 esac
49 case "$rev" in
50 ?*' '?*' '?*)
51 usage
53 ?*' '^?*)
54 begin=$(expr "$rev" : '.*^.\([0-9a-f]*\).*') &&
55 end=$(expr "$rev" : '.\([0-9a-f]*\). .*') || exit
56 cmd="git-diff-tree $flags $begin $end -- $files"
58 ?*' '?*)
59 cmd="git-diff-tree $flags $rev -- $files"
61 ?*' ')
62 cmd="git-diff-index $flags $rev -- $files"
64 '')
65 cmd="git-diff-files $flags -- $files"
68 usage
70 esac
72 eval "$cmd"