From: David Aguilar <davvid@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Tim Henigan <tim.henigan@gmail.com>, git@vger.kernel.org
Subject: [PATCH 3/5] difftool: Move option values into a hash
Date: Sun, 22 Jul 2012 20:57:09 -0700 [thread overview]
Message-ID: <1343015831-17498-4-git-send-email-davvid@gmail.com> (raw)
In-Reply-To: <1343015831-17498-3-git-send-email-davvid@gmail.com>
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>
---
Fixed typo in the commit message
git-difftool.perl | 55 +++++++++++++++++++++++++++++++------------------------
1 file changed, 31 insertions(+), 24 deletions(-)
diff --git a/git-difftool.perl b/git-difftool.perl
index 41ba932..0ce6168 100755
--- a/git-difftool.perl
+++ b/git-difftool.perl
@@ -264,41 +264,48 @@ sub main
{
# parse command-line options. all unrecognized options and arguments
# are passed through to the 'git diff' command.
- my ($difftool_cmd, $dirdiff, $extcmd, $gui, $help, $prompt, $tool_help);
- GetOptions('g|gui!' => \$gui,
- 'd|dir-diff' => \$dirdiff,
- 'h' => \$help,
- 'prompt!' => \$prompt,
- 'y' => sub { $prompt = 0; },
- 't|tool:s' => \$difftool_cmd,
- 'tool-help' => \$tool_help,
- 'x|extcmd:s' => \$extcmd);
-
- if (defined($help)) {
+ my %opts = (
+ difftool_cmd => undef,
+ dirdiff => undef,
+ extcmd => undef,
+ gui => undef,
+ help => undef,
+ prompt => undef,
+ tool_help => undef,
+ );
+ 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($opts{help})) {
usage(0);
}
- if (defined($tool_help)) {
+ if (defined($opts{tool_help})) {
print_tool_help();
}
- if (defined($difftool_cmd)) {
- if (length($difftool_cmd) > 0) {
- $ENV{GIT_DIFF_TOOL} = $difftool_cmd;
+ if (defined($opts{difftool_cmd})) {
+ if (length($opts{difftool_cmd}) > 0) {
+ $ENV{GIT_DIFF_TOOL} = $opts{difftool_cmd};
} else {
print "No <tool> given for --tool=<tool>\n";
usage(1);
}
}
- if (defined($extcmd)) {
- if (length($extcmd) > 0) {
- $ENV{GIT_DIFFTOOL_EXTCMD} = $extcmd;
+ if (defined($opts{extcmd})) {
+ if (length($opts{extcmd}) > 0) {
+ $ENV{GIT_DIFFTOOL_EXTCMD} = $opts{extcmd};
} else {
print "No <cmd> given for --extcmd=<cmd>\n";
usage(1);
}
}
- if ($gui) {
- my $guitool = '';
- $guitool = Git::config('diff.guitool');
+ if ($opts{gui}) {
+ my $guitool = Git::config('diff.guitool');
if (length($guitool) > 0) {
$ENV{GIT_DIFF_TOOL} = $guitool;
}
@@ -308,10 +315,10 @@ sub main
# to compare the a/b directories. In file diff mode, 'git diff'
# will invoke a separate instance of 'git-difftool--helper' for
# each file that changed.
- if (defined($dirdiff)) {
- dir_diff($extcmd);
+ if (defined($opts{dirdiff})) {
+ dir_diff($opts{extcmd});
} else {
- file_diff($prompt);
+ file_diff($opts{prompt});
}
}
--
1.7.11.2.255.g5f133da
next prev parent reply other threads:[~2012-07-23 3:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-23 3:57 [PATCH v2 0/5] difftool: Use symlinks in dir-diff mode David Aguilar
2012-07-23 3:57 ` [PATCH v2 1/5] difftool: Simplify print_tool_help() David Aguilar
2012-07-23 3:57 ` [PATCH 2/5] difftool: Eliminate global variables David Aguilar
2012-07-23 3:57 ` David Aguilar [this message]
2012-07-23 3:57 ` [PATCH 4/5] difftool: Call the temp directory "git-difftool" David Aguilar
2012-07-23 3:57 ` [PATCH 5/5] difftool: Use symlinks when diffing against the worktree David Aguilar
2012-07-23 4:57 ` Junio C Hamano
2012-07-23 6:05 ` [PATCH v3 4/5] " David Aguilar
2012-07-23 16:38 ` Junio C Hamano
2012-07-24 13:35 ` Tim Henigan
2012-07-24 15:57 ` Junio C Hamano
2012-07-23 5:14 ` [PATCH v2 0/5] difftool: Use symlinks in dir-diff mode Junio C Hamano
2012-07-23 5:34 ` David Aguilar
-- strict thread matches above, loose matches on Subject: below --
2012-07-23 3:42 [PATCH 1/5] difftool: Simplify print_tool_help() David Aguilar
2012-07-23 3:42 ` [PATCH 3/5] difftool: Move option values into a hash David Aguilar
2012-07-23 3:49 ` David Aguilar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1343015831-17498-4-git-send-email-davvid@gmail.com \
--to=davvid@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=tim.henigan@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).