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

Re: [PATCH] builtin: pass repository to sub commands

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 26, 2024, 19:26 UTC
Message-ID
<xmqq34jdyey3.fsf@gitster.g>
In-Reply-To
<Z0WNKV5prRE2Hupw@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 6 quoted lines
> So if the code were refactored to instead accept an arbitrary `void *`
> pointer, callers could provide a custom structure and pass that along to
> its subcommands. In many cases we may end up just passing the repo
> directly, but I'm sure there are others where this direction would buy
> us additional flexibility and allow us to get rid of even more global
> state.

I am of two minds. Certainly for OPT_SUBCOMMAND macro to be able to work with arbitrary types that are specific to each git subcommand, we'd need "void *" plus casting on the receiving end. But it loses type safety.

I personally think (but not so strongly) that we should add a repo to parse_opt_subcommand_fn(), if this exercise is about giving consistent access to the repository object universally across subsubcommands.

If we want flexibility on top, we can either add another "void *" for it after we are done with adding the repository, or we may even be able to make the parse_opt_subcommand_fn() a varargs.

Previous: karthik nayakNext: Karthik Nayak
Message 6 of 12 in “builtin: pass repository to sub commands”
  1. builtin: pass repository to sub commandsKarthik Nayak, Nov 25, 2024
  2. Christian CouderNov 26, 2024
  3. karthik nayakNov 26, 2024
  4. Patrick SteinhardtNov 26, 2024
  5. karthik nayakNov 26, 2024
  6. Junio C HamanoNov 26, 2024
  7. builtin: allow passing custom data to sub-commandsKarthik Nayak, Nov 26, 2024
  8. shejialuoNov 26, 2024
  9. karthik nayakNov 26, 2024
  10. Junio C HamanoNov 26, 2024
  11. karthik nayakNov 27, 2024
  12. karthik nayakNov 27, 2024

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.