-
Notifications
You must be signed in to change notification settings - Fork 141
Turn more preprocessor constants into enums #357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Correction: in https://public-inbox.org/git/[email protected]/, the Git maintainer frowned upon using |
we have to convert every single preprocessor constant into |
We don't have to 😀 But it would be nice to make older code consistent with newer coding conventions, no? And when breaking it apart into the individual |
Looks good issue for me to getting started. 😄 |
Cool! Do keep in mind that you do not need to do all of them. Just pick one, for a start. |
Question for lurkers: when compiling with |
Answering my own question: In GDB, if (gdb) p (int) RECURSE_SUBMODULES_OFF
0
(gdb) p /d RECURSE_SUBMODULES_OFF
0
(gdb) p RECURSE_SUBMODULES_OFF+0
0 Source: https://sourceware.org/bugzilla/show_bug.cgi?id=11067 In LLDB (tested in version 10.0.0), it seems enums have to be named for the debugger to understand the enum constants, i.e. with this patch: diff --git i/submodule.h w/submodule.h
index 84640c49c1..61151810cb 100644
--- i/submodule.h
+++ w/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, you can do (lldb) p (int) submodule_recurse_mode::RECURSE_SUBMODULES_ON_DEMAND
(int) $0 = -1
(lldb) p submodule_recurse_mode::RECURSE_SUBMODULES_ON_DEMAND+0
(int) $1 = -1 You can also check in the other direction, i.e. cast the In GDB you can do: (gdb) p (enum submodule_recurse_mode) recurse_submodules
$1 = RECURSE_SUBMODULES_ON In LLDB you can do: (lldb) p (submodule_recurse_mode) recurse_submodules
(submodule_recurse_mode) $1 = RECURSE_SUBMODULES_ON
(lldb) p (enum submodule_recurse_mode) recurse_submodules
(submodule_recurse_mode) $2 = RECURSE_SUBMODULES_ON EDIT I've added these tips to my "Debugging Git" Gist: |
Is this issue still doable? I kinda want to know |
@ffyuanda I would actually recommend thinking of something you want to change in Git. If there has been any moment where you said "if Git only would...", that's a good idea to pursue. Turning preprocessor constants into enums is not only boring, it also has been met with lackluster enthusiasm by the Git maintainer. |
In Git's source, code, there are a number of constants such as:
In recent years, the Git project started preferring
enum
values instead, for added type safety and to allow stronger reasoning via static analysis.Even values that are intended to be used in bit fields can benefit from this, e.g.
As there are too many instances of this kind in Git's source code, a good first issue to tackle would be to find a group of such preprocessor constants and turn them into an
enum
. Also find where those constants are stored in variables and in structs and passed around as function parameters, and change the type of those variables, fields and parameters to the newenum
.Suggested in https://public-inbox.org/git/[email protected]/
The text was updated successfully, but these errors were encountered: