[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; }