Re: [PATCH 2/5] support fetching into a shallow repository
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Nov 14, 2006, 10:43 UTC
- Message-ID
- <Pine.LNX.4.63.0611141140530.13772@wbgn013.biozentrum.uni-wuerzburg.de>
- In-Reply-To
- <7vac2u1oee.fsf@assigned-by-dhcp.cox.net>
Hi,
On Mon, 13 Nov 2006, Junio C Hamano wrote:
Show 48 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
> > diff --git a/shallow.c b/shallow.c
> > new file mode 100644
> > index 0000000..3cf2127
> > --- /dev/null
> > +++ b/shallow.c
> >...
> > +struct commit_list *get_shallow_commits(struct object_array *heads, int depth)
> > +{
> > + int i = 0, cur_depth = 0;
> > + struct commit_list *result = NULL;
> > + struct object_array stack = {0, 0, NULL};
> > + struct commit *commit = NULL;
> > +
> > + while (commit || i < heads->nr || stack.nr) {
> > + struct commit_list *p;
> > + if (!commit) {
> >...
> > + }
> > + parse_commit(commit);
> > + cur_depth++;
> > + for (p = commit->parents, commit = NULL; p; p = p->next) {
> > + if (!p->item->util) {
> >...
> > + } else {
> >...
> > + }
> > + if (cur_depth < depth) {
> > + if (p->next)
> > + add_object_array(&p->item->object,
> > + NULL, &stack);
> > + else {
> > + commit = p->item;
> > + cur_depth = *(int *)commit->util;
> > + }
> > + } else
> > + commit_list_insert(p->item, &result);
> > + }
> > + }
> > +
> > + return result;
> > +}
>
> I think the "commit = p->item" part is trying to do a tail
> recursion optimization, but this is a bit too clever to my
> liking (at first I mistook that the code forgot to re-point p at
> its parents list and incrementing cur_depth).I take it as a compliment ;-)
Seriously again, would you like me to add a comment, or rather do away with the tail recursion optimization? It is not a huge optimization anyway. Maybe a cleverer way would be to use an object_array instead of a commit_list?
Ciao, Dscho