From: Jeff King <peff@peff.net>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>,
Junio C Hamano <gitster@pobox.com>,
Lars Hjemli <hjemli@gmail.com>,
Christian Couder <christian.couder@gmail.com>
Subject: [PATCH 2/4] ref-filter: use contains_result enum consistently
Date: Thu, 9 Mar 2017 08:28:48 -0500 [thread overview]
Message-ID: <20170309132847.ptysbio377cy765j@sigill.intra.peff.net> (raw)
In-Reply-To: <20170309132728.c57ltzel746l366a@sigill.intra.peff.net>
Commit cbc60b672 (git tag --contains: avoid stack overflow,
2014-04-24) adapted the -1/0/1 contains status into a
tri-state enum. However, some of the code still used the
numeric values, or assumed that no/yes correspond to C's
boolean true/false.
Let's switch to using the symbolic values everywhere, which
will make it easier to change them.
Signed-off-by: Jeff King <peff@peff.net>
---
ref-filter.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/ref-filter.c b/ref-filter.c
index 6546dba73..631978a4f 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1513,20 +1513,20 @@ static enum contains_result contains_test(struct commit *candidate,
{
/* was it previously marked as containing a want commit? */
if (candidate->object.flags & TMP_MARK)
- return 1;
+ return CONTAINS_YES;
/* or marked as not possibly containing a want commit? */
if (candidate->object.flags & UNINTERESTING)
- return 0;
+ return CONTAINS_NO;
/* or are we it? */
if (in_commit_list(want, candidate)) {
candidate->object.flags |= TMP_MARK;
- return 1;
+ return CONTAINS_YES;
}
if (parse_commit(candidate) < 0)
- return 0;
+ return CONTAINS_NO;
- return -1;
+ return CONTAINS_UNKNOWN;
}
static void push_to_contains_stack(struct commit *candidate, struct contains_stack *contains_stack)
@@ -1540,7 +1540,7 @@ static enum contains_result contains_tag_algo(struct commit *candidate,
const struct commit_list *want)
{
struct contains_stack contains_stack = { 0, 0, NULL };
- int result = contains_test(candidate, want);
+ enum contains_result result = contains_test(candidate, want);
if (result != CONTAINS_UNKNOWN)
return result;
@@ -1557,7 +1557,7 @@ static enum contains_result contains_tag_algo(struct commit *candidate,
}
/*
* If we just popped the stack, parents->item has been marked,
- * therefore contains_test will return a meaningful 0 or 1.
+ * therefore contains_test will return a meaningful yes/no.
*/
else switch (contains_test(parents->item, want)) {
case CONTAINS_YES:
@@ -1579,7 +1579,7 @@ static enum contains_result contains_tag_algo(struct commit *candidate,
static int commit_contains(struct ref_filter *filter, struct commit *commit)
{
if (filter->with_commit_tag_algo)
- return contains_tag_algo(commit, filter->with_commit);
+ return contains_tag_algo(commit, filter->with_commit) == CONTAINS_YES;
return is_descendant_of(commit, filter->with_commit);
}
--
2.12.0.445.g818af77e0
next prev parent reply other threads:[~2017-03-09 13:28 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-08 20:20 [PATCH] branch & tag: Add a --no-contains option Ævar Arnfjörð Bjarmason
2017-03-08 23:02 ` Junio C Hamano
2017-03-09 10:09 ` Jeff King
2017-03-09 10:41 ` Ævar Arnfjörð Bjarmason
2017-03-09 10:46 ` Jeff King
2017-03-09 12:12 ` Ævar Arnfjörð Bjarmason
2017-03-09 12:51 ` Jeff King
2017-03-09 13:27 ` [PATCH 0/4] fix object flag pollution in "tag --contains" Jeff King
2017-03-09 13:27 ` [PATCH 1/4] ref-filter: move ref_cbdata definition into ref-filter.c Jeff King
2017-03-09 13:28 ` Jeff King [this message]
2017-03-09 13:29 ` [PATCH 3/4] ref-filter: die on parse_commit errors Jeff King
2017-03-09 13:29 ` [PATCH 4/4] ref-filter: use separate cache for contains_tag_algo Jeff King
2017-03-11 20:01 ` Ævar Arnfjörð Bjarmason
2017-03-11 20:21 ` Ævar Arnfjörð Bjarmason
2017-03-12 11:12 ` Jeff King
2017-03-11 13:06 ` [PATCH 0/4] fix object flag pollution in "tag --contains" Ævar Arnfjörð Bjarmason
2017-03-11 20:18 ` [PATCH v4] ref-filter: Add --no-contains option to tag/branch/for-each-ref Ævar Arnfjörð Bjarmason
2017-03-12 4:44 ` Junio C Hamano
2017-03-12 9:10 ` Ævar Arnfjörð Bjarmason
2017-03-12 17:49 ` Junio C Hamano
2017-03-09 14:52 ` [PATCH] branch & tag: Add a --no-contains option Ævar Arnfjörð Bjarmason
2017-03-09 14:55 ` Jeff King
2017-03-10 11:31 ` Ævar Arnfjörð Bjarmason
2017-03-09 20:02 ` [PATCH v2] ref-filter: Add --no-contains option to tag/branch/for-each-ref Ævar Arnfjörð Bjarmason
2017-03-09 20:31 ` Christian Couder
2017-03-10 11:46 ` Ævar Arnfjörð Bjarmason
2017-03-10 12:09 ` Ævar Arnfjörð Bjarmason
2017-03-10 20:33 ` [PATCH v3] " Ævar Arnfjörð Bjarmason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170309132847.ptysbio377cy765j@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=avarab@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hjemli@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).