git p4: introduce gitConfigBool
Make the intent of "--bool" more obvious by returning a direct True or False value. Convert a couple non-bool users with obvious bool intent. Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Pete Wyckoff committed
Jan 26, 2013 at 22:11 UTC
0d60903293d1a839541add545846c9a8b3967c5f
1 file changed
+26
-19
git-p4.py
+26
-19
@@ -561,17 +561,25 @@ def gitBranchExists(branch):
561
562
_gitConfig = {}
563
564
-def gitConfig(key, args=None): # set args to "--bool", for instance
564
+def gitConfig(key):
565
if not _gitConfig.has_key(key):
566
- cmd = [ "git", "config" ]
567
- if args:
568
- assert(args == "--bool")
569
- cmd.append(args)
570
- cmd.append(key)
566
+ cmd = [ "git", "config", key ]
567
s = read_pipe(cmd, ignore_error=True)
568
_gitConfig[key] = s.strip()
569
return _gitConfig[key]
570
571
+def gitConfigBool(key):
572
+ """Return a bool, using git config --bool. It is True only if the
573
+ variable is set to true, and False if set to false or not present
574
+ in the config."""
575
+
576
+ if not _gitConfig.has_key(key):
577
+ cmd = [ "git", "config", "--bool", key ]
578
+ s = read_pipe(cmd, ignore_error=True)
579
+ v = s.strip()
580
+ _gitConfig[key] = v == "true"
581
+ return _gitConfig[key]
582
+
583
def gitConfigList(key):
584
if not _gitConfig.has_key(key):
585
s = read_pipe(["git", "config", "--get-all", key], ignore_error=True)
@@ -722,8 +730,7 @@ def p4PathStartsWith(path, prefix):
730
#
731
# we may or may not have a problem. If you have core.ignorecase=true,
732
# we treat DirA and dira as the same directory
725
- ignorecase = gitConfig("core.ignorecase", "--bool") == "true"
726
- if ignorecase:
733
+ if gitConfigBool("core.ignorecase"):
734
return path.lower().startswith(prefix.lower())
735
return path.startswith(prefix)
736
@@ -959,7 +966,7 @@ class P4Submit(Command, P4UserMap):
966
self.usage += " [name of git branch to submit into perforce depot]"
967
self.origin = ""
968
self.detectRenames = False
962
- self.preserveUser = gitConfig("git-p4.preserveUser").lower() == "true"
969
+ self.preserveUser = gitConfigBool("git-p4.preserveUser")
970
self.dry_run = False
971
self.prepare_p4_only = False
972
self.conflict_behavior = None
@@ -1068,7 +1075,7 @@ class P4Submit(Command, P4UserMap):
1075
(user,email) = self.p4UserForCommit(id)
1076
if not user:
1077
msg = "Cannot find p4 user for email %s in commit %s." % (email, id)
1071
- if gitConfig('git-p4.allowMissingP4Users').lower() == "true":
1078
+ if gitConfigBool("git-p4.allowMissingP4Users"):
1079
print "%s" % msg
1080
else:
1081
die("Error: %s\nSet git-p4.allowMissingP4Users to true to allow this." % msg)
@@ -1163,7 +1170,7 @@ class P4Submit(Command, P4UserMap):
1170
message. Return true if okay to continue with the submit."""
1171
1172
# if configured to skip the editing part, just submit
1166
- if gitConfig("git-p4.skipSubmitEdit") == "true":
1173
+ if gitConfigBool("git-p4.skipSubmitEdit"):
1174
return True
1175
1176
# look at the modification time, to check later if the user saved
@@ -1179,7 +1186,7 @@ class P4Submit(Command, P4UserMap):
1186
1187
# If the file was not saved, prompt to see if this patch should
1188
# be skipped. But skip this verification step if configured so.
1182
- if gitConfig("git-p4.skipSubmitEditCheck") == "true":
1189
+ if gitConfigBool("git-p4.skipSubmitEditCheck"):
1190
return True
1191
1192
# modification time updated means user saved the file
@@ -1279,7 +1286,7 @@ class P4Submit(Command, P4UserMap):
1286
1287
# Patch failed, maybe it's just RCS keyword woes. Look through
1288
# the patch to see if that's possible.
1282
- if gitConfig("git-p4.attemptRCSCleanup","--bool") == "true":
1289
+ if gitConfigBool("git-p4.attemptRCSCleanup"):
1290
file = None
1291
pattern = None
1292
kwfiles = {}
@@ -1574,7 +1581,7 @@ class P4Submit(Command, P4UserMap):
1581
sys.exit(128)
1582
1583
self.useClientSpec = False
1577
- if gitConfig("git-p4.useclientspec", "--bool") == "true":
1584
+ if gitConfigBool("git-p4.useclientspec"):
1585
self.useClientSpec = True
1586
if self.useClientSpec:
1587
self.clientSpecDirs = getClientSpec()
@@ -1614,7 +1621,7 @@ class P4Submit(Command, P4UserMap):
1621
commits.append(line.strip())
1622
commits.reverse()
1623
1617
- if self.preserveUser or (gitConfig("git-p4.skipUserNameCheck") == "true"):
1624
+ if self.preserveUser or gitConfigBool("git-p4.skipUserNameCheck"):
1625
self.checkAuthorship = False
1626
else:
1627
self.checkAuthorship = True
@@ -1650,7 +1657,7 @@ class P4Submit(Command, P4UserMap):
1657
else:
1658
self.diffOpts += " -C%s" % detectCopies
1659
1653
- if gitConfig("git-p4.detectCopiesHarder", "--bool") == "true":
1660
+ if gitConfigBool("git-p4.detectCopiesHarder"):
1661
self.diffOpts += " --find-copies-harder"
1662
1663
#
@@ -1734,7 +1741,7 @@ class P4Submit(Command, P4UserMap):
1741
"--format=format:%h %s", c])
1742
print "You will have to do 'git p4 sync' and rebase."
1743
1737
- if gitConfig("git-p4.exportLabels", "--bool") == "true":
1744
+ if gitConfigBool("git-p4.exportLabels"):
1745
self.exportLabels = True
1746
1747
if self.exportLabels:
@@ -2834,7 +2841,7 @@ class P4Sync(Command, P4UserMap):
2841
# will use this after clone to set the variable
2842
self.useClientSpec_from_options = True
2843
else:
2837
- if gitConfig("git-p4.useclientspec", "--bool") == "true":
2844
+ if gitConfigBool("git-p4.useclientspec"):
2845
self.useClientSpec = True
2846
if self.useClientSpec:
2847
self.clientSpecDirs = getClientSpec()
@@ -3074,7 +3081,7 @@ class P4Sync(Command, P4UserMap):
3081
sys.stdout.write("%s " % b)
3082
sys.stdout.write("\n")
3083
3077
- if gitConfig("git-p4.importLabels", "--bool") == "true":
3084
+ if gitConfigBool("git-p4.importLabels"):
3085
self.importLabels = True
3086
3087
if self.importLabels: