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

Re: [PATCH 7/9] builtin-checkout-index.c: use parse_options()

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Jul 25, 2008, 09:01 UTC
Message-ID
<48899657.5090209@lsrfire.ath.cx>
In-Reply-To
<bd6139dc0807241335i3ab5280aq6a46325428ccc70f@mail.gmail.com>
Sverre Rabbelier schrieb:
Show 15 quoted lines
> On Thu, Jul 24, 2008 at 10:08 PM, Michele Ballabio
> <barra_cuda@katamail.com> wrote:
>> On Thursday 24 July 2008, Johannes Schindelin wrote:
>>> On Wed, 23 Jul 2008, Michele Ballabio wrote:
>>>
>>>> +           { OPTION_CALLBACK, 'f', "force", &state, NULL,
>>>> +             "force overwrite of existing files",
>>>> +             PARSE_OPT_NOARG, parse_state_force_cb, 0 },
>>> I wonder if this could not be written as
>>>
>>>               OPT_BOOLEAN('f', "force", &state.force,
>>>                       "force overwrite of existing files"),
>> I did it that way because 'force' is a bitfield.
> 
> I thought there is an OPT_BIT?
OPT_BIT is for flags and bitmasks, not for bitfields.

Since you can't get the address of a bitfield member, a function that wants to change its value needs to know its name. Switching to bitmasks would make the option parsing code look cleaner, but you'd have to change all those bitfield accesses to explicit bitmask operations, e.g.:

	if (state.force)
		state.force = 0;
vs.
	if (state.flags & CHECKOUT_FORCE)
		state.flags &= ~CHECKOUT_FORCE;

In the case of struct checkout, though, we could simply make the bitfield members full ints, because there are only a few instances of this structure in memory at any given time. Wasting a few bytes of RAM in order to gain much simpler code is OK in this case, I think. OPT_BOOLEAN looks a lot nicer than a callback.

René
Previous: Sverre RabbelierNext: Michele Ballabio
Message 28 of 31 in “Extend use of parse_options()”
  1. 0/9 Extend use of parse_options()Michele Ballabio, Jul 23, 2008
  2. 1/9 builtin-verify-tag.c: use parse_options()Michele Ballabio, Jul 23, 2008
  3. Olivier MarinJul 24, 2008
  4. Johannes SchindelinJul 24, 2008
  5. Olivier MarinJul 25, 2008
  6. Johannes SchindelinJul 26, 2008
  7. builtin-verify-tag: fix -v option parsingOlivier Marin, Jul 28, 2008
  8. Johannes SchindelinJul 28, 2008
  9. Olivier MarinJul 28, 2008
  10. Johannes SchindelinJul 28, 2008
  11. 2/9 builtin-write-tree.c: use parse_options()Michele Ballabio, Jul 23, 2008
  12. 3/9 builtin-prune-packed.c: use parse_options()Michele Ballabio, Jul 23, 2008
  13. 4/9 builtin-ls-tree.c: use parse_options()Michele Ballabio, Jul 23, 2008
  14. 5/9 builtin-rev-list.c: use parse_options()Michele Ballabio, Jul 23, 2008
  15. 6/9 builtin-init-db.c: use parse_options()Michele Ballabio, Jul 23, 2008
  16. Olivier MarinJul 24, 2008
  17. Johannes SchindelinJul 24, 2008
  18. Olivier MarinJul 25, 2008
  19. Johannes SchindelinJul 26, 2008
  20. Michele BallabioJul 24, 2008
  21. 6/9 builtin-init-db.c: use parse_options()Michele Ballabio, Jul 25, 2008
  22. Olivier MarinJul 25, 2008
  23. 6/9 builtin-init-db.c: use parse_options()Michele Ballabio, Jul 25, 2008
  24. 7/9 builtin-checkout-index.c: use parse_options()Michele Ballabio, Jul 23, 2008
  25. Johannes SchindelinJul 24, 2008
  26. Michele BallabioJul 24, 2008
  27. Sverre RabbelierJul 24, 2008
  28. René ScharfeJul 25, 2008
  29. 7/9 builtin-checkout-index.c: use parse_options()Michele Ballabio, Jul 25, 2008
  30. 8/9 builtin-fetch-pack.c: use parse_options()Michele Ballabio, Jul 23, 2008
  31. 9/9 builtin-mailinfo.c: use parse_options()Michele Ballabio, Jul 23, 2008

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.