368
return strbuf_detach(&sb, NULL);
369
}
370
371
+/*
372
+ * Find first index of 'nicks' where there is 'nick'. 'nick' is
373
+ * compared case insensitively to the strings in 'nicks'. If not found
374
+ * 'nicks->nr' is returned.
375
+ */
376
+static size_t remote_nick_find(struct strvec *nicks, const char *nick)
377
+{
378
+ for (size_t i = 0; i < nicks->nr; i++)
379
+ if (!strcasecmp(nicks->v[i], nick))
380
+ return i;
381
+ return nicks->nr;
382
+}
383
+
384
enum accept_promisor {
385
ACCEPT_NONE = 0,
386
+ ACCEPT_KNOWN_URL,
387
+ ACCEPT_KNOWN_NAME,
388
ACCEPT_ALL
389
};
390
391
static int should_accept_remote(enum accept_promisor accept,
377
- const char *remote_name UNUSED,
378
- const char *remote_url UNUSED)
392
+ const char *remote_name, const char *remote_url,
393
+ struct strvec *names, struct strvec *urls)
394
{
395
+ size_t i;
396
+
397
if (accept == ACCEPT_ALL)
398
return 1;
399
383
- BUG("Unhandled 'enum accept_promisor' value '%d'", accept);
400
+ i = remote_nick_find(names, remote_name);
401
+
402
+ if (i >= names->nr)
403
+ /* We don't know about that remote */
404
+ return 0;
405
+
406
+ if (accept == ACCEPT_KNOWN_NAME)
407
+ return 1;
408
+
409
+ if (accept != ACCEPT_KNOWN_URL)
410
+ BUG("Unhandled 'enum accept_promisor' value '%d'", accept);
411
+
412
+ if (!strcmp(urls->v[i], remote_url))
413
+ return 1;
414
+
415
+ warning(_("known remote named '%s' but with url '%s' instead of '%s'"),
416
+ remote_name, urls->v[i], remote_url);
417
+
418
+ return 0;
419
}
420
386
-static void filter_promisor_remote(struct strvec *accepted, const char *info)
421
+static void filter_promisor_remote(struct repository *repo,
422
+ struct strvec *accepted,
423
+ const char *info)
424
{
425
struct strbuf **remotes;
426
const char *accept_str;
427
enum accept_promisor accept = ACCEPT_NONE;
428
+ struct strvec names = STRVEC_INIT;
429
+ struct strvec urls = STRVEC_INIT;
430
431
if (!git_config_get_string_tmp("promisor.acceptfromserver", &accept_str)) {
432
if (!*accept_str || !strcasecmp("None", accept_str))
433
accept = ACCEPT_NONE;
434
+ else if (!strcasecmp("KnownUrl", accept_str))
435
+ accept = ACCEPT_KNOWN_URL;
436
+ else if (!strcasecmp("KnownName", accept_str))
437
+ accept = ACCEPT_KNOWN_NAME;
438
else if (!strcasecmp("All", accept_str))
439
accept = ACCEPT_ALL;
440
else
445
if (accept == ACCEPT_NONE)
446
return;
447
448
+ if (accept != ACCEPT_ALL)
449
+ promisor_info_vecs(repo, &names, &urls);
450
+
451
/* Parse remote info received */
452
453
remotes = strbuf_split_str(info, ';', 0);
477
if (remote_url)
478
decoded_url = url_percent_decode(remote_url);
479
434
- if (decoded_name && should_accept_remote(accept, decoded_name, decoded_url))
480
+ if (decoded_name && should_accept_remote(accept, decoded_name, decoded_url, &names, &urls))
481
strvec_push(accepted, decoded_name);
482
483
strbuf_list_free(elems);
485
free(decoded_url);
486
}
487
488
+ strvec_clear(&names);
489
+ strvec_clear(&urls);
490
strbuf_list_free(remotes);
491
}
492
495
struct strvec accepted = STRVEC_INIT;
496
struct strbuf reply = STRBUF_INIT;
497
450
- filter_promisor_remote(&accepted, info);
498
+ filter_promisor_remote(the_repository, &accepted, info);
499
500
if (!accepted.nr)
501
return NULL;