Bug 977384 - mach mercurial-setup: Refactor part 1; r=gps
authorEd Morley <emorley@mozilla.com>
Thu, 27 Feb 2014 10:10:20 +0000
changeset 171264 aad2d9752a5e8c0bc7f8c975475ba1e68c281ee3
parent 171263 83fc9dab3ddb4c329b18be8f96302318f147b7e6
child 171265 903893620b9f726bf12a2ea7cdeb9ef690a31a08
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewersgps
bugs977384
milestone30.0a1
Bug 977384 - mach mercurial-setup: Refactor part 1; r=gps
tools/mercurial/hgsetup/wizard.py
--- a/tools/mercurial/hgsetup/wizard.py
+++ b/tools/mercurial/hgsetup/wizard.py
@@ -129,40 +129,27 @@ class MercurialSetupWizard(object):
         if not c.have_recommended_diff_settings():
             print(BAD_DIFF_SETTINGS)
             print('')
             if self._prompt_yn('Would you like me to fix this for you'):
                 c.ensure_recommended_diff_settings()
                 print('Fixed patch settings.')
                 print('')
 
-        active = c.extensions
+        self.prompt_native_extension(c, 'progress',
+            'Would you like to see progress bars during Mercurial operations')
 
-        if 'progress' not in active:
-            if self._prompt_yn('Would you like to see progress bars during '
-                'long-running Mercurial operations'):
-                c.activate_extension('progress')
-                print('Activated progress extension.')
-                print('')
+        self.prompt_native_extension(c, 'color',
+            'Would you like Mercurial to colorize output to your terminal')
 
-        if 'color' not in active:
-            if self._prompt_yn('Would you like Mercurial to colorize output '
-                'to your terminal'):
-                c.activate_extension('color')
-                print('Activated color extension.')
-                print('')
+        self.prompt_native_extension(c, 'rebase',
+            'Would you like to enable the rebase extension to allow you to move'
+            ' changesets around (which can help maintain a linear history)')
 
-        if 'rebase' not in active:
-            if self._prompt_yn('Would you like to enable the rebase extension '
-                'to allow you to move changesets around (which can help '
-                'maintain a linear history)'):
-                c.activate_extension('rebase')
-                print('Activated rebase extension.')
-                print('')
-
+        active = c.extensions
         update_vcs_tools = False
         activate_bzexport = False
 
         if 'bzexport' not in active:
             print(BZEXPORT_INFO)
             if self._prompt_yn('Would you like to activate bzexport'):
                 activate_bzexport = True
                 update_vcs_tools = True
@@ -171,22 +158,18 @@ class MercurialSetupWizard(object):
 
         if activate_bzexport:
             update_vcs_tools = True
             c.activate_extension('bzexport',
                 os.path.join(self.vcs_tools_dir, 'hgext', 'bzexport'))
             print('Activated bzexport extension.')
             print('')
 
-        if 'mq' not in active:
-            if self._prompt_yn('Would you like to activate the mq extension '
-                'to manage patches'):
-                c.activate_extension('mq')
-                print('Activated mq extension.')
-                print('')
+        self.prompt_native_extension(c, 'mq',
+            'Would you like to activate the mq extension to manage patches')
 
         active = c.extensions
 
         if 'mq' in active:
             update_mqext = 'mqext' in active
             if 'mqext' not in active:
                 print(MQEXT_INFO)
                 if self._prompt_yn('Would you like to activate mqext and '
@@ -276,16 +259,24 @@ class MercurialSetupWizard(object):
                 print('hgrc changes not written to file. I would have '
                     'written the following:\n')
                 c.write(sys.stdout)
                 return 1
 
         print(FINISHED)
         return 0
 
+    def prompt_native_extension(self, c, name, prompt_text):
+        # Ask the user if the specified extension bundled with Mercurial should be enabled.
+        if name in c.extensions:
+            return
+        if self._prompt_yn(prompt_text):
+            c.activate_extension(name)
+            print('Activated %s extension.\n' % name)
+
     def update_mercurial_repo(self, hg, url, dest, branch, msg):
         # We always pass the host fingerprints that we "know" to be canonical
         # because the existing config may have outdated fingerprints and this
         # may cause Mercurial to abort.
         return self._update_repo(hg, url, dest, branch, msg,
             update_mercurial_repo, hostfingerprints=HOST_FINGERPRINTS)
 
     def update_git_repo(self, git, url, dest, ref, msg):