diff rust/hg-core/src/revlog/revlog.rs @ 45806:7252f5237352

hg-core: fix path encoding usage 1. Hash encoded path are in `.hg/store/dh` instead of `.hg/store/data`. 2. Path encoded index and data files may not have the same parent path. It is not just about replacing `.i` by `.d` Differential Revision: https://phab.mercurial-scm.org/D9121
author Antoine cezar<acezar@chwitlabs.fr>
date Mon, 28 Sep 2020 17:13:15 +0200
parents be951ca95b08
children 8d6164098782
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/revlog.rs	Mon Oct 26 11:45:32 2020 +0100
+++ b/rust/hg-core/src/revlog/revlog.rs	Mon Sep 28 17:13:15 2020 +0200
@@ -47,7 +47,10 @@
     /// It will also open the associated data file if index and data are not
     /// interleaved.
     #[timed]
-    pub fn open(index_path: &Path) -> Result<Self, RevlogError> {
+    pub fn open(
+        index_path: &Path,
+        data_path: Option<&Path>,
+    ) -> Result<Self, RevlogError> {
         let index_mmap =
             mmap_open(&index_path).map_err(RevlogError::IoError)?;
 
@@ -58,16 +61,17 @@
 
         let index = Index::new(Box::new(index_mmap))?;
 
-        // TODO load data only when needed //
+        let default_data_path = index_path.with_extension("d");
+
         // type annotation required
         // won't recognize Mmap as Deref<Target = [u8]>
         let data_bytes: Option<Box<dyn Deref<Target = [u8]> + Send>> =
             if index.is_inline() {
                 None
             } else {
-                let data_path = index_path.with_extension("d");
+                let data_path = data_path.unwrap_or(&default_data_path);
                 let data_mmap =
-                    mmap_open(&data_path).map_err(RevlogError::IoError)?;
+                    mmap_open(data_path).map_err(RevlogError::IoError)?;
                 Some(Box::new(data_mmap))
             };