Skip to content

Commit 72da5cf

Browse files
blanetgitster
authored andcommitted
remote: introduce remote.<name>.serverOption configuration
Currently, server options for Git protocol v2 can only be specified via the command line option "--server-option" or "-o", which is inconvenient when users want to specify a list of default options to send. Therefore, we are introducing a new configuration to hold a list of default server options, akin to the `push.pushOption` configuration for push options. Initially, I named the new configuration `fetch.serverOption` to align with `push.pushOption`. However, after discussing with Patrick, it was renamed to `remote.<name>.serverOption` as suggested, because: 1. Server options are designed to be server-specific, making it more logical to use a per-remote configuration. 2. Using "fetch." prefixed configurations in git-clone or git-ls-remote seems out of place and inconsistent in design. The parsing logic for `remote.<name>.serverOption` also relies on `transport.c:parse_transport_option`, similar to `push.pushOption`, and they follow the same priority design: 1. Server options set in lower-priority configuration files (e.g., /etc/gitconfig or $HOME/.gitconfig) can be overridden or unset in more specific repository configurations using an empty string. 2. Command-line specified server options take precedence over those from the configuration. Server options from configuration are stored to the corresponding `remote.h:remote` as a new field `server_options`. The field will be utilized in the subsequent commit to help initialize the `server_options` of `transport.h:transport`. And documentation have been updated accordingly. Helped-by: Patrick Steinhardt <[email protected]> Helped-by: Junio C Hamano <[email protected]> Reported-by: Liu Zhongbo <[email protected]> Signed-off-by: Xing Xin <[email protected]> Reviewed-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 06708ce commit 72da5cf

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

Documentation/config/remote.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,13 @@ remote.<name>.partialclonefilter::
9696
Changing or clearing this value will only affect fetches for new commits.
9797
To fetch associated objects for commits already present in the local object
9898
database, use the `--refetch` option of linkgit:git-fetch[1].
99+
100+
remote.<name>.serverOption::
101+
The default set of server options used when fetching from this remote.
102+
These server options can be overridden by the `--server-option=` command
103+
line arguments.
104+
+
105+
This is a multi-valued variable, and an empty value can be used in a higher
106+
priority configuration file (e.g. `.git/config` in a repository) to clear
107+
the values inherited from a lower priority configuration files (e.g.
108+
`$HOME/.gitconfig`).

remote.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "advice.h"
2525
#include "connect.h"
2626
#include "parse-options.h"
27+
#include "transport.h"
2728

2829
enum map_direction { FROM_SRC, FROM_DST };
2930

@@ -143,6 +144,7 @@ static struct remote *make_remote(struct remote_state *remote_state,
143144
ret->name = xstrndup(name, len);
144145
refspec_init(&ret->push, REFSPEC_PUSH);
145146
refspec_init(&ret->fetch, REFSPEC_FETCH);
147+
string_list_init_dup(&ret->server_options);
146148

147149
ALLOC_GROW(remote_state->remotes, remote_state->remotes_nr + 1,
148150
remote_state->remotes_alloc);
@@ -166,6 +168,7 @@ static void remote_clear(struct remote *remote)
166168
free((char *)remote->uploadpack);
167169
FREE_AND_NULL(remote->http_proxy);
168170
FREE_AND_NULL(remote->http_proxy_authmethod);
171+
string_list_clear(&remote->server_options, 0);
169172
}
170173

171174
static void add_merge(struct branch *branch, const char *name)
@@ -508,6 +511,9 @@ static int handle_config(const char *key, const char *value,
508511
} else if (!strcmp(subkey, "vcs")) {
509512
FREE_AND_NULL(remote->foreign_vcs);
510513
return git_config_string(&remote->foreign_vcs, key, value);
514+
} else if (!strcmp(subkey, "serveroption")) {
515+
return parse_transport_option(key, value,
516+
&remote->server_options);
511517
}
512518
return 0;
513519
}

remote.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "hash.h"
55
#include "hashmap.h"
66
#include "refspec.h"
7+
#include "string-list.h"
78
#include "strvec.h"
89

910
struct option;
@@ -104,6 +105,8 @@ struct remote {
104105

105106
/* The method used for authenticating against `http_proxy`. */
106107
char *http_proxy_authmethod;
108+
109+
struct string_list server_options;
107110
};
108111

109112
/**

0 commit comments

Comments
 (0)