examples/log.c: invert filtering impl and conditional
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
diff --git a/examples/log.c b/examples/log.c
index 965f854..d5f75a2 100644
--- a/examples/log.c
+++ b/examples/log.c
@@ -67,8 +67,8 @@ static void print_commit(git_commit *commit);
static int match_with_parent(git_commit *commit, int i, git_diff_options *);
/** utility functions for filtering */
-static int signature_does_not_match(const git_signature *sig, const char *filter);
-static int log_message_does_not_match(const git_commit *commit, const char *filter);
+static int signature_matches(const git_signature *sig, const char *filter);
+static int log_message_matches(const git_commit *commit, const char *filter);
int main(int argc, char *argv[])
{
@@ -132,13 +132,13 @@ int main(int argc, char *argv[])
continue;
}
- if (signature_does_not_match(git_commit_author(commit), opt.author))
+ if (!signature_matches(git_commit_author(commit), opt.author))
continue;
- if (signature_does_not_match(git_commit_committer(commit), opt.committer))
+ if (!signature_matches(git_commit_committer(commit), opt.committer))
continue;
- if (log_message_does_not_match(commit, opt.grep))
+ if (!log_message_matches(commit, opt.grep))
continue;
if (count++ < opt.skip)
@@ -186,26 +186,26 @@ int main(int argc, char *argv[])
}
/** Determine if the given git_signature does not contain the filter text. */
-static int signature_does_not_match(const git_signature *sig, const char *filter) {
+static int signature_matches(const git_signature *sig, const char *filter) {
if (filter == NULL)
- return 0;
+ return 1;
- if (sig == NULL ||
- (strstr(sig->name, filter) == NULL &&
- strstr(sig->email, filter) == NULL))
+ if (sig != NULL &&
+ (strstr(sig->name, filter) != NULL ||
+ strstr(sig->email, filter) != NULL))
return 1;
return 0;
}
-static int log_message_does_not_match(const git_commit *commit, const char *filter) {
+static int log_message_matches(const git_commit *commit, const char *filter) {
const char *message = NULL;
if (filter == NULL)
- return 0;
+ return 1;
- if ((message = git_commit_message(commit)) == NULL ||
- strstr(message, filter) == NULL)
+ if ((message = git_commit_message(commit)) != NULL &&
+ strstr(message, filter) != NULL)
return 1;
return 0;