Compute projectName in GitCloneStep constructor
The projectName variable was recalculated multiple times
based on the same instance values which would make sense
to be done only once in the constructor.
Change-Id: I62580d40127c6c620e5f2f8af2f1aa2e4268ceb1
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java
index bcd725e..0e0e72d 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/GitCloneStep.java
@@ -53,6 +53,7 @@
private final DynamicSet<ProjectDeletedListener> deletedListeners;
private final ProjectCache projectCache;
private final GitRepositoryManager repoManager;
+ private final String projectName;
public interface Factory {
GitCloneStep create(
@@ -80,15 +81,15 @@
this.context = context;
this.organisation = organisation;
this.repository = repository;
- this.destinationDirectory = prepareTargetGitDirectory(gitDir, organisation, repository);
+ this.projectName = organisation + "/" + repository;
+ this.destinationDirectory = prepareTargetGitDirectory(gitDir, this.projectName);
this.deletedListeners = deletedListeners;
this.projectCache = projectCache;
this.repoManager = repoManager;
}
- private static File prepareTargetGitDirectory(File gitDir, String organisation, String repository)
+ private static File prepareTargetGitDirectory(File gitDir, String projectName)
throws GitException {
- String projectName = organisation + "/" + repository;
File repositoryDir = new File(gitDir, projectName + ".git");
if (repositoryDir.exists()) {
throw new GitDestinationAlreadyExistsException(projectName);
@@ -97,7 +98,6 @@
}
private void createNewProject() throws GitException {
- String projectName = organisation + "/" + repository;
try (ManualRequestContext requestContext = context.openAs(config.importAccountId)) {
ProjectInput pi = new ProjectInput();
pi.name = projectName;
@@ -140,7 +140,6 @@
}
try {
- String projectName = organisation + "/" + repository;
Project.NameKey key = Project.nameKey(projectName);
cleanJGitCache(key);
FileUtils.deleteDirectory(gitDirectory);