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

Re: [PATCH v3 4/4] wt-status.c: Set the committable flag in the collect phase.

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 7, 2018, 22:01 UTC
Message-ID
<xmqqworxufuv.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20180906005329.11277-5-ischis2@cox.net>
"Stephen P. Smith" <ischis2@cox.net> writes:
Show 16 quoted lines
>  void wt_status_collect(struct wt_status *s)
>  {
> +	struct wt_status_state state;
>  	wt_status_collect_changes_worktree(s);
>  
>  	if (s->is_initial)
> @@ -746,6 +752,11 @@ void wt_status_collect(struct wt_status *s)
>  	else
>  		wt_status_collect_changes_index(s);
>  	wt_status_collect_untracked(s);
> +
> +	memset(&state, 0, sizeof(state));
> +	wt_status_get_state(&state, s->branch && !strcmp(s->branch, "HEAD"));
> +	if (state.merge_in_progress && !has_unmerged(s))
> +		s->committable = 1;
>  }

I do not think this is wrong per-se, but now we have three calls to wt_status_get_state() in wt-status.c, and it smells (at least to me) that each of these callsites does so only because their callers do not give them enough information, forcing them to find the state out for themselves.

Given that the ideal paradigm to come up with the "work tree status" is to do the collection followed by printing, and among three callers of get_state(), two appear in the "printing" side of the callchain [*1*], I wonder if it makes a better organization to

 - embed struct wt_status_state in struct wt_status
 - make the new call to wt_status_get_state() added above in this
   patch to populate the wt_status_state embedded in 's'
 - change the other two callers of wt_status_get_state() in
   wt_longstatus_print() and wt_porcelain_v2_print_tracking(), both
   of which will receive 's' that has been populated by a previous
   call to wt_status_collect(), so that they do *not* call
   get_state() themselves, but instead use the result recorded in
   wt_status_state embedded in 's', which was populated by
   wt_status_collect() before they got called.

That would bring the resulting code even closer to the ideal, i.e. the "collect" phase learns _everything_ we need about the current state that is necessary in order to later show to the user, and the "print" phase does not do its own separate discovery.

What do you think?
Thanks.
[Reference]
*1* Here are the selected functions and what other functions they
    call.
    wt_status_collect()
     -> wt_status_collect_changes_initial()
     -> wt_status_collect_changes_index()
     -> wt_status_collect_untracked()
     -> wt_status_get_state()
    wt_longstatus_print()
     -> wt_status_get_state()
    wt_porcelain_v2_print_tracking()
     -> wt_status_get_state()
    wt_status_print()
     -> wt_porcelain_v2_print()
        -> wt_porcelain_v2_print_tracking()
     -> wt_longstatus_print()
    run_status()
     -> wt_status_collect()
     -> wt_status_print()
    cmd_status()
     -> wt_status_collect()
     -> wt_status_print()
    prepare_to_commit(), dry_run_commit()
     -> run_status()
    Most notably, wt_status_collect() always happens before
    wt_status_print(), which is natural because the former is to
    collect information in 's' that is used by the latter to print.
    And in various functions wt_status_print() calls indirectly, the
    two other callers of wt_status_get_state() appear.
Previous: Stephen P. SmithNext: Junio C Hamano
Message 7 of 25 in “wt-status.c: commitable flag”
  1. 0/4 wt-status.c: commitable flagStephen P. Smith, Sep 6, 2018
  2. 1/4 Move has_unmerged earlier in the file.Stephen P. Smith, Sep 6, 2018
  3. 3/4 t7501: add test of "commit --dry-run --short"Stephen P. Smith, Sep 6, 2018
  4. 2/4 wt-status: rename commitable to committableStephen P. Smith, Sep 6, 2018
  5. Junio C HamanoSep 7, 2018
  6. 4/4 wt-status.c: Set the committable flag in the collect phase.Stephen P. Smith, Sep 6, 2018
  7. Junio C HamanoSep 7, 2018
  8. Junio C HamanoSep 7, 2018
  9. 0/1 wt-status-state-cleanupStephen P. Smith, Sep 28, 2018
  10. 1/1 roll wt_status_state into wt_status and populate in the collect phaseStephen P. Smith, Sep 28, 2018
  11. Taylor BlauSep 28, 2018
  12. Junio C HamanoSep 28, 2018
  13. 0/1 wt-status-state-cleanupStephen P. Smith, Sep 29, 2018
  14. 1/1 roll wt_status_state into wt_status and populate in the collect phaseStephen P. Smith, Sep 29, 2018
  15. Eric SunshineSep 30, 2018
  16. 0/1 wt-status-state-cleanupStephen P. Smith, Sep 30, 2018
  17. 1/1 roll wt_status_state into wt_status and populate in the collect phaseStephen P. Smith, Sep 30, 2018
  18. Eric SunshineSep 30, 2018
  19. Stephen P. SmithSep 7, 2018
  20. Junio C HamanoSep 11, 2018
  21. Stephen SmithSep 24, 2018
  22. Junio C HamanoSep 24, 2018
  23. Ævar Arnfjörð BjarmasonSep 6, 2018
  24. Stephen & Linda SmithSep 6, 2018
  25. Junio C HamanoSep 7, 2018

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.