sapling/eden/fs/inodes/DeferredDiffEntry.h
Chad Austin fc07c3b6e6 add an ObjectFetchContext interface
Summary:
Add a fetch context interface to ObjectStore that allows tracing cache
hits, backing store fetches, and fetch durations in the context of a
diff or checkout operation.

Reviewed By: simpkins

Differential Revision: D19135625

fbshipit-source-id: d0d8f134b1c89f7ba4971a404a46a69a1704ba5c
2020-02-05 13:15:01 -08:00

125 lines
3.5 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#pragma once
#include <memory>
#include "eden/fs/inodes/InodePtrFwd.h"
#include "eden/fs/utils/PathFuncs.h"
namespace folly {
template <typename T>
class Future;
struct Unit;
} // namespace folly
namespace facebook {
namespace eden {
class DiffContext;
class GitIgnoreStack;
class Hash;
class ObjectStore;
class TreeEntry;
class TreeInode;
class DiffCallback;
/**
* A helper class for use in TreeInode::diff()
*
* While diff() holds the contents_ lock it computes a set of child entries
* that need to be examined later once it releases the contents_ lock.
* DeferredDiffEntry is used to store the data about which children need to be
* examined. The DeferredDiffEntry subclasses contain the logic for how to
* then perform the diff on the child entry.
*/
class DeferredDiffEntry {
public:
explicit DeferredDiffEntry(DiffContext* context, RelativePath&& path)
: context_{context}, path_{std::move(path)} {}
virtual ~DeferredDiffEntry() {}
const RelativePath& getPath() const {
return path_;
}
FOLLY_NODISCARD virtual folly::Future<folly::Unit> run() = 0;
static std::unique_ptr<DeferredDiffEntry> createUntrackedEntry(
DiffContext* context,
RelativePath path,
InodePtr inode,
const GitIgnoreStack* ignore,
bool isIgnored);
/*
* This is named differently from the createUntrackedEntry() function above
* just to avoid ambiguous overload calls--folly::Future<X> can unfortunately
* be implicitly constructed from X. We could help the compiler avoid the
* ambiguity by making the Future<InodePtr> version of createUntrackedEntry()
* be a template method. However, just using a separate name is easier for
* now.
*/
static std::unique_ptr<DeferredDiffEntry> createUntrackedEntryFromInodeFuture(
DiffContext* context,
RelativePath path,
folly::Future<InodePtr>&& inodeFuture,
const GitIgnoreStack* ignore,
bool isIgnored);
static std::unique_ptr<DeferredDiffEntry> createRemovedEntry(
DiffContext* context,
RelativePath path,
const TreeEntry& scmEntry);
static std::unique_ptr<DeferredDiffEntry> createModifiedEntry(
DiffContext* context,
RelativePath path,
const TreeEntry& scmEntry,
InodePtr inode,
const GitIgnoreStack* ignore,
bool isIgnored);
static std::unique_ptr<DeferredDiffEntry> createModifiedEntryFromInodeFuture(
DiffContext* context,
RelativePath path,
const TreeEntry& scmEntry,
folly::Future<InodePtr>&& inodeFuture,
const GitIgnoreStack* ignore,
bool isIgnored);
static std::unique_ptr<DeferredDiffEntry> createModifiedEntry(
DiffContext* context,
RelativePath path,
const TreeEntry& scmEntry,
Hash currentBlobHash);
static std::unique_ptr<DeferredDiffEntry> createModifiedScmEntry(
DiffContext* context,
RelativePath path,
Hash scmHash,
Hash wdHash,
const GitIgnoreStack* ignore,
bool isIgnored);
static std::unique_ptr<DeferredDiffEntry> createAddedScmEntry(
DiffContext* context,
RelativePath path,
Hash wdHash,
const GitIgnoreStack* ignore,
bool isIgnored);
static std::unique_ptr<DeferredDiffEntry>
createRemovedScmEntry(DiffContext* context, RelativePath path, Hash scmHash);
protected:
DiffContext* const context_;
RelativePath const path_;
};
} // namespace eden
} // namespace facebook