diff --git a/src/libfetchers/git-utils.cc b/src/libfetchers/git-utils.cc index 8eca1fe91..5f6bafdfe 100644 --- a/src/libfetchers/git-utils.cc +++ b/src/libfetchers/git-utils.cc @@ -91,10 +91,21 @@ typedef std::unique_ptr> Indexer; Hash toHash(const git_oid & oid) { -#ifdef GIT_EXPERIMENTAL_SHA256 - assert(oid.type == GIT_OID_SHA1); -#endif - Hash hash(HashAlgorithm::SHA1); + HashAlgorithm algo; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wswitch-enum" + 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); return hash; } @@ -111,7 +122,21 @@ static void initLibGit2() git_oid hashToOID(const Hash & hash) { 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()); return oid; } @@ -304,7 +329,8 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this // (synchronously on the git_packbuilder_write_buf thread) Indexer indexer; 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); // TODO: provide index callback for checkInterrupt() termination