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 <ps@pks.im> Helped-by: Junio C Hamano <gitster@pobox.com> Reported-by: Liu Zhongbo <liuzhongbo.6666@bytedance.com> 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>
This commit is contained in:
@ -96,3 +96,13 @@ remote.<name>.partialclonefilter::
|
|||||||
Changing or clearing this value will only affect fetches for new commits.
|
Changing or clearing this value will only affect fetches for new commits.
|
||||||
To fetch associated objects for commits already present in the local object
|
To fetch associated objects for commits already present in the local object
|
||||||
database, use the `--refetch` option of linkgit:git-fetch[1].
|
database, use the `--refetch` option of linkgit:git-fetch[1].
|
||||||
|
|
||||||
|
remote.<name>.serverOption::
|
||||||
|
The default set of server options used when fetching from this remote.
|
||||||
|
These server options can be overridden by the `--server-option=` command
|
||||||
|
line arguments.
|
||||||
|
+
|
||||||
|
This is a multi-valued variable, and an empty value can be used in a higher
|
||||||
|
priority configuration file (e.g. `.git/config` in a repository) to clear
|
||||||
|
the values inherited from a lower priority configuration files (e.g.
|
||||||
|
`$HOME/.gitconfig`).
|
||||||
|
6
remote.c
6
remote.c
@ -24,6 +24,7 @@
|
|||||||
#include "advice.h"
|
#include "advice.h"
|
||||||
#include "connect.h"
|
#include "connect.h"
|
||||||
#include "parse-options.h"
|
#include "parse-options.h"
|
||||||
|
#include "transport.h"
|
||||||
|
|
||||||
enum map_direction { FROM_SRC, FROM_DST };
|
enum map_direction { FROM_SRC, FROM_DST };
|
||||||
|
|
||||||
@ -143,6 +144,7 @@ static struct remote *make_remote(struct remote_state *remote_state,
|
|||||||
ret->name = xstrndup(name, len);
|
ret->name = xstrndup(name, len);
|
||||||
refspec_init(&ret->push, REFSPEC_PUSH);
|
refspec_init(&ret->push, REFSPEC_PUSH);
|
||||||
refspec_init(&ret->fetch, REFSPEC_FETCH);
|
refspec_init(&ret->fetch, REFSPEC_FETCH);
|
||||||
|
string_list_init_dup(&ret->server_options);
|
||||||
|
|
||||||
ALLOC_GROW(remote_state->remotes, remote_state->remotes_nr + 1,
|
ALLOC_GROW(remote_state->remotes, remote_state->remotes_nr + 1,
|
||||||
remote_state->remotes_alloc);
|
remote_state->remotes_alloc);
|
||||||
@ -166,6 +168,7 @@ static void remote_clear(struct remote *remote)
|
|||||||
free((char *)remote->uploadpack);
|
free((char *)remote->uploadpack);
|
||||||
FREE_AND_NULL(remote->http_proxy);
|
FREE_AND_NULL(remote->http_proxy);
|
||||||
FREE_AND_NULL(remote->http_proxy_authmethod);
|
FREE_AND_NULL(remote->http_proxy_authmethod);
|
||||||
|
string_list_clear(&remote->server_options, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_merge(struct branch *branch, const char *name)
|
static void add_merge(struct branch *branch, const char *name)
|
||||||
@ -508,6 +511,9 @@ static int handle_config(const char *key, const char *value,
|
|||||||
} else if (!strcmp(subkey, "vcs")) {
|
} else if (!strcmp(subkey, "vcs")) {
|
||||||
FREE_AND_NULL(remote->foreign_vcs);
|
FREE_AND_NULL(remote->foreign_vcs);
|
||||||
return git_config_string(&remote->foreign_vcs, key, value);
|
return git_config_string(&remote->foreign_vcs, key, value);
|
||||||
|
} else if (!strcmp(subkey, "serveroption")) {
|
||||||
|
return parse_transport_option(key, value,
|
||||||
|
&remote->server_options);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
3
remote.h
3
remote.h
@ -4,6 +4,7 @@
|
|||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "hashmap.h"
|
#include "hashmap.h"
|
||||||
#include "refspec.h"
|
#include "refspec.h"
|
||||||
|
#include "string-list.h"
|
||||||
#include "strvec.h"
|
#include "strvec.h"
|
||||||
|
|
||||||
struct option;
|
struct option;
|
||||||
@ -104,6 +105,8 @@ struct remote {
|
|||||||
|
|
||||||
/* The method used for authenticating against `http_proxy`. */
|
/* The method used for authenticating against `http_proxy`. */
|
||||||
char *http_proxy_authmethod;
|
char *http_proxy_authmethod;
|
||||||
|
|
||||||
|
struct string_list server_options;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user