difftool: Move option values into a hash

Shorten the "my" declaration for all of the option-specific variables
by wrapping all of them in a hash.  This also gives us a place to
specify default values, should we need them.

Signed-off-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
David Aguilar 2012-07-22 20:57:09 -07:00 committed by Junio C Hamano
parent 75cd758309
commit c9bdd50520

View File

@ -264,41 +264,48 @@ sub main
{ {
# parse command-line options. all unrecognized options and arguments # parse command-line options. all unrecognized options and arguments
# are passed through to the 'git diff' command. # are passed through to the 'git diff' command.
my ($difftool_cmd, $dirdiff, $extcmd, $gui, $help, $prompt, $tool_help); my %opts = (
GetOptions('g|gui!' => \$gui, difftool_cmd => undef,
'd|dir-diff' => \$dirdiff, dirdiff => undef,
'h' => \$help, extcmd => undef,
'prompt!' => \$prompt, gui => undef,
'y' => sub { $prompt = 0; }, help => undef,
't|tool:s' => \$difftool_cmd, prompt => undef,
'tool-help' => \$tool_help, tool_help => undef,
'x|extcmd:s' => \$extcmd); );
GetOptions('g|gui!' => \$opts{gui},
'd|dir-diff' => \$opts{dirdiff},
'h' => \$opts{help},
'prompt!' => \$opts{prompt},
'y' => sub { $opts{prompt} = 0; },
't|tool:s' => \$opts{difftool_cmd},
'tool-help' => \$opts{tool_help},
'x|extcmd:s' => \$opts{extcmd});
if (defined($help)) { if (defined($opts{help})) {
usage(0); usage(0);
} }
if (defined($tool_help)) { if (defined($opts{tool_help})) {
print_tool_help(); print_tool_help();
} }
if (defined($difftool_cmd)) { if (defined($opts{difftool_cmd})) {
if (length($difftool_cmd) > 0) { if (length($opts{difftool_cmd}) > 0) {
$ENV{GIT_DIFF_TOOL} = $difftool_cmd; $ENV{GIT_DIFF_TOOL} = $opts{difftool_cmd};
} else { } else {
print "No <tool> given for --tool=<tool>\n"; print "No <tool> given for --tool=<tool>\n";
usage(1); usage(1);
} }
} }
if (defined($extcmd)) { if (defined($opts{extcmd})) {
if (length($extcmd) > 0) { if (length($opts{extcmd}) > 0) {
$ENV{GIT_DIFFTOOL_EXTCMD} = $extcmd; $ENV{GIT_DIFFTOOL_EXTCMD} = $opts{extcmd};
} else { } else {
print "No <cmd> given for --extcmd=<cmd>\n"; print "No <cmd> given for --extcmd=<cmd>\n";
usage(1); usage(1);
} }
} }
if ($gui) { if ($opts{gui}) {
my $guitool = ''; my $guitool = Git::config('diff.guitool');
$guitool = Git::config('diff.guitool');
if (length($guitool) > 0) { if (length($guitool) > 0) {
$ENV{GIT_DIFF_TOOL} = $guitool; $ENV{GIT_DIFF_TOOL} = $guitool;
} }
@ -308,10 +315,10 @@ sub main
# to compare the a/b directories. In file diff mode, 'git diff' # to compare the a/b directories. In file diff mode, 'git diff'
# will invoke a separate instance of 'git-difftool--helper' for # will invoke a separate instance of 'git-difftool--helper' for
# each file that changed. # each file that changed.
if (defined($dirdiff)) { if (defined($opts{dirdiff})) {
dir_diff($extcmd); dir_diff($opts{extcmd});
} else { } else {
file_diff($prompt); file_diff($opts{prompt});
} }
} }