Download raw body.
tog log reference labels
On 2023/05/15 18:11:35 +0200, Stefan Sperling <stsp@stsp.name> wrote: > Show reference labels next to commit messages in the tog log view. > Requested by mpi@ > > ok? that's nice, i like it too. ok op@ suggestion below > --- tog/tog.c > +++ tog/tog.c > @@ -2405,12 +2405,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) > @@ -2490,6 +2492,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; Instead of building up this temporary string we could directly fed ref_str to mbs2ws() > + /* > + * 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); then do wrefstr_len += 2 to account for '[' and ']'. > + if (asprintf(&newlogmsg, "%s %s", p, logmsg) == -1) { and adding the brackets here + if (asprintf(&newlogmsg, "[%s] %s", p, logmsg) == -1) { but maybe I'm too paranoid about avoiding temporary allocations. > + err = got_error_from_errno("asprintf"); > + free(p); > + goto done; > + } > + free(p); > + > + free(logmsg0); > + logmsg0 = newlogmsg; > + logmsg = logmsg0; > + } > +
tog log reference labels