Skip to contentSkip to conversation

{apply,alias}: convert pre-processor macros to enums

PATCH In review Vinayak Dev 3 participants 8 messages Feb 10, 2023 – Feb 15, 2023

lore
Share & tools
lore
#0 lore raw

v2 cover {apply,alias}: convert pre-processor macros to enums

Revert changes to alias.c, and change variable types in apply.c

It is needed to revert changes to alias.c as the changed #define macros were actually returned values, so it is not right to change their types to enums.

Also, SPLIT_CMDLINE_BAD_ENDING is returned after changing to negative sign, breaking the validity of the conversion to enum.

The changes to apply.c are actually useful only if the variable types are enum, so change the type of variable int patch_method and function argument int side to enums as well.

Changes are in accordance to Eric's review of v1:
https://lore.kernel.org/git/CADE8NappDSaZrMLeqak4is59oL=X1wJOj2eCLLjaCKyrnoK9PQ@mail.gmail.com/T/

Vinayak Dev (2):
Revert added enum to #define
Change types of int patch_method and int side to enum

Vinayak Dev (1):
Change #define to enum in apply.c and alias.c

 alias.c |  1 +
 apply.c | 17 +++++++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)

Range-diff against v1:

1:  f64b1af2a5 = 1:  eaaa09dfb1 Change #define to enum in apply.c and alias.c
-:  ---------- > 2:  86e27e7f64 Revert added enum to #define
-:  ---------- > 3:  17233eb3fe Change types of int patch_method and int side to enum
Signature · 1 line
2.39.1
#1 lore raw

PATCH v2 1/3 {apply,alias}: convert pre-processor macros to enums

From: vinayakdsci <[email protected]>

Changes made to alias.c and apply.c in v1, requiring refactoring.

---
 alias.c | 12 +++++++++---
 apply.c | 19 +++++++++++++++----
 2 files changed, 24 insertions(+), 7 deletions(-)
alias.c +9 -3
index 00abde0817..61ef2c0c54 100644
@@ -44,9 +44,15 @@ void list_aliases(struct string_list *list)
 	read_early_config(config_alias_cb, &data);
 }
 
-#define SPLIT_CMDLINE_BAD_ENDING 1
-#define SPLIT_CMDLINE_UNCLOSED_QUOTE 2
-#define SPLIT_CMDLINE_ARGC_OVERFLOW 3
+/* #define SPLIT_CMDLINE_BAD_ENDING 1 */
+/* #define SPLIT_CMDLINE_UNCLOSED_QUOTE 2 */
+/* #define SPLIT_CMDLINE_ARGC_OVERFLOW 3 */
+enum split_cmdline_error {
+	SPLIT_CMDLINE_BAD_ENDING = 1,
+	SPLIT_CMDLINE_UNCLOSED_QUOTE,
+	SPLIT_CMDLINE_ARGC_OVERFLOW
+};
+
 static const char *split_cmdline_errors[] = {
 	N_("cmdline ends with \\"),
 	N_("unclosed quote"),
apply.c +15 -4
index 5eec433583..1e9cf2f4f2 100644
@@ -205,8 +205,13 @@ struct fragment {
  * or deflated "literal".
  */
 #define binary_patch_method leading
-#define BINARY_DELTA_DEFLATED	1
-#define BINARY_LITERAL_DEFLATED 2
+/* #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,8 +923,14 @@ 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
+
+/* #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,
Signature · 1 line
2.39.1
#2 lore raw

PATCH v2 2/3 {apply,alias}: convert pre-processor macros to enums

In reply to Vinayak Dev

Revert the changes made to alias.c in v1.

---
 alias.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
alias.c +3 -8
index 61ef2c0c54..deb871d59c 100644
@@ -44,14 +44,9 @@ void list_aliases(struct string_list *list)
 	read_early_config(config_alias_cb, &data);
 }
 
-/* #define SPLIT_CMDLINE_BAD_ENDING 1 */
-/* #define SPLIT_CMDLINE_UNCLOSED_QUOTE 2 */
-/* #define SPLIT_CMDLINE_ARGC_OVERFLOW 3 */
-enum split_cmdline_error {
-	SPLIT_CMDLINE_BAD_ENDING = 1,
-	SPLIT_CMDLINE_UNCLOSED_QUOTE,
-	SPLIT_CMDLINE_ARGC_OVERFLOW
-};
+#define SPLIT_CMDLINE_BAD_ENDING 1
+#define SPLIT_CMDLINE_UNCLOSED_QUOTE 2
+#define SPLIT_CMDLINE_ARGC_OVERFLOW 3
 
 static const char *split_cmdline_errors[] = {
 	N_("cmdline ends with \\"),
Signature · 1 line
2.39.1
#3 lore raw

PATCH v2 3/3 {apply,alias}: convert pre-processor macros to enums

In reply to Vinayak Dev

Change variables int side and int patch_method to enum in apply.c. This allows for proper listing of enum constants during debugging.

---
 apply.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)
apply.c +2 -8
index 1e9cf2f4f2..8612bd44c8 100644
@@ -205,9 +205,6 @@ 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
@@ -924,9 +921,6 @@ static int gitdiff_hdrend(struct gitdiff_data *state UNUSED,
  * to make sure..
  */
 
-/* #define DIFF_OLD_NAME 0 */
-/* #define DIFF_NEW_NAME 1 */
-
 enum diff_name {
 	DIFF_OLD_NAME = 0,
 	DIFF_NEW_NAME
@@ -936,7 +930,7 @@ 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);
@@ -1921,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;
Signature · 1 line
2.39.1
#4 lore raw
In reply to Vinayak Dev
Quoted 1 line · Vinayak Dev

Revert changes to alias.c, and change variable types in apply.c

When you send out a rerolled series, you do not have to show your past mistakes. This [v2] is structured as a three patch series whose first one makes a similar mess as what [v1] did, the second one and the third one then revert some parts of that earlier mess.

That is not what you want to show your reviewers, and more importantly, that is not what we want to record in our history. Rerolling a series is your chance to pretend that you are much better programmer than you who wrote the [v1] patch. The review exchange is to help you do that. Please take advantage of that.

You may find "git rebase -i" is a useful tool to help you pretend that you got to the ideal end result without these "I tried this first, which was wrong in these points, which I correct in a subsequent step" steps.

Thanks.

#5 lore raw
Quoted 16 lines · Junio C Hamano
Quoted 1 line · Vinayak Dev

Revert changes to alias.c, and change variable types in apply.c

When you send out a rerolled series, you do not have to show your past mistakes. This [v2] is structured as a three patch series whose first one makes a similar mess as what [v1] did, the second one and the third one then revert some parts of that earlier mess.

That is not what you want to show your reviewers, and more importantly, that is not what we want to record in our history. Rerolling a series is your chance to pretend that you are much better programmer than you who wrote the [v1] patch. The review exchange is to help you do that. Please take advantage of that.

Quoted 6 lines

You may find "git rebase -i" is a useful tool to help you pretend that you got to the ideal end result without these "I tried this first, which was wrong in these points, which I correct in a subsequent step" steps.

Thanks.

OK, I will keep that in mind before sending subsequent patches. Should I re-send [v2] after making corrections for this mistake? That would make the corrections more obvious and the mistakes less.

Thanks a lot!
Vinayak

#6 lore raw
Quoted 15 lines · Vinayak Dev
Quoted 14 lines · Junio C Hamano
Quoted 1 line · Vinayak Dev

Revert changes to alias.c, and change variable types in apply.c

When you send out a rerolled series, you do not have to show your past mistakes. This [v2] is structured as a three patch series whose first one makes a similar mess as what [v1] did, the second one and the third one then revert some parts of that earlier mess.

That is not what you want to show your reviewers, and more importantly, that is not what we want to record in our history. Rerolling a series is your chance to pretend that you are much better programmer than you who wrote the [v1] patch. The review exchange is to help you do that. Please take advantage of that.

Quoted 8 lines
Quoted 4 lines

You may find "git rebase -i" is a useful tool to help you pretend that you got to the ideal end result without these "I tried this first, which was wrong in these points, which I correct in a subsequent step" steps.

OK, I will keep that in mind before sending subsequent patches. Should I re-send [v2] after making corrections for this mistake? That would make the corrections more obvious and the mistakes less.

You should send a v3 which completely replaces v1 and v2.

To prepare v3, use the "squash" (or "fixup") command of git rebase -i to squash all three patches from v2 into a single patch, so that v3 consists of just one patch. The squashed patch should contain only changes to "apply.c"; specifically, changing #define to enum, and changing the variable declarations from int to enum.

You can also update the commit message of the squashed patch so that it explains the reason for the patch: specifically, the debugger will display the values symbolically rather than as mere numbers.

Finally, proofread the commit message and the patch itself, and resubmit as v3.

#7 lore raw
Quoted 14 lines · Eric Sunshine
Quoted 2 lines · Vinayak Dev

Should I re-send [v2] after making corrections for this mistake? That would make the corrections more obvious and the mistakes less.

You should send a v3 which completely replaces v1 and v2.

To prepare v3, use the "squash" (or "fixup") command of git rebase -i to squash all three patches from v2 into a single patch, so that v3 consists of just one patch. The squashed patch should contain only changes to "apply.c"; specifically, changing #define to enum, and changing the variable declarations from int to enum.

Quoted 5 lines

You can also update the commit message of the squashed patch so that it explains the reason for the patch: specifically, the debugger will display the values symbolically rather than as mere numbers.

Finally, proofread the commit message and the patch itself, and resubmit as v3.

Ok! I have absolutely understood your points. I will roll out v3 with appropriate
changes, as you suggest.

Thanks a lot!
Vinayak