Commit 7186d7ba by Edward Thomson

revparse: don't assume SHA1

parent e56f3507
......@@ -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,7 +117,7 @@ static int revparse_lookup_object(
if (error != GIT_ENOTFOUND)
return error;
if ((strlen(spec) < GIT_OID_SHA1_HEXSIZE) &&
if ((strlen(spec) < git_oid_hexsize(repo->oid_type)) &&
((error = maybe_abbrev(object_out, repo, spec)) != GIT_ENOTFOUND))
return error;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment