transport: introduce parse_transport_option() method
Add the `parse_transport_option()` method to parse the `push.pushOption` configuration. This method will also be used in the next commit to handle the new `remote.<name>.serverOption` configuration for setting server options in Git protocol v2. Signed-off-by: Xing Xin <xingxin.xx@bytedance.com> Reviewed-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Xing Xin committed
Oct 8, 2024 at 03:38 UTC
06708ce18066b40e05fba22491542d95b43b0f22
3 files changed
+17
-8
builtin/push.c
+1
-8
@@ -519,14 +519,7 @@ static int git_push_config(const char *k, const char *v,
519
RECURSE_SUBMODULES_ON_DEMAND : RECURSE_SUBMODULES_OFF;
520
recurse_submodules = val;
521
} else if (!strcmp(k, "push.pushoption")) {
522
- if (!v)
523
- return config_error_nonbool(k);
524
- else
525
- if (!*v)
526
- string_list_clear(&push_options_config, 0);
527
- else
528
- string_list_append(&push_options_config, v);
529
- return 0;
522
+ return parse_transport_option(k, v, &push_options_config);
523
} else if (!strcmp(k, "color.push")) {
524
push_use_color = git_config_colorbool(k, v);
525
return 0;
transport.c
+12
@@ -1108,6 +1108,18 @@ int is_transport_allowed(const char *type, int from_user)
1108
BUG("invalid protocol_allow_config type");
1109
}
1110
1111
+int parse_transport_option(const char *var, const char *value,
1112
+ struct string_list *transport_options)
1113
+{
1114
+ if (!value)
1115
+ return config_error_nonbool(var);
1116
+ if (!*value)
1117
+ string_list_clear(transport_options, 0);
1118
+ else
1119
+ string_list_append(transport_options, value);
1120
+ return 0;
1121
+}
1122
+
1123
void transport_check_allowed(const char *type)
1124
{
1125
if (!is_transport_allowed(type, -1))
transport.h
+4
@@ -342,4 +342,8 @@ void transport_print_push_status(const char *dest, struct ref *refs,
342
/* common method used by transport-helper.c and send-pack.c */
343
void reject_atomic_push(struct ref *refs, int mirror_mode);
344
345
+/* common method to parse push-option or server-option from config */
346
+int parse_transport_option(const char *var, const char *value,
347
+ struct string_list *transport_options);
348
+
349
#endif