remove got_parse_object_id(), add got_object_open_by_id_str() instead
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
diff --git a/include/got_object.h b/include/got_object.h
index 1e490d0..197e0e0 100644
--- a/include/got_object.h
+++ b/include/got_object.h
@@ -58,11 +58,12 @@ struct got_object;
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 *);
diff --git a/lib/object.c b/lib/object.c
index e9db3c6..0cabc1b 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -58,21 +58,6 @@ got_object_id_str(struct got_object_id *id, char *buf, size_t size)
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)
{
@@ -269,6 +254,18 @@ done:
}
+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)
{
diff --git a/regress/repository/repository_test.c b/regress/repository/repository_test.c
index 0dac4a0..510c96d 100644
--- a/regress/repository/repository_test.c
+++ b/regress/repository/repository_test.c
@@ -212,21 +212,15 @@ repo_read_tree(const char *repo_path)
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)
@@ -245,22 +239,16 @@ repo_read_blob(const char *repo_path)
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)
@@ -294,8 +282,6 @@ repo_diff_blob(const char *repo_path)
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;
@@ -305,26 +291,16 @@ repo_diff_blob(const char *repo_path)
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)
@@ -363,8 +339,6 @@ repo_diff_tree(const char *repo_path)
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;
@@ -374,26 +348,16 @@ repo_diff_tree(const char *repo_path)
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)