* subversion/svn/main.c
[svn.git] / contrib / client-side / svn-viewdiff
blobfb5fcacb44a27b9c330a0d77418de237bb770b28
1 #!/bin/sh
2 # -*- coding:utf-8;mode:shell-script;mode:font-lock -*-
4 ##
5 # GNU diff wrapper for FileMerge.
7 # (FileMerge is a graphical diff tool in the Mac OS X Developer
8 # Tools.)
10 # Use this as a --diff-cmd argument to svn diff in order to view your
11 # diffs using FileMerge.
13 # Copyright (c) 2002 Wilfredo Sanchez Vega <wsanchez@wsanchez.net>.
14 # All rights reserved.
16 # Permission to use, copy, modify, and distribute this software for any
17 # purpose with or without fee is hereby granted, provided that the above
18 # copyright notice and this permission notice appear in all copies.
20 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
21 # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
22 # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
23 # AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
24 # DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
25 # PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
26 # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27 # PERFORMANCE OF THIS SOFTWARE.
30 set -e
31 set -u
34 # Handle command line
37 usage ()
39 program=$(basename "$0");
41 if [ $# != 0 ]; then echo "$@"; echo ""; fi;
43 echo "${program}: usage:";
44 echo " ${program} [options] file1 file2";
45 echo "";
46 echo "options:";
47 echo " --help Print this help";
48 echo " -c Ignored";
49 echo " -C --context X Ignored";
50 echo " -u Ignored";
51 echo " -U --unified X Ignored";
52 echo " -L --label X Ignored";
53 #echo " -p --show-c-function Ignored";
54 #echo " -F --show-function-line X Ignored";
55 echo " -q --brief Ignored";
56 echo " -y --side-by-side Ignored";
57 echo " -w --width X Ignored";
58 #echo " --left-column Ignored";
59 #echo " --suppress-common-lines Ignored";
60 echo " -l --paginate Ignored";
61 echo " -t --expand-tabs Ignored";
62 echo " -T --initial-tab Ignored";
63 #echo " -r --recursive Ignored";
64 echo " -d --minimal Ignored";
65 echo " -H --speed-large-files Ignored";
68 # Process arguments
69 while [ $# != 0 ]; do
70 case "$1" in
71 --help)
72 usage;
73 exit 0;
76 # These display options would not make sense for FileMerge
77 -c ) shift 1; ;; # Context diff
78 -C|--context ) shift 2; ;; # Context diff
79 -u ) shift 1; ;; # Unified diff
80 -U|--unified ) shift 2; ;; # Unified diff
81 -L|--label ) shift 2; ;; # Label
82 #-p|--show-c-function ) shift 1; ;; # C function names
83 #-F|--show-function-line) shift 2; ;; # Show recent line w/ regex
84 -q|--brief ) shift 1; ;; # Output only whether files differ
85 -y|--side-by-side ) shift 1; ;; # Output in two columns
86 -w|--width ) shift 2; ;; # Max chars per line
87 #--left-column ) shift 1; ;; # Left only if common
88 #--suppress-common-lines) shift 1; ;; # No output if common
89 -l|--paginate ) shift 1; ;; # Pass through pr
90 -t|--expand-tabs ) shift 1; ;; # Expand tabs
91 -T|--initial-tab ) shift 1; ;; # Add initial tab
92 #-r|--recursive ) shift 1; ;; # Recurse into directories
93 -d|--minimal ) shift 1; ;; # Try hard to minimize changes
94 -H|--speed-large-files ) shift 1; ;; # Assume large files and small changes
96 # Implement these
97 #-s --report-identical-files
99 --|*) break; ;;
100 esac;
101 done;
103 if [ $# != 2 ]; then
104 usage "Invalid arguments: $*";
105 exit 1;
108 file1="$1"; shift;
109 file2="$1"; shift;
112 # Do The Right Thing
116 # If opendiff isn't installed, you can't launch FileMerge.
117 # If we're not in the OS X Terminal, we probably can't run FileMerge
119 if ! type opendiff >& /dev/null || [ "${TERM_PROGRAM:=}" != "Apple_Terminal" ]; then
120 diff "$@";
121 exit $?;
124 merge="${file2}";
126 tmp="";
128 if [ $(dirname "${file1}") == "/tmp" ]; then
129 if [ -z "${tmp}" ]; then tmp=$(mktemp -d /tmp/viewdiff.XXXX); fi;
131 ln "${file1}" "${tmp}/left";
132 file1="${tmp}/left";
135 if [ $(dirname "${file2}") == "/tmp" ]; then
136 if [ -z "${tmp}" ]; then tmp=$(mktemp -d /tmp/viewdiff.XXXX); fi;
138 ln "${file2}" "${tmp}/right";
139 file2="${tmp}/right";
140 merge="";
143 echo opendiff "${file1}" "${file2}";
144 if [ -z "${merge}" ]; then
145 opendiff "${file1}" "${file2}";
146 else
147 opendiff "${file1}" "${file2}" -merge "${merge}";
150 sleep 1
152 # Give FileMerge some time before letting svn diff continue and possibly delete
153 # any temp files, or before deleting our own temp files.
154 if [ -n "${tmp}" ]; then (sleep 2; rm -rf "${tmp}") & fi;