1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-21 12:46:09 +02:00

git-p4: python3: replace dict.has_key(k) with "k in dict"

Python3 does not have the dict.has_key() function, so replace all
such calls with "k in dict". This will still work with python2.6
and python2.7.

Converted using 2to3 (plus some hand-editing)

Signed-off-by: Luke Diamand <luke@diamand.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Luke Diamand 2018-06-19 09:04:07 +01:00 committed by Junio C Hamano
parent fc35c9d5dc
commit dba1c9d9f2

View File

@ -767,7 +767,7 @@ def gitDeleteRef(ref):
_gitConfig = {} _gitConfig = {}
def gitConfig(key, typeSpecifier=None): def gitConfig(key, typeSpecifier=None):
if not _gitConfig.has_key(key): if key not in _gitConfig:
cmd = [ "git", "config" ] cmd = [ "git", "config" ]
if typeSpecifier: if typeSpecifier:
cmd += [ typeSpecifier ] cmd += [ typeSpecifier ]
@ -781,12 +781,12 @@ def gitConfigBool(key):
variable is set to true, and False if set to false or not present variable is set to true, and False if set to false or not present
in the config.""" in the config."""
if not _gitConfig.has_key(key): if key not in _gitConfig:
_gitConfig[key] = gitConfig(key, '--bool') == "true" _gitConfig[key] = gitConfig(key, '--bool') == "true"
return _gitConfig[key] return _gitConfig[key]
def gitConfigInt(key): def gitConfigInt(key):
if not _gitConfig.has_key(key): if key not in _gitConfig:
cmd = [ "git", "config", "--int", key ] cmd = [ "git", "config", "--int", key ]
s = read_pipe(cmd, ignore_error=True) s = read_pipe(cmd, ignore_error=True)
v = s.strip() v = s.strip()
@ -797,7 +797,7 @@ def gitConfigInt(key):
return _gitConfig[key] return _gitConfig[key]
def gitConfigList(key): def gitConfigList(key):
if not _gitConfig.has_key(key): if key not in _gitConfig:
s = read_pipe(["git", "config", "--get-all", key], ignore_error=True) s = read_pipe(["git", "config", "--get-all", key], ignore_error=True)
_gitConfig[key] = s.strip().splitlines() _gitConfig[key] = s.strip().splitlines()
if _gitConfig[key] == ['']: if _gitConfig[key] == ['']:
@ -855,7 +855,7 @@ def findUpstreamBranchPoint(head = "HEAD"):
tip = branches[branch] tip = branches[branch]
log = extractLogMessageFromGitCommit(tip) log = extractLogMessageFromGitCommit(tip)
settings = extractSettingsGitLog(log) settings = extractSettingsGitLog(log)
if settings.has_key("depot-paths"): if "depot-paths" in settings:
paths = ",".join(settings["depot-paths"]) paths = ",".join(settings["depot-paths"])
branchByDepotPath[paths] = "remotes/p4/" + branch branchByDepotPath[paths] = "remotes/p4/" + branch
@ -865,9 +865,9 @@ def findUpstreamBranchPoint(head = "HEAD"):
commit = head + "~%s" % parent commit = head + "~%s" % parent
log = extractLogMessageFromGitCommit(commit) log = extractLogMessageFromGitCommit(commit)
settings = extractSettingsGitLog(log) settings = extractSettingsGitLog(log)
if settings.has_key("depot-paths"): if "depot-paths" in settings:
paths = ",".join(settings["depot-paths"]) paths = ",".join(settings["depot-paths"])
if branchByDepotPath.has_key(paths): if paths in branchByDepotPath:
return [branchByDepotPath[paths], settings] return [branchByDepotPath[paths], settings]
parent = parent + 1 parent = parent + 1
@ -891,8 +891,8 @@ def createOrUpdateBranchesFromOrigin(localRefPrefix = "refs/remotes/p4/", silent
originHead = line originHead = line
original = extractSettingsGitLog(extractLogMessageFromGitCommit(originHead)) original = extractSettingsGitLog(extractLogMessageFromGitCommit(originHead))
if (not original.has_key('depot-paths') if ('depot-paths' not in original
or not original.has_key('change')): or 'change' not in original):
continue continue
update = False update = False
@ -902,7 +902,7 @@ def createOrUpdateBranchesFromOrigin(localRefPrefix = "refs/remotes/p4/", silent
update = True update = True
else: else:
settings = extractSettingsGitLog(extractLogMessageFromGitCommit(remoteHead)) settings = extractSettingsGitLog(extractLogMessageFromGitCommit(remoteHead))
if settings.has_key('change') > 0: if 'change' in settings:
if settings['depot-paths'] == original['depot-paths']: if settings['depot-paths'] == original['depot-paths']:
originP4Change = int(original['change']) originP4Change = int(original['change'])
p4Change = int(settings['change']) p4Change = int(settings['change'])
@ -1002,7 +1002,7 @@ def p4ChangesForPaths(depotPaths, changeRange, requestedBlockSize):
# Insert changes in chronological order # Insert changes in chronological order
for entry in reversed(result): for entry in reversed(result):
if not entry.has_key('change'): if 'change' not in entry:
continue continue
changes.add(int(entry['change'])) changes.add(int(entry['change']))
@ -1312,7 +1312,7 @@ def p4UserId(self):
results = p4CmdList("user -o") results = p4CmdList("user -o")
for r in results: for r in results:
if r.has_key('User'): if 'User' in r:
self.myP4UserId = r['User'] self.myP4UserId = r['User']
return r['User'] return r['User']
die("Could not find your p4 user id") die("Could not find your p4 user id")
@ -1336,7 +1336,7 @@ def getUserMapFromPerforceServer(self):
self.emails = {} self.emails = {}
for output in p4CmdList("users"): for output in p4CmdList("users"):
if not output.has_key("User"): if "User" not in output:
continue continue
self.users[output["User"]] = output["FullName"] + " <" + output["Email"] + ">" self.users[output["User"]] = output["FullName"] + " <" + output["Email"] + ">"
self.emails[output["Email"]] = output["User"] self.emails[output["Email"]] = output["User"]
@ -1588,7 +1588,7 @@ def p4UserForCommit(self,id):
gitEmail = read_pipe(["git", "log", "--max-count=1", gitEmail = read_pipe(["git", "log", "--max-count=1",
"--format=%ae", id]) "--format=%ae", id])
gitEmail = gitEmail.strip() gitEmail = gitEmail.strip()
if not self.emails.has_key(gitEmail): if gitEmail not in self.emails:
return (None,gitEmail) return (None,gitEmail)
else: else:
return (self.emails[gitEmail],gitEmail) return (self.emails[gitEmail],gitEmail)
@ -1612,14 +1612,14 @@ def lastP4Changelist(self):
results = p4CmdList("client -o") # find the current client results = p4CmdList("client -o") # find the current client
client = None client = None
for r in results: for r in results:
if r.has_key('Client'): if 'Client' in r:
client = r['Client'] client = r['Client']
break break
if not client: if not client:
die("could not get client spec") die("could not get client spec")
results = p4CmdList(["changes", "-c", client, "-m", "1"]) results = p4CmdList(["changes", "-c", client, "-m", "1"])
for r in results: for r in results:
if r.has_key('change'): if 'change' in r:
return r['change'] return r['change']
die("Could not get changelist number for last submit - cannot patch up user details") die("Could not get changelist number for last submit - cannot patch up user details")
@ -1637,10 +1637,10 @@ def modifyChangelistUser(self, changelist, newUser):
result = p4CmdList("change -f -i", stdin=input) result = p4CmdList("change -f -i", stdin=input)
for r in result: for r in result:
if r.has_key('code'): if 'code' in r:
if r['code'] == 'error': if r['code'] == 'error':
die("Could not modify user field of changelist %s to %s:%s" % (changelist, newUser, r['data'])) die("Could not modify user field of changelist %s to %s:%s" % (changelist, newUser, r['data']))
if r.has_key('data'): if 'data' in r:
print("Updated user field for changelist %s to %s" % (changelist, newUser)) print("Updated user field for changelist %s to %s" % (changelist, newUser))
return return
die("Could not modify user field of changelist %s to %s" % (changelist, newUser)) die("Could not modify user field of changelist %s to %s" % (changelist, newUser))
@ -1650,7 +1650,7 @@ def canChangeChangelists(self):
# which are required to modify changelists. # which are required to modify changelists.
results = p4CmdList(["protects", self.depotPath]) results = p4CmdList(["protects", self.depotPath])
for r in results: for r in results:
if r.has_key('perm'): if 'perm' in r:
if r['perm'] == 'admin': if r['perm'] == 'admin':
return 1 return 1
if r['perm'] == 'super': if r['perm'] == 'super':
@ -1690,7 +1690,7 @@ def prepareSubmitTemplate(self, changelist=None):
if changelist: if changelist:
args.append(str(changelist)) args.append(str(changelist))
for entry in p4CmdList(args): for entry in p4CmdList(args):
if not entry.has_key('code'): if 'code' not in entry:
continue continue
if entry['code'] == 'stat': if entry['code'] == 'stat':
change_entry = entry change_entry = entry
@ -1699,7 +1699,7 @@ def prepareSubmitTemplate(self, changelist=None):
die('Failed to decode output of p4 change -o') die('Failed to decode output of p4 change -o')
for key, value in change_entry.iteritems(): for key, value in change_entry.iteritems():
if key.startswith('File'): if key.startswith('File'):
if settings.has_key('depot-paths'): if 'depot-paths' in settings:
if not [p for p in settings['depot-paths'] if not [p for p in settings['depot-paths']
if p4PathStartsWith(value, p)]: if p4PathStartsWith(value, p)]:
continue continue
@ -1710,7 +1710,7 @@ def prepareSubmitTemplate(self, changelist=None):
continue continue
# Output in the order expected by prepareLogMessage # Output in the order expected by prepareLogMessage
for key in ['Change', 'Client', 'User', 'Status', 'Description', 'Jobs']: for key in ['Change', 'Client', 'User', 'Status', 'Description', 'Jobs']:
if not change_entry.has_key(key): if key not in change_entry:
continue continue
template += '\n' template += '\n'
template += key + ':' template += key + ':'
@ -1738,7 +1738,7 @@ def edit_template(self, template_file):
mtime = os.stat(template_file).st_mtime mtime = os.stat(template_file).st_mtime
# invoke the editor # invoke the editor
if os.environ.has_key("P4EDITOR") and (os.environ.get("P4EDITOR") != ""): if "P4EDITOR" in os.environ and (os.environ.get("P4EDITOR") != ""):
editor = os.environ.get("P4EDITOR") editor = os.environ.get("P4EDITOR")
else: else:
editor = read_pipe("git var GIT_EDITOR").strip() editor = read_pipe("git var GIT_EDITOR").strip()
@ -1762,7 +1762,7 @@ def edit_template(self, template_file):
def get_diff_description(self, editedFiles, filesToAdd, symlinks): def get_diff_description(self, editedFiles, filesToAdd, symlinks):
# diff # diff
if os.environ.has_key("P4DIFF"): if "P4DIFF" in os.environ:
del(os.environ["P4DIFF"]) del(os.environ["P4DIFF"])
diff = "" diff = ""
for editedFile in editedFiles: for editedFile in editedFiles:
@ -2085,7 +2085,7 @@ def exportGitTags(self, gitTags):
logMessage = extractLogMessageFromGitCommit(name) logMessage = extractLogMessageFromGitCommit(name)
values = extractSettingsGitLog(logMessage) values = extractSettingsGitLog(logMessage)
if not values.has_key('change'): if 'change' not in values:
# a tag pointing to something not sent to p4; ignore # a tag pointing to something not sent to p4; ignore
if verbose: if verbose:
print "git tag %s does not give a p4 commit" % name print "git tag %s does not give a p4 commit" % name
@ -2600,7 +2600,7 @@ def extractFilesFromCommit(self, commit, shelved=False, shelved_cl = 0, origin_r
for path in self.cloneExclude] for path in self.cloneExclude]
files = [] files = []
fnum = 0 fnum = 0
while commit.has_key("depotFile%s" % fnum): while "depotFile%s" % fnum in commit:
path = commit["depotFile%s" % fnum] path = commit["depotFile%s" % fnum]
if [p for p in self.cloneExclude if [p for p in self.cloneExclude
@ -2638,7 +2638,7 @@ def extractFilesFromCommit(self, commit, shelved=False, shelved_cl = 0, origin_r
def extractJobsFromCommit(self, commit): def extractJobsFromCommit(self, commit):
jobs = [] jobs = []
jnum = 0 jnum = 0
while commit.has_key("job%s" % jnum): while "job%s" % jnum in commit:
job = commit["job%s" % jnum] job = commit["job%s" % jnum]
jobs.append(job) jobs.append(job)
jnum = jnum + 1 jnum = jnum + 1
@ -2686,7 +2686,7 @@ def splitFilesIntoBranches(self, commit):
branches = {} branches = {}
fnum = 0 fnum = 0
while commit.has_key("depotFile%s" % fnum): while "depotFile%s" % fnum in commit:
path = commit["depotFile%s" % fnum] path = commit["depotFile%s" % fnum]
found = [p for p in self.depotPaths found = [p for p in self.depotPaths
if p4PathStartsWith(path, p)] if p4PathStartsWith(path, p)]
@ -2866,7 +2866,7 @@ def streamP4FilesCb(self, marshalled):
else: else:
die("Error from p4 print: %s" % err) die("Error from p4 print: %s" % err)
if marshalled.has_key('depotFile') and self.stream_have_file_info: if 'depotFile' in marshalled and self.stream_have_file_info:
# start of a new file - output the old one first # start of a new file - output the old one first
self.streamOneP4File(self.stream_file, self.stream_contents) self.streamOneP4File(self.stream_file, self.stream_contents)
self.stream_file = {} self.stream_file = {}
@ -2938,7 +2938,7 @@ def streamP4FilesCbSelf(entry):
cb=streamP4FilesCbSelf) cb=streamP4FilesCbSelf)
# do the last chunk # do the last chunk
if self.stream_file.has_key('depotFile'): if 'depotFile' in self.stream_file:
self.streamOneP4File(self.stream_file, self.stream_contents) self.streamOneP4File(self.stream_file, self.stream_contents)
def make_email(self, userid): def make_email(self, userid):
@ -2957,7 +2957,7 @@ def streamTag(self, gitStream, labelName, labelDetails, commit, epoch):
gitStream.write("tag %s\n" % labelName) gitStream.write("tag %s\n" % labelName)
gitStream.write("from %s\n" % commit) gitStream.write("from %s\n" % commit)
if labelDetails.has_key('Owner'): if 'Owner' in labelDetails:
owner = labelDetails["Owner"] owner = labelDetails["Owner"]
else: else:
owner = None owner = None
@ -2973,7 +2973,7 @@ def streamTag(self, gitStream, labelName, labelDetails, commit, epoch):
gitStream.write("tagger %s\n" % tagger) gitStream.write("tagger %s\n" % tagger)
print "labelDetails=",labelDetails print "labelDetails=",labelDetails
if labelDetails.has_key('Description'): if 'Description' in labelDetails:
description = labelDetails['Description'] description = labelDetails['Description']
else: else:
description = 'Label from git p4' description = 'Label from git p4'
@ -3052,7 +3052,7 @@ def commit(self, details, files, branch, parent = ""):
change = int(details["change"]) change = int(details["change"])
if self.labels.has_key(change): if change in self.labels:
label = self.labels[change] label = self.labels[change]
labelDetails = label[0] labelDetails = label[0]
labelRevisions = label[1] labelRevisions = label[1]
@ -3141,7 +3141,7 @@ def importP4Labels(self, stream, p4Labels):
change = p4Cmd(["changes", "-m", "1"] + ["%s...@%s" % (p, name) change = p4Cmd(["changes", "-m", "1"] + ["%s...@%s" % (p, name)
for p in self.depotPaths]) for p in self.depotPaths])
if change.has_key('change'): if 'change' in change:
# find the corresponding git commit; take the oldest commit # find the corresponding git commit; take the oldest commit
changelist = int(change['change']) changelist = int(change['change'])
if changelist in self.committedChanges: if changelist in self.committedChanges:
@ -3200,7 +3200,7 @@ def getBranchMapping(self):
for info in p4CmdList(command): for info in p4CmdList(command):
details = p4Cmd(["branch", "-o", info["branch"]]) details = p4Cmd(["branch", "-o", info["branch"]])
viewIdx = 0 viewIdx = 0
while details.has_key("View%s" % viewIdx): while "View%s" % viewIdx in details:
paths = details["View%s" % viewIdx].split(" ") paths = details["View%s" % viewIdx].split(" ")
viewIdx = viewIdx + 1 viewIdx = viewIdx + 1
# require standard //depot/foo/... //depot/bar/... mapping # require standard //depot/foo/... //depot/bar/... mapping
@ -3266,7 +3266,7 @@ def updateOptionDict(self, d):
d["options"] = ' '.join(sorted(option_keys.keys())) d["options"] = ' '.join(sorted(option_keys.keys()))
def readOptions(self, d): def readOptions(self, d):
self.keepRepoPath = (d.has_key('options') self.keepRepoPath = ('options' in d
and ('keepRepoPath' in d['options'])) and ('keepRepoPath' in d['options']))
def gitRefForBranch(self, branch): def gitRefForBranch(self, branch):
@ -3576,8 +3576,8 @@ def run(self, args):
settings = extractSettingsGitLog(logMsg) settings = extractSettingsGitLog(logMsg)
self.readOptions(settings) self.readOptions(settings)
if (settings.has_key('depot-paths') if ('depot-paths' in settings
and settings.has_key ('change')): and 'change' in settings):
change = int(settings['change']) + 1 change = int(settings['change']) + 1
p4Change = max(p4Change, change) p4Change = max(p4Change, change)
@ -3950,7 +3950,7 @@ def findLastP4Revision(self, starting_point):
for parent in (range(65535)): for parent in (range(65535)):
log = extractLogMessageFromGitCommit("{0}^{1}".format(starting_point, parent)) log = extractLogMessageFromGitCommit("{0}^{1}".format(starting_point, parent))
settings = extractSettingsGitLog(log) settings = extractSettingsGitLog(log)
if settings.has_key('change'): if 'change' in settings:
return settings return settings
sys.exit("could not find git-p4 commits in {0}".format(self.origin)) sys.exit("could not find git-p4 commits in {0}".format(self.origin))