git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [External] Re: [PATCH v1] negotiator/default.c: avoid stack overflow

From
Derrick Stolee <derrickstolee@github.com>
Date
Apr 25, 2023, 13:34 UTC
Message-ID
<4ddb4030-0789-5ed4-448d-96f6afb48334@github.com>
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:
Show 36 quoted lines
>>> @@ -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.
 
Show 9 quoted lines
> 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.

Show 9 quoted lines
> 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

Previous: Han XinNext: Han Xin
Message 4 of 20 in “negotiator/default.c: avoid stack overflow”
  1. negotiator/default.c: avoid stack overflowHan Xin, Apr 24, 2023
  2. Derrick StoleeApr 24, 2023
  3. Han XinApr 25, 2023
  4. Derrick StoleeApr 25, 2023
  5. 0/2 negotiator/default: avoid stack overflowHan Xin, Apr 26, 2023
  6. 2/2 negotiator/skipping: fix some problems in mark_common()Han Xin, Apr 26, 2023
  7. Derrick StoleeApr 26, 2023
  8. Han XinApr 26, 2023
  9. 1/2 negotiator/default: avoid stack overflowHan Xin, Apr 26, 2023
  10. Derrick StoleeApr 26, 2023
  11. Han XinApr 26, 2023
  12. 0/2 negotiator/default: avoid stack overflowHan Xin, Apr 26, 2023
  13. 1/2 negotiator/default: avoid stack overflowHan Xin, Apr 26, 2023
  14. Junio C HamanoApr 26, 2023
  15. Derrick StoleeApr 26, 2023
  16. Junio C HamanoApr 26, 2023
  17. 2/2 negotiator/skipping: fix some problems in mark_common()Han Xin, Apr 26, 2023
  18. Junio C HamanoMay 1, 2023
  19. Derrick StoleeMay 2, 2023
  20. Junio C HamanoMay 2, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.