speed up search in 'tog log' while commits are still being loaded
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
diff --git a/tog/tog.c b/tog/tog.c
index 9093d14..32a7137 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -156,6 +156,7 @@ struct tog_log_view_state {
pthread_t thread;
struct tog_log_thread_args thread_args;
struct commit_queue_entry *matched_entry;
+ struct commit_queue_entry *search_entry;
};
struct tog_blame_cb_args {
@@ -1719,6 +1720,7 @@ search_start_log_view(struct tog_view *view)
struct tog_log_view_state *s = &view->state.log;
s->matched_entry = NULL;
+ s->search_entry = NULL;
return NULL;
}
@@ -1752,7 +1754,13 @@ search_next_log_view(struct tog_view *view)
return NULL;
}
- if (s->matched_entry) {
+ if (s->search_entry) {
+ if (view->searching == TOG_SEARCH_FORWARD)
+ entry = TAILQ_NEXT(s->search_entry, entry);
+ else
+ entry = TAILQ_PREV(s->search_entry,
+ commit_queue_head, entry);
+ } else if (s->matched_entry) {
if (view->searching == TOG_SEARCH_FORWARD)
entry = TAILQ_NEXT(s->selected_entry, entry);
else
@@ -1773,6 +1781,11 @@ search_next_log_view(struct tog_view *view)
view->search_next_done = 1;
return NULL;
}
+ /*
+ * Poke the log thread for more commits and return,
+ * allowing the main loop to make progress. Search
+ * will resume at s->search_entry once we come back.
+ */
s->thread_args.commits_needed = 1;
return trigger_log_thread(0,
&s->thread_args.commits_needed,
@@ -1791,6 +1804,7 @@ search_next_log_view(struct tog_view *view)
break;
}
free(id_str);
+ s->search_entry = entry;
if (view->searching == TOG_SEARCH_FORWARD)
entry = TAILQ_NEXT(entry, entry);
else
@@ -1813,6 +1827,8 @@ search_next_log_view(struct tog_view *view)
}
}
+ s->search_entry = NULL;
+
return NULL;
}