Re: [PATCH 2/2] receive-pack: ignore duplicated commands which can occur with symrefs

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

 



Jay Soffian <jaysoffian@xxxxxxxxx> writes:

> When pushing to a remote repo, normally the sending side tries to
> filter out any aliased updates (e.g, foo:baz bar:baz). However, it
> is impossible for the sender to know if two refs are aliased on the
> receiving side via symrefs. Here is one such scenario:
>
> $ git init origin

Indent this line a bit.

> (cd origin && touch file && git add file && git commit -a -m intial)
> git clone --bare origin origin.git
> rm -rf origin
>
> git clone origin.git client
>
> git clone --mirror client backup.git &&
> (cd backup.git && git remote set-head origin --auto)
>
> (cd client &&
> 	git remote add --mirror backup ../backup.git &&
> 	echo change1 > file && git commit -a -m change1 &&
> 	git push origin &&
> 	git push backup
> )

Consistently use prompt and indent these to match the first "init".

>
> The push to backup fails with:
>
> Counting objects: 5, done.
> Writing objects: 100% (3/3), 244 bytes, done.
> Total 3 (delta 0), reused 0 (delta 0)
> Unpacking objects: 100% (3/3), done.
> error: Ref refs/remotes/origin/master is at ef307ff6d0026900f84bae7bfe2f5d695238ca66 but expected 262cd5762e76e0aca2c185a3995095318772e2f2

Indent this as well, and trim the object names as the exact values do not
matter.

> remote: error: failed to lock refs/remotes/origin/master
> To ../backup.git
>    262cd57..ef307ff  master -> master
>    262cd57..ef307ff  origin/HEAD -> origin/HEAD
>  ! [remote rejected] origin/master -> origin/master (failed to lock)
> error: failed to push some refs to '../backup.git'

> diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
> index 3fc73cf..a2e3bc8 100644
> --- a/builtin/receive-pack.c
> +++ b/builtin/receive-pack.c
> @@ -9,6 +9,7 @@
>  #include "object.h"
>  #include "remote.h"
>  #include "transport.h"
> +#include "string-list.h"
>  
>  static const char receive_pack_usage[] = "git receive-pack <git-dir>";
>  
> @@ -486,10 +487,30 @@ static void run_update_post_hook(struct command *commands)
>  	}
>  }
>  
> +static int aliased_ref(struct command *cmd, struct string_list *list)
> +{

Nit; what this does sounds more like "aliased update" to me.

> +	struct string_list_item *item;
> +	unsigned char sha1[20];
> +	int flag;
> +
> +	const char *dst_name = resolve_ref(cmd->ref_name, sha1, 0, &flag);
> +
> +	if (!(flag & REF_ISSYMREF))
> +		return 0;
> +
> +	if ((item = string_list_lookup(dst_name, list)) != NULL) {
> +		struct command *other_cmd = (struct command *) item->util;
> +		return (!(hashcmp(cmd->old_sha1, other_cmd->old_sha1) &&
> +			hashcmp(cmd->new_sha1, other_cmd->new_sha1)));

This will also catch two symrefs that point at the same underlying ref.
If all three are updated consistently then all will be fine.  If even one
of them is inconsistent, we will try the update() and give an error
message.

We _could_ give even stronger error message to help diagnosing the
situation if we wanted to.

Very nice.

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