All of its users have been migrated to the new API
Details
Details
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Branch
- default
- Lint
No Linters Available - Unit
No Unit Test Coverage
hg-reviewers |
All of its users have been migrated to the new API
No Linters Available |
No Unit Test Coverage |
Path | Packages | |||
---|---|---|---|---|
M | rust/hg-core/src/dirstate_tree/dirstate_map.rs (54 lines) | |||
M | rust/hg-cpython/src/dirstate/dirstate_map.rs (14 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
57e7eb22a025 | ca1d4fb72f24 | Raphaël Gomès | Wed, Mar 23, 12:19 PM |
Status | Author | Revision | |
---|---|---|---|
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare | ||
Needs Review | Alphare |
self.nodes_with_entry_count += 1; | self.nodes_with_entry_count += 1; | ||||
new = true; | new = true; | ||||
DirstateEntry::new_tracked() | DirstateEntry::new_tracked() | ||||
}; | }; | ||||
node.data = NodeData::Entry(new_entry); | node.data = NodeData::Entry(new_entry); | ||||
Ok(new) | Ok(new) | ||||
} | } | ||||
fn add_or_remove_file( | |||||
&mut self, | |||||
path: &HgPath, | |||||
old_state: Option<EntryState>, | |||||
new_entry: DirstateEntry, | |||||
) -> Result<(), DirstateV2ParseError> { | |||||
let had_entry = old_state.is_some(); | |||||
let was_tracked = old_state.map_or(false, |s| s.is_tracked()); | |||||
let tracked_count_increment = | |||||
match (was_tracked, new_entry.state().is_tracked()) { | |||||
(false, true) => 1, | |||||
(true, false) => -1, | |||||
_ => 0, | |||||
}; | |||||
let node = Self::get_or_insert_node( | |||||
self.on_disk, | |||||
&mut self.unreachable_bytes, | |||||
&mut self.root, | |||||
path, | |||||
WithBasename::to_cow_owned, | |||||
|ancestor| { | |||||
if !had_entry { | |||||
ancestor.descendants_with_entry_count += 1; | |||||
} | |||||
// We can’t use `+= increment` because the counter is unsigned, | |||||
// and we want debug builds to detect accidental underflow | |||||
// through zero | |||||
match tracked_count_increment { | |||||
1 => ancestor.tracked_descendants_count += 1, | |||||
-1 => ancestor.tracked_descendants_count -= 1, | |||||
_ => {} | |||||
} | |||||
}, | |||||
)?; | |||||
if !had_entry { | |||||
self.nodes_with_entry_count += 1 | |||||
} | |||||
node.data = NodeData::Entry(new_entry); | |||||
Ok(()) | |||||
} | |||||
/// It is the responsibility of the caller to know that there was an entry | /// It is the responsibility of the caller to know that there was an entry | ||||
/// there before. Does not handle the removal of copy source | /// there before. Does not handle the removal of copy source | ||||
fn set_untracked( | fn set_untracked( | ||||
&mut self, | &mut self, | ||||
filename: &HgPath, | filename: &HgPath, | ||||
old_entry: DirstateEntry, | old_entry: DirstateEntry, | ||||
) -> Result<(), DirstateV2ParseError> { | ) -> Result<(), DirstateV2ParseError> { | ||||
let node = Self::get_or_insert_node( | let node = Self::get_or_insert_node( | ||||
entry: DirstateEntry, | entry: DirstateEntry, | ||||
) -> Result<(), DirstateV2ParseError> { | ) -> Result<(), DirstateV2ParseError> { | ||||
self.with_dmap_mut(|map| { | self.with_dmap_mut(|map| { | ||||
map.get_or_insert(&filename)?.data = NodeData::Entry(entry); | map.get_or_insert(&filename)?.data = NodeData::Entry(entry); | ||||
Ok(()) | Ok(()) | ||||
}) | }) | ||||
} | } | ||||
pub fn add_file( | |||||
&mut self, | |||||
filename: &HgPath, | |||||
entry: DirstateEntry, | |||||
) -> Result<(), DirstateError> { | |||||
let old_state = self.get(filename)?.map(|e| e.state()); | |||||
self.with_dmap_mut(|map| { | |||||
Ok(map.add_or_remove_file(filename, old_state, entry)?) | |||||
}) | |||||
} | |||||
pub fn set_tracked( | pub fn set_tracked( | ||||
&mut self, | &mut self, | ||||
filename: &HgPath, | filename: &HgPath, | ||||
) -> Result<bool, DirstateV2ParseError> { | ) -> Result<bool, DirstateV2ParseError> { | ||||
let old_entry_opt = self.get(filename)?; | let old_entry_opt = self.get(filename)?; | ||||
self.with_dmap_mut(|map| map.set_tracked(filename, old_entry_opt)) | self.with_dmap_mut(|map| map.set_tracked(filename, old_entry_opt)) | ||||
} | } | ||||
let filename = HgPath::new(f.data(py)); | let filename = HgPath::new(f.data(py)); | ||||
self.inner(py) | self.inner(py) | ||||
.borrow_mut() | .borrow_mut() | ||||
.set_entry(filename, item.get_entry(py)) | .set_entry(filename, item.get_entry(py)) | ||||
.map_err(|e| v2_error(py, e))?; | .map_err(|e| v2_error(py, e))?; | ||||
Ok(py.None()) | Ok(py.None()) | ||||
} | } | ||||
def addfile( | |||||
&self, | |||||
f: PyBytes, | |||||
item: DirstateItem, | |||||
) -> PyResult<PyNone> { | |||||
let filename = HgPath::new(f.data(py)); | |||||
let entry = item.get_entry(py); | |||||
self.inner(py) | |||||
.borrow_mut() | |||||
.add_file(filename, entry) | |||||
.map_err(|e |dirstate_error(py, e))?; | |||||
Ok(PyNone) | |||||
} | |||||
def set_tracked(&self, f: PyObject) -> PyResult<PyBool> { | def set_tracked(&self, f: PyObject) -> PyResult<PyBool> { | ||||
let bytes = f.extract::<PyBytes>(py)?; | let bytes = f.extract::<PyBytes>(py)?; | ||||
let path = HgPath::new(bytes.data(py)); | let path = HgPath::new(bytes.data(py)); | ||||
let res = self.inner(py).borrow_mut().set_tracked(path); | let res = self.inner(py).borrow_mut().set_tracked(path); | ||||
let was_tracked = res.or_else(|_| { | let was_tracked = res.or_else(|_| { | ||||
Err(PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string())) | Err(PyErr::new::<exc::OSError, _>(py, "Dirstate error".to_string())) | ||||
})?; | })?; | ||||
Ok(was_tracked.to_py_object(py)) | Ok(was_tracked.to_py_object(py)) |