mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-18 02:04:19 +00:00
lib: add Commit::is_discardable()
This commit is contained in:
parent
5d184e6694
commit
616058c2fa
2 changed files with 12 additions and 5 deletions
|
@ -128,4 +128,15 @@ impl Commit {
|
||||||
pub fn committer(&self) -> &Signature {
|
pub fn committer(&self) -> &Signature {
|
||||||
&self.data.committer
|
&self.data.committer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A commit is discardable if it has one parent, no change from its
|
||||||
|
/// parent, and an empty description.
|
||||||
|
pub fn is_discardable(&self) -> bool {
|
||||||
|
if self.description().is_empty() {
|
||||||
|
if let [parent_commit] = &*self.parents() {
|
||||||
|
return self.tree_id() == parent_commit.tree_id();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -743,11 +743,7 @@ impl MutableRepo {
|
||||||
.store()
|
.store()
|
||||||
.get_commit(&wc_commit_id)
|
.get_commit(&wc_commit_id)
|
||||||
.map_err(EditCommitError::WorkingCopyCommitNotFound)?;
|
.map_err(EditCommitError::WorkingCopyCommitNotFound)?;
|
||||||
if wc_commit.parent_ids().len() == 1
|
if wc_commit.is_discardable() && self.view().heads().contains(wc_commit.id()) {
|
||||||
&& wc_commit.parents()[0].tree_id() == wc_commit.tree_id()
|
|
||||||
&& wc_commit.description().is_empty()
|
|
||||||
&& self.view().heads().contains(wc_commit.id())
|
|
||||||
{
|
|
||||||
// Abandon the working-copy commit we're leaving if it's empty and a head commit
|
// Abandon the working-copy commit we're leaving if it's empty and a head commit
|
||||||
self.record_abandoned_commit(wc_commit_id);
|
self.record_abandoned_commit(wc_commit_id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue