threads / patch / 13757

patchGit.pm: fix return value of config method

Subject: [PATCH] Git.pm: fix return value of config method

## tl;dr

One message between Jun 1, 2008 and Jun 1, 2008. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Lea Wiemann· Jun 1, 2008, 20:34 UTC · lore

If config is called in array context, it is supposed to return all values set for the given option key. This works for all cases except if there is no value set at all. In that case, it wrongly returns (undef) instead of (). This fixes the return statement so that it returns undef in scalar context but an empty array in array context.

Signed-off-by: Lea Wiemann <LeWiemann@gmail.com>
---
Use the following command to test this:
perl -e 'use Git; $r = Git->repository("."); my @a = $r->config("nonexistent"); print scalar @a;'
This prints 1 before and 0 after applying this patch.

This will also be covered by the Git.pm test suite, which I'm correctly working on.

 perl/Git.pm |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to perl/Git.pm +1 −1
diff --git a/perl/Git.pm b/perl/Git.pm
index 07b92c7..222fdbf 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -565,7 +565,7 @@ sub config {
 		my $E = shift;
 		if ($E->value() == 1) {
 			# Key not found.
-			return undef;
+			return;
 		} else {
 			throw $E;
 		}
-- 
1.5.5.GIT

← back to recent threads