[git] Pass PlatformFacade to GitRepositoryImpl

Instead of querying it via the ServiceManager.
Thus GitRepositoryImpl can be used in light tests.
This commit is contained in:
Kirill Likhodedov
2012-10-06 16:27:28 +04:00
parent a3c0caad94
commit ad468166d9
6 changed files with 31 additions and 18 deletions
@@ -15,6 +15,7 @@
*/
package git4idea.history.browser;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Getter;
@@ -27,6 +28,7 @@ import com.intellij.util.AsynchConsumer;
import git4idea.GitBranch;
import git4idea.GitTag;
import git4idea.GitUtil;
import git4idea.PlatformFacade;
import git4idea.branch.GitBranchesCollection;
import git4idea.config.GitConfigUtil;
import git4idea.history.GitHistoryUtils;
@@ -110,7 +112,7 @@ public class LowLevelAccessImpl implements LowLevelAccess {
if (! child.exists()) {
throw new VcsException("No git repository in " + myRoot.getPath());
}
repository = GitRepositoryImpl.getLightInstance(myRoot, myProject, myProject);
repository = GitRepositoryImpl.getLightInstance(myRoot, myProject, ServiceManager.getService(myProject, PlatformFacade.class), myProject);
repository.update(GitRepository.TrackedTopic.BRANCHES);
repository.getBranches();
}
@@ -16,10 +16,10 @@
package git4idea.repo;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
import com.intellij.util.concurrency.QueueProcessor;
@@ -43,6 +43,7 @@ public class GitRepositoryImpl implements GitRepository, Disposable {
private static final Object STUB_OBJECT = new Object();
private final Project myProject;
@NotNull private final PlatformFacade myPlatformFacade;
private final VirtualFile myRootDir;
private final GitRepositoryReader myReader;
private final VirtualFile myGitDir;
@@ -59,11 +60,12 @@ public class GitRepositoryImpl implements GitRepository, Disposable {
/**
* 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(com.intellij.openapi.vfs.VirtualFile, com.intellij.openapi.project.Project, com.intellij.openapi.Disposable)}.
* {@link #getLightInstance(VirtualFile, Project, PlatformFacade, Disposable)}.
*/
private GitRepositoryImpl(@NotNull VirtualFile rootDir, @NotNull Project project, @NotNull Disposable parentDisposable,
final boolean light) {
private GitRepositoryImpl(@NotNull VirtualFile rootDir, @NotNull PlatformFacade facade, @NotNull Project project,
@NotNull Disposable parentDisposable, final boolean light) {
myRootDir = rootDir;
myPlatformFacade = facade;
myProject = project;
Disposer.register(parentDisposable, this);
@@ -77,11 +79,10 @@ public class GitRepositoryImpl implements GitRepository, Disposable {
if (! light) {
myUntrackedFilesHolder = new GitUntrackedFilesHolder(this);
Disposer.register(this, myUntrackedFilesHolder);
update(TrackedTopic.ALL);
} else {
myUntrackedFilesHolder = null;
}
update(TrackedTopic.ALL);
}
/**
@@ -90,16 +91,18 @@ public class GitRepositoryImpl implements GitRepository, Disposable {
* {@link GitUntrackedFilesHolder}.
*/
@NotNull
public static GitRepository getLightInstance(@NotNull VirtualFile root, @NotNull Project project, @NotNull Disposable parentDisposable) {
return new GitRepositoryImpl(root, project, parentDisposable, true);
public static GitRepository getLightInstance(@NotNull VirtualFile root, @NotNull Project project, @NotNull PlatformFacade facade,
@NotNull Disposable parentDisposable) {
return new GitRepositoryImpl(root, facade, project, parentDisposable, true);
}
/**
* 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}.
*/
public static GitRepository getFullInstance(@NotNull VirtualFile root, @NotNull Project project, @NotNull Disposable parentDisposable) {
GitRepositoryImpl repository = new GitRepositoryImpl(root, project, parentDisposable, false);
public static GitRepository getFullInstance(@NotNull VirtualFile root, @NotNull Project project, @NotNull PlatformFacade facade,
@NotNull Disposable parentDisposable) {
GitRepositoryImpl repository = new GitRepositoryImpl(root, facade, project, parentDisposable, false);
repository.myUntrackedFilesHolder.setupVfsListener(project);
repository.setupUpdater();
return repository;
@@ -240,8 +243,8 @@ public class GitRepositoryImpl implements GitRepository, Disposable {
}
private void updateConfig() {
File configFile = new File(VfsUtil.virtualToIoFile(myGitDir), "config");
myConfig = GitConfig.read(ServiceManager.getService(PlatformFacade.class), configFile);
File configFile = new File(VfsUtilCore.virtualToIoFile(myGitDir), "config");
myConfig = GitConfig.read(myPlatformFacade, configFile);
}
/**
@@ -50,9 +50,11 @@ public class GitRepositoryManagerImpl extends AbstractProjectComponent implement
@NotNull private final Set<GitRepositoryChangeListener> myListeners = new HashSet<GitRepositoryChangeListener>();
@NotNull private final ReentrantReadWriteLock REPO_LOCK = new ReentrantReadWriteLock();
@NotNull private final PlatformFacade myPlatformFacade;
public GitRepositoryManagerImpl(@NotNull Project project, @NotNull PlatformFacade platformFacade) {
super(project);
myPlatformFacade = platformFacade;
myVcsManager = ProjectLevelVcsManager.getInstance(myProject);
myVcs = platformFacade.getVcs(myProject);
}
@@ -227,7 +229,7 @@ public class GitRepositoryManagerImpl extends AbstractProjectComponent implement
}
private GitRepository createGitRepository(VirtualFile root) {
GitRepository repository = GitRepositoryImpl.getFullInstance(root, myProject, this);
GitRepository repository = GitRepositoryImpl.getFullInstance(root, myProject, myPlatformFacade, this);
for (GitRepositoryChangeListener listener : myListeners) {
repository.addListener(listener);
}
@@ -60,7 +60,7 @@ class GitCrlfProblemsDetectorTest {
git ("init")
GitRepository repository = GitRepositoryImpl.getLightInstance(new GitMockVirtualFile(myRootDir), myProject, myProject)
GitRepository repository = GitRepositoryImpl.getLightInstance(new GitMockVirtualFile(myRootDir), myProject, myPlatformFacade, myProject)
((GitTestRepositoryManager)myPlatformFacade.getRepositoryManager(myProject)).add(repository)
}
@@ -15,8 +15,10 @@
*/
package git4idea.repo;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.vfs.VfsUtil;
import git4idea.GitBranch;
import git4idea.PlatformFacade;
import git4idea.tests.GitTest;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -48,7 +50,8 @@ public class GitRepositoryTest extends GitTest {
@BeforeMethod
public void setUp(Method testMethod) throws Exception {
super.setUp(testMethod);
myRepository = GitRepositoryImpl.getFullInstance(myRepo.getVFRootDir(), myProject, myProject);
PlatformFacade facade = ServiceManager.getService(myProject, PlatformFacade.class);
myRepository = GitRepositoryImpl.getFullInstance(myRepo.getVFRootDir(), myProject, facade, myProject);
myReader = new GitRepositoryReader(new File(VfsUtil.virtualToIoFile(myRepository.getRoot()), ".git"));
}
@@ -15,6 +15,7 @@
*/
package git4idea.test;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
@@ -22,6 +23,7 @@ import com.intellij.testFramework.vcs.AbstractVcsTestCase;
import com.intellij.testFramework.VfsTestUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ui.UIUtil;
import git4idea.PlatformFacade;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryImpl;
import org.jetbrains.annotations.NotNull;
@@ -42,7 +44,7 @@ public class GitExec {
public static GitRepository init(@NotNull Project project, @NotNull VirtualFile root) throws IOException {
new GitTestRunEnv(new File(root.getPath())).run("init");
root.refresh(false, true);
return GitRepositoryImpl.getLightInstance(root, project, project);
return GitRepositoryImpl.getLightInstance(root, project, ServiceManager.getService(project, PlatformFacade.class), project);
}
/**
@@ -58,7 +60,8 @@ public class GitExec {
VirtualFile root = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(destinationPath));
assert root != null;
root.refresh(false, true);
return bare ? null : GitRepositoryImpl.getLightInstance(root, project, project);
return bare ? null : GitRepositoryImpl.getLightInstance(root, project,
ServiceManager.getService(project, PlatformFacade.class), project);
}
public static String push(@NotNull GitRepository repository, String... args) throws IOException {