Commit 75b7a700d9d14ef8eb902961255212acbedef164

Stefan Sperling 2018-07-10T13:32:19

allow quitting tog blame view while blame is in progress

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);