Sfoglia il codice sorgente

[git_cl] Minor type annotation and initialization cleanup.

Noticed that the comments around lazily initialization on settings
mentioned that it does logging or something like this, but in fact
the __init__ method is purely vanilla.

R=gavinmak@google.com

Bug: 336351842
Change-Id: I9d8120001690b2bbd52ac2172d346ce95e2dddd3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5565083
Reviewed-by: Gavin Mak <gavinmak@google.com>
Auto-Submit: Robbie Iannucci <iannucci@chromium.org>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Robert Iannucci 1 anno fa
parent
commit
2f779d3061
2 ha cambiato i file con 9 aggiunte e 18 eliminazioni
  1. 8 17
      git_cl.py
  2. 1 1
      tests/git_cl_test.py

+ 8 - 17
git_cl.py

@@ -6,6 +6,8 @@
 # Copyright (C) 2008 Evan Martin <martine@danga.com>
 # Copyright (C) 2008 Evan Martin <martine@danga.com>
 """A git-command for integrating reviews on Gerrit."""
 """A git-command for integrating reviews on Gerrit."""
 
 
+from __future__ import annotations
+
 import base64
 import base64
 import collections
 import collections
 import datetime
 import datetime
@@ -140,9 +142,6 @@ LAST_UPLOAD_HASH_CONFIG_KEY = 'last-upload-hash'
 # Shortcut since it quickly becomes repetitive.
 # Shortcut since it quickly becomes repetitive.
 Fore = colorama.Fore
 Fore = colorama.Fore
 
 
-# Initialized in main()
-settings = None
-
 # Used by tests/git_cl_test.py to add extra logging.
 # Used by tests/git_cl_test.py to add extra logging.
 # Inside the weirdly failing test, add this:
 # Inside the weirdly failing test, add this:
 # >>> self.mock(git_cl, '_IS_BEING_TESTED', True)
 # >>> self.mock(git_cl, '_IS_BEING_TESTED', True)
@@ -942,6 +941,9 @@ class Settings(object):
         return scm.GIT.GetConfig(self.GetRoot(), key, default)
         return scm.GIT.GetConfig(self.GetRoot(), key, default)
 
 
 
 
+settings = Settings()
+
+
 class _CQState(object):
 class _CQState(object):
     """Enum for states of CL with respect to CQ."""
     """Enum for states of CL with respect to CQ."""
     NONE = 'none'
     NONE = 'none'
@@ -1312,13 +1314,6 @@ class Changelist(object):
 
 
         **kwargs will be passed directly to Gerrit implementation.
         **kwargs will be passed directly to Gerrit implementation.
         """
         """
-        # Poke settings so we get the "configure your server" message if
-        # necessary.
-        global settings
-        if not settings:
-            # Happens when git_cl.py is used as a utility library.
-            settings = Settings()
-
         self.branchref = branchref
         self.branchref = branchref
         if self.branchref:
         if self.branchref:
             assert (branchref.startswith(('refs/heads/', 'refs/branch-heads/'))
             assert (branchref.startswith(('refs/heads/', 'refs/branch-heads/'))
@@ -3920,7 +3915,9 @@ def color_for_status(status):
     }.get(status, Fore.WHITE)
     }.get(status, Fore.WHITE)
 
 
 
 
-def get_cl_statuses(changes, fine_grained, max_processes=None):
+def get_cl_statuses(changes: List[Changelist],
+                    fine_grained,
+                    max_processes=None):
     """Returns a blocking iterable of (cl, status) for given branches.
     """Returns a blocking iterable of (cl, status) for given branches.
 
 
     If fine_grained is true, this will fetch CL statuses from the server.
     If fine_grained is true, this will fetch CL statuses from the server.
@@ -6815,12 +6812,6 @@ class OptionParser(optparse.OptionParser):
         try:
         try:
             return self._parse_args(args)
             return self._parse_args(args)
         finally:
         finally:
-            # Regardless of success or failure of args parsing, we want to
-            # report metrics, but only after logging has been initialized (if
-            # parsing succeeded).
-            global settings
-            settings = Settings()
-
             if metrics.collector.config.should_collect_metrics:
             if metrics.collector.config.should_collect_metrics:
                 try:
                 try:
                     # GetViewVCUrl ultimately calls logging method.
                     # GetViewVCUrl ultimately calls logging method.

+ 1 - 1
tests/git_cl_test.py

@@ -673,7 +673,7 @@ class TestGitCl(unittest.TestCase):
         mock.patch('scm.GIT.CaptureStatus',
         mock.patch('scm.GIT.CaptureStatus',
                    return_value=[('M', 'foo.txt')]).start()
                    return_value=[('M', 'foo.txt')]).start()
         # It's important to reset settings to not have inter-tests interference.
         # It's important to reset settings to not have inter-tests interference.
-        git_cl.settings = None
+        git_cl.settings = git_cl.Settings()
         self.addCleanup(mock.patch.stopall)
         self.addCleanup(mock.patch.stopall)
 
 
     def tearDown(self):
     def tearDown(self):