Search in sources :

Example 1 with GitHeavyCommit

use of git4idea.history.browser.GitHeavyCommit in project intellij-community by JetBrains.

the class GitCommittedChangeListProvider method getOneList.

@Override
public Pair<CommittedChangeList, FilePath> getOneList(final VirtualFile file, final VcsRevisionNumber number) throws VcsException {
    FilePath filePath = VcsUtil.getFilePath(file);
    final List<GitHeavyCommit> gitCommits = GitHistoryUtils.commitsDetails(myProject, filePath, new SymbolicRefs(), Collections.singletonList(number.asString()));
    if (gitCommits.size() != 1) {
        return null;
    }
    final GitHeavyCommit gitCommit = gitCommits.get(0);
    CommittedChangeList commit = new GitCommittedChangeList(gitCommit.getDescription() + " (" + gitCommit.getShortHash().getString() + ")", gitCommit.getDescription(), gitCommit.getAuthor(), (GitRevisionNumber) number, new Date(gitCommit.getAuthorTime()), gitCommit.getChanges(), assertNotNull(GitVcs.getInstance(myProject)), true);
    final Collection<Change> changes = commit.getChanges();
    if (changes.size() == 1) {
        Change change = changes.iterator().next();
        return Pair.create(commit, ChangesUtil.getFilePath(change));
    }
    for (Change change : changes) {
        if (change.getAfterRevision() != null && FileUtil.filesEqual(filePath.getIOFile(), change.getAfterRevision().getFile().getIOFile())) {
            return Pair.create(commit, filePath);
        }
    }
    final String afterTime = "--after=" + GitUtil.gitTime(gitCommit.getDate());
    final List<VcsFileRevision> history = GitHistoryUtils.history(myProject, filePath, (VirtualFile) null, afterTime);
    if (history.isEmpty()) {
        return Pair.create(commit, filePath);
    }
    return Pair.create(commit, ((GitFileRevision) history.get(history.size() - 1)).getPath());
}
Also used : SymbolicRefs(git4idea.history.browser.SymbolicRefs) GitHeavyCommit(git4idea.history.browser.GitHeavyCommit) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) Change(com.intellij.openapi.vcs.changes.Change) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision)

Example 2 with GitHeavyCommit

use of git4idea.history.browser.GitHeavyCommit in project intellij-community by JetBrains.

the class GitHistoryUtils method createCommit.

@NotNull
private static GitHeavyCommit createCommit(@NotNull Project project, @Nullable SymbolicRefsI refs, @NotNull VirtualFile root, @NotNull GitLogRecord record) throws VcsException {
    final Collection<String> currentRefs = record.getRefs();
    List<String> locals = new ArrayList<>();
    List<String> remotes = new ArrayList<>();
    List<String> tags = new ArrayList<>();
    final String s = parseRefs(refs, currentRefs, locals, remotes, tags);
    GitHeavyCommit gitCommit = new GitHeavyCommit(root, AbstractHash.create(record.getHash()), new SHAHash(record.getHash()), record.getAuthorName(), record.getCommitterName(), record.getDate(), record.getSubject(), record.getFullMessage(), new HashSet<>(Arrays.asList(record.getParentsHashes())), record.getFilePaths(root), record.getAuthorEmail(), record.getCommitterEmail(), tags, locals, remotes, record.parseChanges(project, root), record.getAuthorTimeStamp());
    gitCommit.setCurrentBranch(s);
    return gitCommit;
}
Also used : SHAHash(git4idea.history.browser.SHAHash) GitHeavyCommit(git4idea.history.browser.GitHeavyCommit) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GitHeavyCommit

use of git4idea.history.browser.GitHeavyCommit in project intellij-community by JetBrains.

the class GitHistoryUtils method commitsDetails.

@Deprecated
@NotNull
public static List<GitHeavyCommit> commitsDetails(@NotNull Project project, @NotNull FilePath path, @Nullable SymbolicRefsI refs, @NotNull Collection<String> commitsIds) throws VcsException {
    // adjust path using change manager
    path = getLastCommitName(project, path);
    VirtualFile root = GitUtil.getGitRoot(path);
    GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.SHOW);
    GitLogParser parser = new GitLogParser(project, GitLogParser.NameStatus.STATUS, HASH, HASH, COMMIT_TIME, AUTHOR_NAME, AUTHOR_TIME, AUTHOR_EMAIL, COMMITTER_NAME, COMMITTER_EMAIL, PARENTS, REF_NAMES, SUBJECT, BODY, RAW_BODY);
    h.setSilent(true);
    h.addParameters("--name-status", "-M", parser.getPretty(), "--encoding=UTF-8");
    h.addParameters(new ArrayList<>(commitsIds));
    String output = h.run();
    final List<GitHeavyCommit> rc = new ArrayList<>();
    for (GitLogRecord record : parser.parse(output)) {
        final GitHeavyCommit gitCommit = createCommit(project, refs, root, record);
        rc.add(gitCommit);
    }
    return rc;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitHeavyCommit(git4idea.history.browser.GitHeavyCommit) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GitHeavyCommit (git4idea.history.browser.GitHeavyCommit)3 NotNull (org.jetbrains.annotations.NotNull)2 Change (com.intellij.openapi.vcs.changes.Change)1 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)1 CommittedChangeList (com.intellij.openapi.vcs.versionBrowser.CommittedChangeList)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 SHAHash (git4idea.history.browser.SHAHash)1 SymbolicRefs (git4idea.history.browser.SymbolicRefs)1