Search in sources :

Example 1 with RefPatternMatcher

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());
                    }
                }
            }
        }
    }
}
Also used : AllUsersName(com.google.gerrit.server.config.AllUsersName) AccountCache(com.google.gerrit.server.account.AccountCache) Arrays(java.util.Arrays) ProjectCache(com.google.gerrit.server.project.ProjectCache) MultimapBuilder(com.google.common.collect.MultimapBuilder) Inject(com.google.inject.Inject) Multimap(com.google.common.collect.Multimap) RefPatternMatcher(com.google.gerrit.server.project.RefPatternMatcher) GroupIndexer(com.google.gerrit.server.index.group.GroupIndexer) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) RefNames(com.google.gerrit.entities.RefNames) Collectors.toSet(java.util.stream.Collectors.toSet) AccountGroup(com.google.gerrit.entities.AccountGroup) RefState(com.google.gerrit.index.RefState) Collection(java.util.Collection) Account(com.google.gerrit.entities.Account) Set(java.util.Set) RefUpdate(org.eclipse.jgit.lib.RefUpdate) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) GroupIncludeCache(com.google.gerrit.server.account.GroupIncludeCache) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ObjectId(org.eclipse.jgit.lib.ObjectId) Objects(java.util.Objects) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) Stream(java.util.stream.Stream) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) Ref(org.eclipse.jgit.lib.Ref) Project(com.google.gerrit.entities.Project) REFS_USERS(com.google.gerrit.entities.RefNames.REFS_USERS) GroupCache(com.google.gerrit.server.account.GroupCache) Repository(org.eclipse.jgit.lib.Repository) AccountIndexer(com.google.gerrit.server.index.account.AccountIndexer) Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) RefPatternMatcher(com.google.gerrit.server.project.RefPatternMatcher) Collection(java.util.Collection) Map(java.util.Map) RefUpdate(org.eclipse.jgit.lib.RefUpdate)

Aggregations

Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 Multimap (com.google.common.collect.Multimap)1 MultimapBuilder (com.google.common.collect.MultimapBuilder)1 Sets (com.google.common.collect.Sets)1 Nullable (com.google.gerrit.common.Nullable)1 Account (com.google.gerrit.entities.Account)1 AccountGroup (com.google.gerrit.entities.AccountGroup)1 Project (com.google.gerrit.entities.Project)1 RefNames (com.google.gerrit.entities.RefNames)1 REFS_USERS (com.google.gerrit.entities.RefNames.REFS_USERS)1 RefState (com.google.gerrit.index.RefState)1 AccountCache (com.google.gerrit.server.account.AccountCache)1 GroupCache (com.google.gerrit.server.account.GroupCache)1 GroupIncludeCache (com.google.gerrit.server.account.GroupIncludeCache)1 AllUsersName (com.google.gerrit.server.config.AllUsersName)1 GitRepositoryManager (com.google.gerrit.server.git.GitRepositoryManager)1 AccountIndexer (com.google.gerrit.server.index.account.AccountIndexer)1 GroupIndexer (com.google.gerrit.server.index.group.GroupIndexer)1 ProjectCache (com.google.gerrit.server.project.ProjectCache)1