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

[Outreachy] [PATCH] blame: Convert pickaxe_blame defined constants to enums

From
WKWambui Karuga <wambui.karugax@gmail.com>
Date
Oct 10, 2019, 11:52 UTC
Message-ID
<20191010115230.10623-1-wambui.karugax@gmail.com>

Convert pickaxe_blame preprocessor constants in blame.h to an enum. Also replace previous instances of the constants with the new enum values.

Signed-off-by: Wambui Karuga <wambui.karugax@gmail.com>
---
 blame.c         |  8 ++++----
 blame.h         | 12 +++++++-----
 builtin/blame.c | 17 ++++++++---------
 3 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/blame.c b/blame.c
index 36a2e7ef11..4ad86d1217 100644
--- a/blame.c
+++ b/blame.c
@@ -2183,8 +2183,8 @@ static void find_copy_in_parent(struct blame_scoreboard *sb,
 	 * and this code needs to be after diff_setup_done(), which
 	 * usually makes find-copies-harder imply copy detection.
 	 */
-	if ((opt & PICKAXE_BLAME_COPY_HARDEST)
-	    || ((opt & PICKAXE_BLAME_COPY_HARDER)
+	if ((opt & BLAME_COPY_HARDEST)
+	    || ((opt & BLAME_COPY_HARDER)
 		&& (!porigin || strcmp(target->path, porigin->path))))
 		diff_opts.flags.find_copies_harder = 1;
 
@@ -2429,7 +2429,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
 	/*
 	 * Optionally find moves in parents' files.
 	 */
-	if (opt & PICKAXE_BLAME_MOVE) {
+	if (opt & BLAME_MOVE) {
 		filter_small(sb, &toosmall, &origin->suspects, sb->move_score);
 		if (origin->suspects) {
 			for (i = 0, sg = first_scapegoat(revs, commit, sb->reverse);
@@ -2448,7 +2448,7 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
 	/*
 	 * Optionally find copies from parents' files.
 	 */
-	if (opt & PICKAXE_BLAME_COPY) {
+	if (opt & BLAME_COPY) {
 		if (sb->copy_score > sb->move_score)
 			filter_small(sb, &toosmall, &origin->suspects, sb->copy_score);
 		else if (sb->copy_score < sb->move_score) {
diff --git a/blame.h b/blame.h
index 4a9e1270b0..a4bbf3a8c5 100644
--- a/blame.h
+++ b/blame.h
@@ -8,14 +8,16 @@
 #include "prio-queue.h"
 #include "diff.h"
 
-#define PICKAXE_BLAME_MOVE		01
-#define PICKAXE_BLAME_COPY		02
-#define PICKAXE_BLAME_COPY_HARDER	04
-#define PICKAXE_BLAME_COPY_HARDEST	010
-
 #define BLAME_DEFAULT_MOVE_SCORE	20
 #define BLAME_DEFAULT_COPY_SCORE	40
 
+enum pickaxe_blame_action {
+	BLAME_MOVE = 01,
+	BLAME_COPY,
+	BLAME_COPY_HARDER = 04,
+	BLAME_COPY_HARDEST = 010,
+};
+
 /*
  * One blob in a commit that is being suspected
  */
diff --git a/builtin/blame.c b/builtin/blame.c
index b6534d4dea..fb71517b5c 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -771,11 +771,11 @@ static int blame_copy_callback(const struct option *option, const char *arg, int
 	 * -C -C -C enables copy from existing files for
 	 *          everybody
 	 */
-	if (*opt & PICKAXE_BLAME_COPY_HARDER)
-		*opt |= PICKAXE_BLAME_COPY_HARDEST;
-	if (*opt & PICKAXE_BLAME_COPY)
-		*opt |= PICKAXE_BLAME_COPY_HARDER;
-	*opt |= PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE;
+	if (*opt & BLAME_COPY_HARDER)
+		*opt |= BLAME_COPY_HARDEST;
+	if (*opt & BLAME_COPY)
+		*opt |= BLAME_COPY_HARDER;
+	*opt |= BLAME_COPY | BLAME_MOVE;
 
 	if (arg)
 		blame_copy_score = parse_score(arg);
@@ -788,8 +788,7 @@ static int blame_move_callback(const struct option *option, const char *arg, int
 
 	BUG_ON_OPT_NEG(unset);
 
-	*opt |= PICKAXE_BLAME_MOVE;
-
+	*opt |= BLAME_MOVE;
 	if (arg)
 		blame_move_score = parse_score(arg);
 	return 0;
@@ -993,8 +992,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 	blame_date_width -= 1; /* strip the null */
 
 	if (revs.diffopt.flags.find_copies_harder)
-		opt |= (PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE |
-			PICKAXE_BLAME_COPY_HARDER);
+		opt |= (BLAME_COPY | BLAME_MOVE |
+			BLAME_COPY_HARDER);
 
 	/*
 	 * We have collected options unknown to us in argv[1..unk]
-- 
2.23.0
Next: Jonathan Tan
Message 1 of 13 in “blame: Convert pickaxe_blame defined constants to enums”
  1. Wambui KarugaOct 10, 2019
  2. Jonathan TanOct 10, 2019
  3. Junio C HamanoOct 11, 2019
  4. Jonathan TanOct 11, 2019
  5. Junio C HamanoOct 12, 2019
  6. Jonathan TanOct 14, 2019
  7. Wambui KarugaOct 14, 2019
  8. Jonathan TanOct 14, 2019
  9. Wambui KarugaOct 15, 2019
  10. SZEDER GáborOct 15, 2019
  11. Wambui KarugaOct 11, 2019
  12. Jonathan TanOct 11, 2019
  13. Wambui KarugaOct 11, 2019

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.