Patchwork D10766: rhg: A missing .hg/dirstate file is not an error

login
register
mail settings
Submitter phabricator
Date May 22, 2021, 5:39 p.m.
Message ID <differential-rev-PHID-DREV-sd3faojlzt6clvnxfwe6-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49085/
State Superseded
Headers show

Comments

phabricator - May 22, 2021, 5:39 p.m.
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Instead treat it as like an empty file

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  rust/rhg/src/commands/status.rs

CHANGE DETAILS




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

Patch

diff --git a/rust/rhg/src/commands/status.rs b/rust/rhg/src/commands/status.rs
--- a/rust/rhg/src/commands/status.rs
+++ b/rust/rhg/src/commands/status.rs
@@ -9,6 +9,7 @@ 
 use crate::ui::Ui;
 use clap::{Arg, SubCommand};
 use hg;
+use hg::errors::HgResultExt;
 use hg::errors::IoResultExt;
 use hg::matchers::AlwaysMatcher;
 use hg::operations::cat;
@@ -164,8 +165,13 @@ 
 
     let repo = invocation.repo?;
     let mut dmap = DirstateMap::new();
-    let dirstate_data = repo.hg_vfs().mmap_open("dirstate")?;
-    let parents = dmap.read(&dirstate_data)?;
+    let dirstate_data =
+        repo.hg_vfs().mmap_open("dirstate").io_not_found_as_none()?;
+    let dirstate_data = match &dirstate_data {
+        Some(mmap) => &**mmap,
+        None => b"",
+    };
+    let parents = dmap.read(dirstate_data)?;
     let options = StatusOptions {
         // TODO should be provided by the dirstate parsing and
         // hence be stored on dmap. Using a value that assumes we aren't