rust/hg-core/src/dirstate_tree/dirstate_map.rs
changeset 47102 d6c94ca40863
parent 47101 5d62243c7732
child 47103 214ae40e136b
equal deleted inserted replaced
47101:5d62243c7732 47102:d6c94ca40863
     1 use std::collections::BTreeMap;
     1 use bytes_cast::BytesCast;
     2 use std::path::PathBuf;
     2 use std::path::PathBuf;
       
     3 use std::{collections::BTreeMap, convert::TryInto};
     3 
     4 
     4 use super::path_with_basename::WithBasename;
     5 use super::path_with_basename::WithBasename;
       
     6 use crate::dirstate::parsers::clear_ambiguous_mtime;
       
     7 use crate::dirstate::parsers::pack_entry;
       
     8 use crate::dirstate::parsers::packed_entry_size;
     5 use crate::dirstate::parsers::parse_dirstate_entries;
     9 use crate::dirstate::parsers::parse_dirstate_entries;
     6 use crate::dirstate::parsers::parse_dirstate_parents;
    10 use crate::dirstate::parsers::parse_dirstate_parents;
     7 use crate::dirstate::parsers::Timestamp;
    11 use crate::dirstate::parsers::Timestamp;
     8 
       
     9 use crate::matchers::Matcher;
    12 use crate::matchers::Matcher;
    10 use crate::revlog::node::NULL_NODE;
    13 use crate::revlog::node::NULL_NODE;
    11 use crate::utils::hg_path::{HgPath, HgPathBuf};
    14 use crate::utils::hg_path::{HgPath, HgPathBuf};
    12 use crate::CopyMapIter;
    15 use crate::CopyMapIter;
    13 use crate::DirstateEntry;
    16 use crate::DirstateEntry;
   325         Ok(Some(parents))
   328         Ok(Some(parents))
   326     }
   329     }
   327 
   330 
   328     fn pack(
   331     fn pack(
   329         &mut self,
   332         &mut self,
   330         _parents: DirstateParents,
   333         parents: DirstateParents,
   331         _now: Timestamp,
   334         now: Timestamp,
   332     ) -> Result<Vec<u8>, DirstateError> {
   335     ) -> Result<Vec<u8>, DirstateError> {
   333         let _ = self.iter_node_data_mut();
   336         // Optizimation (to be measured?): pre-compute size to avoid `Vec`
   334         todo!()
   337         // reallocations
       
   338         let mut size = parents.as_bytes().len();
       
   339         for (path, node) in self.iter_nodes() {
       
   340             if node.entry.is_some() {
       
   341                 size += packed_entry_size(
       
   342                     path.full_path(),
       
   343                     node.copy_source.as_ref(),
       
   344                 )
       
   345             }
       
   346         }
       
   347 
       
   348         let mut packed = Vec::with_capacity(size);
       
   349         packed.extend(parents.as_bytes());
       
   350 
       
   351         let now: i32 = now.0.try_into().expect("time overflow");
       
   352         for (path, opt_entry, copy_source) in self.iter_node_data_mut() {
       
   353             if let Some(entry) = opt_entry {
       
   354                 clear_ambiguous_mtime(entry, now);
       
   355                 pack_entry(
       
   356                     path.full_path(),
       
   357                     entry,
       
   358                     copy_source.as_ref(),
       
   359                     &mut packed,
       
   360                 );
       
   361             }
       
   362         }
       
   363         self.dirty_parents = false;
       
   364         Ok(packed)
   335     }
   365     }
   336 
   366 
   337     fn build_file_fold_map(&mut self) -> &FastHashMap<HgPathBuf, HgPathBuf> {
   367     fn build_file_fold_map(&mut self) -> &FastHashMap<HgPathBuf, HgPathBuf> {
   338         todo!()
   368         todo!()
   339     }
   369     }