use of git4idea.GitFileRevision in project intellij-community by JetBrains.
the class GitSkippedCommits method getData.
@Override
public Object getData(String dataId) {
if (CommonDataKeys.PROJECT.is(dataId)) {
return myProject;
}
TreePath selectionPath = myTree.getSelectionPath();
DefaultMutableTreeNode node = selectionPath == null ? null : (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
Object o = node == null ? null : node.getUserObject();
if (o instanceof Commit) {
Commit c = (Commit) o;
if (VcsDataKeys.VCS_VIRTUAL_FILE.is(dataId)) {
return c.root;
}
if (VcsDataKeys.VCS_FILE_REVISION.is(dataId)) {
return new GitFileRevision(myProject, VcsUtil.getFilePath(c.root.getPath()), c.commitInfo.revision);
}
}
return super.getData(dataId);
}
use of git4idea.GitFileRevision in project intellij-community by JetBrains.
the class GithubOpenInBrowserAction method getDataFromHistory.
@Nullable
private static CommitData getDataFromHistory(AnActionEvent e) {
Project project = e.getData(CommonDataKeys.PROJECT);
FilePath filePath = e.getData(VcsDataKeys.FILE_PATH);
VcsFileRevision fileRevision = e.getData(VcsDataKeys.VCS_FILE_REVISION);
if (project == null || filePath == null || fileRevision == null)
return null;
if (!(fileRevision instanceof GitFileRevision))
return null;
GitRepository repository = GitUtil.getRepositoryManager(project).getRepositoryForFile(filePath);
if (repository == null || !GithubUtil.isRepositoryOnGitHub(repository))
return null;
return new CommitData(project, repository, fileRevision.getRevisionNumber().asString());
}
use of git4idea.GitFileRevision in project intellij-community by JetBrains.
the class GitDiffFromHistoryHandler method createParentRevision.
@NotNull
private GitFileRevision createParentRevision(@NotNull GitRepository repository, @NotNull GitFileRevision currentRevision, @NotNull String parentHash, @Nullable List<VcsFileRevision> revisions) throws VcsException {
if (revisions != null) {
for (VcsFileRevision revision : revisions) {
if (((GitFileRevision) revision).getHash().equals(parentHash)) {
return (GitFileRevision) revision;
}
}
}
FilePath currentRevisionPath = currentRevision.getPath();
if (currentRevisionPath.isDirectory()) {
// for directories the history doesn't follow renames
return makeRevisionFromHash(currentRevisionPath, parentHash);
}
// can't limit by the path: in that case rename information will be missed
Collection<Change> changes = GitChangeUtils.getDiff(myProject, repository.getRoot(), parentHash, currentRevision.getHash(), null);
for (Change change : changes) {
ContentRevision afterRevision = change.getAfterRevision();
ContentRevision beforeRevision = change.getBeforeRevision();
if (afterRevision != null && afterRevision.getFile().equals(currentRevisionPath)) {
// if the file was renamed, taking the path how it was in the parent; otherwise the path didn't change
FilePath path = (beforeRevision != null ? beforeRevision.getFile() : afterRevision.getFile());
return makeRevisionFromHash(path, parentHash);
}
}
LOG.error(String.format("Could not find parent revision. Will use the path from parent revision. Current revision: %s, parent hash: %s", currentRevision, parentHash));
return makeRevisionFromHash(currentRevisionPath, parentHash);
}
use of git4idea.GitFileRevision in project intellij-community by JetBrains.
the class GitHistoryUtilsTest method toReadable.
@NotNull
private String toReadable(@NotNull Collection<VcsFileRevision> history) {
int maxSubjectLength = findMaxLength(history, new Function<VcsFileRevision, String>() {
@Override
public String fun(VcsFileRevision revision) {
return revision.getCommitMessage();
}
});
StringBuilder sb = new StringBuilder();
for (VcsFileRevision revision : history) {
GitFileRevision rev = (GitFileRevision) revision;
String relPath = FileUtil.getRelativePath(new File(myProjectPath), rev.getPath().getIOFile());
sb.append(String.format("%s %-" + maxSubjectLength + "s %s%n", getShortHash(rev.getHash()), rev.getCommitMessage(), relPath));
}
return sb.toString();
}
Aggregations