commit - eab8809f807c6efa50cb26be1c068d6ae680a28a
commit + 8496bf63db31d4c4e433fa8e5fddf5719038aa32
blob - 8c21271a99fe7416ffc1a6b97ce8ce11403a6f35
blob + 4f544396c2a7e9672cb82f64712cf9b3840d4881
--- tog/tog.c
+++ tog/tog.c
int *complete;
got_cancel_cb cancel_cb;
void *cancel_arg;
+ pthread_cond_t blame_complete;
};
struct tog_blame {
*ch = -1;
- if (tog_io.wait_for_ui)
- goto done;
-
if (getline(&line, &linesz, script) == -1) {
if (feof(script)) {
*done = 1;
goto done;
}
}
+
if (strncasecmp(line, "WAIT_FOR_UI", 11) == 0)
tog_io.wait_for_ui = 1;
else if (strncasecmp(line, "KEY_ENTER", 9) == 0)
"newterm: failed to initialise curses");
using_mock_io = 1;
+
done:
if (err)
tog_io_close();
if (view->gline > blame->nlines)
view->gline = blame->nlines;
+ if (tog_io.wait_for_ui) {
+ struct tog_blame_thread_args *bta = &s->blame.thread_args;
+ int rc;
+
+ rc = pthread_cond_wait(&bta->blame_complete, &tog_mutex);
+ if (rc)
+ return got_error_set_errno(rc, "pthread_cond_wait");
+ tog_io.wait_for_ui = 0;
+ }
+
if (asprintf(&line, "[%d/%d] %s%s", view->gline ? view->gline :
s->first_displayed_line - 1 + s->selected_line, blame->nlines,
s->blame_complete ? "" : "annotating... ", s->path) == -1) {
view_border(view);
- if (tog_io.wait_for_ui) {
- if (s->blame_complete)
- tog_io.wait_for_ui = 0;
- }
-
return NULL;
}
ta->repo = NULL;
*ta->complete = 1;
+ if (tog_io.wait_for_ui) {
+ errcode = pthread_cond_signal(&ta->blame_complete);
+ if (errcode && err == NULL)
+ err = got_error_set_errno(errcode,
+ "pthread_cond_signal");
+ }
+
errcode = pthread_mutex_unlock(&tog_mutex);
if (errcode && err == NULL)
err = got_error_set_errno(errcode, "pthread_mutex_unlock");
view->search_setup = search_setup_blame_view;
view->search_next = search_next_view_match;
+ if (using_mock_io) {
+ struct tog_blame_thread_args *bta = &s->blame.thread_args;
+ int rc;
+
+ rc = pthread_cond_init(&bta->blame_complete, NULL);
+ if (rc)
+ return got_error_set_errno(rc, "pthread_cond_init");
+ }
+
return run_blame(view);
}
got_object_qid_free(blamed_commit);
}
+ if (using_mock_io) {
+ struct tog_blame_thread_args *bta = &s->blame.thread_args;
+ int rc;
+
+ rc = pthread_cond_destroy(&bta->blame_complete);
+ if (rc && err == NULL)
+ err = got_error_set_errno(rc, "pthread_cond_destroy");
+ }
+
free(s->path);
free_colors(&s->colors);
return err;