| 2188 | */ |
| 2189 | |
| 2190 | static 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); |
no test coverage detected