Add options for repo url and branch to checkout_aosp.py

Change-Id: I737a22158b4f1f4bf53abdbac15926ada9848a80
diff --git a/tools/checkout_aosp.py b/tools/checkout_aosp.py
index a62e641..842ae3b 100755
--- a/tools/checkout_aosp.py
+++ b/tools/checkout_aosp.py
@@ -21,13 +21,17 @@
 J_DEFAULT = multiprocessing.cpu_count() - 2
 
 # Checkout AOSP source to the specified direcotry using the speficied manifest.
-def checkout_aosp(aosp_root, manifest_xml, concurrency):
-  manifests_dir = join(aosp_root, '.repo', 'manifests')
-  utils.makedirs_if_needed(manifests_dir)
-
-  copy2(manifest_xml, manifests_dir)
-  check_call(['repo', 'init', '-u', AOSP_MANIFEST_URL, '-m',
-    basename(manifest_xml), '--depth=1'], cwd = aosp_root)
+def checkout_aosp(aosp_root, url, branch, manifest_xml, concurrency):
+  utils.makedirs_if_needed(aosp_root)
+  command = ['repo', 'init', '-u', url, '--depth=1']
+  if (branch):
+    command.extend(['-b', branch])
+  else:
+    manifests_dir = join(aosp_root, '.repo', 'manifests')
+    utils.makedirs_if_needed(manifests_dir)
+    copy2(manifest_xml, manifests_dir)
+    command.extend(['-m', basename(manifest_xml)])
+  check_call(command, cwd = aosp_root)
 
   check_call(['repo', 'sync', '-dq', '-j' + concurrency], cwd = aosp_root)
 
@@ -35,10 +39,17 @@
   parser = argparse.ArgumentParser(
       description = 'Checkout the AOSP source tree.')
   utils_aosp.add_root_argument(parser)
+  parser.add_argument('--url',
+                      help='URL the repo. ' +
+                           'Defaults to ' + AOSP_MANIFEST_URL + '.',
+                      default=AOSP_MANIFEST_URL)
   parser.add_argument('--manifest',
                       help='Manifest to use for the checkout. ' +
                            'Defaults to ' + AOSP_MANIFEST_XML + '.',
                       default=AOSP_MANIFEST_XML)
+  parser.add_argument('--branch',
+                      help='Branch to checkout. This overrides ' +
+                           'passing --manifest')
   parser.add_argument('-j',
                       help='Projects to fetch simultaneously. ' +
                            'Defaults to ' + str(J_DEFAULT) + '.',
@@ -47,7 +58,7 @@
 
 def Main():
   args = parse_arguments()
-  checkout_aosp(args.aosp_root, args.manifest, args.j)
+  checkout_aosp(args.aosp_root, args.url, args.branch, args.manifest, args.j)
 
 if __name__ == '__main__':
   sys.exit(Main())