@@ -561,17 +561,25 @@ def gitBranchExists(branch):
561
561
562
562
_gitConfig = {}
563
563
564
- def gitConfig (key , args = None ): # set args to "--bool", for instance
564
+ def gitConfig (key ):
565
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 ]
571
567
s = read_pipe (cmd , ignore_error = True )
572
568
_gitConfig [key ] = s .strip ()
573
569
return _gitConfig [key ]
574
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
+
575
583
def gitConfigList (key ):
576
584
if not _gitConfig .has_key (key ):
577
585
s = read_pipe (["git" , "config" , "--get-all" , key ], ignore_error = True )
@@ -722,8 +730,7 @@ def p4PathStartsWith(path, prefix):
722
730
#
723
731
# we may or may not have a problem. If you have core.ignorecase=true,
724
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" ):
727
734
return path .lower ().startswith (prefix .lower ())
728
735
return path .startswith (prefix )
729
736
@@ -959,7 +966,7 @@ def __init__(self):
959
966
self .usage += " [name of git branch to submit into perforce depot]"
960
967
self .origin = ""
961
968
self .detectRenames = False
962
- self .preserveUser = gitConfig ("git-p4.preserveUser" ). lower () == "true"
969
+ self .preserveUser = gitConfigBool ("git-p4.preserveUser" )
963
970
self .dry_run = False
964
971
self .prepare_p4_only = False
965
972
self .conflict_behavior = None
@@ -1068,7 +1075,7 @@ def checkValidP4Users(self,commits):
1068
1075
(user ,email ) = self .p4UserForCommit (id )
1069
1076
if not user :
1070
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" ) :
1072
1079
print "%s" % msg
1073
1080
else :
1074
1081
die ("Error: %s\n Set git-p4.allowMissingP4Users to true to allow this." % msg )
@@ -1163,7 +1170,7 @@ def edit_template(self, template_file):
1163
1170
message. Return true if okay to continue with the submit."""
1164
1171
1165
1172
# if configured to skip the editing part, just submit
1166
- if gitConfig ("git-p4.skipSubmitEdit" ) == "true" :
1173
+ if gitConfigBool ("git-p4.skipSubmitEdit" ):
1167
1174
return True
1168
1175
1169
1176
# look at the modification time, to check later if the user saved
@@ -1179,7 +1186,7 @@ def edit_template(self, template_file):
1179
1186
1180
1187
# If the file was not saved, prompt to see if this patch should
1181
1188
# be skipped. But skip this verification step if configured so.
1182
- if gitConfig ("git-p4.skipSubmitEditCheck" ) == "true" :
1189
+ if gitConfigBool ("git-p4.skipSubmitEditCheck" ):
1183
1190
return True
1184
1191
1185
1192
# modification time updated means user saved the file
@@ -1279,7 +1286,7 @@ def applyCommit(self, id):
1279
1286
1280
1287
# Patch failed, maybe it's just RCS keyword woes. Look through
1281
1288
# the patch to see if that's possible.
1282
- if gitConfig ("git-p4.attemptRCSCleanup" , "--bool" ) == "true" :
1289
+ if gitConfigBool ("git-p4.attemptRCSCleanup" ) :
1283
1290
file = None
1284
1291
pattern = None
1285
1292
kwfiles = {}
@@ -1574,7 +1581,7 @@ def run(self, args):
1574
1581
sys .exit (128 )
1575
1582
1576
1583
self .useClientSpec = False
1577
- if gitConfig ("git-p4.useclientspec" , "--bool" ) == "true" :
1584
+ if gitConfigBool ("git-p4.useclientspec" ) :
1578
1585
self .useClientSpec = True
1579
1586
if self .useClientSpec :
1580
1587
self .clientSpecDirs = getClientSpec ()
@@ -1614,7 +1621,7 @@ def run(self, args):
1614
1621
commits .append (line .strip ())
1615
1622
commits .reverse ()
1616
1623
1617
- if self .preserveUser or ( gitConfig ( "git-p4.skipUserNameCheck" ) == "true " ):
1624
+ if self .preserveUser or gitConfigBool ( "git-p4.skipUserNameCheck" ):
1618
1625
self .checkAuthorship = False
1619
1626
else :
1620
1627
self .checkAuthorship = True
@@ -1650,7 +1657,7 @@ def run(self, args):
1650
1657
else :
1651
1658
self .diffOpts += " -C%s" % detectCopies
1652
1659
1653
- if gitConfig ("git-p4.detectCopiesHarder" , "--bool" ) == "true" :
1660
+ if gitConfigBool ("git-p4.detectCopiesHarder" ) :
1654
1661
self .diffOpts += " --find-copies-harder"
1655
1662
1656
1663
#
@@ -1734,7 +1741,7 @@ def run(self, args):
1734
1741
"--format=format:%h %s" , c ])
1735
1742
print "You will have to do 'git p4 sync' and rebase."
1736
1743
1737
- if gitConfig ("git-p4.exportLabels" , "--bool" ) == "true" :
1744
+ if gitConfigBool ("git-p4.exportLabels" ) :
1738
1745
self .exportLabels = True
1739
1746
1740
1747
if self .exportLabels :
@@ -2834,7 +2841,7 @@ def run(self, args):
2834
2841
# will use this after clone to set the variable
2835
2842
self .useClientSpec_from_options = True
2836
2843
else :
2837
- if gitConfig ("git-p4.useclientspec" , "--bool" ) == "true" :
2844
+ if gitConfigBool ("git-p4.useclientspec" ) :
2838
2845
self .useClientSpec = True
2839
2846
if self .useClientSpec :
2840
2847
self .clientSpecDirs = getClientSpec ()
@@ -3074,7 +3081,7 @@ def run(self, args):
3074
3081
sys .stdout .write ("%s " % b )
3075
3082
sys .stdout .write ("\n " )
3076
3083
3077
- if gitConfig ("git-p4.importLabels" , "--bool" ) == "true" :
3084
+ if gitConfigBool ("git-p4.importLabels" ) :
3078
3085
self .importLabels = True
3079
3086
3080
3087
if self .importLabels :
0 commit comments