"GOT", but the "O" is a cute, smiling sun Index | Thread

From:
Stefan Sperling <stsp@stsp.name>
Subject:
cope with deleted branches during tog log refresh
To:
gameoftrees@openbsd.org
Date:
Thu, 17 Nov 2022 11:33:31 +0100

Download raw body.

If tog is displaying the log for a branch and this branch is deleted
while tog is running then using Ctrl-l to refresh the log view will
cause tog to exit with an error.

With this patch, tog falls back to loading the default branch if its
current branch can no longer be found.

ok?

diff /home/stsp/src/got
commit - a45aafaf9bf7910fed713ff35d6d051d463bae98
path + /home/stsp/src/got
blob - 579801c1a62932c7ba58ad585ac0ba45e1ddbf06
file + tog/tog.c
--- tog/tog.c
+++ tog/tog.c
@@ -3784,8 +3784,19 @@ input_log_view(struct tog_view **new_view, struct tog_
 			err = got_repo_match_object_id(&start_id, NULL,
 			    s->head_ref_name ? s->head_ref_name : GOT_REF_HEAD,
 			    GOT_OBJ_TYPE_COMMIT, &tog_refs, s->repo);
-			if (err)
-				return err;
+			if (err) {
+				if (s->head_ref_name == NULL ||
+				    err->code != GOT_ERR_NOT_REF)
+					return err;
+				/* Try to cope with deleted references. */
+				free(s->head_ref_name);
+				s->head_ref_name = NULL;
+				err = got_repo_match_object_id(&start_id,
+				    NULL, GOT_REF_HEAD, GOT_OBJ_TYPE_COMMIT,
+				    &tog_refs, s->repo);
+				if (err)
+					return err;
+			}
 			free(s->start_id);
 			s->start_id = start_id;
 			s->thread_args.start_id = s->start_id;