Open
Description
In Git's source, code, there are a number of constants such as:
#define DT_UNKNOWN 0
#define DT_DIR 1
#define DT_REG 2
#define DT_LNK 3
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.
#define ACTION_GET (1<<0)
#define ACTION_GET_ALL (1<<1)
#define ACTION_GET_REGEXP (1<<2)
#define ACTION_REPLACE_ALL (1<<3)
#define ACTION_ADD (1<<4)
#define ACTION_UNSET (1<<5)
#define ACTION_UNSET_ALL (1<<6)
#define ACTION_RENAME_SECTION (1<<7)
#define ACTION_REMOVE_SECTION (1<<8)
#define ACTION_LIST (1<<9)
#define ACTION_EDIT (1<<10)
#define ACTION_SET (1<<11)
#define ACTION_SET_ALL (1<<12)
#define ACTION_GET_COLOR (1<<13)
#define ACTION_GET_COLORBOOL (1<<14)
#define ACTION_GET_URLMATCH (1<<15)
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 anenum
. 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 new enum
.
Suggested in https://public-inbox.org/git/20190923180649.GA2886@szeder.dev/