commit a19581a24bec8161b09eab50d721edc1c8f42be9 from: Stefan Sperling date: Thu Jun 21 20:04:27 2018 UTC implement got_object_open_as_blob() commit - 67606321850286a3a613541da555fd6642abaccd commit + a19581a24bec8161b09eab50d721edc1c8f42be9 blob - 60c024909bd661ac5ba3c006a17501e2ad3e1ed4 blob + 9268ff826f30da37420b9969e0b0283db36d0455 --- include/got_object.h +++ include/got_object.h @@ -193,6 +193,9 @@ got_object_open_as_commit(struct got_commit_object **, const struct got_error * got_object_open_as_tree(struct got_tree_object **, struct got_repository *, struct got_object_id *); +const struct got_error * +got_object_open_as_blob(struct got_blob_object **, + struct got_repository *, struct got_object_id *, size_t); const struct got_error * got_object_open_by_path(struct got_object **, struct got_repository *, blob - 530f08f012ebee6cb4dcacf2a20e838ee7f87618 blob + 3bf9f6042a612ec493d55e91c4bb3fe3b468552d --- lib/object.c +++ lib/object.c @@ -1316,7 +1316,29 @@ done: free((*blob)->read_buf); free(*blob); *blob = NULL; + } + return err; +} + +const struct got_error * +got_object_open_as_blob(struct got_blob_object **blob, + struct got_repository *repo, struct got_object_id *id, + size_t blocksize) +{ + const struct got_error *err; + struct got_object *obj; + + err = got_object_open(&obj, repo, id); + if (err) + return err; + if (got_object_get_type(obj) != GOT_OBJ_TYPE_BLOB) { + err = got_error(GOT_ERR_OBJ_TYPE); + goto done; } + + err = got_object_blob_open(blob, repo, obj, blocksize); +done: + got_object_close(obj); return err; }