src/main.cpp
browsing at commit = 4fe276c400f51581a3858e55f7b9a48a1f90f419
#include "application.h"
#include "git_repo.h"
#include "repo_scanner.h"
#include <cppcms/applications_pool.h>
#include <cppcms/service.h>
#include <cstdlib>
#include <iostream>
#include <string>
namespace {
// Repository root resolution order: GIT_ROOT env, config key "git.root",
// then $HOME/git.
std::string resolve_root(cppcms::service &srv) {
if (const char *env = std::getenv("GIT_ROOT"); env && *env)
return env;
const std::string configured = srv.settings().get<std::string>("git.root", "");
if (!configured.empty())
return configured;
if (const char *home = std::getenv("HOME"); home && *home)
return std::string(home) + "/git";
return "/srv/git";
}
} // namespace
int main(int argc, char **argv) {
try {
GitLibrary git_library;
cppcms::service srv(argc, argv);
const std::string root = resolve_root(srv);
RepoScanner scanner(root);
std::cout << "Serving " << scanner.names().size() << " repositories from "
<< root << std::endl;
srv.applications_pool().mount(cppcms::create_pool<GitApp>(&scanner));
srv.run();
} catch (const std::exception &e) {
std::cerr << "fatal: " << e.what() << std::endl;
return 1;
}
return 0;
}