Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2021-02-05 23:48:49 +0300
committerJunio C Hamano <gitster@pobox.com>2021-02-06 00:49:55 +0300
commit4f37d45706514a4b3d0259d26f719678a0cf3521 (patch)
tree2b38899f23f3e5e88b72fba0f093e8fb76255089 /connect.c
parent39835409d10de2402c4b3e10dba20286989627d4 (diff)
clone: respect remote unborn HEAD
Teach Git to use the "unborn" feature introduced in a previous patch as follows: Git will always send the "unborn" argument if it is supported by the server. During "git clone", if cloning an empty repository, Git will use the new information to determine the local branch to create. In all other cases, Git will ignore it. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'connect.c')
-rw-r--r--connect.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/connect.c b/connect.c
index 328c279250..879669df93 100644
--- a/connect.c
+++ b/connect.c
@@ -376,7 +376,8 @@ struct ref **get_remote_heads(struct packet_reader *reader,
}
/* Returns 1 when a valid ref has been added to `list`, 0 otherwise */
-static int process_ref_v2(struct packet_reader *reader, struct ref ***list)
+static int process_ref_v2(struct packet_reader *reader, struct ref ***list,
+ char **unborn_head_target)
{
int ret = 1;
int i = 0;
@@ -397,6 +398,25 @@ static int process_ref_v2(struct packet_reader *reader, struct ref ***list)
goto out;
}
+ if (!strcmp("unborn", line_sections.items[i].string)) {
+ i++;
+ if (unborn_head_target &&
+ !strcmp("HEAD", line_sections.items[i++].string)) {
+ /*
+ * Look for the symref target (if any). If found,
+ * return it to the caller.
+ */
+ for (; i < line_sections.nr; i++) {
+ const char *arg = line_sections.items[i].string;
+
+ if (skip_prefix(arg, "symref-target:", &arg)) {
+ *unborn_head_target = xstrdup(arg);
+ break;
+ }
+ }
+ }
+ goto out;
+ }
if (parse_oid_hex_algop(line_sections.items[i++].string, &old_oid, &end, reader->hash_algo) ||
*end) {
ret = 0;
@@ -461,6 +481,8 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
const char *hash_name;
struct strvec *ref_prefixes = transport_options ?
&transport_options->ref_prefixes : NULL;
+ char **unborn_head_target = transport_options ?
+ &transport_options->unborn_head_target : NULL;
*list = NULL;
if (server_supports_v2("ls-refs", 1))
@@ -490,6 +512,8 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
if (!for_push)
packet_write_fmt(fd_out, "peel\n");
packet_write_fmt(fd_out, "symrefs\n");
+ if (server_supports_feature("ls-refs", "unborn", 0))
+ packet_write_fmt(fd_out, "unborn\n");
for (i = 0; ref_prefixes && i < ref_prefixes->nr; i++) {
packet_write_fmt(fd_out, "ref-prefix %s\n",
ref_prefixes->v[i]);
@@ -498,7 +522,7 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
/* Process response from server */
while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
- if (!process_ref_v2(reader, &list))
+ if (!process_ref_v2(reader, &list, unborn_head_target))
die(_("invalid ls-refs response: %s"), reader->line);
}