From f08e8ee1dbf694ac0829827dfcb5f4359a34863f Mon Sep 17 00:00:00 2001 From: Constantine Plotnikov Date: Fri, 18 Dec 2009 18:23:23 +0300 Subject: [PATCH] git4idea: Git init is done in background --- plugins/git4idea/src/git4idea/actions/GitInit.java | 70 ++++++++++++---------- .../src/git4idea/i18n/GitBundle.properties | 1 + 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/plugins/git4idea/src/git4idea/actions/GitInit.java b/plugins/git4idea/src/git4idea/actions/GitInit.java index 2b35431a86..5985ea5b1a 100644 --- a/plugins/git4idea/src/git4idea/actions/GitInit.java +++ b/plugins/git4idea/src/git4idea/actions/GitInit.java @@ -20,19 +20,22 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.fileChooser.FileChooser; import com.intellij.openapi.fileChooser.FileChooserDescriptor; +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsDirectoryMapping; -import com.intellij.openapi.vcs.VcsException; import com.intellij.openapi.vfs.VirtualFile; import git4idea.GitUtil; import git4idea.GitVcs; import git4idea.commands.GitHandler; -import git4idea.commands.GitSimpleHandler; +import git4idea.commands.GitHandlerUtil; +import git4idea.commands.GitLineHandler; import git4idea.i18n.GitBundle; import git4idea.ui.GitUIUtil; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collections; @@ -60,19 +63,17 @@ public class GitInit extends DumbAwareAction { if (files.length == 0) { return; } - VirtualFile root = files[0]; + final VirtualFile root = files[0]; if (GitUtil.isUnderGit(root)) { Messages.showErrorDialog(project, GitBundle.message("init.error.already.under.git", root.getPresentableUrl()), GitBundle.getString("init.error.title")); return; } - try { - GitSimpleHandler h = new GitSimpleHandler(project, root, GitHandler.INIT); - h.setNoSSH(true); - h.run(); - } - catch (VcsException ex) { - GitUIUtil.showOperationError(project, ex, "git init"); + GitLineHandler h = new GitLineHandler(project, root, GitHandler.INIT); + h.setNoSSH(true); + GitHandlerUtil.doSynchronously(h, GitBundle.getString("initializing.title"), h.printableCommandLine()); + if (!h.errors().isEmpty()) { + GitUIUtil.showOperationErrors(project, h.errors(), "git init"); return; } int rc = Messages.showYesNoDialog(project, GitBundle.getString("init.add.root.message"), GitBundle.getString("init.add.root.title"), @@ -80,31 +81,36 @@ public class GitInit extends DumbAwareAction { if (rc != 0) { return; } - root.refresh(false, false); - final String path = root.equals(baseDir) ? "" : root.getPath(); - ProjectLevelVcsManager vcs = ProjectLevelVcsManager.getInstance(project); - final List vcsDirectoryMappings = new ArrayList(vcs.getDirectoryMappings()); - VcsDirectoryMapping mapping = new VcsDirectoryMapping(path, GitVcs.getInstance(project).getName()); - for (int i = 0; i < vcsDirectoryMappings.size(); i++) { - final VcsDirectoryMapping m = vcsDirectoryMappings.get(i); - if (m.getDirectory().equals(path)) { - if (m.getVcs().length() == 0) { - vcsDirectoryMappings.set(i, mapping); - mapping = null; - break; + GitVcs.getInstance(project).runInBackground(new Task.Backgroundable(project, GitBundle.getString("common.refreshing")) { + @Override + public void run(@NotNull ProgressIndicator indicator) { + root.refresh(false, false); + final String path = root.equals(baseDir) ? "" : root.getPath(); + ProjectLevelVcsManager vcs = ProjectLevelVcsManager.getInstance(project); + final List vcsDirectoryMappings = new ArrayList(vcs.getDirectoryMappings()); + VcsDirectoryMapping mapping = new VcsDirectoryMapping(path, GitVcs.getInstance(project).getName()); + for (int i = 0; i < vcsDirectoryMappings.size(); i++) { + final VcsDirectoryMapping m = vcsDirectoryMappings.get(i); + if (m.getDirectory().equals(path)) { + if (m.getVcs().length() == 0) { + vcsDirectoryMappings.set(i, mapping); + mapping = null; + break; + } + else if (m.getVcs().equals(mapping.getVcs())) { + mapping = null; + break; + } + } } - else if (m.getVcs().equals(mapping.getVcs())) { - mapping = null; - break; + if (mapping != null) { + vcsDirectoryMappings.add(mapping); } + vcs.setDirectoryMappings(vcsDirectoryMappings); + vcs.updateActiveVcss(); + GitUtil.refreshFiles(project, Collections.singleton(root)); } - } - if (mapping != null) { - vcsDirectoryMappings.add(mapping); - } - vcs.setDirectoryMappings(vcsDirectoryMappings); - vcs.updateActiveVcss(); - GitUtil.refreshFiles(project, Collections.singleton(root)); + }); } /** diff --git a/plugins/git4idea/src/git4idea/i18n/GitBundle.properties b/plugins/git4idea/src/git4idea/i18n/GitBundle.properties index 478996b93b..83a423e413 100644 --- a/plugins/git4idea/src/git4idea/i18n/GitBundle.properties +++ b/plugins/git4idea/src/git4idea/i18n/GitBundle.properties @@ -148,6 +148,7 @@ init.destination.directory.description=Select directory where the new Git reposi init.destination.directory.title=Select directory for git init init.error.already.under.git=The selected directory {0} is already under git. The submodules are not yet supported. init.error.title=git init Error +initializing.title=Intializing repository... merge.action.name=Merge merge.add.log.information.tooltip=Add log information to the commit message (\"--log\" option) merge.add.log.information=Add &log information -- 2.11.4.GIT