mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Pass a validated .git directory to GitRepositoryImpl constructor + simplify API
No external usages of modified constructors were found.
This commit is contained in:
+1
-4
@@ -22,14 +22,12 @@ import com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot;
|
||||
import com.intellij.ide.util.projectWizard.importSources.ProjectFromSourcesBuilder;
|
||||
import com.intellij.ide.util.projectWizard.importSources.ProjectStructureDetector;
|
||||
import com.intellij.ide.util.projectWizard.importSources.impl.JavaProjectStructureDetector;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.remoteServer.util.CloudGitDeploymentDetector;
|
||||
import git4idea.GitPlatformFacade;
|
||||
import git4idea.GitUtil;
|
||||
import git4idea.repo.GitRepository;
|
||||
import git4idea.repo.GitRepositoryImpl;
|
||||
@@ -74,8 +72,7 @@ public class CloudGitProjectStructureDetector extends ProjectStructureDetector {
|
||||
}
|
||||
|
||||
Project project = ProjectManager.getInstance().getDefaultProject();
|
||||
GitRepository repository
|
||||
= GitRepositoryImpl.getLightInstance(repositoryRoot, project, ServiceManager.getService(project, GitPlatformFacade.class), project);
|
||||
GitRepository repository = GitRepositoryImpl.getInstance(repositoryRoot, project, false);
|
||||
repository.update();
|
||||
|
||||
for (CloudGitDeploymentDetector deploymentDetector : CloudGitDeploymentDetector.EP_NAME.getExtensions()) {
|
||||
|
||||
@@ -129,7 +129,7 @@ public class GitShowExternalLogAction extends DumbAwareAction {
|
||||
final GitRepositoryManager repositoryManager = ServiceManager.getService(project, GitRepositoryManager.class);
|
||||
GitPlatformFacade facade = ServiceManager.getService(GitPlatformFacade.class);
|
||||
for (VirtualFile root : roots) {
|
||||
repositoryManager.addExternalRepository(root, GitRepositoryImpl.getFullInstance(root, project, facade, project));
|
||||
repositoryManager.addExternalRepository(root, GitRepositoryImpl.getInstance(root, project, true));
|
||||
}
|
||||
VcsLogManager manager = new VcsLogManager(project, ServiceManager.getService(project, VcsLogSettings.class),
|
||||
ServiceManager.getService(project, VcsLogUiProperties.class));
|
||||
|
||||
@@ -26,8 +26,6 @@ import git4idea.GitVcs;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class GitRepositoryCreator extends VcsRepositoryCreator {
|
||||
@NotNull private final Project myProject;
|
||||
@NotNull private final GitPlatformFacade myPlatformFacade;
|
||||
@@ -40,9 +38,8 @@ public class GitRepositoryCreator extends VcsRepositoryCreator {
|
||||
@Override
|
||||
@Nullable
|
||||
public Repository createRepositoryIfValid(@NotNull VirtualFile root) {
|
||||
return GitUtil.isGitRoot(new File(root.getPath()))
|
||||
? GitRepositoryImpl.getFullInstance(root, myProject, myPlatformFacade, myProject)
|
||||
: null;
|
||||
VirtualFile gitDir = GitUtil.findGitDir(root);
|
||||
return gitDir == null ? null : GitRepositoryImpl.getInstance(root, gitDir, myProject, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -18,6 +18,7 @@ package git4idea.repo;
|
||||
import com.intellij.dvcs.repo.RepositoryImpl;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vcs.AbstractVcs;
|
||||
@@ -34,6 +35,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
import static com.intellij.util.ObjectUtils.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Kirill Likhodedov
|
||||
*/
|
||||
@@ -46,22 +49,21 @@ public class GitRepositoryImpl extends RepositoryImpl implements GitRepository {
|
||||
|
||||
@NotNull private volatile GitRepoInfo myInfo;
|
||||
|
||||
/**
|
||||
* Get the GitRepository instance from the {@link GitRepositoryManager}.
|
||||
* If you need to have an instance of GitRepository for a repository outside the project, use
|
||||
* {@link #getLightInstance(VirtualFile, Project, git4idea.GitPlatformFacade, Disposable)}
|
||||
*/
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
protected GitRepositoryImpl(@NotNull VirtualFile rootDir, @NotNull GitPlatformFacade facade, @NotNull Project project,
|
||||
@NotNull Disposable parentDisposable, final boolean light) {
|
||||
private GitRepositoryImpl(@NotNull VirtualFile rootDir,
|
||||
@NotNull VirtualFile gitDir,
|
||||
@NotNull GitPlatformFacade facade,
|
||||
@NotNull Project project,
|
||||
@NotNull Disposable parentDisposable,
|
||||
final boolean light) {
|
||||
super(project, rootDir, parentDisposable);
|
||||
myPlatformFacade = facade;
|
||||
myGitDir = GitUtil.findGitDir(rootDir);
|
||||
assert myGitDir != null : ".git directory wasn't found under " + rootDir.getPresentableUrl();
|
||||
myGitDir = gitDir;
|
||||
myReader = new GitRepositoryReader(VfsUtilCore.virtualToIoFile(myGitDir));
|
||||
if (!light) {
|
||||
myUntrackedFilesHolder = new GitUntrackedFilesHolder(this);
|
||||
Disposer.register(this, myUntrackedFilesHolder);
|
||||
myUntrackedFilesHolder.setupVfsListener(project);
|
||||
setupUpdater();
|
||||
}
|
||||
else {
|
||||
myUntrackedFilesHolder = null;
|
||||
@@ -69,28 +71,20 @@ public class GitRepositoryImpl extends RepositoryImpl implements GitRepository {
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the temporary light instance of GitRepository.
|
||||
* It lacks functionality of auto-updating GitRepository on Git internal files change, and also stored a stub instance of
|
||||
* {@link GitUntrackedFilesHolder}.
|
||||
*/
|
||||
@NotNull
|
||||
public static GitRepository getLightInstance(@NotNull VirtualFile root, @NotNull Project project, @NotNull GitPlatformFacade facade,
|
||||
@NotNull Disposable parentDisposable) {
|
||||
return new GitRepositoryImpl(root, facade, project, parentDisposable, true);
|
||||
public static GitRepository getInstance(@NotNull VirtualFile root,
|
||||
@NotNull Project project,
|
||||
boolean listenToRepoChanges) {
|
||||
return getInstance(root, assertNotNull(GitUtil.findGitDir(root)), project, listenToRepoChanges);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the full-functional instance of GitRepository - with UntrackedFilesHolder and GitRepositoryUpdater.
|
||||
* This is used for repositories registered in project, and should be optained via {@link GitRepositoryManager}.
|
||||
*/
|
||||
@NotNull
|
||||
public static GitRepository getFullInstance(@NotNull VirtualFile root, @NotNull Project project, @NotNull GitPlatformFacade facade,
|
||||
@NotNull Disposable parentDisposable) {
|
||||
GitRepositoryImpl repository = new GitRepositoryImpl(root, facade, project, parentDisposable, false);
|
||||
repository.myUntrackedFilesHolder.setupVfsListener(project); //myUntrackedFilesHolder cannot be null because it is not light instance
|
||||
repository.setupUpdater();
|
||||
return repository;
|
||||
public static GitRepository getInstance(@NotNull VirtualFile root,
|
||||
@NotNull VirtualFile gitDir,
|
||||
@NotNull Project project,
|
||||
boolean listenToRepoChanges) {
|
||||
GitPlatformFacade platformFacade = ServiceManager.getService(project, GitPlatformFacade.class);
|
||||
return new GitRepositoryImpl(root, gitDir, platformFacade, project, project, !listenToRepoChanges);
|
||||
}
|
||||
|
||||
private void setupUpdater() {
|
||||
|
||||
Reference in New Issue
Block a user