Skip to content

Commit

Permalink
fix!: make clear what with_pruned() is doing by renaming it to `wit…
Browse files Browse the repository at this point in the history
…h_boundary()`.

This is how it acts, and it's not at all the same as `hide()` in `git2`.
  • Loading branch information
Byron committed Jan 30, 2025
1 parent 14d6b8d commit b78e7dd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
29 changes: 15 additions & 14 deletions gix/src/revision/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub struct Platform<'repo> {
/// The owning repository.
pub repo: &'repo Repository,
pub(crate) tips: Vec<ObjectId>,
pub(crate) prune: Vec<ObjectId>,
pub(crate) boundary: Vec<ObjectId>,
pub(crate) sorting: Sorting,
pub(crate) parents: gix_traverse::commit::Parents,
pub(crate) use_commit_graph: Option<bool>,
Expand All @@ -171,7 +171,7 @@ impl<'repo> Platform<'repo> {
parents: Default::default(),
use_commit_graph: None,
commit_graph: None,
prune: Vec::new(),
boundary: Vec::new(),
}
}
}
Expand Down Expand Up @@ -210,29 +210,30 @@ impl Platform<'_> {
self
}

/// Prune the commit with the given `ids` such that they won't be returned, and such that none of their ancestors is returned either.
///
/// Note that this forces the [sorting](Self::sorting) to
/// [`ByCommitTimeCutoff`](Sorting::ByCommitTimeCutoff) configured with
/// the oldest available commit time, ensuring that no commits older than the oldest of `ids` will be returned either.
/// Don't cross the given `ids` during traversal.
///
/// Note that this forces the [sorting](Self::sorting()) to [`ByCommitTimeCutoff`](Sorting::ByCommitTimeCutoff)
/// configured with the oldest available commit time, ensuring that no commits older than the oldest of `ids` will be returned either.
/// Also note that commits that can't be accessed or are missing are simply ignored for the purpose of obtaining the cutoff date.
#[doc(alias = "hide", alias = "git2")]
pub fn with_pruned(mut self, ids: impl IntoIterator<Item = impl Into<ObjectId>>) -> Self {
///
/// A boundary is distinctly different from exclusive refsepcs `^branch-to-not-list` in Git log.
///
/// If this is not desired, [set the sorting](Self::sorting()) to something else right after this call.
pub fn with_boundary(mut self, ids: impl IntoIterator<Item = impl Into<ObjectId>>) -> Self {
let (mut cutoff, order) = match self.sorting {
Sorting::ByCommitTimeCutoff { seconds, order } => (Some(seconds), order),
Sorting::ByCommitTime(order) => (None, order),
Sorting::BreadthFirst => (None, CommitTimeOrder::default()),
};
for id in ids.into_iter() {
let id = id.into();
if !self.prune.contains(&id) {
if !self.boundary.contains(&id) {
if let Some(time) = self.repo.find_commit(id).ok().and_then(|c| c.time().ok()) {
if cutoff.is_none() || cutoff > Some(time.seconds) {
cutoff = time.seconds.into();
}
}
self.prune.push(id);
self.boundary.push(id);
}
}

Expand Down Expand Up @@ -260,9 +261,9 @@ impl<'repo> Platform<'repo> {
parents,
use_commit_graph,
commit_graph,
mut prune,
mut boundary,
} = self;
prune.sort();
boundary.sort();
Ok(revision::Walk {
repo,
inner: Box::new(
Expand All @@ -277,7 +278,7 @@ impl<'repo> Platform<'repo> {
return false;
}
let id = id.to_owned();
if prune.binary_search(&id).is_ok() {
if boundary.binary_search(&id).is_ok() {
return false;
}
match shallow_commits.as_ref() {
Expand Down
2 changes: 1 addition & 1 deletion gix/tests/gix/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ mod ancestors {
for use_commit_graph in [false, true] {
let commits_graph_order = head
.ancestors()
.with_pruned(Some(hex_to_id("bcb05040a6925f2ff5e10d3ae1f9264f2e8c43ac")))
.with_boundary(Some(hex_to_id("bcb05040a6925f2ff5e10d3ae1f9264f2e8c43ac")))
.use_commit_graph(use_commit_graph)
.all()?
.map(|c| c.map(|c| c.id))
Expand Down

0 comments on commit b78e7dd

Please sign in to comment.