rust/hg-core/src/dirstate/dirstate_map.rs
author Pierre-Yves David <pierre-yves.david@octobus.net>
Sat, 03 Jul 2021 19:52:00 +0200
changeset 47511 eaae39894312
parent 47335 ed1583a845d2
child 47521 abed645b8e96
permissions -rw-r--r--
dirstate: move most of the `remove` logic with dirstatemap `removefile` This code deal with special logic to preserving "merged" and "from_p2" information when removing a file. These are implementation details that are more suitable for the dirstatemap layer. Since the dirstatemap layer alreaday have most of the information necessary to do so, the move is easy. This move helps us to encapsulate more implementation details within the dirstatemap and its entry. Easing the use of a different storage for dirstate v2. Differential Revision: https://phab.mercurial-scm.org/D10953
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     1
// dirstate_map.rs
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     2
//
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     3
// Copyright 2019 Raphaël Gomès <rgomes@octobus.net>
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     4
//
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     5
// This software may be used and distributed according to the terms of the
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     6
// GNU General Public License version 2 or any later version.
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     7
47101
5d62243c7732 rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents: 47093
diff changeset
     8
use crate::dirstate::parsers::Timestamp;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
     9
use crate::{
47121
b6339a993b91 rust: Remove handling of `parents` in `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents: 47109
diff changeset
    10
    dirstate::EntryState,
47511
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
    11
    dirstate::SIZE_FROM_OTHER_PARENT,
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
    12
    dirstate::SIZE_NON_NORMAL,
42840
b1b984f9c01d rust-utils: add normalize_case util to mirror Python one
Raphaël Gomès <rgomes@octobus.net>
parents: 42802
diff changeset
    13
    pack_dirstate, parse_dirstate,
47109
33e5511b571a rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents: 47108
diff changeset
    14
    utils::hg_path::{HgPath, HgPathBuf},
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
    15
    CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateParents,
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
    16
    StateMap,
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    17
};
45558
80bf7b1ada15 rust-dirstatemap: add #[timed] to dirstatemap read for comparison
Raphaël Gomès <rgomes@octobus.net>
parents: 45531
diff changeset
    18
use micro_timer::timed;
43826
5ac243a92e37 rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents: 43788
diff changeset
    19
use std::collections::HashSet;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    20
use std::iter::FromIterator;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    21
use std::ops::Deref;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    22
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    23
#[derive(Default)]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    24
pub struct DirstateMap {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    25
    state_map: StateMap,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    26
    pub copy_map: CopyMap,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    27
    pub dirs: Option<DirsMultiset>,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    28
    pub all_dirs: Option<DirsMultiset>,
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
    29
    non_normal_set: Option<HashSet<HgPathBuf>>,
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
    30
    other_parent_set: Option<HashSet<HgPathBuf>>,
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    31
}
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    32
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    33
/// Should only really be used in python interface code, for clarity
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    34
impl Deref for DirstateMap {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    35
    type Target = StateMap;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    36
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    37
    fn deref(&self) -> &Self::Target {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    38
        &self.state_map
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    39
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    40
}
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    41
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
    42
impl FromIterator<(HgPathBuf, DirstateEntry)> for DirstateMap {
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
    43
    fn from_iter<I: IntoIterator<Item = (HgPathBuf, DirstateEntry)>>(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
    44
        iter: I,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
    45
    ) -> Self {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    46
        Self {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    47
            state_map: iter.into_iter().collect(),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    48
            ..Self::default()
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    49
        }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    50
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    51
}
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    52
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    53
impl DirstateMap {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    54
    pub fn new() -> Self {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    55
        Self::default()
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    56
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    57
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    58
    pub fn clear(&mut self) {
45610
496537c9c1b4 rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents: 45588
diff changeset
    59
        self.state_map = StateMap::default();
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    60
        self.copy_map.clear();
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
    61
        self.non_normal_set = None;
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
    62
        self.other_parent_set = None;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    63
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    64
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    65
    /// Add a tracked file to the dirstate
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    66
    pub fn add_file(
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    67
        &mut self,
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
    68
        filename: &HgPath,
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    69
        old_state: EntryState,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    70
        entry: DirstateEntry,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
    71
    ) -> Result<(), DirstateError> {
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
    72
        if old_state == EntryState::Unknown || old_state == EntryState::Removed
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
    73
        {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    74
            if let Some(ref mut dirs) = self.dirs {
43788
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43605
diff changeset
    75
                dirs.add_path(filename)?;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    76
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    77
        }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    78
        if old_state == EntryState::Unknown {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    79
            if let Some(ref mut all_dirs) = self.all_dirs {
43788
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43605
diff changeset
    80
                all_dirs.add_path(filename)?;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    81
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    82
        }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    83
        self.state_map.insert(filename.to_owned(), entry.to_owned());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    84
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
    85
        if entry.is_non_normal() {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
    86
            self.get_non_normal_other_parent_entries()
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
    87
                .0
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
    88
                .insert(filename.to_owned());
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    89
        }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    90
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
    91
        if entry.is_from_other_parent() {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
    92
            self.get_non_normal_other_parent_entries()
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
    93
                .1
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
    94
                .insert(filename.to_owned());
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    95
        }
43788
1fe2e574616e rust-dirs: address failing tests for `dirs` impl with a temporary fix
Raphaël Gomès <rgomes@octobus.net>
parents: 43605
diff changeset
    96
        Ok(())
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    97
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    98
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    99
    /// Mark a file as removed in the dirstate.
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   100
    ///
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   101
    /// The `size` parameter is used to store sentinel values that indicate
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   102
    /// the file's previous state.  In the future, we should refactor this
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   103
    /// to be more explicit about what that state is.
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   104
    pub fn remove_file(
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   105
        &mut self,
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
   106
        filename: &HgPath,
47511
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   107
        in_merge: bool,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   108
    ) -> Result<(), DirstateError> {
47511
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   109
        let old_entry_opt = self.get(filename);
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   110
        let old_state = match old_entry_opt {
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   111
            Some(e) => e.state,
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   112
            None => EntryState::Unknown,
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   113
        };
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   114
        let mut size = 0;
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   115
        if in_merge {
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   116
            // XXX we should not be able to have 'm' state and 'FROM_P2' if not
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   117
            // during a merge. So I (marmoute) am not sure we need the
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   118
            // conditionnal at all. Adding double checking this with assert
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   119
            // would be nice.
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   120
            if let Some(old_entry) = old_entry_opt {
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   121
                // backup the previous state
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   122
                if old_entry.state == EntryState::Merged {
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   123
                    size = SIZE_NON_NORMAL;
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   124
                } else if old_entry.state == EntryState::Normal
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   125
                    && old_entry.size == SIZE_FROM_OTHER_PARENT
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   126
                {
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   127
                    // other parent
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   128
                    size = SIZE_FROM_OTHER_PARENT;
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   129
                    self.get_non_normal_other_parent_entries()
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   130
                        .1
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   131
                        .insert(filename.to_owned());
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   132
                }
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   133
            }
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   134
        }
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   135
        if old_state != EntryState::Unknown && old_state != EntryState::Removed
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   136
        {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   137
            if let Some(ref mut dirs) = self.dirs {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   138
                dirs.delete_path(filename)?;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   139
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   140
        }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   141
        if old_state == EntryState::Unknown {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   142
            if let Some(ref mut all_dirs) = self.all_dirs {
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   143
                all_dirs.add_path(filename)?;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   144
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   145
        }
47511
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   146
        if size == 0 {
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   147
            self.copy_map.remove(filename);
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   148
        }
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   149
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   150
        self.state_map.insert(
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   151
            filename.to_owned(),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   152
            DirstateEntry {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   153
                state: EntryState::Removed,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   154
                mode: 0,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   155
                size,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   156
                mtime: 0,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   157
            },
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   158
        );
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   159
        self.get_non_normal_other_parent_entries()
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   160
            .0
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   161
            .insert(filename.to_owned());
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   162
        Ok(())
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   163
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   164
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   165
    /// Remove a file from the dirstate.
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   166
    /// Returns `true` if the file was previously recorded.
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   167
    pub fn drop_file(
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   168
        &mut self,
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
   169
        filename: &HgPath,
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   170
        old_state: EntryState,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   171
    ) -> Result<bool, DirstateError> {
42795
8d2d5dfa07f5 rust-dirstate: remove too abstracted way of getting &[u8]
Yuya Nishihara <yuya@tcha.org>
parents: 42753
diff changeset
   172
        let exists = self.state_map.remove(filename).is_some();
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   173
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   174
        if exists {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   175
            if old_state != EntryState::Removed {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   176
                if let Some(ref mut dirs) = self.dirs {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   177
                    dirs.delete_path(filename)?;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   178
                }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   179
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   180
            if let Some(ref mut all_dirs) = self.all_dirs {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   181
                all_dirs.delete_path(filename)?;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   182
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   183
        }
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   184
        self.get_non_normal_other_parent_entries()
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   185
            .0
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   186
            .remove(filename);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   187
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   188
        Ok(exists)
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   189
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   190
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   191
    pub fn clear_ambiguous_times(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   192
        &mut self,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   193
        filenames: Vec<HgPathBuf>,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   194
        now: i32,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   195
    ) {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   196
        for filename in filenames {
45610
496537c9c1b4 rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents: 45588
diff changeset
   197
            if let Some(entry) = self.state_map.get_mut(&filename) {
47330
73f23e7610f8 dirstate-tree: Remove DirstateMap::iter_node_data_mut
Simon Sapin <simon.sapin@octobus.net>
parents: 47124
diff changeset
   198
                if entry.clear_ambiguous_mtime(now) {
47105
ba17a2ee85ac dirstate-tree: Add clear_ambiguous_times in the new DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
   199
                    self.get_non_normal_other_parent_entries()
ba17a2ee85ac dirstate-tree: Add clear_ambiguous_times in the new DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
   200
                        .0
ba17a2ee85ac dirstate-tree: Add clear_ambiguous_times in the new DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
   201
                        .insert(filename.to_owned());
45610
496537c9c1b4 rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents: 45588
diff changeset
   202
                }
496537c9c1b4 rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents: 45588
diff changeset
   203
            }
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   204
        }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   205
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   206
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
   207
    pub fn non_normal_entries_remove(&mut self, key: impl AsRef<HgPath>) {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   208
        self.get_non_normal_other_parent_entries()
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   209
            .0
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
   210
            .remove(key.as_ref());
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   211
    }
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
   212
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   213
    pub fn non_normal_entries_union(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   214
        &mut self,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   215
        other: HashSet<HgPathBuf>,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   216
    ) -> Vec<HgPathBuf> {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   217
        self.get_non_normal_other_parent_entries()
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   218
            .0
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   219
            .union(&other)
44973
26114bd6ec60 rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents: 44416
diff changeset
   220
            .map(ToOwned::to_owned)
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   221
            .collect()
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   222
    }
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   223
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   224
    pub fn get_non_normal_other_parent_entries(
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   225
        &mut self,
44362
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
   226
    ) -> (&mut HashSet<HgPathBuf>, &mut HashSet<HgPathBuf>) {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   227
        self.set_non_normal_other_parent_entries(false);
44362
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
   228
        (
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
   229
            self.non_normal_set.as_mut().unwrap(),
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
   230
            self.other_parent_set.as_mut().unwrap(),
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
   231
        )
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   232
    }
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   233
44416
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   234
    /// Useful to get immutable references to those sets in contexts where
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   235
    /// you only have an immutable reference to the `DirstateMap`, like when
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   236
    /// sharing references with Python.
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   237
    ///
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   238
    /// TODO, get rid of this along with the other "setter/getter" stuff when
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   239
    /// a nice typestate plan is defined.
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   240
    ///
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   241
    /// # Panics
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   242
    ///
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   243
    /// Will panic if either set is `None`.
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   244
    pub fn get_non_normal_other_parent_entries_panic(
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   245
        &self,
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   246
    ) -> (&HashSet<HgPathBuf>, &HashSet<HgPathBuf>) {
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   247
        (
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   248
            self.non_normal_set.as_ref().unwrap(),
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   249
            self.other_parent_set.as_ref().unwrap(),
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   250
        )
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   251
    }
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   252
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   253
    pub fn set_non_normal_other_parent_entries(&mut self, force: bool) {
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   254
        if !force
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   255
            && self.non_normal_set.is_some()
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   256
            && self.other_parent_set.is_some()
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   257
        {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   258
            return;
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   259
        }
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   260
        let mut non_normal = HashSet::new();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   261
        let mut other_parent = HashSet::new();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   262
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
   263
        for (filename, entry) in self.state_map.iter() {
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
   264
            if entry.is_non_normal() {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   265
                non_normal.insert(filename.to_owned());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   266
            }
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
   267
            if entry.is_from_other_parent() {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   268
                other_parent.insert(filename.to_owned());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   269
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   270
        }
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   271
        self.non_normal_set = Some(non_normal);
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   272
        self.other_parent_set = Some(other_parent);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   273
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   274
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   275
    /// Both of these setters and their uses appear to be the simplest way to
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   276
    /// emulate a Python lazy property, but it is ugly and unidiomatic.
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   277
    /// TODO One day, rewriting this struct using the typestate might be a
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   278
    /// good idea.
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   279
    pub fn set_all_dirs(&mut self) -> Result<(), DirstateError> {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   280
        if self.all_dirs.is_none() {
47093
787ff5d21bcd dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
   281
            self.all_dirs = Some(DirsMultiset::from_dirstate(
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   282
                self.state_map.iter().map(|(k, v)| Ok((k, *v))),
47093
787ff5d21bcd dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
   283
                None,
787ff5d21bcd dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
   284
            )?);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   285
        }
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   286
        Ok(())
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   287
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   288
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   289
    pub fn set_dirs(&mut self) -> Result<(), DirstateError> {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   290
        if self.dirs.is_none() {
42802
2e1f74cc3350 rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents: 42801
diff changeset
   291
            self.dirs = Some(DirsMultiset::from_dirstate(
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   292
                self.state_map.iter().map(|(k, v)| Ok((k, *v))),
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   293
                Some(EntryState::Removed),
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   294
            )?);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   295
        }
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   296
        Ok(())
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   297
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   298
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   299
    pub fn has_tracked_dir(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   300
        &mut self,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   301
        directory: &HgPath,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   302
    ) -> Result<bool, DirstateError> {
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   303
        self.set_dirs()?;
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   304
        Ok(self.dirs.as_ref().unwrap().contains(directory))
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   305
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   306
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   307
    pub fn has_dir(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   308
        &mut self,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   309
        directory: &HgPath,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   310
    ) -> Result<bool, DirstateError> {
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   311
        self.set_all_dirs()?;
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   312
        Ok(self.all_dirs.as_ref().unwrap().contains(directory))
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   313
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   314
45558
80bf7b1ada15 rust-dirstatemap: add #[timed] to dirstatemap read for comparison
Raphaël Gomès <rgomes@octobus.net>
parents: 45531
diff changeset
   315
    #[timed]
47123
d8ac62374943 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   316
    pub fn read(
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   317
        &mut self,
47123
d8ac62374943 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   318
        file_contents: &[u8],
d8ac62374943 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   319
    ) -> Result<Option<DirstateParents>, DirstateError> {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   320
        if file_contents.is_empty() {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   321
            return Ok(None);
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   322
        }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   323
45357
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   324
        let (parents, entries, copies) = parse_dirstate(file_contents)?;
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   325
        self.state_map.extend(
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   326
            entries
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   327
                .into_iter()
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   328
                .map(|(path, entry)| (path.to_owned(), entry)),
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   329
        );
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   330
        self.copy_map.extend(
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   331
            copies
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   332
                .into_iter()
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   333
                .map(|(path, copy)| (path.to_owned(), copy.to_owned())),
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   334
        );
47123
d8ac62374943 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   335
        Ok(Some(parents.clone()))
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   336
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   337
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   338
    pub fn pack(
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   339
        &mut self,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   340
        parents: DirstateParents,
47101
5d62243c7732 rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents: 47093
diff changeset
   341
        now: Timestamp,
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   342
    ) -> Result<Vec<u8>, DirstateError> {
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   343
        let packed =
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   344
            pack_dirstate(&mut self.state_map, &self.copy_map, parents, now)?;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   345
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   346
        self.set_non_normal_other_parent_entries(true);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   347
        Ok(packed)
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   348
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   349
}
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   350
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   351
#[cfg(test)]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   352
mod tests {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   353
    use super::*;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   354
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   355
    #[test]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   356
    fn test_dirs_multiset() {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   357
        let mut map = DirstateMap::new();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   358
        assert!(map.dirs.is_none());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   359
        assert!(map.all_dirs.is_none());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   360
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   361
        assert_eq!(map.has_dir(HgPath::new(b"nope")).unwrap(), false);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   362
        assert!(map.all_dirs.is_some());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   363
        assert!(map.dirs.is_none());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   364
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   365
        assert_eq!(map.has_tracked_dir(HgPath::new(b"nope")).unwrap(), false);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   366
        assert!(map.dirs.is_some());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   367
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   368
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   369
    #[test]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   370
    fn test_add_file() {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   371
        let mut map = DirstateMap::new();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   372
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   373
        assert_eq!(0, map.len());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   374
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   375
        map.add_file(
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
   376
            HgPath::new(b"meh"),
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   377
            EntryState::Normal,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   378
            DirstateEntry {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   379
                state: EntryState::Normal,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   380
                mode: 1337,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   381
                mtime: 1337,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   382
                size: 1337,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   383
            },
43890
d8a96cebf75d rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents: 43863
diff changeset
   384
        )
d8a96cebf75d rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents: 43863
diff changeset
   385
        .unwrap();
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   386
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   387
        assert_eq!(1, map.len());
44362
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
   388
        assert_eq!(0, map.get_non_normal_other_parent_entries().0.len());
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
   389
        assert_eq!(0, map.get_non_normal_other_parent_entries().1.len());
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   390
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   391
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   392
    #[test]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   393
    fn test_non_normal_other_parent_entries() {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   394
        let mut map: DirstateMap = [
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   395
            (b"f1", (EntryState::Removed, 1337, 1337, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   396
            (b"f2", (EntryState::Normal, 1337, 1337, -1)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   397
            (b"f3", (EntryState::Normal, 1337, 1337, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   398
            (b"f4", (EntryState::Normal, 1337, -2, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   399
            (b"f5", (EntryState::Added, 1337, 1337, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   400
            (b"f6", (EntryState::Added, 1337, 1337, -1)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   401
            (b"f7", (EntryState::Merged, 1337, 1337, -1)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   402
            (b"f8", (EntryState::Merged, 1337, 1337, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   403
            (b"f9", (EntryState::Merged, 1337, -2, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   404
            (b"fa", (EntryState::Added, 1337, -2, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   405
            (b"fb", (EntryState::Removed, 1337, -2, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   406
        ]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   407
        .iter()
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   408
        .map(|(fname, (state, mode, size, mtime))| {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   409
            (
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
   410
                HgPathBuf::from_bytes(fname.as_ref()),
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   411
                DirstateEntry {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   412
                    state: *state,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   413
                    mode: *mode,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   414
                    size: *size,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   415
                    mtime: *mtime,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   416
                },
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   417
            )
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   418
        })
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   419
        .collect();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   420
44362
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
   421
        let mut non_normal = [
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   422
            b"f1", b"f2", b"f5", b"f6", b"f7", b"f8", b"f9", b"fa", b"fb",
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   423
        ]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   424
        .iter()
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
   425
        .map(|x| HgPathBuf::from_bytes(x.as_ref()))
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   426
        .collect();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   427
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   428
        let mut other_parent = HashSet::new();
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
   429
        other_parent.insert(HgPathBuf::from_bytes(b"f4"));
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   430
        let entries = map.get_non_normal_other_parent_entries();
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   431
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   432
        assert_eq!(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   433
            (&mut non_normal, &mut other_parent),
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   434
            (entries.0, entries.1)
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   435
        );
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   436
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   437
}