git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [[TIG][PATCH] 1/3] Add log_select function to find commit from context in log view

From
Kumar Appaiah <a.kumar@alumni.iitm.ac.in>
Date
Aug 6, 2013, 04:08 UTC
Message-ID
<20130806040826.GA14703@bluemoon.alumni.iitm.ac.in>
In-Reply-To
<CAFuPQ1KkUn5t54BXLTnYUcH_jY-SiSEJx3dDVzQ3FpswhFg0Bw@mail.gmail.com>
Dear Jonas,

Thanks for the patient review. On Mon, Aug 05, 2013 at 11:27:44PM -0400, Jonas Fonseca wrote:

Show 8 quoted lines
> On Fri, Aug 2, 2013 at 8:23 PM, Kumar Appaiah <a.kumar@alumni.iitm.ac.in> wrote:
> > This commit introduces and uses the log_select function to find the
> > correct commit in the unsplit log view. In the log view, if one
> > scrolls down across a commit line, the current commit (as displayed in
> > the status bar) gets updated, but not so when scrolling upward across
> > a commit. The log_select function handles this scenario to to the
> 
> s/to to/to do/
Done.
Show 34 quoted lines
> > ``right thing''. In addition, it introduces the log_state structure as
> > the private entry of the log view to hold a flag that decides whether
> > to re-evaluate the current commit based on scrolling.
> >
> > Signed-off-by: Kumar Appaiah <a.kumar@alumni.iitm.ac.in>
> > ---
> >  tig.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++--
> >  1 file changed, 48 insertions(+), 2 deletions(-)
> >
> > diff --git a/tig.c b/tig.c
> > index 72f132a..dd4b0f4 100644
> > --- a/tig.c
> > +++ b/tig.c
> > @@ -4384,6 +4384,33 @@ pager_select(struct view *view, struct line *line)
> >         }
> >  }
> >
> > +struct log_state {
> > +       bool update_commit_ref;
> > +};
> > +
> > +static void
> > +log_select(struct view *view, struct line *line)
> > +{
> > +       struct log_state *state = (struct log_state *) view->private;
> > +
> > +       if (state->update_commit_ref && line->lineno > 1) {
> > +               /* We need to recalculate the previous commit,
> > +                  since the user has likely scrolled up. */
> 
> I'd prefer that state->update_commit_ref is given another name so it
> won't be necessary to have these comments everywhere the field is
> used, for example recalculate_commit_context. The comment could be
> moved to the declaration in struct log_state to explain its use.
Done.
> Multi-line comments should start with '*' for each additonal line, e.g.
> 
>   /* bla bla
>    * bla bla */
Done.
Show 8 quoted lines
> > +               const struct line *commit_line = find_prev_line_by_type(view, line, LINE_COMMIT);
> > +
> > +               if (commit_line)
> > +                       string_copy_rev(view->ref, (char *) (commit_line->data + STRING_SIZE("commit ")));
> 
> You mentioned elsewhere that this looked funny, and I guess you are
> right. I will extract this into a utility method so you can simply
> call: string_copy_rev_from_line(view->ref, commit_line); ...

I will wait on this. The next iteration of the patch will still have this problem.

Show 8 quoted lines
> > +       }
> > +       if (line->type == LINE_COMMIT) {
> > +               char *text = (char *)line->data + STRING_SIZE("commit ");
> > +
> > +               if (!view_has_flags(view, VIEW_NO_REF))
> > +                       string_copy_rev(view->ref, text);
> 
> ... and: string_copy_rev_from_line(view->ref, line);
I understand.
Show 15 quoted lines
> > +       }
> > +       string_copy_rev(ref_commit, view->ref);
> > +       state->update_commit_ref = FALSE;
> > +}
> > +
> >  static bool
> >  pager_open(struct view *view, enum open_flags flags)
> >  {
> > @@ -4427,11 +4454,30 @@ log_open(struct view *view, enum open_flags flags)
> >  static enum request
> >  log_request(struct view *view, enum request request, struct line *line)
> >  {
> > +       struct log_state *state = (struct log_state *) view->private;
> 
> There's no need to cast view->private here.
Done.
Show 15 quoted lines
> > +
> >         switch (request) {
> >         case REQ_REFRESH:
> >                 load_refs();
> >                 refresh_view(view);
> >                 return REQ_NONE;
> > +
> > +       case REQ_MOVE_UP:
> > +       case REQ_PREVIOUS:
> > +               if (line->type == LINE_COMMIT && line->lineno > 1) {
> > +                       /* We are at a commit, and heading upward. We
> > +                          force log_select to find the previous
> > +                          commit above, from the context. */
> 
> Please delete this comment.
Done.
Show 6 quoted lines
> > +                       state->update_commit_ref = TRUE;
> > +               }
> > +               return pager_request(view, request, line);
> 
> There's not really any reason to call pager_request here, since it
> only handles REQ_ENTER.
Done.
Show 6 quoted lines
> > +
> > +       case REQ_MOVE_PAGE_UP:
> > +       case REQ_MOVE_PAGE_DOWN:
> > +               /* We need to figure out the right commit again. */
> 
> Please delete this this comment.
Done.
> > +               state->update_commit_ref = TRUE;
> > +               return pager_request(view, request, line);
> 
> Calling pager_request again.
Done.
I will send in another patch to review shortly.
Thanks!
Kumar
-- 
Kumar Appaiah
Previous: Jonas FonsecaNext: Jonas Fonseca
Message 4 of 9 in “Refactoring of the log view”
  1. Kumar AppaiahAug 3, 2013
  2. [[TIG][PATCH] 1/3] Add log_select function to find commit from context in log viewKumar Appaiah, Aug 3, 2013
  3. Jonas FonsecaAug 6, 2013
  4. Kumar AppaiahAug 6, 2013
  5. Jonas FonsecaAug 6, 2013
  6. [[TIG][PATCH] 2/3] Display correct diff the context in split log viewKumar Appaiah, Aug 3, 2013
  7. Jonas FonsecaAug 6, 2013
  8. [[TIG][PATCH] 3/3] Revert "Scroll diff with arrow keys in log view"Kumar Appaiah, Aug 3, 2013
  9. Jonas FonsecaAug 6, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.