summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2022-09-21 08:25:58 -0400
committerEdward Thomson <ethomson@edwardthomson.com>2023-02-12 22:02:00 +0000
commit7186d7baadfe3e5e129710e07bdd57b1c7c0e862 (patch)
treeaa33899320dc97ec9259fb82c57a02cf7ca0b14d
parente56f35076e0b669d6b226eb3b8808d84899e425b (diff)
downloadlibgit2-7186d7baadfe3e5e129710e07bdd57b1c7c0e862.tar.gz
revparse: don't assume SHA1
-rw-r--r--src/libgit2/revparse.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/libgit2/revparse.c b/src/libgit2/revparse.c
index 2ed282159..bd13727eb 100644
--- a/src/libgit2/revparse.c
+++ b/src/libgit2/revparse.c
@@ -15,21 +15,28 @@
#include "git2.h"
-static int maybe_sha_or_abbrev(git_object **out, git_repository *repo, const char *spec, size_t speclen)
+static int maybe_sha_or_abbrev(
+ git_object **out,
+ git_repository *repo,
+ const char *spec,
+ size_t speclen)
{
git_oid oid;
- if (git_oid__fromstrn(&oid, spec, speclen, GIT_OID_SHA1) < 0)
+ if (git_oid__fromstrn(&oid, spec, speclen, repo->oid_type) < 0)
return GIT_ENOTFOUND;
return git_object_lookup_prefix(out, repo, &oid, speclen, GIT_OBJECT_ANY);
}
-static int maybe_sha(git_object **out, git_repository *repo, const char *spec)
+static int maybe_sha(
+ git_object **out,
+ git_repository *repo,
+ const char *spec)
{
size_t speclen = strlen(spec);
- if (speclen != GIT_OID_SHA1_HEXSIZE)
+ if (speclen != git_oid_hexsize(repo->oid_type))
return GIT_ENOTFOUND;
return maybe_sha_or_abbrev(out, repo, spec, speclen);
@@ -110,8 +117,8 @@ static int revparse_lookup_object(
if (error != GIT_ENOTFOUND)
return error;
- if ((strlen(spec) < GIT_OID_SHA1_HEXSIZE) &&
- ((error = maybe_abbrev(object_out, repo, spec)) != GIT_ENOTFOUND))
+ if ((strlen(spec) < git_oid_hexsize(repo->oid_type)) &&
+ ((error = maybe_abbrev(object_out, repo, spec)) != GIT_ENOTFOUND))
return error;
if ((error = maybe_describe(object_out, repo, spec)) != GIT_ENOTFOUND)