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

Re: [PATCH 2/3] commit: add function to unparse a commit and its parents

From
Christian Couder <chriscool@tuxfamily.org>
Date
May 27, 2009, 05:12 UTC
Message-ID
<200905270712.36866.chriscool@tuxfamily.org>
In-Reply-To
<alpine.DEB.1.00.0905251140320.4288@intel-tinevez-2-302>
Hi,
Le Monday 25 May 2009, Johannes Schindelin a écrit :
Show 47 quoted lines
> Hi,
>
> On Mon, 25 May 2009, Johannes Sixt wrote:
> > Christian Couder schrieb:
> > > +static void unparse_commit_list(struct commit_list *list)
> > > +{
> > > +	for (; list; list = list->next)
> > > +		unparse_commit(list->item);
> > > +}
> > > +
> > > +void unparse_commit(struct commit *item)
> > > +{
> > > +	item->object.flags = 0;
> > > +	item->object.used = 0;
> > > +	if (item->object.parsed) {
> > > +		item->object.parsed = 0;
> > > +		if (item->parents) {
> > > +			unparse_commit_list(item->parents);
> > > +			free_commit_list(item->parents);
> > > +			item->parents = NULL;
> > > +		}
> > > +	}
> > > +}
> >
> > I see a recursion here. Could this not overflow the stack if there is a
> > long ancestry chain?
>
> You mean tail recursion, i.e. something like
>
> void unparse_commit(struct commit *item)
> {
> 	item->object.flags = 0;
> 	item->object.used = 0;
> 	while (item->object.parsed) {
> 		struct commit *first;
>
> 		item->object.parsed = 0;
> 		if (!item->parents)
> 			break;
> 		if (item->parents->next)
> 			unparse_commit_list(item->parents->next);
> 		first = item->parents->item;
> 		free_commit_list(item->parents);
> 		item->parents = NULL;
> 		item = first;
> 	}
> }
Yes, it is better like this. Thanks and sorry about responding late.
> However, I am a bit concerned that this function is dangerous, as it just
> assumes that there is no reference to the commits left, which assumption
> is _very_ easy to break by mistake.

Anyway I will send a 2 patch series that will use clear_commit_marks instead of this function.

Thanks, Christian.

Previous: Johannes SchindelinNext: Christian Couder
Message 12 of 13 in “bisect: rework some rev related functions to make them more reusable”
  1. 1/3 bisect: rework some rev related functions to make them more reusableChristian Couder, May 17, 2009
  2. 2/3 commit: add function to unparse a commit and its parentsChristian Couder, May 17, 2009
  3. Junio C HamanoMay 18, 2009
  4. Christian CouderMay 19, 2009
  5. Junio C HamanoMay 19, 2009
  6. Jakub NarebskiMay 19, 2009
  7. Miles BaderMay 19, 2009
  8. Junio C HamanoMay 19, 2009
  9. Jakub NarebskiMay 19, 2009
  10. Johannes SixtMay 25, 2009
  11. Johannes SchindelinMay 25, 2009
  12. Christian CouderMay 27, 2009
  13. 3/3 bisect: check ancestors without forking a "git rev-list" processChristian Couder, May 17, 2009

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.