Search in sources :

Example 11 with VcsRevisionNumber

use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.

the class AnnotateToggleAction method computeBgColors.

@Nullable
private static Couple<Map<VcsRevisionNumber, Color>> computeBgColors(@NotNull FileAnnotation fileAnnotation, @NotNull Editor editor) {
    Map<VcsRevisionNumber, Color> commitOrderColors = new HashMap<>();
    Map<VcsRevisionNumber, Color> commitAuthorColors = new HashMap<>();
    EditorColorsScheme colorScheme = editor.getColorsScheme();
    AnnotationsSettings settings = AnnotationsSettings.getInstance();
    List<Color> authorsColorPalette = settings.getAuthorsColors(colorScheme);
    List<Color> orderedColorPalette = settings.getOrderedColors(colorScheme);
    FileAnnotation.AuthorsMappingProvider authorsMappingProvider = fileAnnotation.getAuthorsMappingProvider();
    if (authorsMappingProvider != null) {
        Map<VcsRevisionNumber, String> authorsMap = authorsMappingProvider.getAuthors();
        Map<String, Color> authorColors = new HashMap<>();
        for (String author : ContainerUtil.sorted(authorsMap.values(), Comparing::compare)) {
            int index = authorColors.size();
            Color color = authorsColorPalette.get(index % authorsColorPalette.size());
            authorColors.put(author, color);
        }
        for (Map.Entry<VcsRevisionNumber, String> entry : authorsMap.entrySet()) {
            VcsRevisionNumber revision = entry.getKey();
            String author = entry.getValue();
            Color color = authorColors.get(author);
            commitAuthorColors.put(revision, color);
        }
    }
    FileAnnotation.RevisionsOrderProvider revisionsOrderProvider = fileAnnotation.getRevisionsOrderProvider();
    if (revisionsOrderProvider != null) {
        List<List<VcsRevisionNumber>> orderedRevisions = revisionsOrderProvider.getOrderedRevisions();
        int revisionsCount = orderedRevisions.size();
        for (int index = 0; index < revisionsCount; index++) {
            Color color = orderedColorPalette.get(orderedColorPalette.size() * index / revisionsCount);
            for (VcsRevisionNumber number : orderedRevisions.get(index)) {
                commitOrderColors.put(number, color);
            }
        }
    }
    return Couple.of(commitOrderColors.size() > 1 ? commitOrderColors : null, commitAuthorColors.size() > 1 ? commitAuthorColors : null);
}
Also used : HashMap(java.util.HashMap) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) ArrayList(java.util.ArrayList) List(java.util.List) FileAnnotation(com.intellij.openapi.vcs.annotate.FileAnnotation) HashMap(java.util.HashMap) Map(java.util.Map) Comparing(com.intellij.openapi.util.Comparing) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with VcsRevisionNumber

use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.

the class AnnotateToggleAction method computeLineNumbers.

@Nullable
private static Map<VcsRevisionNumber, Integer> computeLineNumbers(@NotNull FileAnnotation fileAnnotation) {
    final Map<VcsRevisionNumber, Integer> numbers = new HashMap<>();
    final List<VcsFileRevision> fileRevisionList = fileAnnotation.getRevisions();
    if (fileRevisionList != null) {
        int size = fileRevisionList.size();
        for (int i = 0; i < size; i++) {
            VcsFileRevision revision = fileRevisionList.get(i);
            final VcsRevisionNumber number = revision.getRevisionNumber();
            numbers.put(number, size - i);
        }
    }
    return numbers.size() < 2 ? null : numbers;
}
Also used : HashMap(java.util.HashMap) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with VcsRevisionNumber

use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.

the class ContentRevisionCache method getOrLoadCurrentAsBytes.

public static Pair<VcsRevisionNumber, byte[]> getOrLoadCurrentAsBytes(final Project project, FilePath path, @NotNull VcsKey vcsKey, final CurrentRevisionProvider loader) throws VcsException, IOException {
    ContentRevisionCache cache = ProjectLevelVcsManager.getInstance(project).getContentRevisionCache();
    VcsRevisionNumber currentRevision;
    Pair<VcsRevisionNumber, byte[]> loaded;
    while (true) {
        currentRevision = putIntoCurrentCache(cache, path, vcsKey, loader);
        final byte[] cachedCurrent = cache.getBytes(path, currentRevision, vcsKey, UniqueType.REPOSITORY_CONTENT);
        if (cachedCurrent != null) {
            return Pair.create(currentRevision, cachedCurrent);
        }
        checkLocalFileSize(path);
        loaded = loader.get();
        if (loaded.getFirst().equals(currentRevision))
            break;
    }
    cache.put(path, currentRevision, vcsKey, UniqueType.REPOSITORY_CONTENT, loaded.getSecond());
    return loaded;
}
Also used : VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber)

Example 14 with VcsRevisionNumber

use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.

the class ContentRevisionCache method putIntoCurrentCache.

private static VcsRevisionNumber putIntoCurrentCache(final ContentRevisionCache cache, FilePath path, @NotNull VcsKey vcsKey, final CurrentRevisionProvider loader) throws VcsException, IOException {
    VcsRevisionNumber loadedRevisionNumber;
    Pair<VcsRevisionNumber, Long> currentRevision;
    while (true) {
        loadedRevisionNumber = loader.getCurrentRevision();
        currentRevision = cache.getCurrent(path, vcsKey);
        if (loadedRevisionNumber.equals(currentRevision.getFirst()))
            return loadedRevisionNumber;
        if (cache.putCurrent(path, loadedRevisionNumber, vcsKey, currentRevision.getSecond())) {
            return loadedRevisionNumber;
        }
    }
}
Also used : VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber)

Example 15 with VcsRevisionNumber

use of com.intellij.openapi.vcs.history.VcsRevisionNumber in project intellij-community by JetBrains.

the class FileAnnotation method createDefaultAuthorsMappingProvider.

@Nullable
private static AuthorsMappingProvider createDefaultAuthorsMappingProvider(@NotNull FileAnnotation annotation) {
    List<VcsFileRevision> revisions = annotation.getRevisions();
    if (revisions == null)
        return null;
    Map<VcsRevisionNumber, String> authorsMapping = new HashMap<>();
    for (VcsFileRevision revision : revisions) {
        String author = revision.getAuthor();
        if (author != null)
            authorsMapping.put(revision.getRevisionNumber(), author);
    }
    return () -> authorsMapping;
}
Also used : HashMap(com.intellij.util.containers.HashMap) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)48 VirtualFile (com.intellij.openapi.vfs.VirtualFile)14 Nullable (org.jetbrains.annotations.Nullable)12 NotNull (org.jetbrains.annotations.NotNull)11 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)7 FilePath (com.intellij.openapi.vcs.FilePath)6 Project (com.intellij.openapi.project.Project)5 VcsException (com.intellij.openapi.vcs.VcsException)4 File (java.io.File)4 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)3 Pair (com.intellij.openapi.util.Pair)3 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)3 VcsRoot (com.intellij.openapi.vcs.VcsRoot)3 Change (com.intellij.openapi.vcs.changes.Change)3 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)3 HashMap (com.intellij.util.containers.HashMap)3 DiffContent (com.intellij.diff.contents.DiffContent)2 Logger (com.intellij.openapi.diagnostic.Logger)2 Document (com.intellij.openapi.editor.Document)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2