Default repo manifest settings in git config

A default manifest URL can be specified using:
  git config --global repo-manifest.<id>.url <url>

A default manifest server can be specified using:
  git config --global repo-manifest.<id>.server <url>

A default git mirror reference can be specified using:
  git config --global repo-manifest.<id>.reference <path>

This will allow the user to use 'repo init -u <id>' as
a shorter alternative to specifying the full URL.

Also, manifest server will not have to be specified in the
manifest XML and the reference will not have to be specified
on the command line. If they are, they will override these
default values however.

Change-Id: Ifdbc160bd5909ec7df9efb0c5d7136f1d9351754
Signed-off-by: Victor Boivie <victor.boivie@sonyericsson.com>
diff --git a/manifest_xml.py b/manifest_xml.py
index 9189eec..c9e5c40 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -228,7 +228,11 @@
   @property
   def manifest_server(self):
     self._Load()
-    return self._manifest_server
+
+    if self._manifest_server:
+      return self._manifest_server
+
+    return self.manifestProject.config.GetString('repo.manifest-server')
 
   @property
   def IsMirror(self):
diff --git a/repo b/repo
index 0e77983..1c71f07 100755
--- a/repo
+++ b/repo
@@ -28,7 +28,7 @@
 del magic
 
 # increment this whenever we make important changes to this script
-VERSION = (1, 13)
+VERSION = (1, 14)
 
 # increment this if the MAINTAINER_KEYS block is modified
 KEYRING_VERSION = (1,0)
@@ -149,7 +149,7 @@
   """Installs repo by cloning it over the network.
   """
   opt, args = init_optparse.parse_args(args)
-  if args or not opt.manifest_url:
+  if args:
     init_optparse.print_usage()
     sys.exit(1)
 
diff --git a/subcmds/init.py b/subcmds/init.py
index 1c23d62..e80d698 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -23,6 +23,7 @@
 from project import SyncBuffer
 from git_config import GitConfig
 from git_command import git_require, MIN_GIT_VERSION
+from git_config import GitConfig
 
 class Init(InteractiveCommand, MirrorSafeCommand):
   common = True
@@ -36,6 +37,20 @@
 from the server and is installed in the .repo/ directory in the
 current working directory.
 
+The optional -u argument can be used to specify a URL to the
+manifest project. It is also possible to have a git configuration
+section as below to use 'identifier' as argument to -u:
+
+  [repo-manifest "identifier"]
+    url = ...
+    server = ...
+    reference = ...
+
+Only the url is required - the others are optional.
+
+If no -u argument is specified, the 'repo-manifest' section named
+'default' will be used if present.
+
 The optional -b argument can be used to select the manifest branch
 to checkout and use.  If no branch is specified, master is assumed.
 
@@ -69,7 +84,7 @@
     # Manifest
     g = p.add_option_group('Manifest options')
     g.add_option('-u', '--manifest-url',
-                 dest='manifest_url',
+                 dest='manifest_url', default='default',
                  help='manifest repository location', metavar='URL')
     g.add_option('-b', '--manifest-branch',
                  dest='manifest_branch',
@@ -102,10 +117,25 @@
   def _SyncManifest(self, opt):
     m = self.manifest.manifestProject
     is_new = not m.Exists
+    manifest_server = None
+
+    # The manifest url may point out a manifest section in the config
+    key = 'repo-manifest.%s.' % opt.manifest_url
+    if GitConfig.ForUser().GetString(key + 'url'):
+      opt.manifest_url = GitConfig.ForUser().GetString(key + 'url')
+
+      # Also copy other options to the manifest config if not specified already.
+      if not opt.reference:
+        opt.reference = GitConfig.ForUser().GetString(key + 'reference')
+      manifest_server = GitConfig.ForUser().GetString(key + 'server')
 
     if is_new:
-      if not opt.manifest_url:
-        print >>sys.stderr, 'fatal: manifest url (-u) is required.'
+      if not opt.manifest_url or opt.manifest_url == 'default':
+        print >>sys.stderr, """\
+fatal: missing manifest url (-u) and no default found.
+
+  tip: The global git configuration key 'repo-manifest.default.url' can
+       be used to specify a default url."""
         sys.exit(1)
 
       if not opt.quiet:
@@ -129,6 +159,9 @@
       r.ResetFetch()
       r.Save()
 
+    if manifest_server:
+      m.config.SetString('repo.manifest-server', manifest_server)
+
     if opt.reference:
       m.config.SetString('repo.reference', opt.reference)