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

Re: [PATCH 2/5] revision.c: group ref selection options together

From
Duy Nguyen <pclouds@gmail.com>
Date
Jan 26, 2017, 09:12 UTC
Message-ID
<CACsJy8Dwr5g6ZvemYgfg7Lecu=PsWz734tWgfFDCkWB_Htg7Hg@mail.gmail.com>
In-Reply-To
<xmqqo9yualqn.fsf@gitster.mtv.corp.google.com>
On Thu, Jan 26, 2017 at 4:11 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 6 quoted lines
>  * I am expecting that the new one yet to be introduced will not
>    share the huge "switch (selector)" part, but does its own things
>    in a separate function with a similar structure.  The only thing
>    common between these two functions would be the structure
>    (i.e. it has a big "switch(selector)" that does different things
>    depending on REF_SELECT_*) and a call to clear_* function.
Yep. The "new one" is demonstrated in 5/5.
Show 6 quoted lines
>    If we were to add a new kind of REF_SELECT_* (say
>    REF_SELECT_NOTES just for the sake of being concrete), what
>    changes will be needed to the code if the addition of "use reflog
>    from this class of refs for decoration" feature was done with or
>    without this step?  I have a suspicion that the change will be
>    simpler without this step.

The switch/case is to deal with new REF_SELECT_* (at least it's how I imagine it). What I was worried about was, when a user adds --select-notes, they may not be aware that it's in the same all/branches/tags/remotes group that's supposed to work with --decorate-reflog as well, and as a result "--decorate-reflog --select-notes" is the same as "--select-notes".

With the switch/case, when you add a new enum item, at the least the compiler should warn about unhandled cases. And we can have a new "case REF_SELECT_NOTES:" for both --exclude and --decorate-reflog. Without the switch/case, I guess it's still possible to do something like

if (!strcmp(arg, "--select-notes")) {
    if (preceded_by_exclude())
        does_one_thing();
    else if (preceded_by_decorate_reflog())
       does_another_thing();
}

It's probably easier to maintain though, if all decorate-reflog-related things are grouped together, rather than spread out per option like the above.

-- 
Duy
Previous: Junio C HamanoNext: Nguyễn Thái Ngọc Duy
Message 15 of 27 in “log: new option decorate reflog of remote refs”
  1. log: new option decorate reflog of remote refsNguyễn Thái Ngọc Duy, Jan 19, 2017
  2. Jeff KingJan 19, 2017
  3. Duy NguyenJan 20, 2017
  4. Jeff KingJan 20, 2017
  5. Jacob KellerJan 20, 2017
  6. Duy NguyenJan 21, 2017
  7. Jeff KingJan 21, 2017
  8. 0/5 Prep steps for --decorate-reflogNguyễn Thái Ngọc Duy, Jan 25, 2017
  9. 1/5 rev-list-options.txt: delete an empty lineNguyễn Thái Ngọc Duy, Jan 25, 2017
  10. 2/5 revision.c: group ref selection options togetherNguyễn Thái Ngọc Duy, Jan 25, 2017
  11. Jeff KingJan 25, 2017
  12. Duy NguyenJan 26, 2017
  13. Jeff KingJan 26, 2017
  14. Junio C HamanoJan 25, 2017
  15. Duy NguyenJan 26, 2017
  16. 3/5 revision.c: allow to change pseudo opt parsing functionNguyễn Thái Ngọc Duy, Jan 25, 2017
  17. 5/5 revision.c: add --decorate-reflogNguyễn Thái Ngọc Duy, Jan 25, 2017
  18. 4/5 revision.c: refactor ref selection handler after --excludeNguyễn Thái Ngọc Duy, Jan 25, 2017
  19. Jacob KellerJan 25, 2017
  20. Jeff KingJan 25, 2017
  21. Jeff KingJan 25, 2017
  22. Jacob KellerJan 25, 2017
  23. Junio C HamanoJan 25, 2017
  24. Duy NguyenJan 26, 2017
  25. Jeff KingJan 26, 2017
  26. Junio C HamanoJan 26, 2017
  27. Junio C HamanoJan 25, 2017

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.