Download raw body.
introduce got_object_id_serialize
add a function that's analogous to got_object_id_str but writes to the
given buffer. at the moment is just a wrapper around got_sha1_digest_to_str
but will gain some more logic in the future.
i've avoided all the calls to got_sha1_digest_to_str that were in the
pack code, the network code and gotd. There are a few calls to build
a GOT_ERR_OBJ_CSUM error that i'm going to deal with in a follow-up
diff. The two calls in the patch code were kept too, will revisit
them when we'll start to have some real initial sha256 support.
diffstat -s /home/op/w/got
M include/got_object.h | 7+ 0-
M lib/error.c | 1+ 1-
M lib/object.c | 1+ 1-
M lib/object_parse.c | 7+ 1-
4 files changed, 16 insertions(+), 3 deletions(-)
diff -s /home/op/w/got
commit - 09cbb981df84d9c12f0fa371cb6b85d3f1b615c0
path + /home/op/w/got (staged changes)
blob - 9d11c8f4f518f5f911295671d3aafcb494a7ec10
blob + 3dea2df3656c85f425a01b9e66471da1fc10fdaf
--- include/got_object.h
+++ include/got_object.h
@@ -82,6 +82,13 @@ const struct got_error *got_object_id_str(char **, str
const struct got_error *got_object_id_str(char **, struct got_object_id *);
/*
+ * Write the string representation of an object ID in the given buffer.
+ * The output depends on the hash function used by the repository format
+ * (currently SHA1).
+ */
+char *got_object_id_serialize(struct got_object_id *, char *, size_t);
+
+/*
* Compare two object IDs. Return value behaves like memcmp(3).
*/
int got_object_id_cmp(const struct got_object_id *,
blob - 3c84ba7eeb9c88175a7652495f934263b6fd2328
blob + a63dabdbb6ea9f180683f4d148b335902323042d
--- lib/error.c
+++ lib/error.c
@@ -371,7 +371,7 @@ got_error_no_obj(struct got_object_id *id)
char id_str[SHA1_DIGEST_STRING_LENGTH];
int ret;
- if (!got_sha1_digest_to_str(id->sha1, id_str, sizeof(id_str)))
+ if (!got_object_id_serialize(id, id_str, sizeof(id_str)))
return got_error(GOT_ERR_NO_OBJ);
ret = snprintf(msg, sizeof(msg), "object %s not found", id_str);
blob - 52e7c967c9cc041ec94d6baa8ab706eb7434b845
blob + 2edd56b4111b31d75289b1602308e6b1dcd7922d
--- lib/object.c
+++ lib/object.c
@@ -374,7 +374,7 @@ got_object_blob_id_str(struct got_blob_object *blob, c
char *
got_object_blob_id_str(struct got_blob_object *blob, char *buf, size_t size)
{
- return got_sha1_digest_to_str(blob->id.sha1, buf, size);
+ return got_object_id_serialize(&blob->id, buf, size);
}
size_t
blob - c9a711f7c6066bf89187c9058634f85a5a61c2e1
blob + 27d66bb8f8798c76dc4f448a3c48249d762a5f98
--- lib/object_parse.c
+++ lib/object_parse.c
@@ -94,7 +94,7 @@ got_object_id_str(char **outbuf, struct got_object_id
if (*outbuf == NULL)
return got_error_from_errno("malloc");
- if (got_sha1_digest_to_str(id->sha1, *outbuf, len) == NULL) {
+ if (got_object_id_serialize(id, *outbuf, len) == NULL) {
free(*outbuf);
*outbuf = NULL;
return got_error(GOT_ERR_BAD_OBJ_ID_STR);
@@ -103,6 +103,12 @@ void
return NULL;
}
+char *
+got_object_id_serialize(struct got_object_id *id, char *buf, size_t len)
+{
+ return got_sha1_digest_to_str(id->sha1, buf, len);
+}
+
void
got_object_close(struct got_object *obj)
{
introduce got_object_id_serialize