+++ /dev/null
-/*
- * Copyright 2000-2010 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 com.intellij.openapi.vcs.changes;
-
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vcs.FilePath;
-import com.intellij.openapi.vcs.ProjectLevelVcsManager;
-import com.intellij.openapi.vcs.VcsRoot;
-import com.intellij.util.containers.Convertor;
-import com.intellij.util.containers.MultiMap;
-
-import java.util.Collection;
-
-public class SortByVcsRoots<T> {
- private final Project myProject;
- private final Convertor<T, FilePath> myConvertor;
- private ProjectLevelVcsManager myVcsManager;
- public static final VcsRoot ourFictiveValue = new VcsRoot(null, null);
-
- public SortByVcsRoots(Project project, final Convertor<T, FilePath> convertor) {
- myProject = project;
- myVcsManager = ProjectLevelVcsManager.getInstance(project);
- myConvertor = convertor;
- }
-
- public MultiMap<VcsRoot, T> sort(final Collection<T> in) {
- final MultiMap<VcsRoot, T> result = new MultiMap<>();
- for (T t : in) {
- final VcsRoot root = myVcsManager.getVcsRootObjectFor(myConvertor.convert(t));
- if (root != null) {
- result.putValue(root, t);
- } else {
- result.putValue(ourFictiveValue, t);
- }
- }
- return result;
- }
-}
import com.intellij.openapi.vfs.*;
import com.intellij.openapi.vfs.newvfs.RefreshQueue;
import com.intellij.openapi.wm.StatusBar;
+import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtilRt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.*;
+import static com.intellij.util.ObjectUtils.notNull;
+import static java.util.stream.Collectors.groupingBy;
+
@SuppressWarnings({"UtilityClassWithoutPrivateConstructor"})
public class VcsUtil {
protected static final char[] ourCharsToBeChopped = new char[]{'/', '\\'};
public final static String MAX_VCS_LOADED_SIZE_KB = "idea.max.vcs.loaded.size.kb";
private static final int ourMaxLoadedFileSize = computeLoadedFileSize();
+ @NotNull private static final VcsRoot FICTIVE_ROOT = new VcsRoot(null, null);
+
public static int getMaxVcsLoadedFileSize() {
return ourMaxLoadedFileSize;
}
return file.getName() + " (" + file.getParent() + ")";
}
+ @NotNull
+ public static <T> Map<VcsRoot, List<T>> groupByRoots(@NotNull Project project,
+ @NotNull Collection<T> items,
+ @NotNull Function<T, FilePath> filePathMapper) {
+ ProjectLevelVcsManager manager = ProjectLevelVcsManager.getInstance(project);
+
+ return items.stream().collect(groupingBy(item -> notNull(manager.getVcsRootObjectFor(filePathMapper.fun(item)), FICTIVE_ROOT)));
+ }
+
@NotNull
public static Collection<VcsDirectoryMapping> findRoots(@NotNull VirtualFile rootDir, @NotNull Project project)
throws IllegalArgumentException {
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.VcsOutgoingChangesProvider;
import com.intellij.openapi.vcs.VcsRoot;
-import com.intellij.openapi.vcs.changes.*;
+import com.intellij.openapi.vcs.changes.BinaryContentRevision;
+import com.intellij.openapi.vcs.changes.ByteBackedContentRevision;
+import com.intellij.openapi.vcs.changes.Change;
+import com.intellij.openapi.vcs.changes.ContentRevision;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.BeforeAfter;
-import com.intellij.util.containers.Convertor;
-import com.intellij.util.containers.MultiMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
+
+import static com.intellij.openapi.vcs.changes.ChangesUtil.getAfterPath;
+import static com.intellij.openapi.vcs.changes.ChangesUtil.getBeforePath;
+import static com.intellij.util.ObjectUtils.chooseNotNull;
+import static com.intellij.vcsUtil.VcsUtil.groupByRoots;
public class IdeaTextPatchBuilder {
private IdeaTextPatchBuilder() {
public static List<BeforeAfter<AirContentRevision>> revisionsConvertor(final Project project, final List<Change> changes) throws VcsException {
final List<BeforeAfter<AirContentRevision>> result = new ArrayList<>(changes.size());
-
- final Convertor<Change, FilePath> beforePrefferingConvertor = new Convertor<Change, FilePath>() {
- public FilePath convert(Change o) {
- final FilePath before = ChangesUtil.getBeforePath(o);
- return before == null ? ChangesUtil.getAfterPath(o) : before;
- }
- };
- final MultiMap<VcsRoot,Change> byRoots = new SortByVcsRoots<>(project, beforePrefferingConvertor).sort(changes);
+ Map<VcsRoot, List<Change>> byRoots =
+ groupByRoots(project, changes, change -> chooseNotNull(getBeforePath(change), getAfterPath(change)));
for (VcsRoot root : byRoots.keySet()) {
final Collection<Change> rootChanges = byRoots.get(root);
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.*;
-import com.intellij.openapi.vcs.changes.SortByVcsRoots;
import com.intellij.openapi.vcs.checkin.CheckinEnvironment;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.util.ObjectUtils;
import com.intellij.util.Processor;
import com.intellij.util.containers.ContainerUtil;
-import com.intellij.util.containers.Convertor;
import com.intellij.util.containers.MultiMap;
import org.jetbrains.annotations.NotNull;
import java.util.*;
+import static com.intellij.util.Functions.identity;
+import static com.intellij.vcsUtil.VcsUtil.groupByRoots;
+
public class TriggerAdditionOrDeletion {
private final Collection<FilePath> myExisting;
private final Collection<FilePath> myDeleted;
public void prepare() {
if (myExisting.isEmpty() && myDeleted.isEmpty()) return;
- final SortByVcsRoots<FilePath> sortByVcsRoots = new SortByVcsRoots<>(myProject, new Convertor.IntoSelf<>());
-
if (! myExisting.isEmpty()) {
- processAddition(sortByVcsRoots);
+ processAddition();
}
if (! myDeleted.isEmpty()) {
- processDeletion(sortByVcsRoots);
+ processDeletion();
}
}
return myAffected;
}
- private void processDeletion(SortByVcsRoots<FilePath> sortByVcsRoots) {
- final MultiMap<VcsRoot, FilePath> map = sortByVcsRoots.sort(myDeleted);
+ private void processDeletion() {
+ Map<VcsRoot, List<FilePath>> map = groupByRoots(myProject, myDeleted, identity());
+
myPreparedDeletion = new MultiMap<>();
for (VcsRoot vcsRoot : map.keySet()) {
if (vcsRoot != null && vcsRoot.getVcs() != null) {
}
}
- private void processAddition(SortByVcsRoots<FilePath> sortByVcsRoots) {
- final MultiMap<VcsRoot, FilePath> map = sortByVcsRoots.sort(myExisting);
+ private void processAddition() {
+ Map<VcsRoot, List<FilePath>> map = groupByRoots(myProject, myExisting, identity());
+
myPreparedAddition = new MultiMap<>();
for (VcsRoot vcsRoot : map.keySet()) {
if (vcsRoot != null && vcsRoot.getVcs() != null) {