summaryrefslogtreecommitdiff
path: root/hex.c
diff options
context:
space:
mode:
Diffstat (limited to 'hex.c')
-rw-r--r--hex.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/hex.c b/hex.c
index da51e64..4f64d34 100644
--- a/hex.c
+++ b/hex.c
@@ -69,7 +69,10 @@ int get_sha1_hex(const char *hex, unsigned char *sha1)
int get_oid_hex_algop(const char *hex, struct object_id *oid,
const struct git_hash_algo *algop)
{
- return get_hash_hex_algop(hex, oid->hash, algop);
+ int ret = get_hash_hex_algop(hex, oid->hash, algop);
+ if (!ret)
+ oid_set_algo(oid, algop);
+ return ret;
}
/*
@@ -80,7 +83,7 @@ int get_oid_hex_any(const char *hex, struct object_id *oid)
{
int i;
for (i = GIT_HASH_NALGOS - 1; i > 0; i--) {
- if (!get_hash_hex_algop(hex, oid->hash, &hash_algos[i]))
+ if (!get_oid_hex_algop(hex, oid, &hash_algos[i]))
return i;
}
return GIT_HASH_UNKNOWN;
@@ -95,7 +98,7 @@ int parse_oid_hex_algop(const char *hex, struct object_id *oid,
const char **end,
const struct git_hash_algo *algop)
{
- int ret = get_hash_hex_algop(hex, oid->hash, algop);
+ int ret = get_oid_hex_algop(hex, oid, algop);
if (!ret)
*end = hex + algop->hexsz;
return ret;
@@ -121,6 +124,13 @@ char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash,
char *buf = buffer;
int i;
+ /*
+ * Our struct object_id has been memset to 0, so default to printing
+ * using the default hash.
+ */
+ if (algop == &hash_algos[0])
+ algop = the_hash_algo;
+
for (i = 0; i < algop->rawsz; i++) {
unsigned int val = *hash++;
*buf++ = hex[val >> 4];
@@ -133,7 +143,7 @@ char *hash_to_hex_algop_r(char *buffer, const unsigned char *hash,
char *oid_to_hex_r(char *buffer, const struct object_id *oid)
{
- return hash_to_hex_algop_r(buffer, oid->hash, the_hash_algo);
+ return hash_to_hex_algop_r(buffer, oid->hash, &hash_algos[oid->algo]);
}
char *hash_to_hex_algop(const unsigned char *hash, const struct git_hash_algo *algop)
@@ -151,5 +161,5 @@ char *hash_to_hex(const unsigned char *hash)
char *oid_to_hex(const struct object_id *oid)
{
- return hash_to_hex_algop(oid->hash, the_hash_algo);
+ return hash_to_hex_algop(oid->hash, &hash_algos[oid->algo]);
}