changeset 47379:d2fb8b4adcc3

rhg: Remove some intermediate Vecs in `rhg files` Instead of calling `parse_dirstate` which then calls `parse_dirstate_entries`, call the latter directly in order to skip some intermediate steps. Differential Revision: https://phab.mercurial-scm.org/D10803
author Simon Sapin <simon.sapin@octobus.net>
date Wed, 26 May 2021 11:53:37 +0200
parents 9e6e12e1a87e
children bd88b6bfd8da
files rust/hg-core/src/operations/list_tracked_files.rs
diffstat 1 files changed, 11 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/operations/list_tracked_files.rs	Tue Jun 01 15:19:08 2021 -0700
+++ b/rust/hg-core/src/operations/list_tracked_files.rs	Wed May 26 11:53:37 2021 +0200
@@ -5,7 +5,7 @@
 // This software may be used and distributed according to the terms of the
 // GNU General Public License version 2 or any later version.
 
-use crate::dirstate::parsers::parse_dirstate;
+use crate::dirstate::parsers::parse_dirstate_entries;
 use crate::errors::HgError;
 use crate::repo::Repo;
 use crate::revlog::changelog::Changelog;
@@ -13,7 +13,6 @@
 use crate::revlog::node::Node;
 use crate::revlog::revlog::RevlogError;
 use crate::utils::hg_path::HgPath;
-use crate::EntryState;
 use rayon::prelude::*;
 
 /// List files under Mercurial control in the working directory
@@ -30,14 +29,16 @@
     }
 
     pub fn tracked_files(&self) -> Result<Vec<&HgPath>, HgError> {
-        let (_, entries, _) = parse_dirstate(&self.content)?;
-        let mut files: Vec<&HgPath> = entries
-            .into_iter()
-            .filter_map(|(path, entry)| match entry.state {
-                EntryState::Removed => None,
-                _ => Some(path),
-            })
-            .collect();
+        let mut files = Vec::new();
+        let _parents = parse_dirstate_entries(
+            &self.content,
+            |path, entry, _copy_source| {
+                if entry.state.is_tracked() {
+                    files.push(path)
+                }
+                Ok(())
+            },
+        )?;
         files.par_sort_unstable();
         Ok(files)
     }