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

[GSoC][PATCH v3] apply: Change #define to enum and variable types from int to enum

From
Vinayak Dev <vinayakdev.sci@gmail.com>
Date
Feb 15, 2023, 09:19 UTC
Message-ID
<20230215091950.2976-1-vinayakdev.sci@gmail.com>
From: vinayakdsci <vinayakdev.sci@gmail.com>

Change #define constants to enum and variable types from int to enum in apply.c

Enum constants have an advantage over #define macro constants in that modern debuggers are able to report them symbolically instead of just as simple numbers. This makes debugging and catching undercover errors easier, and can many a times save quite some time and inconvenience.

Signed-off-by: Vinayak Dev <vinayakdev.sci@gmail.com>
---
 apply.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/apply.c b/apply.c
index 5cc5479c9c..b2a03d9fc3 100644
--- a/apply.c
+++ b/apply.c
@@ -205,8 +205,10 @@ struct fragment {
  * or deflated "literal".
  */
 #define binary_patch_method leading
-#define BINARY_DELTA_DEFLATED	1
-#define BINARY_LITERAL_DEFLATED 2
+enum binary_type_deflated {
+	BINARY_DELTA_DEFLATED = 1,
+	BINARY_LITERAL_DEFLATED
+};
 
 static void free_fragment_list(struct fragment *list)
 {
@@ -918,14 +920,17 @@ static int gitdiff_hdrend(struct gitdiff_data *state UNUSED,
  * their names against any previous information, just
  * to make sure..
  */
-#define DIFF_OLD_NAME 0
-#define DIFF_NEW_NAME 1
+
+enum diff_name {
+	DIFF_OLD_NAME = 0,
+	DIFF_NEW_NAME
+};
 
 static int gitdiff_verify_name(struct gitdiff_data *state,
 			       const char *line,
 			       int isnull,
 			       char **name,
-			       int side)
+			       enum diff_name side)
 {
 	if (!*name && !isnull) {
 		*name = find_name(state->root, line, NULL, state->p_value, TERM_TAB);
@@ -1910,7 +1915,7 @@ static struct fragment *parse_binary_hunk(struct apply_state *state,
 	int llen, used;
 	unsigned long size = *sz_p;
 	char *buffer = *buf_p;
-	int patch_method;
+	enum binary_type_deflated patch_method;
 	unsigned long origlen;
 	char *data = NULL;
 	int hunk_size = 0;

base-commit: b1485644f936ee83a995ec24d23f713f4230a1ae
-- 
2.39.1
Next: Junio C Hamano
Message 1 of 5 in “apply: Change #define to enum and variable types from int to enum”
  1. Vinayak DevFeb 15, 2023
  2. Junio C HamanoFeb 15, 2023
  3. Vinayak DevFeb 16, 2023
  4. Junio C HamanoFeb 16, 2023
  5. Vinayak DevFeb 16, 2023

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.