use of org.craftercms.studio.impl.v2.utils.RingBuffer in project studio by craftercms.
the class GitContentRepository method updateGitlog.
@Override
public void updateGitlog(String siteId, String lastProcessedCommitId, int batchSize) throws SiteNotFoundException {
RingBuffer<RevCommit> commitIds = new RingBuffer<RevCommit>(batchSize);
try {
GitRepositoryHelper helper = GitRepositoryHelper.getHelper(studioConfiguration, securityService, userServiceInternal, encryptor, generalLockService, retryingRepositoryOperationFacade);
Repository repository = helper.getRepository(siteId, StringUtils.isEmpty(siteId) ? GLOBAL : SANDBOX);
if (repository != null) {
try {
ObjectId objCommitIdFrom = repository.resolve(lastProcessedCommitId);
ObjectId objCommitIdTo = repository.resolve(HEAD);
logger.debug("Update git log from " + objCommitIdFrom.getName() + " to " + objCommitIdTo.getName());
try (Git git = new Git(repository)) {
// let's do it
if (!objCommitIdFrom.equals(objCommitIdTo)) {
// Get the log of all the commits between commitId and head
Iterable<RevCommit> commits = git.log().call();
ObjectId nextCommitId;
String commitId = EMPTY;
Iterator<RevCommit> iterator = commits.iterator();
while (iterator.hasNext()) {
RevCommit commit = iterator.next();
if (StringUtils.equals(commit.getId().getName(), lastProcessedCommitId)) {
break;
}
commitIds.write(commit);
}
List<String> batch = new ArrayList<String>();
RevCommit current = commitIds.read();
while (current != null) {
nextCommitId = current.getId();
commitId = nextCommitId.getName();
if (StringUtils.contains(current.getFullMessage(), studioConfiguration.getProperty(REPO_SYNC_DB_COMMIT_MESSAGE_NO_PROCESSING))) {
logger.debug("Skipping commitId: " + commitId + " for site " + siteId + " because it is marked not to be processed.");
} else {
batch.add(0, commitId);
}
current = commitIds.read();
}
if (batch.size() > 0) {
gitLogDao.insertIgnoreGitLogList(siteId, batch);
siteService.updateLastSyncedGitlogCommitId(siteId, batch.get(batch.size() - 1));
logger.debug("Inserted " + batch.size() + " git log commits for site " + siteId);
} else {
siteService.updateLastSyncedGitlogCommitId(siteId, objCommitIdTo.getName());
}
}
} catch (GitAPIException e) {
logger.error("Error getting commit ids for site " + siteId + " from commit ID: " + lastProcessedCommitId + " to HEAD", e);
}
} catch (IOException e) {
logger.error("Error getting commit ids for site " + siteId + " from commit ID: " + lastProcessedCommitId + " to HEAD", e);
}
}
} catch (CryptoException e) {
logger.error("Error getting commit ids for site " + siteId + " from commit ID: " + lastProcessedCommitId + " to HEAD", e);
}
}
Aggregations