From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Andreas Krey <a.krey@gmx.de>
Subject: [PATCH v3 6/7] connect: annotate refs with their symref information in get_remote_head()
Date: Tue, 17 Sep 2013 22:14:22 -0700 [thread overview]
Message-ID: <1379481263-29903-7-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1379481263-29903-1-git-send-email-gitster@pobox.com>
By doing this, clients of upload-pack can now reliably tell what ref
a symbolic ref points at; the updated test in t5505 used to expect
failure due to the ambiguity and made sure we give diagnostics, but
we no longer need to be so pessimistic. Make sure we correctly learn
which branch HEAD points at from the other side instead.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
connect.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
t/t5505-remote.sh | 15 ++++----------
2 files changed, 64 insertions(+), 11 deletions(-)
diff --git a/connect.c b/connect.c
index e4c7ae6..553a80c 100644
--- a/connect.c
+++ b/connect.c
@@ -6,6 +6,7 @@
#include "run-command.h"
#include "remote.h"
#include "url.h"
+#include "string-list.h"
static char *server_capabilities;
static const char *parse_feature_value(const char *, const char *, int *);
@@ -60,6 +61,61 @@ static void die_initial_contact(int got_at_least_one_head)
"and the repository exists.");
}
+static void parse_one_symref_info(struct string_list *symref, const char *val, int len)
+{
+ char *sym, *target;
+ struct string_list_item *item;
+
+ if (!len)
+ return; /* just "symref" */
+ /* e.g. "symref=HEAD:refs/heads/master" */
+ sym = xmalloc(len + 1);
+ memcpy(sym, val, len);
+ sym[len] = '\0';
+ target = strchr(sym, ':');
+ if (!target)
+ /* just "symref=something" */
+ goto reject;
+ *(target++) = '\0';
+ if (check_refname_format(sym, REFNAME_ALLOW_ONELEVEL) ||
+ check_refname_format(target, REFNAME_ALLOW_ONELEVEL))
+ /* "symref=bogus:pair */
+ goto reject;
+ item = string_list_append(symref, sym);
+ item->util = target;
+ return;
+reject:
+ free(sym);
+ return;
+}
+
+static void annotate_refs_with_symref_info(struct ref *ref)
+{
+ struct string_list symref = STRING_LIST_INIT_DUP;
+ const char *feature_list = server_capabilities;
+
+ while (feature_list) {
+ int len;
+ const char *val;
+
+ val = parse_feature_value(feature_list, "symref", &len);
+ if (!val)
+ break;
+ parse_one_symref_info(&symref, val, len);
+ feature_list = val + 1;
+ }
+ sort_string_list(&symref);
+
+ for (; ref; ref = ref->next) {
+ struct string_list_item *item;
+ item = string_list_lookup(&symref, ref->name);
+ if (!item)
+ continue;
+ ref->symref = xstrdup((char *)item->util);
+ }
+ string_list_clear(&symref, 0);
+}
+
/*
* Read all the refs from the other end
*/
@@ -67,6 +123,7 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
struct ref **list, unsigned int flags,
struct extra_have_objects *extra_have)
{
+ struct ref **orig_list = list;
int got_at_least_one_head = 0;
*list = NULL;
@@ -114,6 +171,9 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
list = &ref->next;
got_at_least_one_head = 1;
}
+
+ annotate_refs_with_symref_info(*orig_list);
+
return list;
}
diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh
index 197d3f7..ac79dd9 100755
--- a/t/t5505-remote.sh
+++ b/t/t5505-remote.sh
@@ -160,9 +160,7 @@ cat >test/expect <<EOF
* remote two
Fetch URL: ../two
Push URL: ../three
- HEAD branch (remote HEAD is ambiguous, may be one of the following):
- another
- master
+ HEAD branch: master
Local refs configured for 'git push':
ahead forces to master (fast-forwardable)
master pushes to another (up to date)
@@ -262,17 +260,12 @@ test_expect_success 'set-head --auto' '
)
'
-cat >test/expect <<\EOF
-error: Multiple remote HEAD branches. Please choose one explicitly with:
- git remote set-head two another
- git remote set-head two master
-EOF
-
-test_expect_success 'set-head --auto fails w/multiple HEADs' '
+test_expect_success 'set-head --auto has no problem w/multiple HEADs' '
(
cd test &&
git fetch two "refs/heads/*:refs/remotes/two/*" &&
- test_must_fail git remote set-head --auto two >output 2>&1 &&
+ git remote set-head --auto two >output 2>&1 &&
+ echo "two/HEAD set to master" >expect &&
test_i18ncmp expect output
)
'
--
1.8.4-585-g8d1dcaf
next prev parent reply other threads:[~2013-09-18 5:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-18 5:14 [PATCH v3 0/7] Removing the guesswork of HEAD in "clone" Junio C Hamano
2013-09-18 5:14 ` [PATCH v3 1/7] t5505: fix "set-head --auto with ambiguous HEAD" test Junio C Hamano
2013-09-18 5:14 ` [PATCH v3 2/7] upload-pack.c: do not pass confusing cb_data to mark_our_ref() Junio C Hamano
2013-09-18 5:14 ` [PATCH v3 3/7] upload-pack: send symbolic ref information as capability Junio C Hamano
2013-09-18 5:14 ` [PATCH v3 4/7] upload-pack: send non-HEAD symbolic refs Junio C Hamano
2013-09-18 5:14 ` [PATCH v3 5/7] connect.c: make parse_feature_value() static Junio C Hamano
2013-09-18 5:14 ` Junio C Hamano [this message]
2013-09-18 5:14 ` [PATCH v3 7/7] clone: test the new HEAD detection logic 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=1379481263-29903-7-git-send-email-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=a.krey@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;
as well as URLs for NNTP newsgroup(s).