com.intellij.openapi.vcs.history.VcsFileRevision Java Examples

The following examples show how to use com.intellij.openapi.vcs.history.VcsFileRevision. 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: TFSHistoryProvider.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
private static VcsAbstractHistorySession createSession(final VcsRevisionNumber currentRevisionNumber,
                                                       final List<TfsFileRevision> revisions,
                                                       final boolean isFile) {
    return new VcsAbstractHistorySession(revisions) {
        public VcsRevisionNumber calcCurrentRevisionNumber() {
            return currentRevisionNumber;
        }

        public HistoryAsTreeProvider getHistoryAsTreeProvider() {
            return null;
        }

        @Override
        public VcsHistorySession copy() {
            return createSession(currentRevisionNumber, revisions, isFile);
        }

        @Override
        public boolean isContentAvailable(final VcsFileRevision revision) {
            return isFile;
        }
    };
}
 
Example #2
Source File: P4HistoryProvider.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public VcsHistorySession createSessionFor(FilePath filePath) throws VcsException {
    ClientConfigRoot root = getRootFor(filePath);
    if (root == null) {
        LOG.info("Not in P4 project: " + filePath);
        return null;
    }

    try {
        List<VcsFileRevision> revisions = P4ServerComponent
                .query(project, root.getClientConfig(),
                        new ListFileHistoryQuery(filePath, -1))
                .blockingGet(UserProjectPreferences.getLockWaitTimeoutMillis(project), TimeUnit.MILLISECONDS)
                .getRevisions(formatter, loader);
        return createAppendableSession(filePath, revisions, null);
    } catch (InterruptedException e) {
        throw new VcsInterruptedException(e);
    }
}
 
Example #3
Source File: P4HistoryProvider.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
@Override
@Nullable
public VcsFileRevision getLastRevision(FilePath filePath)
        throws VcsException {
    ClientConfigRoot root = getRootFor(filePath);
    if (root == null) {
        LOG.info("File not under vcs: " + filePath);
        return null;
    }

    try {
        List<VcsFileRevision> revisions = getHistory(root, filePath, 1)
                .blockingGet(UserProjectPreferences.getLockWaitTimeoutMillis(project), TimeUnit.MILLISECONDS)
                .getRevisions(formatter, loader);
        if (revisions.isEmpty()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("no revisions found for " + filePath);
            }
            return null;
        }
        return revisions.get(0);
    } catch (InterruptedException e) {
        InternalErrorMessage.send(project).cacheLockTimeoutError(new ErrorEvent<>(new VcsInterruptedException(e)));
        return null;
    }
}
 
Example #4
Source File: AnnotateRevisionAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
protected VirtualFile getFile(@Nonnull AnActionEvent e) {
  VcsFileRevision revision = getFileRevision(e);
  if (revision == null) return null;

  final FileType currentFileType = myAnnotation.getFile().getFileType();
  FilePath filePath = (revision instanceof VcsFileRevisionEx ? ((VcsFileRevisionEx)revision).getPath() : VcsUtil.getFilePath(myAnnotation.getFile()));
  return new VcsVirtualFile(filePath.getPath(), revision, VcsFileSystem.getInstance()) {
    @Nonnull
    @Override
    public FileType getFileType() {
      FileType type = super.getFileType();
      if (!type.isBinary()) return type;
      if (!currentFileType.isBinary()) return currentFileType;
      return PlainTextFileType.INSTANCE;
    }
  };
}
 
Example #5
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 #6
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 #7
Source File: P4AnnotatedFileImpl.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
/**
 * Get all revisions that are mentioned in the annotations
 *
 * @return the list of revisions that are mentioned in annotations. Or null
 * if before/after popups cannot be supported by the VCS system.
 */
@Nullable
@Override
public List<VcsFileRevision> getRevisions() {

    // Possibly look into using P4HistoryProvider#getHistory instead,
    // however that wouldn't conform to the API.

    Set<VcsFileRevision> revs = new HashSet<>();
    for (P4AnnotatedLine line : annotatedFile.getAnnotatedLines()) {
        if (line != null) {
            P4HistoryVcsFileRevision fileRev = new P4HistoryVcsFileRevision(
                    file, config, line.getRevisionData(), formatter, loader);
            revs.add(fileRev);
        }
    }
    LOG.debug("getRevisions(): " + revs.size() + " " + revs);
    return new ArrayList<>(revs);
}
 
Example #8
Source File: ChangelistDescriptionAction.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
private Pair<OptionalClientServerConfig, P4ChangelistId> findAttachedFileRevision(AnActionEvent e) {
    final VirtualFile file;
    {
        final Boolean nonLocal = e.getData(VcsDataKeys.VCS_NON_LOCAL_HISTORY_SESSION);
        if (Boolean.TRUE.equals(nonLocal)) {
            LOG.info("non-local VCS history session; ignoring changelist description action");
            return null;
        }
        file = e.getData(VcsDataKeys.VCS_VIRTUAL_FILE);
        if (file == null || file.isDirectory()) {
            LOG.info("No VCS virtual file associated with changelist description action; ignoring request.");
            return null;
        }
    }

    final VcsFileRevision revision = e.getData(VcsDataKeys.VCS_FILE_REVISION);
    if (!(revision instanceof P4HistoryVcsFileRevision)) {
        LOG.info("No file revision associated with file " + file);
        return null;
    }
    P4HistoryVcsFileRevision history = (P4HistoryVcsFileRevision) revision;
    return Pair.create(new OptionalClientServerConfig(history.getClientConfig()), history.getChangelistId());
}
 
Example #9
Source File: HighlightAnnotationsActions.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void initShowComments(final List<VcsFileRevision> revisions) {
  for (VcsFileRevision revision : revisions) {
    if (revision.getCommitMessage() != null) {
      myShowComments = true;
      return;
    }
  }
  myShowComments = false;
}
 
Example #10
Source File: VcsAnnotation.java    From consulo with Apache License 2.0 5 votes vote down vote up
public VcsAnnotation(FilePath filePath, VcsLineAnnotationData basicAnnotation, VcsRevisionNumber lastRevision) {
  myBasicAnnotation = basicAnnotation;
  myLastRevision = lastRevision;
  myAdditionalAnnotations = new HashMap<Object, VcsLineAnnotationData>();
  myCachedOtherRevisions = new HashMap<VcsRevisionNumber, VcsFileRevision>();
  myFilePath = filePath;
}
 
Example #11
Source File: FileAnnotation.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private static PreviousFileRevisionProvider createDefaultPreviousFileRevisionProvider(@Nonnull FileAnnotation annotation) {
  List<VcsFileRevision> revisions = annotation.getRevisions();
  if (revisions == null) return null;

  Map<VcsRevisionNumber, VcsFileRevision> map = new HashMap<>();
  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);
  }

  List<VcsFileRevision> lineToRevision = new ArrayList<>(annotation.getLineCount());
  for (int i = 0; i < annotation.getLineCount(); i++) {
    lineToRevision.add(map.get(annotation.getLineRevisionNumber(i)));
  }

  VcsFileRevision lastRevision = ContainerUtil.getFirstItem(revisions);

  return new PreviousFileRevisionProvider() {
    @javax.annotation.Nullable
    @Override
    public VcsFileRevision getPreviousRevision(int lineNumber) {
      LOG.assertTrue(lineNumber >= 0 && lineNumber < lineToRevision.size());
      return lineToRevision.get(lineNumber);
    }

    @javax.annotation.Nullable
    @Override
    public VcsFileRevision getLastRevision() {
      return lastRevision;
    }
  };
}
 
Example #12
Source File: HighlightAnnotationsActions.java    From consulo with Apache License 2.0 5 votes vote down vote up
public HighlightAnnotationsActions(final Project project, final VirtualFile virtualFile, final FileAnnotation fileAnnotation,
                                   final EditorGutterComponentEx gutter) {
  myGutter = gutter;
  myBefore = new HightlightAction(true, project, virtualFile, fileAnnotation, myGutter, null);
  final List<VcsFileRevision> fileRevisionList = fileAnnotation.getRevisions();
  final VcsFileRevision afterSelected = ((fileRevisionList != null) && (fileRevisionList.size() > 1)) ? fileRevisionList.get(0) : null;
  myAfter = new HightlightAction(false, project, virtualFile, fileAnnotation, myGutter, afterSelected);
  myRemove = new RemoveHighlightingAction();
}
 
Example #13
Source File: HighlightAnnotationsActions.java    From consulo with Apache License 2.0 5 votes vote down vote up
private HightlightAction(final boolean before, final Project project, final VirtualFile virtualFile, final FileAnnotation fileAnnotation,
                         final EditorGutterComponentEx gutter, @javax.annotation.Nullable final VcsFileRevision selectedRevision) {
  myBefore = before;
  myProject = project;
  myVirtualFile = virtualFile;
  myFileAnnotation = fileAnnotation;
  myGutter = gutter;
  myShowComments = null;
  mySelectedRevision = selectedRevision;
}
 
Example #14
Source File: HighlightAnnotationsActions.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(final AnActionEvent e) {
  final List<VcsFileRevision> fileRevisionList = myFileAnnotation.getRevisions();
  if (fileRevisionList != null) {
    if (myShowComments == null) {
      initShowComments(fileRevisionList);
    }
    CompareWithSelectedRevisionAction.showListPopup(fileRevisionList, myProject,
                                                    new Consumer<VcsFileRevision>() {
                                                      public void consume(final VcsFileRevision vcsFileRevision) {
                                                        mySelectedRevision = vcsFileRevision;
                                                        myGutter.revalidateMarkup();
                                                      }
                                                    }, myShowComments.booleanValue());
  }
}
 
Example #15
Source File: ShowAllAffectedGenericAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  final Project project = e.getData(CommonDataKeys.PROJECT);
  if (project == null) return;
  final VcsKey vcsKey = e.getData(VcsDataKeys.VCS);
  if (vcsKey == null) return;
  final VcsFileRevision revision = e.getData(VcsDataKeys.VCS_FILE_REVISION);
  VirtualFile revisionVirtualFile = e.getData(VcsDataKeys.VCS_VIRTUAL_FILE);
  final Boolean isNonLocal = e.getData(VcsDataKeys.VCS_NON_LOCAL_HISTORY_SESSION);
  if ((revision != null) && (revisionVirtualFile != null)) {
    showSubmittedFiles(project, revision.getRevisionNumber(), revisionVirtualFile, vcsKey, revision.getChangedRepositoryPath(),
                       Boolean.TRUE.equals(isNonLocal));
  }
}
 
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: AnnotateRevisionAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
protected VcsFileRevision getFileRevision(@Nonnull AnActionEvent e) {
  List<VcsFileRevision> revisions = getRevisions();
  assert revisions != null;

  if (currentLine < 0 || currentLine >= revisions.size()) return null;
  return revisions.get(currentLine);
}
 
Example #18
Source File: AnnotateStackTraceAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static LastRevision create(@Nonnull VcsFileRevision revision) {
  VcsRevisionNumber number = revision.getRevisionNumber();
  String author = StringUtil.notNullize(revision.getAuthor(), "Unknown");
  Date date = revision.getRevisionDate();
  String message = StringUtil.notNullize(revision.getCommitMessage());
  return new LastRevision(number, author, date, message);
}
 
Example #19
Source File: P4HistoryProvider.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@Override
public void showDiffForTwo(@NotNull Project project,
        @NotNull FilePath filePath,
        @NotNull VcsFileRevision revision1,
        @NotNull VcsFileRevision revision2) {
    VcsHistoryUtil.showDifferencesInBackground(project, filePath, revision1, revision2);
}
 
Example #20
Source File: ConnectCommandRunner.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@NotNull
private ListFileHistoryResult.VcsFileRevisionFactory createFileHistoryList(
        @NotNull final ClientConfig config,
        @NotNull final FilePath file,
        @NotNull final List<IFileRevisionData> history) {
    return (formatter, loader) -> {
        List<VcsFileRevision> ret = new ArrayList<>(history.size());
        history.forEach((d) -> {
            P4HistoryVcsFileRevision rev = new P4HistoryVcsFileRevision(
                    file, config, d, formatter, loader);
            ret.add(rev);
        });
        return ret;
    };
}
 
Example #21
Source File: P4HistoryProvider.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
Integer getDataOf(VcsFileRevision rev) {
    if (rev instanceof P4FileRevision) {
        return ((P4FileRevision) rev).getChangelistId().getChangelistId();
    }
    if (rev instanceof P4HistoryVcsFileRevision) {
        return ((P4HistoryVcsFileRevision) rev).getChangelistId().getChangelistId();
    }
    return null;
}
 
Example #22
Source File: ListFileHistoryResult.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
public List<VcsFileRevision> getRevisions(@Nullable HistoryMessageFormatter formatter,
        @Nullable HistoryContentLoader loader) {
    return factory.create(formatter, loader);
}
 
Example #23
Source File: P4AnnotationProvider.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public FileAnnotation annotate(@NotNull VirtualFile file, VcsFileRevision revision) throws VcsException {
    if (ApplicationManager.getApplication().isDispatchThread()) {
        LOG.info("Fetching annotation from the EDT");
        // TODO bundle for error messages
        throw new VcsException("Does not support fetching annotations from the EDT.");
    }
    // TODO use a better location for this constant.
    int rev = IFileSpec.HEAD_REVISION;
    if (revision != null) {
        VcsRevisionNumber revNumber = revision.getRevisionNumber();
        if (revNumber instanceof VcsRevisionNumber.Int) {
            rev = ((VcsRevisionNumber.Int) revNumber).getValue();
        } else {
            LOG.warn("Unknown file revision " + revision + " for " + file + "; using head revision");
        }
    }
    FilePath fp = VcsUtil.getFilePath(file);
    if (fp == null) {
        // TODO bundle for error messages
        throw new VcsException("No known Perforce server for " + file);
    }
    ProjectConfigRegistry registry = ProjectConfigRegistry.getInstance(project);
    if (registry == null) {
        // TODO bundle for error messages
        throw new VcsException("Project not configured for showing annotations");
    }
    ClientConfigRoot client = registry.getClientFor(file);
    if (client == null) {
        // TODO bundle for error messages
        throw new VcsException("No known Perforce server for " + file);
    }
    String clientname = client.getClientConfig().getClientname();
    if (clientname == null) {
        // TODO bundle for error messages
        throw new VcsException("No workspace name set for Perforce connection for " + file);
    }
    try {
        return new P4AnnotatedFileImpl(project, fp,
                messageFormatter, contentLoader,
                P4ServerComponent
                    .query(project, client.getClientConfig(), new AnnotateFileQuery(fp, rev))
                    .blockingGet(UserProjectPreferences.getLockWaitTimeoutMillis(project), TimeUnit.MILLISECONDS));
    } catch (InterruptedException e) {
        throw new VcsInterruptedException(e);
    }
}
 
Example #24
Source File: P4HistoryProvider.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
@Override
public void showDiffForOne(@NotNull AnActionEvent e, @NotNull Project project, @NotNull FilePath filePath,
        @NotNull VcsFileRevision previousRevision, @NotNull VcsFileRevision revision) {
    VcsHistoryUtil.showDifferencesInBackground(project, filePath, previousRevision, revision);
}
 
Example #25
Source File: AnnotateRevisionAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
protected abstract List<VcsFileRevision> getRevisions();
 
Example #26
Source File: AnnotateRevisionActionBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean isEnabled(@Nonnull AnActionEvent e) {
  if (e.getProject() == null) return false;

  VcsFileRevision fileRevision = getFileRevision(e);
  if (fileRevision == null) return false;

  VirtualFile file = getFile(e);
  if (file == null) return false;

  AbstractVcs vcs = getVcs(e);
  if (vcs == null) return false;

  AnnotationProvider provider = vcs.getAnnotationProvider();
  if (provider == null || !provider.isAnnotationValid(fileRevision)) return false;

  if (VcsAnnotateUtil.getBackgroundableLock(vcs.getProject(), file).isLocked()) return false;

  return true;
}
 
Example #27
Source File: AnnotateRevisionActionBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
protected abstract VcsFileRevision getFileRevision(@Nonnull AnActionEvent e);
 
Example #28
Source File: AnnotatePreviousRevisionAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
public List<VcsFileRevision> getRevisions() {
  return myRevisions;
}
 
Example #29
Source File: AnnotateCurrentRevisionAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
public List<VcsFileRevision> getRevisions() {
  return myRevisions;
}
 
Example #30
Source File: P4HistoryProvider.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
public Comparator<VcsFileRevision> getComparator() {
    return this;
}