rust/hg-core/src/dirstate/dirstate_map.rs
author Pierre-Yves David <pierre-yves.david@octobus.net>
Tue, 28 Sep 2021 20:05:37 +0200
changeset 48061 060cd909439f
parent 48056 cd13d3c2ad2e
permissions -rw-r--r--
dirstate: drop all logic around the "non-normal" sets The dirstate has a lot of code to compute a set of all "non-normal" and "from_other_parent" entries. This is all used in one, unique, location, when `setparent` is called and moved from a merge to a non merge. At that time, any "merge related" information has to be dropped. This is mostly useful for command like `graft` or `shelve` that move to a single-parent state -before- the commit. Otherwise the commit will already have removed all traces of the merge information in the dirstate (e.g. for a regular merges). The bookkeeping for these sets is quite invasive. And it seems simpler to just drop it and do the full computation in the single location where we actually use it (since we have to do the computation at least once anyway). This simplify the code a lot, and clarify why this kind of computation is needed. The possible drawback compared to the previous code are: - if the operation happens in a loop, we will end up doing it multiple time, - the C code to detect entry of interest have been dropped, for now. It will be re-introduced later, with a processing code directly in C for even faster operation. Differential Revision: https://phab.mercurial-scm.org/D11507
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;
48061
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
     9
use crate::errors::HgError;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    10
use crate::{
47121
b6339a993b91 rust: Remove handling of `parents` in `DirstateMap`
Simon Sapin <simon.sapin@octobus.net>
parents: 47109
diff changeset
    11
    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
    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,
42840
b1b984f9c01d rust-utils: add normalize_case util to mirror Python one
Raphaël Gomès <rgomes@octobus.net>
parents: 42802
diff changeset
    14
    pack_dirstate, parse_dirstate,
47109
33e5511b571a rust: Remove DirstateMap::file_fold_map
Simon Sapin <simon.sapin@octobus.net>
parents: 47108
diff changeset
    15
    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
    16
    CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateParents,
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
    17
    StateMap,
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    18
};
45558
80bf7b1ada15 rust-dirstatemap: add #[timed] to dirstatemap read for comparison
Raphaël Gomès <rgomes@octobus.net>
parents: 45531
diff changeset
    19
use micro_timer::timed;
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>,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    29
}
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    30
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    31
/// 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
    32
impl Deref for DirstateMap {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    33
    type Target = StateMap;
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
    fn deref(&self) -> &Self::Target {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    36
        &self.state_map
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    37
    }
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
42957
7a01778bc7b7 rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents: 42840
diff changeset
    40
impl FromIterator<(HgPathBuf, DirstateEntry)> for DirstateMap {
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
    41
    fn from_iter<I: IntoIterator<Item = (HgPathBuf, DirstateEntry)>>(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
    42
        iter: I,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
    43
    ) -> Self {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    44
        Self {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    45
            state_map: iter.into_iter().collect(),
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    46
            ..Self::default()
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    47
        }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    48
    }
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
impl DirstateMap {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    52
    pub fn new() -> Self {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    53
        Self::default()
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
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    56
    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
    57
        self.state_map = StateMap::default();
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    58
        self.copy_map.clear();
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
48045
32ef647821b2 dirstate: Skip no-op conversion in Rust DirstateMap::set_v1
Simon Sapin <simon.sapin@octobus.net>
parents: 48042
diff changeset
    61
    pub fn set_entry(&mut self, filename: &HgPath, entry: DirstateEntry) {
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
    62
        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
    63
    }
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
    64
42753
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
        entry: DirstateEntry,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
    70
    ) -> Result<(), DirstateError> {
48026
1b2ee68e85f9 rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents: 48022
diff changeset
    71
        let old_state = self.get(filename).map(|e| e.state());
1b2ee68e85f9 rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents: 48022
diff changeset
    72
        if old_state.is_none() || old_state == Some(EntryState::Removed) {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    73
            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
    74
                dirs.add_path(filename)?;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    75
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    76
        }
48026
1b2ee68e85f9 rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents: 48022
diff changeset
    77
        if old_state.is_none() {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    78
            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
    79
                all_dirs.add_path(filename)?;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    80
            }
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
        self.state_map.insert(filename.to_owned(), entry.to_owned());
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
    83
        Ok(())
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    84
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    85
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    86
    /// 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
    87
    ///
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    88
    /// 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
    89
    /// 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
    90
    /// 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
    91
    pub fn remove_file(
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
    92
        &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
    93
        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
    94
        in_merge: bool,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
    95
    ) -> 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
    96
        let old_entry_opt = self.get(filename);
48026
1b2ee68e85f9 rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents: 48022
diff changeset
    97
        let old_state = old_entry_opt.map(|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
    98
        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
    99
        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
   100
            // 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
   101
            // 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
   102
            // 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
   103
            // 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
   104
            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
   105
                // backup the previous state
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   106
                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
   107
                    size = SIZE_NON_NORMAL;
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   108
                } 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
   109
                    && 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
   110
                {
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   111
                    // 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
   112
                    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
   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
            }
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   115
        }
48026
1b2ee68e85f9 rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents: 48022
diff changeset
   116
        if old_state.is_some() && old_state != Some(EntryState::Removed) {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   117
            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
   118
                dirs.delete_path(filename)?;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   119
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   120
        }
48026
1b2ee68e85f9 rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents: 48022
diff changeset
   121
        if old_state.is_none() {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   122
            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
   123
                all_dirs.add_path(filename)?;
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   124
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   125
        }
47511
eaae39894312 dirstate: move most of the `remove` logic with dirstatemap `removefile`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47335
diff changeset
   126
        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
   127
            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
   128
        }
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   129
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   130
        self.state_map
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   131
            .insert(filename.to_owned(), DirstateEntry::new_removed(size));
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   132
        Ok(())
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   133
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   134
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   135
    /// Remove a file from the dirstate.
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   136
    /// Returns `true` if the file was previously recorded.
48050
2ac0e6b23222 dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents: 48048
diff changeset
   137
    pub fn drop_entry_and_copy_source(
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   138
        &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
   139
        filename: &HgPath,
48048
76f1c76186a1 dirstate: Remove return boolean from dirstatemap.dropfile
Simon Sapin <simon.sapin@octobus.net>
parents: 48045
diff changeset
   140
    ) -> Result<(), DirstateError> {
48026
1b2ee68e85f9 rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents: 48022
diff changeset
   141
        let old_state = self.get(filename).map(|e| e.state());
42795
8d2d5dfa07f5 rust-dirstate: remove too abstracted way of getting &[u8]
Yuya Nishihara <yuya@tcha.org>
parents: 42753
diff changeset
   142
        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
   143
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   144
        if exists {
48026
1b2ee68e85f9 rust: Remove EntryState::Unknown
Simon Sapin <simon.sapin@octobus.net>
parents: 48022
diff changeset
   145
            if old_state != Some(EntryState::Removed) {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   146
                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
   147
                    dirs.delete_path(filename)?;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   148
                }
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
            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
   151
                all_dirs.delete_path(filename)?;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   152
            }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   153
        }
48050
2ac0e6b23222 dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents: 48048
diff changeset
   154
        self.copy_map.remove(filename);
2ac0e6b23222 dirstate: Replace dropfile with drop_item_and_copy_source
Simon Sapin <simon.sapin@octobus.net>
parents: 48048
diff changeset
   155
48048
76f1c76186a1 dirstate: Remove return boolean from dirstatemap.dropfile
Simon Sapin <simon.sapin@octobus.net>
parents: 48045
diff changeset
   156
        Ok(())
42753
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
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   159
    /// 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
   160
    /// 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
   161
    /// 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
   162
    /// good idea.
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   163
    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
   164
        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
   165
            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
   166
                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
   167
                false,
47093
787ff5d21bcd dirstate-tree: Make Rust DirstateMap bindings go through a trait object
Simon Sapin <simon.sapin@octobus.net>
parents: 46890
diff changeset
   168
            )?);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   169
        }
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   170
        Ok(())
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   171
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   172
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   173
    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
   174
        if self.dirs.is_none() {
42802
2e1f74cc3350 rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents: 42801
diff changeset
   175
            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
   176
                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
   177
                true,
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   178
            )?);
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   179
        }
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   180
        Ok(())
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   181
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   182
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   183
    pub fn has_tracked_dir(
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   184
        &mut self,
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   185
        directory: &HgPath,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   186
    ) -> Result<bool, DirstateError> {
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   187
        self.set_dirs()?;
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   188
        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
   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 has_dir(
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
        directory: &HgPath,
47335
ed1583a845d2 dirstate-v2: Make more APIs fallible, returning Result
Simon Sapin <simon.sapin@octobus.net>
parents: 47332
diff changeset
   194
    ) -> Result<bool, DirstateError> {
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   195
        self.set_all_dirs()?;
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   196
        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
   197
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   198
45558
80bf7b1ada15 rust-dirstatemap: add #[timed] to dirstatemap read for comparison
Raphaël Gomès <rgomes@octobus.net>
parents: 45531
diff changeset
   199
    #[timed]
47123
d8ac62374943 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   200
    pub fn read(
45588
c35db907363d rust: format with rustfmt
Raphaël Gomès <rgomes@octobus.net>
parents: 45558
diff changeset
   201
        &mut self,
47123
d8ac62374943 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   202
        file_contents: &[u8],
d8ac62374943 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   203
    ) -> Result<Option<DirstateParents>, DirstateError> {
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   204
        if file_contents.is_empty() {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   205
            return Ok(None);
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   206
        }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   207
45357
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   208
        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
   209
        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
   210
            entries
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   211
                .into_iter()
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   212
                .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
   213
        );
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   214
        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
   215
            copies
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   216
                .into_iter()
27424779c5b8 hg-core: make parse_dirstate return references rather than update hashmaps
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
   217
                .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
   218
        );
47123
d8ac62374943 dirstate-tree: Make `DirstateMap` borrow from a bytes buffer
Simon Sapin <simon.sapin@octobus.net>
parents: 47121
diff changeset
   219
        Ok(Some(parents.clone()))
42753
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
    pub fn pack(
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   223
        &mut self,
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   224
        parents: DirstateParents,
47101
5d62243c7732 rust: Add a Timestamp struct instead of abusing Duration
Simon Sapin <simon.sapin@octobus.net>
parents: 47093
diff changeset
   225
        now: Timestamp,
48061
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   226
    ) -> Result<Vec<u8>, HgError> {
060cd909439f dirstate: drop all logic around the "non-normal" sets
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 48056
diff changeset
   227
        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
   228
    }
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
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   231
#[cfg(test)]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   232
mod tests {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   233
    use super::*;
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   234
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   235
    #[test]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   236
    fn test_dirs_multiset() {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   237
        let mut map = DirstateMap::new();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   238
        assert!(map.dirs.is_none());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   239
        assert!(map.all_dirs.is_none());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   240
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   241
        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
   242
        assert!(map.all_dirs.is_some());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   243
        assert!(map.dirs.is_none());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   244
43863
bc7d8f45c3b6 rust-dirs: handle forgotten `Result`s
Raphaël Gomès <rgomes@octobus.net>
parents: 43826
diff changeset
   245
        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
   246
        assert!(map.dirs.is_some());
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
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   249
    #[test]
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   250
    fn test_add_file() {
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   251
        let mut map = DirstateMap::new();
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   252
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   253
        assert_eq!(0, map.len());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   254
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   255
        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
   256
            HgPath::new(b"meh"),
48022
f2a9db29cb2d rust: Make the fields of DirstateEntry private
Simon Sapin <simon.sapin@octobus.net>
parents: 47944
diff changeset
   257
            DirstateEntry::from_v1_data(EntryState::Normal, 1337, 1337, 1337),
43890
d8a96cebf75d rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents: 43863
diff changeset
   258
        )
d8a96cebf75d rust-warnings: fix warnings in tests
Raphaël Gomès <rgomes@octobus.net>
parents: 43863
diff changeset
   259
        .unwrap();
42753
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   260
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   261
        assert_eq!(1, map.len());
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   262
    }
fce6dc93a510 rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff changeset
   263
}