Re: [PATCH 2/5] support fetching into a shallow repository

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

 



Johannes Schindelin <Johannes.Schindelin@xxxxxx> 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@xxxxxx>
> ---
> 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).

-
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]