git repos / sago_web_git

src/repo_scanner.h

browsing at commit = 4fe276c400f51581a3858e55f7b9a48a1f90f419

raw · blame · history

#pragma once

#include <map>
#include <string>
#include <vector>

// Discovers git repositories that are direct children of a root directory and
// keeps an immutable name -> absolute path mapping. The name (directory name)
// is the public identifier used in URLs.
class RepoScanner {
public:
    explicit RepoScanner(std::string root);

    // Repository names sorted alphabetically.
    std::vector<std::string> names() const;

    // Absolute path for a repository, or "" if the name is unknown.
    std::string path_for(const std::string &name) const;

    const std::string &root() const { return root_; }

private:
    std::string root_;
    std::map<std::string, std::string> repos_; // name -> path
};