commit - 59ece79d29ce555391953bc053f934b5b1ec15ff
commit + 6dfa2fd3f637ad1cc8606021277f04819645c9ba
blob - 1e490d07749d5bc65262db22d608334fc7dc81f3
blob + 197e0e04fe9bf5281b0fecfd2a4c1cd6d6a629fa
--- include/got_object.h
+++ include/got_object.h
struct got_repository;
char *got_object_id_str(struct got_object_id *, char *, size_t);
-const struct got_error *got_parse_object_id(struct got_object_id **, const char *);
int got_object_id_cmp(struct got_object_id *, struct got_object_id *);
int got_object_get_type(struct got_object *);
const struct got_error *got_object_open(struct got_object **,
struct got_repository *, struct got_object_id *);
+const struct got_error *got_object_open_by_id_str(struct got_object **,
+ struct got_repository *, const char *);
void got_object_close(struct got_object *);
const struct got_error *got_object_commit_open(struct got_commit_object **,
struct got_repository *, struct got_object *);
blob - e9db3c6742df9df3e1e59370a935408eefd16704
blob + 0cabc1b435a44aa60cc3705c43ae113eb0629e05
--- lib/object.c
+++ lib/object.c
return got_sha1_digest_to_str(id->sha1, buf, size);
}
-const struct got_error *
-got_parse_object_id(struct got_object_id **id, const char *buf)
-{
- *id = calloc(1, sizeof(**id));
- if (*id == NULL)
- return got_error(GOT_ERR_NO_MEM);
- if (!got_parse_sha1_digest((*id)->sha1, buf)) {
- free(*id);
- *id = NULL;
- return got_error(GOT_ERR_BAD_OBJ_ID_STR);
- }
- return NULL;
-}
-
-
int
got_object_id_cmp(struct got_object_id *id1, struct got_object_id *id2)
{
}
+const struct got_error *
+got_object_open_by_id_str(struct got_object **obj, struct got_repository *repo,
+ const char *id_str)
+{
+ struct got_object_id id;
+
+ if (!got_parse_sha1_digest(id.sha1, id_str))
+ return got_error(GOT_ERR_BAD_OBJ_ID_STR);
+
+ return got_object_open(obj, repo, &id);
+}
+
void
got_object_close(struct got_object *obj)
{
blob - 0dac4a0e1383ef0e7db9adee92a2dbed8d1e67ec
blob + 510c96d0e38d95012f013e9b3004a362af3335df
--- regress/repository/repository_test.c
+++ regress/repository/repository_test.c
const char *tree_sha1 = "6cc96e0e093fb30630ba7f199d0a008b24c6a690";
const struct got_error *err;
struct got_repository *repo;
- struct got_object_id *id;
struct got_object *obj;
char hex[SHA1_DIGEST_STRING_LENGTH];
int i;
size_t len;
- err = got_parse_object_id(&id, tree_sha1);
- if (err != NULL)
- return 0;
-
err = got_repo_open(&repo, repo_path);
if (err != NULL || repo == NULL)
return 0;
- err = got_object_open(&obj, repo, id);
- free(id);
+ err = got_object_open_by_id_str(&obj, repo, tree_sha1);
if (err != NULL || obj == NULL)
return 0;
if (got_object_get_type(obj) != GOT_OBJ_TYPE_TREE)
const char *blob_sha1 = "141f5fdc96126c1f4195558560a3c915e3d9b4c3";
const struct got_error *err;
struct got_repository *repo;
- struct got_object_id *id;
struct got_object *obj;
struct got_blob_object *blob;
char hex[SHA1_DIGEST_STRING_LENGTH];
int i;
size_t len;
-
- err = got_parse_object_id(&id, blob_sha1);
- if (err != NULL)
- return 0;
err = got_repo_open(&repo, repo_path);
if (err != NULL || repo == NULL)
return 0;
- err = got_object_open(&obj, repo, id);
- free(id);
+ err = got_object_open_by_id_str(&obj, repo, blob_sha1);
if (err != NULL || obj == NULL)
return 0;
if (got_object_get_type(obj) != GOT_OBJ_TYPE_BLOB)
const char *blob2_sha1 = "de7eb21b21c7823a753261aadf7cba35c9580fbf";
const struct got_error *err;
struct got_repository *repo;
- struct got_object_id *id1;
- struct got_object_id *id2;
struct got_object *obj1;
struct got_object *obj2;
struct got_blob_object *blob1;
int i;
size_t len;
FILE *outfile;
-
- err = got_parse_object_id(&id1, blob1_sha1);
- if (err != NULL)
- return 0;
-
- err = got_parse_object_id(&id2, blob2_sha1);
- if (err != NULL)
- return 0;
err = got_repo_open(&repo, repo_path);
if (err != NULL || repo == NULL)
return 0;
- err = got_object_open(&obj1, repo, id1);
- free(id1);
+ err = got_object_open_by_id_str(&obj1, repo, blob1_sha1);
if (err != NULL || obj1 == NULL)
return 0;
if (got_object_get_type(obj1) != GOT_OBJ_TYPE_BLOB)
return 0;
- err = got_object_open(&obj2, repo, id2);
- free(id2);
+ err = got_object_open_by_id_str(&obj2, repo, blob2_sha1);
if (err != NULL || obj2 == NULL)
return 0;
if (got_object_get_type(obj2) != GOT_OBJ_TYPE_BLOB)
const char *tree2_sha1 = "4aa8f2933839ff8a8fb3f905a4c232d22c6ff5f3";
const struct got_error *err;
struct got_repository *repo;
- struct got_object_id *id1;
- struct got_object_id *id2;
struct got_object *obj1;
struct got_object *obj2;
struct got_tree_object *tree1;
size_t len;
FILE *outfile;
- err = got_parse_object_id(&id1, tree1_sha1);
- if (err != NULL)
- return 0;
-
- err = got_parse_object_id(&id2, tree2_sha1);
- if (err != NULL)
- return 0;
-
err = got_repo_open(&repo, repo_path);
if (err != NULL || repo == NULL)
return 0;
- err = got_object_open(&obj1, repo, id1);
- free(id1);
+ err = got_object_open_by_id_str(&obj1, repo, tree1_sha1);
if (err != NULL || obj1 == NULL)
return 0;
if (got_object_get_type(obj1) != GOT_OBJ_TYPE_TREE)
return 0;
- err = got_object_open(&obj2, repo, id2);
- free(id2);
+ err = got_object_open_by_id_str(&obj2, repo, tree2_sha1);
if (err != NULL || obj2 == NULL)
return 0;
if (got_object_get_type(obj2) != GOT_OBJ_TYPE_TREE)