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

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

Download raw body.

Thread
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.

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

diff /Users/mark/Library/Mobile Documents/com~apple~CloudDocs/src/got-current
commit - 882bd7ed85046aaa89aa9f71782acf70dfd5b17e
path + /Users/mark/Library/Mobile Documents/com~apple~CloudDocs/src/got-current
blob - e7f0700696947892c8ddb172fd705c31304b984e
file + tog/tog.c
--- tog/tog.c
+++ tog/tog.c
@@ -2285,12 +2285,16 @@ draw_commits(struct tog_view *view)
 	ncommits = 0;
 	view->maxx = 0;
 	while (entry) {
+		struct got_commit_object *commit = 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(commit));
+		else
+			author = strdup(got_object_commit_get_author(commit));
 		if (author == NULL) {
 			err = got_error_from_errno("strdup");
 			goto done;

> diff /home/op/w/got
> commit - d2587c5f95c6edb51ccc8d4abfac838b58f3a463
> path + /home/op/w/got
> blob - 4ec26b8962b911a5c478faf7aebc3d0686931d6e
> file + tog/tog.1
> --- 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
> file + tog/tog.c
> --- 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;
> @@ -3258,6 +3262,11 @@ 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;
> +		if (view->reset)
> +			err = view->reset(view);

here            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> +		break;
>  	case 'G':
>  	case KEY_END: {
>  		/* We don't know yet how many commits, so we're forced to
> 

-- 
Mark Jamsek <fnc.bsdbox.org>
GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68