Skip to content

Commit

Permalink
Make MRepo static keys a member
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Mar 24, 2023
1 parent 52f415f commit 3692fbf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
4 changes: 4 additions & 0 deletions libmamba/include/mamba/core/repo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ namespace mamba

MRepo(MPool& pool, const std::string& name, const std::vector<PackageInfo>& uris);

void init(MPool& pool);

bool read_file(const fs::u8path& filename);

fs::u8path m_json_file, m_solv_file;
Expand All @@ -146,6 +148,8 @@ namespace mamba
RepoMetadata m_metadata;

Repo* m_repo;
::Id m_real_repo_key = 0;
::Id m_noarch_repo_key = 0;
const Channel* p_channel = nullptr;
};

Expand Down
32 changes: 18 additions & 14 deletions libmamba/src/core/repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,26 @@ namespace mamba
const RepoMetadata& metadata,
const Channel& channel
)
: m_metadata(metadata)
: m_url(rsplit(metadata.url, "/", 1)[0])
, m_metadata(metadata)
{
m_url = rsplit(metadata.url, "/", 1)[0];
m_repo = repo_create(pool, m_url.c_str());
m_repo->appdata = this;
read_file(index);
p_channel = &channel;
init(pool);
}

MRepo::MRepo(MPool& pool, const std::string& name, const std::string& index, const std::string& url)
: m_url(url)
, m_repo(repo_create(pool, name.c_str()))
{
m_repo = repo_create(pool, name.c_str());
m_repo->appdata = this;
read_file(index);
init(pool);
}

MRepo::MRepo(MPool& pool, const std::string& name, const std::vector<PackageInfo>& package_infos)
: m_repo(repo_create(pool, name.c_str()))
{
m_repo = repo_create(pool, name.c_str());
m_repo->appdata = this;
int flags = 0;
Repodata* data;
data = repo_add_repodata(m_repo, flags);
Expand All @@ -73,12 +72,12 @@ namespace mamba
add_package_info(data, info);
}
repodata_internalize(data);
init(pool);
}

MRepo::MRepo(MPool& pool, const PrefixData& prefix_data)
: m_repo(repo_create(pool, "installed"))
{
m_repo = repo_create(pool, "installed");
m_repo->appdata = this;
int flags = 0;
Repodata* data;
data = repo_add_repodata(m_repo, flags);
Expand All @@ -95,6 +94,14 @@ namespace mamba

repodata_internalize(data);
set_installed();
init(pool);
}

void MRepo::init(MPool& pool)
{
m_repo->appdata = this;
m_real_repo_key = pool_str2id(pool, "solvable:real_repo_url", 1);
m_noarch_repo_key = pool_str2id(pool, "solvable:noarch_type", 1);
}

MRepo::~MRepo()
Expand Down Expand Up @@ -153,9 +160,6 @@ namespace mamba
LOG_INFO << "Adding package record to repo " << info.name;
Pool* pool = m_repo->pool;

Id real_repo_key = pool_str2id(pool, "solvable:real_repo_url", 1);
Id noarch_repo_key = pool_str2id(pool, "solvable:noarch_type", 1);

Id handle = repo_add_solvable(m_repo);
Solvable* s = pool_id2solvable(pool, handle);
solvable_set_str(s, SOLVABLE_BUILDVERSION, std::to_string(info.build_number).c_str());
Expand All @@ -166,11 +170,11 @@ namespace mamba
// No ``solvable_xxx`` equivalent
repodata_set_checksum(data, handle, SOLVABLE_PKGID, REPOKEY_TYPE_MD5, info.md5.c_str());

solvable_set_str(s, real_repo_key, info.url.c_str());
solvable_set_str(s, m_real_repo_key, info.url.c_str());

if (!info.noarch.empty())
{
solvable_set_str(s, noarch_repo_key, info.noarch.c_str());
solvable_set_str(s, m_noarch_repo_key, info.noarch.c_str());
}

// No ``solvable_xxx`` equivalent
Expand Down

0 comments on commit 3692fbf

Please sign in to comment.