move some of the test code to a helper function
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
diff --git a/regress/repository/repository_test.c b/regress/repository/repository_test.c
index fe5aa01..b2c6877 100644
--- a/regress/repository/repository_test.c
+++ b/regress/repository/repository_test.c
@@ -30,6 +30,34 @@
#define GOT_REPO_PATH "../../../"
+
+static const struct got_error *
+print_commit_object(struct got_object *obj, struct got_repository *repo)
+{
+ struct got_commit_object *commit;
+ struct got_parent_id *pid;
+ char buf[SHA1_DIGEST_STRING_LENGTH];
+ const struct got_error *err;
+
+ err = got_object_commit_open(&commit, repo, obj);
+ if (err != NULL)
+ return err;
+
+ printf("tree: %s\n",
+ got_object_id_str(&commit->tree_id, buf, sizeof(buf)));
+ printf("parent%s: ", (commit->nparents == 1) ? "" : "s");
+ SIMPLEQ_FOREACH(pid, &commit->parent_ids, entry) {
+ printf("%s\n",
+ got_object_id_str(&pid->id, buf, sizeof(buf)));
+ }
+ printf("author: %s\n", commit->author);
+ printf("committer: %s\n", commit->committer);
+ printf("log: %s\n", commit->logmsg);
+ got_object_commit_close(commit);
+
+ return NULL;
+}
+
static int
repo_read_object_header(const char *repo_path)
{
@@ -55,25 +83,8 @@ repo_read_object_header(const char *repo_path)
if (err != NULL || obj == NULL)
return 0;
printf("object type=%d size=%lu\n", obj->type, obj->size);
- if (obj->type == GOT_OBJ_TYPE_COMMIT) {
- struct got_commit_object *commit;
- struct got_parent_id *pid;
-
- err = got_object_commit_open(&commit, repo, obj);
- if (err != NULL || commit == NULL)
- return 0;
- printf("tree: %s\n",
- got_object_id_str(&commit->tree_id, buf, sizeof(buf)));
- printf("parent%s: ", (commit->nparents == 1) ? "" : "s");
- SIMPLEQ_FOREACH(pid, &commit->parent_ids, entry) {
- printf("%s\n",
- got_object_id_str(&pid->id, buf, sizeof(buf)));
- }
- printf("author: %s\n", commit->author);
- printf("committer: %s\n", commit->committer);
- printf("log: %s\n", commit->logmsg);
- got_object_commit_close(commit);
- }
+ if (obj->type == GOT_OBJ_TYPE_COMMIT)
+ print_commit_object(obj, repo);
got_object_close(obj);
free(id);
got_ref_close(head_ref);