From aaf75b479349f3caa8eec41505a3a3e6dab898a7 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 28 Jan 2023 14:39:18 -0800 Subject: [PATCH] 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. --- lib/src/commit.rs | 6 ------ lib/src/repo.rs | 3 ++- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/src/commit.rs b/lib/src/commit.rs index a6ffe3ec2..3480c8152 100644 --- a/lib/src/commit.rs +++ b/lib/src/commit.rs @@ -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 } diff --git a/lib/src/repo.rs b/lib/src/repo.rs index d7d90b061..008fb2872 100644 --- a/lib/src/repo.rs +++ b/lib/src/repo.rs @@ -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()) {