Skip to content

Commit

Permalink
Calculate GitProvenance only once per build.
Browse files Browse the repository at this point in the history
In repositories with many commits computing this can be expensive, so avoid any unnecessary repetition of the same computation with caching.
  • Loading branch information
sambsnyd committed Aug 1, 2024
1 parent a6e4db6 commit 6abcb02
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,11 @@ private static List<Path> listSources(Path sourceDirectory, String extension) th
}
}

private static final Map<Path, GitProvenance> 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);
Expand Down

0 comments on commit 6abcb02

Please sign in to comment.