Skip to main content

apply_patch

Function apply_patch 

Source
pub fn apply_patch<F>(
    tree: &FileTree,
    patch: &Patch,
    get_payload_blob: F,
) -> Result<FileTree, ApplyError>
where F: FnMut(&Patch) -> Option<Hash>,
Expand description

Apply a single patch to a FileTree, producing a new FileTree.

§Operation Semantics

OperationPreconditionEffect
CreatePath must NOT existInsert path → blob hash
ModifyPath must existUpdate blob hash
DeletePath must existRemove path
MoveOld path must exist, new must NOTRename
MetadataPath must exist (if specified)No tree change
MergeN/ANo tree change (merge commits carry no payload)
IdentityN/ANo change

§Arguments

  • tree - The current file tree state
  • patch - The patch to apply
  • get_payload_blob - Function to resolve the patch payload to a CAS hash. For Modify/Create, the payload is a hex-encoded CAS hash; this function parses it and returns the actual hash.