mirror of
https://github.com/facebook/sapling.git
synced 2024-10-05 14:28:17 +03:00
Persist the in-progress checkout pid
Summary: The in-progress checkout pid was always serialized to the snapshot file, but we ignored it when reading the file. Let's read it and keep it in memory. This will be used by the next diff to determine if the in progress checkout is resumable or not. Reviewed By: xavierd Differential Revision: D37006722 fbshipit-source-id: 2fa374b309eda36e280bcd352abdaf03193d167e
This commit is contained in:
parent
938c3ed7a5
commit
96276a8af6
@ -167,8 +167,7 @@ ParentCommit CheckoutConfig::getParentCommit() const {
|
||||
}
|
||||
|
||||
case kSnapshotFormatCheckoutInProgressVersion: {
|
||||
// Skip the PID
|
||||
cursor.skip(sizeof(uint32_t));
|
||||
auto pid = cursor.readBE<int32_t>();
|
||||
|
||||
auto fromLength = cursor.readBE<uint32_t>();
|
||||
std::string fromRootId = cursor.readFixedString(fromLength);
|
||||
@ -177,7 +176,7 @@ ParentCommit CheckoutConfig::getParentCommit() const {
|
||||
std::string toRootId = cursor.readFixedString(toLength);
|
||||
|
||||
return ParentCommit::CheckoutInProgress{
|
||||
RootId{std::move(fromRootId)}, RootId{std::move(toRootId)}};
|
||||
RootId{std::move(fromRootId)}, RootId{std::move(toRootId)}, pid};
|
||||
}
|
||||
|
||||
case kSnapshotFormatWorkingCopyParentAndCheckedOutRevisionVersion: {
|
||||
|
@ -14,6 +14,21 @@ bool ParentCommit::isCheckoutInProgress() const {
|
||||
return std::holds_alternative<ParentCommit::CheckoutInProgress>(state_);
|
||||
}
|
||||
|
||||
std::optional<pid_t> ParentCommit::getInProgressPid() const {
|
||||
return std::visit(
|
||||
[](auto&& state) -> std::optional<pid_t> {
|
||||
using StateType = std::decay_t<decltype(state)>;
|
||||
if constexpr (std::is_same_v<
|
||||
StateType,
|
||||
WorkingCopyParentAndCheckedOutRevision>) {
|
||||
return std::nullopt;
|
||||
} else {
|
||||
return state.pid;
|
||||
}
|
||||
},
|
||||
state_);
|
||||
}
|
||||
|
||||
std::optional<RootId> ParentCommit::getLastCheckoutId(
|
||||
RootIdPreference preference) const {
|
||||
return std::visit(
|
||||
|
@ -33,6 +33,11 @@ class ParentCommit {
|
||||
*/
|
||||
bool isCheckoutInProgress() const;
|
||||
|
||||
/**
|
||||
* Returns the pid of the process currently doing a checkout.
|
||||
*/
|
||||
std::optional<pid_t> getInProgressPid() const;
|
||||
|
||||
/**
|
||||
* Since the parent commit might contain multiple RootId, allows chosing
|
||||
* which one should be preferred.
|
||||
@ -68,6 +73,7 @@ class ParentCommit {
|
||||
struct CheckoutInProgress {
|
||||
RootId from;
|
||||
RootId to;
|
||||
pid_t pid;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -162,7 +162,8 @@ TEST_F(CheckoutConfigTest, testInProgress) {
|
||||
|
||||
ParentCommit inProgress = ParentCommit::CheckoutInProgress{
|
||||
RootId{"99887766554433221100aabbccddeeffabcdef99"},
|
||||
RootId{"fedcba99887766554433221100ffeeddccbbaa99"}};
|
||||
RootId{"fedcba99887766554433221100ffeeddccbbaa99"},
|
||||
123};
|
||||
|
||||
auto parent = config->getParentCommit();
|
||||
EXPECT_EQ(inProgress, parent);
|
||||
@ -174,7 +175,7 @@ TEST_F(CheckoutConfigTest, testInProgressRoundtrip) {
|
||||
|
||||
auto from = RootId{"99887766554433221100aabbccddeeffabcdef99"};
|
||||
auto to = RootId{"fedcba998887766554433221100ffeeddccbbaa99"};
|
||||
ParentCommit inProgress = ParentCommit::CheckoutInProgress{from, to};
|
||||
ParentCommit inProgress = ParentCommit::CheckoutInProgress{from, to, 123};
|
||||
|
||||
config->setCheckoutInProgress(from, to);
|
||||
|
||||
|
@ -292,7 +292,8 @@ FOLLY_NODISCARD folly::Future<folly::Unit> EdenMount::initialize(
|
||||
checkoutOriginalDest = parentCommit.getLastCheckoutId(
|
||||
ParentCommit::RootIdPreference::To),
|
||||
checkoutOriginalSrc = parentCommit.getLastCheckoutId(
|
||||
ParentCommit::RootIdPreference::From)](
|
||||
ParentCommit::RootIdPreference::From),
|
||||
checkoutPid = parentCommit.getInProgressPid()](
|
||||
std::shared_ptr<const Tree> parentTree) mutable {
|
||||
std::optional<std::tuple<RootId, RootId>> originalCheckoutTrees =
|
||||
std::nullopt;
|
||||
@ -305,7 +306,9 @@ FOLLY_NODISCARD folly::Future<folly::Unit> EdenMount::initialize(
|
||||
parentTree,
|
||||
workingCopyParentRootId,
|
||||
inProgressCheckout,
|
||||
originalCheckoutTrees};
|
||||
originalCheckoutTrees,
|
||||
checkoutPid,
|
||||
};
|
||||
|
||||
// Record the transition from no snapshot to the current snapshot in
|
||||
// the journal. This also sets things up so that we can carry the
|
||||
|
@ -1155,6 +1155,7 @@ class EdenMount : public std::enable_shared_from_this<EdenMount> {
|
||||
RootId workingCopyParentRootId;
|
||||
bool checkoutInProgress = false;
|
||||
std::optional<std::tuple<RootId, RootId>> checkoutOriginalTrees;
|
||||
std::optional<pid_t> checkoutPid;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user