rust/hg-core/src/dirstate_tree/on_disk.rs
changeset 47331 0252600fd1cf
parent 47330 73f23e7610f8
child 47333 69530e5d4fe5
equal deleted inserted replaced
47330:73f23e7610f8 47331:0252600fd1cf
   256     out[..header_len].copy_from_slice(header.as_bytes());
   256     out[..header_len].copy_from_slice(header.as_bytes());
   257     Ok(out)
   257     Ok(out)
   258 }
   258 }
   259 
   259 
   260 fn write_nodes(
   260 fn write_nodes(
   261     nodes: &mut dirstate_map::ChildNodes,
   261     nodes: &dirstate_map::ChildNodes,
   262     out: &mut Vec<u8>,
   262     out: &mut Vec<u8>,
   263 ) -> Result<ChildNodes, DirstateError> {
   263 ) -> Result<ChildNodes, DirstateError> {
   264     // `dirstate_map::ChildNodes` is a `HashMap` with undefined iteration
   264     // `dirstate_map::ChildNodes` is a `HashMap` with undefined iteration
   265     // order. Sort to enable binary search in the written file.
   265     // order. Sort to enable binary search in the written file.
   266     let nodes = dirstate_map::Node::sorted(nodes);
   266     let nodes = dirstate_map::Node::sorted(nodes);
   267 
   267 
   268     // First accumulate serialized nodes in a `Vec`
   268     // First accumulate serialized nodes in a `Vec`
   269     let mut on_disk_nodes = Vec::with_capacity(nodes.len());
   269     let mut on_disk_nodes = Vec::with_capacity(nodes.len());
   270     for (full_path, node) in nodes {
   270     for (full_path, node) in nodes {
   271         on_disk_nodes.push(Node {
   271         on_disk_nodes.push(Node {
   272             children: write_nodes(&mut node.children, out)?,
   272             children: write_nodes(&node.children, out)?,
   273             tracked_descendants_count: node.tracked_descendants_count.into(),
   273             tracked_descendants_count: node.tracked_descendants_count.into(),
   274             full_path: write_slice::<u8>(
   274             full_path: write_slice::<u8>(
   275                 full_path.full_path().as_bytes(),
   275                 full_path.full_path().as_bytes(),
   276                 out,
   276                 out,
   277             ),
   277             ),
   285                 Slice {
   285                 Slice {
   286                     start: 0.into(),
   286                     start: 0.into(),
   287                     len: 0.into(),
   287                     len: 0.into(),
   288                 }
   288                 }
   289             },
   289             },
   290             entry: if let Some(entry) = &mut node.entry {
   290             entry: if let Some(entry) = &node.entry {
   291                 OptEntry {
   291                 OptEntry {
   292                     state: entry.state.into(),
   292                     state: entry.state.into(),
   293                     mode: entry.mode.into(),
   293                     mode: entry.mode.into(),
   294                     mtime: entry.mtime.into(),
   294                     mtime: entry.mtime.into(),
   295                     size: entry.size.into(),
   295                     size: entry.size.into(),