From: Mark Jamsek Subject: tog wt diff: don't fatal error if worktree is busy To: gameoftrees@openbsd.org Date: Sun, 08 Dec 2024 12:10:35 +1100 Rather than fatal error, report the "worktree already locked" message to the diff view if a worktree diff has been selected or refreshed when the work tree is busy. To reproduce and see the improved behaviour, perform the following in a dirty work tree invoking tog with and without the below diff applied: $ tog ^z $ got commit ^z $ fg %1 # press `return' on the work tree entry commit 70df4b3021cd5b9da8fc154219cb5ca17a7c8905 (main) from: Mark Jamsek date: Sun Dec 8 00:49:02 2024 UTC tog worktree diff: don't fatal error if worktree is busy Report the "worktree already locked" message to the view like we do in corresponding command line situations. M tog/tog.c | 19+ 5- 1 file changed, 19 insertions(+), 5 deletions(-) commit - cb83367306af4e956036c78dfcbb556adfa8adc9 commit + 70df4b3021cd5b9da8fc154219cb5ca17a7c8905 blob - 16256a8af275d99da1e2a192df7aa03132f49e5b blob + 2ce26fea02651c5c22189e43095204197b89c0d7 --- tog/tog.c +++ tog/tog.c @@ -6363,9 +6363,27 @@ tog_diff_worktree(struct tog_diff_view_state *s, FILE if (cwd == NULL) return got_error_from_errno("getcwd"); + err = add_line_metadata(lines, nlines, 0, GOT_DIFF_LINE_NONE); + if (err != NULL) + goto done; + err = got_worktree_open(&worktree, cwd, NULL); - if (err != NULL) + if (err != NULL) { + if (err->code == GOT_ERR_WORKTREE_BUSY) { + int n; + + if ((n = fprintf(f, "%s\n", err->msg)) < 0) { + err = got_ferror(f, GOT_ERR_IO); + goto done; + } + err = add_line_metadata(lines, nlines, n, + GOT_DIFF_LINE_META); + if (err != NULL) + goto done; + err = got_error(GOT_ERR_DIFF_NOCHANGES); + } goto done; + } err = got_object_id_str(&id_str, got_worktree_get_base_commit_id(worktree)); @@ -6393,10 +6411,6 @@ tog_diff_worktree(struct tog_diff_view_state *s, FILE arg.f2 = s->f2; arg.outfile = f; - err = add_line_metadata(lines, nlines, 0, GOT_DIFF_LINE_NONE); - if (err != NULL) - goto done; - if (s->paths == NULL) { err = got_pathlist_insert(NULL, &pathlist, "", NULL); if (err != NULL) -- Mark Jamsek GPG: F2FF 13DE 6A06 C471 CA80 E6E2 2930 DC66 86EE CF68