com.intellij.openapi.vcs.annotate.FileAnnotation Java Examples

The following examples show how to use com.intellij.openapi.vcs.annotate.FileAnnotation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VcsAnnotationLocalChangesListenerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void processFile(VcsRevisionNumber number, VirtualFile vf) {
  final Collection<FileAnnotation> annotations;
  synchronized (myLock) {
    annotations = myFileAnnotationMap.get(vf);
  }
  if (! annotations.isEmpty()) {
    if (number == null) {
      number = fromDiffProvider(vf);
    }
    if (number == null) return;

    for (FileAnnotation annotation : annotations) {
      if (annotation.isBaseRevisionChanged(number)) {
        annotation.close();
      }
    }
  }
}
 
Example #2
Source File: VcsAnnotationLocalChangesListenerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void processUnderFile(VirtualFile file) {
  final MultiMap<VirtualFile, FileAnnotation> annotations = new MultiMap<>();
  synchronized (myLock) {
    for (VirtualFile virtualFile : myFileAnnotationMap.keySet()) {
      if (VfsUtilCore.isAncestor(file, virtualFile, true)) {
        final Collection<FileAnnotation> values = myFileAnnotationMap.get(virtualFile);
        for (FileAnnotation value : values) {
          annotations.putValue(virtualFile, value);
        }
      }
    }
  }
  if (! annotations.isEmpty()) {
    for (Map.Entry<VirtualFile, Collection<FileAnnotation>> entry : annotations.entrySet()) {
      final VirtualFile key = entry.getKey();
      final VcsRevisionNumber number = fromDiffProvider(key);
      if (number == null) continue;
      final Collection<FileAnnotation> fileAnnotations = entry.getValue();
      for (FileAnnotation annotation : fileAnnotations) {
        if (annotation.isBaseRevisionChanged(number)) {
          annotation.close();
        }
      }
    }
  }
}
 
Example #3
Source File: AnnotationGutterActionProvider.java    From GitLink with MIT License 6 votes vote down vote up
FileAndCommitGroup(@NotNull FileAnnotation annotation) {
    super("GitLink", true);

    browserCommitAnnotationAction    = new BrowserCommitAnnotationAction(annotation);
    clipboardCommitAnnotationAction  = new ClipboardCommitAnnotationAction(annotation);
    browserFileAnnotationAction      = new BrowserFileAnnotationAction(annotation);
    clipboardFileAnnotationAction    = new ClipboardFileAnnotationAction(annotation);

    fileGroup = new Group(
        "File",
        new AnAction[] {
            browserFileAnnotationAction,
            clipboardFileAnnotationAction
        }
    );

    commitGroup = new Group(
        "Commit",
        new AnAction[] {
            browserCommitAnnotationAction,
            clipboardCommitAnnotationAction
        }
    );
}
 
Example #4
Source File: AnnotateDiffViewerAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
private static FileAnnotationLoader doCreateAnnotationsLoader(@Nonnull Project project, @javax.annotation.Nullable AbstractVcs vcs, @javax.annotation.Nullable final VirtualFile file) {
  if (vcs == null || file == null) return null;
  final AnnotationProvider annotationProvider = vcs.getAnnotationProvider();
  if (annotationProvider == null) return null;

  FileStatus fileStatus = FileStatusManager.getInstance(project).getStatus(file);
  if (fileStatus == FileStatus.UNKNOWN || fileStatus == FileStatus.ADDED || fileStatus == FileStatus.IGNORED) {
    return null;
  }

  return new FileAnnotationLoader(vcs) {
    @Override
    public FileAnnotation compute() throws VcsException {
      return annotationProvider.annotate(file);
    }
  };
}
 
Example #5
Source File: AnnotateDiffViewerAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@javax.annotation.Nullable
private static FileAnnotationLoader doCreateAnnotationsLoader(@javax.annotation.Nullable AbstractVcs vcs,
                                                              @javax.annotation.Nullable final FilePath path,
                                                              @javax.annotation.Nullable final VcsRevisionNumber revisionNumber) {
  if (vcs == null || path == null || revisionNumber == null) return null;
  if (revisionNumber instanceof TextRevisionNumber) return null;
  final AnnotationProvider annotationProvider = vcs.getAnnotationProvider();
  if (!(annotationProvider instanceof AnnotationProviderEx)) return null;

  return new FileAnnotationLoader(vcs) {
    @Override
    public FileAnnotation compute() throws VcsException {
      return ((AnnotationProviderEx)annotationProvider).annotate(path, revisionNumber);
    }
  };
}
 
Example #6
Source File: ContentAnnotationCacheImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void register(final VirtualFile vf, final VcsKey vcsKey, final VcsRevisionNumber number, final FileAnnotation fa) {
  final HistoryCacheWithRevisionKey key = new HistoryCacheWithRevisionKey(VcsContextFactory.SERVICE.getInstance().createFilePathOn(vf), vcsKey, number);
  synchronized (myLock) {
    if (myCache.get(key) != null) return;
  }
  final long absoluteLimit = System.currentTimeMillis() - VcsContentAnnotationSettings.ourAbsoluteLimit;
  final TreeMap<Integer, Long> map = new TreeMap<Integer, Long>();
  final int lineCount = fa.getLineCount();
  for (int i = 0; i < lineCount; i++) {
    Date lineDate = fa.getLineDate(i);
    if (lineDate == null) return;
    if (lineDate.getTime() >= absoluteLimit) map.put(i, lineDate.getTime());
  }
  synchronized (myLock) {
    myCache.put(key, map);
  }
}
 
Example #7
Source File: AnnotateCurrentRevisionAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public AnnotateCurrentRevisionAction(@Nonnull FileAnnotation annotation, @Nonnull AbstractVcs vcs) {
  super("Annotate Revision", "Annotate selected revision in new tab", AllIcons.Actions.Annotate,
        annotation, vcs);
  List<VcsFileRevision> revisions = annotation.getRevisions();
  if (revisions == null) {
    myRevisions = null;
    return;
  }

  Map<VcsRevisionNumber, VcsFileRevision> map = new HashMap<VcsRevisionNumber, VcsFileRevision>();
  for (VcsFileRevision revision : revisions) {
    map.put(revision.getRevisionNumber(), revision);
  }

  myRevisions = new ArrayList<VcsFileRevision>(annotation.getLineCount());
  for (int i = 0; i < annotation.getLineCount(); i++) {
    myRevisions.add(map.get(annotation.getLineRevisionNumber(i)));
  }
}
 
Example #8
Source File: AnnotatePreviousRevisionAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public AnnotatePreviousRevisionAction(@Nonnull FileAnnotation annotation, @Nonnull AbstractVcs vcs) {
  super("Annotate Previous Revision", "Annotate successor of selected revision in new tab", AllIcons.Actions.Annotate,
        annotation, vcs);
  List<VcsFileRevision> revisions = annotation.getRevisions();
  if (revisions == null) {
    myRevisions = null;
    return;
  }

  Map<VcsRevisionNumber, VcsFileRevision> map = new HashMap<VcsRevisionNumber, VcsFileRevision>();
  for (int i = 0; i < revisions.size(); i++) {
    VcsFileRevision revision = revisions.get(i);
    VcsFileRevision previousRevision = i + 1 < revisions.size() ? revisions.get(i + 1) : null;
    map.put(revision.getRevisionNumber(), previousRevision);
  }

  myRevisions = new ArrayList<VcsFileRevision>(annotation.getLineCount());
  for (int i = 0; i < annotation.getLineCount(); i++) {
    myRevisions.add(map.get(annotation.getLineRevisionNumber(i)));
  }
}
 
Example #9
Source File: AnnotateToggleAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void doAnnotate(@Nonnull final Editor editor,
                              @Nonnull final Project project,
                              @javax.annotation.Nullable final VirtualFile currentFile,
                              @Nonnull final FileAnnotation fileAnnotation,
                              @Nonnull final AbstractVcs vcs,
                              @Nonnull final UpToDateLineNumberProvider upToDateLineNumbers) {
  doAnnotate(editor, project, currentFile, fileAnnotation, vcs, upToDateLineNumbers, true);
}
 
Example #10
Source File: AnnotationFieldGutter.java    From consulo with Apache License 2.0 5 votes vote down vote up
AnnotationFieldGutter(@Nonnull FileAnnotation annotation,
                      @Nonnull TextAnnotationPresentation presentation,
                      @javax.annotation.Nullable Couple<Map<VcsRevisionNumber, Color>> colorScheme) {
  myAnnotation = annotation;
  myPresentation = presentation;
  myColorScheme = colorScheme;
}
 
Example #11
Source File: ShowDiffFromAnnotation.java    From consulo with Apache License 2.0 5 votes vote down vote up
ShowDiffFromAnnotation(final FileAnnotation fileAnnotation, final AbstractVcs vcs, final VirtualFile file) {
  super(ActionsBundle.message("action.Diff.UpdatedFiles.text"),
        ActionsBundle.message("action.Diff.UpdatedFiles.description"),
        AllIcons.Actions.Diff);
  myFileAnnotation = fileAnnotation;
  myVcs = vcs;
  myFile = file;
  currentLine = -1;
  myEnabled = ProjectLevelVcsManager.getInstance(vcs.getProject()).getVcsFor(myFile) != null;
}
 
Example #12
Source File: HistoryIdColumn.java    From consulo with Apache License 2.0 5 votes vote down vote up
HistoryIdColumn(FileAnnotation annotation,
                final TextAnnotationPresentation presentation,
                Couple<Map<VcsRevisionNumber, Color>> colorScheme,
                Map<VcsRevisionNumber, Integer> ids) {
  super(annotation, presentation, colorScheme);
  myHistoryIds = ids;
}
 
Example #13
Source File: AnnotateToggleAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void doAnnotate(@Nonnull final Editor editor,
                              @Nonnull final Project project,
                              @Nullable final VirtualFile currentFile,
                              @Nonnull final FileAnnotation fileAnnotation,
                              @Nonnull final AbstractVcs vcs) {
  UpToDateLineNumberProvider upToDateLineNumberProvider = new UpToDateLineNumberProviderImpl(editor.getDocument(), project);
  doAnnotate(editor, project, currentFile, fileAnnotation, vcs, upToDateLineNumberProvider);
}
 
Example #14
Source File: AspectAnnotationFieldGutter.java    From consulo with Apache License 2.0 5 votes vote down vote up
public AspectAnnotationFieldGutter(@Nonnull FileAnnotation annotation,
                                   @Nonnull LineAnnotationAspect aspect,
                                   @Nonnull TextAnnotationPresentation presentation,
                                   @javax.annotation.Nullable Couple<Map<VcsRevisionNumber, Color>> colorScheme) {
  super(annotation, presentation, colorScheme);
  myAspect = aspect;
  myIsGutterAction = myAspect instanceof EditorGutterAction;
}
 
Example #15
Source File: AnnotateToggleAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void addActionsFromExtensions(@Nonnull AnnotationPresentation presentation, @Nonnull FileAnnotation fileAnnotation) {
  List<AnnotationGutterActionProvider> extensions = AnnotationGutterActionProvider.EP_NAME.getExtensionList();
  if (extensions.size() > 0) {
    presentation.addAction(new AnSeparator());
  }
  for (AnnotationGutterActionProvider provider : extensions) {
    presentation.addAction(provider.createAction(fileAnnotation));
  }
}
 
Example #16
Source File: AnnotateToggleAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
private static Map<VcsRevisionNumber, Integer> computeLineNumbers(@Nonnull 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;
}
 
Example #17
Source File: AbstractVcsHelperImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void showAnnotation(FileAnnotation annotation, VirtualFile file, AbstractVcs vcs, int line) {
  TextEditor textFileEditor;
  FileEditor fileEditor = FileEditorManager.getInstance(myProject).getSelectedEditor(file);
  if (fileEditor instanceof TextEditor) {
    textFileEditor = ((TextEditor)fileEditor);
  }
  else {
    FileEditor[] editors = FileEditorManager.getInstance(myProject).getEditors(file);
    textFileEditor = ContainerUtil.findInstance(editors, TextEditor.class);
  }

  Editor editor;
  if (textFileEditor != null) {
    editor = textFileEditor.getEditor();
  }
  else {
    OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(myProject, file, line, 0);
    editor = FileEditorManager.getInstance(myProject).openTextEditor(openFileDescriptor, true);
  }

  if (editor == null) {
    Messages.showMessageDialog(VcsBundle.message("message.text.cannot.open.editor", file.getPresentableUrl()),
                               VcsBundle.message("message.title.cannot.open.editor"), Messages.getInformationIcon());
    return;
  }

  AnnotateToggleAction.doAnnotate(editor, myProject, file, annotation, vcs);
}
 
Example #18
Source File: VcsAnnotationLocalChangesListenerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void unregisterAnnotation(final VirtualFile file, final FileAnnotation annotation) {
  synchronized (myLock) {
    final Collection<FileAnnotation> annotations = myFileAnnotationMap.get(file);
    if (!annotations.isEmpty()) {
      annotations.remove(annotation);
    }
    if (annotations.isEmpty()) {
      myFileAnnotationMap.remove(file);
    }
  }
}
 
Example #19
Source File: AnnotateStackTraceAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public String getLineText(int line, Editor editor) {
  LastRevision revision = myRevisions.get(line);
  if (revision != null) {
    return String.format("%" + myMaxDateLength + "s", FileAnnotation.formatDate(revision.getDate())) + " " + revision.getAuthor();
  }
  return "";
}
 
Example #20
Source File: VcsAnnotationCachedProxy.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public FileAnnotation annotate(final VirtualFile file, final VcsFileRevision revision) throws VcsException {
  return annotate(file, revision.getRevisionNumber(), false, new ThrowableComputable<FileAnnotation, VcsException>() {
    @Override
    public FileAnnotation compute() throws VcsException {
      return myAnnotationProvider.annotate(file, revision);
    }
  });
}
 
Example #21
Source File: VcsAnnotationCachedProxy.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public FileAnnotation annotate(final VirtualFile file) throws VcsException {
  final DiffProvider diffProvider = myVcs.getDiffProvider();
  final VcsRevisionNumber currentRevision = diffProvider.getCurrentRevision(file);

  return annotate(file, currentRevision, true, new ThrowableComputable<FileAnnotation, VcsException>() {
    @Override
    public FileAnnotation compute() throws VcsException {
      return myAnnotationProvider.annotate(file);
    }
  });
}
 
Example #22
Source File: BrowserFileAnnotationAction.java    From GitLink with MIT License 4 votes vote down vote up
public BrowserFileAnnotationAction(@NotNull final FileAnnotation annotation) {
    super(annotation);
}
 
Example #23
Source File: VcsAnnotationCachedProxy.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @param currentRevision - just a hint for optimization
 */
private FileAnnotation annotate(VirtualFile file, final VcsRevisionNumber revisionNumber, final boolean currentRevision,
                                final ThrowableComputable<FileAnnotation, VcsException> delegate) throws VcsException {
  final AnnotationProvider annotationProvider = myAnnotationProvider;

  final FilePath filePath = VcsUtil.getFilePath(file);

  final VcsCacheableAnnotationProvider cacheableAnnotationProvider = (VcsCacheableAnnotationProvider)annotationProvider;

  VcsAnnotation vcsAnnotation = null;
  if (revisionNumber != null) {
    Object cachedData = myCache.get(filePath, myVcs.getKeyInstanceMethod(), revisionNumber);
    vcsAnnotation = ObjectUtils.tryCast(cachedData, VcsAnnotation.class);
  }

  if (vcsAnnotation != null) {
    final VcsHistoryProvider historyProvider = myVcs.getVcsHistoryProvider();
    final VcsAbstractHistorySession history = getHistory(revisionNumber, filePath, historyProvider, vcsAnnotation.getFirstRevision());
    if (history == null) return null;
    // question is whether we need "not moved" path here?
    final ContentRevision fileContent = myVcs.getDiffProvider().createFileContent(revisionNumber, file);
    final FileAnnotation restored = cacheableAnnotationProvider.
            restore(vcsAnnotation, history, fileContent.getContent(), currentRevision,
                    revisionNumber);
    if (restored != null) {
      return restored;
    }
  }

  final FileAnnotation fileAnnotation = delegate.compute();
  vcsAnnotation = cacheableAnnotationProvider.createCacheable(fileAnnotation);
  if (vcsAnnotation == null) return fileAnnotation;

  if (revisionNumber != null) {
    myCache.put(filePath, myVcs.getKeyInstanceMethod(), revisionNumber, vcsAnnotation);
  }

  if (myVcs.getVcsHistoryProvider() instanceof VcsCacheableHistorySessionFactory) {
    loadHistoryInBackgroundToCache(revisionNumber, filePath, vcsAnnotation);
  }
  return fileAnnotation;
}
 
Example #24
Source File: AnnotationProviderEx.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
FileAnnotation annotate(@Nonnull FilePath path, @Nonnull VcsRevisionNumber revision) throws VcsException;
 
Example #25
Source File: BrowserCommitAnnotationAction.java    From GitLink with MIT License 4 votes vote down vote up
public BrowserCommitAnnotationAction(@NotNull final FileAnnotation annotation) {
    super(annotation);
}
 
Example #26
Source File: VcsAnnotationLocalChangesListenerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void registerAnnotation(final VirtualFile file, final FileAnnotation annotation) {
  synchronized (myLock) {
    myFileAnnotationMap.putValue(file, annotation);
  }
}
 
Example #27
Source File: ClipboardCommitAnnotationAction.java    From GitLink with MIT License 4 votes vote down vote up
public ClipboardCommitAnnotationAction(@NotNull FileAnnotation annotation) {
    super(annotation);
}
 
Example #28
Source File: AnnotationAction.java    From GitLink with MIT License 4 votes vote down vote up
public AnnotationAction(@NotNull final FileAnnotation annotation) {
    this.annotation = annotation;
}
 
Example #29
Source File: AnnotationGutterActionProvider.java    From GitLink with MIT License 4 votes vote down vote up
@NotNull
@Override
public AnAction createAction(@NotNull FileAnnotation annotation) {
    return new FileAndCommitGroup(annotation);
}
 
Example #30
Source File: AbstractVcsHelperImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void showAnnotation(FileAnnotation annotation, VirtualFile file, AbstractVcs vcs) {
  showAnnotation(annotation, file, vcs, 0);
}