Re: [PATCH v2 13/19] pull: implement pulling into an unborn branch

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

 



Paul Tan <pyokagan@xxxxxxxxx> writes:

>  /**
> + * "Pulls into void" by branching off merge_head.
> + */
> +static int pull_into_void(unsigned char merge_head[GIT_SHA1_RAWSZ],
> +		unsigned char curr_head[GIT_SHA1_RAWSZ])
> +{

It is not wrong per-se, but is rather unusual (and misleading) to
specify the array-ness and array-size of parameters.  Our codebase
tends to prefer spelling it like so instead:

	static int pull_into_void(unsigned char *merge_head,
			          unsigned char *curr_head)
	{

> +	/*
> +	 * Two-way merge: we claim the index is based on an empty tree,

s/claim/treat/ perhaps?

> +	 * and try to fast-forward to HEAD. This ensures we will not lose
> +	 * index/worktree changes that the user already made on the unborn
> +	 * branch.
> +	 */
> +	if (checkout_fast_forward(EMPTY_TREE_SHA1_BIN, merge_head, 0))
> +		return 1;
> +
> +	if (update_ref("initial pull", "HEAD", merge_head, curr_head, 0, UPDATE_REFS_DIE_ON_ERR))
> +		return 1;
> +
> +	return 0;
> +}
> +
> +/**
>   * Runs git-merge, returning its exit status.
>   */
>  static int run_merge(void)
> @@ -475,5 +497,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
>  	if (!merge_heads.nr)
>  		die_no_merge_candidates(repo, refspecs);
>  
> -	return run_merge();
> +	if (is_null_sha1(orig_head)) {
> +		if (merge_heads.nr > 1)
> +			die(_("Cannot merge multiple branches into empty head."));
> +		return pull_into_void(*merge_heads.sha1, curr_head);
> +	} else
> +		return run_merge();
>  }

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