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>
Luke Diamand committed
Jun 19, 2018 at 09:04 UTC
dba1c9d9f26ac9fce55d0bfde8a040700fc9ff52
1 file changed
+39
-39
git-p4.py
+39
-39
@@ -767,7 +767,7 @@ def gitDeleteRef(ref):
767
_gitConfig = {}
768
769
def gitConfig(key, typeSpecifier=None):
770
- if not _gitConfig.has_key(key):
770
+ if key not in _gitConfig:
771
cmd = [ "git", "config" ]
772
if typeSpecifier:
773
cmd += [ typeSpecifier ]
@@ -781,12 +781,12 @@ def gitConfigBool(key):
781
variable is set to true, and False if set to false or not present
782
in the config."""
783
784
- if not _gitConfig.has_key(key):
784
+ if key not in _gitConfig:
785
_gitConfig[key] = gitConfig(key, '--bool') == "true"
786
return _gitConfig[key]
787
788
def gitConfigInt(key):
789
- if not _gitConfig.has_key(key):
789
+ if key not in _gitConfig:
790
cmd = [ "git", "config", "--int", key ]
791
s = read_pipe(cmd, ignore_error=True)
792
v = s.strip()
@@ -797,7 +797,7 @@ def gitConfigInt(key):
797
return _gitConfig[key]
798
799
def gitConfigList(key):
800
- if not _gitConfig.has_key(key):
800
+ if key not in _gitConfig:
801
s = read_pipe(["git", "config", "--get-all", key], ignore_error=True)
802
_gitConfig[key] = s.strip().splitlines()
803
if _gitConfig[key] == ['']:
@@ -855,7 +855,7 @@ def findUpstreamBranchPoint(head = "HEAD"):
855
tip = branches[branch]
856
log = extractLogMessageFromGitCommit(tip)
857
settings = extractSettingsGitLog(log)
858
- if settings.has_key("depot-paths"):
858
+ if "depot-paths" in settings:
859
paths = ",".join(settings["depot-paths"])
860
branchByDepotPath[paths] = "remotes/p4/" + branch
861
@@ -865,9 +865,9 @@ def findUpstreamBranchPoint(head = "HEAD"):
865
commit = head + "~%s" % parent
866
log = extractLogMessageFromGitCommit(commit)
867
settings = extractSettingsGitLog(log)
868
- if settings.has_key("depot-paths"):
868
+ if "depot-paths" in settings:
869
paths = ",".join(settings["depot-paths"])
870
- if branchByDepotPath.has_key(paths):
870
+ if paths in branchByDepotPath:
871
return [branchByDepotPath[paths], settings]
872
873
parent = parent + 1
@@ -891,8 +891,8 @@ def createOrUpdateBranchesFromOrigin(localRefPrefix = "refs/remotes/p4/", silent
891
originHead = line
892
893
original = extractSettingsGitLog(extractLogMessageFromGitCommit(originHead))
894
- if (not original.has_key('depot-paths')
895
- or not original.has_key('change')):
894
+ if ('depot-paths' not in original
895
+ or 'change' not in original):
896
continue
897
898
update = False
@@ -902,7 +902,7 @@ def createOrUpdateBranchesFromOrigin(localRefPrefix = "refs/remotes/p4/", silent
902
update = True
903
else:
904
settings = extractSettingsGitLog(extractLogMessageFromGitCommit(remoteHead))
905
- if settings.has_key('change') > 0:
905
+ if 'change' in settings:
906
if settings['depot-paths'] == original['depot-paths']:
907
originP4Change = int(original['change'])
908
p4Change = int(settings['change'])
@@ -1002,7 +1002,7 @@ def p4ChangesForPaths(depotPaths, changeRange, requestedBlockSize):
1002
1003
# Insert changes in chronological order
1004
for entry in reversed(result):
1005
- if not entry.has_key('change'):
1005
+ if 'change' not in entry:
1006
continue
1007
changes.add(int(entry['change']))
1008
@@ -1312,7 +1312,7 @@ class P4UserMap:
1312
1313
results = p4CmdList("user -o")
1314
for r in results:
1315
- if r.has_key('User'):
1315
+ if 'User' in r:
1316
self.myP4UserId = r['User']
1317
return r['User']
1318
die("Could not find your p4 user id")
@@ -1336,7 +1336,7 @@ class P4UserMap:
1336
self.emails = {}
1337
1338
for output in p4CmdList("users"):
1339
- if not output.has_key("User"):
1339
+ if "User" not in output:
1340
continue
1341
self.users[output["User"]] = output["FullName"] + " <" + output["Email"] + ">"
1342
self.emails[output["Email"]] = output["User"]
@@ -1588,7 +1588,7 @@ class P4Submit(Command, P4UserMap):
1588
gitEmail = read_pipe(["git", "log", "--max-count=1",
1589
"--format=%ae", id])
1590
gitEmail = gitEmail.strip()
1591
- if not self.emails.has_key(gitEmail):
1591
+ if gitEmail not in self.emails:
1592
return (None,gitEmail)
1593
else:
1594
return (self.emails[gitEmail],gitEmail)
@@ -1612,14 +1612,14 @@ class P4Submit(Command, P4UserMap):
1612
results = p4CmdList("client -o") # find the current client
1613
client = None
1614
for r in results:
1615
- if r.has_key('Client'):
1615
+ if 'Client' in r:
1616
client = r['Client']
1617
break
1618
if not client:
1619
die("could not get client spec")
1620
results = p4CmdList(["changes", "-c", client, "-m", "1"])
1621
for r in results:
1622
- if r.has_key('change'):
1622
+ if 'change' in r:
1623
return r['change']
1624
die("Could not get changelist number for last submit - cannot patch up user details")
1625
@@ -1637,10 +1637,10 @@ class P4Submit(Command, P4UserMap):
1637
1638
result = p4CmdList("change -f -i", stdin=input)
1639
for r in result:
1640
- if r.has_key('code'):
1640
+ if 'code' in r:
1641
if r['code'] == 'error':
1642
die("Could not modify user field of changelist %s to %s:%s" % (changelist, newUser, r['data']))
1643
- if r.has_key('data'):
1643
+ if 'data' in r:
1644
print("Updated user field for changelist %s to %s" % (changelist, newUser))
1645
return
1646
die("Could not modify user field of changelist %s to %s" % (changelist, newUser))
@@ -1650,7 +1650,7 @@ class P4Submit(Command, P4UserMap):
1650
# which are required to modify changelists.
1651
results = p4CmdList(["protects", self.depotPath])
1652
for r in results:
1653
- if r.has_key('perm'):
1653
+ if 'perm' in r:
1654
if r['perm'] == 'admin':
1655
return 1
1656
if r['perm'] == 'super':
@@ -1690,7 +1690,7 @@ class P4Submit(Command, P4UserMap):
1690
if changelist:
1691
args.append(str(changelist))
1692
for entry in p4CmdList(args):
1693
- if not entry.has_key('code'):
1693
+ if 'code' not in entry:
1694
continue
1695
if entry['code'] == 'stat':
1696
change_entry = entry
@@ -1699,7 +1699,7 @@ class P4Submit(Command, P4UserMap):
1699
die('Failed to decode output of p4 change -o')
1700
for key, value in change_entry.iteritems():
1701
if key.startswith('File'):
1702
- if settings.has_key('depot-paths'):
1702
+ if 'depot-paths' in settings:
1703
if not [p for p in settings['depot-paths']
1704
if p4PathStartsWith(value, p)]:
1705
continue
@@ -1710,7 +1710,7 @@ class P4Submit(Command, P4UserMap):
1710
continue
1711
# Output in the order expected by prepareLogMessage
1712
for key in ['Change', 'Client', 'User', 'Status', 'Description', 'Jobs']:
1713
- if not change_entry.has_key(key):
1713
+ if key not in change_entry:
1714
continue
1715
template += '\n'
1716
template += key + ':'
@@ -1738,7 +1738,7 @@ class P4Submit(Command, P4UserMap):
1738
mtime = os.stat(template_file).st_mtime
1739
1740
# invoke the editor
1741
- if os.environ.has_key("P4EDITOR") and (os.environ.get("P4EDITOR") != ""):
1741
+ if "P4EDITOR" in os.environ and (os.environ.get("P4EDITOR") != ""):
1742
editor = os.environ.get("P4EDITOR")
1743
else:
1744
editor = read_pipe("git var GIT_EDITOR").strip()
@@ -1762,7 +1762,7 @@ class P4Submit(Command, P4UserMap):
1762
1763
def get_diff_description(self, editedFiles, filesToAdd, symlinks):
1764
# diff
1765
- if os.environ.has_key("P4DIFF"):
1765
+ if "P4DIFF" in os.environ:
1766
del(os.environ["P4DIFF"])
1767
diff = ""
1768
for editedFile in editedFiles:
@@ -2085,7 +2085,7 @@ class P4Submit(Command, P4UserMap):
2085
logMessage = extractLogMessageFromGitCommit(name)
2086
values = extractSettingsGitLog(logMessage)
2087
2088
- if not values.has_key('change'):
2088
+ if 'change' not in values:
2089
# a tag pointing to something not sent to p4; ignore
2090
if verbose:
2091
print "git tag %s does not give a p4 commit" % name
@@ -2600,7 +2600,7 @@ class P4Sync(Command, P4UserMap):
2600
for path in self.cloneExclude]
2601
files = []
2602
fnum = 0
2603
- while commit.has_key("depotFile%s" % fnum):
2603
+ while "depotFile%s" % fnum in commit:
2604
path = commit["depotFile%s" % fnum]
2605
2606
if [p for p in self.cloneExclude
@@ -2638,7 +2638,7 @@ class P4Sync(Command, P4UserMap):
2638
def extractJobsFromCommit(self, commit):
2639
jobs = []
2640
jnum = 0
2641
- while commit.has_key("job%s" % jnum):
2641
+ while "job%s" % jnum in commit:
2642
job = commit["job%s" % jnum]
2643
jobs.append(job)
2644
jnum = jnum + 1
@@ -2686,7 +2686,7 @@ class P4Sync(Command, P4UserMap):
2686
2687
branches = {}
2688
fnum = 0
2689
- while commit.has_key("depotFile%s" % fnum):
2689
+ while "depotFile%s" % fnum in commit:
2690
path = commit["depotFile%s" % fnum]
2691
found = [p for p in self.depotPaths
2692
if p4PathStartsWith(path, p)]
@@ -2866,7 +2866,7 @@ class P4Sync(Command, P4UserMap):
2866
else:
2867
die("Error from p4 print: %s" % err)
2868
2869
- if marshalled.has_key('depotFile') and self.stream_have_file_info:
2869
+ if 'depotFile' in marshalled and self.stream_have_file_info:
2870
# start of a new file - output the old one first
2871
self.streamOneP4File(self.stream_file, self.stream_contents)
2872
self.stream_file = {}
@@ -2938,7 +2938,7 @@ class P4Sync(Command, P4UserMap):
2938
cb=streamP4FilesCbSelf)
2939
2940
# do the last chunk
2941
- if self.stream_file.has_key('depotFile'):
2941
+ if 'depotFile' in self.stream_file:
2942
self.streamOneP4File(self.stream_file, self.stream_contents)
2943
2944
def make_email(self, userid):
@@ -2957,7 +2957,7 @@ class P4Sync(Command, P4UserMap):
2957
gitStream.write("tag %s\n" % labelName)
2958
gitStream.write("from %s\n" % commit)
2959
2960
- if labelDetails.has_key('Owner'):
2960
+ if 'Owner' in labelDetails:
2961
owner = labelDetails["Owner"]
2962
else:
2963
owner = None
@@ -2973,7 +2973,7 @@ class P4Sync(Command, P4UserMap):
2973
gitStream.write("tagger %s\n" % tagger)
2974
2975
print "labelDetails=",labelDetails
2976
- if labelDetails.has_key('Description'):
2976
+ if 'Description' in labelDetails:
2977
description = labelDetails['Description']
2978
else:
2979
description = 'Label from git p4'
@@ -3052,7 +3052,7 @@ class P4Sync(Command, P4UserMap):
3052
3053
change = int(details["change"])
3054
3055
- if self.labels.has_key(change):
3055
+ if change in self.labels:
3056
label = self.labels[change]
3057
labelDetails = label[0]
3058
labelRevisions = label[1]
@@ -3141,7 +3141,7 @@ class P4Sync(Command, P4UserMap):
3141
change = p4Cmd(["changes", "-m", "1"] + ["%s...@%s" % (p, name)
3142
for p in self.depotPaths])
3143
3144
- if change.has_key('change'):
3144
+ if 'change' in change:
3145
# find the corresponding git commit; take the oldest commit
3146
changelist = int(change['change'])
3147
if changelist in self.committedChanges:
@@ -3200,7 +3200,7 @@ class P4Sync(Command, P4UserMap):
3200
for info in p4CmdList(command):
3201
details = p4Cmd(["branch", "-o", info["branch"]])
3202
viewIdx = 0
3203
- while details.has_key("View%s" % viewIdx):
3203
+ while "View%s" % viewIdx in details:
3204
paths = details["View%s" % viewIdx].split(" ")
3205
viewIdx = viewIdx + 1
3206
# require standard //depot/foo/... //depot/bar/... mapping
@@ -3266,7 +3266,7 @@ class P4Sync(Command, P4UserMap):
3266
d["options"] = ' '.join(sorted(option_keys.keys()))
3267
3268
def readOptions(self, d):
3269
- self.keepRepoPath = (d.has_key('options')
3269
+ self.keepRepoPath = ('options' in d
3270
and ('keepRepoPath' in d['options']))
3271
3272
def gitRefForBranch(self, branch):
@@ -3576,8 +3576,8 @@ class P4Sync(Command, P4UserMap):
3576
settings = extractSettingsGitLog(logMsg)
3577
3578
self.readOptions(settings)
3579
- if (settings.has_key('depot-paths')
3580
- and settings.has_key ('change')):
3579
+ if ('depot-paths' in settings
3580
+ and 'change' in settings):
3581
change = int(settings['change']) + 1
3582
p4Change = max(p4Change, change)
3583
@@ -3950,7 +3950,7 @@ class P4Unshelve(Command):
3950
for parent in (range(65535)):
3951
log = extractLogMessageFromGitCommit("{0}^{1}".format(starting_point, parent))
3952
settings = extractSettingsGitLog(log)
3953
- if settings.has_key('change'):
3953
+ if 'change' in settings:
3954
return settings
3955
3956
sys.exit("could not find git-p4 commits in {0}".format(self.origin))