Skip to content

Commit

Permalink
lib: inherit parent / rewrite source topics when creating / rewriting…
Browse files Browse the repository at this point in the history
… a commit
  • Loading branch information
noahmayr committed May 4, 2024
1 parent f888798 commit cd847ec
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/src/commit_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#![allow(missing_docs)]

use std::collections::HashSet;
use std::sync::Arc;

use crate::backend::{self, BackendResult, ChangeId, CommitId, MergedTreeId, Signature, SigningFn};
Expand Down Expand Up @@ -202,6 +203,35 @@ impl CommitBuilder<'_> {
self.mut_repo
.set_rewritten_commit(rewrite_source.id().clone(), commit.id().clone());
}
let base_repo = self.mut_repo.base_repo().clone();
let topics = base_repo
.view()
.topics_containing_commit(rewrite_source.id());
self.mut_repo.update_topics(topics, |_, commits| {
let mut commits = commits.clone();
commits.remove(rewrite_source.id());
commits.insert(commit.id().clone());
Some(commits)
});
} else {
let parent_set = HashSet::from_iter(commit.parent_ids().iter().cloned());
let base_repo = self.mut_repo.base_repo().clone();
let topics = base_repo
.view()
.topics()
.iter()
.filter_map(|(topic, commits)| {
if commits.is_disjoint(&parent_set) {
None
} else {
Some(topic)
}
});
self.mut_repo.update_topics(topics, |_, commits| {
let mut commits = commits.clone();
commits.insert(commit.id().clone());
Some(commits)
});
}
Ok(commit)
}
Expand Down

0 comments on commit cd847ec

Please sign in to comment.