summaryrefslogtreecommitdiff
path: root/connect.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-10-30 12:10:00 -0700
committerJunio C Hamano <gitster@pobox.com>2013-10-30 12:10:06 -0700
commit9907d1359ccb1e670a408e5ab91d2b6048bd997b (patch)
tree34b940ad8c553384f7748710a75de9f24dedf8fa /connect.c
parent177f0a400955f2345c73a5c8b0459d617429ffd9 (diff)
parent360a3261a471ee59760b0743bbb27d3a60849ae2 (diff)
downloadgit-9907d1359ccb1e670a408e5ab91d2b6048bd997b.tar.gz
Merge branch 'jc/upload-pack-send-symref'
One long-standing flaw in the pack transfer protocol used by "git clone" was that there was no way to tell the other end which branch "HEAD" points at, and the receiving end needed to guess. A new capability has been defined in the pack protocol to convey this information so that cloning from a repository with more than one branches pointing at the same commit where the HEAD is at now reliably sets the initial branch in the resulting repository. * jc/upload-pack-send-symref: t5570: Update for clone-progress-to-stderr branch t5570: Update for symref capability clone: test the new HEAD detection logic connect: annotate refs with their symref information in get_remote_head() connect.c: make parse_feature_value() static upload-pack: send non-HEAD symbolic refs upload-pack: send symbolic ref information as capability upload-pack.c: do not pass confusing cb_data to mark_our_ref() t5505: fix "set-head --auto with ambiguous HEAD" test
Diffstat (limited to 'connect.c')
-rw-r--r--connect.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/connect.c b/connect.c
index 40868610ab..06e88b0705 100644
--- a/connect.c
+++ b/connect.c
@@ -7,8 +7,10 @@
#include "remote.h"
#include "connect.h"
#include "url.h"
+#include "string-list.h"
static char *server_capabilities;
+static const char *parse_feature_value(const char *, const char *, int *);
static int check_ref(const char *name, int len, unsigned int flags)
{
@@ -60,6 +62,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 +124,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,10 +172,13 @@ 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;
}
-const char *parse_feature_value(const char *feature_list, const char *feature, int *lenp)
+static const char *parse_feature_value(const char *feature_list, const char *feature, int *lenp)
{
int len;