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

Re: [PATCH] submodule.h: use a named enum for RECURSE_SUBMODULES_*

From
Philippe Blain <levraiphilippeblain@gmail.com>
Date
Jan 7, 2022, 13:27 UTC
Message-ID
<3160705c-d95c-c389-e929-f1f6bbcd80fc@gmail.com>
In-Reply-To
<xmqq1r1lhobf.fsf@gitster.g>
Hi Junio,
Le 2022-01-05 à 16:20, Junio C Hamano a écrit :
Show 19 quoted lines
> "Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 
>> From: Philippe Blain <levraiphilippeblain@gmail.com>
>>
>> Using a named enum allows casting an integer to the enum type in both
>> GDB and LLDB:
>>
>>      (gdb) p (enum diff_submodule_format) options->submodule_format
>>      $1 = DIFF_SUBMODULE_LOG
> 
> Hmph, this was somewhat unexpected and quite disappointing.
> 
> Because that's not what those "Let's move away from #define'd
> constants and use more enums" said when they sold their "enum" to
> us.  In the diff_options struct, the .submodule_format member is of
> type enum already, so, if we trust what they told us when they sold
> their enums, "p options->submodule_format" should be enough to give
> us "DIFF_SUBMODULE_LOG", not "1", as its output.  Do you really need
> the cast in the above example?

Yes, you are right that my example does not reflect what I'm saying, since options->submodule_format is not an int. I checked and indeed we do not need any cast to get "DIFF_SUBMODULE_LOG". We do need it when dealing with int's, which is not the case here. I'll try to find a better example.

Show 9 quoted lines
> 
>> Name the enum listing the different RECURSE_SUBMODULES_* modes, to make
>> debugging easier.
> 
> Even though this patch may be a good single step in the right
> direction, until it is _used_ to declare a variable or a member of a
> struct of that enum type, it probably is not useful as much as it
> could be.  The user needs to know which enum is stored in that "int"
> variable or member the user is interested in to cast it to.

Yes, that's true. But when I came across that, I was in a place of the code where some int was compared with a constant in this enum, RECURSE_SUBMODULES_something. So it would have been easy to check where the enum is declared, learn its name and use it to cast the int to the enum type. That's the kind of situation I have in mind.

Show 17 quoted lines
> 
> That is, many changes like this one.
> 
> diff --git i/builtin/pull.c w/builtin/pull.c
> index c8457619d8..f2fd4784df 100644
> --- i/builtin/pull.c
> +++ w/builtin/pull.c
> @@ -71,7 +71,7 @@ static const char * const pull_usage[] = {
>   /* Shared options */
>   static int opt_verbosity;
>   static char *opt_progress;
> -static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
> +static enum submodule_recurse_mode recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
>   
>   /* Options passed to git-merge or git-rebase */
>   static enum rebase_type opt_rebase = -1;
> 

Yes, this is a parallel effort that could be done, I agree, but my patch was meant to help in the mean time.

Thanks,
Philippe.
Previous: Junio C HamanoNext: Glen Choo
Message 3 of 7 in “submodule.h: use a named enum for RECURSE_SUBMODULES_*”
  1. submodule.h: use a named enum for RECURSE_SUBMODULES_*Philippe Blain via GitGitGadget, Jan 5, 2022
  2. Junio C HamanoJan 5, 2022
  3. Philippe BlainJan 7, 2022
  4. Glen ChooJan 7, 2022
  5. Glen ChooJan 18, 2022
  6. submodule.h: use a named enum for RECURSE_SUBMODULES_*Philippe Blain via GitGitGadget, Apr 4, 2022
  7. Glen ChooApr 4, 2022

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.