changeset 43605:8210c3f46912

rust: introduce SIZE_FROM_OTHER_PARENT constant This will clarify what `-2` meant in the codebase. This change also merged imports in affected files for cleanup. Differential Revision: https://phab.mercurial-scm.org/D7301
author Raphaël Gomès <rgomes@octobus.net>
date Thu, 07 Nov 2019 11:13:31 +0100
parents 51cd86735608
children 14ce03e13508
files rust/hg-core/src/dirstate.rs rust/hg-core/src/dirstate/dirstate_map.rs rust/hg-core/src/dirstate/status.rs
diffstat 3 files changed, 22 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/rust/hg-core/src/dirstate.rs	Thu Nov 07 10:32:26 2019 +0100
+++ b/rust/hg-core/src/dirstate.rs	Thu Nov 07 11:13:31 2019 +0100
@@ -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>;
--- a/rust/hg-core/src/dirstate/dirstate_map.rs	Thu Nov 07 10:32:26 2019 +0100
+++ b/rust/hg-core/src/dirstate/dirstate_map.rs	Thu Nov 07 11:13:31 2019 +0100
@@ -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());
             }
         }
--- a/rust/hg-core/src/dirstate/status.rs	Thu Nov 07 10:32:26 2019 +0100
+++ b/rust/hg-core/src/dirstate/status.rs	Thu Nov 07 11:13:31 2019 +0100
@@ -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;
 
@@ -69,7 +74,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())