mirror of
https://github.com/facebook/sapling.git
synced 2024-10-05 14:28:17 +03:00
start writing the v2 SNAPSHOT
Summary: Start writing the v2 format (single, variable-width parent) into the SNAPSHOT file. Reviewed By: xavierd Differential Revision: D28528419 fbshipit-source-id: 245bd4f749c45f4de2912b0406fc0d1b52278987
This commit is contained in:
parent
f005f37d74
commit
ebbcef7605
@ -1122,12 +1122,14 @@ class EdenCheckout:
|
||||
else:
|
||||
raise RuntimeError("SNAPSHOT file has invalid header")
|
||||
|
||||
def save_snapshot(self, commid_id: str) -> None:
|
||||
def save_snapshot(self, commit_id: str) -> None:
|
||||
"""Write a new parent commit ID into the SNAPSOHT file."""
|
||||
snapshot_path = self.state_dir / SNAPSHOT
|
||||
assert len(commid_id) == 40
|
||||
commit_bin = binascii.unhexlify(commid_id)
|
||||
write_file_atomically(snapshot_path, SNAPSHOT_MAGIC_1 + commit_bin)
|
||||
assert len(commit_id) == 40
|
||||
encoded = commit_id.encode()
|
||||
write_file_atomically(
|
||||
snapshot_path, SNAPSHOT_MAGIC_2 + struct.pack(">L", len(encoded)) + encoded
|
||||
)
|
||||
|
||||
def get_backing_repo(self) -> util.HgRepo:
|
||||
repo_path = self.get_config().backing_repo
|
||||
|
@ -161,7 +161,10 @@ Hash CheckoutConfig::getParentCommit() const {
|
||||
}
|
||||
|
||||
void CheckoutConfig::setParentCommit(Hash parent) const {
|
||||
std::array<uint8_t, kSnapshotHeaderSize + (2 * Hash::RAW_SIZE)> buffer;
|
||||
std::array<
|
||||
uint8_t,
|
||||
kSnapshotHeaderSize + sizeof(uint32_t) + (2 * Hash::RAW_SIZE)>
|
||||
buffer;
|
||||
IOBuf buf(IOBuf::WRAP_BUFFER, ByteRange{buffer});
|
||||
folly::io::RWPrivateCursor cursor{&buf};
|
||||
|
||||
@ -169,15 +172,14 @@ void CheckoutConfig::setParentCommit(Hash parent) const {
|
||||
// 4-byte identifier: "eden"
|
||||
cursor.push(ByteRange{kSnapshotFileMagic});
|
||||
// 4-byte format version identifier
|
||||
cursor.writeBE<uint32_t>(kSnapshotFormatVersion1);
|
||||
// 20-byte commit ID: parent1
|
||||
cursor.push(parent.getBytes());
|
||||
// Older versions of EdenFS would write a second 20-byte hash here to track
|
||||
// the second HG parent commit, but it was never used for anything. Optional
|
||||
// 20-byte commit ID: parent2
|
||||
cursor.writeBE<uint32_t>(kSnapshotFormatVersion2);
|
||||
cursor.writeBE<uint32_t>(2 * Hash::RAW_SIZE);
|
||||
// 40-byte hex commit ID: parent1
|
||||
cursor.push(folly::StringPiece{parent.toString()});
|
||||
size_t writtenSize = cursor - folly::io::RWPrivateCursor{&buf};
|
||||
ByteRange snapshotData{buffer.data(), writtenSize};
|
||||
writeFileAtomic(getSnapshotPath(), snapshotData).value();
|
||||
XCHECK_EQ(buffer.size(), writtenSize);
|
||||
writeFileAtomic(getSnapshotPath(), ByteRange{buffer.data(), buffer.size()})
|
||||
.value();
|
||||
}
|
||||
|
||||
const AbsolutePath& CheckoutConfig::getClientDirectory() const {
|
||||
|
Loading…
Reference in New Issue
Block a user