7 #include <unordered_map> 9 #include "../git/Repo.h" 10 #include "../git/Tree.h" 11 #include "../helpers/String.h" 27 while (
auto l = g.
get()) {
29 if (trimmed.empty() || trimmed.front() ==
'#')
31 auto eq = trimmed.find(
'=');
32 if (eq == trimmed.npos)
36 if (val.size() >= 2 && val.front() ==
'"' && val.back() ==
'"')
37 val = val.substr(1, val.size() - 2);
39 m_config[std::string(key)] = val;
45 if (
const auto config = tree.catFile(
"rpm/config.sh"))
53 const std::string &branch) noexcept {
54 if (
const auto config = repo.catFile(
"origin/" + branch,
"rpm/config.sh"))
61 bool contains(std::string_view key)
const noexcept {
return m_config.contains(key); }
64 std::optional<std::reference_wrapper<const std::string>>
65 get(std::string_view key)
const noexcept {
66 auto it = m_config.find(key);
67 if (it == m_config.end())
69 return std::cref(it->second);
73 const auto &
operator[](std::string_view key)
const noexcept {
74 return m_config.find(key)->second;
static constexpr T trim(const T &line) noexcept
Trim string (remove surrounding whitespace)
Definition: String.h:158
bool contains(std::string_view key) const noexcept
Test whether key exists in the config.
Definition: RPMConfig.h:61
Equality test for string and string_view to be used in containers.
Definition: String.h:250
Hash for string and string_view to be used in hashing containers.
Definition: String.h:223
static std::optional< RPMConfig > create(const SlGit::Repo &repo, const std::string &branch) noexcept
Create a new RPMConfig from the branch in the repo.
Definition: RPMConfig.h:52
The most important Git class.
Definition: Repo.h:45
const auto & operator[](std::string_view key) const noexcept
Find key in the config and return its value.
Definition: RPMConfig.h:73
Tree is a representation of a git tree.
Definition: Tree.h:27
Parses a string view into lines.
Definition: String.h:25
Definition: Branches.h:15
RPMConfig(std::string_view rpmConfig) noexcept
Create a new RPMConfig from the rpmConfig.
Definition: RPMConfig.h:25
static std::optional< RPMConfig > create(const SlGit::Tree &tree) noexcept
Create a new RPMConfig from the tree.
Definition: RPMConfig.h:44
Parse rpm/config.sh into a map of key -> value.
Definition: RPMConfig.h:18
std::optional< std::string_view > get() noexcept
Read one line.
Definition: String.h:37