changeset 47098:d7631d55da3e

dirstate-tree: Add parsing only dirstate parents from disk Differential Revision: https://phab.mercurial-scm.org/D10368
author Simon Sapin <simon.sapin@octobus.net>
date Tue, 06 Apr 2021 14:29:05 +0200
parents e66ea29e2b1a
children 3da19db33cbc
files rust/hg-core/src/dirstate_tree/dirstate_map.rs
diffstat 1 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Wed Mar 31 18:59:49 2021 +0200
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs	Tue Apr 06 14:29:05 2021 +0200
@@ -3,8 +3,9 @@
 use std::time::Duration;
 
 use super::path_with_basename::WithBasename;
+use crate::dirstate::parsers::parse_dirstate_entries;
+use crate::dirstate::parsers::parse_dirstate_parents;
 
-use crate::dirstate::parsers::parse_dirstate_entries;
 use crate::matchers::Matcher;
 use crate::revlog::node::NULL_NODE;
 use crate::utils::hg_path::{HgPath, HgPathBuf};
@@ -175,9 +176,20 @@
 
     fn parents(
         &mut self,
-        _file_contents: &[u8],
+        file_contents: &[u8],
     ) -> Result<&DirstateParents, DirstateError> {
-        todo!()
+        if self.parents.is_none() {
+            let parents = if !file_contents.is_empty() {
+                parse_dirstate_parents(file_contents)?.clone()
+            } else {
+                DirstateParents {
+                    p1: NULL_NODE,
+                    p2: NULL_NODE,
+                }
+            };
+            self.parents = Some(parents);
+        }
+        Ok(self.parents.as_ref().unwrap())
     }
 
     fn set_parents(&mut self, parents: &DirstateParents) {