Search in sources :

Example 1 with LogPage

use of org.eclipse.che.api.git.LogPage in project che by eclipse.

the class JGitConnection method log.

/** @see org.eclipse.che.api.git.GitConnection#log(LogParams) */
@Override
public LogPage log(LogParams params) throws GitException {
    LogCommand logCommand = getGit().log();
    try {
        setRevisionRange(logCommand, params);
        logCommand.setSkip(params.getSkip());
        logCommand.setMaxCount(params.getMaxCount());
        List<String> fileFilter = params.getFileFilter();
        if (fileFilter != null) {
            fileFilter.forEach(logCommand::addPath);
        }
        String filePath = params.getFilePath();
        if (!isNullOrEmpty(filePath)) {
            logCommand.addPath(filePath);
        }
        Iterator<RevCommit> revIterator = logCommand.call().iterator();
        List<Revision> commits = new ArrayList<>();
        while (revIterator.hasNext()) {
            RevCommit commit = revIterator.next();
            Revision revision = getRevision(commit, filePath);
            commits.add(revision);
        }
        return new LogPage(commits);
    } catch (GitAPIException | IOException exception) {
        String errorMessage = exception.getMessage();
        if (ERROR_LOG_NO_HEAD_EXISTS.equals(errorMessage)) {
            throw new GitException(errorMessage, ErrorCodes.INIT_COMMIT_WAS_NOT_PERFORMED);
        } else {
            LOG.error("Failed to retrieve log. ", exception);
            throw new GitException(exception);
        }
    }
}
Also used : GitException(org.eclipse.che.api.git.exception.GitException) LogPage(org.eclipse.che.api.git.LogPage) ArrayList(java.util.ArrayList) IOException(java.io.IOException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Revision(org.eclipse.che.api.git.shared.Revision) LogCommand(org.eclipse.jgit.api.LogCommand) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LogPage (org.eclipse.che.api.git.LogPage)1 GitException (org.eclipse.che.api.git.exception.GitException)1 Revision (org.eclipse.che.api.git.shared.Revision)1 LogCommand (org.eclipse.jgit.api.LogCommand)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1