"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
Re: tog: add key to toggle between author and committer
To:
Mark Jamsek <mark@jamsek.com>
Cc:
gameoftrees@openbsd.org
Date:
Tue, 19 Jul 2022 09:47:52 +0200

Download raw body.

Thread
Mark Jamsek <mark@jamsek.com> wrote:
> On 22-07-18 10:44pm, Omar Polo wrote:
> > i've been reminded by the recent commit(s) to the TODO file; this adds a
> > C key for the log view that toggles the display of the author in the log
> > view.  ok?
> 
> Nice! This works well for me with one minor issue.
> 
> In got-portable repo:
>   $ tog  # 80x24
>   S  # switch to hsplit
>   8f  # page down (index should display 185/n)
>   return
>   tab  # focus top log split
>   C
> 
> Now the author column changes the five "op" and "stsp" names to "thomas"
> but there is no space between the 's' in "thomas" and the first letter
> of each log message field.
> 
> This happens because the max author_cols width needs to be computed
> again based on the committer name before redrawing the screen.  The
> below diff applied on top of yours fixes this issue.

thanks for testing and for the fix!

in my defence, i tested on a different repository where this issue
wasn't present :)

> Also, the log view doesn't have a reset method (yet?) so the
> view->reset() check could probably be dropped but ok either way.

yup.  at first i thougt it was a good idea to call it in case we add one
in the future, but on a second thought even if log had a reset method
this is probably not the right place to call it anyway, so I'm dropping
it.

diff refs/heads/main refs/heads/togauthor
commit - d2587c5f95c6edb51ccc8d4abfac838b58f3a463
commit + c3a2f478b19ac60211c983ef4245d82e49e461d8
blob - 4ec26b8962b911a5c478faf7aebc3d0686931d6e
blob + 5b14298225faae01d45c27c546da03a458a7b9fd
--- tog/tog.1
+++ tog/tog.1
@@ -214,6 +214,8 @@ view listing all references in the repository.
 This can then be used to open a new
 .Cm log
 view for arbitrary branches and tags.
+.It Cm C
+Switch between showing the author and the committer.
 .El
 .Pp
 The options for
blob - 97ac0690a9232815bb10bc4a237246e2ec53e069
blob + 4e852dea1423813614fd412bb96730341ea37f1d
--- tog/tog.c
+++ tog/tog.c
@@ -137,6 +137,7 @@ STAILQ_HEAD(tog_colors, tog_color);
 static struct got_reflist_head tog_refs = TAILQ_HEAD_INITIALIZER(tog_refs);
 static struct got_reflist_object_id_map *tog_refs_idmap;
 static enum got_diff_algorithm tog_diff_algo = GOT_DIFF_ALGORITHM_MYERS;
+static int tog_show_committer;
 
 static const struct got_error *
 tog_ref_cmp_by_name(void *arg, int *cmp, struct got_reference *re1,
@@ -1962,7 +1963,10 @@ draw_commit(struct tog_view *view, struct got_commit_o
 			goto done;
 	}
 
-	author = strdup(got_object_commit_get_author(commit));
+	if (tog_show_committer)
+		author = strdup(got_object_commit_get_committer(commit));
+	else
+		author = strdup(got_object_commit_get_author(commit));
 	if (author == NULL) {
 		err = got_error_from_errno("strdup");
 		goto done;
@@ -2272,12 +2276,16 @@ draw_commits(struct tog_view *view)
 	ncommits = 0;
 	view->maxx = 0;
 	while (entry) {
+		struct got_commit_object *c = entry->commit;
 		char *author, *eol, *msg, *msg0;
 		wchar_t *wauthor, *wmsg;
 		int width;
 		if (ncommits >= limit - 1)
 			break;
-		author = strdup(got_object_commit_get_author(entry->commit));
+		if (tog_show_committer)
+			author = strdup(got_object_commit_get_committer(c));
+		else
+			author = strdup(got_object_commit_get_author(c));
 		if (author == NULL) {
 			err = got_error_from_errno("strdup");
 			goto done;
@@ -2288,7 +2296,7 @@ draw_commits(struct tog_view *view)
 			author_cols = width;
 		free(wauthor);
 		free(author);
-		err = got_object_commit_get_logmsg(&msg0, entry->commit);
+		err = got_object_commit_get_logmsg(&msg0, c);
 		if (err)
 			goto done;
 		msg = msg0;
@@ -3258,6 +3266,9 @@ input_log_view(struct tog_view **new_view, struct tog_
 	case CTRL('n'):
 		err = log_move_cursor_down(view, 0);
 		break;
+	case 'C':
+		tog_show_committer = !tog_show_committer;
+		break;
 	case 'G':
 	case KEY_END: {
 		/* We don't know yet how many commits, so we're forced to