| @@ -50,13 +50,14 @@ impl<'repo> Platform<'repo> { · 49 unmodified lines |
| 50 | 50 | |
| 51 | 51 | /// Produce the iterator |
| 52 | 52 | impl<'repo> Platform<'repo> { |
| 53 | | − /// Return an iterator to traverse all commits reachable as configured by the [Platform]. |
| 54 | | − /// |
| 55 | | − /// # Performance |
| 53 | + /// For each commit, let `filter` return `true` if it and its parents should be included in the traversal, or `false` |
| 54 | + /// if the traversal should exclude it and its ancestry entirely. |
| 56 | 55 | /// |
| 57 | | − /// It's highly recommended to set an [`object cache`][Repository::object_cache_size()] on the parent repo |
| 58 | | − /// to greatly speed up performance if the returned id is supposed to be looked up right after. |
| 59 | | − pub fn all(self) -> Result<revision::Walk<'repo>, Error> { |
| 56 | + /// If `filter` is None, no pruning of the graph will be performed which is the default. |
| 57 | + pub fn selected( |
| 58 | + self, |
| 59 | + mut filter: impl FnMut(&gix_hash::oid) -> bool + 'repo, |
| 60 | + ) -> Result<revision::Walk<'repo>, Error> { |
| 60 | 61 | let Platform { |
| 61 | 62 | repo, |
| 62 | 63 | tips, |
| @@ -74,22 +75,27 @@ impl<'repo> Platform<'repo> { · 11 unmodified lines |
| 74 | 75 | let shallow_commits = repo.shallow_commits()?; |
| 75 | 76 | let mut grafted_parents_to_skip = Vec::new(); |
| 76 | 77 | let mut buf = Vec::new(); |
| 77 | | − move |id| match shallow_commits.as_ref() { |
| 78 | | − Some(commits) => { |
| 79 | | − let id = id.to_owned(); |
| 80 | | − if let Ok(idx) = grafted_parents_to_skip.binary_search(&id) { |
| 81 | | − grafted_parents_to_skip.remove(idx); |
| 82 | | − return false; |
| 83 | | − }; |
| 84 | | − if commits.binary_search(&id).is_ok() { |
| 85 | | − if let Ok(commit) = repo.objects.find_commit_iter(id, &mut buf) { |
| 86 | | − grafted_parents_to_skip.extend(commit.parent_ids()); |
| 87 | | − grafted_parents_to_skip.sort(); |
| 88 | | − } |
| 89 | | − }; |
| 90 | | − true |
| 78 | + move |id| { |
| 79 | + if !filter(id) { |
| 80 | + return false; |
| 81 | + } |
| 82 | + match shallow_commits.as_ref() { |
| 83 | + Some(commits) => { |
| 84 | + let id = id.to_owned(); |
| 85 | + if let Ok(idx) = grafted_parents_to_skip.binary_search(&id) { |
| 86 | + grafted_parents_to_skip.remove(idx); |
| 87 | + return false; |
| 88 | + }; |
| 89 | + if commits.binary_search(&id).is_ok() { |
| 90 | + if let Ok(commit) = repo.objects.find_commit_iter(id, &mut buf) { |
| 91 | + grafted_parents_to_skip.extend(commit.parent_ids()); |
| 92 | + grafted_parents_to_skip.sort(); |
| 93 | + } |
| 94 | + }; |
| 95 | + true |
| 96 | + } |
| 97 | + None => true, |
| 91 | 98 | } |
| 92 | | − None => true, |
| 93 | 99 | } |
| 94 | 100 | }, |
| 95 | 101 | ) |
| @@ -98,6 +104,15 @@ impl<'repo> Platform<'repo> { · 2 unmodified lines |
| 98 | 104 | ), |
| 99 | 105 | }) |
| 100 | 106 | } |
| 107 | + /// Return an iterator to traverse all commits reachable as configured by the [Platform]. |
| 108 | + /// |
| 109 | + /// # Performance |
| 110 | + /// |
| 111 | + /// It's highly recommended to set an [`object cache`][Repository::object_cache_size()] on the parent repo |
| 112 | + /// to greatly speed up performance if the returned id is supposed to be looked up right after. |
| 113 | + pub fn all(self) -> Result<revision::Walk<'repo>, Error> { |
| 114 | + self.selected(|_| true) |
| 115 | + } |
| 101 | 116 | } |
| 102 | 117 | |
| 103 | 118 | pub(crate) mod iter { |