difftool: exit(0) when usage is printed

Prior to this commit, the script exited with an error whenever the usage string was printed, regardless of the reason it was done. In cases where usage was printed due to a user request (e.g. '-h' option), the script should exit without error (exit 0). This commit adds an argument to the usage function that allows the exit code to be specified when the function is called. Signed-off-by: Tim Henigan <tim.henigan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tim Henigan committed Mar 22, 2012 at 15:52 UTC 283607694c1248a8e1ff4cda48aa5d1eb1287733
1 file changed +5 -4
git-difftool.perl
+5 -4
@@ -20,6 +20,7 @@ use Git;
20
21 sub usage
22 {
23 + my $exitcode = shift;
24 print << 'USAGE';
25 usage: git difftool [-t|--tool=<tool>]
26 [-x|--extcmd=<cmd>]
@@ -27,7 +28,7 @@ usage: git difftool [-t|--tool=<tool>]
28 [--prompt] [-y|--no-prompt]
29 ['git diff' options]
30 USAGE
30 - exit 1;
31 + exit($exitcode);
32 }
33
34 sub setup_environment
@@ -58,14 +59,14 @@ GetOptions('g|gui!' => \$gui,
59 'x|extcmd:s' => \$extcmd);
60
61 if (defined($help)) {
61 - usage();
62 + usage(0);
63 }
64 if (defined($difftool_cmd)) {
65 if (length($difftool_cmd) > 0) {
66 $ENV{GIT_DIFF_TOOL} = $difftool_cmd;
67 } else {
68 print "No <tool> given for --tool=<tool>\n";
68 - usage();
69 + usage(1);
70 }
71 }
72 if (defined($extcmd)) {
@@ -73,7 +74,7 @@ if (defined($extcmd)) {
74 $ENV{GIT_DIFFTOOL_EXTCMD} = $extcmd;
75 } else {
76 print "No <cmd> given for --extcmd=<cmd>\n";
76 - usage();
77 + usage(1);
78 }
79 }
80 if ($gui) {