433
434
static void get_commons_through_negotiation(struct repository *r,
435
const char *url,
436
+ const struct string_list *negotiation_include,
437
+ const struct string_list *negotiation_restrict,
438
const struct ref *remote_refs,
439
struct oid_array *commons)
440
{
441
struct child_process child = CHILD_PROCESS_INIT;
442
const struct ref *ref;
443
int len = r->hash_algo->hexsz + 1; /* hash + NL */
442
- int nr_negotiation_tip = 0;
444
+ int nr_negotiation = 0;
445
446
child.git_cmd = 1;
447
child.no_stdin = 1;
448
child.out = -1;
449
strvec_pushl(&child.args, "fetch", "--negotiate-only", NULL);
448
- for (ref = remote_refs; ref; ref = ref->next) {
449
- if (!is_null_oid(&ref->new_oid)) {
450
+
451
+ if (negotiation_restrict && negotiation_restrict->nr) {
452
+ struct string_list_item *item;
453
+ for_each_string_list_item(item, negotiation_restrict)
454
strvec_pushf(&child.args, "--negotiation-restrict=%s",
451
- oid_to_hex(&ref->new_oid));
452
- nr_negotiation_tip++;
455
+ item->string);
456
+ nr_negotiation = negotiation_restrict->nr;
457
+ } else {
458
+ for (ref = remote_refs; ref; ref = ref->next) {
459
+ if (!is_null_oid(&ref->new_oid)) {
460
+ strvec_pushf(&child.args, "--negotiation-restrict=%s",
461
+ oid_to_hex(&ref->new_oid));
462
+ nr_negotiation++;
463
+ }
464
}
465
}
466
+
467
+ if (negotiation_include && negotiation_include->nr) {
468
+ struct string_list_item *item;
469
+ for_each_string_list_item(item, negotiation_include)
470
+ strvec_pushf(&child.args, "--negotiation-include=%s",
471
+ item->string);
472
+ nr_negotiation += negotiation_include->nr;
473
+ }
474
+
475
strvec_push(&child.args, url);
476
457
- if (!nr_negotiation_tip) {
477
+ if (!nr_negotiation) {
478
child_process_clear(&child);
479
return;
480
}
548
repo_config_get_bool(r, "push.negotiate", &push_negotiate);
549
if (push_negotiate) {
550
trace2_region_enter("send_pack", "push_negotiate", r);
531
- get_commons_through_negotiation(r, args->url, remote_refs, &commons);
551
+ get_commons_through_negotiation(r, args->url,
552
+ args->negotiation_include,
553
+ args->negotiation_restrict,
554
+ remote_refs, &commons);
555
trace2_region_leave("send_pack", "push_negotiate", r);
556
}
557