allow quitting tog blame view while blame is in progress
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
diff --git a/lib/blame.c b/lib/blame.c
index 1a2d03c..c57eaab 100644
--- a/lib/blame.c
+++ b/lib/blame.c
@@ -345,6 +345,7 @@ got_blame_incremental(const char *path, struct got_object_id *commit_id,
err = blame_open(&blame, abspath, commit_id, repo, cb, arg);
free(abspath);
- blame_close(blame);
+ if (err == NULL)
+ blame_close(blame);
return err;
}
diff --git a/tog/tog.c b/tog/tog.c
index 4404ee4..5819996 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -1125,6 +1125,7 @@ struct tog_blame_cb_args {
WINDOW *window;
int *first_displayed_line;
int *last_displayed_line;
+ int *done;
};
static const struct got_error *
@@ -1135,6 +1136,9 @@ blame_cb(void *arg, int nlines, int lineno, struct got_object_id *id)
struct tog_blame_line *line;
int eof;
+ if (*a->done)
+ return got_error(GOT_ERR_ITER_COMPLETED);
+
if (nlines != a->nlines || lineno < 1 || lineno > a->nlines)
return got_error(GOT_ERR_RANGE);
@@ -1241,6 +1245,7 @@ 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_thread_args.path = path;
blame_thread_args.commit_id = commit_id;
@@ -1318,6 +1323,8 @@ done:
if (thread) {
if (pthread_join(thread, (void **)&err) != 0)
err = got_error_from_errno();
+ if (err && err->code == GOT_ERR_ITER_COMPLETED)
+ err = NULL;
}
if (blob)
got_object_blob_close(blob);