nicer blame progress display in tog
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
diff --git a/tog/tog.c b/tog/tog.c
index 390bc18..edd2b6d 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1056,8 +1056,9 @@ struct tog_blame_line {
static const struct got_error *
draw_blame(WINDOW *window, FILE *f, const char *path,
- struct tog_blame_line *lines, int nlines, int *first_displayed_line,
- int *last_displayed_line, int *eof, int max_lines)
+ struct tog_blame_line *lines, int nlines, int blame_complete,
+ int *first_displayed_line, int *last_displayed_line,
+ int *eof, int max_lines)
{
const struct got_error *err;
int lineno = 0, nprinted = 0;
@@ -1070,8 +1071,9 @@ draw_blame(WINDOW *window, FILE *f, const char *path,
rewind(f);
werase(window);
- if (asprintf(&line, "annotation of %s (lines %d-%d of %d)", path,
- *first_displayed_line, *last_displayed_line, nlines) == -1)
+ if (asprintf(&line, "[%d-%d/%d] annotation of %s%s",
+ *first_displayed_line, *last_displayed_line, nlines,
+ path, blame_complete ? "" : " in progress...") == -1)
return got_error_from_errno();
err = format_line(&wline, &width, line, COLS);
free(line);
@@ -1137,7 +1139,7 @@ struct tog_blame_cb_args {
WINDOW *window;
int *first_displayed_line;
int *last_displayed_line;
- int *done;
+ int *quit;
};
static const struct got_error *
@@ -1155,7 +1157,7 @@ blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
if (pthread_mutex_lock(a->mutex) != 0)
return got_error_from_errno();
- if (*a->done) { /* user has quit the blame view */
+ if (*a->quit) { /* user has quit the blame view */
err = got_error(GOT_ERR_ITER_COMPLETED);
goto done;
}
@@ -1174,7 +1176,7 @@ blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
}
line->annotated = 1;
- err = draw_blame(a->window, a->f, a->path, a->lines, a->nlines,
+ err = draw_blame(a->window, a->f, a->path, a->lines, a->nlines, 0,
a->first_displayed_line, a->last_displayed_line, &eof, LINES);
done:
if (pthread_mutex_unlock(a->mutex) != 0)
@@ -1187,14 +1189,33 @@ struct tog_blame_thread_args {
struct got_object_id *commit_id;
struct got_repository *repo;
void *blame_cb_args;
+ int *complete;
};
static void *
blame_thread(void *arg)
{
- struct tog_blame_thread_args *a = arg;
- return (void *)got_blame_incremental(a->path, a->commit_id, a->repo,
- blame_cb, a->blame_cb_args);
+ const struct got_error *err;
+ struct tog_blame_thread_args *ta = arg;
+ struct tog_blame_cb_args *a = ta->blame_cb_args;
+ int eof;
+
+ err = got_blame_incremental(ta->path, ta->commit_id, ta->repo,
+ blame_cb, ta->blame_cb_args);
+ *ta->complete = 1;
+ if (err)
+ return (void *)err;
+
+ if (pthread_mutex_lock(a->mutex) != 0)
+ return (void *)got_error_from_errno();
+
+ err = draw_blame(a->window, a->f, a->path, a->lines, a->nlines, 1,
+ a->first_displayed_line, a->last_displayed_line, &eof, LINES);
+
+ if (pthread_mutex_unlock(a->mutex) != 0 && err == NULL)
+ err = got_error_from_errno();
+
+ return (void *)err;
}
static const struct got_error *
@@ -1203,7 +1224,7 @@ show_blame_view(const char *path, struct got_object_id *commit_id,
{
const struct got_error *err = NULL;
int ch, done = 0, first_displayed_line = 1, last_displayed_line = LINES;
- int eof, i;
+ int eof, i, blame_complete = 0;
struct got_object *obj = NULL;
struct got_blob_object *blob = NULL;
FILE *f = NULL;
@@ -1267,12 +1288,13 @@ show_blame_view(const char *path, struct got_object_id *commit_id,
blame_cb_args.window = tog_blame_view.window;
blame_cb_args.first_displayed_line = &first_displayed_line;
blame_cb_args.last_displayed_line = &last_displayed_line;
- blame_cb_args.done = &done;
+ blame_cb_args.quit = &done;
blame_thread_args.path = path;
blame_thread_args.commit_id = commit_id;
blame_thread_args.repo = repo;
blame_thread_args.blame_cb_args = &blame_cb_args;
+ blame_thread_args.complete = &blame_complete;
if (pthread_create(&thread, NULL, blame_thread,
&blame_thread_args) != 0) {
@@ -1286,7 +1308,8 @@ show_blame_view(const char *path, struct got_object_id *commit_id,
goto done;
}
err = draw_blame(tog_blame_view.window, f, path, lines, nlines,
- &first_displayed_line, &last_displayed_line, &eof, LINES);
+ blame_complete, &first_displayed_line, &last_displayed_line,
+ &eof, LINES);
if (pthread_mutex_unlock(&mutex) != 0) {
err = got_error_from_errno();
goto done;