rust/hg-core/src/dirstate/dirstate_map.rs
author Simon Sapin <simon.sapin@octobus.net>
Fri, 17 Sep 2021 13:33:45 +0200
changeset 48022 f2a9db29cb2d
parent 47944 e02f9af7aed1
child 48026 1b2ee68e85f9
permissions -rw-r--r--
rust: Make the fields of DirstateEntry private This is a first step toward making its internal structure equivalent to Python’s DirstateItem. Differential Revision: https://phab.mercurial-scm.org/D11461
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,
47521
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47511
diff changeset
    11
    dirstate::MTIME_UNSET,
47511
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_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
    13
    dirstate::SIZE_NON_NORMAL,
47521
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47511
diff changeset
    14
    dirstate::V1_RANGEMASK,
42840
b1b984f9c01d rust-utils: add normalize_case util to mirror Python one
Raphaël Gomès <rgomes@octobus.net>
parents: 42802
diff changeset
    15
    pack_dirstate, parse_dirstate,
47109
33e5511b571a rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents: 47108
diff changeset
    16
    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
    17
    CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateParents,
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
    18
    StateMap,
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    19
};
45558
80bf7b1ada15 rust-dirstatemap: add #[timed] to dirstatemap read for comparison
Raphaël Gomès <rgomes@octobus.net>
parents: 45531
diff changeset
    20
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
    21
use std::collections::HashSet;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    22
use std::iter::FromIterator;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    23
use std::ops::Deref;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    24
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    25
#[derive(Default)]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    26
pub struct DirstateMap {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    27
    state_map: StateMap,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    28
    pub copy_map: CopyMap,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    29
    pub dirs: Option<DirsMultiset>,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    30
    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
    31
    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
    32
    other_parent_set: Option<HashSet<HgPathBuf>>,
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    33
}
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    34
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    35
/// 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
    36
impl Deref for DirstateMap {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    37
    type Target = StateMap;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    38
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    39
    fn deref(&self) -> &Self::Target {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    40
        &self.state_map
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    41
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    42
}
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    43
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
    44
impl FromIterator<(HgPathBuf, DirstateEntry)> for DirstateMap {
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
    45
    fn from_iter<I: IntoIterator<Item = (HgPathBuf, DirstateEntry)>>(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
    46
        iter: I,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
    47
    ) -> Self {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    48
        Self {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    49
            state_map: iter.into_iter().collect(),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    50
            ..Self::default()
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
}
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    54
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    55
impl DirstateMap {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    56
    pub fn new() -> Self {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    57
        Self::default()
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    58
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    59
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    60
    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
    61
        self.state_map = StateMap::default();
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    62
        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
    63
        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
    64
        self.other_parent_set = None;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    65
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    66
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47535
diff changeset
    67
    pub fn set_v1_inner(&mut self, filename: &HgPath, entry: DirstateEntry) {
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47535
diff changeset
    68
        self.state_map.insert(filename.to_owned(), entry);
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47535
diff changeset
    69
    }
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47535
diff changeset
    70
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    71
    /// Add a tracked file to the dirstate
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    72
    pub fn add_file(
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    73
        &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
    74
        filename: &HgPath,
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    75
        entry: DirstateEntry,
47521
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47511
diff changeset
    76
        // XXX once the dust settle this should probably become an enum
47525
fe4641cf9b72 dirstate: use a `added` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47524
diff changeset
    77
        added: bool,
47527
c6b91a9c242a dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47525
diff changeset
    78
        merged: bool,
47521
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47511
diff changeset
    79
        from_p2: bool,
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47511
diff changeset
    80
        possibly_dirty: bool,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
    81
    ) -> Result<(), DirstateError> {
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
    82
        let state;
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
    83
        let size;
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
    84
        let mtime;
47525
fe4641cf9b72 dirstate: use a `added` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47524
diff changeset
    85
        if added {
47521
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47511
diff changeset
    86
            assert!(!possibly_dirty);
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47511
diff changeset
    87
            assert!(!from_p2);
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
    88
            state = EntryState::Added;
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
    89
            size = SIZE_NON_NORMAL;
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
    90
            mtime = MTIME_UNSET;
47527
c6b91a9c242a dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47525
diff changeset
    91
        } else if merged {
c6b91a9c242a dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47525
diff changeset
    92
            assert!(!possibly_dirty);
c6b91a9c242a dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47525
diff changeset
    93
            assert!(!from_p2);
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
    94
            state = EntryState::Merged;
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
    95
            size = SIZE_FROM_OTHER_PARENT;
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
    96
            mtime = MTIME_UNSET;
47521
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47511
diff changeset
    97
        } else if from_p2 {
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47511
diff changeset
    98
            assert!(!possibly_dirty);
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
    99
            state = EntryState::Normal;
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   100
            size = SIZE_FROM_OTHER_PARENT;
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   101
            mtime = MTIME_UNSET;
47521
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47511
diff changeset
   102
        } else if possibly_dirty {
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   103
            state = EntryState::Normal;
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   104
            size = SIZE_NON_NORMAL;
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   105
            mtime = MTIME_UNSET;
47521
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47511
diff changeset
   106
        } else {
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   107
            state = EntryState::Normal;
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   108
            size = entry.size() & V1_RANGEMASK;
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   109
            mtime = entry.mtime() & V1_RANGEMASK;
47521
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47511
diff changeset
   110
        }
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   111
        let mode = entry.mode();
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   112
        let entry = DirstateEntry::from_v1_data(state, mode, size, mtime);
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   113
47524
69a463a4f193 dirstate: no longer pass the `oldstate` value to the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47521
diff changeset
   114
        let old_state = match self.get(filename) {
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   115
            Some(e) => e.state(),
47524
69a463a4f193 dirstate: no longer pass the `oldstate` value to the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47521
diff changeset
   116
            None => EntryState::Unknown,
69a463a4f193 dirstate: no longer pass the `oldstate` value to the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47521
diff changeset
   117
        };
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   118
        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
   119
        {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   120
            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
   121
                dirs.add_path(filename)?;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   122
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   123
        }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   124
        if old_state == EntryState::Unknown {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   125
            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
   126
                all_dirs.add_path(filename)?;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   127
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   128
        }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   129
        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
   130
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
   131
        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
   132
            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
   133
                .0
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   134
                .insert(filename.to_owned());
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   135
        }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   136
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
   137
        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
   138
            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
   139
                .1
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   140
                .insert(filename.to_owned());
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   141
        }
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
   142
        Ok(())
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   143
    }
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
    /// 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
   146
    ///
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   147
    /// 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
   148
    /// 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
   149
    /// 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
   150
    pub fn remove_file(
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   151
        &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
   152
        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
   153
        in_merge: bool,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   154
    ) -> 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
   155
        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
   156
        let old_state = match old_entry_opt {
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   157
            Some(e) => e.state(),
47511
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   158
            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
   159
        };
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   160
        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
   161
        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
   162
            // 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
   163
            // 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
   164
            // 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
   165
            // 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
   166
            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
   167
                // backup the previous state
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   168
                if old_entry.state() == EntryState::Merged {
47511
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   169
                    size = SIZE_NON_NORMAL;
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   170
                } else if old_entry.state() == EntryState::Normal
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   171
                    && old_entry.size() == SIZE_FROM_OTHER_PARENT
47511
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   172
                {
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   173
                    // 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
   174
                    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
   175
                    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
   176
                        .1
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   177
                        .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
   178
                }
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   179
            }
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   180
        }
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   181
        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
   182
        {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   183
            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
   184
                dirs.delete_path(filename)?;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   185
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   186
        }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   187
        if old_state == EntryState::Unknown {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   188
            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
   189
                all_dirs.add_path(filename)?;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   190
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   191
        }
47511
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   192
        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
   193
            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
   194
        }
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   195
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   196
        self.state_map
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   197
            .insert(filename.to_owned(), DirstateEntry::new_removed(size));
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   198
        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
   199
            .0
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   200
            .insert(filename.to_owned());
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   201
        Ok(())
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   202
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   203
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   204
    /// Remove a file from the dirstate.
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   205
    /// 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
   206
    pub fn drop_file(
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   207
        &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
   208
        filename: &HgPath,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   209
    ) -> Result<bool, DirstateError> {
47535
6025353c9c55 dirstate: no longer pass `oldstate` to the `dropfile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47530
diff changeset
   210
        let old_state = match self.get(filename) {
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   211
            Some(e) => e.state(),
47535
6025353c9c55 dirstate: no longer pass `oldstate` to the `dropfile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47530
diff changeset
   212
            None => EntryState::Unknown,
6025353c9c55 dirstate: no longer pass `oldstate` to the `dropfile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47530
diff changeset
   213
        };
42795
8d2d5dfa07f5 rust-dirstate: remove too abstracted way of getting &[u8]
Yuya Nishihara <yuya@tcha.org>
parents: 42753
diff changeset
   214
        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
   215
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   216
        if exists {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   217
            if old_state != EntryState::Removed {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   218
                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
   219
                    dirs.delete_path(filename)?;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   220
                }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   221
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   222
            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
   223
                all_dirs.delete_path(filename)?;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   224
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   225
        }
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   226
        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
   227
            .0
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   228
            .remove(filename);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   229
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   230
        Ok(exists)
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   231
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   232
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   233
    pub fn clear_ambiguous_times(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   234
        &mut self,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   235
        filenames: Vec<HgPathBuf>,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   236
        now: i32,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   237
    ) {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   238
        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
   239
            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
   240
                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
   241
                    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
   242
                        .0
ba17a2ee85ac dirstate-tree: Add clear_ambiguous_times in the new DirstateMap
Simon Sapin <simon.sapin@octobus.net>
parents: 47101
diff changeset
   243
                        .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
   244
                }
496537c9c1b4 rust: start plugging the dirstate tree behind a feature gate
Raphaël Gomès <rgomes@octobus.net>
parents: 45588
diff changeset
   245
            }
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   246
        }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   247
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   248
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47535
diff changeset
   249
    pub fn non_normal_entries_remove(
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47535
diff changeset
   250
        &mut self,
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47535
diff changeset
   251
        key: impl AsRef<HgPath>,
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47535
diff changeset
   252
    ) -> bool {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   253
        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
   254
            .0
47692
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47535
diff changeset
   255
            .remove(key.as_ref())
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47535
diff changeset
   256
    }
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47535
diff changeset
   257
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47535
diff changeset
   258
    pub fn non_normal_entries_add(&mut self, key: impl AsRef<HgPath>) {
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47535
diff changeset
   259
        self.get_non_normal_other_parent_entries()
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47535
diff changeset
   260
            .0
e5fb14a07866 dirstate-map: move most of `dirstate.update_file` logic in the dsmap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47535
diff changeset
   261
            .insert(key.as_ref().into());
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
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
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   264
    pub fn non_normal_entries_union(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   265
        &mut self,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   266
        other: HashSet<HgPathBuf>,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   267
    ) -> Vec<HgPathBuf> {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   268
        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
   269
            .0
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   270
            .union(&other)
44973
26114bd6ec60 rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents: 44416
diff changeset
   271
            .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
   272
            .collect()
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   273
    }
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   274
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   275
    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
   276
        &mut self,
44362
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
   277
    ) -> (&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
   278
        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
   279
        (
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
   280
            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
   281
            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
   282
        )
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   283
    }
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   284
44416
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   285
    /// 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
   286
    /// 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
   287
    /// 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
   288
    ///
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   289
    /// 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
   290
    /// 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
   291
    ///
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   292
    /// # Panics
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   293
    ///
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   294
    /// 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
   295
    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
   296
        &self,
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   297
    ) -> (&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
   298
        (
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   299
            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
   300
            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
   301
        )
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   302
    }
8ac5726d695d rust-cpython: make `NonNormalEntires` iterable to fix `fsmonitor` (issue6276)
Raphaël Gomès <rgomes@octobus.net>
parents: 44362
diff changeset
   303
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   304
    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
   305
        if !force
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   306
            && self.non_normal_set.is_some()
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   307
            && self.other_parent_set.is_some()
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   308
        {
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   309
            return;
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   310
        }
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   311
        let mut non_normal = HashSet::new();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   312
        let mut other_parent = HashSet::new();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   313
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
   314
        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
   315
            if entry.is_non_normal() {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   316
                non_normal.insert(filename.to_owned());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   317
            }
47108
e3cebe96c0fc dirstate-tree: Add "non normal" and "from other parent" sets
Simon Sapin <simon.sapin@octobus.net>
parents: 47105
diff changeset
   318
            if entry.is_from_other_parent() {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   319
                other_parent.insert(filename.to_owned());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   320
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   321
        }
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   322
        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
   323
        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
   324
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   325
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   326
    /// 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
   327
    /// 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
   328
    /// 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
   329
    /// good idea.
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   330
    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
   331
        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
   332
            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
   333
                self.state_map.iter().map(|(k, v)| Ok((k, *v))),
47944
e02f9af7aed1 pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47692
diff changeset
   334
                false,
47093
787ff5d21bcd dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
   335
            )?);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   336
        }
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   337
        Ok(())
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   338
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   339
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   340
    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
   341
        if self.dirs.is_none() {
42802
2e1f74cc3350 rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents: 42801
diff changeset
   342
            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
   343
                self.state_map.iter().map(|(k, v)| Ok((k, *v))),
47944
e02f9af7aed1 pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47692
diff changeset
   344
                true,
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   345
            )?);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   346
        }
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   347
        Ok(())
42753
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
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   350
    pub fn has_tracked_dir(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   351
        &mut self,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   352
        directory: &HgPath,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   353
    ) -> Result<bool, DirstateError> {
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   354
        self.set_dirs()?;
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   355
        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
   356
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   357
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   358
    pub fn has_dir(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   359
        &mut self,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   360
        directory: &HgPath,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   361
    ) -> Result<bool, DirstateError> {
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   362
        self.set_all_dirs()?;
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   363
        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
   364
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   365
45558
80bf7b1ada15 rust-dirstatemap: add #[timed] to dirstatemap read for comparison
Raphaël Gomès <rgomes@octobus.net>
parents: 45531
diff changeset
   366
    #[timed]
47123
d8ac62374943 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   367
    pub fn read(
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   368
        &mut self,
47123
d8ac62374943 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   369
        file_contents: &[u8],
d8ac62374943 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   370
    ) -> Result<Option<DirstateParents>, DirstateError> {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   371
        if file_contents.is_empty() {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   372
            return Ok(None);
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   373
        }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   374
45357
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   375
        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
   376
        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
   377
            entries
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   378
                .into_iter()
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   379
                .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
   380
        );
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   381
        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
   382
            copies
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   383
                .into_iter()
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   384
                .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
   385
        );
47123
d8ac62374943 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   386
        Ok(Some(parents.clone()))
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   387
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   388
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   389
    pub fn pack(
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   390
        &mut self,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   391
        parents: DirstateParents,
47101
5d62243c7732 rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents: 47093
diff changeset
   392
        now: Timestamp,
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   393
    ) -> Result<Vec<u8>, DirstateError> {
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   394
        let packed =
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   395
            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
   396
44293
83b2b829c94e rust-dirstatemap: cache non normal and other parent set
Raphaël Gomès <rgomes@octobus.net>
parents: 43890
diff changeset
   397
        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
   398
        Ok(packed)
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   399
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   400
}
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   401
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   402
#[cfg(test)]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   403
mod tests {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   404
    use super::*;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   405
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   406
    #[test]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   407
    fn test_dirs_multiset() {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   408
        let mut map = DirstateMap::new();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   409
        assert!(map.dirs.is_none());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   410
        assert!(map.all_dirs.is_none());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   411
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   412
        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
   413
        assert!(map.all_dirs.is_some());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   414
        assert!(map.dirs.is_none());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   415
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   416
        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
   417
        assert!(map.dirs.is_some());
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
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   420
    #[test]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   421
    fn test_add_file() {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   422
        let mut map = DirstateMap::new();
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
        assert_eq!(0, map.len());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   425
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   426
        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
   427
            HgPath::new(b"meh"),
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   428
            DirstateEntry::from_v1_data(EntryState::Normal, 1337, 1337, 1337),
47521
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47511
diff changeset
   429
            false,
abed645b8e96 dirstate: move the handling of special case within the dirstatemap
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47511
diff changeset
   430
            false,
47525
fe4641cf9b72 dirstate: use a `added` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47524
diff changeset
   431
            false,
47527
c6b91a9c242a dirstate: use a `merged` parameter to _addpath
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47525
diff changeset
   432
            false,
43890
d8a96cebf75d rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents: 43863
diff changeset
   433
        )
d8a96cebf75d rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents: 43863
diff changeset
   434
        .unwrap();
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   435
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   436
        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
   437
        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
   438
        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
   439
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   440
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   441
    #[test]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   442
    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
   443
        let mut map: DirstateMap = [
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   444
            (b"f1", (EntryState::Removed, 1337, 1337, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   445
            (b"f2", (EntryState::Normal, 1337, 1337, -1)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   446
            (b"f3", (EntryState::Normal, 1337, 1337, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   447
            (b"f4", (EntryState::Normal, 1337, -2, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   448
            (b"f5", (EntryState::Added, 1337, 1337, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   449
            (b"f6", (EntryState::Added, 1337, 1337, -1)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   450
            (b"f7", (EntryState::Merged, 1337, 1337, -1)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   451
            (b"f8", (EntryState::Merged, 1337, 1337, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   452
            (b"f9", (EntryState::Merged, 1337, -2, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   453
            (b"fa", (EntryState::Added, 1337, -2, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   454
            (b"fb", (EntryState::Removed, 1337, -2, 1337)),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   455
        ]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   456
        .iter()
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   457
        .map(|(fname, (state, mode, size, mtime))| {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   458
            (
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
   459
                HgPathBuf::from_bytes(fname.as_ref()),
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   460
                DirstateEntry::from_v1_data(*state, *mode, *size, *mtime),
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   461
            )
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   462
        })
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   463
        .collect();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   464
44362
c089a0947f3e rust-dirstatemap: directly return `non_normal` and `other_entries`
Raphaël Gomès <rgomes@octobus.net>
parents: 44293
diff changeset
   465
        let mut non_normal = [
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   466
            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
   467
        ]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   468
        .iter()
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
   469
        .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
   470
        .collect();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   471
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   472
        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
   473
        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
   474
        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
   475
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   476
        assert_eq!(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   477
            (&mut non_normal, &mut other_parent),
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   478
            (entries.0, entries.1)
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   479
        );
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   480
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   481
}