From: Stefan Sperling Subject: Re: tog: open log view of annotated line To: Mark Jamsek Cc: gameoftrees@openbsd.org Date: Tue, 19 Jul 2022 16:40:53 +0200 On Wed, Jul 20, 2022 at 12:07:16AM +1000, Mark Jamsek wrote: > As per the TODO item: open a log view of the selected annotated line. > > diff refs/heads/main refs/heads/dev/blamelog > commit - 314c3f148b7679296136b460ea9a8f0d4c74d437 > commit + 1de4f1ca80d74e859beae5c3633adcf960c79938 > blob - 765c5ecd53d258c8af195523d4fb1fea0c8f41d3 > blob + 80d025e6069d90b874a54b9778401bf07c5b84b1 > --- tog/tog.1 > +++ tog/tog.1 > @@ -406,6 +406,10 @@ currently selected line's commit. > Reload the > .Cm blame > view with the previously blamed commit. > +.It Cm L > +Open a > +.Cm log > +view for the currently selected annotated line. Hmm. I'm wondering if we should change the tree view's l key to L in a follow-up change? Because l is now a horizontal movement key in most views, using L for opening a log view seems better. > +log_annotated_line(struct tog_view **new_view, int begin_y, int begin_x, > + struct got_repository *repo, struct got_object_id *id) > +{ > + struct tog_view *log_view; > + struct got_reference *ref = NULL; > + char *id_str = NULL; > + const char *ref_str = NULL; > + const struct got_error *err = NULL; > + > + *new_view = NULL; > + > + err = got_object_id_str(&id_str, id); > + if (err) > + return err; > + > + err = got_ref_open(&ref, repo, id_str, 0); > + if (err == NULL) > + ref_str = got_ref_get_name(ref); > + else if (err->code != GOT_ERR_NOT_REF) > + goto done; This code assumes that a reference might exist which is named after the commit ID of an annotated line...? That does not really make a lot of sense. This code was apparently copied from cmd_log(), where "start_commit" is user-provided input and may well be string such as "origin/main", which would then be resolved to an object ID. But in log_annotated_line() we definitely have an object ID already. I think you can just set ref_str = GOT_REF_HEAD for now. This may be slightly wrong iin case tog was started in a work tree. But more work will be needed to obtain the correct value in that case. Most commands use got_worktree_get_head_ref_name() to show the current branch of the work tree by default. The log and tree views are storing it in s->head_ref_name to keep the branch name available for Ctrl+L and allow new commits on this branch to be loaded. I suppose tog could store this name globally somewhere, such that you could reuse it here, too. That can be done as a separate change, though. And it is not very critical since the log view will open up just fine at the desired commit either way.