use of org.jooq.Commit in project jOOQ by jOOQ.
the class GitCommitProvider method provide.
@Override
public final Commits provide() {
Commits commits = Migrations.commits(dsl.configuration());
try (Git g = Git.open(git.repository());
Repository r = g.getRepository()) {
List<RevCommit> revCommits = new ArrayList<>();
RevCommit last = null;
try {
for (RevCommit commit : g.log().call()) {
if (last == null)
last = commit;
revCommits.add(commit);
}
} catch (NoHeadException e) {
log.debug("No HEAD exists");
}
// The commits seem to come in reverse order from jgit.
Collections.reverse(revCommits);
Commit init = commits.root();
// TODO: We collect all the commits from git, when we could ignore the empty ones
while (!revCommits.isEmpty()) {
Iterator<RevCommit> it = revCommits.iterator();
commitLoop: while (it.hasNext()) {
RevCommit revCommit = it.next();
if (revCommit.getParents() == null || revCommit.getParents().length == 0) {
commits.add(init.commit(revCommit.getName(), revCommit.getFullMessage(), editFiles(r, revCommit)));
it.remove();
} else {
Commit[] parents = new Commit[revCommit.getParentCount()];
// It seems the parents are not ordered deterministically in the order of which they were merged
List<RevCommit> l = new ArrayList<>(asList(revCommit.getParents()));
l.sort(COMMIT_COMPARATOR);
for (int i = 0; i < parents.length; i++) if ((parents[i] = commits.get(revCommit.getParents()[i].getName())) == null)
continue commitLoop;
if (parents.length == 1)
commits.add(parents[0].commit(revCommit.getName(), revCommit.getFullMessage(), editFiles(r, revCommit)));
else if (parents.length == 2)
commits.add(parents[0].merge(revCommit.getName(), revCommit.getFullMessage(), parents[1], editFiles(r, revCommit)));
else
throw new UnsupportedOperationException("Merging more than two parents not yet supported");
it.remove();
}
}
}
Status status = g.status().call();
if (status.hasUncommittedChanges() || !status.getUntracked().isEmpty())
commits.add(commit(last != null ? commits.get(last.getName()) : init, status));
} catch (Exception e) {
throw new GitException("Error while providing git versions", e);
}
return commits;
}
Aggregations