blob: 6447aa541d0a3877bea8b920e670d6761bb6a77d [file] [log] [blame]
// Copyright 2017 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <lib/fit/function.h>
#include <functional>
#include <memory>
#include "src/ledger/bin/fidl/include/types.h"
#include "src/ledger/bin/storage/public/page_storage.h"
#include "src/ledger/lib/coroutine/coroutine.h"
#include "src/lib/fxl/memory/ref_counted.h"
namespace ledger {
// Comparator for commits that order commits based on their generation, then on
// their id, with highest generation/highest id first.
struct GenerationComparator {
bool operator()(const std::unique_ptr<const storage::Commit>& lhs,
const std::unique_ptr<const storage::Commit>& rhs) const;
// Records the result of comparing two commits.
enum class CommitComparison : int {
// Each commit contains changes that are not present in the other commit.
// All changes present in the left commit are present in the right commit.
// All changes present in the right commit are present in the left commit.
// The two commits contain the same set of changes.
// Find the set of lowest common ancestors of |left| and |right|, and returns a
// status, a list of ancestors, and a comparison result. If |left| is a subset
// of |right|, |right| a subset of |left|, or |left| and |right| are equivalent,
// the list of ancestors is empty and the comparison result is set to the
// appropriate value. Otherwise, the comparison result is set to
storage::Status FindCommonAncestors(
coroutine::CoroutineHandler* handler, storage::PageStorage* storage,
std::unique_ptr<const storage::Commit> left,
std::unique_ptr<const storage::Commit> right, CommitComparison* comparison,
std::vector<std::unique_ptr<const storage::Commit>>* ancestors);
} // namespace ledger