Mercurial > hg
changeset 51978:5d1e6f447d2d
head-revs: move hg-core's inner_headrevsfiltered closer to inner_headrevs
This is pure code movement, it make a coming changesets significantly clearer.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 26 Sep 2024 01:52:09 +0200 |
parents | 42a116f1cdc1 |
children | 609700e5d8df |
files | rust/hg-core/src/revlog/index.rs |
diffstat | 1 files changed, 55 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/index.rs Tue Sep 03 11:11:17 2024 +0200 +++ b/rust/hg-core/src/revlog/index.rs Thu Sep 26 01:52:09 2024 +0200 @@ -545,6 +545,61 @@ .map(|h| h.unwrap()) } + /// Return the head revisions of this index + pub fn head_revs_filtered( + &self, + filtered_revs: &HashSet<Revision>, + py_shortcut: bool, + ) -> Result<Option<Vec<Revision>>, GraphError> { + { + let guard = self + .head_revs + .read() + .expect("RwLock on Index.head_revs should not be poisoned"); + let self_head_revs = &guard.0; + let self_filtered_revs = &guard.1; + if !self_head_revs.is_empty() + && filtered_revs == self_filtered_revs + { + if py_shortcut { + // Don't copy the revs since we've already cached them + // on the Python side. + return Ok(None); + } else { + return Ok(Some(self_head_revs.to_owned())); + } + } + } + + let as_vec = if self.is_empty() { + vec![NULL_REVISION] + } else { + let mut not_heads = bitvec![0; self.len()]; + dagops::retain_heads_fast( + self, + not_heads.as_mut_bitslice(), + filtered_revs, + )?; + not_heads + .into_iter() + .enumerate() + .filter_map(|(idx, is_not_head)| { + if is_not_head { + None + } else { + Some(Revision(idx as BaseRevision)) + } + }) + .collect() + }; + *self + .head_revs + .write() + .expect("RwLock on Index.head_revs should not be poisoned") = + (as_vec.to_owned(), filtered_revs.to_owned()); + Ok(Some(as_vec)) + } + /// Python-specific shortcut to save on PyList creation pub fn head_revs_shortcut( &self, @@ -603,61 +658,6 @@ Ok((heads_removed, heads_added)) } - /// Return the head revisions of this index - pub fn head_revs_filtered( - &self, - filtered_revs: &HashSet<Revision>, - py_shortcut: bool, - ) -> Result<Option<Vec<Revision>>, GraphError> { - { - let guard = self - .head_revs - .read() - .expect("RwLock on Index.head_revs should not be poisoned"); - let self_head_revs = &guard.0; - let self_filtered_revs = &guard.1; - if !self_head_revs.is_empty() - && filtered_revs == self_filtered_revs - { - if py_shortcut { - // Don't copy the revs since we've already cached them - // on the Python side. - return Ok(None); - } else { - return Ok(Some(self_head_revs.to_owned())); - } - } - } - - let as_vec = if self.is_empty() { - vec![NULL_REVISION] - } else { - let mut not_heads = bitvec![0; self.len()]; - dagops::retain_heads_fast( - self, - not_heads.as_mut_bitslice(), - filtered_revs, - )?; - not_heads - .into_iter() - .enumerate() - .filter_map(|(idx, is_not_head)| { - if is_not_head { - None - } else { - Some(Revision(idx as BaseRevision)) - } - }) - .collect() - }; - *self - .head_revs - .write() - .expect("RwLock on Index.head_revs should not be poisoned") = - (as_vec.to_owned(), filtered_revs.to_owned()); - Ok(Some(as_vec)) - } - /// Obtain the delta chain for a revision. /// /// `stop_rev` specifies a revision to stop at. If not specified, we