commit 9472af9550ec85323ab6c004d71f8a671a6b014d from: Stefan Sperling via: Thomas Adam date: Mon May 15 19:06:57 2023 UTC show reference labels next to commit messages in tog log view requested by mpi@ ok op@ commit - 075759e6d59e0884b6d96dd7a98f9e72a7276132 commit + 9472af9550ec85323ab6c004d71f8a671a6b014d blob - f48397af6cde738244b53c3c26263b6fa6031107 blob + 67469c1eae523eaf0c2b46922e300c93c42a323f --- regress/tog/log.sh +++ regress/tog/log.sh @@ -33,7 +33,7 @@ EOF cat <$testroot/view.expected commit $head_id [1/1] master -$ymd flan_hacker adding the test tree +$ymd flan_hacker [master] adding the test tree @@ -89,7 +89,7 @@ EOF cat <$testroot/view.expected commit $head_id [1/1] master |[1/40] diff /dev/null $head_id -$ymd flan_hacker adding the test tree |commit $head_id (master) +$ymd flan_hacker [master] adding the test tree |commit $head_id (master) |from: Flan Hacker |date: $date | @@ -153,7 +153,7 @@ EOF cat <$testroot/view.expected commit $commit1 [1/2] master -$ymd $id1_len8 john author +$ymd $id1_len8 john [master] author $ymd $head_id_len8 flan_hacker adding the test tree :show commit author EOF @@ -179,7 +179,7 @@ test_log_scroll_right() local date=`date -u -r $author_time +"%a %b %e %X %Y UTC"` local ymd=`date -u -r $author_time +"%G-%m-%d"` local msg="scroll this log message to the right four characters" - local scrolled_msg="ll this log message to the right four characters" + local scrolled_msg="ter] scroll this log message to the right four character" echo "mod alpha" > $testroot/repo/alpha cd $testroot/repo && git add . && git commit -m "$msg" > /dev/null @@ -228,7 +228,7 @@ EOF cat <$testroot/view.expected commit $head_id [1/1] master -$ymd flan_hacker adding the test tree +$ymd flan_hacker [master] adding the test tree -------------------------------------------------------------------------------- references [1/2] @@ -270,7 +270,7 @@ EOF cat <$testroot/view.expected commit $head_id [1/1] master -$ymd flan_hacker adding the test tree +$ymd flan_hacker [master] adding the test tree -------------------------------------------------------------------------------- commit $head_id blob - 11b06f5c163c7f7ae9770567b2f8f3ba89659353 blob + 07e729502bd265d19becc465a899c24ecb04323a --- tog/tog.c +++ tog/tog.c @@ -2409,12 +2409,14 @@ draw_commit(struct tog_view *view, struct got_commit_o char *author = NULL; wchar_t *wlogmsg = NULL, *wauthor = NULL; int author_width, logmsg_width; + size_t wrefstr_len = 0; char *newline, *line = NULL; int col, limit, scrollx; const int avail = view->ncols; struct tm tm; time_t committer_time; struct tog_color *tc; + struct got_reflist_head *refs; committer_time = got_object_commit_get_committer_time(commit); if (gmtime_r(&committer_time, &tm) == NULL) @@ -2494,6 +2496,46 @@ draw_commit(struct tog_view *view, struct got_commit_o newline = strchr(logmsg, '\n'); if (newline) *newline = '\0'; + + /* Prepend reference labels to log message if possible .*/ + refs = got_reflist_object_id_map_lookup(tog_refs_idmap, id); + if (refs) { + char *refs_str, *p, *newlogmsg; + wchar_t *ws; + + err = build_refs_str(&refs_str, refs, id, s->repo); + if (err) + goto done; + + if (asprintf(&p, "[%s]", refs_str) == -1) { + err = got_error_from_errno("asprintf"); + free(refs_str); + goto done; + } + free(refs_str); + refs_str = NULL; + + /* + * The length of this wide-char sub-string will be + * needed later for colorization. + */ + err = mbs2ws(&ws, &wrefstr_len, p); + if (err) + goto done; + free(ws); + + if (asprintf(&newlogmsg, "%s %s", p, logmsg) == -1) { + err = got_error_from_errno("asprintf"); + free(p); + goto done; + } + free(p); + + free(logmsg0); + logmsg0 = newlogmsg; + logmsg = logmsg0; + } + limit = avail - col; if (view->child && !view_is_hsplit_top(view) && limit > 0) limit--; /* for the border */ @@ -2501,7 +2543,19 @@ draw_commit(struct tog_view *view, struct got_commit_o limit, col, 1); if (err) goto done; - waddwstr(view->window, &wlogmsg[scrollx]); + if (wrefstr_len > 0 && scrollx < wrefstr_len) { + tc = get_color(&s->colors, TOG_COLOR_COMMIT); + if (tc) + wattr_on(view->window, + COLOR_PAIR(tc->colorpair), NULL); + waddnwstr(view->window, &wlogmsg[scrollx], + wrefstr_len - scrollx); + if (tc) + wattr_off(view->window, + COLOR_PAIR(tc->colorpair), NULL); + waddwstr(view->window, &wlogmsg[wrefstr_len]); + } else + waddwstr(view->window, &wlogmsg[scrollx]); col += MAX(logmsg_width, 0); while (col < avail) { waddch(view->window, ' ');