Skip to content

Commit c9bdd50

Browse files
davvidgitster
authored andcommitted
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>
1 parent 75cd758 commit c9bdd50

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

git-difftool.perl

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -264,41 +264,48 @@ sub main
264264
{
265265
# parse command-line options. all unrecognized options and arguments
266266
# 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})) {
278286
usage(0);
279287
}
280-
if (defined($tool_help)) {
288+
if (defined($opts{tool_help})) {
281289
print_tool_help();
282290
}
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};
286294
} else {
287295
print "No <tool> given for --tool=<tool>\n";
288296
usage(1);
289297
}
290298
}
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};
294302
} else {
295303
print "No <cmd> given for --extcmd=<cmd>\n";
296304
usage(1);
297305
}
298306
}
299-
if ($gui) {
300-
my $guitool = '';
301-
$guitool = Git::config('diff.guitool');
307+
if ($opts{gui}) {
308+
my $guitool = Git::config('diff.guitool');
302309
if (length($guitool) > 0) {
303310
$ENV{GIT_DIFF_TOOL} = $guitool;
304311
}
@@ -308,10 +315,10 @@ sub main
308315
# to compare the a/b directories. In file diff mode, 'git diff'
309316
# will invoke a separate instance of 'git-difftool--helper' for
310317
# each file that changed.
311-
if (defined($dirdiff)) {
312-
dir_diff($extcmd);
318+
if (defined($opts{dirdiff})) {
319+
dir_diff($opts{extcmd});
313320
} else {
314-
file_diff($prompt);
321+
file_diff($opts{prompt});
315322
}
316323
}
317324

0 commit comments

Comments
 (0)