summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSylvain <sylvain.desodt@gmail.com>2023-08-19 23:21:49 +0200
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-09-10 19:24:56 +0000
commit25d6c7cc108bea4c81e124623bcf7f4b6832a914 (patch)
tree35fe26972cbeda47f37261ac8140eba8d03fa2fd
parentf19b310f15e03e92075e7409c9d7f0956acc007d (diff)
downloadgit-repo-25d6c7cc108bea4c81e124623bcf7f4b6832a914.tar.gz
manifest_xml: use a set instead of (sorted) list in projectsDiff
The logic in projectsDiff performs various operations which suggest that a set is more appropriate than a list: - membership lookup ("in") - removal Also, sorting can be performed on the the remaining elements at the end (which will usually involve a much smaller number of elements). (The performance gain is invisible in comparison to the time being spent performing git operations). Cosmetic chance: - the definition of 'fromProj' is moved to be used in more places - the values in diff["added"] are added with a single call to extend Change-Id: I5ed22ba73b50650ca2d3a49a1ae81f02be3b3055 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/383434 Tested-by: Sylvain Desodt <sylvain.desodt@gmail.com> Reviewed-by: Mike Frysinger <vapier@google.com> Commit-Queue: Sylvain Desodt <sylvain.desodt@gmail.com>
-rw-r--r--manifest_xml.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/manifest_xml.py b/manifest_xml.py
index d944b409..458dfb7d 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -2210,7 +2210,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
2210 toProjects = manifest.paths 2210 toProjects = manifest.paths
2211 2211
2212 fromKeys = sorted(fromProjects.keys()) 2212 fromKeys = sorted(fromProjects.keys())
2213 toKeys = sorted(toProjects.keys()) 2213 toKeys = set(toProjects.keys())
2214 2214
2215 diff = { 2215 diff = {
2216 "added": [], 2216 "added": [],
@@ -2221,13 +2221,13 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
2221 } 2221 }
2222 2222
2223 for proj in fromKeys: 2223 for proj in fromKeys:
2224 fromProj = fromProjects[proj]
2224 if proj not in toKeys: 2225 if proj not in toKeys:
2225 diff["removed"].append(fromProjects[proj]) 2226 diff["removed"].append(fromProj)
2226 elif not fromProjects[proj].Exists: 2227 elif not fromProj.Exists:
2227 diff["missing"].append(toProjects[proj]) 2228 diff["missing"].append(toProjects[proj])
2228 toKeys.remove(proj) 2229 toKeys.remove(proj)
2229 else: 2230 else:
2230 fromProj = fromProjects[proj]
2231 toProj = toProjects[proj] 2231 toProj = toProjects[proj]
2232 try: 2232 try:
2233 fromRevId = fromProj.GetCommitRevisionId() 2233 fromRevId = fromProj.GetCommitRevisionId()
@@ -2239,8 +2239,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
2239 diff["changed"].append((fromProj, toProj)) 2239 diff["changed"].append((fromProj, toProj))
2240 toKeys.remove(proj) 2240 toKeys.remove(proj)
2241 2241
2242 for proj in toKeys: 2242 diff["added"].extend(toProjects[proj] for proj in sorted(toKeys))
2243 diff["added"].append(toProjects[proj])
2244 2243
2245 return diff 2244 return diff
2246 2245