git-p4: add optional type specifier to gitConfig reader
The functions "gitConfig" and "gitConfigBool" are almost identical. Make "gitConfig" more generic by adding an optional type specifier. Use the type specifier "--bool" with "gitConfig" to implement "gitConfigBool. This prepares the implementation of other type specifiers such as "--int". Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Acked-by: Luke Diamand <luke@diamand.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lars Schneider committed
Sep 26, 2015 at 09:54 UTC
692e17964dd4f8da4b3994c5c7055ec9a8c22a75
1 file changed
+6
-6
git-p4.py
+6
-6
@@ -604,9 +604,12 @@ def gitBranchExists(branch):
604
605
_gitConfig = {}
606
607
-def gitConfig(key):
607
+def gitConfig(key, typeSpecifier=None):
608
if not _gitConfig.has_key(key):
609
- cmd = [ "git", "config", key ]
609
+ cmd = [ "git", "config" ]
610
+ if typeSpecifier:
611
+ cmd += [ typeSpecifier ]
612
+ cmd += [ key ]
613
s = read_pipe(cmd, ignore_error=True)
614
_gitConfig[key] = s.strip()
615
return _gitConfig[key]
@@ -617,10 +620,7 @@ def gitConfigBool(key):
620
in the config."""
621
622
if not _gitConfig.has_key(key):
620
- cmd = [ "git", "config", "--bool", key ]
621
- s = read_pipe(cmd, ignore_error=True)
622
- v = s.strip()
623
- _gitConfig[key] = v == "true"
623
+ _gitConfig[key] = gitConfig(key, '--bool') == "true"
624
return _gitConfig[key]
625
626
def gitConfigList(key):