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

[PATCH] Factor out filtering in rev-list.c

From
jon@blackcubes.dyndns.org <jon@blackcubes.dyndns.org>
Date
Jun 6, 2005, 07:05 UTC
Message-ID
<20050606071728.30223.qmail@blackcubes.dyndns.org>
[PATCH] Factor out filtering in rev-list.c
This patch:
   * factors out the filtering logic in show_commit_list into filter_commit.
   * groups calls to filter_commit and show_commit into process_commit.
   * replaces the body of the show_commit_list while loop with a call to process_commit.
   * fixes a compiler warning by adding a return statement to get_commit_format.

The purpose of these changes is to faciliate a future merge with Jon Seymour's --merge-order patch which will pass pointer to process_commit to another module.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
This patch can also be downloaded from: http://blackcubes.dyndns.org/epoch/rev-list.patch .

Diverged from 000182eacf99cde27d5916aa415921924b82972c by Linus Torvalds <torvalds@ppc970.osdl.org> ---

diff --git a/rev-list.c b/rev-list.c
--- a/rev-list.c
+++ b/rev-list.c
@@ -40,20 +40,48 @@ static void show_commit(struct commit *c
 	}
 }
 
+#define STOP     0
+#define CONTINUE 1
+#define DO       2
+
+static int filter_commit(struct commit * commit)
+{
+	if (commit->object.flags & UNINTERESTING)
+		return CONTINUE;
+	if (min_age != -1 && (commit->date > min_age))
+		return CONTINUE;
+	if (max_age != -1 && (commit->date < max_age))
+		return STOP;
+	if (max_count != -1 && !max_count--)
+		return STOP;
+
+	return DO;
+}
+
+static int process_commit(struct commit * commit)
+{
+	int action=filter_commit(commit);
+
+	if (action == STOP) {
+		return STOP;
+	}
+
+	if (action == CONTINUE) {
+		return CONTINUE;
+	}
+
+	show_commit(commit);
+
+	return CONTINUE;
+}
+
 static void show_commit_list(struct commit_list *list)
 {
 	while (list) {
 		struct commit *commit = pop_most_recent_commit(&list, SEEN);
 
-		if (commit->object.flags & UNINTERESTING)
-			continue;
-		if (min_age != -1 && (commit->date > min_age))
-			continue;
-		if (max_age != -1 && (commit->date < max_age))
+		if (process_commit(commit) == STOP)
 			break;
-		if (max_count != -1 && !max_count--)
-			break;
-		show_commit(commit);
 	}
 }
 
@@ -110,6 +138,8 @@ static enum cmit_fmt get_commit_format(c
 	if (!strcmp(arg, "=short"))
 		return CMIT_FMT_SHORT;
 	usage(rev_list_usage);	
+
+	return CMIT_FMT_DEFAULT;
 }			
 
 
Message 1 of 1 in “Factor out filtering in rev-list.c”
  1. Factor out filtering in rev-list.cjon@blackcubes.dyndns.org, Jun 6, 2005

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.