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);