]>
Commit | Line | Data |
---|---|---|
5c38ea31 DA |
1 | #!/usr/bin/env perl |
2 | # Copyright (c) 2009 David Aguilar | |
3 | # | |
4 | # This is a wrapper around the GIT_EXTERNAL_DIFF-compatible | |
afcbc8e7 | 5 | # git-difftool--helper script. This script exports |
5c38ea31 | 6 | # GIT_EXTERNAL_DIFF and GIT_PAGER for use by git, and |
afcbc8e7 | 7 | # GIT_DIFFTOOL_NO_PROMPT and GIT_DIFF_TOOL for use by git-difftool--helper. |
5c38ea31 DA |
8 | # Any arguments that are unknown to this script are forwarded to 'git diff'. |
9 | ||
10 | use strict; | |
11 | use warnings; | |
12 | use Cwd qw(abs_path); | |
13 | use File::Basename qw(dirname); | |
14 | ||
15 | my $DIR = abs_path(dirname($0)); | |
16 | ||
17 | ||
18 | sub usage | |
19 | { | |
20 | print << 'USAGE'; | |
8b733222 | 21 | usage: git difftool [--tool=<tool>] [-y|--no-prompt] ["git diff" options] |
5c38ea31 DA |
22 | USAGE |
23 | exit 1; | |
24 | } | |
25 | ||
26 | sub setup_environment | |
27 | { | |
28 | $ENV{PATH} = "$DIR:$ENV{PATH}"; | |
29 | $ENV{GIT_PAGER} = ''; | |
afcbc8e7 | 30 | $ENV{GIT_EXTERNAL_DIFF} = 'git-difftool--helper'; |
5c38ea31 DA |
31 | } |
32 | ||
33 | sub exe | |
34 | { | |
35 | my $exe = shift; | |
46ae156d DA |
36 | if ($^O eq 'MSWin32' || $^O eq 'msys') { |
37 | return "$exe.exe"; | |
38 | } | |
39 | return $exe; | |
5c38ea31 DA |
40 | } |
41 | ||
42 | sub generate_command | |
43 | { | |
44 | my @command = (exe('git'), 'diff'); | |
45 | my $skip_next = 0; | |
46 | my $idx = -1; | |
47 | for my $arg (@ARGV) { | |
48 | $idx++; | |
49 | if ($skip_next) { | |
50 | $skip_next = 0; | |
51 | next; | |
52 | } | |
46ae156d | 53 | if ($arg eq '-t' || $arg eq '--tool') { |
5c38ea31 | 54 | usage() if $#ARGV <= $idx; |
2464456a | 55 | $ENV{GIT_DIFF_TOOL} = $ARGV[$idx + 1]; |
5c38ea31 DA |
56 | $skip_next = 1; |
57 | next; | |
58 | } | |
59 | if ($arg =~ /^--tool=/) { | |
2464456a | 60 | $ENV{GIT_DIFF_TOOL} = substr($arg, 7); |
5c38ea31 DA |
61 | next; |
62 | } | |
8b733222 | 63 | if ($arg eq '-y' || $arg eq '--no-prompt') { |
5c38ea31 DA |
64 | $ENV{GIT_DIFFTOOL_NO_PROMPT} = 'true'; |
65 | next; | |
66 | } | |
8b733222 | 67 | if ($arg eq '-h' || $arg eq '--help') { |
5c38ea31 DA |
68 | usage(); |
69 | } | |
70 | push @command, $arg; | |
71 | } | |
72 | return @command | |
73 | } | |
74 | ||
75 | setup_environment(); | |
76 | exec(generate_command()); |