25
#include "oidset.h"
26
#include "packfile.h"
27
#include "odb.h"
28
+#include "object-name.h"
29
#include "path.h"
30
#include "connected.h"
31
#include "fetch-negotiator.h"
333
}
334
}
335
336
+static void add_oids_to_set(const struct oid_array *array,
337
+ struct oidset *set)
338
+{
339
+ if (!array)
340
+ return;
341
+
342
+ for (size_t i = 0; i < array->nr; i++) {
343
+ struct object_id *oid = &array->oid[i];
344
+ if (!odb_has_object(the_repository->objects, oid, 0))
345
+ die(_("the object %s does not exist"), oid_to_hex(oid));
346
+
347
+ oidset_insert(set, oid);
348
+ }
349
+}
350
+
351
static int find_common(struct fetch_negotiator *negotiator,
352
struct fetch_pack_args *args,
353
int fd[2], struct object_id *result_oid,
363
struct strbuf req_buf = STRBUF_INIT;
364
size_t state_len = 0;
365
struct packet_reader reader;
366
+ struct oidset negotiation_include_oids = OIDSET_INIT;
367
368
if (args->stateless_rpc && multi_ack == 1)
369
die(_("the option '%s' requires '%s'"), "--stateless-rpc", "multi_ack_detailed");
491
trace2_region_enter("fetch-pack", "negotiation_v0_v1", the_repository);
492
flushes = 0;
493
retval = -1;
494
+
495
+ /* Send unconditional haves from --negotiation-include */
496
+ add_oids_to_set(args->negotiation_include_tips,
497
+ &negotiation_include_oids);
498
+ if (oidset_size(&negotiation_include_oids)) {
499
+ struct oidset_iter iter;
500
+ oidset_iter_init(&negotiation_include_oids, &iter);
501
+
502
+ while ((oid = oidset_iter_next(&iter))) {
503
+ struct commit *commit;
504
+ packet_buf_write(&req_buf, "have %s\n",
505
+ oid_to_hex(oid));
506
+ print_verbose(args, "have %s", oid_to_hex(oid));
507
+ count++;
508
+
509
+ commit = lookup_commit(the_repository, oid);
510
+ if (commit)
511
+ negotiator->have_sent(negotiator, commit);
512
+ }
513
+ }
514
+
515
while ((oid = negotiator->next(negotiator))) {
516
packet_buf_write(&req_buf, "have %s\n", oid_to_hex(oid));
517
print_verbose(args, "have %s", oid_to_hex(oid));
622
flushes++;
623
}
624
strbuf_release(&req_buf);
625
+ oidset_clear(&negotiation_include_oids);
626
627
if (!got_ready || !no_done)
628
consume_shallow_list(args, &reader);
1344
1345
static int add_haves(struct fetch_negotiator *negotiator,
1346
struct strbuf *req_buf,
1308
- int *haves_to_send)
1347
+ int *haves_to_send,
1348
+ struct oidset *negotiation_include_oids)
1349
{
1350
int haves_added = 0;
1351
const struct object_id *oid;
1352
1353
+ /* Send unconditional haves from --negotiation-include */
1354
+ if (negotiation_include_oids) {
1355
+ struct oidset_iter iter;
1356
+ oidset_iter_init(negotiation_include_oids, &iter);
1357
+
1358
+ while ((oid = oidset_iter_next(&iter))) {
1359
+ struct commit *commit = lookup_commit(the_repository, oid);
1360
+ if (commit) {
1361
+ packet_buf_write(req_buf, "have %s\n",
1362
+ oid_to_hex(oid));
1363
+ negotiator->have_sent(negotiator, commit);
1364
+ }
1365
+ }
1366
+ }
1367
+
1368
while ((oid = negotiator->next(negotiator))) {
1369
packet_buf_write(req_buf, "have %s\n", oid_to_hex(oid));
1370
if (++haves_added >= *haves_to_send)
1413
struct fetch_pack_args *args,
1414
const struct ref *wants, struct oidset *common,
1415
int *haves_to_send, int *in_vain,
1361
- int sideband_all, int seen_ack)
1416
+ int sideband_all, int seen_ack,
1417
+ struct oidset *negotiation_include_oids)
1418
{
1419
int haves_added;
1420
int done_sent = 0;
1469
/* Add all of the common commits we've found in previous rounds */
1470
add_common(&req_buf, common);
1471
1416
- haves_added = add_haves(negotiator, &req_buf, haves_to_send);
1472
+ haves_added = add_haves(negotiator, &req_buf, haves_to_send,
1473
+ negotiation_include_oids);
1474
*in_vain += haves_added;
1475
trace2_data_intmax("negotiation_v2", the_repository, "haves_added", haves_added);
1476
trace2_data_intmax("negotiation_v2", the_repository, "in_vain", *in_vain);
1714
struct ref *ref = copy_ref_list(orig_ref);
1715
enum fetch_state state = FETCH_CHECK_LOCAL;
1716
struct oidset common = OIDSET_INIT;
1717
+ struct oidset negotiation_include_oids = OIDSET_INIT;
1718
struct packet_reader reader;
1719
int in_vain = 0, negotiation_started = 0;
1720
int negotiation_round = 0;
1787
state = FETCH_SEND_REQUEST;
1788
1789
mark_tips(negotiator, args->negotiation_restrict_tips);
1790
+ add_oids_to_set(args->negotiation_include_tips,
1791
+ &negotiation_include_oids);
1792
for_each_cached_alternate(negotiator,
1793
insert_one_alternate_object);
1794
break;
1807
&common,
1808
&haves_to_send, &in_vain,
1809
reader.use_sideband,
1750
- seen_ack)) {
1810
+ seen_ack,
1811
+ &negotiation_include_oids)) {
1812
trace2_region_leave_printf("negotiation_v2", "round",
1813
the_repository, "%d",
1814
negotiation_round);
1944
negotiator->release(negotiator);
1945
1946
oidset_clear(&common);
1947
+ oidset_clear(&negotiation_include_oids);
1948
return ref;
1949
}
1950
2243
const struct string_list *server_options,
2244
int stateless_rpc,
2245
int fd[],
2184
- struct oidset *acked_commits)
2246
+ struct oidset *acked_commits,
2247
+ const struct oid_array *negotiation_include_tips)
2248
{
2249
struct fetch_negotiator negotiator;
2250
struct packet_reader reader;
2251
struct object_array nt_object_array = OBJECT_ARRAY_INIT;
2252
struct strbuf req_buf = STRBUF_INIT;
2253
+ struct oidset negotiation_include_oids = OIDSET_INIT;
2254
int haves_to_send = INITIAL_FLUSH;
2255
int in_vain = 0;
2256
int seen_ack = 0;
2261
fetch_negotiator_init(the_repository, &negotiator);
2262
mark_tips(&negotiator, negotiation_restrict_tips);
2263
2264
+ add_oids_to_set(negotiation_include_tips,
2265
+ &negotiation_include_oids);
2266
+
2267
packet_reader_init(&reader, fd[0], NULL, 0,
2268
PACKET_READ_CHOMP_NEWLINE |
2269
PACKET_READ_DIE_ON_ERR_PACKET);
2288
2289
packet_buf_write(&req_buf, "wait-for-done");
2290
2224
- haves_added = add_haves(&negotiator, &req_buf, &haves_to_send);
2291
+ haves_added = add_haves(&negotiator, &req_buf, &haves_to_send,
2292
+ &negotiation_include_oids);
2293
in_vain += haves_added;
2294
if (!haves_added || (seen_ack && in_vain >= MAX_IN_VAIN))
2295
last_iteration = 1;
2341
2342
clear_common_flag(acked_commits);
2343
object_array_clear(&nt_object_array);
2344
+ oidset_clear(&negotiation_include_oids);
2345
negotiator.release(&negotiator);
2346
strbuf_release(&req_buf);
2347
}