Skip to content

Commit d542ba8

Browse files
derrickstoleegitster
authored andcommitted
fetch: add --negotiation-restrict option
The --negotiation-tip option to 'git fetch' and 'git pull' allows users to specify that they want to focus negotiation on a small set of references. This is a _restriction_ on the negotiation set, helping to focus the negotiation when the ref count is high. However, it doesn't allow for the ability to opportunistically select references beyond that list. This subtle detail that this is a 'maximum set' and not a 'minimum set' is not immediately clear from the option name. This makes it more complicated to add a new option that provides the complementary behavior of a minimum set. For now, create a new synonym option, --negotiation-restrict, that behaves identically to --negotiation-tip. Update the documentation to make it clear that this new name is the preferred option, but we keep the old name for compatibility. Update a few warning messages with the new option, but also make them translatable with the option name inserted by formatting. At least one of these messages will be reused later for a new option. Signed-off-by: Derrick Stolee <stolee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent efbb763 commit d542ba8

File tree

5 files changed

+41
-6
lines changed

5 files changed

+41
-6
lines changed

Documentation/fetch-options.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ the current repository has the same history as the source repository.
4949
`.git/shallow`. This option updates `.git/shallow` and accepts such
5050
refs.
5151

52+
`--negotiation-restrict=(<commit>|<glob>)`::
5253
`--negotiation-tip=(<commit>|<glob>)`::
5354
By default, Git will report, to the server, commits reachable
5455
from all local refs to find common commits in an attempt to
@@ -58,6 +59,9 @@ the current repository has the same history as the source repository.
5859
local ref is likely to have commits in common with the
5960
upstream ref being fetched.
6061
+
62+
`--negotiation-restrict` is the preferred name for this option;
63+
`--negotiation-tip` is accepted as a synonym.
64+
+
6165
This option may be specified more than once; if so, Git will report
6266
commits reachable from any of the given commits.
6367
+

builtin/fetch.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,8 +1558,8 @@ static void add_negotiation_tips(struct git_transport_options *smart_options)
15581558
refs_for_each_ref_ext(get_main_ref_store(the_repository),
15591559
add_oid, oids, &opts);
15601560
if (old_nr == oids->nr)
1561-
warning("ignoring --negotiation-tip=%s because it does not match any refs",
1562-
s);
1561+
warning(_("ignoring %s=%s because it does not match any refs"),
1562+
"--negotiation-restrict", s);
15631563
}
15641564
smart_options->negotiation_tips = oids;
15651565
}
@@ -1599,7 +1599,8 @@ static struct transport *prepare_transport(struct remote *remote, int deepen,
15991599
if (transport->smart_options)
16001600
add_negotiation_tips(transport->smart_options);
16011601
else
1602-
warning("ignoring --negotiation-tip because the protocol does not support it");
1602+
warning(_("ignoring %s because the protocol does not support it"),
1603+
"--negotiation-restrict");
16031604
}
16041605
return transport;
16051606
}
@@ -2567,6 +2568,8 @@ int cmd_fetch(int argc,
25672568
OPT_IPVERSION(&family),
25682569
OPT_STRING_LIST(0, "negotiation-tip", &negotiation_tip, N_("revision"),
25692570
N_("report that we have only objects reachable from this object")),
2571+
OPT_STRING_LIST(0, "negotiation-restrict", &negotiation_tip, N_("revision"),
2572+
N_("report that we have only objects reachable from this object")),
25702573
OPT_BOOL(0, "negotiate-only", &negotiate_only,
25712574
N_("do not fetch a packfile; instead, print ancestors of negotiation tips")),
25722575
OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options),
@@ -2657,7 +2660,7 @@ int cmd_fetch(int argc,
26572660
}
26582661

26592662
if (negotiate_only && !negotiation_tip.nr)
2660-
die(_("--negotiate-only needs one or more --negotiation-tip=*"));
2663+
die(_("--negotiate-only needs one or more --negotiation-restrict=*"));
26612664

26622665
if (deepen_relative) {
26632666
if (deepen_relative < 0)

builtin/pull.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,9 @@ int cmd_pull(int argc,
999999
OPT_PASSTHRU_ARGV(0, "negotiation-tip", &opt_fetch, N_("revision"),
10001000
N_("report that we have only objects reachable from this object"),
10011001
0),
1002+
OPT_PASSTHRU_ARGV(0, "negotiation-restrict", &opt_fetch, N_("revision"),
1003+
N_("report that we have only objects reachable from this object"),
1004+
0),
10021005
OPT_BOOL(0, "show-forced-updates", &opt_show_forced_updates,
10031006
N_("check for forced-updates on all updated branches")),
10041007
OPT_PASSTHRU(0, "set-upstream", &set_upstream, NULL,

t/t5510-fetch.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,6 +1460,31 @@ EOF
14601460
test_cmp fatal-expect fatal-actual
14611461
'
14621462

1463+
test_expect_success '--negotiation-restrict limits "have" lines sent' '
1464+
setup_negotiation_tip server server 0 &&
1465+
GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1466+
--negotiation-restrict=alpha_1 --negotiation-restrict=beta_1 \
1467+
origin alpha_s beta_s &&
1468+
check_negotiation_tip
1469+
'
1470+
1471+
test_expect_success '--negotiation-restrict understands globs' '
1472+
setup_negotiation_tip server server 0 &&
1473+
GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1474+
--negotiation-restrict=*_1 \
1475+
origin alpha_s beta_s &&
1476+
check_negotiation_tip
1477+
'
1478+
1479+
test_expect_success '--negotiation-restrict and --negotiation-tip can be mixed' '
1480+
setup_negotiation_tip server server 0 &&
1481+
GIT_TRACE_PACKET="$(pwd)/trace" git -C client fetch \
1482+
--negotiation-restrict=alpha_1 \
1483+
--negotiation-tip=beta_1 \
1484+
origin alpha_s beta_s &&
1485+
check_negotiation_tip
1486+
'
1487+
14631488
test_expect_success SYMLINKS 'clone does not get confused by a D/F conflict' '
14641489
git init df-conflict &&
14651490
(

t/t5702-protocol-v2.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,14 +869,14 @@ setup_negotiate_only () {
869869
test_commit -C client three
870870
}
871871

872-
test_expect_success 'usage: --negotiate-only without --negotiation-tip' '
872+
test_expect_success 'usage: --negotiate-only without --negotiation-restrict' '
873873
SERVER="server" &&
874874
URI="file://$(pwd)/server" &&
875875
876876
setup_negotiate_only "$SERVER" "$URI" &&
877877
878878
cat >err.expect <<-\EOF &&
879-
fatal: --negotiate-only needs one or more --negotiation-tip=*
879+
fatal: --negotiate-only needs one or more --negotiation-restrict=*
880880
EOF
881881
882882
test_must_fail git -c protocol.version=2 -C client fetch \

0 commit comments

Comments
 (0)