show selected commit's hash in tog 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
diff --git a/tog/tog.c b/tog/tog.c
index 0c8100f..df9498a 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -445,14 +445,53 @@ draw_commits(struct commit_queue_entry **last, struct commit_queue_entry **selec
{
const struct got_error *err = NULL;
struct commit_queue_entry *entry;
- int ncommits = 0;
+ int ncommits;
+ char *id_str, *header;
+ size_t header_len;
+
+ entry = first;
+ *selected = NULL;
+ ncommits = 0;
+ while (entry) {
+ if (++ncommits - 1 == selected_idx) {
+ *selected = entry;
+ break;
+ }
+ entry = TAILQ_NEXT(entry, entry);
+ }
+ if (*selected == NULL)
+ return got_error(GOT_ERR_RANGE);
+
+ err = got_object_id_str(&id_str, (*selected)->id);
+ if (err)
+ return err;
+
+ if (asprintf(&header, "commit: %s", id_str) == -1) {
+ err = got_error_from_errno();
+ free(id_str);
+ return err;
+ }
werase(tog_log_view.window);
+ header_len = strlen(header);
+ if (header_len > COLS) {
+ id_str[COLS + 1] = '\0';
+ header_len = COLS;
+ }
+ wprintw(tog_log_view.window, header);
+ while (header_len < COLS) {
+ waddch(tog_log_view.window, ' ');
+ header_len++;
+ }
+ free(id_str);
+ free(header);
+
entry = first;
*last = first;
+ ncommits = 0;
while (entry) {
- if (ncommits == limit)
+ if (ncommits == limit - 1)
break;
if (ncommits == selected_idx) {
wstandout(tog_log_view.window);
@@ -646,6 +685,7 @@ show_log_view(struct got_object_id *start_id, struct got_repository *repo)
goto done;
}
+ selected_entry = first_displayed_entry;
while (!done) {
err = draw_commits(&last_displayed_entry, &selected_entry,
first_displayed_entry, selected, LINES);
@@ -685,7 +725,7 @@ show_log_view(struct got_object_id *start_id, struct got_repository *repo)
case 'j':
case KEY_DOWN:
nparents = num_parents(first_displayed_entry);
- if (selected < LINES - 1 &&
+ if (selected < LINES - 2 &&
selected < nparents - 1) {
selected++;
break;
@@ -706,13 +746,13 @@ show_log_view(struct got_object_id *start_id, struct got_repository *repo)
break;
/* can't scroll any further; move cursor down */
nparents = num_parents(first_displayed_entry);
- if (selected < LINES - 1 ||
+ if (selected < LINES - 2 ||
selected < nparents - 1)
- selected = MIN(LINES - 1, nparents - 1);
+ selected = MIN(LINES - 2, nparents - 1);
break;
case KEY_RESIZE:
- if (selected > LINES)
- selected = LINES - 1;
+ if (selected > LINES - 1)
+ selected = LINES - 2;
break;
case KEY_ENTER:
case '\r':