git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] revision.c: Remove unneeded check for NULL
@ 2015-06-26 19:40 Stefan Beller
  2015-06-27  6:07 ` Jeff King
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Beller @ 2015-06-26 19:40 UTC (permalink / raw)
  To: gitster; +Cc: git, jrnieder, peff, Stefan Beller

The function is called only from one place, which makes sure
to have `interesting_cache` not NULL. Additionally it is a
dereferenced a few lines before unconditionally, which would
result in a segmentation fault.

Signed-off-by: Stefan Beller <sbeller@google.com>
---

Notes:
    > So I think the right solution is just to drop the conditional entirely.
    > The current code is not wrong (it is always a noop). What you have here
    > actually misbehaves; it does not update the cache slot when it has
    > become UNINTERESTING. That does not produce wrong results, but it loses
    > the benefit of the cache in some cases.
    
    After reading the code a bit more, I agree.
    
    > I'm having trouble parsing this sentence.  Do you mean that limit_list()
    > only calls still_interesting() (and thus, indirectly,
    > everybody_uninteresting()), with the second parameter equal to the
    > address of the local interesting_cache variable, so it can never be
    > NULL?
    
    I completely reworded the commit message.
    
    > Should there be
    >
    >        if (!interesting_cache)
    >                die("BUG: &interesting_cache == NULL");
    >
    > checks at the top of still_interesting and everybody_uninteresting to
    > futureproof this?
    
    I don't think this is necessary as these functions are local functions
    so when somebody wants to use them they will be aware of the limitations.
    
    > This code seems to be underdocumented.
    
    I am not a expert in this area of the code, so I hoped Peff
    would document it if he feels like so.

 revision.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/revision.c b/revision.c
index 3ff8723..ab97ffd 100644
--- a/revision.c
+++ b/revision.c
@@ -361,8 +361,8 @@ static int everybody_uninteresting(struct commit_list *orig,
 		list = list->next;
 		if (commit->object.flags & UNINTERESTING)
 			continue;
-		if (interesting_cache)
-			*interesting_cache = commit;
+
+		*interesting_cache = commit;
 		return 0;
 	}
 	return 1;
-- 
2.4.1.345.gab207b6.dirty

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-06-30 22:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-26 19:40 [PATCH] revision.c: Remove unneeded check for NULL Stefan Beller
2015-06-27  6:07 ` Jeff King
2015-06-30 22:48   ` Jonathan Nieder

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 NNTP newsgroup(s).