[vcs-log] use util method to determine short VcsRoot name; move DvcsUtil.getShortRepositoryName method to VcsImplUtil and rename to getShortVcsRootName

This commit is contained in:
Julia Beliaeva
2015-11-02 17:22:47 +03:00
parent 52cf9f531a
commit 58914b5ee0
4 changed files with 38 additions and 18 deletions
@@ -55,6 +55,7 @@ import com.intellij.util.io.storage.HeavyProcessLatch;
import com.intellij.util.text.DateFormatUtil;
import com.intellij.vcs.log.TimedVcsCommit;
import com.intellij.vcs.log.VcsFullCommitDetails;
import com.intellij.vcsUtil.VcsImplUtil;
import com.intellij.vcsUtil.VcsUtil;
import org.intellij.images.editor.ImageFileEditor;
import org.jetbrains.annotations.Contract;
@@ -75,19 +76,13 @@ public class DvcsUtil {
private static final int SHORT_HASH_LENGTH = 8;
private static final int LONG_HASH_LENGTH = 40;
/**
* @deprecated use {@link VcsImplUtil#getShortVcsRootName}
*/
@NotNull
@Deprecated
public static String getShortRepositoryName(@NotNull Project project, @NotNull VirtualFile root) {
VirtualFile projectDir = project.getBaseDir();
String repositoryPath = root.getPresentableUrl();
if (projectDir != null) {
String relativePath = VfsUtilCore.getRelativePath(root, projectDir, File.separatorChar);
if (relativePath != null) {
repositoryPath = relativePath;
}
}
return repositoryPath.isEmpty() ? root.getName() : repositoryPath;
return VcsImplUtil.getShortVcsRootName(project, root);
}
@NotNull
@@ -281,8 +276,9 @@ public class DvcsUtil {
@NotNull AbstractRepositoryManager<T> manager,
@Nullable String defaultRootPathValue) {
T repository = manager.getRepositoryForRootQuick(guessVcsRoot(project, getSelectedFile(project)));
return repository != null ? repository
: manager.getRepositoryForRootQuick(guessRootForVcs(project, manager.getVcs(), defaultRootPathValue));
return repository != null
? repository
: manager.getRepositoryForRootQuick(guessRootForVcs(project, manager.getVcs(), defaultRootPathValue));
}
@Nullable
@@ -17,7 +17,12 @@ package com.intellij.vcsUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.WaitForProgressToShow;
import org.jetbrains.annotations.NotNull;
import java.io.File;
/**
* <p>{@link VcsUtil} extension that needs access to the <code>vcs-impl</code> module.</p>
@@ -38,4 +43,19 @@ public class VcsImplUtil {
Runnable task = new Runnable() { public void run() { Messages.showErrorDialog(project, message, title); } };
WaitForProgressToShow.runOrInvokeLaterAboveProgress(task, null, project);
}
@NotNull
public static String getShortVcsRootName(@NotNull Project project, @NotNull VirtualFile root) {
VirtualFile projectDir = project.getBaseDir();
String repositoryPath = root.getPresentableUrl();
if (projectDir != null) {
String relativePath = VfsUtilCore.getRelativePath(root, projectDir, File.separatorChar);
if (relativePath != null) {
repositoryPath = relativePath;
}
}
return repositoryPath.isEmpty() ? root.getName() : repositoryPath;
}
}
@@ -34,6 +34,7 @@ import com.intellij.util.ui.UIUtil;
import com.intellij.vcs.log.VcsRef;
import com.intellij.vcs.log.ui.VcsLogColorManager;
import com.intellij.vcs.log.ui.frame.VcsLogGraphTable;
import com.intellij.vcsUtil.VcsImplUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -64,7 +65,7 @@ public class GoToHashOrRefPopup {
@NotNull Comparator<VcsRef> comparator) {
myOnSelectedHash = onSelectedHash;
myOnSelectedRef = onSelectedRef;
myTextField = new TextFieldWithProgress<VcsRef>(project, new VcsRefCompletionProvider(variants, colorManager, comparator)) {
myTextField = new TextFieldWithProgress<VcsRef>(project, new VcsRefCompletionProvider(project, variants, colorManager, comparator)) {
@Override
public void onOk() {
if (myFuture == null) {
@@ -147,13 +148,16 @@ public class GoToHashOrRefPopup {
}
private class VcsRefCompletionProvider extends TextFieldWithAutoCompletionListProvider<VcsRef> {
@NotNull private final Project myProject;
@NotNull private final VcsLogColorManager myColorManager;
@NotNull private final Comparator<VcsRef> myReferenceComparator;
public VcsRefCompletionProvider(@NotNull Collection<VcsRef> variants,
public VcsRefCompletionProvider(@NotNull Project project,
@NotNull Collection<VcsRef> variants,
@NotNull VcsLogColorManager colorManager,
@NotNull Comparator<VcsRef> comparator) {
super(variants);
myProject = project;
myColorManager = colorManager;
myReferenceComparator = comparator;
}
@@ -192,7 +196,7 @@ public class GoToHashOrRefPopup {
@Override
protected String getTypeText(@NotNull VcsRef item) {
if (!myColorManager.isMultipleRoots()) return null;
return item.getRoot().getName();
return VcsImplUtil.getShortVcsRootName(myProject, item.getRoot());
}
@Override
@@ -15,7 +15,6 @@
*/
package git4idea.update;
import com.intellij.dvcs.DvcsUtil;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
@@ -26,6 +25,7 @@ import com.intellij.openapi.vcs.VcsNotifier;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.ArrayUtil;
import com.intellij.vcsUtil.VcsImplUtil;
import git4idea.GitLocalBranch;
import git4idea.GitRemoteBranch;
import git4idea.GitUtil;
@@ -298,7 +298,7 @@ public class GitFetcher {
StringBuilder info = new StringBuilder();
if (myRepositoryManager.moreThanOneRoot()) {
for (Map.Entry<VirtualFile, String> entry : additionalInfo.entrySet()) {
info.append(entry.getValue()).append(" in ").append(DvcsUtil.getShortRepositoryName(myProject, entry.getKey())).append("<br/>");
info.append(entry.getValue()).append(" in ").append(VcsImplUtil.getShortVcsRootName(myProject, entry.getKey())).append("<br/>");
}
}
else {