Skip to content

Commit 31a9554

Browse files
committed
Merge branch 'ab/serve-cleanup' into seen
Code clean-up around "git serve". * ab/serve-cleanup: serve: use designated initializers transport: use designated initializers transport: rename "fetch" in transport_vtable to "fetch_refs" SQUASH??? struct strvec no longer needed serve: mark has_capability() as static
2 parents 7de7e84 + e51a1dc commit 31a9554

File tree

5 files changed

+56
-42
lines changed

5 files changed

+56
-42
lines changed

serve.c

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,37 @@ struct protocol_capability {
7373
};
7474

7575
static struct protocol_capability capabilities[] = {
76-
{ "agent", agent_advertise, NULL },
77-
{ "ls-refs", ls_refs_advertise, ls_refs },
78-
{ "fetch", upload_pack_advertise, upload_pack_v2 },
79-
{ "server-option", always_advertise, NULL },
80-
{ "object-format", object_format_advertise, NULL },
81-
{ "session-id", session_id_advertise, NULL },
82-
{ "object-info", always_advertise, cap_object_info },
76+
{
77+
.name = "agent",
78+
.advertise = agent_advertise,
79+
},
80+
{
81+
.name = "ls-refs",
82+
.advertise = ls_refs_advertise,
83+
.command = ls_refs,
84+
},
85+
{
86+
.name = "fetch",
87+
.advertise = upload_pack_advertise,
88+
.command = upload_pack_v2,
89+
},
90+
{
91+
.name = "server-option",
92+
.advertise = always_advertise,
93+
},
94+
{
95+
.name = "object-format",
96+
.advertise = object_format_advertise,
97+
},
98+
{
99+
.name = "session-id",
100+
.advertise = session_id_advertise,
101+
},
102+
{
103+
.name = "object-info",
104+
.advertise = always_advertise,
105+
.command = cap_object_info,
106+
},
83107
};
84108

85109
static void advertise_capabilities(void)
@@ -156,8 +180,8 @@ static int is_command(const char *key, struct protocol_capability **command)
156180
return 0;
157181
}
158182

159-
int has_capability(const struct strvec *keys, const char *capability,
160-
const char **value)
183+
static int has_capability(const struct strvec *keys, const char *capability,
184+
const char **value)
161185
{
162186
int i;
163187
for (i = 0; i < keys->nr; i++) {

serve.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#ifndef SERVE_H
22
#define SERVE_H
33

4-
struct strvec;
5-
int has_capability(const struct strvec *keys, const char *capability,
6-
const char **value);
7-
84
struct serve_options {
95
unsigned advertise_capabilities;
106
unsigned stateless_rpc;

transport-helper.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,8 @@ static int connect_helper(struct transport *transport, const char *name,
671671
static struct ref *get_refs_list_using_list(struct transport *transport,
672672
int for_push);
673673

674-
static int fetch(struct transport *transport,
675-
int nr_heads, struct ref **to_fetch)
674+
static int fetch_refs(struct transport *transport,
675+
int nr_heads, struct ref **to_fetch)
676676
{
677677
struct helper_data *data = transport->data;
678678
int i, count;
@@ -681,7 +681,7 @@ static int fetch(struct transport *transport,
681681

682682
if (process_connect(transport, 0)) {
683683
do_take_over(transport);
684-
return transport->vtable->fetch(transport, nr_heads, to_fetch);
684+
return transport->vtable->fetch_refs(transport, nr_heads, to_fetch);
685685
}
686686

687687
/*
@@ -1261,12 +1261,12 @@ static struct ref *get_refs_list_using_list(struct transport *transport,
12611261
}
12621262

12631263
static struct transport_vtable vtable = {
1264-
set_helper_option,
1265-
get_refs_list,
1266-
fetch,
1267-
push_refs,
1268-
connect_helper,
1269-
release_helper
1264+
.set_option = set_helper_option,
1265+
.get_refs_list = get_refs_list,
1266+
.fetch_refs = fetch_refs,
1267+
.push_refs = push_refs,
1268+
.connect = connect_helper,
1269+
.disconnect = release_helper
12701270
};
12711271

12721272
int transport_helper_init(struct transport *transport, const char *name)

transport-internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct transport_vtable {
3434
* get_refs_list(), it should set the old_sha1 fields in the
3535
* provided refs now.
3636
**/
37-
int (*fetch)(struct transport *transport, int refs_nr, struct ref **refs);
37+
int (*fetch_refs)(struct transport *transport, int refs_nr, struct ref **refs);
3838

3939
/**
4040
* Push the objects and refs. Send the necessary objects, and

transport.c

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -880,12 +880,10 @@ static int disconnect_git(struct transport *transport)
880880
}
881881

882882
static struct transport_vtable taken_over_vtable = {
883-
NULL,
884-
get_refs_via_connect,
885-
fetch_refs_via_pack,
886-
git_transport_push,
887-
NULL,
888-
disconnect_git
883+
.get_refs_list = get_refs_via_connect,
884+
.fetch_refs = fetch_refs_via_pack,
885+
.push_refs = git_transport_push,
886+
.disconnect = disconnect_git
889887
};
890888

891889
void transport_take_over(struct transport *transport,
@@ -1029,21 +1027,17 @@ void transport_check_allowed(const char *type)
10291027
}
10301028

10311029
static struct transport_vtable bundle_vtable = {
1032-
NULL,
1033-
get_refs_from_bundle,
1034-
fetch_refs_from_bundle,
1035-
NULL,
1036-
NULL,
1037-
close_bundle
1030+
.get_refs_list = get_refs_from_bundle,
1031+
.fetch_refs = fetch_refs_from_bundle,
1032+
.disconnect = close_bundle
10381033
};
10391034

10401035
static struct transport_vtable builtin_smart_vtable = {
1041-
NULL,
1042-
get_refs_via_connect,
1043-
fetch_refs_via_pack,
1044-
git_transport_push,
1045-
connect_git,
1046-
disconnect_git
1036+
.get_refs_list = get_refs_via_connect,
1037+
.fetch_refs = fetch_refs_via_pack,
1038+
.push_refs = git_transport_push,
1039+
.connect = connect_git,
1040+
.disconnect = disconnect_git
10471041
};
10481042

10491043
struct transport *transport_get(struct remote *remote, const char *url)
@@ -1449,7 +1443,7 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
14491443
heads[nr_heads++] = rm;
14501444
}
14511445

1452-
rc = transport->vtable->fetch(transport, nr_heads, heads);
1446+
rc = transport->vtable->fetch_refs(transport, nr_heads, heads);
14531447

14541448
free(heads);
14551449
return rc;

0 commit comments

Comments
 (0)