From: Omar Polo Subject: Re: tog: add key to toggle between author and committer To: Stefan Sperling Cc: Mark Jamsek , gameoftrees@openbsd.org Date: Tue, 19 Jul 2022 10:34:16 +0200 Stefan Sperling wrote: > On Tue, Jul 19, 2022 at 09:47:52AM +0200, Omar Polo wrote: > > 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. > > Documentation is a bit sparse, but please go ahead and I'll > try to fix it up later. > > > 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; > > Do you have plans to make this toggle visible to any other view types? > If not, could this not be stored in struct tog_log_view state instead of > adding a global? I am just trying to prevent us from ending up with lots > of global toggles because that makes it harder for readers of the code > to figure out which views are using a given toggle. it may be marginally useful to have this on the blame view too but otherwise no, there aren't reasons not to keep this in the log state struct. i've just remembered that in the blame view the 'C' key is already taken, should we use a different key for this toggle from the beginning? diff refs/heads/main refs/heads/togauthor commit - d2587c5f95c6edb51ccc8d4abfac838b58f3a463 commit + b331f2710ad741e694a891da5a08de40c9b4cc22 blob - 4ec26b8962b911a5c478faf7aebc3d0686931d6e blob + d3e7cb97c694e06240c84ee80d70b69cb5df951b --- 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 +Toggle between showing the author and the committer name. .El .Pp The options for blob - 97ac0690a9232815bb10bc4a237246e2ec53e069 blob + c1fa1d88d371899d046595df8c410651f5af1977 --- tog/tog.c +++ tog/tog.c @@ -376,6 +376,7 @@ struct tog_log_view_state { struct commit_queue_entry *matched_entry; struct commit_queue_entry *search_entry; struct tog_colors colors; + int use_committer; }; #define TOG_COLOR_DIFF_MINUS 1 @@ -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 (view->state.log.use_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 (view->state.log.use_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': + view->state.log.use_committer = !view->state.log.use_committer; + break; case 'G': case KEY_END: { /* We don't know yet how many commits, so we're forced to