author | Raphaël Gomès <rgomes@octobus.net> |
Fri, 29 Nov 2019 18:33:56 +0100 | |
changeset 43832 | 1bb4e9b02984 |
parent 43826 | 5ac243a92e37 |
child 43863 | bc7d8f45c3b6 |
permissions | -rw-r--r-- |
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 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
8 |
use crate::{ |
43605
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
9 |
dirstate::{parsers::PARENT_SIZE, EntryState, SIZE_FROM_OTHER_PARENT}, |
42840
b1b984f9c01d
rust-utils: add normalize_case util to mirror Python one
Raphaël Gomès <rgomes@octobus.net>
parents:
42802
diff
changeset
|
10 |
pack_dirstate, parse_dirstate, |
43605
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
11 |
utils::{ |
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
12 |
files::normalize_case, |
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
13 |
hg_path::{HgPath, HgPathBuf}, |
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
14 |
}, |
42840
b1b984f9c01d
rust-utils: add normalize_case util to mirror Python one
Raphaël Gomès <rgomes@octobus.net>
parents:
42802
diff
changeset
|
15 |
CopyMap, DirsMultiset, DirstateEntry, DirstateError, DirstateMapError, |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
16 |
DirstateParents, DirstateParseError, FastHashMap, StateMap, |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
17 |
}; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
18 |
use core::borrow::Borrow; |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
19 |
use std::collections::HashSet; |
42799
5399532510ae
rust: simply use TryInto to convert slice to array
Yuya Nishihara <yuya@tcha.org>
parents:
42798
diff
changeset
|
20 |
use std::convert::TryInto; |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
21 |
use std::iter::FromIterator; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
22 |
use std::ops::Deref; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
23 |
use std::time::Duration; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
24 |
|
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
25 |
pub type FileFoldMap = FastHashMap<HgPathBuf, HgPathBuf>; |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
26 |
|
42797
1faa2bed47c6
rust-dirstate: rename NULL_REVISION to NULL_ID which isn't a revision number
Yuya Nishihara <yuya@tcha.org>
parents:
42796
diff
changeset
|
27 |
const NULL_ID: [u8; 20] = [0; 20]; |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
28 |
const MTIME_UNSET: i32 = -1; |
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 |
#[derive(Default)] |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
31 |
pub struct DirstateMap { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
32 |
state_map: StateMap, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
33 |
pub copy_map: CopyMap, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
34 |
file_fold_map: Option<FileFoldMap>, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
35 |
pub dirs: Option<DirsMultiset>, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
36 |
pub all_dirs: Option<DirsMultiset>, |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42840
diff
changeset
|
37 |
non_normal_set: HashSet<HgPathBuf>, |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42840
diff
changeset
|
38 |
other_parent_set: HashSet<HgPathBuf>, |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
39 |
parents: Option<DirstateParents>, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
40 |
dirty_parents: bool, |
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 |
/// 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
|
44 |
impl Deref for DirstateMap { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
45 |
type Target = StateMap; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
46 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
47 |
fn deref(&self) -> &Self::Target { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
48 |
&self.state_map |
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 |
|
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42840
diff
changeset
|
52 |
impl FromIterator<(HgPathBuf, DirstateEntry)> for DirstateMap { |
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42840
diff
changeset
|
53 |
fn from_iter<I: IntoIterator<Item = (HgPathBuf, DirstateEntry)>>( |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
54 |
iter: I, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
55 |
) -> Self { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
56 |
Self { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
57 |
state_map: iter.into_iter().collect(), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
58 |
..Self::default() |
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 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
61 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
62 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
63 |
impl DirstateMap { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
64 |
pub fn new() -> Self { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
65 |
Self::default() |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
66 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
67 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
68 |
pub fn clear(&mut self) { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
69 |
self.state_map.clear(); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
70 |
self.copy_map.clear(); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
71 |
self.file_fold_map = None; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
72 |
self.non_normal_set.clear(); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
73 |
self.other_parent_set.clear(); |
42801
1a535313ad1b
rust-dirstate: remove excessive clone() of parameter and return value
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
74 |
self.set_parents(&DirstateParents { |
42797
1faa2bed47c6
rust-dirstate: rename NULL_REVISION to NULL_ID which isn't a revision number
Yuya Nishihara <yuya@tcha.org>
parents:
42796
diff
changeset
|
75 |
p1: NULL_ID, |
1faa2bed47c6
rust-dirstate: rename NULL_REVISION to NULL_ID which isn't a revision number
Yuya Nishihara <yuya@tcha.org>
parents:
42796
diff
changeset
|
76 |
p2: NULL_ID, |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
77 |
}) |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
78 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
79 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
80 |
/// Add a tracked file to the dirstate |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
81 |
pub fn add_file( |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
82 |
&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
|
83 |
filename: &HgPath, |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
84 |
old_state: EntryState, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
85 |
entry: DirstateEntry, |
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
|
86 |
) -> Result<(), DirstateMapError> { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
87 |
if old_state == EntryState::Unknown || old_state == EntryState::Removed |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
88 |
{ |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
89 |
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
|
90 |
dirs.add_path(filename)?; |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
91 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
92 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
93 |
if old_state == EntryState::Unknown { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
94 |
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
|
95 |
all_dirs.add_path(filename)?; |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
96 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
97 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
98 |
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
|
99 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
100 |
if entry.state != EntryState::Normal || entry.mtime == MTIME_UNSET { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
101 |
self.non_normal_set.insert(filename.to_owned()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
102 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
103 |
|
43605
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
104 |
if entry.size == SIZE_FROM_OTHER_PARENT { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
105 |
self.other_parent_set.insert(filename.to_owned()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
106 |
} |
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
|
107 |
Ok(()) |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
108 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
109 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
110 |
/// 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
|
111 |
/// |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
112 |
/// 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
|
113 |
/// 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
|
114 |
/// 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
|
115 |
pub fn remove_file( |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
116 |
&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
|
117 |
filename: &HgPath, |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
118 |
old_state: EntryState, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
119 |
size: i32, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
120 |
) -> Result<(), DirstateMapError> { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
121 |
if old_state != EntryState::Unknown && old_state != EntryState::Removed |
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 |
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
|
124 |
dirs.delete_path(filename)?; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
125 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
126 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
127 |
if old_state == EntryState::Unknown { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
128 |
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
|
129 |
all_dirs.add_path(filename); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
130 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
131 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
132 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
133 |
if let Some(ref mut file_fold_map) = self.file_fold_map { |
42840
b1b984f9c01d
rust-utils: add normalize_case util to mirror Python one
Raphaël Gomès <rgomes@octobus.net>
parents:
42802
diff
changeset
|
134 |
file_fold_map.remove(&normalize_case(filename)); |
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 |
self.state_map.insert( |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
137 |
filename.to_owned(), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
138 |
DirstateEntry { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
139 |
state: EntryState::Removed, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
140 |
mode: 0, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
141 |
size, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
142 |
mtime: 0, |
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 |
self.non_normal_set.insert(filename.to_owned()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
146 |
Ok(()) |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
147 |
} |
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 |
/// Remove a file from the dirstate. |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
150 |
/// 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
|
151 |
pub fn drop_file( |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
152 |
&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
|
153 |
filename: &HgPath, |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
154 |
old_state: EntryState, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
155 |
) -> Result<bool, DirstateMapError> { |
42795
8d2d5dfa07f5
rust-dirstate: remove too abstracted way of getting &[u8]
Yuya Nishihara <yuya@tcha.org>
parents:
42753
diff
changeset
|
156 |
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
|
157 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
158 |
if exists { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
159 |
if old_state != EntryState::Removed { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
160 |
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
|
161 |
dirs.delete_path(filename)?; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
162 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
163 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
164 |
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
|
165 |
all_dirs.delete_path(filename)?; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
166 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
167 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
168 |
if let Some(ref mut file_fold_map) = self.file_fold_map { |
42840
b1b984f9c01d
rust-utils: add normalize_case util to mirror Python one
Raphaël Gomès <rgomes@octobus.net>
parents:
42802
diff
changeset
|
169 |
file_fold_map.remove(&normalize_case(filename)); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
170 |
} |
42795
8d2d5dfa07f5
rust-dirstate: remove too abstracted way of getting &[u8]
Yuya Nishihara <yuya@tcha.org>
parents:
42753
diff
changeset
|
171 |
self.non_normal_set.remove(filename); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
172 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
173 |
Ok(exists) |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
174 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
175 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
176 |
pub fn clear_ambiguous_times( |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
177 |
&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
|
178 |
filenames: Vec<HgPathBuf>, |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
179 |
now: i32, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
180 |
) { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
181 |
for filename in filenames { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
182 |
let mut changed = false; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
183 |
self.state_map |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
184 |
.entry(filename.to_owned()) |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
185 |
.and_modify(|entry| { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
186 |
if entry.state == EntryState::Normal && entry.mtime == now |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
187 |
{ |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
188 |
changed = true; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
189 |
*entry = DirstateEntry { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
190 |
mtime: MTIME_UNSET, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
191 |
..*entry |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
192 |
}; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
193 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
194 |
}); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
195 |
if changed { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
196 |
self.non_normal_set.insert(filename.to_owned()); |
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 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
199 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
200 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
201 |
pub fn non_normal_other_parent_entries( |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
202 |
&self, |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42840
diff
changeset
|
203 |
) -> (HashSet<HgPathBuf>, HashSet<HgPathBuf>) { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
204 |
let mut non_normal = HashSet::new(); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
205 |
let mut other_parent = HashSet::new(); |
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 |
for ( |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
208 |
filename, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
209 |
DirstateEntry { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
210 |
state, size, mtime, .. |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
211 |
}, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
212 |
) in self.state_map.iter() |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
213 |
{ |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
214 |
if *state != EntryState::Normal || *mtime == MTIME_UNSET { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
215 |
non_normal.insert(filename.to_owned()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
216 |
} |
43605
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
217 |
if *state == EntryState::Normal && *size == SIZE_FROM_OTHER_PARENT |
8210c3f46912
rust: introduce SIZE_FROM_OTHER_PARENT constant
Raphaël Gomès <rgomes@octobus.net>
parents:
42957
diff
changeset
|
218 |
{ |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
219 |
other_parent.insert(filename.to_owned()); |
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 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
223 |
(non_normal, other_parent) |
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 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
226 |
/// 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
|
227 |
/// 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
|
228 |
/// 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
|
229 |
/// good idea. |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
230 |
pub fn set_all_dirs(&mut self) { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
231 |
if self.all_dirs.is_none() { |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42801
diff
changeset
|
232 |
self.all_dirs = |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42801
diff
changeset
|
233 |
Some(DirsMultiset::from_dirstate(&self.state_map, None)); |
42753
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 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
236 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
237 |
pub fn set_dirs(&mut self) { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
238 |
if self.dirs.is_none() { |
42802
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42801
diff
changeset
|
239 |
self.dirs = Some(DirsMultiset::from_dirstate( |
2e1f74cc3350
rust-dirstate: split DirsMultiset constructor per input type
Yuya Nishihara <yuya@tcha.org>
parents:
42801
diff
changeset
|
240 |
&self.state_map, |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
241 |
Some(EntryState::Removed), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
242 |
)); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
243 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
244 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
245 |
|
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42840
diff
changeset
|
246 |
pub fn has_tracked_dir(&mut self, directory: &HgPath) -> bool { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
247 |
self.set_dirs(); |
42795
8d2d5dfa07f5
rust-dirstate: remove too abstracted way of getting &[u8]
Yuya Nishihara <yuya@tcha.org>
parents:
42753
diff
changeset
|
248 |
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
|
249 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
250 |
|
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42840
diff
changeset
|
251 |
pub fn has_dir(&mut self, directory: &HgPath) -> bool { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
252 |
self.set_all_dirs(); |
42795
8d2d5dfa07f5
rust-dirstate: remove too abstracted way of getting &[u8]
Yuya Nishihara <yuya@tcha.org>
parents:
42753
diff
changeset
|
253 |
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
|
254 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
255 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
256 |
pub fn parents( |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
257 |
&mut self, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
258 |
file_contents: &[u8], |
42801
1a535313ad1b
rust-dirstate: remove excessive clone() of parameter and return value
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
259 |
) -> Result<&DirstateParents, DirstateError> { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
260 |
if let Some(ref parents) = self.parents { |
42801
1a535313ad1b
rust-dirstate: remove excessive clone() of parameter and return value
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
261 |
return Ok(parents); |
42753
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 |
let parents; |
42798
99dff4264524
rust-dirstate: use PARENT_SIZE constant where appropriate
Yuya Nishihara <yuya@tcha.org>
parents:
42797
diff
changeset
|
264 |
if file_contents.len() == PARENT_SIZE * 2 { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
265 |
parents = DirstateParents { |
42799
5399532510ae
rust: simply use TryInto to convert slice to array
Yuya Nishihara <yuya@tcha.org>
parents:
42798
diff
changeset
|
266 |
p1: file_contents[..PARENT_SIZE].try_into().unwrap(), |
5399532510ae
rust: simply use TryInto to convert slice to array
Yuya Nishihara <yuya@tcha.org>
parents:
42798
diff
changeset
|
267 |
p2: file_contents[PARENT_SIZE..PARENT_SIZE * 2] |
5399532510ae
rust: simply use TryInto to convert slice to array
Yuya Nishihara <yuya@tcha.org>
parents:
42798
diff
changeset
|
268 |
.try_into() |
5399532510ae
rust: simply use TryInto to convert slice to array
Yuya Nishihara <yuya@tcha.org>
parents:
42798
diff
changeset
|
269 |
.unwrap(), |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
270 |
}; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
271 |
} else if file_contents.is_empty() { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
272 |
parents = DirstateParents { |
42797
1faa2bed47c6
rust-dirstate: rename NULL_REVISION to NULL_ID which isn't a revision number
Yuya Nishihara <yuya@tcha.org>
parents:
42796
diff
changeset
|
273 |
p1: NULL_ID, |
1faa2bed47c6
rust-dirstate: rename NULL_REVISION to NULL_ID which isn't a revision number
Yuya Nishihara <yuya@tcha.org>
parents:
42796
diff
changeset
|
274 |
p2: NULL_ID, |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
275 |
}; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
276 |
} else { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
277 |
return Err(DirstateError::Parse(DirstateParseError::Damaged)); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
278 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
279 |
|
42801
1a535313ad1b
rust-dirstate: remove excessive clone() of parameter and return value
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
280 |
self.parents = Some(parents); |
1a535313ad1b
rust-dirstate: remove excessive clone() of parameter and return value
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
281 |
Ok(self.parents.as_ref().unwrap()) |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
282 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
283 |
|
42801
1a535313ad1b
rust-dirstate: remove excessive clone() of parameter and return value
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
284 |
pub fn set_parents(&mut self, parents: &DirstateParents) { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
285 |
self.parents = Some(parents.clone()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
286 |
self.dirty_parents = true; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
287 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
288 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
289 |
pub fn read( |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
290 |
&mut self, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
291 |
file_contents: &[u8], |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
292 |
) -> Result<Option<DirstateParents>, DirstateError> { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
293 |
if file_contents.is_empty() { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
294 |
return Ok(None); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
295 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
296 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
297 |
let parents = parse_dirstate( |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
298 |
&mut self.state_map, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
299 |
&mut self.copy_map, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
300 |
file_contents, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
301 |
)?; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
302 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
303 |
if !self.dirty_parents { |
42801
1a535313ad1b
rust-dirstate: remove excessive clone() of parameter and return value
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
304 |
self.set_parents(&parents); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
305 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
306 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
307 |
Ok(Some(parents)) |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
308 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
309 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
310 |
pub fn pack( |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
311 |
&mut self, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
312 |
parents: DirstateParents, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
313 |
now: Duration, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
314 |
) -> Result<Vec<u8>, DirstateError> { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
315 |
let packed = |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
316 |
pack_dirstate(&mut self.state_map, &self.copy_map, parents, now)?; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
317 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
318 |
self.dirty_parents = false; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
319 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
320 |
let result = self.non_normal_other_parent_entries(); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
321 |
self.non_normal_set = result.0; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
322 |
self.other_parent_set = result.1; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
323 |
Ok(packed) |
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 |
|
42801
1a535313ad1b
rust-dirstate: remove excessive clone() of parameter and return value
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
326 |
pub fn build_file_fold_map(&mut self) -> &FileFoldMap { |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
327 |
if let Some(ref file_fold_map) = self.file_fold_map { |
42801
1a535313ad1b
rust-dirstate: remove excessive clone() of parameter and return value
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
328 |
return file_fold_map; |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
329 |
} |
43826
5ac243a92e37
rust-performance: introduce FastHashMap type alias for HashMap
Raphaël Gomès <rgomes@octobus.net>
parents:
43788
diff
changeset
|
330 |
let mut new_file_fold_map = FileFoldMap::default(); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
331 |
for (filename, DirstateEntry { state, .. }) in self.state_map.borrow() |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
332 |
{ |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
333 |
if *state == EntryState::Removed { |
42840
b1b984f9c01d
rust-utils: add normalize_case util to mirror Python one
Raphaël Gomès <rgomes@octobus.net>
parents:
42802
diff
changeset
|
334 |
new_file_fold_map |
b1b984f9c01d
rust-utils: add normalize_case util to mirror Python one
Raphaël Gomès <rgomes@octobus.net>
parents:
42802
diff
changeset
|
335 |
.insert(normalize_case(filename), filename.to_owned()); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
336 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
337 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
338 |
self.file_fold_map = Some(new_file_fold_map); |
42801
1a535313ad1b
rust-dirstate: remove excessive clone() of parameter and return value
Yuya Nishihara <yuya@tcha.org>
parents:
42799
diff
changeset
|
339 |
self.file_fold_map.as_ref().unwrap() |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
340 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
341 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
342 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
343 |
#[cfg(test)] |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
344 |
mod tests { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
345 |
use super::*; |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
346 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
347 |
#[test] |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
348 |
fn test_dirs_multiset() { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
349 |
let mut map = DirstateMap::new(); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
350 |
assert!(map.dirs.is_none()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
351 |
assert!(map.all_dirs.is_none()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
352 |
|
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42840
diff
changeset
|
353 |
assert_eq!(false, map.has_dir(HgPath::new(b"nope"))); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
354 |
assert!(map.all_dirs.is_some()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
355 |
assert!(map.dirs.is_none()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
356 |
|
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42840
diff
changeset
|
357 |
assert_eq!(false, map.has_tracked_dir(HgPath::new(b"nope"))); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
358 |
assert!(map.dirs.is_some()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
359 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
360 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
361 |
#[test] |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
362 |
fn test_add_file() { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
363 |
let mut map = DirstateMap::new(); |
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 |
assert_eq!(0, map.len()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
366 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
367 |
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
|
368 |
HgPath::new(b"meh"), |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
369 |
EntryState::Normal, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
370 |
DirstateEntry { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
371 |
state: EntryState::Normal, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
372 |
mode: 1337, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
373 |
mtime: 1337, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
374 |
size: 1337, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
375 |
}, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
376 |
); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
377 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
378 |
assert_eq!(1, map.len()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
379 |
assert_eq!(0, map.non_normal_set.len()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
380 |
assert_eq!(0, map.other_parent_set.len()); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
381 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
382 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
383 |
#[test] |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
384 |
fn test_non_normal_other_parent_entries() { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
385 |
let map: DirstateMap = [ |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
386 |
(b"f1", (EntryState::Removed, 1337, 1337, 1337)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
387 |
(b"f2", (EntryState::Normal, 1337, 1337, -1)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
388 |
(b"f3", (EntryState::Normal, 1337, 1337, 1337)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
389 |
(b"f4", (EntryState::Normal, 1337, -2, 1337)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
390 |
(b"f5", (EntryState::Added, 1337, 1337, 1337)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
391 |
(b"f6", (EntryState::Added, 1337, 1337, -1)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
392 |
(b"f7", (EntryState::Merged, 1337, 1337, -1)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
393 |
(b"f8", (EntryState::Merged, 1337, 1337, 1337)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
394 |
(b"f9", (EntryState::Merged, 1337, -2, 1337)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
395 |
(b"fa", (EntryState::Added, 1337, -2, 1337)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
396 |
(b"fb", (EntryState::Removed, 1337, -2, 1337)), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
397 |
] |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
398 |
.iter() |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
399 |
.map(|(fname, (state, mode, size, mtime))| { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
400 |
( |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42840
diff
changeset
|
401 |
HgPathBuf::from_bytes(fname.as_ref()), |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
402 |
DirstateEntry { |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
403 |
state: *state, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
404 |
mode: *mode, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
405 |
size: *size, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
406 |
mtime: *mtime, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
407 |
}, |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
408 |
) |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
409 |
}) |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
410 |
.collect(); |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
411 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
412 |
let non_normal = [ |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
413 |
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
|
414 |
] |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
415 |
.iter() |
42957
7a01778bc7b7
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf
Raphaël Gomès <rgomes@octobus.net>
parents:
42840
diff
changeset
|
416 |
.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
|
417 |
.collect(); |
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 |
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
|
420 |
other_parent.insert(HgPathBuf::from_bytes(b"f4")); |
42753
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
421 |
|
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
422 |
assert_eq!( |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
423 |
(non_normal, other_parent), |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
424 |
map.non_normal_other_parent_entries() |
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 |
} |
fce6dc93a510
rust-dirstate: rust implementation of dirstatemap
Raphaël Gomès <rgomes@octobus.net>
parents:
diff
changeset
|
427 |
} |