File: svn-viewdiff

package info (click to toggle)
subversion 1.4.2dfsg1-3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,284 kB
  • ctags: 32,888
  • sloc: ansic: 406,472; python: 38,378; sh: 15,438; cpp: 9,604; ruby: 8,313; perl: 5,308; java: 4,576; lisp: 3,860; xml: 3,298; makefile: 856
file content (154 lines) | stat: -rwxr-xr-x 4,796 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/sh
# -*- coding:utf-8;mode:shell-script;mode:font-lock -*-

##
# GNU diff wrapper for FileMerge.
#
# (FileMerge is a graphical diff tool in the Mac OS X Developer
# Tools.)
#
# Use this as a --diff-cmd argument to svn diff in order to view your
# diffs using FileMerge.
##
# Copyright (c) 2002 Wilfredo Sanchez Vega <wsanchez@wsanchez.net>.
# All rights reserved.
# 
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
# 
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
# AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
# DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
# PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
##

set -e
set -u

##
# Handle command line
##

usage ()
{
  program=$(basename "$0");

  if [ $# != 0 ]; then echo "$@"; echo ""; fi;

  echo "${program}: usage:";
  echo "    ${program} [options] file1 file2";
  echo "";
  echo "options:";
  echo "  --help                     Print this help";
  echo "  -c                         Ignored";
  echo "  -C --context X             Ignored";
  echo "  -u                         Ignored";
  echo "  -U --unified X             Ignored";
  echo "  -L --label X               Ignored";
 #echo "  -p --show-c-function       Ignored";
 #echo "  -F --show-function-line X  Ignored";
  echo "  -q --brief                 Ignored";
  echo "  -y --side-by-side          Ignored";
  echo "  -w --width X               Ignored";
 #echo "  --left-column              Ignored";
 #echo "  --suppress-common-lines    Ignored";
  echo "  -l --paginate              Ignored";
  echo "  -t --expand-tabs           Ignored";
  echo "  -T --initial-tab           Ignored";
 #echo "  -r --recursive             Ignored";
  echo "  -d --minimal               Ignored";
  echo "  -H --speed-large-files     Ignored";
}

# Process arguments
while [ $# != 0 ]; do
  case "$1" in
    --help)
      usage;
      exit 0;
      ;;

    # These display options would not make sense for FileMerge
    -c                     ) shift 1; ;; # Context diff
    -C|--context           ) shift 2; ;; # Context diff
    -u                     ) shift 1; ;; # Unified diff
    -U|--unified           ) shift 2; ;; # Unified diff
    -L|--label             ) shift 2; ;; #   Label
   #-p|--show-c-function   ) shift 1; ;; #   C function names
   #-F|--show-function-line) shift 2; ;; #   Show recent line w/ regex
    -q|--brief             ) shift 1; ;; # Output only whether files differ
    -y|--side-by-side      ) shift 1; ;; # Output in two columns
    -w|--width             ) shift 2; ;; #   Max chars per line
   #--left-column          ) shift 1; ;; #   Left only if common
   #--suppress-common-lines) shift 1; ;; #   No output if common
    -l|--paginate          ) shift 1; ;; # Pass through pr
    -t|--expand-tabs       ) shift 1; ;; # Expand tabs
    -T|--initial-tab       ) shift 1; ;; # Add initial tab
   #-r|--recursive         ) shift 1; ;; # Recurse into directories
    -d|--minimal           ) shift 1; ;; # Try hard to minimize changes
    -H|--speed-large-files ) shift 1; ;; # Assume large files and small changes

    # Implement these
   #-s  --report-identical-files

    --|*) break; ;;
  esac;
done;

if [ $# != 2 ]; then
    usage "Invalid arguments: $*";
    exit 1;
fi;

file1="$1"; shift;
file2="$1"; shift;

##
# Do The Right Thing
##

#
# If opendiff isn't installed, you can't launch FileMerge.
# If we're not in the OS X Terminal, we probably can't run FileMerge
#
if ! type opendiff >& /dev/null || [ "${TERM_PROGRAM:=}" != "Apple_Terminal" ]; then
    diff "$@";
    exit $?;
fi;

merge="${file2}";

tmp="";

if [ $(dirname "${file1}") == "/tmp" ]; then
    if [ -z "${tmp}" ]; then tmp=$(mktemp -d /tmp/viewdiff.XXXX); fi;

    ln "${file1}" "${tmp}/left";
    file1="${tmp}/left";
fi;

if [ $(dirname "${file2}") == "/tmp" ]; then
    if [ -z "${tmp}" ]; then tmp=$(mktemp -d /tmp/viewdiff.XXXX); fi;

    ln "${file2}" "${tmp}/right";
    file2="${tmp}/right";
    merge="";
fi;

echo opendiff "${file1}" "${file2}";
if [ -z "${merge}" ]; then
    opendiff "${file1}" "${file2}";
else
    opendiff "${file1}" "${file2}" -merge "${merge}";
fi;

sleep 1

# Give FileMerge some time before letting svn diff continue and possibly delete
# any temp files, or before deleting our own temp files.
if [ -n "${tmp}" ]; then (sleep 2; rm -rf "${tmp}") & fi;