D7301: rust: introduce SIZE_FROM_OTHER_PARENT constant

Alphare (Raphaël Gomès) phabricator at mercurial-scm.org
Thu Nov 7 10:19:58 UTC 2019


Alphare created this revision.
Herald added subscribers: mercurial-devel, kevincox, durin42.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This will clarify what `-2` meant in the codebase.
  This change also merged imports in affected files for cleanup.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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

CHANGE DETAILS

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
@@ -9,9 +9,14 @@
 //! It is currently missing a lot of functionality compared to the Python one
 //! and will only be triggered in narrow cases.
 
-use crate::utils::files::HgMetadata;
-use crate::utils::hg_path::{hg_path_to_path_buf, HgPath};
-use crate::{CopyMap, DirstateEntry, DirstateMap, EntryState};
+use crate::{
+    dirstate::SIZE_FROM_OTHER_PARENT,
+    utils::{
+        files::HgMetadata,
+        hg_path::{hg_path_to_path_buf, HgPath},
+    },
+    CopyMap, DirstateEntry, DirstateMap, EntryState,
+};
 use rayon::prelude::*;
 use std::path::Path;
 
@@ -71,7 +76,7 @@
             let mode_changed =
                 (mode ^ st_mode as i32) & 0o100 != 0o000 && check_exec;
             let metadata_changed = size >= 0 && (size_changed || mode_changed);
-            let other_parent = size == -2;
+            let other_parent = size == SIZE_FROM_OTHER_PARENT;
             if metadata_changed
                 || other_parent
                 || copy_map.contains_key(filename.as_ref())
diff --git a/rust/hg-core/src/dirstate/dirstate_map.rs b/rust/hg-core/src/dirstate/dirstate_map.rs
--- a/rust/hg-core/src/dirstate/dirstate_map.rs
+++ b/rust/hg-core/src/dirstate/dirstate_map.rs
@@ -5,11 +5,13 @@
 // 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::utils::hg_path::{HgPath, HgPathBuf};
 use crate::{
-    dirstate::{parsers::PARENT_SIZE, EntryState},
+    dirstate::{parsers::PARENT_SIZE, EntryState, SIZE_FROM_OTHER_PARENT},
     pack_dirstate, parse_dirstate,
-    utils::files::normalize_case,
+    utils::{
+        files::normalize_case,
+        hg_path::{HgPath, HgPathBuf},
+    },
     CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateMapError,
     DirstateParents, DirstateParseError, StateMap,
 };
@@ -24,7 +26,6 @@
 
 const NULL_ID: [u8; 20] = [0; 20];
 const MTIME_UNSET: i32 = -1;
-const SIZE_DIRTY: i32 = -2;
 
 #[derive(Default)]
 pub struct DirstateMap {
@@ -100,7 +101,7 @@
             self.non_normal_set.insert(filename.to_owned());
         }
 
-        if entry.size == SIZE_DIRTY {
+        if entry.size == SIZE_FROM_OTHER_PARENT {
             self.other_parent_set.insert(filename.to_owned());
         }
     }
@@ -212,7 +213,8 @@
             if *state != EntryState::Normal || *mtime == MTIME_UNSET {
                 non_normal.insert(filename.to_owned());
             }
-            if *state == EntryState::Normal && *size == SIZE_DIRTY {
+            if *state == EntryState::Normal && *size == SIZE_FROM_OTHER_PARENT
+            {
                 other_parent.insert(filename.to_owned());
             }
         }
diff --git a/rust/hg-core/src/dirstate.rs b/rust/hg-core/src/dirstate.rs
--- a/rust/hg-core/src/dirstate.rs
+++ b/rust/hg-core/src/dirstate.rs
@@ -32,6 +32,11 @@
     pub size: i32,
 }
 
+/// A `DirstateEntry` with a size of `-2` means that it was merged from the
+/// other parent. This allows revert to pick the right status back during a
+/// merge.
+pub const SIZE_FROM_OTHER_PARENT: i32 = -2;
+
 pub type StateMap = HashMap<HgPathBuf, DirstateEntry>;
 pub type StateMapIter<'a> = hash_map::Iter<'a, HgPathBuf, DirstateEntry>;
 pub type CopyMap = HashMap<HgPathBuf, HgPathBuf>;



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


More information about the Mercurial-devel mailing list