Skip to content
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 submodule status loading error #8881

Merged
merged 1 commit into from Feb 28, 2021

Conversation

drewnoakes
Copy link
Member

Fixes @gerhardol's comments on #8875

Proposed changes

Refactoring during annotation identified a potential issue here, but the change was not correct. This change allows the task itself to be null (an uncommon pattern) which indicates that SetSubmoduleStatus has not been called.

Test methodology

  • Manual testing

To trigger the broken behaviour:

  1. Open the GE repo
  2. Select the "File Tree" tab
  3. Select a submodule in the tree
  4. Press H to open the history

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

@codecov
Copy link

codecov bot commented Feb 24, 2021

Codecov Report

Merging #8881 (30c0456) into master (b6905f1) will increase coverage by 0.02%.
The diff coverage is 31.98%.

@@            Coverage Diff             @@
##           master    #8881      +/-   ##
==========================================
+ Coverage   56.03%   56.06%   +0.02%     
==========================================
  Files         922      922              
  Lines       65944    65847      -97     
  Branches    12070    12084      +14     
==========================================
- Hits        36951    36915      -36     
+ Misses      25985    25921      -64     
- Partials     3008     3011       +3     
Flag Coverage Δ
production 43.30% <22.76%> (+0.04%) ⬆️
tests 94.82% <87.27%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Copy link
Member

@gerhardol gerhardol left a comment

Choose a reason for hiding this comment

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

quick check only

GitUI/GitUIExtensions.cs Show resolved Hide resolved
Copy link
Member

@gerhardol gerhardol left a comment

Choose a reason for hiding this comment

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

I pushed a proposal to a local branch, using pattern matching declarations where possible and find the code much more easy to read

GitUI/UserControls/FileStatusList.cs Outdated Show resolved Hide resolved
Comment on lines 1955 to 1957
Task<GitSubmoduleStatus?>? statusTask = item.GetSubmoduleStatusAsync();
Validates.NotNull(statusTask);
if (!statusTask.IsCompleted)
Copy link
Member

Choose a reason for hiding this comment

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

I'm struggling with this - statusTask can be null, and in case when it is will it throw on line:1956 or line:1957?

Copy link
Member

Choose a reason for hiding this comment

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

I rewrote most of the checks using pattern matching declarations, I find this much easier to read

@RussKie RussKie added the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Feb 25, 2021
if (item.IsSubmodule
&& item.GetSubmoduleStatusAsync() is Task<GitSubmoduleStatus> task
&& task is not null
&& !task.IsCompleted)
Copy link
Member

Choose a reason for hiding this comment

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

need to remove this check to set status om L942

Copy link
Member

Choose a reason for hiding this comment

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

removed the check in a separate push

@ghost ghost removed the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Feb 25, 2021
Refactoring during annotation identified a potential issue here, but the change was not correct. This change allows the task itself to be null (an uncommon pattern) which indicates that `SetSubmoduleStatus` has not been called.
Comment on lines +931 to +932
&& item.GetSubmoduleStatusAsync() is Task<GitSubmoduleStatus> task
&& task is not null)
Copy link
Member Author

Choose a reason for hiding this comment

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

@gerhardol the type check is essentially a null check too.

Suggested change
&& item.GetSubmoduleStatusAsync() is Task<GitSubmoduleStatus> task
&& task is not null)
&& item.GetSubmoduleStatusAsync() is Task<GitSubmoduleStatus> task)

I'm not a fan of this code though. It makes it look like a runtime type test is needed, which is not the case. This is just a null check.

Copy link
Member Author

Choose a reason for hiding this comment

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

Another way of writing this is:

Suggested change
&& item.GetSubmoduleStatusAsync() is Task<GitSubmoduleStatus> task
&& task is not null)
&& item.GetSubmoduleStatusAsync() is { } task)

But is that actually better than assigning the task to a local and doing an explicit is not null test? The only downside is a bit of nesting, which is not the end of the world.

Copy link
Member

Choose a reason for hiding this comment

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

We had this discussion before: This is a hard to read. One does not need to use every new C# syntax invention.

Copy link
Member

Choose a reason for hiding this comment

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

The task is not null checks in FileStatusList.cs are not needed.
I changed to that style as it is required in FormCommit

I prefer to have a minimal code why my preference is to just removing is not null where possible.

@RussKie RussKie merged commit 7f7a6f2 into gitextensions:master Feb 28, 2021
@ghost ghost added this to the 3.6 milestone Feb 28, 2021
@drewnoakes drewnoakes deleted the fix-submodule-status branch March 1, 2021 01:48
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.

None yet

4 participants