diff mbox series

[v4,2/3] format-patch: use enum variables

Message ID 19ee1f71493fa584991f530e952d9198880208eb.1570821015.git.liu.denton@gmail.com (mailing list archive)
State New, archived
Headers show
Series format-patch: learn --cover-from-description option | expand

Commit Message

Denton Liu Oct. 11, 2019, 7:12 p.m. UTC
Before, `thread` and `config_cover_letter` were defined as ints even
though they behaved as enums. Define actual enums and change these
variables to use these new definitions.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 builtin/log.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

Comments

Junio C Hamano Oct. 12, 2019, 2:16 a.m. UTC | #1
Denton Liu <liu.denton@gmail.com> writes:

> -#define THREAD_SHALLOW 1
> -#define THREAD_DEEP 2
> -static int thread;
> +enum thread_level {
> +	THREAD_UNSET,
> +	THREAD_SHALLOW,
> +	THREAD_DEEP
> +};
> +static enum thread_level thread;

As the assignment of values do not change, this is a safe conversion
even if an existing code did things like

	if (!thread)
        	... do this ...;

Hopefully nobody did arithmetic on it; thread_level may now become
unsigned depending on the compiler.

> -static int config_cover_letter;
> +static enum cover_setting config_cover_letter;

Likewise about the signedness.
diff mbox series

Patch

diff --git a/builtin/log.c b/builtin/log.c
index 7d658cecef..f06f5d586b 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -764,24 +764,28 @@  static void add_header(const char *value)
 	item->string[len] = '\0';
 }
 
-#define THREAD_SHALLOW 1
-#define THREAD_DEEP 2
-static int thread;
+enum cover_setting {
+	COVER_UNSET,
+	COVER_OFF,
+	COVER_ON,
+	COVER_AUTO
+};
+
+enum thread_level {
+	THREAD_UNSET,
+	THREAD_SHALLOW,
+	THREAD_DEEP
+};
+
+static enum thread_level thread;
 static int do_signoff;
 static int base_auto;
 static char *from;
 static const char *signature = git_version_string;
 static const char *signature_file;
-static int config_cover_letter;
+static enum cover_setting config_cover_letter;
 static const char *config_output_directory;
 
-enum {
-	COVER_UNSET,
-	COVER_OFF,
-	COVER_ON,
-	COVER_AUTO
-};
-
 static int git_format_config(const char *var, const char *value, void *cb)
 {
 	struct rev_info *rev = cb;
@@ -1248,9 +1252,9 @@  static int output_directory_callback(const struct option *opt, const char *arg,
 
 static int thread_callback(const struct option *opt, const char *arg, int unset)
 {
-	int *thread = (int *)opt->value;
+	enum thread_level *thread = (enum thread_level *)opt->value;
 	if (unset)
-		*thread = 0;
+		*thread = THREAD_UNSET;
 	else if (!arg || !strcmp(arg, "shallow"))
 		*thread = THREAD_SHALLOW;
 	else if (!strcmp(arg, "deep"))