[PATCH 1 of 2 V4] shelve: refactor option combination check to easily add new ones

Kevin Bullock kbullock+mercurial at ringworld.org
Wed Jun 11 22:20:27 CDT 2014


On Jun 11, 2014, at 8:50 AM, FUJIWARA Katsunori <foozy at lares.dti.ne.jp> wrote:

> # HG changeset patch
> # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> # Date 1402494363 -32400
> #      Wed Jun 11 22:46:03 2014 +0900
> # Node ID af2b2360b9dc87167b8ffe729342794b8acd115a
> # Parent  0f73ed6293629f69aa2f01d8940e91faeded49ae
> shelve: refactor option combination check to easily add new ones
> 
> Before this patch, the name of a newly added option had to be added
> into each string that was passed to the 'checkopt()' internal
> function: these are white-space-separated list of un-acceptable option
> names.
> 
> This new option had to be added into multiple strings because each
> option could belong to only one category of 'create', 'cleanup',
> 'delete' or 'list'.
> 
> In addition to this redundancy, each string passed to 'checkopt()' was
> already too long to include a new one.

The old way, though cumbersome, at least reads in a straightforward way to me. I can't verify by staring at the code that your new way actually does the same thing.

What about constructing the whitelist as:

    {
        'create': ['addremove', 'date', 'message', 'name']
        # ...
    }

and then looping over the array of compatible(?) options for the option we're checking, looking for each one in `opts`?

pacem in terris / мир / शान्ति / ‎‫سَلاَم‬ / 平和
Kevin R. Bullock



More information about the Mercurial-devel mailing list