From: Jay Soffian <jaysoffian@gmail.com>
To: git@vger.kernel.org
Cc: Jay Soffian <jaysoffian@gmail.com>,
"Shawn O . Pearce" <spearce@spearce.org>,
Junio C Hamano <junio@kernel.org>
Subject: [PATCH 2/2] receive-pack: ignore duplicated commands which can occur with symrefs
Date: Thu, 15 Apr 2010 16:54:08 -0400 [thread overview]
Message-ID: <1271364848-32805-2-git-send-email-jaysoffian@gmail.com> (raw)
In-Reply-To: <1271364848-32805-1-git-send-email-jaysoffian@gmail.com>
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
(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
)
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
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'
The reason is that refs/remotes/origin/HEAD is a symref to
refs/remotes/origin/master, but it is impossible for the sending
side to unambiguously know this in all cases.
This commit fixes the issue by having receive pack ignore updates to
any symrefs IFF the target of the symref is being identically
updated.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
builtin/receive-pack.c | 35 +++++++++++++++++++++++++++++++++--
t/t5516-fetch-push.sh | 20 ++++++++++++++++++++
2 files changed, 53 insertions(+), 2 deletions(-)
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)
+{
+ 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)));
+ }
+ return 0;
+}
+
static void execute_commands(struct command *commands, const char *unpacker_error)
{
struct command *cmd;
unsigned char sha1[20];
+ struct string_list ref_list = { NULL, 0, 0, 0 };
if (unpacker_error) {
for (cmd = commands; cmd; cmd = cmd->next)
@@ -505,8 +526,18 @@ static void execute_commands(struct command *commands, const char *unpacker_erro
head_name = resolve_ref("HEAD", sha1, 0, NULL);
- for (cmd = commands; cmd; cmd = cmd->next)
- cmd->error_string = update(cmd);
+ for (cmd = commands; cmd; cmd = cmd->next) {
+ struct string_list_item *item =
+ string_list_append(cmd->ref_name, &ref_list);
+ item->util = (void *)cmd;
+ }
+ sort_string_list(&ref_list);
+
+ for (cmd = commands; cmd; cmd = cmd->next) {
+ if (!aliased_ref(cmd, &ref_list))
+ cmd->error_string = update(cmd);
+ }
+ string_list_clear(&ref_list, 0);
}
static struct command *read_head_info(void)
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 2de98e6..c384529 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -660,6 +660,26 @@ test_expect_success 'push with branches containing #' '
git checkout master
'
+test_expect_success 'push into aliased refs' '
+ mk_test heads/master &&
+ mk_child child1 &&
+ mk_child child2 &&
+ (cd child1 &&
+ git branch foo &&
+ git symbolic-ref refs/heads/bar refs/heads/foo
+ git config receive.denyCurrentBranch false
+ ) &&
+ (cd child2 &&
+ : >path2 &&
+ git add path2 &&
+ test_tick &&
+ git commit -a -m child2 &&
+ git branch foo &&
+ git branch bar &&
+ git push ../child1 foo bar
+ )
+'
+
test_expect_success 'push --porcelain' '
mk_empty &&
echo >.git/foo "To testrepo" &&
--
1.7.0.3.436.g2b878
next prev parent reply other threads:[~2010-04-15 20:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-15 20:54 [PATCH 1/2] receive-pack: Switch global variable 'commands' to a parameter Jay Soffian
2010-04-15 20:54 ` Jay Soffian [this message]
2010-04-15 22:57 ` [PATCH 2/2] receive-pack: ignore duplicated commands which can occur with symrefs Junio C Hamano
2010-04-15 23:07 ` Jay Soffian
2010-04-18 23:11 ` 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=1271364848-32805-2-git-send-email-jaysoffian@gmail.com \
--to=jaysoffian@gmail.com \
--cc=git@vger.kernel.org \
--cc=junio@kernel.org \
--cc=spearce@spearce.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;
as well as URLs for NNTP newsgroup(s).