Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
Bas Leijdekkers
2012-03-13 11:09:31 +01:00
41 changed files with 598 additions and 289 deletions
+3 -1
View File
@@ -74,7 +74,9 @@
<project-components>
<component>
<implementation-class>git4idea.repo.GitRepositoryManager</implementation-class>
<interface-class>git4idea.repo.GitRepositoryManager</interface-class>
<implementation-class>git4idea.repo.GitRepositoryManagerImpl</implementation-class>
<headless-implementation-class>git4idea.test.GitTestRepositoryManager</headless-implementation-class>
</component>
</project-components>
+11 -1
View File
@@ -15,6 +15,7 @@
*/
package git4idea;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
@@ -561,7 +562,11 @@ public class GitUtil {
}
public static boolean justOneGitRepository(Project project) {
return !GitRepositoryManager.getInstance(project).moreThanOneRoot();
GitRepositoryManager manager = getRepositoryManager(project);
if (manager == null) {
return true;
}
return !manager.moreThanOneRoot();
}
public static List<GitRepository> sortRepositories(@NotNull Collection<GitRepository> repositories) {
@@ -708,4 +713,9 @@ public class GitUtil {
}
return affectedChanges;
}
@Nullable
public static GitRepositoryManager getRepositoryManager(@NotNull Project project) {
return ServiceManager.getService(project, GitRepositoryManager.class);
}
}
@@ -37,6 +37,7 @@ import com.intellij.ui.components.JBList;
import git4idea.GitBranch;
import git4idea.GitFileRevision;
import git4idea.GitRevisionNumber;
import git4idea.GitUtil;
import git4idea.history.GitHistoryUtils;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
@@ -64,7 +65,11 @@ public class GitCompareWithBranchAction extends DumbAwareAction {
final VirtualFile file = getAffectedFile(event);
GitRepository repository = GitRepositoryManager.getInstance(project).getRepositoryForFile(file);
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager == null) {
return;
}
GitRepository repository = manager.getRepositoryForFile(file);
assert repository != null;
final String head = repository.getCurrentRevision();
@@ -126,7 +131,14 @@ public class GitCompareWithBranchAction extends DumbAwareAction {
return;
}
GitRepository repository = GitRepositoryManager.getInstance(project).getRepositoryForFile(vFiles[0]);
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager == null) {
presentation.setEnabled(false);
presentation.setVisible(true);
return;
}
GitRepository repository = manager.getRepositoryForFile(vFiles[0]);
if (repository == null || repository.isFresh() || noBranchesToCompare(repository)) {
presentation.setEnabled(false);
presentation.setVisible(true);
@@ -22,6 +22,7 @@ import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.update.ActionInfo;
import com.intellij.openapi.vfs.VirtualFile;
import git4idea.GitRevisionNumber;
import git4idea.GitUtil;
import git4idea.commands.GitHandlerUtil;
import git4idea.commands.GitLineHandler;
import git4idea.i18n.GitBundle;
@@ -71,7 +72,10 @@ public class GitMerge extends GitRepositoryAction {
}
finally {
exceptions.addAll(h.errors());
GitRepositoryManager.getInstance(project).updateRepository(root, GitRepository.TrackedTopic.ALL_CURRENT);
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager != null) {
manager.updateRepository(root, GitRepository.TrackedTopic.ALL_CURRENT);
}
}
if (exceptions.size() != 0) {
return;
@@ -71,7 +71,12 @@ public class GitPull extends GitRepositoryAction {
new Task.Modal(project, GitBundle.message("pulling.title", dialog.getRemote()), true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
GitRepository repository = GitRepositoryManager.getInstance(project).getRepositoryForRoot(dialog.gitRoot());
final GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(myProject);
if (repositoryManager == null) {
return;
}
GitRepository repository = repositoryManager.getRepositoryForRoot(dialog.gitRoot());
assert repository != null : "Repository can't be null for root " + dialog.gitRoot();
String remoteOrUrl = dialog.getRemote();
@@ -108,13 +113,13 @@ public class GitPull extends GitRepositoryAction {
@Override
protected void onSuccess() {
GitMergeUtil.showUpdates(GitPull.this, project, exceptions, root, currentRev, beforeLabel, getActionName(), ActionInfo.UPDATE);
GitRepositoryManager.getInstance(project).updateRepository(root, GitRepository.TrackedTopic.ALL);
repositoryManager.updateRepository(root, GitRepository.TrackedTopic.ALL);
}
@Override
protected void onFailure() {
GitUIUtil.notifyGitErrors(project, "Error pulling " + dialog.getRemote(), "", handlerReference.get().errors());
GitRepositoryManager.getInstance(project).updateRepository(root, GitRepository.TrackedTopic.ALL);
repositoryManager.updateRepository(root, GitRepository.TrackedTopic.ALL);
}
});
}
@@ -19,7 +19,11 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vfs.VirtualFile;
import git4idea.commands.*;
import git4idea.GitUtil;
import git4idea.commands.GitLineHandler;
import git4idea.commands.GitTask;
import git4idea.commands.GitTaskResult;
import git4idea.commands.GitTaskResultHandlerAdapter;
import git4idea.i18n.GitBundle;
import git4idea.rebase.GitInteractiveRebaseEditorHandler;
import git4idea.rebase.GitRebaseEditorService;
@@ -62,7 +66,10 @@ public abstract class GitRebaseActionBase extends GitRepositoryAction {
@Override
protected void run(GitTaskResult taskResult) {
editor.close();
GitRepositoryManager.getInstance(project).updateRepository(root, GitRepository.TrackedTopic.ALL_CURRENT);
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager != null) {
manager.updateRepository(root, GitRepository.TrackedTopic.ALL_CURRENT);
}
notifyAboutErrorResult(taskResult, resultListener, exceptions, project);
}
});
@@ -15,7 +15,10 @@
*/
package git4idea.actions;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.ActionPlaces;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.DumbAwareAction;
@@ -113,7 +116,11 @@ public abstract class GitRepositoryAction extends DumbAwareAction {
final VirtualFile[] files = e.getData(PlatformDataKeys.VIRTUAL_FILE_ARRAY);
if (files != null) {
for (VirtualFile file : files) {
final GitRepository repositoryForFile = GitRepositoryManager.getInstance(project).getRepositoryForFile(file);
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager == null) {
return false;
}
final GitRepository repositoryForFile = manager.getRepositoryForFile(file);
if (repositoryForFile != null && repositoryForFile.getState() == GitRepository.State.REBASING) {
return true;
}
@@ -18,6 +18,7 @@ package git4idea.actions;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vfs.VirtualFile;
import git4idea.GitUtil;
import git4idea.commands.GitHandlerUtil;
import git4idea.commands.GitLineHandler;
import git4idea.i18n.GitBundle;
@@ -57,6 +58,9 @@ public class GitResetHead extends GitRepositoryAction {
GitLineHandler h = d.handler();
affectedRoots.add(d.getGitRoot());
GitHandlerUtil.doSynchronously(h, GitBundle.getString("resetting.title"), h.printableCommandLine());
GitRepositoryManager.getInstance(project).updateRepository(d.getGitRoot(), GitRepository.TrackedTopic.ALL_CURRENT);
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager != null) {
manager.updateRepository(d.getGitRoot(), GitRepository.TrackedTopic.ALL_CURRENT);
}
}
}
@@ -24,9 +24,9 @@ import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vcs.changes.ContentRevision;
import com.intellij.openapi.vfs.VirtualFile;
import git4idea.GitUtil;
import git4idea.GitVcs;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import org.jetbrains.annotations.NotNull;
import java.util.*;
@@ -71,7 +71,7 @@ public class GitResolveConflictsAction extends GitAction {
AbstractVcsHelper.getInstance(project).showMergeDialog(new ArrayList<VirtualFile>(conflictedFiles), GitVcs.getInstance(project).getMergeProvider());
for (VirtualFile conflictedFile : conflictedFiles) {
final GitRepository repo = GitRepositoryManager.getInstance(project).getRepositoryForFile(conflictedFile);
final GitRepository repo = GitUtil.getRepositoryManager(project).getRepositoryForFile(conflictedFile);
if (repo != null) {
repo.update(GitRepository.TrackedTopic.ALL_CURRENT);
}
@@ -23,6 +23,7 @@ import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vcs.changes.ui.RollbackChangesDialog;
import com.intellij.openapi.vfs.VirtualFile;
import git4idea.GitUtil;
import git4idea.GitVcs;
import git4idea.i18n.GitBundle;
import git4idea.repo.GitRepository;
@@ -50,9 +51,12 @@ public class GitRevert extends BasicAction {
}
RollbackChangesDialog.rollbackChanges(project, changes);
for (VirtualFile conflictedFile : affectedFiles) {
final GitRepository repo = GitRepositoryManager.getInstance(project).getRepositoryForFile(conflictedFile);
if (repo != null) {
repo.update(GitRepository.TrackedTopic.ALL_CURRENT);
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager != null) {
final GitRepository repo = manager.getRepositoryForFile(conflictedFile);
if (repo != null) {
repo.update(GitRepository.TrackedTopic.ALL_CURRENT);
}
}
}
return false;
@@ -404,7 +404,7 @@ public class GitChangeUtils {
fullComment = commentSubject;
}
else {
fullComment = commentBody + "\n\n" + commentSubject;
fullComment = commentSubject + "\n" + commentBody;
}
GitRevisionNumber thisRevision = new GitRevisionNumber(revisionNumber, commitDate);
@@ -330,8 +330,10 @@ public class GitCheckinEnvironment implements CheckinEnvironment {
}
handler.endOptions();
handler.run();
GitRepositoryManager.getInstance(project).updateRepository(root, GitRepository.TrackedTopic.CURRENT_REVISION,
GitRepository.TrackedTopic.STATE);
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager != null) {
manager.updateRepository(root, GitRepository.TrackedTopic.CURRENT_REVISION, GitRepository.TrackedTopic.STATE);
}
}
catch (VcsException ex) {
exceptions.add(ex);
@@ -474,9 +476,10 @@ public class GitCheckinEnvironment implements CheckinEnvironment {
handler.addParameters(paths);
handler.run();
}
GitRepositoryManager.getInstance(project).updateRepository(root,
GitRepository.TrackedTopic.CURRENT_REVISION,
GitRepository.TrackedTopic.STATE);
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager != null) {
manager.updateRepository(root, GitRepository.TrackedTopic.CURRENT_REVISION, GitRepository.TrackedTopic.STATE);
}
}
@@ -28,6 +28,7 @@ import com.intellij.openapi.vcs.checkin.CheckinHandler;
import com.intellij.openapi.vcs.checkin.VcsCheckinHandlerFactory;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.PairConsumer;
import git4idea.GitUtil;
import git4idea.GitVcs;
import git4idea.config.GitConfigUtil;
import git4idea.config.GitVersion;
@@ -241,7 +242,10 @@ public class GitCheckinHandlerFactory extends VcsCheckinHandlerFactory {
*/
@Nullable
private DetachedRoot getDetachedRoot() {
GitRepositoryManager repositoryManager = GitRepositoryManager.getInstance(myPanel.getProject());
GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(myPanel.getProject());
if (repositoryManager == null) {
return null;
}
for (VirtualFile root : myPanel.getRoots()) {
GitRepository repository = repositoryManager.getRepositoryForRoot(root);
if (repository == null) {
@@ -16,8 +16,8 @@
package git4idea.commands;
import com.intellij.openapi.project.Project;
import git4idea.GitUtil;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
@@ -90,6 +90,6 @@ public final class GitCompoundResult {
}
private boolean onlyOneRepositoryInTheProject() {
return !GitRepositoryManager.getInstance(myProject).moreThanOneRoot();
return !GitUtil.getRepositoryManager(myProject).moreThanOneRoot();
}
}
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.ui.components.JBCheckBox;
import git4idea.GitUtil;
import git4idea.GitVcs;
import git4idea.i18n.GitBundle;
import git4idea.repo.GitRepositoryManager;
@@ -74,7 +75,7 @@ public class GitVcsPanel {
myConvertTextFilesComboBox.setSelectedItem(CRLF_ASK);
myGitField.addBrowseFolderListener(GitBundle.getString("find.git.title"), GitBundle.getString("find.git.description"), project,
FileChooserDescriptorFactory.createSingleFileNoJarsDescriptor());
final GitRepositoryManager repositoryManager = GitRepositoryManager.getInstance(project);
final GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(myProject);
mySyncBranchControl.setVisible(repositoryManager != null && repositoryManager.moreThanOneRoot());
}
@@ -26,12 +26,12 @@ import com.intellij.openapi.vcs.FilePathImpl;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
import com.intellij.openapi.vcs.merge.MergeDialogCustomizer;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ArrayUtil;
import com.intellij.util.AsynchConsumer;
import git4idea.GitBranch;
import git4idea.GitTag;
import git4idea.GitUtil;
import git4idea.GitVcs;
import git4idea.branch.GitBranchesCollection;
import git4idea.commands.GitCommand;
@@ -43,7 +43,6 @@ import git4idea.history.wholeTree.AbstractHash;
import git4idea.history.wholeTree.CommitHashPlusParents;
import git4idea.merge.GitConflictResolver;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -116,7 +115,7 @@ public class LowLevelAccessImpl implements LowLevelAccess {
// uses cached version
public CachedRefs getRefs() throws VcsException {
final CachedRefs refs = new CachedRefs();
final GitRepository repositoryForRoot = GitRepositoryManager.getInstance(myProject).getRepositoryForRoot(myRoot);
final GitRepository repositoryForRoot = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(myRoot);
final GitBranchesCollection branches;
if (repositoryForRoot != null) {
branches = repositoryForRoot.getBranches();
@@ -57,6 +57,7 @@ import com.intellij.util.ui.AdjustComponentWhenShown;
import com.intellij.util.ui.ColumnInfo;
import com.intellij.util.ui.UIUtil;
import com.intellij.vcsUtil.VcsUtil;
import git4idea.GitUtil;
import git4idea.GitVcs;
import git4idea.changes.GitChangeUtils;
import git4idea.history.browser.*;
@@ -2326,7 +2327,7 @@ public class GitLogUI implements Disposable {
if (commitAt.holdsDecoration() || myTableModel.isStashed(commitAt)) return;
final GitRepository repository =
GitRepositoryManager.getInstance(myProject).getRepositoryForRoot(commitAt.selectRepository(myRootsUnderVcs));
GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(commitAt.selectRepository(myRootsUnderVcs));
if (repository == null) return;
new GitBranchOperationsProcessor(repository, myRefresh).checkout(commitAt.getHash().getString());
}
@@ -2350,7 +2351,7 @@ public class GitLogUI implements Disposable {
if (commitAt.holdsDecoration() || myTableModel.isStashed(commitAt)) return;
final GitRepository repository =
GitRepositoryManager.getInstance(myProject).getRepositoryForRoot(commitAt.selectRepository(myRootsUnderVcs));
GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(commitAt.selectRepository(myRootsUnderVcs));
if (repository == null) return;
String reference = commitAt.getHash().getString();
@@ -2390,7 +2391,7 @@ public class GitLogUI implements Disposable {
if (commitAt.holdsDecoration() || myTableModel.isStashed(commitAt)) return;
final GitRepository repository =
GitRepositoryManager.getInstance(myProject).getRepositoryForRoot(commitAt.selectRepository(myRootsUnderVcs));
GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(commitAt.selectRepository(myRootsUnderVcs));
if (repository == null) return;
new GitCreateNewTag(myProject, repository, commitAt.getHash().getString(), myRefresh).execute();
}
@@ -23,6 +23,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.DocumentAdapter;
import com.intellij.util.ArrayUtil;
import git4idea.GitDeprecatedRemote;
import git4idea.GitUtil;
import git4idea.GitVcs;
import git4idea.commands.GitCommand;
import git4idea.commands.GitHandlerUtil;
@@ -31,7 +32,6 @@ import git4idea.commands.GitSimpleHandler;
import git4idea.i18n.GitBundle;
import git4idea.jgit.GitHttpAdapter;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import git4idea.util.GitUIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -183,7 +183,7 @@ public class GitPullDialog extends DialogWrapper {
@NotNull
private Collection<String> getRemoteBranches(@NotNull GitDeprecatedRemote remote) {
if (GitHttpAdapter.shouldUseJGit(remote.fetchUrl())) {
GitRepository repository = GitRepositoryManager.getInstance(myProject).getRepositoryForRoot(gitRoot());
GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(gitRoot());
if (repository == null) {
return Collections.emptyList();
}
@@ -30,7 +30,6 @@ import git4idea.GitUtil;
import git4idea.history.browser.GitCommit;
import git4idea.repo.GitRemote;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -67,7 +66,7 @@ public class GitPushDialog extends DialogWrapper {
myProject = project;
myPusher = new GitPusher(myProject, new EmptyProgressIndicator());
myRepositories = GitRepositoryManager.getInstance(myProject).getRepositories();
myRepositories = GitUtil.getRepositoryManager(myProject).getRepositories();
myLoadingPanel = new JBLoadingPanel(new BorderLayout(), this.getDisposable());
@@ -122,7 +122,7 @@ public final class GitPusher {
public GitPusher(@NotNull Project project, @NotNull ProgressIndicator indicator) {
myProject = project;
myProgressIndicator = indicator;
myRepositoryManager = GitRepositoryManager.getInstance(myProject);
myRepositoryManager = GitUtil.getRepositoryManager(myProject);
myRepositories = myRepositoryManager.getRepositories();
mySettings = GitVcsSettings.getInstance(myProject);
myPushSettings = GitPushSettings.getInstance(myProject);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,253 +15,52 @@
*/
package git4idea.repo;
import com.intellij.ProjectTopics;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.AbstractProjectComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.DumbAwareRunnable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.openapi.roots.ModuleRootListener;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Consumer;
import com.intellij.util.concurrency.QueueProcessor;
import com.intellij.util.messages.MessageBus;
import git4idea.GitUtil;
import git4idea.PlatformFacade;
import git4idea.roots.GitRootProblemNotifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.List;
/**
* GitRepositoryManager initializes and stores {@link GitRepository GitRepositories} for Git roots defined in the project.
* @author Kirill Likhodedov
*/
public final class GitRepositoryManager extends AbstractProjectComponent implements Disposable {
private static final Logger LOG = Logger.getInstance(GitRepositoryManager.class);
@NotNull private final AbstractVcs myVcs;
@NotNull private final ProjectLevelVcsManager myVcsManager;
@NotNull private final Map<VirtualFile, GitRepository> myRepositories = new HashMap<VirtualFile, GitRepository>();
@NotNull private final Set<GitRepositoryChangeListener> myListeners = new HashSet<GitRepositoryChangeListener>();
@NotNull private final ReentrantReadWriteLock REPO_LOCK = new ReentrantReadWriteLock();
@NotNull private final Object ROOT_SCAN_STUB_OBJECT = new Object();
private final Consumer<Object> myRootScanTask = new Consumer<Object>() {
@Override
public void consume(Object o) {
if (!myProject.isDisposed()) {
GitRootProblemNotifier.getInstance(myProject).rescanAndNotifyIfNeeded();
}
}
};
@NotNull private final QueueProcessor<Object> myRootScanQueue = new QueueProcessor<Object>(myRootScanTask);
@Nullable
public static GitRepositoryManager getInstance(@NotNull Project project) {
return ServiceManager.getService(project, GitRepositoryManager.class);
}
public GitRepositoryManager(@NotNull Project project, @NotNull PlatformFacade platformFacade) {
super(project);
myVcsManager = ProjectLevelVcsManager.getInstance(myProject);
myVcs = platformFacade.getVcs(myProject);
}
@Override
public void initComponent() {
Disposer.register(myProject, this);
StartupManager.getInstance(myProject).runWhenProjectIsInitialized(new DumbAwareRunnable() {
@Override
public void run() {
final MessageBus messageBus = myProject.getMessageBus();
final MyRepositoryCreationDeletionListener rootChangeListener = new MyRepositoryCreationDeletionListener();
messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, rootChangeListener);
messageBus.connect().subscribe(ProjectTopics.PROJECT_ROOTS, rootChangeListener);
updateRepositoriesCollection();
}
});
}
@Override
public void dispose() {
try {
REPO_LOCK.writeLock().lock();
myRepositories.clear();
myListeners.clear();
}
finally {
REPO_LOCK.writeLock().unlock();
}
}
public interface GitRepositoryManager {
/**
* Returns the {@link GitRepository} which tracks the Git repository located in the given directory,
* or {@code null} if the given file is not a Git root known to this {@link Project}.
* or {@code null} if the given file is not a Git root known to this {@link com.intellij.openapi.project.Project}.
*/
@Nullable
public GitRepository getRepositoryForRoot(@Nullable VirtualFile root) {
if (root == null) {
return null;
}
try {
REPO_LOCK.readLock().lock();
return myRepositories.get(root);
}
finally {
REPO_LOCK.readLock().unlock();
}
}
GitRepository getRepositoryForRoot(@Nullable VirtualFile root);
/**
* Returns the {@link GitRepository} which the given file belongs to, or {@code null} if the file is not under any Git repository.
*/
@Nullable
public GitRepository getRepositoryForFile(@NotNull VirtualFile file) {
final VirtualFile vcsRoot = myVcsManager.getVcsRootFor(file);
if (vcsRoot == null) { return null; }
return getRepositoryForRoot(vcsRoot);
}
GitRepository getRepositoryForFile(@NotNull VirtualFile file);
/**
* @return all repositories tracked by the manager.
*/
@NotNull
public List<GitRepository> getRepositories() {
try {
REPO_LOCK.readLock().lock();
return GitUtil.sortRepositories(myRepositories.values());
}
finally {
REPO_LOCK.readLock().unlock();
}
}
List<GitRepository> getRepositories();
public boolean moreThanOneRoot() {
return myRepositories.values().size() > 1;
}
boolean moreThanOneRoot();
/**
* Adds the listener to all existing repositories AND all future repositories.
* I.e. if a new GitRepository is be created via this GitRepositoryManager, the listener will be added to the repository.
*/
public void addListenerToAllRepositories(@NotNull GitRepositoryChangeListener listener) {
myListeners.add(listener);
for (GitRepository repo : getRepositories()) {
repo.addListener(listener);
}
}
void addListenerToAllRepositories(@NotNull GitRepositoryChangeListener listener);
/**
* Synchronously updates the specified information about Git repository under the given root.
* @param root root directory of the Git repository.
* @param topics TrackedTopics that are to be updated.
*/
public void updateRepository(VirtualFile root, GitRepository.TrackedTopic... topics) {
GitRepository repo = getRepositoryForRoot(root);
if (repo != null) {
repo.update(topics);
}
}
void updateRepository(VirtualFile root, GitRepository.TrackedTopic... topics);
public void updateAllRepositories(GitRepository.TrackedTopic... topics) {
for (VirtualFile root : myRepositories.keySet()) {
updateRepository(root, topics);
}
}
void updateAllRepositories(GitRepository.TrackedTopic... topics);
// note: we are not calling this method during the project startup - it is called anyway by the GitRootTracker
private void updateRepositoriesCollection() {
try {
REPO_LOCK.writeLock().lock();
final VirtualFile[] roots = myVcsManager.getRootsUnderVcs(myVcs);
// remove repositories that are not in the roots anymore
for (Iterator<Map.Entry<VirtualFile, GitRepository>> iterator = myRepositories.entrySet().iterator(); iterator.hasNext(); ) {
if (!ArrayUtil.contains(iterator.next().getValue().getRoot(), roots)) {
iterator.remove();
}
}
// add GitRepositories for all roots that don't have correspondent GitRepositories yet.
for (VirtualFile root : roots) {
if (!myRepositories.containsKey(root)) {
if (gitRootOK(root)) {
GitRepository repository = createGitRepository(root);
myRepositories.put(root, repository);
}
else {
LOG.info("Invalid Git root: " + root);
}
}
}
}
finally {
REPO_LOCK.writeLock().unlock();
}
if (ApplicationManager.getApplication().isUnitTestMode()) {
myRootScanTask.consume(ROOT_SCAN_STUB_OBJECT);
}
else {
myRootScanQueue.add(ROOT_SCAN_STUB_OBJECT);
}
}
private static boolean gitRootOK(@NotNull VirtualFile root) {
VirtualFile gitDir = root.findChild(".git");
return gitDir != null && gitDir.exists();
}
private GitRepository createGitRepository(VirtualFile root) {
GitRepository repository = GitRepository.getFullInstance(root, myProject, this);
for (GitRepositoryChangeListener listener : myListeners) {
repository.addListener(listener);
}
return repository;
}
@Override
public String toString() {
return "GitRepositoryManager{myRepositories: " + myRepositories + '}';
}
private class MyRepositoryCreationDeletionListener implements BulkFileListener, ModuleRootListener {
@Override
public void before(@NotNull List<? extends VFileEvent> events) {
}
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
for (VFileEvent event : events) {
VirtualFile file = event.getFile();
if (file != null && file.getName().equalsIgnoreCase(".git") && file.isDirectory()) {
updateRepositoriesCollection();
}
}
}
@Override
public void beforeRootsChange(ModuleRootEvent event) {
}
@Override
public void rootsChanged(ModuleRootEvent event) {
updateRepositoriesCollection();
}
}
}
@@ -0,0 +1,192 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package git4idea.repo;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.components.AbstractProjectComponent;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.DumbAwareRunnable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vcs.AbstractVcs;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ArrayUtil;
import git4idea.GitUtil;
import git4idea.PlatformFacade;
import git4idea.roots.GitRootScanner;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
* @author Kirill Likhodedov
*/
public class GitRepositoryManagerImpl extends AbstractProjectComponent implements Disposable, GitRepositoryManager {
private static final Logger LOG = Logger.getInstance(GitRepositoryManager.class);
@NotNull private final AbstractVcs myVcs;
@NotNull private final ProjectLevelVcsManager myVcsManager;
@NotNull private final Map<VirtualFile, GitRepository> myRepositories = new HashMap<VirtualFile, GitRepository>();
@NotNull private final Set<GitRepositoryChangeListener> myListeners = new HashSet<GitRepositoryChangeListener>();
@NotNull private final ReentrantReadWriteLock REPO_LOCK = new ReentrantReadWriteLock();
public GitRepositoryManagerImpl(@NotNull Project project, @NotNull PlatformFacade platformFacade) {
super(project);
myVcsManager = ProjectLevelVcsManager.getInstance(myProject);
myVcs = platformFacade.getVcs(myProject);
}
@Override
public void initComponent() {
Disposer.register(myProject, this);
GitRootScanner rootScanner = new GitRootScanner(myProject, new DumbAwareRunnable() {
@Override
public void run() {
updateRepositoriesCollection();
}
});
Disposer.register(this, rootScanner);
}
@Override
public void dispose() {
try {
REPO_LOCK.writeLock().lock();
myRepositories.clear();
myListeners.clear();
}
finally {
REPO_LOCK.writeLock().unlock();
}
}
@Override
@Nullable
public GitRepository getRepositoryForRoot(@Nullable VirtualFile root) {
if (root == null) {
return null;
}
try {
REPO_LOCK.readLock().lock();
return myRepositories.get(root);
}
finally {
REPO_LOCK.readLock().unlock();
}
}
@Override
@Nullable
public GitRepository getRepositoryForFile(@NotNull VirtualFile file) {
final VirtualFile vcsRoot = myVcsManager.getVcsRootFor(file);
if (vcsRoot == null) { return null; }
return getRepositoryForRoot(vcsRoot);
}
@Override
@NotNull
public List<GitRepository> getRepositories() {
try {
REPO_LOCK.readLock().lock();
return GitUtil.sortRepositories(myRepositories.values());
}
finally {
REPO_LOCK.readLock().unlock();
}
}
@Override
public boolean moreThanOneRoot() {
return myRepositories.values().size() > 1;
}
@Override
public void addListenerToAllRepositories(@NotNull GitRepositoryChangeListener listener) {
myListeners.add(listener);
for (GitRepository repo : getRepositories()) {
repo.addListener(listener);
}
}
@Override
public void updateRepository(VirtualFile root, GitRepository.TrackedTopic... topics) {
GitRepository repo = getRepositoryForRoot(root);
if (repo != null) {
repo.update(topics);
}
}
@Override
public void updateAllRepositories(GitRepository.TrackedTopic... topics) {
for (VirtualFile root : myRepositories.keySet()) {
updateRepository(root, topics);
}
}
// note: we are not calling this method during the project startup - it is called anyway by the GitRootTracker
private void updateRepositoriesCollection() {
try {
REPO_LOCK.writeLock().lock();
final VirtualFile[] roots = myVcsManager.getRootsUnderVcs(myVcs);
// remove repositories that are not in the roots anymore
for (Iterator<Map.Entry<VirtualFile, GitRepository>> iterator = myRepositories.entrySet().iterator(); iterator.hasNext(); ) {
if (!ArrayUtil.contains(iterator.next().getValue().getRoot(), roots)) {
iterator.remove();
}
}
// add GitRepositories for all roots that don't have correspondent GitRepositories yet.
for (VirtualFile root : roots) {
if (!myRepositories.containsKey(root)) {
if (gitRootOK(root)) {
GitRepository repository = createGitRepository(root);
myRepositories.put(root, repository);
}
else {
LOG.info("Invalid Git root: " + root);
}
}
}
}
finally {
REPO_LOCK.writeLock().unlock();
}
}
private static boolean gitRootOK(@NotNull VirtualFile root) {
VirtualFile gitDir = root.findChild(".git");
return gitDir != null && gitDir.exists();
}
private GitRepository createGitRepository(VirtualFile root) {
GitRepository repository = GitRepository.getFullInstance(root, myProject, this);
for (GitRepositoryChangeListener listener : myListeners) {
repository.addListener(listener);
}
return repository;
}
@Override
public String toString() {
return "GitRepositoryManager{myRepositories: " + myRepositories + '}';
}
}
@@ -26,6 +26,7 @@ import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
import com.intellij.openapi.vfs.newvfs.events.*;
import com.intellij.util.messages.MessageBusConnection;
import git4idea.GitUtil;
import git4idea.commands.Git;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -295,7 +296,7 @@ public class GitUntrackedFilesHolder implements Disposable, BulkFileListener {
}
private boolean belongsToThisRepository(VirtualFile file) {
final GitRepository repository = GitRepositoryManager.getInstance(myProject).getRepositoryForFile(file);
final GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForFile(file);
return repository != null && repository.getRoot().equals(myRoot);
}
@@ -29,13 +29,12 @@ import com.intellij.vcsUtil.VcsFileUtil;
import com.intellij.vcsUtil.VcsUtil;
import git4idea.GitUtil;
import git4idea.commands.GitCommand;
import git4idea.util.GitFileUtils;
import git4idea.commands.GitHandlerUtil;
import git4idea.commands.GitSimpleHandler;
import git4idea.i18n.GitBundle;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import git4idea.repo.GitUntrackedFilesHolder;
import git4idea.util.GitFileUtils;
import org.jetbrains.annotations.NotNull;
import java.io.File;
@@ -165,7 +164,7 @@ public class GitRollbackEnvironment implements RollbackEnvironment {
}
lfs.refreshIoFiles(filesToRefresh);
for (GitRepository repo : GitRepositoryManager.getInstance(myProject).getRepositories()) {
for (GitRepository repo : GitUtil.getRepositoryManager(myProject).getRepositories()) {
repo.update(GitRepository.TrackedTopic.ALL_CURRENT);
}
}
@@ -200,7 +199,7 @@ public class GitRollbackEnvironment implements RollbackEnvironment {
GitFileUtils.delete(myProject, root, files, "--cached", "-f");
if (toUnversioned) {
final GitRepository repo = GitRepositoryManager.getInstance(myProject).getRepositoryForRoot(root);
final GitRepository repo = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(root);
final GitUntrackedFilesHolder untrackedFilesHolder = (repo == null ? null : repo.getUntrackedFilesHolder());
for (FilePath path : files) {
final VirtualFile vf = VcsUtil.getVirtualFile(path.getIOFile());
@@ -0,0 +1,142 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package git4idea.roots;
import com.intellij.ProjectTopics;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.DumbAwareRunnable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.openapi.roots.ModuleRootListener;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.VcsListener;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
import com.intellij.util.messages.MessageBus;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.util.List;
/**
* @author Kirill Likhodedov
*/
public class GitRootScanner implements BulkFileListener, ModuleRootListener, Disposable, VcsListener {
@NotNull private final Runnable myExecuteAfterScan;
@NotNull private final GitRootProblemNotifier myRootProblemNotifier;
private volatile boolean myProjectIsInitialized;
private volatile boolean myMappingsAreReady;
private volatile boolean myScanning;
@NotNull private final Object SCAN_LOCK = new Object();
public GitRootScanner(@NotNull Project project, @NotNull Runnable executeAfterScan) {
myExecuteAfterScan = executeAfterScan;
StartupManager.getInstance(project).runWhenProjectIsInitialized(new DumbAwareRunnable() {
@Override
public void run() {
myProjectIsInitialized = true;
scanIfReady();
}
});
final MessageBus messageBus = project.getMessageBus();
messageBus.connect().subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, this);
messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, this);
messageBus.connect().subscribe(ProjectTopics.PROJECT_ROOTS, this);
myRootProblemNotifier = GitRootProblemNotifier.getInstance(project);
}
@Override
public void dispose() {
}
@Override
public void before(@NotNull List<? extends VFileEvent> events) {
}
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
for (VFileEvent event : events) {
VirtualFile file = event.getFile();
if (file != null && file.getName().equalsIgnoreCase(".git") && file.isDirectory()) {
scanIfReady();
}
}
}
@Override
public void beforeRootsChange(ModuleRootEvent event) {
}
@Override
public void rootsChanged(ModuleRootEvent event) {
scanIfReady();
}
@Override
public void directoryMappingChanged() {
myMappingsAreReady = true;
scanIfReady();
}
private void scanIfReady() {
if (readyToScan()) {
scan();
}
}
private void scan() {
if (myScanning) {
return;
}
if (SwingUtilities.isEventDispatchThread()) {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
public void run() {
scanWithLock();
}
});
}
else {
scanWithLock();
}
}
private void scanWithLock() {
synchronized (SCAN_LOCK) {
if (myScanning) {
return;
}
myScanning = true;
myRootProblemNotifier.rescanAndNotifyIfNeeded();
myExecuteAfterScan.run();
myScanning = false;
}
}
private boolean readyToScan() {
return myMappingsAreReady && myProjectIsInitialized;
}
}
@@ -27,16 +27,16 @@ import com.intellij.openapi.vcs.changes.ContentRevision;
import com.intellij.openapi.vcs.changes.VcsDirtyScope;
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
import com.intellij.openapi.vfs.VirtualFile;
import git4idea.commands.Git;
import git4idea.GitContentRevision;
import git4idea.GitFormatException;
import git4idea.GitRevisionNumber;
import git4idea.GitUtil;
import git4idea.changes.GitChangeUtils;
import git4idea.commands.Git;
import git4idea.commands.GitCommand;
import git4idea.commands.GitHandler;
import git4idea.commands.GitSimpleHandler;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import git4idea.repo.GitUntrackedFilesHolder;
import org.jetbrains.annotations.NotNull;
@@ -91,7 +91,7 @@ class GitNewChangesCollector extends GitChangesCollector {
{
super(project, changeListManager, dirtyScope, vcsRoot);
myGit = git;
myRepository = GitRepositoryManager.getInstance(project).getRepositoryForRoot(vcsRoot);
myRepository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(vcsRoot);
Collection<FilePath> dirtyPaths = dirtyPaths(true);
if (!dirtyPaths.isEmpty()) {
@@ -22,14 +22,15 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.DocumentAdapter;
import git4idea.GitUtil;
import git4idea.commands.GitCommand;
import git4idea.commands.GitHandlerUtil;
import git4idea.commands.GitSimpleHandler;
import git4idea.util.GitUIUtil;
import git4idea.util.StringScanner;
import git4idea.i18n.GitBundle;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import git4idea.util.GitUIUtil;
import git4idea.util.StringScanner;
import org.jetbrains.annotations.NonNls;
import javax.swing.*;
@@ -201,7 +202,10 @@ public class GitTagDialog extends DialogWrapper {
}
finally {
exceptions.addAll(h.errors());
GitRepositoryManager.getInstance(myProject).updateRepository(getGitRoot(), GitRepository.TrackedTopic.ALL);
GitRepositoryManager manager = GitUtil.getRepositoryManager(myProject);
if (manager != null) {
manager.updateRepository(getGitRoot(), GitRepository.TrackedTopic.ALL);
}
}
}
finally {
@@ -32,6 +32,7 @@ import com.intellij.openapi.util.IconLoader;
import com.intellij.ui.popup.PopupFactoryImpl;
import com.intellij.ui.popup.WizardPopup;
import com.intellij.ui.popup.list.ListPopupImpl;
import git4idea.GitUtil;
import git4idea.GitVcs;
import git4idea.config.GitVcsSettings;
import git4idea.repo.GitRepository;
@@ -81,7 +82,7 @@ class GitBranchPopup {
private GitBranchPopup(@NotNull Project project, @NotNull GitRepository currentRepository) {
myProject = project;
myCurrentRepository = currentRepository;
myRepositoryManager = GitRepositoryManager.getInstance(project);
myRepositoryManager = GitUtil.getRepositoryManager(project);
myVcs = GitVcs.getInstance(project);
myVcsSettings = GitVcsSettings.getInstance(myProject);
@@ -193,7 +194,7 @@ class GitBranchPopup {
private ActionGroup createActions() {
DefaultActionGroup popupGroup = new DefaultActionGroup(null, false);
GitRepositoryManager repositoryManager = GitRepositoryManager.getInstance(myProject);
GitRepositoryManager repositoryManager = myRepositoryManager;
if (repositoryManager.moreThanOneRoot()) {
if (!myMultiRootBranchConfig.diverged() && userWantsSyncControl()) {
@@ -245,7 +246,7 @@ class GitBranchPopup {
private DefaultActionGroup createRepositoriesActions() {
DefaultActionGroup popupGroup = new DefaultActionGroup(null, false);
popupGroup.addSeparator("Repositories");
for (GitRepository repository : GitRepositoryManager.getInstance(myProject).getRepositories()) {
for (GitRepository repository : myRepositoryManager.getRepositories()) {
popupGroup.add(new RootAction(repository, highlightCurrentRepo() ? myCurrentRepository : null));
}
return popupGroup;
@@ -33,6 +33,7 @@ import com.intellij.openapi.wm.WindowManager;
import com.intellij.openapi.wm.impl.status.StatusBarUtil;
import com.intellij.vcsUtil.VcsUtil;
import git4idea.GitBranch;
import git4idea.GitUtil;
import git4idea.GitVcs;
import git4idea.config.GitVcsSettings;
import git4idea.repo.GitRepository;
@@ -163,7 +164,10 @@ public class GitBranchUiUtil {
if (project == null) {
return null;
}
GitRepositoryManager manager = GitRepositoryManager.getInstance(project);
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager == null) {
return null;
}
VirtualFile file = getSelectedFile(project);
if (file != null) {
return manager.getRepositoryForRoot(getVcsRootFor(project, file));
@@ -25,10 +25,10 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.StatusBarWidget;
import com.intellij.openapi.wm.impl.status.EditorBasedWidget;
import com.intellij.util.Consumer;
import git4idea.GitUtil;
import git4idea.config.GitVcsSettings;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryChangeListener;
import git4idea.repo.GitRepositoryManager;
import org.jetbrains.annotations.NotNull;
import java.awt.event.MouseEvent;
@@ -47,7 +47,7 @@ public class GitBranchWidget extends EditorBasedWidget implements StatusBarWidge
public GitBranchWidget(Project project) {
super(project);
GitRepositoryManager.getInstance(project).addListenerToAllRepositories(this);
GitUtil.getRepositoryManager(project).addListenerToAllRepositories(this);
mySettings = GitVcsSettings.getInstance(project);
myMaxString = "Git: Rebasing master";
}
@@ -161,7 +161,7 @@ public class GitBranchWidget extends EditorBasedWidget implements StatusBarWidge
@NotNull
private static String getDisplayableBranchTooltip(GitRepository repo) {
String text = GitBranchUiUtil.getDisplayableBranchText(repo);
if (GitRepositoryManager.getInstance(repo.getProject()).getRepositories().size() > 1) {
if (!GitUtil.justOneGitRepository(repo.getProject())) {
return text + "\n" + "Root: " + repo.getRoot().getName();
}
return text;
@@ -20,6 +20,7 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import git4idea.GitUtil;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
@@ -36,8 +37,10 @@ public class GitBranchesAction extends DumbAwareAction {
public void actionPerformed(AnActionEvent e) {
final Project project = e.getData(PlatformDataKeys.PROJECT);
assert project != null;
GitRepositoryManager repositoryManager = GitRepositoryManager.getInstance(project);
GitRepositoryManager repositoryManager = GitUtil.getRepositoryManager(project);
if (repositoryManager == null) {
return;
}
VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE);
GitRepository repository = (file == null ?
GitBranchUiUtil.getCurrentRepository(project):
@@ -19,8 +19,8 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.IconLoader;
import com.intellij.ui.TabbedPaneImpl;
import git4idea.GitUtil;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import git4idea.util.GitCommitCompareInfo;
import git4idea.util.GitUIUtil;
import org.jetbrains.annotations.NotNull;
@@ -50,7 +50,7 @@ public class GitCompareBranchesDialog extends DialogWrapper {
myInitialRepo = initialRepo;
String rootString;
if (compareInfo.getRepositories().size() == 1 && GitRepositoryManager.getInstance(myProject).moreThanOneRoot()) {
if (compareInfo.getRepositories().size() == 1 && GitUtil.getRepositoryManager(myProject).moreThanOneRoot()) {
rootString = " in root " + GitUIUtil.getShortRepositoryName(initialRepo);
}
else {
@@ -18,6 +18,7 @@ package git4idea.update;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.util.continuation.*;
import git4idea.GitUtil;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import git4idea.util.GitFreezingProcess;
@@ -91,7 +92,7 @@ public class GitComplexProcess {
myOperation = operation;
myFreezeReason = "Local changes are not available until Git " + myTitle + " is finished.";
myRepositoryManager = GitRepositoryManager.getInstance(project);
myRepositoryManager = GitUtil.getRepositoryManager(myProject);
myChangeListManager = ChangeListManager.getInstance(myProject);
// define tasks that need information from constructor
@@ -24,6 +24,7 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vfs.VirtualFile;
import git4idea.GitBranch;
import git4idea.GitUtil;
import git4idea.GitVcs;
import git4idea.Notificator;
import git4idea.branch.GitBranchUtil;
@@ -72,7 +73,7 @@ public class GitFetcher {
myProject = project;
myProgressIndicator = progressIndicator;
myFetchAll = fetchAll;
myRepositoryManager = GitRepositoryManager.getInstance(project);
myRepositoryManager = GitUtil.getRepositoryManager(myProject);
myVcs = GitVcs.getInstance(project);
}
@@ -21,6 +21,7 @@ import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcsUtil.VcsFileUtil;
import git4idea.GitUtil;
import git4idea.commands.GitBinaryHandler;
import git4idea.commands.GitCommand;
import git4idea.commands.GitSimpleHandler;
@@ -116,7 +117,11 @@ public class GitFileUtils {
handler.setNoSSH(true);
handler.run();
}
final GitRepository repository = GitRepositoryManager.getInstance(project).getRepositoryForRoot(root);
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager == null) {
return;
}
final GitRepository repository = manager.getRepositoryForRoot(root);
if (repository != null) {
repository.getUntrackedFilesHolder().remove(files);
}
@@ -145,7 +150,12 @@ public class GitFileUtils {
* @throws VcsException in case of git problem
*/
public static void addPaths(Project project, VirtualFile root, Collection<FilePath> files) throws VcsException {
final GitRepository repository = GitRepositoryManager.getInstance(project).getRepositoryForRoot(root);
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager == null) {
return;
}
final GitRepository repository = manager.getRepositoryForRoot(root);
final GitUntrackedFilesHolder untrackedFilesHolder = (repository == null ? null : repository.getUntrackedFilesHolder());
for (List<String> paths : VcsFileUtil.chunkPaths(root, files)) {
@@ -29,11 +29,11 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Function;
import git4idea.GitBranch;
import git4idea.GitDeprecatedRemote;
import git4idea.GitUtil;
import git4idea.GitVcs;
import git4idea.config.GitConfigUtil;
import git4idea.i18n.GitBundle;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -236,7 +236,7 @@ public class GitUIUtil {
public void actionPerformed(final ActionEvent e) {
VirtualFile root = (VirtualFile)gitRootChooser.getSelectedItem();
assert root != null : "The root must not be null";
GitRepository repo = GitRepositoryManager.getInstance(project).getRepositoryForRoot(root);
GitRepository repo = GitUtil.getRepositoryManager(project).getRepositoryForRoot(root);
assert repo != null : "The repository must not be null";
GitBranch current = repo.getCurrentBranch();
if (current == null) {
@@ -329,7 +329,7 @@ public class GitUIUtil {
* @param fetchUrl if true, the fetch url is shown instead of push url
*/
public static void setupRemotes(final Project project, final VirtualFile root, final JComboBox remoteCombobox, final boolean fetchUrl) {
final GitRepository repo = GitRepositoryManager.getInstance(project).getRepositoryForRoot(root);
final GitRepository repo = GitUtil.getRepositoryManager(project).getRepositoryForRoot(root);
assert repo != null : "GitRepository can't be null for root " + root;
GitBranch gitBranch = repo.getCurrentBranch();
@@ -39,7 +39,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 GitRepository.getFullInstance(root, project, project);
return GitRepository.getLightInstance(root, project, project);
}
public static void create(@NotNull GitRepository repository, @NotNull String filePath) {
@@ -0,0 +1,67 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package git4idea.test;
import com.intellij.openapi.vfs.VirtualFile;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryChangeListener;
import git4idea.repo.GitRepositoryManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* @author Kirill Likhodedov
*/
public class GitTestRepositoryManager implements GitRepositoryManager {
@Override
public GitRepository getRepositoryForRoot(@Nullable VirtualFile root) {
throw new UnsupportedOperationException();
}
@Override
public GitRepository getRepositoryForFile(@NotNull VirtualFile file) {
throw new UnsupportedOperationException();
}
@NotNull
@Override
public List<GitRepository> getRepositories() {
throw new UnsupportedOperationException();
}
@Override
public boolean moreThanOneRoot() {
throw new UnsupportedOperationException();
}
@Override
public void addListenerToAllRepositories(@NotNull GitRepositoryChangeListener listener) {
throw new UnsupportedOperationException();
}
@Override
public void updateRepository(VirtualFile root, GitRepository.TrackedTopic... topics) {
throw new UnsupportedOperationException();
}
@Override
public void updateAllRepositories(GitRepository.TrackedTopic... topics) {
throw new UnsupportedOperationException();
}
}
@@ -10,6 +10,7 @@ import com.intellij.tasks.TaskRepository;
import com.intellij.tasks.github.GitHubRepository;
import com.intellij.tasks.github.GitHubRepositoryType;
import com.intellij.tasks.impl.TaskManagerImpl;
import git4idea.GitUtil;
import git4idea.repo.GitRemote;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
@@ -45,7 +46,11 @@ public class GithubCheckoutListener implements CheckoutListener {
return null;
}
// Check if git is already initialized and presence of remote branch
final GitRepository gitRepository = GitRepositoryManager.getInstance(project).getRepositoryForFile(root);
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager == null) {
return null;
}
final GitRepository gitRepository = manager.getRepositoryForFile(root);
if (gitRepository == null){
return null;
}
@@ -26,6 +26,7 @@ import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vfs.VirtualFile;
import git4idea.GitBranch;
import git4idea.GitUtil;
import git4idea.repo.GitRemote;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
@@ -64,7 +65,11 @@ public class GithubOpenInBrowserAction extends DumbAwareAction {
return false;
}
final GitRepository gitRepository = GitRepositoryManager.getInstance(project).getRepositoryForFile(dir);
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager == null) {
return false;
}
final GitRepository gitRepository = manager.getRepositoryForFile(dir);
if (gitRepository == null) {
return false;
}
@@ -90,7 +95,11 @@ public class GithubOpenInBrowserAction extends DumbAwareAction {
}
final VirtualFile root = project.getBaseDir();
final GitRepository gitRepository = GitRepositoryManager.getInstance(project).getRepositoryForFile(root);
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager == null) {
return;
}
final GitRepository gitRepository = manager.getRepositoryForFile(root);
// Check that given repository is properly configured git repository
final GitRemote gitRemote = GithubUtil.findGitHubRemoteBranch(gitRepository);
final String pushUrl = GithubUtil.getGithubUrl(gitRemote);
@@ -23,12 +23,12 @@ import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ui.UIUtil;
import git4idea.GitUtil;
import git4idea.actions.BasicAction;
import git4idea.commands.GitCommand;
import git4idea.commands.GitSimpleHandler;
@@ -37,8 +37,6 @@ import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import org.jetbrains.plugins.github.ui.GithubLoginDialog;
import javax.swing.*;
/**
* Created by IntelliJ IDEA.
*
@@ -62,7 +60,14 @@ public class GithubRebaseAction extends DumbAwareAction {
return;
}
final GitRepository gitRepository = GitRepositoryManager.getInstance(project).getRepositoryForFile(project.getBaseDir());
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager == null) {
e.getPresentation().setVisible(false);
e.getPresentation().setEnabled(false);
return;
}
final GitRepository gitRepository = manager.getRepositoryForFile(project.getBaseDir());
if (gitRepository == null){
e.getPresentation().setVisible(false);
e.getPresentation().setEnabled(false);
@@ -94,7 +99,11 @@ public class GithubRebaseAction extends DumbAwareAction {
}
final VirtualFile root = project.getBaseDir();
final GitRepository gitRepository = GitRepositoryManager.getInstance(project).getRepositoryForFile(project.getBaseDir());
GitRepositoryManager manager = GitUtil.getRepositoryManager(project);
if (manager == null) {
return;
}
final GitRepository gitRepository = manager.getRepositoryForFile(project.getBaseDir());
// Check that given repository is properly configured git repository
final GitRemote remote = GithubUtil.findGitHubRemoteBranch(gitRepository);
final String pushUrl = GithubUtil.getGithubUrl(remote);