Line data Source code
1 : // Copyright (C) 2009 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.git; 16 : 17 : import com.google.gerrit.entities.Project; 18 : import com.google.inject.ImplementedBy; 19 : import com.google.inject.Singleton; 20 : import java.io.IOException; 21 : import java.util.NavigableSet; 22 : import org.eclipse.jgit.errors.RepositoryNotFoundException; 23 : import org.eclipse.jgit.lib.Repository; 24 : 25 : /** 26 : * Manages Git repositories for the Gerrit server process. 27 : * 28 : * <p>Implementations of this interface should be a {@link Singleton} and registered in Guice so 29 : * they are globally available within the server environment. 30 : */ 31 : @ImplementedBy(value = LocalDiskRepositoryManager.class) 32 : public interface GitRepositoryManager { 33 : 34 : /** Status of the repository. */ 35 144 : enum Status { 36 : /** Repository exists and is available on host. */ 37 144 : ACTIVE, 38 : /** Repository does not exist. */ 39 144 : NON_EXISTENT, 40 : /** 41 : * Repository might exist but can not be opened. This can for example be the case when the 42 : * repository is pending deletion / the caller does not have permissions / repository is broken. 43 : */ 44 144 : UNAVAILABLE; 45 : } 46 : 47 : /** Get {@link Status} of the repository by name. */ 48 : Status getRepositoryStatus(Project.NameKey name); 49 : 50 : /** 51 : * Get (or open) a repository by name. 52 : * 53 : * @param name the repository name, relative to the base directory. 54 : * @return the cached Repository instance. Caller must call {@code close()} when done to decrement 55 : * the resource handle. 56 : * @throws RepositoryNotFoundException the name does not denote an existing repository. 57 : * @throws IOException the name cannot be read as a repository. 58 : */ 59 : Repository openRepository(Project.NameKey name) throws RepositoryNotFoundException, IOException; 60 : 61 : /** 62 : * Create (and open) a repository by name. 63 : * 64 : * @param name the repository name, relative to the base directory. 65 : * @return the cached Repository instance. Caller must call {@code close()} when done to decrement 66 : * the resource handle. 67 : * @throws RepositoryExistsException repository exists. 68 : * @throws RepositoryCaseMismatchException the name collides with an existing repository name, but 69 : * only in case of a character within the name. 70 : * @throws RepositoryNotFoundException the name is invalid. 71 : * @throws IOException the repository cannot be created. 72 : */ 73 : Repository createRepository(Project.NameKey name) 74 : throws RepositoryNotFoundException, RepositoryExistsException, IOException; 75 : 76 : /** Returns set of all known projects, sorted by natural NameKey order. */ 77 : NavigableSet<Project.NameKey> list(); 78 : 79 : /** 80 : * Check if garbage collection can be performed by the repository manager. 81 : * 82 : * @return true if repository can perform garbage collection. 83 : */ 84 : default Boolean canPerformGC() { 85 139 : return false; 86 : } 87 : }