Search in sources :

Example 6 with GitFileRevision

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);
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) GitFileRevision(git4idea.GitFileRevision)

Example 7 with GitFileRevision

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());
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) Project(com.intellij.openapi.project.Project) GitRepository(git4idea.repo.GitRepository) GitFileRevision(git4idea.GitFileRevision) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with GitFileRevision

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);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) GitFileRevision(git4idea.GitFileRevision) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) Change(com.intellij.openapi.vcs.changes.Change) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with GitFileRevision

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();
}
Also used : GitFileRevision(git4idea.GitFileRevision) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GitFileRevision (git4idea.GitFileRevision)9 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)5 NotNull (org.jetbrains.annotations.NotNull)4 FilePath (com.intellij.openapi.vcs.FilePath)3 Nullable (org.jetbrains.annotations.Nullable)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 GitRevisionNumber (git4idea.GitRevisionNumber)2 Project (com.intellij.openapi.project.Project)1 VcsException (com.intellij.openapi.vcs.VcsException)1 Change (com.intellij.openapi.vcs.changes.Change)1 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)1 MergeData (com.intellij.openapi.vcs.merge.MergeData)1 CommittedChangeList (com.intellij.openapi.vcs.versionBrowser.CommittedChangeList)1 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)1 VcsRunnable (com.intellij.vcsUtil.VcsRunnable)1 GitContentRevision (git4idea.GitContentRevision)1 GitRepository (git4idea.repo.GitRepository)1 File (java.io.File)1 IOException (java.io.IOException)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1