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

Function stat_branch_pair

remote.c:2190–2253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2188 */
2189
2190static int stat_branch_pair(const char *branch_name, const char *base,
2191 int *num_ours, int *num_theirs,
2192 enum ahead_behind_flags abf)
2193{
2194 struct object_id oid;
2195 struct commit *ours, *theirs;
2196 struct rev_info revs;
2197 struct strvec argv = STRVEC_INIT;
2198
2199 /* Cannot stat if what we used to build on no longer exists */
2200 if (refs_read_ref(get_main_ref_store(the_repository), base, &oid))
2201 return -1;
2202 theirs = lookup_commit_reference(the_repository, &oid);
2203 if (!theirs)
2204 return -1;
2205
2206 if (refs_read_ref(get_main_ref_store(the_repository), branch_name, &oid))
2207 return -1;
2208 ours = lookup_commit_reference(the_repository, &oid);
2209 if (!ours)
2210 return -1;
2211
2212 *num_theirs = *num_ours = 0;
2213
2214 /* are we the same? */
2215 if (theirs == ours)
2216 return 0;
2217 if (abf == AHEAD_BEHIND_QUICK)
2218 return 1;
2219 if (abf != AHEAD_BEHIND_FULL)
2220 BUG("stat_branch_pair: invalid abf '%d'", abf);
2221
2222 /* Run "rev-list --left-right ours...theirs" internally... */
2223 strvec_push(&argv, ""); /* ignored */
2224 strvec_push(&argv, "--left-right");
2225 strvec_pushf(&argv, "%s...%s",
2226 oid_to_hex(&ours->object.oid),
2227 oid_to_hex(&theirs->object.oid));
2228 strvec_push(&argv, "--");
2229
2230 repo_init_revisions(the_repository, &revs, NULL);
2231 setup_revisions_from_strvec(&argv, &revs, NULL);
2232 if (prepare_revision_walk(&revs))
2233 die(_("revision walk setup failed"));
2234
2235 /* ... and count the commits on each side. */
2236 while (1) {
2237 struct commit *c = get_revision(&revs);
2238 if (!c)
2239 break;
2240 if (c->object.flags & SYMMETRIC_LEFT)
2241 (*num_ours)++;
2242 else
2243 (*num_theirs)++;
2244 }
2245
2246 /* clear object flags smudged by the above traversal */
2247 clear_commit_marks(ours, ALL_REV_FLAGS);

Callers 2

stat_tracking_infoFunction · 0.85
format_tracking_infoFunction · 0.85

Calls 14

refs_read_refFunction · 0.85
get_main_ref_storeFunction · 0.85
lookup_commit_referenceFunction · 0.85
strvec_pushFunction · 0.85
strvec_pushfFunction · 0.85
oid_to_hexFunction · 0.85
repo_init_revisionsFunction · 0.85
prepare_revision_walkFunction · 0.85
get_revisionFunction · 0.85
clear_commit_marksFunction · 0.85
strvec_clearFunction · 0.85

Tested by

no test coverage detected