All of lore.kernel.org
 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

* Re: [PATCH] revision.c: Remove unneeded check for NULL
  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
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff King @ 2015-06-27  6:07 UTC (permalink / raw)
  To: Stefan Beller; +Cc: gitster, git, jrnieder

On Fri, Jun 26, 2015 at 12:40:19PM -0700, Stefan Beller wrote:

> 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.

Yeah, I think this is the right thing to do.

Acked-by: Jeff King <peff@peff.net>

>     > 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.

Agreed. We do not assert non-NULL for every parameter in our functions,
and I do not think this is any more special than the others.

>     > 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.

I kind of thought that the explanation in b6e8a3b covered this code.
Does it not, or did people not read it?

The whole of revision.c is not well documented by comments, but I don't
think that is a new thing.

-Peff

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

* Re: [PATCH] revision.c: Remove unneeded check for NULL
  2015-06-27  6:07 ` Jeff King
@ 2015-06-30 22:48   ` Jonathan Nieder
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Nieder @ 2015-06-30 22:48 UTC (permalink / raw)
  To: Jeff King; +Cc: Stefan Beller, gitster, git

Jeff King wrote:
> On Fri, Jun 26, 2015 at 12:40:19PM -0700, Stefan Beller wrote:

>>> 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.
>
> I kind of thought that the explanation in b6e8a3b covered this code.
> Does it not, or did people not read it?

I know that "tl;dr" is the last thing anyone who has written a clear
description of something wants to read, but I fear it applies here.  I
tried to skim that commit message to get a gist of what the
still_interesting variable is supposed to hold and I failed.

I think part of the problem was that that commit message doesn't give
a specific example early on to motivate the problem and fix[*].

More to the point, someone interested in that specific variable
doesn't need to necessarily understand the optimization that motivated
it.  Instead, they'd want to know what invariants to expect and
preserve: what value does it start with, what does its value mean, are
there some forbidden values, etc.

Is the idea that it represents a commit from the queue which is still
interesting, and that it saves us from looping through the queue to
find a still-interesting commit as long as mark_parents_uninteresting
has not marked this one uninteresting yet?  What does it mean when it
is NULL?

Thanks,
Jonathan

[*] I.e., what command do I run to get quadratic behavior?

The message starts with a diagnosis --- "When we are limiting a
rev-list traversal due to UNINTERESTING refs, we have to walk down the
tips" --- without introducing what problem is being diganosed.

The problem being solved might have been something like "When we call
'git rev-list $commits --not --all' in check_everything_connected
after a fetch, if we fetched something much older than most of our
refs, and if we have a large number of refs, the operation is slow ---
quadratic in the number of refs.  This hasn't been a problem in the
past because people did not use so many refs, but now as the number of
refs in a typical repository grows, it is becoming more noticeable."
Even after re-reading the message more carefully, I'm not sure.  I
assume there was a report motivating the change, which might have been
useful for putting the explanation in context for the reader.
Alas, git://repo.or.cz/git/trast.git branch notes/gmane doesn't have any
annotations for that commit to find the context.

The commit message then goes on to explain how the patch solves that
problem, but without an example to put that explanation in context, it
is hard to follow.  What linear search is the explanation talking
about?  What is the interesting commit we find?  I couldn't tell without
looking at the code.

^ permalink raw reply	[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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.