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

Re: [PATCH] git tag --contains : avoid stack overflow

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Apr 17, 2014, 17:31 UTC
Message-ID
<alpine.DEB.1.00.1404171902010.14982@s15462909.onlinehome-server.info>
In-Reply-To
<20140416154653.GB4691@sigill.intra.peff.net>
Hi Peff,
On Wed, 16 Apr 2014, Jeff King wrote:
Show 31 quoted lines
> On Wed, Apr 16, 2014 at 04:15:19PM +0200, Stepan Kasal wrote:
> 
> > From: Jean-Jacques Lafay at Sat, 10 Nov 2012 18:36:10 +0100
> > 
> > In large repos, the recursion implementation of contains(commit,
> > commit_list) may result in a stack overflow. Replace the recursion
> > with a loop to fix it.
> > 
> > This problem is more apparent on Windows than on Linux, where the
> > stack is more limited by default.
> 
> I think this is a good thing to be doing, and it looks mostly good to
> me. A few comments:
> 
> > -static int contains_recurse(struct commit *candidate,
> > +/*
> > + * Test whether the candidate or one of its parents is contained in the list.
> > + * Do not recurse to find out, though, but return -1 if inconclusive.
> > + */
> > +static int contains_test(struct commit *candidate,
> >  			    const struct commit_list *want)
> 
> Can we turn this return value into
> 
>   enum {
> 	CONTAINS_UNKNOWN = -1,
> 	CONTAINS_NO = 0,
> 	CONTAINS_YES = 1,
>   } contains_result;
> 
> to make the code a little more self-documenting?
Good idea!
Show 21 quoted lines
> [... detailed instructions what changes are implied by the enum ...]
> 
> > +>expect
> > +# ulimit is a bash builtin; we can rely on that in MinGW, but nowhere else
> > +test_expect_success MINGW '--contains works in a deep repo' '
> > +	ulimit -s 64
> 
> It would be nice to test this on Linux.
> 
> Can we do something like:
> 
>   test_lazy_prereq BASH 'bash --version'
> 
>   test_expect_success BASH '--contains works in a deep repo' '
> 	... setup repo ...
> 	bash -c "ulimit -s 64 && git tag --contains HEAD" >actual &&
> 	test_cmp expect actual
>   '
> 
> As a bonus, then our "ulimit" call does not pollute the environment of
> subsequent tests.

That's a very good idea! We mulled it over a bit and did not come up with this excellent solution.

Please see https://github.com/msysgit/git/c63d196 for the fixup, and https://github.com/msysgit/git/compare/tag-contains%5E...tag-contains for the updated patch.

Thanks, Dscho

Previous: Jeff KingNext: Jeff King
Message 3 of 24 in “git tag --contains : avoid stack overflow”
  1. git tag --contains : avoid stack overflowStepan Kasal, Apr 16, 2014
  2. Jeff KingApr 16, 2014
  3. Johannes SchindelinApr 17, 2014
  4. Jeff KingApr 17, 2014
  5. Johannes SchindelinApr 17, 2014
  6. Jeff KingApr 17, 2014
  7. git tag --contains : avoid stack overflowStepan Kasal, Apr 23, 2014
  8. Johannes SchindelinApr 23, 2014
  9. Stepan KasalApr 23, 2014
  10. Junio C HamanoApr 23, 2014
  11. Jeff KingApr 23, 2014
  12. Junio C HamanoApr 23, 2014
  13. Jeff KingApr 23, 2014
  14. Junio C HamanoApr 23, 2014
  15. Stepan KasalApr 24, 2014
  16. Stepan KasalApr 24, 2014
  17. Jeff KingApr 25, 2014
  18. Andreas SchwabSep 20, 2014
  19. Jeff KingSep 23, 2014
  20. Andreas SchwabSep 23, 2014
  21. Junio C HamanoSep 23, 2014
  22. Stepan KasalApr 23, 2014
  23. Jeff KingApr 23, 2014
  24. Johannes SchindelinApr 23, 2014

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.