Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/5] support fetching into a shallow repository
Date: Mon, 13 Nov 2006 23:24:41 -0800	[thread overview]
Message-ID: <7vac2u1oee.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: Pine.LNX.4.63.0610302008520.26682@wbgn013.biozentrum.uni-wuerzburg.de

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> A shallow commit is a commit which has parents, which in turn are
> "grafted away", i.e. the commit appears as if it were a root.
>
> Since these shallow commits should not be edited by the user, but
> only by core git, they are recorded in the file $GIT_DIR/shallow.
>
> A repository containing shallow commits is called shallow.
>
> The advantage of a shallow repository is that even if the upstream
> contains lots of history, your local (shallow) repository needs not
> occupy much disk space.
>
> The disadvantage is that you might miss a merge base when pulling
> some remote branch.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> 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).

  reply	other threads:[~2006-11-14  7:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-30 19:09 [PATCH 2/5] support fetching into a shallow repository Johannes Schindelin
2006-11-14  7:24 ` Junio C Hamano [this message]
2006-11-14 10:43   ` Johannes Schindelin
2006-11-14 17:42     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vac2u1oee.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox