implement got_object_open_as_blob()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
diff --git a/include/got_object.h b/include/got_object.h
index 60c0249..9268ff8 100644
--- a/include/got_object.h
+++ b/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 *,
diff --git a/lib/object.c b/lib/object.c
index 530f08f..3bf9f60 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -1320,6 +1320,28 @@ done:
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;
+}
+
void
got_object_blob_close(struct got_blob_object *blob)
{