Skip to content

Commit 7bd70a9

Browse files
committed
remote: add remote.*.negotiationInclude config
Add a new 'remote.<name>.negotiationInclude' multi-valued config option that provides default values for --negotiation-include when no --negotiation-include arguments are specified over the command line. This is a mirror of how 'remote.<name>.negotiationRestrict' specifies defaults for the --negotiation-restrict arguments. Each value is either an exact ref name or a glob pattern whose tips should always be sent as 'have' lines during negotiation. The config values are resolved through the same resolve_negotiation_include() codepath as the CLI options. This option is additive with the normal negotiation process: the negotiation algorithm still runs and advertises its own selected commits, but the refs matching the config are sent unconditionally on top of those heuristically selected commits. Similar to the negotiationRestrict config, an empty value resets the value list to allow ignoring earlier config values, such as those that might be set in system or global config. Signed-off-by: Derrick Stolee <stolee@gmail.com>
1 parent b4cd458 commit 7bd70a9

6 files changed

Lines changed: 97 additions & 0 deletions

File tree

Documentation/config/remote.adoc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,33 @@ values are not used.
125125
Blank values signal to ignore all previous values, allowing a reset of
126126
the list from broader config scenarios.
127127

128+
remote.<name>.negotiationInclude::
129+
When negotiating with this remote during `git fetch`, the client
130+
advertises a list of commits that exist locally. In repos with
131+
many references, this list of "haves" can be truncated. Depending
132+
on data shape, dropping certain references may be expensive. This
133+
multi-valued config option specifies references, commit hashes,
134+
or ref pattern globs whose tips should always be sent as "have"
135+
commits during fetch negotiation with this remote.
136+
+
137+
Each value is either an exact ref name (e.g. `refs/heads/release`), a
138+
commit hash, or a glob pattern (e.g. `refs/heads/release/*`). The
139+
pattern syntax is the same as for `--negotiation-include`.
140+
+
141+
These config values are used as defaults for the `--negotiation-include`
142+
command-line option. If `--negotiation-include` is specified on the
143+
command line, then the config values are not used.
144+
+
145+
This option is additive with the normal negotiation process: the
146+
negotiation algorithm still runs and advertises its own selected commits,
147+
but the refs matching `remote.<name>.negotiationInclude` are sent
148+
unconditionally on top of those heuristically selected commits. This
149+
option is also used during push negotiation when `push.negotiate` is
150+
enabled.
151+
+
152+
Blank values signal to ignore all previous values, allowing a reset of
153+
the list from broader config scenarios.
154+
128155
remote.<name>.followRemoteHEAD::
129156
How linkgit:git-fetch[1] should handle updates to `remotes/<name>/HEAD`
130157
when fetching using the configured refspecs of a remote.

Documentation/fetch-options.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ The pattern syntax is the same as for `--negotiation-restrict`.
9191
If `--negotiation-restrict` is used, the have set is first restricted by
9292
that option and then increased to include the tips specified by
9393
`--negotiation-include`.
94+
+
95+
If this option is not specified on the command line, then any
96+
`remote.<name>.negotiationInclude` config values for the current remote
97+
are used instead.
9498

9599
`--negotiate-only`::
96100
Do not fetch anything from the server, and instead print the

builtin/fetch.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,17 @@ static struct transport *prepare_transport(struct remote *remote, int deepen,
16301630
else
16311631
warning(_("ignoring %s because the protocol does not support it"),
16321632
"--negotiation-include");
1633+
} else if (remote->negotiation_include.nr) {
1634+
if (transport->smart_options) {
1635+
add_negotiation_tips(&remote->negotiation_include,
1636+
&transport->smart_options->negotiation_include_tips);
1637+
} else {
1638+
struct strbuf config_name = STRBUF_INIT;
1639+
strbuf_addf(&config_name, "remote.%s.negotiationInclude", remote->name);
1640+
warning(_("ignoring %s because the protocol does not support it"),
1641+
config_name.buf);
1642+
strbuf_release(&config_name);
1643+
}
16331644
}
16341645
return transport;
16351646
}

remote.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ static struct remote *make_remote(struct remote_state *remote_state,
153153
refspec_init_fetch(&ret->fetch);
154154
string_list_init_dup(&ret->server_options);
155155
string_list_init_dup(&ret->negotiation_restrict);
156+
string_list_init_dup(&ret->negotiation_include);
156157

157158
ALLOC_GROW(remote_state->remotes, remote_state->remotes_nr + 1,
158159
remote_state->remotes_alloc);
@@ -181,6 +182,7 @@ static void remote_clear(struct remote *remote)
181182
FREE_AND_NULL(remote->http_proxy_authmethod);
182183
string_list_clear(&remote->server_options, 0);
183184
string_list_clear(&remote->negotiation_restrict, 0);
185+
string_list_clear(&remote->negotiation_include, 0);
184186
}
185187

186188
static void add_merge(struct branch *branch, const char *name)
@@ -567,6 +569,9 @@ static int handle_config(const char *key, const char *value,
567569
} else if (!strcmp(subkey, "negotiationrestrict")) {
568570
return parse_transport_option(key, value,
569571
&remote->negotiation_restrict);
572+
} else if (!strcmp(subkey, "negotiationinclude")) {
573+
return parse_transport_option(key, value,
574+
&remote->negotiation_include);
570575
} else if (!strcmp(subkey, "followremotehead")) {
571576
const char *no_warn_branch;
572577
if (!strcmp(value, "never"))

remote.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ struct remote {
118118

119119
struct string_list server_options;
120120
struct string_list negotiation_restrict;
121+
struct string_list negotiation_include;
121122

122123
enum follow_remote_head_settings follow_remote_head;
123124
const char *no_warn_branch;

t/t5510-fetch.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,6 +1587,55 @@ test_expect_success '--negotiation-include avoids duplicates with negotiator' '
15871587
test_line_count = 1 matches
15881588
'
15891589

1590+
test_expect_success 'remote.<name>.negotiationInclude used as default for --negotiation-include' '
1591+
test_when_finished rm -f trace &&
1592+
setup_negotiation_tip server server 0 &&
1593+
1594+
# test the reset of the list on an empty value
1595+
git -C client config --add remote.origin.negotiationInclude refs/tags/alpha_1 &&
1596+
git -C client config --add remote.origin.negotiationInclude "" &&
1597+
git -C client config --add remote.origin.negotiationInclude refs/tags/beta_1 &&
1598+
GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1599+
--negotiation-restrict=beta_2 \
1600+
origin alpha_s beta_s &&
1601+
1602+
ALPHA_1=$(git -C client rev-parse alpha_1) &&
1603+
test_grep ! "fetch> have $ALPHA_1" trace &&
1604+
BETA_1=$(git -C client rev-parse beta_1) &&
1605+
test_grep "fetch> have $BETA_1" trace
1606+
'
1607+
1608+
test_expect_success 'remote.<name>.negotiationInclude works with glob patterns' '
1609+
test_when_finished rm -f trace &&
1610+
setup_negotiation_tip server server 0 &&
1611+
1612+
git -C client config --add remote.origin.negotiationInclude "refs/tags/beta_*" &&
1613+
GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1614+
--negotiation-restrict=alpha_1 \
1615+
origin alpha_s beta_s &&
1616+
1617+
BETA_1=$(git -C client rev-parse beta_1) &&
1618+
test_grep "fetch> have $BETA_1" trace &&
1619+
BETA_2=$(git -C client rev-parse beta_2) &&
1620+
test_grep "fetch> have $BETA_2" trace
1621+
'
1622+
1623+
test_expect_success 'CLI --negotiation-include overrides remote.<name>.negotiationInclude' '
1624+
test_when_finished rm -f trace &&
1625+
setup_negotiation_tip server server 0 &&
1626+
1627+
git -C client config --add remote.origin.negotiationInclude refs/tags/beta_2 &&
1628+
GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1629+
--negotiation-restrict=alpha_1 \
1630+
--negotiation-include=refs/tags/beta_1 \
1631+
origin alpha_s beta_s &&
1632+
1633+
BETA_1=$(git -C client rev-parse beta_1) &&
1634+
test_grep "fetch> have $BETA_1" trace &&
1635+
BETA_2=$(git -C client rev-parse beta_2) &&
1636+
test_grep ! "fetch> have $BETA_2" trace
1637+
'
1638+
15901639
test_expect_success '--negotiation-include avoids duplicates with v0' '
15911640
test_when_finished rm -f trace &&
15921641
setup_negotiation_tip server server 0 &&

0 commit comments

Comments
 (0)