-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(FileStatusList): status for renamed in branch diffs #12245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(FileStatusList): status for renamed in branch diffs #12245
Conversation
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)]; |
There was a problem hiding this comment.
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<>
.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Compares the file names | |
/// Compares the file names. |
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For another PR?
bd2d62f
to
76f94c2
Compare
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
After
Note that the status A-B is not always the same as BASE-A/B
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.