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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Le Monday 25 May 2009, Johannes Schindelin a écrit :
> 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.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]