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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 26, 2017 at 4:11 AM, Junio C Hamano <gitster@xxxxxxxxx> wrote:
>  * 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.

>    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



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]