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>
This commit is contained in:
parent
b345d6c3b7
commit
0d60903293
45
git-p4.py
45
git-p4.py
@ -561,17 +561,25 @@ def gitBranchExists(branch):
|
|||||||
|
|
||||||
_gitConfig = {}
|
_gitConfig = {}
|
||||||
|
|
||||||
def gitConfig(key, args=None): # set args to "--bool", for instance
|
def gitConfig(key):
|
||||||
if not _gitConfig.has_key(key):
|
if not _gitConfig.has_key(key):
|
||||||
cmd = [ "git", "config" ]
|
cmd = [ "git", "config", key ]
|
||||||
if args:
|
|
||||||
assert(args == "--bool")
|
|
||||||
cmd.append(args)
|
|
||||||
cmd.append(key)
|
|
||||||
s = read_pipe(cmd, ignore_error=True)
|
s = read_pipe(cmd, ignore_error=True)
|
||||||
_gitConfig[key] = s.strip()
|
_gitConfig[key] = s.strip()
|
||||||
return _gitConfig[key]
|
return _gitConfig[key]
|
||||||
|
|
||||||
|
def gitConfigBool(key):
|
||||||
|
"""Return a bool, using git config --bool. It is True only if the
|
||||||
|
variable is set to true, and False if set to false or not present
|
||||||
|
in the config."""
|
||||||
|
|
||||||
|
if not _gitConfig.has_key(key):
|
||||||
|
cmd = [ "git", "config", "--bool", key ]
|
||||||
|
s = read_pipe(cmd, ignore_error=True)
|
||||||
|
v = s.strip()
|
||||||
|
_gitConfig[key] = v == "true"
|
||||||
|
return _gitConfig[key]
|
||||||
|
|
||||||
def gitConfigList(key):
|
def gitConfigList(key):
|
||||||
if not _gitConfig.has_key(key):
|
if not _gitConfig.has_key(key):
|
||||||
s = read_pipe(["git", "config", "--get-all", key], ignore_error=True)
|
s = read_pipe(["git", "config", "--get-all", key], ignore_error=True)
|
||||||
@ -722,8 +730,7 @@ def p4PathStartsWith(path, prefix):
|
|||||||
#
|
#
|
||||||
# we may or may not have a problem. If you have core.ignorecase=true,
|
# we may or may not have a problem. If you have core.ignorecase=true,
|
||||||
# we treat DirA and dira as the same directory
|
# we treat DirA and dira as the same directory
|
||||||
ignorecase = gitConfig("core.ignorecase", "--bool") == "true"
|
if gitConfigBool("core.ignorecase"):
|
||||||
if ignorecase:
|
|
||||||
return path.lower().startswith(prefix.lower())
|
return path.lower().startswith(prefix.lower())
|
||||||
return path.startswith(prefix)
|
return path.startswith(prefix)
|
||||||
|
|
||||||
@ -959,7 +966,7 @@ class P4Submit(Command, P4UserMap):
|
|||||||
self.usage += " [name of git branch to submit into perforce depot]"
|
self.usage += " [name of git branch to submit into perforce depot]"
|
||||||
self.origin = ""
|
self.origin = ""
|
||||||
self.detectRenames = False
|
self.detectRenames = False
|
||||||
self.preserveUser = gitConfig("git-p4.preserveUser").lower() == "true"
|
self.preserveUser = gitConfigBool("git-p4.preserveUser")
|
||||||
self.dry_run = False
|
self.dry_run = False
|
||||||
self.prepare_p4_only = False
|
self.prepare_p4_only = False
|
||||||
self.conflict_behavior = None
|
self.conflict_behavior = None
|
||||||
@ -1068,7 +1075,7 @@ class P4Submit(Command, P4UserMap):
|
|||||||
(user,email) = self.p4UserForCommit(id)
|
(user,email) = self.p4UserForCommit(id)
|
||||||
if not user:
|
if not user:
|
||||||
msg = "Cannot find p4 user for email %s in commit %s." % (email, id)
|
msg = "Cannot find p4 user for email %s in commit %s." % (email, id)
|
||||||
if gitConfig('git-p4.allowMissingP4Users').lower() == "true":
|
if gitConfigBool("git-p4.allowMissingP4Users"):
|
||||||
print "%s" % msg
|
print "%s" % msg
|
||||||
else:
|
else:
|
||||||
die("Error: %s\nSet git-p4.allowMissingP4Users to true to allow this." % msg)
|
die("Error: %s\nSet git-p4.allowMissingP4Users to true to allow this." % msg)
|
||||||
@ -1163,7 +1170,7 @@ class P4Submit(Command, P4UserMap):
|
|||||||
message. Return true if okay to continue with the submit."""
|
message. Return true if okay to continue with the submit."""
|
||||||
|
|
||||||
# if configured to skip the editing part, just submit
|
# if configured to skip the editing part, just submit
|
||||||
if gitConfig("git-p4.skipSubmitEdit") == "true":
|
if gitConfigBool("git-p4.skipSubmitEdit"):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# look at the modification time, to check later if the user saved
|
# look at the modification time, to check later if the user saved
|
||||||
@ -1179,7 +1186,7 @@ class P4Submit(Command, P4UserMap):
|
|||||||
|
|
||||||
# If the file was not saved, prompt to see if this patch should
|
# If the file was not saved, prompt to see if this patch should
|
||||||
# be skipped. But skip this verification step if configured so.
|
# be skipped. But skip this verification step if configured so.
|
||||||
if gitConfig("git-p4.skipSubmitEditCheck") == "true":
|
if gitConfigBool("git-p4.skipSubmitEditCheck"):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# modification time updated means user saved the file
|
# modification time updated means user saved the file
|
||||||
@ -1279,7 +1286,7 @@ class P4Submit(Command, P4UserMap):
|
|||||||
|
|
||||||
# Patch failed, maybe it's just RCS keyword woes. Look through
|
# Patch failed, maybe it's just RCS keyword woes. Look through
|
||||||
# the patch to see if that's possible.
|
# the patch to see if that's possible.
|
||||||
if gitConfig("git-p4.attemptRCSCleanup","--bool") == "true":
|
if gitConfigBool("git-p4.attemptRCSCleanup"):
|
||||||
file = None
|
file = None
|
||||||
pattern = None
|
pattern = None
|
||||||
kwfiles = {}
|
kwfiles = {}
|
||||||
@ -1574,7 +1581,7 @@ class P4Submit(Command, P4UserMap):
|
|||||||
sys.exit(128)
|
sys.exit(128)
|
||||||
|
|
||||||
self.useClientSpec = False
|
self.useClientSpec = False
|
||||||
if gitConfig("git-p4.useclientspec", "--bool") == "true":
|
if gitConfigBool("git-p4.useclientspec"):
|
||||||
self.useClientSpec = True
|
self.useClientSpec = True
|
||||||
if self.useClientSpec:
|
if self.useClientSpec:
|
||||||
self.clientSpecDirs = getClientSpec()
|
self.clientSpecDirs = getClientSpec()
|
||||||
@ -1614,7 +1621,7 @@ class P4Submit(Command, P4UserMap):
|
|||||||
commits.append(line.strip())
|
commits.append(line.strip())
|
||||||
commits.reverse()
|
commits.reverse()
|
||||||
|
|
||||||
if self.preserveUser or (gitConfig("git-p4.skipUserNameCheck") == "true"):
|
if self.preserveUser or gitConfigBool("git-p4.skipUserNameCheck"):
|
||||||
self.checkAuthorship = False
|
self.checkAuthorship = False
|
||||||
else:
|
else:
|
||||||
self.checkAuthorship = True
|
self.checkAuthorship = True
|
||||||
@ -1650,7 +1657,7 @@ class P4Submit(Command, P4UserMap):
|
|||||||
else:
|
else:
|
||||||
self.diffOpts += " -C%s" % detectCopies
|
self.diffOpts += " -C%s" % detectCopies
|
||||||
|
|
||||||
if gitConfig("git-p4.detectCopiesHarder", "--bool") == "true":
|
if gitConfigBool("git-p4.detectCopiesHarder"):
|
||||||
self.diffOpts += " --find-copies-harder"
|
self.diffOpts += " --find-copies-harder"
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -1734,7 +1741,7 @@ class P4Submit(Command, P4UserMap):
|
|||||||
"--format=format:%h %s", c])
|
"--format=format:%h %s", c])
|
||||||
print "You will have to do 'git p4 sync' and rebase."
|
print "You will have to do 'git p4 sync' and rebase."
|
||||||
|
|
||||||
if gitConfig("git-p4.exportLabels", "--bool") == "true":
|
if gitConfigBool("git-p4.exportLabels"):
|
||||||
self.exportLabels = True
|
self.exportLabels = True
|
||||||
|
|
||||||
if self.exportLabels:
|
if self.exportLabels:
|
||||||
@ -2834,7 +2841,7 @@ class P4Sync(Command, P4UserMap):
|
|||||||
# will use this after clone to set the variable
|
# will use this after clone to set the variable
|
||||||
self.useClientSpec_from_options = True
|
self.useClientSpec_from_options = True
|
||||||
else:
|
else:
|
||||||
if gitConfig("git-p4.useclientspec", "--bool") == "true":
|
if gitConfigBool("git-p4.useclientspec"):
|
||||||
self.useClientSpec = True
|
self.useClientSpec = True
|
||||||
if self.useClientSpec:
|
if self.useClientSpec:
|
||||||
self.clientSpecDirs = getClientSpec()
|
self.clientSpecDirs = getClientSpec()
|
||||||
@ -3074,7 +3081,7 @@ class P4Sync(Command, P4UserMap):
|
|||||||
sys.stdout.write("%s " % b)
|
sys.stdout.write("%s " % b)
|
||||||
sys.stdout.write("\n")
|
sys.stdout.write("\n")
|
||||||
|
|
||||||
if gitConfig("git-p4.importLabels", "--bool") == "true":
|
if gitConfigBool("git-p4.importLabels"):
|
||||||
self.importLabels = True
|
self.importLabels = True
|
||||||
|
|
||||||
if self.importLabels:
|
if self.importLabels:
|
||||||
|
Loading…
Reference in New Issue
Block a user