Skip to content

Conversation

gerhardol
Copy link
Member

@gerhardol gerhardol commented Mar 8, 2025

Proposed changes

When comparing status for branches, the status compared to BASE is shown as Unequal/Same/A/B.
For renamed and copied files, the old name was not used when comparing, so status was not set correctly.

Screenshots

Comparing 8863b8b with my private branch tmp/test-modified

Before

image

After

Note that the status A-B is not always the same as BASE-A/B

image

Test methodology

Manual

Merge strategy

I agree that the maintainer squash merge this PR (if the commit message is clear).


✒️ I contribute this code under The Developer Certificate of Origin.

When comparing status for branches, the status compared to BASE is shown
as Unequal/Same/A/B.
For renamed and copied files, the old name was not used when comparing,
so status was not set correctly.
List<GitItemStatus> onlyB = allBaseToB.Except(allBaseToA, comparer).ToList();
List<GitItemStatus> sameBaseToAandB = [.. allBaseToB
.Intersect(allBaseToA, comparer)
.Except(allAToB.Where(i => !((i.IsRenamed || i.IsCopied) && i.RenameCopyPercentage == "100")), comparer)];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This subexpression is worth having a name, e.g.

GitItemStatus[] allAToBExceptExactRenameCopy = [.. allAToB.Where(i => !((i.IsRenamed || i.IsCopied) && i.RenameCopyPercentage == "100"))];

For performance reasons, we should use arrays instead of List<>.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note also that allAToBExceptExactRenameCopy etc only needs the path so e.g. a HashSet could be used, but that should not make a noticeable difference

@@ -3,18 +3,32 @@
namespace GitCommands.Git
{
/// <summary>
/// Compares the file names/>.
/// Compares the file names
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Compares the file names
/// Compares the file names.

Comment on lines -249 to +253
return sameBaseToAandB.Any(i => i.Name == f.Name) ? DiffBranchStatus.SameChange
: onlyA.Any(i => i.Name == f.Name) ? DiffBranchStatus.OnlyAChange
: onlyB.Any(i => i.Name == f.Name) ? DiffBranchStatus.OnlyBChange
return sameBaseToAandB.Any(i => comparer.Equals(i, f)) ? DiffBranchStatus.SameChange
: onlyA.Any(i => comparer.Equals(i, f)) ? DiffBranchStatus.OnlyAChange
: onlyB.Any(i => comparer.Equals(i, f)) ? DiffBranchStatus.OnlyBChange
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be more occasions where this comparer should be used - in / around FileStatusList.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For another PR?

@gerhardol gerhardol force-pushed the feature/renamed-status branch from bd2d62f to 76f94c2 Compare March 8, 2025 22:41
@gerhardol gerhardol merged commit 15d5544 into gitextensions:master Mar 16, 2025
3 of 4 checks passed
@gerhardol gerhardol deleted the feature/renamed-status branch March 16, 2025 11:38
@mstv mstv added this to the v5.3 milestone Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants