Patchwork D7927: rust-status: add util for listing a directory

login
register
mail settings
Submitter phabricator
Date Feb. 6, 2020, 3:16 p.m.
Message ID <1c216676aa2d2a5b2f219f1305b763fa@localhost.localdomain>
Download mbox | patch
Permalink /patch/44982/
State Not Applicable
Headers show

Comments

phabricator - Feb. 6, 2020, 3:16 p.m.
Alphare updated this revision to Diff 19942.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7927?vs=19416&id=19942

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7927/new/

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

AFFECTED FILES
  rust/hg-core/src/dirstate/status.rs

CHANGE DETAILS




To: Alphare, #hg-reviewers, marmoute
Cc: marmoute, durin42, kevincox, mercurial-devel

Patch

diff --git a/rust/hg-core/src/dirstate/status.rs b/rust/hg-core/src/dirstate/status.rs
--- a/rust/hg-core/src/dirstate/status.rs
+++ b/rust/hg-core/src/dirstate/status.rs
@@ -14,12 +14,15 @@ 
     matchers::Matcher,
     utils::{
         files::HgMetadata,
-        hg_path::{hg_path_to_path_buf, HgPath},
+        hg_path::{
+            hg_path_to_path_buf, os_string_to_hg_path_buf, HgPath, HgPathBuf,
+        },
     },
     CopyMap, DirstateEntry, DirstateMap, EntryState,
 };
 use rayon::prelude::*;
 use std::collections::HashSet;
+use std::fs::{read_dir, DirEntry};
 use std::path::Path;
 
 /// Marker enum used to dispatch new status entries into the right collections.
@@ -48,6 +51,32 @@ 
     a & i32::max_value() != b & i32::max_value()
 }
 
+/// Return a sorted list containing information about the entries
+/// in the directory.
+///
+/// * `skip_dot_hg` - Return an empty vec if `path` contains a `.hg` directory
+fn list_directory(
+    path: impl AsRef<Path>,
+    skip_dot_hg: bool,
+) -> std::io::Result<Vec<(HgPathBuf, DirEntry)>> {
+    let mut results = vec![];
+    let entries = read_dir(path.as_ref())?;
+
+    for entry in entries {
+        let entry = entry?;
+        let filename = os_string_to_hg_path_buf(entry.file_name())?;
+        let file_type = entry.file_type()?;
+        if skip_dot_hg && filename.as_bytes() == b".hg" && file_type.is_dir() {
+            return Ok(vec![]);
+        } else {
+            results.push((HgPathBuf::from(filename), entry))
+        }
+    }
+
+    results.sort_by(|a, b| a.0.cmp(&b.0));
+    Ok(results)
+}
+
 /// The file corresponding to the dirstate entry was found on the filesystem.
 fn dispatch_found(
     filename: impl AsRef<HgPath>,