Skip to content

Commit b06dcd7

Browse files
pcloudsgitster
authored andcommitted
connect.c: teach get_remote_heads to parse "shallow" lines
No callers pass a non-empty pointer as shallow_points at this stage. As a result, all clients still refuse to talk to shallow repository on the other end. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ad49136 commit b06dcd7

File tree

6 files changed

+20
-8
lines changed

6 files changed

+20
-8
lines changed

builtin/fetch-pack.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
150150
args.verbose ? CONNECT_VERBOSE : 0);
151151
}
152152

153-
get_remote_heads(fd[0], NULL, 0, &ref, 0, NULL);
153+
get_remote_heads(fd[0], NULL, 0, &ref, 0, NULL, NULL);
154154

155155
ref = fetch_pack(&args, fd, conn, ref, dest,
156156
sought, nr_sought, pack_lockfile_ptr);

builtin/send-pack.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix)
232232
args.verbose ? CONNECT_VERBOSE : 0);
233233
}
234234

235-
get_remote_heads(fd[0], NULL, 0, &remote_refs, REF_NORMAL, &extra_have);
235+
get_remote_heads(fd[0], NULL, 0, &remote_refs, REF_NORMAL, &extra_have, NULL);
236236

237237
transport_verify_remote_names(nr_refspecs, refspecs);
238238

connect.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ static void annotate_refs_with_symref_info(struct ref *ref)
116116
*/
117117
struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
118118
struct ref **list, unsigned int flags,
119-
struct sha1_array *extra_have)
119+
struct sha1_array *extra_have,
120+
struct sha1_array *shallow_points)
120121
{
121122
struct ref **orig_list = list;
122123
int got_at_least_one_head = 0;
@@ -142,6 +143,15 @@ struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
142143
if (len > 4 && !prefixcmp(buffer, "ERR "))
143144
die("remote error: %s", buffer + 4);
144145

146+
if (len == 48 && !prefixcmp(buffer, "shallow ")) {
147+
if (get_sha1_hex(buffer + 8, old_sha1))
148+
die("protocol error: expected shallow sha-1, got '%s'", buffer + 8);
149+
if (!shallow_points)
150+
die("repository on the other end cannot be shallow");
151+
sha1_array_append(shallow_points, old_sha1);
152+
continue;
153+
}
154+
145155
if (len < 42 || get_sha1_hex(buffer, old_sha1) || buffer[40] != ' ')
146156
die("protocol error: expected sha/ref, got '%s'", buffer);
147157
name = buffer + 41;

remote-curl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static struct ref *parse_git_refs(struct discovery *heads, int for_push)
107107
{
108108
struct ref *list = NULL;
109109
get_remote_heads(-1, heads->buf, heads->len, &list,
110-
for_push ? REF_NORMAL : 0, NULL);
110+
for_push ? REF_NORMAL : 0, NULL, NULL);
111111
return list;
112112
}
113113

remote.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ void free_refs(struct ref *ref);
140140
struct sha1_array;
141141
extern struct ref **get_remote_heads(int in, char *src_buf, size_t src_len,
142142
struct ref **list, unsigned int flags,
143-
struct sha1_array *extra_have);
143+
struct sha1_array *extra_have,
144+
struct sha1_array *shallow);
144145

145146
int resolve_remote_symref(struct ref *ref, struct ref *list);
146147
int ref_newer(const unsigned char *new_sha1, const unsigned char *old_sha1);

transport.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
512512

513513
connect_setup(transport, for_push, 0);
514514
get_remote_heads(data->fd[0], NULL, 0, &refs,
515-
for_push ? REF_NORMAL : 0, &data->extra_have);
515+
for_push ? REF_NORMAL : 0, &data->extra_have, NULL);
516516
data->got_remote_heads = 1;
517517

518518
return refs;
@@ -542,7 +542,8 @@ static int fetch_refs_via_pack(struct transport *transport,
542542

543543
if (!data->got_remote_heads) {
544544
connect_setup(transport, 0, 0);
545-
get_remote_heads(data->fd[0], NULL, 0, &refs_tmp, 0, NULL);
545+
get_remote_heads(data->fd[0], NULL, 0, &refs_tmp, 0,
546+
NULL, NULL);
546547
data->got_remote_heads = 1;
547548
}
548549

@@ -806,7 +807,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
806807
struct ref *tmp_refs;
807808
connect_setup(transport, 1, 0);
808809

809-
get_remote_heads(data->fd[0], NULL, 0, &tmp_refs, REF_NORMAL, NULL);
810+
get_remote_heads(data->fd[0], NULL, 0, &tmp_refs, REF_NORMAL, NULL, NULL);
810811
data->got_remote_heads = 1;
811812
}
812813

0 commit comments

Comments
 (0)