Improve codereview.settings file lookup.

Remove unnecessary os.listdir call and fix infinite loop on Windows if
no file was found in a tree.

Change-Id: I82a8763e807bbc0ce6fcae6b35a370ffe3b34943
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3687234
Reviewed-by: Josip Sokcevic <sokcevic@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Auto-Submit: Aleksey Khoroshilov <akhoroshilov@brave.com>
changes/34/3687234/2
Aleksey Khoroshilov 3 years ago committed by LUCI CQ
parent 8f1fea025d
commit 2a229719c2

@ -3003,14 +3003,18 @@ def FindCodereviewSettingsFile(filename='codereview.settings'):
cwd = os.getcwd()
root = settings.GetRoot()
if os.path.isfile(os.path.join(root, inherit_ok_file)):
root = '/'
root = None
while True:
if filename in os.listdir(cwd):
if os.path.isfile(os.path.join(cwd, filename)):
return open(os.path.join(cwd, filename))
if os.path.isfile(os.path.join(cwd, filename)):
return open(os.path.join(cwd, filename))
if cwd == root:
break
cwd = os.path.dirname(cwd)
parent_dir = os.path.dirname(cwd)
if parent_dir == cwd:
# We hit the system root directory.
break
cwd = parent_dir
return None
def LoadCodereviewSettingsFromFile(fileobj):

Loading…
Cancel
Save