add push/pop routines to manage commit queue in tog's log view
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
diff --git a/tog/tog.c b/tog/tog.c
index aee7598..3824d7d 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -196,29 +196,66 @@ struct commit_queue_entry {
TAILQ_HEAD(commit_queue, commit_queue_entry);
static const struct got_error *
-fetch_commits(struct commit_queue *commits, struct got_object *root_obj,
- struct got_object_id *root_id, struct got_repository *repo, int limit)
+push_commit(struct commit_queue_entry **entryp, struct commit_queue *commits,
+ struct got_commit_object *commit, struct got_object_id *id)
{
- const struct got_error *err;
- struct got_commit_object *root_commit;
+ const struct got_error *err = NULL;
struct commit_queue_entry *entry;
- int ncommits = 0;
- err = got_object_commit_open(&root_commit, repo, root_obj);
- if (err)
- return err;
+ *entryp = NULL;
entry = calloc(1, sizeof(*entry));
if (entry == NULL)
return got_error_from_errno();
- entry->id = got_object_id_dup(root_id);
+
+ entry->id = got_object_id_dup(id);
if (entry->id == NULL) {
err = got_error_from_errno();
free(entry);
return err;
}
- entry->commit = root_commit;
+
+ entry->commit = commit;
TAILQ_INSERT_HEAD(commits, entry, entry);
+ *entryp = entry;
+ return NULL;
+}
+
+static void
+pop_commit(struct commit_queue *commits)
+{
+ struct commit_queue_entry *entry;
+
+ entry = TAILQ_FIRST(commits);
+ TAILQ_REMOVE(commits, entry, entry);
+ got_object_commit_close(entry->commit);
+ free(entry->id);
+ free(entry);
+}
+
+static void
+free_commits(struct commit_queue *commits)
+{
+ while (!TAILQ_EMPTY(commits))
+ pop_commit(commits);
+}
+
+static const struct got_error *
+fetch_commits(struct commit_queue *commits, struct got_object *root_obj,
+ struct got_object_id *root_id, struct got_repository *repo, int limit)
+{
+ const struct got_error *err;
+ struct got_commit_object *root_commit;
+ struct commit_queue_entry *entry;
+ int ncommits = 0;
+
+ err = got_object_commit_open(&root_commit, repo, root_obj);
+ if (err)
+ return err;
+
+ err = push_commit(&entry, commits, root_commit, root_id);
+ if (err)
+ return err;
while (entry->commit->nparents > 0 && ncommits < limit) {
struct got_parent_id *pid;
@@ -263,20 +300,6 @@ fetch_commits(struct commit_queue *commits, struct got_object *root_obj,
return err;
}
-static void
-free_commits(struct commit_queue *commits)
-{
- struct commit_queue_entry *entry;
-
- while (!TAILQ_EMPTY(commits)) {
- entry = TAILQ_FIRST(commits);
- TAILQ_REMOVE(commits, entry, entry);
- got_object_commit_close(entry->commit);
- free(entry->id);
- free(entry);
- }
-}
-
static const struct got_error *
draw_commits(struct commit_queue *commits, int selected)
{