use of com.google.gerrit.server.project.RefPatternMatcher in project gerrit by GerritCodeReview.
the class ProjectResetter method deleteNewlyCreatedRefs.
private void deleteNewlyCreatedRefs() throws IOException {
for (Map.Entry<Project.NameKey, Collection<String>> e : refsPatternByProject.asMap().entrySet()) {
try (Repository repo = repoManager.openRepository(e.getKey())) {
Collection<Ref> nonRestoredRefs = repo.getRefDatabase().getRefs().stream().filter(r -> !keptRefsByProject.containsEntry(e.getKey(), r.getName()) && !restoredRefsByProject.containsEntry(e.getKey(), r.getName())).collect(toSet());
for (String refPattern : e.getValue()) {
RefPatternMatcher matcher = RefPatternMatcher.getMatcher(refPattern);
for (Ref ref : nonRestoredRefs) {
if (matcher.match(ref.getName(), null) && !deletedRefsByProject.containsEntry(e.getKey(), ref.getName())) {
RefUpdate updateRef = repo.updateRef(ref.getName());
updateRef.setExpectedOldObjectId(ref.getObjectId());
updateRef.setNewObjectId(ObjectId.zeroId());
updateRef.setForceUpdate(true);
RefUpdate.Result result = updateRef.delete();
checkState(result == RefUpdate.Result.FORCED, "deleting branch %s in %s failed", ref.getName(), e.getKey());
deletedRefsByProject.put(e.getKey(), ref.getName());
}
}
}
}
}
}
Aggregations