mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
git annotate without history: fixing actions
This commit is contained in:
@@ -118,6 +118,10 @@ public abstract class FileAnnotation {
|
||||
return getRevisions();
|
||||
}
|
||||
|
||||
public VcsFileRevision getRevisionByDescription(VcsRevisionDescription description) {
|
||||
return (VcsFileRevision)description;
|
||||
}
|
||||
|
||||
public abstract boolean revisionsNotEmpty();
|
||||
|
||||
@Nullable
|
||||
|
||||
+6
-6
@@ -3,7 +3,7 @@ package com.intellij.openapi.vcs.actions;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.openapi.vcs.AbstractVcs;
|
||||
import com.intellij.openapi.vcs.annotate.FileAnnotation;
|
||||
import com.intellij.openapi.vcs.history.VcsFileRevision;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionDescription;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -14,19 +14,19 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
class AnnotateCurrentRevisionAction extends AnnotateRevisionAction {
|
||||
@Nullable private final List<VcsFileRevision> myRevisions;
|
||||
@Nullable private final List<VcsRevisionDescription> myRevisions;
|
||||
|
||||
public AnnotateCurrentRevisionAction(@NotNull FileAnnotation annotation, @NotNull AbstractVcs vcs) {
|
||||
super("Annotate Revision", "Annotate selected revision in new tab", AllIcons.Actions.Annotate,
|
||||
annotation, vcs);
|
||||
List<VcsFileRevision> revisions = annotation.getRevisions();
|
||||
List<? extends VcsRevisionDescription> revisions = annotation.getRevisionDescriptions();
|
||||
if (revisions == null) {
|
||||
myRevisions = null;
|
||||
return;
|
||||
}
|
||||
|
||||
Map<VcsRevisionNumber, VcsFileRevision> map = new HashMap<>();
|
||||
for (VcsFileRevision revision : revisions) {
|
||||
Map<VcsRevisionNumber, VcsRevisionDescription> map = new HashMap<>();
|
||||
for (VcsRevisionDescription revision : revisions) {
|
||||
map.put(revision.getRevisionNumber(), revision);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class AnnotateCurrentRevisionAction extends AnnotateRevisionAction {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public List<VcsFileRevision> getRevisions() {
|
||||
public List<VcsRevisionDescription> getRevisions() {
|
||||
return myRevisions;
|
||||
}
|
||||
}
|
||||
|
||||
+9
-8
@@ -6,6 +6,7 @@ import com.intellij.openapi.localVcs.UpToDateLineNumberProvider;
|
||||
import com.intellij.openapi.vcs.AbstractVcs;
|
||||
import com.intellij.openapi.vcs.annotate.FileAnnotation;
|
||||
import com.intellij.openapi.vcs.history.VcsFileRevision;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionDescription;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
@@ -17,23 +18,23 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
class AnnotatePreviousRevisionAction extends AnnotateRevisionAction {
|
||||
@Nullable private final List<VcsFileRevision> myRevisions;
|
||||
@Nullable private final VcsFileRevision myLastRevision;
|
||||
@Nullable private final List<VcsRevisionDescription> myRevisions;
|
||||
@Nullable private final VcsRevisionDescription myLastRevision;
|
||||
|
||||
public AnnotatePreviousRevisionAction(@NotNull FileAnnotation annotation, @NotNull AbstractVcs vcs) {
|
||||
super("Annotate Previous Revision", "Annotate successor of selected revision in new tab", AllIcons.Actions.Annotate,
|
||||
annotation, vcs);
|
||||
List<VcsFileRevision> revisions = annotation.getRevisions();
|
||||
List<? extends VcsRevisionDescription> revisions = annotation.getRevisionDescriptions();
|
||||
if (revisions == null) {
|
||||
myRevisions = null;
|
||||
myLastRevision = null;
|
||||
return;
|
||||
}
|
||||
|
||||
Map<VcsRevisionNumber, VcsFileRevision> map = new HashMap<>();
|
||||
Map<VcsRevisionNumber, VcsRevisionDescription> 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;
|
||||
VcsRevisionDescription revision = revisions.get(i);
|
||||
VcsRevisionDescription previousRevision = i + 1 < revisions.size() ? revisions.get(i + 1) : null;
|
||||
map.put(revision.getRevisionNumber(), previousRevision);
|
||||
}
|
||||
|
||||
@@ -47,7 +48,7 @@ class AnnotatePreviousRevisionAction extends AnnotateRevisionAction {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public List<VcsFileRevision> getRevisions() {
|
||||
public List<VcsRevisionDescription> getRevisions() {
|
||||
return myRevisions;
|
||||
}
|
||||
|
||||
@@ -55,7 +56,7 @@ class AnnotatePreviousRevisionAction extends AnnotateRevisionAction {
|
||||
@Override
|
||||
protected VcsFileRevision getFileRevision(@NotNull AnActionEvent e) {
|
||||
if (getCurrentLine() == UpToDateLineNumberProvider.ABSENT_LINE_NUMBER) {
|
||||
return myLastRevision;
|
||||
return myAnnotation.getRevisionByDescription(myLastRevision);
|
||||
}
|
||||
return super.getFileRevision(e);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.intellij.openapi.vcs.annotate.FileAnnotation;
|
||||
import com.intellij.openapi.vcs.annotate.UpToDateLineNumberListener;
|
||||
import com.intellij.openapi.vcs.history.VcsFileRevision;
|
||||
import com.intellij.openapi.vcs.history.VcsFileRevisionEx;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionDescription;
|
||||
import com.intellij.openapi.vcs.vfs.VcsFileSystem;
|
||||
import com.intellij.openapi.vcs.vfs.VcsVirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -24,7 +25,7 @@ import javax.swing.*;
|
||||
import java.util.List;
|
||||
|
||||
abstract class AnnotateRevisionAction extends AnnotateRevisionActionBase implements DumbAware, UpToDateLineNumberListener {
|
||||
@NotNull private final FileAnnotation myAnnotation;
|
||||
@NotNull protected final FileAnnotation myAnnotation;
|
||||
@NotNull private final AbstractVcs myVcs;
|
||||
|
||||
private int currentLine;
|
||||
@@ -48,17 +49,13 @@ abstract class AnnotateRevisionAction extends AnnotateRevisionActionBase impleme
|
||||
return;
|
||||
}
|
||||
|
||||
if (getRevisions() == null) {
|
||||
e.getPresentation().setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
e.getPresentation().setVisible(true);
|
||||
|
||||
super.update(e);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract List<VcsFileRevision> getRevisions();
|
||||
protected abstract List<VcsRevisionDescription> getRevisions();
|
||||
|
||||
@Nullable
|
||||
protected AbstractVcs getVcs(@NotNull AnActionEvent e) {
|
||||
@@ -89,7 +86,14 @@ abstract class AnnotateRevisionAction extends AnnotateRevisionActionBase impleme
|
||||
@Nullable
|
||||
@Override
|
||||
protected VcsFileRevision getFileRevision(@NotNull AnActionEvent e) {
|
||||
List<VcsFileRevision> revisions = getRevisions();
|
||||
VcsRevisionDescription description = getRevisionDescription(e);
|
||||
return description == null ? null : myAnnotation.getRevisionByDescription(description);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected VcsRevisionDescription getRevisionDescription(@NotNull AnActionEvent e) {
|
||||
List<VcsRevisionDescription> revisions = getRevisions();
|
||||
assert revisions != null;
|
||||
|
||||
if (currentLine < 0 || currentLine >= revisions.size()) return null;
|
||||
|
||||
+8
-7
@@ -18,6 +18,7 @@ import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.annotate.AnnotationProvider;
|
||||
import com.intellij.openapi.vcs.annotate.FileAnnotation;
|
||||
import com.intellij.openapi.vcs.history.VcsFileRevision;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionDescription;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.diff.Diff;
|
||||
import com.intellij.util.diff.FilesTooBigForDiffException;
|
||||
@@ -43,6 +44,11 @@ public abstract class AnnotateRevisionActionBase extends AnAction {
|
||||
@Nullable
|
||||
protected abstract VcsFileRevision getFileRevision(@NotNull AnActionEvent e);
|
||||
|
||||
@Nullable
|
||||
protected VcsRevisionDescription getRevisionDescription(@NotNull AnActionEvent e) {
|
||||
return getFileRevision(e);
|
||||
};
|
||||
|
||||
@Nullable
|
||||
protected Editor getEditor(@NotNull AnActionEvent e) {
|
||||
return null;
|
||||
@@ -60,19 +66,14 @@ public abstract class AnnotateRevisionActionBase extends AnAction {
|
||||
public boolean isEnabled(@NotNull AnActionEvent e) {
|
||||
if (e.getProject() == null) return false;
|
||||
|
||||
VcsFileRevision fileRevision = getFileRevision(e);
|
||||
VcsRevisionDescription fileRevision = getRevisionDescription(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.getCachingAnnotationProvider();
|
||||
if (provider == null || !provider.isAnnotationValid(fileRevision)) return false;
|
||||
|
||||
if (VcsAnnotateUtil.getBackgroundableLock(vcs.getProject(), file).isLocked()) return false;
|
||||
if (provider == null || (fileRevision instanceof VcsFileRevision) && !provider.isAnnotationValid((VcsFileRevision)fileRevision)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public class GitAnnotationProvider implements AnnotationProviderEx, VcsCacheable
|
||||
private final Project myProject;
|
||||
@NonNls private static final String AUTHOR_KEY = "author";
|
||||
@NonNls private static final String COMMITTER_TIME_KEY = "committer-time";
|
||||
@NonNls private static final String FILENAME_KEY = "filename";
|
||||
private static final Logger LOG = Logger.getInstance(GitAnnotationProvider.class);
|
||||
|
||||
public GitAnnotationProvider(@NotNull Project project) {
|
||||
@@ -129,7 +130,8 @@ public class GitAnnotationProvider implements AnnotationProviderEx, VcsCacheable
|
||||
private GitFileAnnotation annotate(@NotNull final FilePath repositoryFilePath,
|
||||
@Nullable final VcsRevisionNumber revision,
|
||||
@NotNull final VirtualFile file) throws VcsException {
|
||||
GitSimpleHandler h = new GitSimpleHandler(myProject, GitUtil.getGitRoot(repositoryFilePath), GitCommand.BLAME);
|
||||
VirtualFile root = GitUtil.getGitRoot(repositoryFilePath);
|
||||
GitSimpleHandler h = new GitSimpleHandler(myProject, root, GitCommand.BLAME);
|
||||
h.setStdoutSuppressed(true);
|
||||
h.setCharset(file.getCharset());
|
||||
h.addParameters("--porcelain", "-l", "-t", "-w");
|
||||
@@ -142,13 +144,13 @@ public class GitAnnotationProvider implements AnnotationProviderEx, VcsCacheable
|
||||
h.endOptions();
|
||||
h.addRelativePaths(repositoryFilePath);
|
||||
String output = h.run();
|
||||
return parseAnnotations(revision, file, output);
|
||||
return parseAnnotations(revision, file, output, root);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private GitFileAnnotation parseAnnotations(@Nullable VcsRevisionNumber revision,
|
||||
@NotNull VirtualFile file,
|
||||
@NotNull String output) throws VcsException {
|
||||
@NotNull String output, VirtualFile root) throws VcsException {
|
||||
try {
|
||||
List<LineInfo> lines = new ArrayList<>();
|
||||
HashMap<String, LineInfo> commits = new HashMap<>();
|
||||
@@ -173,6 +175,7 @@ public class GitAnnotationProvider implements AnnotationProviderEx, VcsCacheable
|
||||
GitRevisionNumber revisionNumber = null;
|
||||
Date committerDate = null;
|
||||
String author = null;
|
||||
String path = null;
|
||||
|
||||
while (s.hasMoreData() && !s.startsWith('\t')) {
|
||||
String key = s.spaceToken();
|
||||
@@ -184,8 +187,11 @@ public class GitAnnotationProvider implements AnnotationProviderEx, VcsCacheable
|
||||
committerDate = GitUtil.parseTimestamp(value);
|
||||
revisionNumber = new GitRevisionNumber(commitHash, committerDate);
|
||||
}
|
||||
if (FILENAME_KEY.equals(key)) {
|
||||
path = value;
|
||||
}
|
||||
}
|
||||
commit = new LineInfo(committerDate, revisionNumber, author);
|
||||
commit = new LineInfo(committerDate, revisionNumber, author, root.getPath() + "/" + path);
|
||||
commits.put(commitHash, commit);
|
||||
}
|
||||
// parse line
|
||||
@@ -242,7 +248,7 @@ public class GitAnnotationProvider implements AnnotationProviderEx, VcsCacheable
|
||||
if (vcsFileRevision == null) {
|
||||
return null;
|
||||
}
|
||||
lines.add(new LineInfo(vcsFileRevision.getRevisionDate(), revision, vcsFileRevision.getAuthor()));
|
||||
lines.add(new LineInfo(vcsFileRevision.getRevisionDate(), revision, vcsFileRevision.getAuthor(), ((LineInfo)vcsFileRevision).getPath()));
|
||||
}
|
||||
return new GitFileAnnotation(myProject, virtualFile, revisionNumber, lines);
|
||||
}
|
||||
|
||||
@@ -18,8 +18,10 @@ package git4idea.annotate;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.vcs.FilePath;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.VcsKey;
|
||||
import com.intellij.openapi.vcs.actions.VcsContextFactory;
|
||||
import com.intellij.openapi.vcs.annotate.*;
|
||||
import com.intellij.openapi.vcs.changes.ContentRevision;
|
||||
import com.intellij.openapi.vcs.history.VcsFileRevision;
|
||||
@@ -167,6 +169,13 @@ public class GitFileAnnotation extends FileAnnotation {
|
||||
return myRevisions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VcsFileRevision getRevisionByDescription(VcsRevisionDescription description) {
|
||||
LineInfo lineInfo = (LineInfo)description;
|
||||
FilePath path = VcsContextFactory.SERVICE.getInstance().createFilePath(lineInfo.getPath(), false);
|
||||
return new GitFileRevision(myProject, path, (GitRevisionNumber)description.getRevisionNumber());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revisionsNotEmpty() {
|
||||
return !myRevisions.isEmpty();
|
||||
@@ -250,11 +259,13 @@ public class GitFileAnnotation extends FileAnnotation {
|
||||
private final Date myDate;
|
||||
private final GitRevisionNumber myRevision;
|
||||
private final String myAuthor;
|
||||
private final String myPath;
|
||||
|
||||
public LineInfo(Date date, GitRevisionNumber revision, String author) {
|
||||
public LineInfo(Date date, GitRevisionNumber revision, String author, String path) {
|
||||
myDate = date;
|
||||
myRevision = revision;
|
||||
myAuthor = author;
|
||||
myPath = path;
|
||||
}
|
||||
|
||||
public Date getRevisionDate() {
|
||||
@@ -274,6 +285,10 @@ public class GitFileAnnotation extends FileAnnotation {
|
||||
public String getCommitMessage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return myPath;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user