public Repository open(final HttpServletRequest req,
final String repositoryName) throws RepositoryNotFoundException,
ServiceNotEnabledException {
if (isUnreasonableName(repositoryName))
throw new RepositoryNotFoundException(repositoryName);
final Repository db;
try {
final File gitdir = new File(basePath, repositoryName);
db = RepositoryCache.open(FileKey.lenient(gitdir, FS.DETECTED), true);
} catch (IOException e) {
throw new RepositoryNotFoundException(repositoryName, e);
}
try {
if (isExportOk(req, repositoryName, db)) {
// We have to leak the open count to the caller, they
// are responsible for closing the repository if we
// complete successfully.
return db;
} else
throw new ServiceNotEnabledException();
} catch (RuntimeException e) {
db.close();
throw new RepositoryNotFoundException(repositoryName, e);
} catch (IOException e) {
db.close();
throw new RepositoryNotFoundException(repositoryName, e);
} catch (ServiceNotEnabledException e) {
db.close();
throw e;
}