From 4e3a68c96ec5ebc8bc2f73146afb8482cc7f8924 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Mon, 10 Nov 2014 18:58:34 +0300 Subject: [PATCH] [log] modify VcsLogHashMap database naming * Hex looks better than int, especially since the latter is signed. * Project#getLocationHash() is the standard method for project id rather than getName(). * Let's have them under a subdirectory since we may have other persistent structures for vcs-log in future. * cleanup previous id version --- .../intellij/vcs/log/data/VcsLogHashMap.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogHashMap.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogHashMap.java index 6787de3058d9..2f0fb92eda07 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogHashMap.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/VcsLogHashMap.java @@ -23,6 +23,7 @@ import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.ThrowableComputable; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.CommonProcessors; @@ -52,13 +53,14 @@ import java.util.Map; */ public class VcsLogHashMap implements Disposable { - private static final File LOG_CACHE_APP_DIR = new File(PathManager.getSystemPath(), "vcs-log"); + private static final File LOG_CACHE_APP_DIR = new File(new File(PathManager.getSystemPath(), "vcs-log"), "hashes"); private static final Logger LOG = Logger.getInstance(VcsLogHashMap.class); private static final int VERSION = 1; private final PersistentEnumerator myPersistentEnumerator; VcsLogHashMap(@NotNull Project project, @NotNull Map logProviders) throws IOException { + cleanupOldNaming(project, logProviders); String logId = calcLogId(project, logProviders); final File mapFile = new File(LOG_CACHE_APP_DIR, logId + "." + VERSION); if (!mapFile.exists()) { @@ -76,19 +78,30 @@ public class VcsLogHashMap implements Disposable { @NotNull private static String calcLogId(@NotNull Project project, @NotNull final Map logProviders) { + int hashcode = calcLogProvidersHash(logProviders); + return project.getLocationHash() + "." + Integer.toHexString(hashcode); + } + + // TODO remove in IDEA 15 + private static void cleanupOldNaming(@NotNull Project project, @NotNull Map providers) { + int hashcode = calcLogProvidersHash(providers); + String oldLogId = project.getName() + "." + hashcode; + FileUtil.delete(new File(new File(PathManager.getSystemPath(), "vcs-log"), oldLogId)); + } + + private static int calcLogProvidersHash(@NotNull final Map logProviders) { List sortedRoots = ContainerUtil.sorted(logProviders.keySet(), new Comparator() { @Override public int compare(@NotNull VirtualFile o1, @NotNull VirtualFile o2) { return o1.getPath().compareTo(o2.getPath()); } }); - String rootsWithVcss = StringUtil.join(sortedRoots, new Function() { + return StringUtil.join(sortedRoots, new Function() { @Override public String fun(VirtualFile root) { return root.getPath() + "." + logProviders.get(root).getSupportedVcs().getName(); } - }, "."); - return project.getName() + "." + rootsWithVcss.hashCode(); + }, ".").hashCode(); } @Nullable