@@ -561,17 +561,25 @@ def gitBranchExists(branch):
561561
562562_gitConfig = {}
563563
564- def gitConfig (key , args = None ): # set args to "--bool", for instance
564+ def gitConfig (key ):
565565 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 ]
571567 s = read_pipe (cmd , ignore_error = True )
572568 _gitConfig [key ] = s .strip ()
573569 return _gitConfig [key ]
574570
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+
575583def gitConfigList (key ):
576584 if not _gitConfig .has_key (key ):
577585 s = read_pipe (["git" , "config" , "--get-all" , key ], ignore_error = True )
@@ -722,8 +730,7 @@ def p4PathStartsWith(path, prefix):
722730 #
723731 # we may or may not have a problem. If you have core.ignorecase=true,
724732 # we treat DirA and dira as the same directory
725- ignorecase = gitConfig ("core.ignorecase" , "--bool" ) == "true"
726- if ignorecase :
733+ if gitConfigBool ("core.ignorecase" ):
727734 return path .lower ().startswith (prefix .lower ())
728735 return path .startswith (prefix )
729736
@@ -959,7 +966,7 @@ def __init__(self):
959966 self .usage += " [name of git branch to submit into perforce depot]"
960967 self .origin = ""
961968 self .detectRenames = False
962- self .preserveUser = gitConfig ("git-p4.preserveUser" ). lower () == "true"
969+ self .preserveUser = gitConfigBool ("git-p4.preserveUser" )
963970 self .dry_run = False
964971 self .prepare_p4_only = False
965972 self .conflict_behavior = None
@@ -1068,7 +1075,7 @@ def checkValidP4Users(self,commits):
10681075 (user ,email ) = self .p4UserForCommit (id )
10691076 if not user :
10701077 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" ) :
10721079 print "%s" % msg
10731080 else :
10741081 die ("Error: %s\n Set git-p4.allowMissingP4Users to true to allow this." % msg )
@@ -1163,7 +1170,7 @@ def edit_template(self, template_file):
11631170 message. Return true if okay to continue with the submit."""
11641171
11651172 # if configured to skip the editing part, just submit
1166- if gitConfig ("git-p4.skipSubmitEdit" ) == "true" :
1173+ if gitConfigBool ("git-p4.skipSubmitEdit" ):
11671174 return True
11681175
11691176 # look at the modification time, to check later if the user saved
@@ -1179,7 +1186,7 @@ def edit_template(self, template_file):
11791186
11801187 # If the file was not saved, prompt to see if this patch should
11811188 # be skipped. But skip this verification step if configured so.
1182- if gitConfig ("git-p4.skipSubmitEditCheck" ) == "true" :
1189+ if gitConfigBool ("git-p4.skipSubmitEditCheck" ):
11831190 return True
11841191
11851192 # modification time updated means user saved the file
@@ -1279,7 +1286,7 @@ def applyCommit(self, id):
12791286
12801287 # Patch failed, maybe it's just RCS keyword woes. Look through
12811288 # the patch to see if that's possible.
1282- if gitConfig ("git-p4.attemptRCSCleanup" , "--bool" ) == "true" :
1289+ if gitConfigBool ("git-p4.attemptRCSCleanup" ) :
12831290 file = None
12841291 pattern = None
12851292 kwfiles = {}
@@ -1574,7 +1581,7 @@ def run(self, args):
15741581 sys .exit (128 )
15751582
15761583 self .useClientSpec = False
1577- if gitConfig ("git-p4.useclientspec" , "--bool" ) == "true" :
1584+ if gitConfigBool ("git-p4.useclientspec" ) :
15781585 self .useClientSpec = True
15791586 if self .useClientSpec :
15801587 self .clientSpecDirs = getClientSpec ()
@@ -1614,7 +1621,7 @@ def run(self, args):
16141621 commits .append (line .strip ())
16151622 commits .reverse ()
16161623
1617- if self .preserveUser or ( gitConfig ( "git-p4.skipUserNameCheck" ) == "true " ):
1624+ if self .preserveUser or gitConfigBool ( "git-p4.skipUserNameCheck" ):
16181625 self .checkAuthorship = False
16191626 else :
16201627 self .checkAuthorship = True
@@ -1650,7 +1657,7 @@ def run(self, args):
16501657 else :
16511658 self .diffOpts += " -C%s" % detectCopies
16521659
1653- if gitConfig ("git-p4.detectCopiesHarder" , "--bool" ) == "true" :
1660+ if gitConfigBool ("git-p4.detectCopiesHarder" ) :
16541661 self .diffOpts += " --find-copies-harder"
16551662
16561663 #
@@ -1734,7 +1741,7 @@ def run(self, args):
17341741 "--format=format:%h %s" , c ])
17351742 print "You will have to do 'git p4 sync' and rebase."
17361743
1737- if gitConfig ("git-p4.exportLabels" , "--bool" ) == "true" :
1744+ if gitConfigBool ("git-p4.exportLabels" ) :
17381745 self .exportLabels = True
17391746
17401747 if self .exportLabels :
@@ -2834,7 +2841,7 @@ def run(self, args):
28342841 # will use this after clone to set the variable
28352842 self .useClientSpec_from_options = True
28362843 else :
2837- if gitConfig ("git-p4.useclientspec" , "--bool" ) == "true" :
2844+ if gitConfigBool ("git-p4.useclientspec" ) :
28382845 self .useClientSpec = True
28392846 if self .useClientSpec :
28402847 self .clientSpecDirs = getClientSpec ()
@@ -3074,7 +3081,7 @@ def run(self, args):
30743081 sys .stdout .write ("%s " % b )
30753082 sys .stdout .write ("\n " )
30763083
3077- if gitConfig ("git-p4.importLabels" , "--bool" ) == "true" :
3084+ if gitConfigBool ("git-p4.importLabels" ) :
30783085 self .importLabels = True
30793086
30803087 if self .importLabels :
0 commit comments