mirror of
https://github.com/NixOS/nix.git
synced 2025-11-15 15:02:42 +01:00
Make changes to support libgit2 experimental API
This experimental interface is likely to become stable with libgit2 2.0.
This commit is contained in:
parent
9846305fee
commit
6da56d7ed4
1 changed files with 32 additions and 6 deletions
|
|
@ -91,10 +91,21 @@ typedef std::unique_ptr<git_indexer, Deleter<git_indexer_free>> Indexer;
|
||||||
|
|
||||||
Hash toHash(const git_oid & oid)
|
Hash toHash(const git_oid & oid)
|
||||||
{
|
{
|
||||||
#ifdef GIT_EXPERIMENTAL_SHA256
|
HashAlgorithm algo;
|
||||||
assert(oid.type == GIT_OID_SHA1);
|
#pragma GCC diagnostic push
|
||||||
#endif
|
#pragma GCC diagnostic ignored "-Wswitch-enum"
|
||||||
Hash hash(HashAlgorithm::SHA1);
|
switch (oid.type) {
|
||||||
|
case GIT_OID_SHA1:
|
||||||
|
algo = HashAlgorithm::SHA1;
|
||||||
|
break;
|
||||||
|
case GIT_OID_SHA256:
|
||||||
|
algo = HashAlgorithm::SHA256;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
unreachable();
|
||||||
|
}
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
Hash hash(algo);
|
||||||
memcpy(hash.hash, oid.id, hash.hashSize);
|
memcpy(hash.hash, oid.id, hash.hashSize);
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
@ -111,7 +122,21 @@ static void initLibGit2()
|
||||||
git_oid hashToOID(const Hash & hash)
|
git_oid hashToOID(const Hash & hash)
|
||||||
{
|
{
|
||||||
git_oid oid;
|
git_oid oid;
|
||||||
if (git_oid_fromstr(&oid, hash.gitRev().c_str()))
|
git_oid_t t;
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wswitch-enum"
|
||||||
|
switch (hash.algo) {
|
||||||
|
case HashAlgorithm::SHA1:
|
||||||
|
t = GIT_OID_SHA1;
|
||||||
|
break;
|
||||||
|
case HashAlgorithm::SHA256:
|
||||||
|
t = GIT_OID_SHA256;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw Error("unsupported hash algorithm for Git: %s", printHashAlgo(hash.algo));
|
||||||
|
}
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
if (git_oid_fromstr(&oid, hash.gitRev().c_str(), t))
|
||||||
throw Error("cannot convert '%s' to a Git OID", hash.gitRev());
|
throw Error("cannot convert '%s' to a Git OID", hash.gitRev());
|
||||||
return oid;
|
return oid;
|
||||||
}
|
}
|
||||||
|
|
@ -304,7 +329,8 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||||
// (synchronously on the git_packbuilder_write_buf thread)
|
// (synchronously on the git_packbuilder_write_buf thread)
|
||||||
Indexer indexer;
|
Indexer indexer;
|
||||||
git_indexer_progress stats;
|
git_indexer_progress stats;
|
||||||
if (git_indexer_new(Setter(indexer), pack_dir_path.c_str(), 0, nullptr, nullptr))
|
git_indexer_options indexer_opts = GIT_INDEXER_OPTIONS_INIT;
|
||||||
|
if (git_indexer_new(Setter(indexer), pack_dir_path.c_str(), &indexer_opts))
|
||||||
throw Error("creating git packfile indexer: %s", git_error_last()->message);
|
throw Error("creating git packfile indexer: %s", git_error_last()->message);
|
||||||
|
|
||||||
// TODO: provide index callback for checkInterrupt() termination
|
// TODO: provide index callback for checkInterrupt() termination
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue