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

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

From
Glen Choo <chooglen@google.com>
Date
Apr 4, 2022, 17:52 UTC
Message-ID
<kl6lv8voybvh.fsf@chooglen-macbookpro.roam.corp.google.com>
In-Reply-To
<pull.1111.v2.git.1649092211419.gitgitgadget@gmail.com>
"Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 24 quoted lines
> From: Philippe Blain <levraiphilippeblain@gmail.com>
>
> Using a named enum allows casting an integer to the enum type in both
> GDB and LLDB:
>
>     $ gdb -q -ex 'b wt-status.c:44' -ex r --args ./git status
>     (gdb) p (enum color_wt_status) slot
>     $1 = WT_STATUS_ONBRANCH
>
>     $ lldb -o 'b wt-status.c:44' -o r -- ./git status
>     (lldb) p (color_wt_status) slot
>     (color_wt_status) $0 = WT_STATUS_ONBRANCH
>
> In LLDB, it's also required to cast in the reversed direction, i.e.
> cast an enum constant into its corresponding integer:
>
>     (lldb) p (int) color_wt_status::WT_STATUS_ONBRANCH
>     (int) $1 = 8
>
> Name the enum listing the different RECURSE_SUBMODULES_* modes, to make
> debugging easier. For example, when stepping through a part of the code
> where an int is compared with a constant in this enum, it allows casting
> the int to the enum type or vice-versa, after quickly checking where the
> enum constant is declared and learning the enum name.

Makes sense, and besides just making debugging easier, this would also make code easier to read once we use the enum in more places (instead of just int).

> As to not make this patch a debug-only change, convert the
> 'fetch_recurse' member of 'struct submodule' to use the newly named
> enum.
[...]
Show 30 quoted lines
>  submodule-config.h | 2 +-
>  submodule.h        | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/submodule-config.h b/submodule-config.h
> index 65875b94ea5..55a4c3e0bd5 100644
> --- a/submodule-config.h
> +++ b/submodule-config.h
> @@ -37,7 +37,7 @@ struct submodule {
>  	const char *path;
>  	const char *name;
>  	const char *url;
> -	int fetch_recurse;
> +	enum submodule_recurse_mode fetch_recurse;
>  	const char *ignore;
>  	const char *branch;
>  	struct submodule_update_strategy update_strategy;
> diff --git a/submodule.h b/submodule.h
> index 6bd2c99fd99..55cf6f01d0c 100644
> --- a/submodule.h
> +++ b/submodule.h
> @@ -13,7 +13,7 @@ struct repository;
>  struct string_list;
>  struct strbuf;
>  
> -enum {
> +enum submodule_recurse_mode {
>  	RECURSE_SUBMODULES_ONLY = -5,
>  	RECURSE_SUBMODULES_CHECK = -4,
>  	RECURSE_SUBMODULES_ERROR = -3,

Like Junio, I think it would be nice to use the enum in more places, but frankly there are so many sites that would need to change that I don't think it's reasonable for one person to change them all.

So I'm happy to take this first step and do the rest of the refactoring incrementally. I still think the enum's values are too disjointed and should eventually be broken up, but that's a refactoring for later.

Reviewed-by: Glen Choo <chooglen@google.com>
Previous: Philippe Blain via GitGitGadget
Message 7 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.