From 6abcb02653b101723b6ec4d454bd78be03ffc23d Mon Sep 17 00:00:00 2001 From: Sam Snyder Date: Wed, 31 Jul 2024 17:39:30 -0700 Subject: [PATCH] Calculate GitProvenance only once per build. In repositories with many commits computing this can be expensive, so avoid any unnecessary repetition of the same computation with caching. --- .../java/org/openrewrite/maven/MavenMojoProjectParser.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java b/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java index 690e05ac..e35bd353 100644 --- a/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java +++ b/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java @@ -767,9 +767,11 @@ private static List listSources(Path sourceDirectory, String extension) th } } + private static final Map REPO_ROOT_TO_PROVENANCE = new HashMap<>(); private @Nullable GitProvenance gitProvenance(Path baseDir, @Nullable BuildEnvironment buildEnvironment) { try { - return GitProvenance.fromProjectDirectory(baseDir, buildEnvironment); + // Computing git provenance can be expensive for repositories with many commits, ensure we do it only once + return REPO_ROOT_TO_PROVENANCE.computeIfAbsent(baseDir, dir -> GitProvenance.fromProjectDirectory(dir, buildEnvironment)); } catch (Exception e) { // Logging at a low level as this is unlikely to happen except in non-git projects, where it is expected logger.debug("Unable to determine git provenance", e);