MCPcopy Index your code
hub / github.com/git/git / format_tracking_info

Function format_tracking_info

remote.c:2375–2465  ·  view source on GitHub ↗

* Return true when there is anything to report, otherwise false. */

Source from the content-addressed store, hash-verified

2373 * Return true when there is anything to report, otherwise false.
2374 */
2375int format_tracking_info(struct branch *branch, struct strbuf *sb,
2376 enum ahead_behind_flags abf,
2377 int show_divergence_advice)
2378{
2379 char *compare_branches = NULL;
2380 struct string_list branches = STRING_LIST_INIT_DUP;
2381 struct strset processed_refs = STRSET_INIT;
2382 int reported = 0;
2383 size_t i;
2384 const char *upstream_ref;
2385 const char *push_ref;
2386
2387 repo_config_get_string(the_repository, "status.comparebranches",
2388 &compare_branches);
2389
2390 if (compare_branches) {
2391 string_list_split(&branches, compare_branches, " ", -1);
2392 string_list_remove_empty_items(&branches, 0);
2393 } else {
2394 string_list_append(&branches, "@{upstream}");
2395 }
2396
2397 upstream_ref = branch_get_upstream(branch, NULL);
2398 push_ref = branch_get_push(branch, NULL);
2399
2400 for (i = 0; i < branches.nr; i++) {
2401 char *full_ref;
2402 char *short_ref;
2403 int ours, theirs, cmp;
2404 int is_upstream, is_push;
2405 unsigned flags = 0;
2406
2407 full_ref = resolve_compare_branch(branch,
2408 branches.items[i].string);
2409 if (!full_ref)
2410 continue;
2411
2412 if (!strset_add(&processed_refs, full_ref)) {
2413 free(full_ref);
2414 continue;
2415 }
2416
2417 short_ref = refs_shorten_unambiguous_ref(
2418 get_main_ref_store(the_repository), full_ref, 0);
2419
2420 is_upstream = upstream_ref && !strcmp(full_ref, upstream_ref);
2421 is_push = push_ref && !strcmp(full_ref, push_ref);
2422
2423 if (is_upstream && (!push_ref || !strcmp(upstream_ref, push_ref)))
2424 is_push = 1;
2425
2426 cmp = stat_branch_pair(branch->refname, full_ref,
2427 &ours, &theirs, abf);
2428
2429 if (cmp < 0) {
2430 if (is_upstream) {
2431 strbuf_addf(sb,
2432 _("Your branch is based on '%s', but the upstream is gone.\n"),

Callers 2

report_trackingFunction · 0.85

Calls 15

repo_config_get_stringFunction · 0.85
string_list_splitFunction · 0.85
branch_get_upstreamFunction · 0.85
branch_get_pushFunction · 0.85
resolve_compare_branchFunction · 0.85
strset_addFunction · 0.85
get_main_ref_storeFunction · 0.85
stat_branch_pairFunction · 0.85
strbuf_addfFunction · 0.85
advice_enabledFunction · 0.85

Tested by

no test coverage detected