From: Derrick Stolee <derrickstolee@github.com>
To: Han Xin <hanxin.hx@bytedance.com>
Cc: git@vger.kernel.org, xingxin.xx@bytedance.com,
jonathantanmy@google.com, Junio C Hamano <gitster@pobox.com>
Subject: Re: [External] Re: [PATCH v1] negotiator/default.c: avoid stack overflow
Date: Tue, 25 Apr 2023 09:34:38 -0400 [thread overview]
Message-ID: <4ddb4030-0789-5ed4-448d-96f6afb48334@github.com> (raw)
In-Reply-To: <CAKgqsWUEnbmhLL3p9+_P4yH_=A+hz+bBPqmfb8FyRUeW-u7_gw@mail.gmail.com>
On 4/24/2023 11:02 PM, Han Xin wrote:
> On Mon, Apr 24, 2023 at 10:44 PM Derrick Stolee
> <derrickstolee@github.com> wrote:
>>> @@ -70,15 +76,17 @@ static void mark_common(struct negotiation_state *ns, struct commit *commit,
>>> ns->non_common_revs--;
>>> if (!o->parsed && !dont_parse)
>>> if (repo_parse_commit(the_repository, commit))
>>> - return;
>>> + continue;
>>>
>>> + ancestors_only = 0;
>>
>> This caught me off guard, but this flag essentially says "should
>> I mark the first commit as common or not?". It would probably be
>> clearer if this was done before the loop, and then was ignored
>> within the loop, setting the flag on each parent in this loop:
>>
>>> for (parents = commit->parents;
>>> parents;
>>> parents = parents->next)
>>> - mark_common(ns, parents->item, 0,
>>> - dont_parse);
>>> + prio_queue_put(&queue, parents->item);
>>
>
> I'll think about how to optimize this again.
>
> ancestors_only is used multiple times in the original logic:
> 1.
> if (!ancestors_only)
> o->flags |= COMMON;
> 2.
> if (!(o->flags & SEEN))
> rev_list_push(ns, commit, SEEN);
> else {
> struct commit_list *parents;
>
> if (!ancestors_only && !(o->flags & POPPED))
> ns->non_common_revs--;
Good point. Thanks for checking.
> Should we use this ?
>
> if (!ancestors_only) {
> commit->object.flags |= COMMON;
>
> if ((commit->object.flags & SEEN) &&
> !(commit->object.flags & POPPED))
> ns->non_common_revs--;
> }
This seems correct, although your email seems to have done a strange
line wrap that I'm sure you'll fix in the actual patch.
> and
>
> for (parents = commit->parents;
> parents;
> parents = parents->next) {
> if (parents->item->object.flags & COMMON)
> continue;
>
> parents->item->object.flags |= COMMON;
Thanks, this part avoids duplicate additions to the queue.
> if ((parents->item->object.flags & SEEN)
> && !(parents->item->object.flags & POPPED))
> ns->non_common_revs--;
And this matches the non_common_revs part.
If you want this code to be a little cleaner, you could add
struct commit *p = parents->item;
at the start of the loop and then s/parents->item/p/ for the rest
of the uses in the loop.
> prio_queue_put(&queue, parents->item);
> }
>> In addition, the mark_common() method there seems to have a few
>> problems:
...
>> Consider fixing these issues while you are here.
>>
>
> Make sense.
I'm looking forward to your v2!
Thanks,
-Stolee
next prev parent reply other threads:[~2023-04-25 13:35 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-24 2:23 [PATCH v1] negotiator/default.c: avoid stack overflow Han Xin
2023-04-24 14:44 ` Derrick Stolee
2023-04-25 3:02 ` [External] " Han Xin
2023-04-25 13:34 ` Derrick Stolee [this message]
2023-04-26 4:05 ` [PATCH v2 0/2] negotiator/default: " Han Xin
2023-04-26 4:05 ` [PATCH v2 1/2] " Han Xin
2023-04-26 11:13 ` Derrick Stolee
2023-04-26 11:40 ` [External] " Han Xin
2023-04-26 4:05 ` [PATCH v2 2/2] negotiator/skipping: fix some problems in mark_common() Han Xin
2023-04-26 11:08 ` Derrick Stolee
2023-04-26 11:55 ` [External] " Han Xin
2023-04-26 13:15 ` [PATCH v2 0/2] negotiator/default: avoid stack overflow Han Xin
2023-04-26 13:15 ` [PATCH v3 1/2] " Han Xin
2023-04-26 17:14 ` Junio C Hamano
2023-04-26 17:30 ` Derrick Stolee
2023-04-26 17:38 ` Junio C Hamano
2023-04-26 13:15 ` [PATCH v3 2/2] negotiator/skipping: fix some problems in mark_common() Han Xin
2023-05-01 22:11 ` [PATCH v2 0/2] negotiator/default: avoid stack overflow Junio C Hamano
2023-05-02 1:49 ` Derrick Stolee
2023-05-02 15:51 ` Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4ddb4030-0789-5ed4-448d-96f6afb48334@github.com \
--to=derrickstolee@github.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hanxin.hx@bytedance.com \
--cc=jonathantanmy@google.com \
--cc=xingxin.xx@bytedance.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.
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).