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

[PATCH 2/4] trailer: simplify check_if_different

From
Paolo Bonzini <pbonzini@redhat.com>
Date
Oct 5, 2017, 13:22 UTC
Message-ID
<20171005132243.27058-3-pbonzini@redhat.com>
In-Reply-To
<20171005132243.27058-1-pbonzini@redhat.com>

The check_all argument is pointless, because the function degenerates to !same_trailer when check_all==0 (if same_trailer fails, it always ends up returning 1). Remove it, switching the check_all==0 caller to use same_trailer directly.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 trailer.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/trailer.c b/trailer.c
index 4ba28ae33..91f89db7f 100644
--- a/trailer.c
+++ b/trailer.c
@@ -194,14 +194,11 @@ static void add_arg_to_input_list(struct trailer_item *on_tok,
 
 static int check_if_different(struct trailer_item *in_tok,
 			      struct arg_item *arg_tok,
-			      int check_all,
 			      struct list_head *head)
 {
 	enum trailer_where where = arg_tok->conf.where;
 	struct list_head *next_head;
-	do {
-		if (same_trailer(in_tok, arg_tok))
-			return 0;
+	while (!same_trailer(in_tok, arg_tok)) {
 		/*
 		 * if we want to add a trailer after another one,
 		 * we have to check those before this one
@@ -209,10 +206,10 @@ static int check_if_different(struct trailer_item *in_tok,
 		next_head = after_or_end(where) ? in_tok->list.prev
 						: in_tok->list.next;
 		if (next_head == head)
-			break;
+			return 1;
 		in_tok = list_entry(next_head, struct trailer_item, list);
-	} while (check_all);
-	return 1;
+	}
+	return 0;
 }
 
 static char *apply_command(const char *command, const char *arg)
@@ -283,12 +280,12 @@ static void apply_arg_if_exists(struct trailer_item *in_tok,
 		break;
 	case EXISTS_ADD_IF_DIFFERENT:
 		apply_item_command(in_tok, arg_tok);
-		if (check_if_different(in_tok, arg_tok, 1, head))
+		if (check_if_different(in_tok, arg_tok, head))
 			add_arg_to_input_list(on_tok, arg_tok);
 		break;
 	case EXISTS_ADD_IF_DIFFERENT_NEIGHBOR:
 		apply_item_command(in_tok, arg_tok);
-		if (check_if_different(on_tok, arg_tok, 0, head))
+		if (!same_trailer(on_tok, arg_tok))
 			add_arg_to_input_list(on_tok, arg_tok);
 		break;
 	default:
-- 
2.14.2
Previous: Paolo BonziniNext: Junio C Hamano
Message 5 of 14 in “interpret-trailers: introduce "move" action”
  1. 0/4 interpret-trailers: introduce "move" actionPaolo Bonzini, Oct 5, 2017
  2. 3/4 trailer: create a new function to handle adding trailersPaolo Bonzini, Oct 5, 2017
  3. 4/4 trailer: add "move" configuration for trailer.ifExistsPaolo Bonzini, Oct 5, 2017
  4. 1/4 trailer: push free_arg_item upPaolo Bonzini, Oct 5, 2017
  5. 2/4 trailer: simplify check_if_differentPaolo Bonzini, Oct 5, 2017
  6. Junio C HamanoOct 6, 2017
  7. Paolo BonziniOct 6, 2017
  8. Christian CouderOct 6, 2017
  9. Paolo BonziniOct 6, 2017
  10. Christian CouderOct 6, 2017
  11. Paolo BonziniOct 6, 2017
  12. Christian CouderOct 6, 2017
  13. Paolo BonziniOct 6, 2017
  14. Junio C HamanoOct 7, 2017

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.