25x speed up of download exoplayer script
Accelerate script from 3min 30 to 8sec.
This is done by only downloading commits without tree or blobs
(filter=tree:0).
Additionally, improve parsing of exclusive arguments and remove
unnecessary call to str().
Test: time ./download_exoplayer.py --tag r2.16.0
Change-Id: Ie1a10a63548e337e76d54044f2115118c1a8446c
Bug: 205680780
diff --git a/download_exoplayer.py b/download_exoplayer.py
index e0f9add..05f48a6 100755
--- a/download_exoplayer.py
+++ b/download_exoplayer.py
@@ -37,9 +37,9 @@
print("The following files will not be added to exoplayer/external: \n" +
files_to_delete)
while True:
- print("Please confirm [y/n] ")
+ print("Please confirm [Y/n] ")
choice = input().lower()
- if choice in ["y", "yes"]:
+ if choice in ["y", "yes", ""]:
return
elif choice in ["n", "no"]:
sys.exit("User rejected the list of .mk files to exclude from the tree.")
@@ -54,20 +54,17 @@
"directory, where <SHA> identifies the commit to download. This script "
"also stages the changes for commit. Either --tag or --commit must be "
"provided.")
-parser.add_argument(
+refGroup = parser.add_mutually_exclusive_group(required=True)
+refGroup.add_argument(
"--tag", help="The tag that identifies the ExoPlayer commit to download.")
-parser.add_argument(
+refGroup.add_argument(
"--commit", help="The commit SHA of the ExoPlayer version to download.")
parser.add_argument(
"--branch",
help="The branch to create for the change.",
- default="update-exoplayer")
+ default="download-exoplayer")
args = parser.parse_args()
-if (args.tag is None) == (args.commit is None):
- parser.print_help()
- sys.exit("\nError: Either the tag or the commit must be provided.")
-
cd_to_script_parent_directory()
# Check whether the branch exists, and abort if it does.
@@ -75,14 +72,15 @@
sys.exit(f"\nBranch {args.branch} already exists. Please delete, or change "
"branch.")
-if run(f"repo start {args.branch}", check=False):
+if run(f"repo start {args.branch}"):
sys.exit(f"\nFailed to repo start {args.branch}. Check you don't have "
"uncommited changes in your current branch.")
with tempfile.TemporaryDirectory() as tmpdir:
logging.info(f"Created temporary directory {tmpdir}")
- run(f"git clone {EXOPLAYER_SOURCE_REPO} {tmpdir}")
- os.chdir(str(tmpdir))
+ run("git clone --no-checkout --filter=tree:0 "
+ f"{EXOPLAYER_SOURCE_REPO} {tmpdir}")
+ os.chdir(tmpdir)
if args.tag:
# Get the commit SHA associated to the tag.