Skip to content

Commit a2d15fa

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 ae81ef3 commit a2d15fa

6 files changed

Lines changed: 99 additions & 0 deletions

File tree

Documentation/config/remote.adoc

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

129+
remote.<name>.negotiationInclude::
130+
When negotiating with this remote during `git fetch` and `git push`,
131+
the client advertises a list of commits that exist locally. In
132+
repos with many references, this list of "haves" can be truncated.
133+
Depending on data shape, dropping certain references may be
134+
expensive. This multi-valued config option specifies ref patterns
135+
whose tips should always be sent as "have" commits during fetch
136+
negotiation with this remote.
137+
+
138+
Each value is either an exact ref name (e.g. `refs/heads/release`) or a
139+
glob pattern (e.g. `refs/heads/release/*`). The pattern syntax is the same
140+
as for `--negotiation-restrict`.
141+
+
142+
These config values are used as defaults for the `--negotiation-include`
143+
command-line option. If `--negotiation-include` is specified on the
144+
command line, then the config values are not used.
145+
+
146+
This option is additive with the normal negotiation process: the
147+
negotiation algorithm still runs and advertises its own selected commits,
148+
but the refs matching `remote.<name>.negotiationInclude` are sent
149+
unconditionally on top of those heuristically selected commits. This
150+
option is also used during push negotiation when `push.negotiate` is
151+
enabled.
152+
+
153+
Blank values signal to ignore all previous values, allowing a reset of
154+
the list from broader config scenarios.
155+
129156
remote.<name>.followRemoteHEAD::
130157
How linkgit:git-fetch[1] should handle updates to `remotes/<name>/HEAD`
131158
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 @@ 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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,6 +1626,16 @@ static struct transport *prepare_transport(struct remote *remote, int deepen,
16261626
else
16271627
warning(_("ignoring %s because the protocol does not support it"),
16281628
"--negotiation-include");
1629+
} else if (remote->negotiation_include.nr) {
1630+
if (transport->smart_options) {
1631+
transport->smart_options->negotiation_include = &remote->negotiation_include;
1632+
} else {
1633+
struct strbuf config_name = STRBUF_INIT;
1634+
strbuf_addf(&config_name, "remote.%s.negotiationInclude", remote->name);
1635+
warning(_("ignoring %s because the protocol does not support it"),
1636+
config_name.buf);
1637+
strbuf_release(&config_name);
1638+
}
16291639
}
16301640
return transport;
16311641
}

remote.c

Lines changed: 8 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)
@@ -570,6 +572,12 @@ static int handle_config(const char *key, const char *value,
570572
string_list_clear(&remote->negotiation_restrict, 0);
571573
else
572574
string_list_append(&remote->negotiation_restrict, value);
575+
} else if (!strcmp(subkey, "negotiationinclude")) {
576+
/* reset list on empty value. */
577+
if (!value || !*value)
578+
string_list_clear(&remote->negotiation_include, 0);
579+
else
580+
string_list_append(&remote->negotiation_include, value);
573581
} else if (!strcmp(subkey, "followremotehead")) {
574582
const char *no_warn_branch;
575583
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
@@ -1577,6 +1577,55 @@ test_expect_success '--negotiation-include avoids duplicates with negotiator' '
15771577
test_line_count = 1 matches
15781578
'
15791579

1580+
test_expect_success 'remote.<name>.negotiationInclude used as default for --negotiation-include' '
1581+
test_when_finished rm -f trace &&
1582+
setup_negotiation_tip server server 0 &&
1583+
1584+
# test the reset of the list on an empty value
1585+
git -C client config --add remote.origin.negotiationInclude refs/tags/alpha_1 &&
1586+
git -C client config --add remote.origin.negotiationInclude "" &&
1587+
git -C client config --add remote.origin.negotiationInclude refs/tags/beta_1 &&
1588+
GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1589+
--negotiation-restrict=alpha_1 \
1590+
origin alpha_s beta_s &&
1591+
1592+
ALPHA_1=$(git -C client rev-parse alpha_1) &&
1593+
test_grep "fetch> have $ALPHA_1" trace &&
1594+
BETA_1=$(git -C client rev-parse beta_1) &&
1595+
test_grep "fetch> have $BETA_1" trace
1596+
'
1597+
1598+
test_expect_success 'remote.<name>.negotiationInclude works with glob patterns' '
1599+
test_when_finished rm -f trace &&
1600+
setup_negotiation_tip server server 0 &&
1601+
1602+
git -C client config --add remote.origin.negotiationInclude "refs/tags/beta_*" &&
1603+
GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1604+
--negotiation-restrict=alpha_1 \
1605+
origin alpha_s beta_s &&
1606+
1607+
BETA_1=$(git -C client rev-parse beta_1) &&
1608+
test_grep "fetch> have $BETA_1" trace &&
1609+
BETA_2=$(git -C client rev-parse beta_2) &&
1610+
test_grep "fetch> have $BETA_2" trace
1611+
'
1612+
1613+
test_expect_success 'CLI --negotiation-include overrides remote.<name>.negotiationInclude' '
1614+
test_when_finished rm -f trace &&
1615+
setup_negotiation_tip server server 0 &&
1616+
1617+
git -C client config --add remote.origin.negotiationInclude refs/tags/beta_2 &&
1618+
GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1619+
--negotiation-restrict=alpha_1 \
1620+
--negotiation-include=refs/tags/beta_1 \
1621+
origin alpha_s beta_s &&
1622+
1623+
BETA_1=$(git -C client rev-parse beta_1) &&
1624+
test_grep "fetch> have $BETA_1" trace &&
1625+
BETA_2=$(git -C client rev-parse beta_2) &&
1626+
test_grep ! "fetch> have $BETA_2" trace
1627+
'
1628+
15801629
test_expect_success SYMLINKS 'clone does not get confused by a D/F conflict' '
15811630
git init df-conflict &&
15821631
(

0 commit comments

Comments
 (0)