use of org.eclipse.jgit.storage.file.FileBasedConfig in project gitblit by gitblit.
the class RepositoryManager method getRepositoryModel.
/**
* Returns the repository model for the specified repository. This method
* does not consider user access permissions.
*
* @param name
* @return repository model or null
*/
@Override
public RepositoryModel getRepositoryModel(String name) {
String repositoryName = fixRepositoryName(name);
String repositoryKey = getRepositoryKey(repositoryName);
if (!repositoryListCache.containsKey(repositoryKey)) {
RepositoryModel model = loadRepositoryModel(repositoryName);
if (model == null) {
return null;
}
addToCachedRepositoryList(model);
return DeepCopier.copy(model);
}
// cached model
RepositoryModel model = repositoryListCache.get(repositoryKey);
if (isCollectingGarbage(model.name)) {
// Gitblit is busy collecting garbage, use our cached model
RepositoryModel rm = DeepCopier.copy(model);
rm.isCollectingGarbage = true;
return rm;
}
// check for updates
Repository r = getRepository(model.name);
if (r == null) {
// repository is missing
removeFromCachedRepositoryList(repositoryName);
logger.error(MessageFormat.format("Repository \"{0}\" is missing! Removing from cache.", repositoryName));
return null;
}
FileBasedConfig config = (FileBasedConfig) getRepositoryConfig(r);
if (config.isOutdated()) {
// reload model
logger.debug(MessageFormat.format("Config for \"{0}\" has changed. Reloading model and updating cache.", repositoryName));
model = loadRepositoryModel(model.name);
removeFromCachedRepositoryList(model.name);
addToCachedRepositoryList(model);
} else {
// update a few repository parameters
if (!model.hasCommits) {
// update hasCommits, assume a repository only gains commits :)
model.hasCommits = JGitUtils.hasCommits(r);
}
updateLastChangeFields(r, model);
}
r.close();
// return a copy of the cached model
return DeepCopier.copy(model);
}
use of org.eclipse.jgit.storage.file.FileBasedConfig in project gerrit by GerritCodeReview.
the class ProjectCacheIT method allProjectsProjectsConfig_ChangeInFileInvalidatesPersistedCache.
@Test
public void allProjectsProjectsConfig_ChangeInFileInvalidatesPersistedCache() throws Exception {
assertThat(projectCache.getAllProjects().getConfig().getCheckReceivedObjects()).isTrue();
// Change etc/All-Projects-project.config
FileBasedConfig fileBasedConfig = new FileBasedConfig(sitePaths.etc_dir.resolve(allProjects.get()).resolve(ProjectConfig.PROJECT_CONFIG).toFile(), FS.DETECTED);
fileBasedConfig.setString("receive", null, "checkReceivedObjects", "false");
fileBasedConfig.save();
// Invalidate only the in-memory cache
inMemoryProjectCache.invalidate(allProjects);
assertThat(projectCache.getAllProjects().getConfig().getCheckReceivedObjects()).isFalse();
}
use of org.eclipse.jgit.storage.file.FileBasedConfig in project gerrit by GerritCodeReview.
the class AllProjectsConfigTest method setUp.
@Before
public void setUp() throws Exception {
sitePaths = new SitePaths(temporaryFolder.newFolder().toPath());
Files.createDirectories(sitePaths.etc_dir);
Path gitPath = sitePaths.resolve("git");
StoredConfig gerritConfig = new FileBasedConfig(sitePaths.resolve("etc").resolve("gerrit.config").toFile(), FS.DETECTED);
gerritConfig.load();
gerritConfig.setString("gerrit", null, "basePath", gitPath.toAbsolutePath().toString());
gerritConfig.setString("gerrit", null, "allProjects", ALL_PROJECTS);
gerritConfig.save();
Files.createDirectories(sitePaths.resolve("git"));
allProjectsRepoFile = gitPath.resolve("All-The-Projects.git").toFile();
try (Repository repo = new FileRepository(allProjectsRepoFile)) {
repo.create(true);
}
InMemorySecureStore secureStore = new InMemorySecureStore();
InitFlags flags = new InitFlags(sitePaths, secureStore, ImmutableList.of(), false);
Section.Factory sections = (name, subsection) -> new Section(flags, sitePaths, secureStore, ui, name, subsection);
AllProjectsConfigProvider configProvider = new FileBasedAllProjectsConfigProvider(sitePaths);
allProjectsConfig = new AllProjectsConfig(new AllProjectsNameOnInitProvider(sections), configProvider, sitePaths, flags);
}
use of org.eclipse.jgit.storage.file.FileBasedConfig in project gerrit by GerritCodeReview.
the class JGitConfigTest method openSystemConfigReturnsDifferentInstances.
@Test
public void openSystemConfigReturnsDifferentInstances() throws Exception {
FileBasedConfig system1 = SystemReader.getInstance().openSystemConfig(null, FS.DETECTED);
system1.load();
assertThat(system1.getString("core", null, "trustFolderStat")).isEqualTo("false");
FileBasedConfig system2 = SystemReader.getInstance().openSystemConfig(null, FS.DETECTED);
system2.load();
assertThat(system2.getString("core", null, "trustFolderStat")).isEqualTo("false");
system1.setString("core", null, "trustFolderStat", "true");
assertThat(system1.getString("core", null, "trustFolderStat")).isEqualTo("true");
assertThat(system2.getString("core", null, "trustFolderStat")).isEqualTo("false");
}
use of org.eclipse.jgit.storage.file.FileBasedConfig in project gerrit by GerritCodeReview.
the class JGitConfigTest method openSystemConfigRespectsParent.
@Test
public void openSystemConfigRespectsParent() throws Exception {
Config parent = new Config();
parent.setString("foo", null, "bar", "value");
FileBasedConfig system = SystemReader.getInstance().openSystemConfig(parent, FS.DETECTED);
system.load();
assertThat(system.getString("core", null, "trustFolderStat")).isEqualTo("false");
assertThat(system.getString("foo", null, "bar")).isEqualTo("value");
}
Aggregations