Patchwork D10548: dirstate-tree: Ignore FIFOs etc. in the status algorithm

login
register
mail settings
Submitter phabricator
Date May 3, 2021, 10:27 a.m.
Message ID <differential-rev-PHID-DREV-wfgjn24tbgqw76c5ypfk-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48865/
State Superseded
Headers show

Comments

phabricator - May 3, 2021, 10:27 a.m.
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  If a filesystem directory contains anything that is not:
  
  - a "normal" file
  - a symbolic link
  - or a directory
  
  … act as if that directory entry was not there. For example, if that path was
  previously a tracked file, mark it as deleted or removed.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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

CHANGE DETAILS




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

Patch

diff --git a/rust/hg-core/src/dirstate_tree/status.rs b/rust/hg-core/src/dirstate_tree/status.rs
--- a/rust/hg-core/src/dirstate_tree/status.rs
+++ b/rust/hg-core/src/dirstate_tree/status.rs
@@ -125,17 +125,21 @@ 
         dirstate_node: &'tree mut Node,
         has_ignored_ancestor: bool,
     ) {
-        if fs_entry.metadata.is_dir() {
-            if self.options.collect_traversed_dirs {
-                self.outcome.traversed.push(hg_path.into())
-            }
+        let file_type = fs_entry.metadata.file_type();
+        let file_or_symlink = file_type.is_file() || file_type.is_symlink();
+        if !file_or_symlink {
             // If we previously had a file here, it was removed (with
             // `hg rm` or similar) or deleted before it could be
-            // replaced by a directory.
+            // replaced by a directory or something else.
             self.mark_removed_or_deleted_if_file(
                 hg_path,
                 dirstate_node.state(),
             );
+        }
+        if file_type.is_dir() {
+            if self.options.collect_traversed_dirs {
+                self.outcome.traversed.push(hg_path.into())
+            }
             let is_ignored = has_ignored_ancestor || (self.ignore_fn)(hg_path);
             let is_at_repo_root = false;
             self.traverse_fs_directory_and_dirstate(
@@ -146,7 +150,7 @@ 
                 is_at_repo_root,
             );
         } else {
-            if self.matcher.matches(hg_path) {
+            if file_or_symlink && self.matcher.matches(hg_path) {
                 let full_path = Cow::from(hg_path);
                 if let Some(entry) = &dirstate_node.entry {
                     match entry.state {
@@ -259,7 +263,9 @@ 
         fs_entry: &DirEntry,
     ) {
         let hg_path = directory_hg_path.join(&fs_entry.base_name);
-        if fs_entry.metadata.is_dir() {
+        let file_type = fs_entry.metadata.file_type();
+        let file_or_symlink = file_type.is_file() || file_type.is_symlink();
+        if file_type.is_dir() {
             let is_ignored =
                 has_ignored_ancestor || (self.ignore_fn)(&hg_path);
             let traverse_children = if is_ignored {
@@ -287,7 +293,7 @@ 
             if self.options.collect_traversed_dirs {
                 self.outcome.traversed.push(hg_path.into())
             }
-        } else if self.matcher.matches(&hg_path) {
+        } else if file_or_symlink && self.matcher.matches(&hg_path) {
             self.mark_unknown_or_ignored(has_ignored_ancestor, hg_path.into())
         }
     }