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>
David Aguilar committed
Jul 22, 2012 at 20:57 UTC
c9bdd505200120a8dab0f7417ad3fd7553e39e3f
1 file changed
+31
-24
git-difftool.perl
+31
-24
@@ -264,41 +264,48 @@ sub main
264
{
265
# parse command-line options. all unrecognized options and arguments
266
# are passed through to the 'git diff' command.
267
- my ($difftool_cmd, $dirdiff, $extcmd, $gui, $help, $prompt, $tool_help);
268
- GetOptions('g|gui!' => \$gui,
269
- 'd|dir-diff' => \$dirdiff,
270
- 'h' => \$help,
271
- 'prompt!' => \$prompt,
272
- 'y' => sub { $prompt = 0; },
273
- 't|tool:s' => \$difftool_cmd,
274
- 'tool-help' => \$tool_help,
275
- 'x|extcmd:s' => \$extcmd);
276
-
277
- if (defined($help)) {
267
+ my %opts = (
268
+ difftool_cmd => undef,
269
+ dirdiff => undef,
270
+ extcmd => undef,
271
+ gui => undef,
272
+ help => undef,
273
+ prompt => undef,
274
+ tool_help => undef,
275
+ );
276
+ GetOptions('g|gui!' => \$opts{gui},
277
+ 'd|dir-diff' => \$opts{dirdiff},
278
+ 'h' => \$opts{help},
279
+ 'prompt!' => \$opts{prompt},
280
+ 'y' => sub { $opts{prompt} = 0; },
281
+ 't|tool:s' => \$opts{difftool_cmd},
282
+ 'tool-help' => \$opts{tool_help},
283
+ 'x|extcmd:s' => \$opts{extcmd});
284
+
285
+ if (defined($opts{help})) {
286
usage(0);
287
}
280
- if (defined($tool_help)) {
288
+ if (defined($opts{tool_help})) {
289
print_tool_help();
290
}
283
- if (defined($difftool_cmd)) {
284
- if (length($difftool_cmd) > 0) {
285
- $ENV{GIT_DIFF_TOOL} = $difftool_cmd;
291
+ if (defined($opts{difftool_cmd})) {
292
+ if (length($opts{difftool_cmd}) > 0) {
293
+ $ENV{GIT_DIFF_TOOL} = $opts{difftool_cmd};
294
} else {
295
print "No <tool> given for --tool=<tool>\n";
296
usage(1);
297
}
298
}
291
- if (defined($extcmd)) {
292
- if (length($extcmd) > 0) {
293
- $ENV{GIT_DIFFTOOL_EXTCMD} = $extcmd;
299
+ if (defined($opts{extcmd})) {
300
+ if (length($opts{extcmd}) > 0) {
301
+ $ENV{GIT_DIFFTOOL_EXTCMD} = $opts{extcmd};
302
} else {
303
print "No <cmd> given for --extcmd=<cmd>\n";
304
usage(1);
305
}
306
}
299
- if ($gui) {
300
- my $guitool = '';
301
- $guitool = Git::config('diff.guitool');
307
+ if ($opts{gui}) {
308
+ my $guitool = Git::config('diff.guitool');
309
if (length($guitool) > 0) {
310
$ENV{GIT_DIFF_TOOL} = $guitool;
311
}
@@ -308,10 +315,10 @@ sub main
315
# to compare the a/b directories. In file diff mode, 'git diff'
316
# will invoke a separate instance of 'git-difftool--helper' for
317
# each file that changed.
311
- if (defined($dirdiff)) {
312
- dir_diff($extcmd);
318
+ if (defined($opts{dirdiff})) {
319
+ dir_diff($opts{extcmd});
320
} else {
314
- file_diff($prompt);
321
+ file_diff($opts{prompt});
322
}
323
}
324