use of org.eclipse.jgit.lib.RepositoryCache.FileKey in project gerrit by GerritCodeReview.
the class LocalDiskRepositoryManager method createRepository.
@Override
public Repository createRepository(Project.NameKey name) throws RepositoryNotFoundException, RepositoryCaseMismatchException, IOException {
Path path = getBasePath(name);
if (isUnreasonableName(name)) {
throw new RepositoryNotFoundException("Invalid name: " + name);
}
File dir = FileKey.resolve(path.resolve(name.get()).toFile(), FS.DETECTED);
FileKey loc;
if (dir != null) {
// Already exists on disk, use the repository we found.
//
Project.NameKey onDiskName = getProjectName(path, dir.getCanonicalFile().toPath());
onCreateProject(onDiskName);
loc = FileKey.exact(dir, FS.DETECTED);
if (!names.contains(name)) {
throw new RepositoryCaseMismatchException(name);
}
} else {
// It doesn't exist under any of the standard permutations
// of the repository name, so prefer the standard bare name.
//
String n = name.get() + Constants.DOT_GIT_EXT;
loc = FileKey.exact(path.resolve(n).toFile(), FS.DETECTED);
}
try {
Repository db = RepositoryCache.open(loc, false);
db.create(true);
StoredConfig config = db.getConfig();
config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES, true);
config.save();
// JGit only writes to the reflog for refs/meta/config if the log file
// already exists.
//
File metaConfigLog = new File(db.getDirectory(), "logs/" + RefNames.REFS_CONFIG);
if (!metaConfigLog.getParentFile().mkdirs() || !metaConfigLog.createNewFile()) {
log.error(String.format("Failed to create ref log for %s in repository %s", RefNames.REFS_CONFIG, name));
}
onCreateProject(name);
return db;
} catch (IOException e1) {
final RepositoryNotFoundException e2;
e2 = new RepositoryNotFoundException("Cannot create repository " + name);
e2.initCause(e1);
throw e2;
}
}
Aggregations