Patchwork D10368: dirstate-tree: Add parsing only dirstate parents from disk

login
register
mail settings
Submitter phabricator
Date April 12, 2021, 12:24 p.m.
Message ID <differential-rev-PHID-DREV-ax5zl2teeuj5ku3ehvza-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48682/
State Superseded
Headers show

Comments

phabricator - April 12, 2021, 12:24 p.m.
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10368

AFFECTED FILES
  rust/hg-core/src/dirstate_tree/dirstate_map.rs

CHANGE DETAILS




To: SimonSapin, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/rust/hg-core/src/dirstate_tree/dirstate_map.rs b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
--- a/rust/hg-core/src/dirstate_tree/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate_tree/dirstate_map.rs
@@ -3,8 +3,8 @@ 
 use std::time::Duration;
 
 use super::path_with_basename::WithBasename;
+use crate::dirstate::parsers::{parse_dirstate, parse_dirstate_parents};
 
-use crate::dirstate::parsers::parse_dirstate;
 use crate::matchers::Matcher;
 use crate::revlog::node::NULL_NODE;
 use crate::utils::hg_path::{HgPath, HgPathBuf};
@@ -175,9 +175,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) {