Search in sources :

Example 1 with GitRepository

use of net.nemerosa.ontrack.git.GitRepository in project ontrack by nemerosa.

the class GitRepositoryClientImpl method log.

@Override
public Stream<GitCommit> log(String from, String to) {
    try {
        Repository gitRepository = git.getRepository();
        ObjectId oFrom = gitRepository.resolve(from);
        ObjectId oTo = gitRepository.resolve(to);
        if (oFrom == null || oTo == null) {
            return Collections.<GitCommit>emptyList().stream();
        } else {
            return Lists.newArrayList(git.log().addRange(oFrom, oTo).call()).stream().map(this::toCommit);
        }
    } catch (GitAPIException e) {
        throw new GitRepositoryAPIException(repository.getRemote(), e);
    } catch (IOException e) {
        throw new GitRepositoryIOException(repository.getRemote(), e);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) GitRepository(net.nemerosa.ontrack.git.GitRepository) IOException(java.io.IOException)

Example 2 with GitRepository

use of net.nemerosa.ontrack.git.GitRepository in project ontrack by nemerosa.

the class GitRepositoryClientImpl method range.

protected GitRange range(String from, String to, boolean reorder) throws IOException {
    Repository gitRepository = git.getRepository();
    ObjectId oFrom = gitRepository.resolve(from);
    ObjectId oTo = gitRepository.resolve(to);
    RevWalk walk = new RevWalk(gitRepository);
    RevCommit commitFrom = walk.parseCommit(oFrom);
    RevCommit commitTo = walk.parseCommit(oTo);
    if (reorder && commitFrom.getCommitTime() > commitTo.getCommitTime()) {
        RevCommit t = commitFrom;
        commitFrom = commitTo;
        commitTo = t;
    }
    return new GitRange(commitFrom, commitTo);
}
Also used : GitRepository(net.nemerosa.ontrack.git.GitRepository) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

GitRepository (net.nemerosa.ontrack.git.GitRepository)2 IOException (java.io.IOException)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1