Bug 556394 - Allow a single option to control tag/revision to pull in client.py. r=gozer
authorJustin Wood <Callek@gmail.com>
Tue, 15 Jun 2010 23:47:11 -0400
changeset 5895 b999fdbf21074a31160fe2af5af9c2cd24f3e972
parent 5894 f33643d4a469ac7c17f46ac8a48a78e7eedadd43
child 5896 9fb2b78003f34ab594dea3aa478f788b48643b32
push idunknown
push userunknown
push dateunknown
reviewersgozer
bugs556394
Bug 556394 - Allow a single option to control tag/revision to pull in client.py. r=gozer Part 2 - The real work and adds the commandline option
client.py
--- a/client.py
+++ b/client.py
@@ -20,21 +20,21 @@ DEFAULTS = {
 
   # URL of the default hg repository to clone for Venkman.
   'VENKMAN_REPO': 'http://hg.mozilla.org/venkman/',
 
   # URL of the default hg repository to clone for Mozilla.
   'MOZILLA_REPO': 'http://hg.mozilla.org/mozilla-central/',
 }
 
-# Populate initial defaults
-for index in ['CHATZILLA_REV', 'INSPECTOR_REV', 'VENKMAN_REV', 'COMM_REV', 'MOZILLA_REV']:
-  if index not in DEFAULTS:
-    DEFAULTS[index] = DEFAULTS['REV']
-
+def get_DEFAULT_tag(index):
+  if index in DEFAULTS:
+    return DEFAULTS[index]
+  else:
+    return DEFAULTS['REV']
 
 # The set of defaults below relate to the current switching mechanism between
 # trunk or branches and back again if it is required.
 
 # The current version expected in the .treestate file for nothing to happen.
 # This reflects the "[treestate] src_update_version = ..." value.
 #
 # src_update_version values:
@@ -329,62 +329,62 @@ def check_retries_option(option, opt_str
 o = OptionParser(usage="%prog [options] checkout")
 o.add_option("-m", "--comm-repo", dest="comm_repo",
              default=None,
              help="URL of comm (Calendar/Mail/Suite) repository to pull from (default: use hg default in .hg/hgrc)")
 o.add_option("--skip-comm", dest="skip_comm",
              action="store_true", default=False,
              help="Skip pulling the comm (Calendar/Mail/Suite) repository.")
 o.add_option("--comm-rev", dest="comm_rev",
-             default=DEFAULTS['COMM_REV'],
-             help="Revision of comm (Calendar/Mail/Suite) repository to update to. Default: \"" + DEFAULTS['COMM_REV'] + "\"")
+             default=None,
+             help="Revision of comm (Calendar/Mail/Suite) repository to update to. Default: \"" + get_DEFAULT_tag('COMM_REV') + "\"")
 
 o.add_option("-z", "--mozilla-repo", dest="mozilla_repo",
              default=None,
              help="URL of Mozilla repository to pull from (default: use hg default in mozilla/.hg/hgrc; or if that file doesn't exist, use \"" + DEFAULTS['MOZILLA_REPO'] + "\".)")
 o.add_option("--skip-mozilla", dest="skip_mozilla",
              action="store_true", default=False,
              help="Skip pulling the Mozilla repository.")
 o.add_option("--mozilla-rev", dest="mozilla_rev",
-             default=DEFAULTS['MOZILLA_REV'],
-             help="Revision of Mozilla repository to update to. Default: \"" + DEFAULTS['MOZILLA_REV'] + "\"")
+             default=None,
+             help="Revision of Mozilla repository to update to. Default: \"" + get_DEFAULT_tag('MOZILLA_REV') + "\"")
 
 o.add_option("--inspector-repo", dest="inspector_repo",
              default=None,
              help="URL of DOM Inspector repository to pull from (default: use hg default in mozilla/extensions/inspector/.hg/hgrc; or if that file doesn't exist, use \"" + DEFAULTS['INSPECTOR_REPO'] + "\".)")
 o.add_option("--skip-inspector", dest="skip_inspector",
              action="store_true", default=False,
              help="Skip pulling the DOM Inspector repository.")
 o.add_option("--inspector-rev", dest="inspector_rev",
-             default=DEFAULTS['INSPECTOR_REV'],
-             help="Revision of DOM Inspector repository to update to. Default: \"" + DEFAULTS['INSPECTOR_REV'] + "\"")
+             default=None,
+             help="Revision of DOM Inspector repository to update to. Default: \"" + get_DEFAULT_tag('INSPECTOR_REV') + "\"")
 
 o.add_option("--skip-ldap", dest="skip_ldap",
              action="store_true", default=False,
              help="Skip pulling LDAP from the Mozilla CVS repository.")
 
 o.add_option("--chatzilla-repo", dest = "chatzilla_repo",
              default = None,
              help = "URL of ChatZilla repository to pull from (default: use hg default in mozilla/extensions/irc/.hg/hgrc; or if that file doesn't exist, use \"" + DEFAULTS['CHATZILLA_REPO'] + "\".)")
 o.add_option("--skip-chatzilla", dest="skip_chatzilla",
              action="store_true", default=False,
              help="Skip pulling the ChatZilla repository.")
 o.add_option("--chatzilla-rev", dest = "chatzilla_rev",
-             default = DEFAULTS['CHATZILLA_REV'],
-             help = "Revision of ChatZilla repository to update to. Default: \"" + DEFAULTS['CHATZILLA_REV'] + "\"")
+             default = None,
+             help = "Revision of ChatZilla repository to update to. Default: \"" + get_DEFAULT_tag('CHATZILLA_REV') + "\"")
 
 o.add_option("--venkman-repo", dest = "venkman_repo",
              default = None,
              help = "URL of Venkman repository to pull from (default: use hg default in mozilla/extensions/venkman/.hg/hgrc; or if that file doesn't exist, use \"" + DEFAULTS['VENKMAN_REPO'] + "\".)")
 o.add_option("--skip-venkman", dest="skip_venkman",
              action="store_true", default=False,
              help="Skip pulling the Venkman repository.")
 o.add_option("--venkman-rev", dest = "venkman_rev",
-             default = DEFAULTS['VENKMAN_REV'],
-             help = "Revision of Venkman repository to update to. Default: \"" + DEFAULTS['VENKMAN_REV'] + "\"")
+             default = None,
+             help = "Revision of Venkman repository to update to. Default: \"" + get_DEFAULT_tag('VENKMAN_REV') + "\"")
 
 o.add_option("--hg", dest="hg", default=os.environ.get('HG', 'hg'),
              help="The location of the hg binary")
 o.add_option("-v", "--verbose", dest="verbose",
              action="store_true", default=False,
              help="Enable verbose output on hg updates")
 o.add_option("--hg-options", dest="hgopts",
              help="Pass arbitrary options to hg commands (i.e. --debug, --time)")
@@ -396,87 +396,115 @@ o.add_option("--cvs", dest="cvs", defaul
 o.add_option("--cvsroot", dest="cvsroot",
              default=os.environ.get('CVSROOT', ':pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot'),
              help="The CVSROOT (default: :pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot")
 
 o.add_option("--retries", dest="retries", type="int", metavar="NUM",
              default=1, help="Number of times to retry a failed command before giving up. (default: 1)",
              action="callback", callback=check_retries_option)
 
+o.add_option("-r", "--rev", dest = "default_rev",
+             default = None,
+             help = "Revision of all repositories to update to, unless otherwise specified.")
+
 def fixup_comm_repo_options(options):
     """Check options.comm_repo value.
 
     options.comm_repo is normally None.
     This is fine -- our "hg pull" command will omit the repo URL.
     The exception is the initial checkout, which does an "hg clone".
     That command requires a repository URL.
     """
 
     if options.comm_repo is None and \
             not os.path.exists(os.path.join(topsrcdir, '.hg')):
         o.print_help()
         print
         print "Error: the -m option is required for the initial checkout!"
         sys.exit(2)
 
+    if options.comm_rev is None:
+        options.comm_rev = get_DEFAULT_tag("COMM_REV")
+
 def fixup_mozilla_repo_options(options):
     """Handle special case: initial checkout of Mozilla.
 
     See fixup_comm_repo_options().
     """
     if options.mozilla_repo is None and \
             not os.path.exists(os.path.join(topsrcdir, 'mozilla')):
         options.mozilla_repo = DEFAULTS['MOZILLA_REPO']
+    
+    if options.mozilla_rev is None:
+        options.mozilla_rev = get_DEFAULT_tag("MOZILLA_REV")
 
 def fixup_chatzilla_repo_options(options):
     """Handle special case: initial hg checkout of Chatzilla.
 
     See fixup_comm_repo_options().
     backup_cvs_extension() is also called.
     """
 
     extensionPath = os.path.join(topsrcdir, 'mozilla', 'extensions', 'irc')
 
     backup_cvs_extension('Chatzilla', 'irc', extensionPath)
 
     if options.chatzilla_repo is None and not os.path.exists(extensionPath):
         options.chatzilla_repo = DEFAULTS['CHATZILLA_REPO']
 
+    if options.chatzilla_rev is None:
+        options.chatzilla_rev = get_DEFAULT_tag("CHATZILLA_REV")
+
 def fixup_inspector_repo_options(options):
     """Handle special case: initial checkout of DOM Inspector.
 
     See fixup_comm_repo_options().
     """
 
     # No cvs backup needed as DOM Inspector was part (and removed from)
     # Mozilla hg repository.
     if options.inspector_repo is None and \
             not os.path.exists(os.path.join(topsrcdir, 'mozilla', 'extensions', 'inspector')):
         options.inspector_repo = DEFAULTS['INSPECTOR_REPO']
 
+    if options.inspector_rev is None:
+        options.inspector_rev = get_DEFAULT_tag("INSPECTOR_REV")
+
 def fixup_venkman_repo_options(options):
     """Handle special case: initial hg checkout of Venkman.
 
     See fixup_comm_repo_options().
     backup_cvs_extension() is also called.
     """
 
     extensionPath = os.path.join(topsrcdir, 'mozilla', 'extensions', 'venkman')
 
     backup_cvs_extension('Venkman', 'venkman', extensionPath)
 
     if options.venkman_repo is None and not os.path.exists(extensionPath):
         options.venkman_repo = DEFAULTS['VENKMAN_REPO']
 
+    if options.venkman_rev is None:
+        options.venkman_rev = get_DEFAULT_tag("VENKMAN_REV")
+
 try:
     (options, (action,)) = o.parse_args()
 except ValueError:
     o.print_help()
     sys.exit(2)
 
+if options.default_rev:
+  # We now wish to override all the DEFAULTS.
+  DEFAULTS['REV'] = options.default_rev
+  for index in ['CHATZILLA', 'INSPECTOR', 'VENKMAN', 'COMM', 'MOZILLA']:
+    index += "_REV"
+    # Clear the rest from file-defaults
+    if index in DEFAULTS:
+      del DEFAULTS[index]
+
 if action in ('checkout', 'co'):
     # Update Comm repository configuration.
     repo_config()
 
     if not options.skip_comm:
         fixup_comm_repo_options(options)
         do_hg_pull('.', options.comm_repo, options.hg, options.comm_rev)