mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
GitRepositoryImpl: fix NPE happening due to "this" leakage from the constructor + more clear initialization
* read information before setting up a listener. * set up the listener from the outside to avoid leaking `this` from the constructor * explicitly initialize myInfo.
This commit is contained in:
@@ -58,16 +58,14 @@ public class GitRepositoryImpl extends RepositoryImpl implements GitRepository {
|
||||
myVcs = assertNotNull(GitVcs.getInstance(project));
|
||||
myGitDir = gitDir;
|
||||
myReader = new GitRepositoryReader(VfsUtilCore.virtualToIoFile(myGitDir));
|
||||
myInfo = readRepoInfo();
|
||||
if (!light) {
|
||||
myUntrackedFilesHolder = new GitUntrackedFilesHolder(this);
|
||||
Disposer.register(this, myUntrackedFilesHolder);
|
||||
myUntrackedFilesHolder.setupVfsListener(project);
|
||||
setupUpdater();
|
||||
}
|
||||
else {
|
||||
myUntrackedFilesHolder = null;
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -83,7 +81,13 @@ public class GitRepositoryImpl extends RepositoryImpl implements GitRepository {
|
||||
@NotNull Project project,
|
||||
boolean listenToRepoChanges) {
|
||||
GitPlatformFacade platformFacade = ServiceManager.getService(project, GitPlatformFacade.class);
|
||||
return new GitRepositoryImpl(root, gitDir, platformFacade, project, project, !listenToRepoChanges);
|
||||
GitRepositoryImpl repository = new GitRepositoryImpl(root, gitDir, platformFacade, project, project, !listenToRepoChanges);
|
||||
if (listenToRepoChanges) {
|
||||
repository.getUntrackedFilesHolder().setupVfsListener(project);
|
||||
repository.setupUpdater();
|
||||
notifyListenersAsync(repository);
|
||||
}
|
||||
return repository;
|
||||
}
|
||||
|
||||
private void setupUpdater() {
|
||||
@@ -185,7 +189,7 @@ public class GitRepositoryImpl extends RepositoryImpl implements GitRepository {
|
||||
public void update() {
|
||||
GitRepoInfo previousInfo = myInfo;
|
||||
myInfo = readRepoInfo();
|
||||
notifyListeners(this, previousInfo, myInfo);
|
||||
notifyIfRepoChanged(this, previousInfo, myInfo);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -199,23 +203,26 @@ public class GitRepositoryImpl extends RepositoryImpl implements GitRepository {
|
||||
state.getLocalBranches(), state.getRemoteBranches(), trackInfos);
|
||||
}
|
||||
|
||||
// previous info can be null before the first update
|
||||
private static void notifyListeners(@NotNull final GitRepository repository, @Nullable GitRepoInfo previousInfo, @NotNull GitRepoInfo info) {
|
||||
private static void notifyIfRepoChanged(@NotNull final GitRepository repository, @NotNull GitRepoInfo previousInfo, @NotNull GitRepoInfo info) {
|
||||
if (Disposer.isDisposed(repository.getProject())) {
|
||||
return;
|
||||
}
|
||||
if (!info.equals(previousInfo)) {
|
||||
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
public void run() {
|
||||
Project project = repository.getProject();
|
||||
if (!project.isDisposed()) {
|
||||
project.getMessageBus().syncPublisher(GIT_REPO_CHANGE).repositoryChanged(repository);
|
||||
}
|
||||
}
|
||||
});
|
||||
notifyListenersAsync(repository);
|
||||
}
|
||||
}
|
||||
|
||||
private static void notifyListenersAsync(@NotNull final GitRepository repository) {
|
||||
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
|
||||
public void run() {
|
||||
Project project = repository.getProject();
|
||||
if (!project.isDisposed()) {
|
||||
project.getMessageBus().syncPublisher(GIT_REPO_CHANGE).repositoryChanged(repository);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toLogString() {
|
||||
|
||||
Reference in New Issue
Block a user