Skip to content

Commit 7186d7b

Browse files
committed
revparse: don't assume SHA1
1 parent e56f350 commit 7186d7b

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/libgit2/revparse.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,28 @@
1515

1616
#include "git2.h"
1717

18-
static int maybe_sha_or_abbrev(git_object **out, git_repository *repo, const char *spec, size_t speclen)
18+
static int maybe_sha_or_abbrev(
19+
git_object **out,
20+
git_repository *repo,
21+
const char *spec,
22+
size_t speclen)
1923
{
2024
git_oid oid;
2125

22-
if (git_oid__fromstrn(&oid, spec, speclen, GIT_OID_SHA1) < 0)
26+
if (git_oid__fromstrn(&oid, spec, speclen, repo->oid_type) < 0)
2327
return GIT_ENOTFOUND;
2428

2529
return git_object_lookup_prefix(out, repo, &oid, speclen, GIT_OBJECT_ANY);
2630
}
2731

28-
static int maybe_sha(git_object **out, git_repository *repo, const char *spec)
32+
static int maybe_sha(
33+
git_object **out,
34+
git_repository *repo,
35+
const char *spec)
2936
{
3037
size_t speclen = strlen(spec);
3138

32-
if (speclen != GIT_OID_SHA1_HEXSIZE)
39+
if (speclen != git_oid_hexsize(repo->oid_type))
3340
return GIT_ENOTFOUND;
3441

3542
return maybe_sha_or_abbrev(out, repo, spec, speclen);
@@ -110,8 +117,8 @@ static int revparse_lookup_object(
110117
if (error != GIT_ENOTFOUND)
111118
return error;
112119

113-
if ((strlen(spec) < GIT_OID_SHA1_HEXSIZE) &&
114-
((error = maybe_abbrev(object_out, repo, spec)) != GIT_ENOTFOUND))
120+
if ((strlen(spec) < git_oid_hexsize(repo->oid_type)) &&
121+
((error = maybe_abbrev(object_out, repo, spec)) != GIT_ENOTFOUND))
115122
return error;
116123

117124
if ((error = maybe_describe(object_out, repo, spec)) != GIT_ENOTFOUND)

0 commit comments

Comments
 (0)