Skip to content

Commit 8d2c89b

Browse files
authored
Merge pull request #9668 from gitbutlerapp/enhance-upstream-commit-filter
Improve upstream commit filtering
2 parents ab845ac + 2f658f0 commit 8d2c89b

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

crates/but-workspace/src/stacks.rs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{RefInfo, StacksFilter, branch, head_info, ref_info, state_handle, ui
66
use anyhow::{Context, bail};
77
use bstr::BString;
88
use but_core::RefMetadata;
9+
use but_core::diff::tree_changes;
910
use but_graph::VirtualBranchesTomlMetadata;
1011
use gitbutler_command_context::CommandContext;
1112
use gitbutler_commit::commit_ext::CommitExt;
@@ -698,18 +699,37 @@ fn upstream_only_commits(
698699
// If the id matches verbatim or if there is a known remote_id (in the case of LocalAndRemote) that matchies
699700
c.id == commit.id().to_gix() || matches!(&c.state, CommitState::LocalAndRemote(remote_id) if remote_id == &commit.id().to_gix())
700701
});
702+
701703
// Ignore commits that strictly speaking are remote only, but they match a known local commit (rebase etc)
702-
if !matches_known_commit {
703-
let created_at = i128::from(commit.time().seconds()) * 1000;
704-
let upstream_commit = ui::UpstreamCommit {
705-
id: commit.id().to_gix(),
706-
message: commit.message_bstr().into(),
707-
created_at,
708-
author: commit.author().into(),
709-
};
710-
upstream_only.push(upstream_commit);
704+
if matches_known_commit {
705+
continue;
706+
}
707+
708+
let last_local_commit = local_and_remote.last();
709+
710+
// If there's a last local commit, compare the trees
711+
if let Some(last_local_commit) = last_local_commit {
712+
let lhs = last_local_commit.id;
713+
let rhs = commit.id().to_gix();
714+
715+
// We don't care about upstream commits that bring no new changes.
716+
// This helps us avoid showing 'upstream commits' after squashing commits or rebasing.
717+
let (changes, _) = tree_changes(repo, Some(lhs), rhs)?;
718+
if changes.is_empty() {
719+
continue;
720+
}
711721
}
722+
723+
let created_at = i128::from(commit.time().seconds()) * 1000;
724+
let upstream_commit = ui::UpstreamCommit {
725+
id: commit.id().to_gix(),
726+
message: commit.message_bstr().into(),
727+
created_at,
728+
author: commit.author().into(),
729+
};
730+
upstream_only.push(upstream_commit);
712731
}
732+
713733
upstream_only.reverse();
714734

715735
Ok(upstream_only)

0 commit comments

Comments
 (0)