use of org.opengrok.indexer.util.Progress in project OpenGrok by OpenGrok.
the class FileHistoryCache method storeRenamed.
/**
* handle renamed files (in parallel).
* @param renamedFiles set of renamed file paths
* @param repository repository
* @param tillRevision end revision (can be null)
*/
public void storeRenamed(Set<String> renamedFiles, Repository repository, String tillRevision) throws HistoryException {
final File root = env.getSourceRootFile();
if (renamedFiles.isEmpty()) {
return;
}
renamedFiles = renamedFiles.stream().filter(f -> new File(env.getSourceRootPath() + f).exists()).collect(Collectors.toSet());
LOGGER.log(Level.FINE, "Storing history for {0} renamed files in repository ''{1}'' till {2}", new Object[] { renamedFiles.size(), repository, getRevisionString(tillRevision) });
createDirectoriesForFiles(renamedFiles, repository, "renamed files for history " + getRevisionString(tillRevision));
final Repository repositoryF = repository;
final CountDownLatch latch = new CountDownLatch(renamedFiles.size());
AtomicInteger renamedFileHistoryCount = new AtomicInteger();
try (Progress progress = new Progress(LOGGER, String.format("history cache for renamed files of %s till %s", repository, getRevisionString(tillRevision)), renamedFiles.size())) {
for (final String file : renamedFiles) {
env.getIndexerParallelizer().getHistoryFileExecutor().submit(() -> {
try {
doRenamedFileHistory(file, new File(env.getSourceRootPath() + file), repositoryF, root, tillRevision);
renamedFileHistoryCount.getAndIncrement();
} catch (Exception ex) {
// We want to catch any exception since we are in thread.
LOGGER.log(Level.WARNING, "doFileHistory() got exception ", ex);
} finally {
latch.countDown();
progress.increment();
}
});
}
// Wait for the executors to finish.
try {
// Wait for the executors to finish.
latch.await();
} catch (InterruptedException ex) {
LOGGER.log(Level.SEVERE, "latch exception", ex);
}
}
LOGGER.log(Level.FINE, "Stored history for {0} renamed files in repository ''{1}''", new Object[] { renamedFileHistoryCount.intValue(), repository });
}
Aggregations