implement downwards scrolling for tog(1)
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
diff --git a/tog/tog.c b/tog/tog.c
index 3824d7d..15126bb 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -240,6 +240,59 @@ free_commits(struct commit_queue *commits)
pop_commit(commits);
}
+
+static const struct got_error *
+fetch_next_commit(struct commit_queue_entry **pentryp,
+ struct commit_queue *commits, struct got_repository *repo)
+{
+ const struct got_error *err;
+ struct got_object *obj = NULL;
+ struct got_commit_object *pcommit;
+ struct commit_queue_entry *entry, *pentry;
+ struct got_parent_id *pid;
+
+ if (pentryp)
+ *pentryp = NULL;
+ entry = TAILQ_LAST(commits, commit_queue);
+
+ /* Follow the first parent (TODO: handle merge commits). */
+ pid = SIMPLEQ_FIRST(&entry->commit->parent_ids);
+ if (pid == NULL)
+ return NULL;
+ err = got_object_open(&obj, repo, pid->id);
+ if (err)
+ return err;
+ if (got_object_get_type(obj) != GOT_OBJ_TYPE_COMMIT) {
+ err = got_error(GOT_ERR_OBJ_TYPE);
+ got_object_close(obj);
+ return err;
+ }
+
+ err = got_object_commit_open(&pcommit, repo, obj);
+ got_object_close(obj);
+ if (err)
+ return err;
+
+ pentry = calloc(1, sizeof(*pentry));
+ if (pentry == NULL) {
+ err = got_error_from_errno();
+ got_object_commit_close(pcommit);
+ return err;
+ }
+ pentry->id = got_object_id_dup(pid->id);
+ if (pentry->id == NULL) {
+ err = got_error_from_errno();
+ got_object_commit_close(pcommit);
+ return err;;
+ }
+ pentry->commit = pcommit;
+ TAILQ_INSERT_TAIL(commits, pentry, entry);
+ if (pentryp)
+ *pentryp = pentry;
+
+ return NULL;
+}
+
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)
@@ -258,42 +311,9 @@ fetch_commits(struct commit_queue *commits, struct got_object *root_obj,
return err;
while (entry->commit->nparents > 0 && ncommits < limit) {
- struct got_parent_id *pid;
- struct got_object *obj;
- struct got_commit_object *pcommit;
- struct commit_queue_entry *pentry;
-
- entry = TAILQ_LAST(commits, commit_queue);
-
- /* Follow the first parent (TODO: handle merge commits). */
- pid = SIMPLEQ_FIRST(&entry->commit->parent_ids);
- err = got_object_open(&obj, repo, pid->id);
+ err = fetch_next_commit(&entry, commits, repo);
if (err)
break;
- if (got_object_get_type(obj) != GOT_OBJ_TYPE_COMMIT) {
- err = got_error(GOT_ERR_OBJ_TYPE);
- break;
- }
-
- err = got_object_commit_open(&pcommit, repo, obj);
- got_object_close(obj);
- if (err)
- break;
-
- pentry = calloc(1, sizeof(*pentry));
- if (pentry == NULL) {
- err = got_error_from_errno();
- got_object_commit_close(pcommit);
- break;
- }
- pentry->id = got_object_id_dup(pid->id);
- if (pentry->id == NULL) {
- err = got_error_from_errno();
- got_object_commit_close(pcommit);
- break;
- }
- pentry->commit = pcommit;
- TAILQ_INSERT_TAIL(commits, pentry, entry);
ncommits++;
}
@@ -331,9 +351,14 @@ show_log_view(struct got_object_id *start_id, struct got_repository *repo)
{
const struct got_error *err = NULL;
struct got_object *obj = NULL;
+ struct got_object_id *id;
int ch, done = 0, selected = 0, refetch_commits = 1;
- struct got_object_id *id = start_id;
struct commit_queue commits;
+ struct commit_queue_entry *entry = NULL;
+
+ id = got_object_id_dup(start_id);
+ if (id == NULL)
+ return got_error_from_errno();
if (tog_log_view.window == NULL) {
tog_log_view.window = newwin(0, 0, 0, 0);
@@ -347,7 +372,7 @@ show_log_view(struct got_object_id *start_id, struct got_repository *repo)
return got_error_from_errno();
}
- err = got_object_open(&obj, repo, id);
+ err = got_object_open(&obj, repo, start_id);
if (err)
return err;
if (got_object_get_type(obj) != GOT_OBJ_TYPE_COMMIT) {
@@ -390,6 +415,36 @@ show_log_view(struct got_object_id *start_id, struct got_repository *repo)
case KEY_DOWN:
if (selected < LINES - 1)
selected++;
+ if (selected < LINES - 1)
+ break;
+
+ /* scroll down if there are more parents */
+ entry = TAILQ_LAST(&commits, commit_queue);
+ if (entry->commit->nparents == 0)
+ break;
+ got_object_close(obj);
+ pop_commit(&commits);
+ if (TAILQ_EMPTY(&commits)) {
+ refetch_commits = 1;
+ break;
+ }
+ entry = TAILQ_FIRST(&commits);
+ id = got_object_id_dup(entry->id);
+ if (id == NULL) {
+ err = got_error_from_errno();
+ goto done;
+ }
+ err = got_object_open(&obj, repo, id);
+ if (err)
+ return err;
+ if (got_object_get_type(obj) !=
+ GOT_OBJ_TYPE_COMMIT) {
+ err = got_error(GOT_ERR_OBJ_TYPE);
+ goto done;
+ }
+ err = fetch_next_commit(NULL, &commits, repo);
+ if (err)
+ goto done;
break;
case KEY_RESIZE:
refetch_commits = 1;