ok/jj
1
0
Fork 0
forked from mirrors/jj

repo: inline single-caller, and surprising, Commit::is_empty()

I would expect `Commit::is_empty()` to check if the commit is empty in
our usual sense, i.e. that there are no changes compared to the
auto-merged parents. However, it would return `false` for any merge
commit (and for the root commit). Since we only use it in one place,
let's inline it there. The use there does seem reasonable, because
it's about abandoning an "uninteresting" working-copy commit.
This commit is contained in:
Martin von Zweigbergk 2023-01-28 14:39:18 -08:00 committed by Martin von Zweigbergk
parent 615862dde8
commit aaf75b4793
2 changed files with 2 additions and 7 deletions

View file

@ -117,12 +117,6 @@ impl Commit {
&self.data
}
pub fn is_empty(&self) -> bool {
let parents = self.parents();
// TODO: Perhaps the root commit should also be considered empty.
parents.len() == 1 && parents[0].tree_id() == self.tree_id()
}
pub fn description(&self) -> &str {
&self.data.description
}

View file

@ -835,7 +835,8 @@ impl MutableRepo {
.store()
.get_commit(&wc_commit_id)
.map_err(EditCommitError::WorkingCopyCommitNotFound)?;
if wc_commit.is_empty()
if wc_commit.parent_ids().len() == 1
&& wc_commit.parents()[0].tree_id() == wc_commit.tree_id()
&& wc_commit.description().is_empty()
&& self.view().heads().contains(wc_commit.id())
{