Skip to content

Commit

Permalink
mozautomation: match built URIs exactly in resolve_uri_to_tree (Bug…
Browse files Browse the repository at this point in the history
… 1768982) r=zeid

`resolve_uri_to_tree` takes a URI (ie `https://hg.mozilla.org/mozilla-central`)
and attempts to resolve it to a known Firefox tree shortname (ie `central`).
It does so by iterating through the list of known Firefox tree repo names and
building out each potential URI, and then checking if each built URI matches
the passed URI. The matching condition used is `uri.startswith`, assumedly
so something like `https://hg.mozilla.org/mozilla-centra` or some other minor
typo results in a match still being found. This has worked without any issue to
date, until `esr102` was created. Since the built URIs for esr10 would match
the `startswith` metric on `esr102`, passing the URI for esr102 is returning
`esr10` as the resolved tree.

Switch `resolve_uri_to_tree` to return the resolved tree only when the built
URI exactly matches the passed URI. Add a few comments clarifying what the
function is doing and use more descriptive variable names.

Differential Revision: https://phabricator.services.mozilla.com/D146210

--HG--
extra : moz-landing-system : lando
  • Loading branch information
cgsheeh committed May 12, 2022
1 parent 45e2b6d commit 98be088
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pylib/mozautomation/mozautomation/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,24 @@ def resolve_trees_to_uris(trees, write_access=False):

def resolve_uri_to_tree(uri):
"""Try to resolve a URI back to a known tree."""
# Account for a trailing `/`.
if uri.endswith(b'/'):
uri = uri[:-1]

for tree, path in REPOS.items():
if uri.startswith(b'%s%s' % (BASE_READ_URI, path)):
# Try `https` URI first.
read_url_https = b'%s%s' % (BASE_READ_URI, path)
if uri == read_url_https:
return tree

if uri.startswith(b'%s%s' % (
BASE_READ_URI.replace(b'https://', b'http://'),
path)):
# Try `http` URI next.
read_url_http = read_url_https.replace(b'https://', b'http://')
if uri == read_url_http:
return tree

if uri.startswith(b'%s%s' % (BASE_WRITE_URI, path)):
# Try `ssh` URI last.
write_url_ssh = b'%s%s' % (BASE_WRITE_URI, path)
if uri == write_url_ssh:
return tree

return None
Expand Down

0 comments on commit 98be088

Please sign in to comment.