From 13d76113d24d7502d8248bd22a58ef31453bb48c Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Mon, 19 Feb 2024 10:47:34 +0100 Subject: [PATCH] perf(downloader): Return early from archive download for an empty revision This avoids trying to download from an invalid archive URL, improving the performance when running e.g. `ort download --dry-run`. Note that the change in the static version of `toArchiveDownloadUrl()` is only done for consistency. Signed-off-by: Sebastian Schuberth --- downloader/src/main/kotlin/VcsHost.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/downloader/src/main/kotlin/VcsHost.kt b/downloader/src/main/kotlin/VcsHost.kt index dae4d396ee307..93db9d31203bb 100644 --- a/downloader/src/main/kotlin/VcsHost.kt +++ b/downloader/src/main/kotlin/VcsHost.kt @@ -425,6 +425,7 @@ enum class VcsHost( */ fun toArchiveDownloadUrl(vcsInfo: VcsInfo): String? { val normalizedVcsInfo = vcsInfo.normalize() + if (normalizedVcsInfo.revision.isEmpty()) return null val host = entries.find { it.isApplicable(normalizedVcsInfo) } ?: return null return normalizedVcsInfo.url.toUri { @@ -518,7 +519,7 @@ enum class VcsHost( */ fun toArchiveDownloadUrl(vcsInfo: VcsInfo): String? { val normalizedVcsInfo = vcsInfo.normalize() - if (!isApplicable(normalizedVcsInfo)) return null + if (normalizedVcsInfo.revision.isEmpty() || !isApplicable(normalizedVcsInfo)) return null return normalizedVcsInfo.url.toUri { val userOrOrg = getUserOrOrgInternal(it) ?: return@toUri null