Skip to content

Commit 6da56d7

Browse files
committed
Make changes to support libgit2 experimental API
This experimental interface is likely to become stable with libgit2 2.0.
1 parent 9846305 commit 6da56d7

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

src/libfetchers/git-utils.cc

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,21 @@ typedef std::unique_ptr<git_indexer, Deleter<git_indexer_free>> Indexer;
9191

9292
Hash toHash(const git_oid & oid)
9393
{
94-
#ifdef GIT_EXPERIMENTAL_SHA256
95-
assert(oid.type == GIT_OID_SHA1);
96-
#endif
97-
Hash hash(HashAlgorithm::SHA1);
94+
HashAlgorithm algo;
95+
#pragma GCC diagnostic push
96+
#pragma GCC diagnostic ignored "-Wswitch-enum"
97+
switch (oid.type) {
98+
case GIT_OID_SHA1:
99+
algo = HashAlgorithm::SHA1;
100+
break;
101+
case GIT_OID_SHA256:
102+
algo = HashAlgorithm::SHA256;
103+
break;
104+
default:
105+
unreachable();
106+
}
107+
#pragma GCC diagnostic pop
108+
Hash hash(algo);
98109
memcpy(hash.hash, oid.id, hash.hashSize);
99110
return hash;
100111
}
@@ -111,7 +122,21 @@ static void initLibGit2()
111122
git_oid hashToOID(const Hash & hash)
112123
{
113124
git_oid oid;
114-
if (git_oid_fromstr(&oid, hash.gitRev().c_str()))
125+
git_oid_t t;
126+
#pragma GCC diagnostic push
127+
#pragma GCC diagnostic ignored "-Wswitch-enum"
128+
switch (hash.algo) {
129+
case HashAlgorithm::SHA1:
130+
t = GIT_OID_SHA1;
131+
break;
132+
case HashAlgorithm::SHA256:
133+
t = GIT_OID_SHA256;
134+
break;
135+
default:
136+
throw Error("unsupported hash algorithm for Git: %s", printHashAlgo(hash.algo));
137+
}
138+
#pragma GCC diagnostic pop
139+
if (git_oid_fromstr(&oid, hash.gitRev().c_str(), t))
115140
throw Error("cannot convert '%s' to a Git OID", hash.gitRev());
116141
return oid;
117142
}
@@ -304,7 +329,8 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
304329
// (synchronously on the git_packbuilder_write_buf thread)
305330
Indexer indexer;
306331
git_indexer_progress stats;
307-
if (git_indexer_new(Setter(indexer), pack_dir_path.c_str(), 0, nullptr, nullptr))
332+
git_indexer_options indexer_opts = GIT_INDEXER_OPTIONS_INIT;
333+
if (git_indexer_new(Setter(indexer), pack_dir_path.c_str(), &indexer_opts))
308334
throw Error("creating git packfile indexer: %s", git_error_last()->message);
309335

310336
// TODO: provide index callback for checkInterrupt() termination

0 commit comments

Comments
 (0)