Search in sources :

Example 1 with LogCommand

use of org.eclipse.jgit.api.LogCommand 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)

Example 2 with LogCommand

use of org.eclipse.jgit.api.LogCommand in project Gargoyle by callakrsos.

the class GitTest method history.

@Test
public void history() throws IOException, NoHeadException, GitAPIException {
    Git open = Git.open(new File("C:\\Users\\KYJ\\.git\\Gargoyle"));
    LogCommand log = open.log();
    log.call().forEach(coit -> {
        ObjectId id = coit.getId();
        String idName = id.getName();
        String fullMessage = coit.getFullMessage();
        String name = coit.getCommitterIdent().getName();
        Date when = coit.getCommitterIdent().getWhen();
        String date = DateUtil.toString(when, DateUtil.SYSTEM_DATEFORMAT_YYYY_MM_DD_HH_MM_SS);
        System.out.printf("%s \t\t %s \t\t %s\t\t %s\n", idName, date, name, fullMessage);
    });
}
Also used : Git(org.eclipse.jgit.api.Git) ObjectId(org.eclipse.jgit.lib.ObjectId) LogCommand(org.eclipse.jgit.api.LogCommand) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 3 with LogCommand

use of org.eclipse.jgit.api.LogCommand in project che by eclipse.

the class JGitConnection method getCommiters.

@Override
public List<GitUser> getCommiters() throws GitException {
    List<GitUser> gitUsers = new ArrayList<>();
    try {
        LogCommand logCommand = getGit().log();
        for (RevCommit commit : logCommand.call()) {
            PersonIdent committerIdentity = commit.getCommitterIdent();
            GitUser gitUser = newDto(GitUser.class).withName(committerIdentity.getName()).withEmail(committerIdentity.getEmailAddress());
            if (!gitUsers.contains(gitUser)) {
                gitUsers.add(gitUser);
            }
        }
    } catch (GitAPIException exception) {
        throw new GitException(exception.getMessage(), exception);
    }
    return gitUsers;
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) PersonIdent(org.eclipse.jgit.lib.PersonIdent) LogCommand(org.eclipse.jgit.api.LogCommand) GitException(org.eclipse.che.api.git.exception.GitException) ArrayList(java.util.ArrayList) GitUser(org.eclipse.che.api.git.shared.GitUser) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

LogCommand (org.eclipse.jgit.api.LogCommand)3 ArrayList (java.util.ArrayList)2 GitException (org.eclipse.che.api.git.exception.GitException)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 File (java.io.File)1 IOException (java.io.IOException)1 Date (java.util.Date)1 LogPage (org.eclipse.che.api.git.LogPage)1 GitUser (org.eclipse.che.api.git.shared.GitUser)1 Revision (org.eclipse.che.api.git.shared.Revision)1 Git (org.eclipse.jgit.api.Git)1 ObjectId (org.eclipse.jgit.lib.ObjectId)1 PersonIdent (org.eclipse.jgit.lib.PersonIdent)1 Test (org.junit.Test)1