blob: 8be59ea02bddc2855f048e555f3dee35100308b8 [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 "src/ledger/bin/fidl/include/types.h"
#include "src/ledger/bin/storage/public/page_storage.h"
#include "src/lib/fxl/macros.h"
namespace ledger {
namespace diff_utils {
// Configure the pagination behavior of |ComputePageChange|.
enum class PaginationBehavior {
// Type of three-way diff performed. If |CONFLICTING| is selected, only
// conflicting keys are returned.
enum class DiffType {
// Asynchronously creates a PageChange representing the diff of the two provided
// commits, starting from the given |min_key|. If |pagination_behavior| is
// |NO_PAGINATION|, it provides all results. If |pagination_behavior| is
// |BY_SIZE| it will provide a number of results that fit in a fidl message.
// The result, or an error, will be provided in |callback| status. The second
// argument of the callback is either a pair of the PageChangePtr, containing
// the diff result and the string representation of the next token if the
// result is paginated, or empty if there are no more results to return. Note
// that the PageChangePtr in the callback will be nullptr if the diff is empty.
void ComputePageChange(
storage::PageStorage* storage, const storage::Commit& base,
const storage::Commit& other, std::string prefix_key, std::string min_key,
PaginationBehavior pagination_behavior,
fit::function<void(storage::Status, std::pair<PageChangePtr, std::string>)>
// Asynchronously computes the three-way diff between a base commit and two
// other commits, starting from the given |min_key|.
void ComputeThreeWayDiff(
storage::PageStorage* storage, const storage::Commit& base,
const storage::Commit& left, const storage::Commit& right,
std::string prefix_key, std::string min_key, DiffType diff_type,
std::pair<std::vector<DiffEntry>, std::string>)>
} // namespace diff_utils
} // namespace ledger