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"))
46 return RPMConfig(*config);
53 const std::string &branch)
noexcept {
54 if (
const auto config = repo.catFile(
"origin/" + branch,
"rpm/config.sh"))
55 return RPMConfig(*config);
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;
The most important Git class.
Definition Repo.h:45
Tree is a representation of a git tree.
Definition Tree.h:27
Parses a string view into lines.
Definition String.h:25
std::optional< std::string_view > get() noexcept
Read one line.
Definition String.h:37
static constexpr T trim(const T &line) noexcept
Trim string (remove surrounding whitespace).
Definition String.h:158
RPMConfig(std::string_view rpmConfig) noexcept
Create a new RPMConfig from the rpmConfig.
Definition RPMConfig.h:25
bool contains(std::string_view key) const noexcept
Test whether key exists in the config.
Definition RPMConfig.h:61
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
static std::optional< RPMConfig > create(const SlGit::Tree &tree) noexcept
Create a new RPMConfig from the tree.
Definition RPMConfig.h:44
const auto & operator[](std::string_view key) const noexcept
Find key in the config and return its value.
Definition RPMConfig.h:73
std::optional< std::reference_wrapper< const std::string > > get(std::string_view key) const noexcept
Find key in the config and return its value if found (or nullopt).
Definition RPMConfig.h:65
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