Bug 1393242 - Helper function to obtain a repository from a build config; r?mshal draft
authorGregory Szorc <gps@mozilla.com>
Wed, 23 Aug 2017 15:03:36 -0700
changeset 657530 f67eb9c2fca1c26f6872e6dd1b985a345d3045df
parent 657500 34933f6390d52779ea498a6a5fd5f34d54734780
child 657531 b73a8ce2cb7b7aa7678e6423929c88168be12bdd
push id77552
push usergszorc@mozilla.com
push dateFri, 01 Sep 2017 16:20:16 +0000
reviewersmshal
bugs1393242
milestone57.0a1
Bug 1393242 - Helper function to obtain a repository from a build config; r?mshal Some callers already have a build config object. Let's not make them call a function that imports buildconfig. MozReview-Commit-ID: J22HhyVma9y
python/mozversioncontrol/mozversioncontrol/__init__.py
--- a/python/mozversioncontrol/mozversioncontrol/__init__.py
+++ b/python/mozversioncontrol/mozversioncontrol/__init__.py
@@ -207,46 +207,51 @@ def get_repository_object(path, hg='hg',
 class MissingVCSInfo(Exception):
     """Represents a general failure to resolve a VCS interface."""
 
 
 class MissingConfigureInfo(MissingVCSInfo):
     """Represents error finding VCS info from configure data."""
 
 
+def get_repository_from_build_config(config):
+    """Obtain a repository from the build configuration.
+
+    Accepts an object that has a ``topsrcdir`` and ``subst`` attribute.
+    """
+    flavor = config.substs.get('VCS_CHECKOUT_TYPE')
+
+    # If in build mode, only use what configure found. That way we ensure
+    # that everything in the build system can be controlled via configure.
+    if not flavor:
+        raise MissingConfigureInfo('could not find VCS_CHECKOUT_TYPE '
+                                   'in build config; check configure '
+                                   'output and verify it could find a '
+                                   'VCS binary')
+
+    if flavor == 'hg':
+        return HgRepository(config.topsrcdir, hg=config.substs['HG'])
+    elif flavor == 'git':
+        return GitRepository(config.topsrcdir, git=config.substs['GIT'])
+    else:
+        raise MissingVCSInfo('unknown VCS_CHECKOUT_TYPE value: %s' % flavor)
+
+
 def get_repository_from_env():
     """Obtain a repository object by looking at the environment.
 
     If inside a build environment (denoted by presence of a ``buildconfig``
     module), VCS info is obtained from it, as found via configure. This allows
     us to respect what was passed into configure. Otherwise, we fall back to
     scanning the filesystem.
     """
     try:
         import buildconfig
 
-        flavor = buildconfig.substs.get('VCS_CHECKOUT_TYPE')
-
-        # If in build mode, only use what configure found. That way we ensure
-        # that everything in the build system can be controlled via configure.
-        if not flavor:
-            raise MissingConfigureInfo('could not find VCS_CHECKOUT_TYPE '
-                                       'in build config; check configure '
-                                       'output and verify it could find a '
-                                       'VCS binary')
-
-        if flavor == 'hg':
-            return HgRepository(buildconfig.topsrcdir,
-                                hg=buildconfig.substs['HG'])
-        elif flavor == 'git':
-            return GitRepository(buildconfig.topsrcdir,
-                                 git=buildconfig.substs['GIT'])
-        else:
-            raise MissingVCSInfo('unknown VCS_CHECKOUT_TYPE value: %s' % flavor)
-
+        return get_repository_from_build_config(buildconfig)
     except ImportError:
         pass
 
     def ancestors(path):
         while path:
             yield path
             path, child = os.path.split(path)
             if child == '':