in src/commit_source.h [661:735]
int commit_source::find_repeat_commits_and_head_impl(
git_cache &cache, long long min_ct_to_merge,
std::vector<const char *> &argv, sha1_ref &next) {
auto &git_reply = cache.git_reply;
git_reply.clear();
if (call_git(argv.data(), nullptr, "", git_reply))
return 1;
git_reply.push_back(0);
// Unset "next", in case there are no search results.
next = sha1_ref();
const char *current = git_reply.data();
const char *end = git_reply.data() + git_reply.size() - 1;
while (current != end) {
fparents.emplace_back(source_index);
if (parse_ch(current, 1) ||
cache.pool.parse_sha1(current, fparents.back().commit) ||
parse_space(current) || parse_num(current, fparents.back().ct) ||
parse_space(current))
return error("failed to parse repeat commit");
// Set the goal, if this is the first commit we found.
if (!goal)
goal = fparents.front().commit;
long long real_ct = fparents.back().ct;
validate_last_ct();
// Reinitialize "next"; it'll be left unset if there's no first-parent.
next = sha1_ref();
// Mark all repeat commits as already translated, so that
// by_non_increasing_commit_timestamp will put them at the back of the
// pile.
fparents.back().is_translated = true;
// Save the metadata.
const char *metadata = current;
const char *end_metadata = end;
if (cache.parse_for_store_metadata(fparents.back().commit, metadata,
end_metadata, fparents.back().is_merge,
next))
return error("failed to parse metadata in repeat commit '" +
fparents.back().commit->to_string() + "'");
cache.store_metadata_if_new(fparents.back().commit, metadata, end_metadata,
fparents.back().is_merge,
next);
current = end_metadata;
if (parse_null(current) || parse_newline(current))
return error("missing terminator for repeat commit '" +
fparents.back().commit->to_string() + "'");
// Break once we're one past the earliest other commit timestamp. This is
// critical for fast-forwarding downstream branches that have no changes
// (yet) from upstream.
if (real_ct <= min_ct_to_merge) {
// Rewind the search by one and set the head if it's not already set.
if (!head)
head = fparents.back().commit;
fparents.pop_back();
next = sha1_ref();
return 0;
}
if (!next)
return 0;
// Point out which parent to override.
fparents.back().head_p = 0;
fparents.back().has_parents = true;
}
return 0;
}