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

Get-Content -Head and -Tail disallow negative values and cleanup #19715

Merged
merged 15 commits into from
Jun 21, 2023

Conversation

CarloToso
Copy link
Contributor

@CarloToso CarloToso commented May 26, 2023

PR Summary

  • Disallow negative values for -Head and -Tail
  • Add fast return if -Tail == 0
  • Cleanup code

TODO:

  • Add tests

PR Context

#19710 @jhoneill @mklement0

PR Checklist

@ghost ghost assigned TravisEz13 May 26, 2023
@ghost ghost added the Review - Needed The PR is being reviewed label Jun 2, 2023
@ghost
Copy link

ghost commented Jun 2, 2023

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@StevenBucher98 StevenBucher98 added the PowerShell-Docs not needed The PR was reviewed and doesn't appear to require a PowerShell Docs update label Jun 5, 2023
Copy link
Member

@TravisEz13 TravisEz13 left a comment

Choose a reason for hiding this comment

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

Are there tests for the modified scenarios?

Update:
https://github.com/PowerShell/PowerShell/blob/master/test/powershell/Modules/Microsoft.PowerShell.Management/Get-Content.Tests.ps1

Add tests for:

  • tail = 0
  • verify error when tail is negative
  • verify error when totalcount is negative.

@daxian-dbw daxian-dbw added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Review - Needed The PR is being reviewed labels Jun 6, 2023
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jun 9, 2023
@CarloToso
Copy link
Contributor Author

@TravisEz13 Added tests

@pull-request-quantifier-deprecated

This PR has 100 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Small
Size       : +40 -60
Percentile : 40%

Total files changed: 2

Change summary by file extension:
.cs : +36 -60
.ps1 : +4 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detected.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@jhoneill jhoneill added the WG-Cmdlets general cmdlet issues label Jun 10, 2023
@jhoneill
Copy link

To me this looks like a valid solution , I have added the wg-cmdlets tag because I think the WG should be saying "There are other ways this could be addressed, we like (or don't like) this one."

@ghost ghost added the Review - Needed The PR is being reviewed label Jun 18, 2023
@ghost
Copy link

ghost commented Jun 18, 2023

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

It looks good to me overall. However, this is a breaking change, as today a user can specify negative value like Get-Content -Tail -50 or Get-Content -TotalCount -100, and they just mean get all content.
It seems to be a bucket 3 breaking change, but I'd like the Cmdlet WG to make a conclusion.

@daxian-dbw daxian-dbw added Needs-Triage The issue is new and needs to be triaged by a work group. CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log and removed Review - Needed The PR is being reviewed labels Jun 19, 2023
@SteveL-MSFT
Copy link
Member

Added to WG agenda

@SteveL-MSFT SteveL-MSFT added PowerShell-Docs needed The PR was reviewed and a PowerShell Docs update is needed and removed PowerShell-Docs not needed The PR was reviewed and doesn't appear to require a PowerShell Docs update labels Jun 21, 2023
@SteveL-MSFT
Copy link
Member

@PowerShell/wg-powershell-cmdlets reviewed this, we agreed that although a breaking change, we think it is a bucket 3 unlikely to impact users change. The main concern is that -1 is documented as default and implied to be supported. Docs would need to be changed to remove mention of this internal detail and users are likely to not specify the parameter rather than explicitly -1 to get all content so we don't expect users to be using -1 directly.

@SteveL-MSFT SteveL-MSFT removed the Needs-Triage The issue is new and needs to be triaged by a work group. label Jun 21, 2023
@SteveL-MSFT
Copy link
Member

@JamesWTruher has some individual PR comments he'll add

@daxian-dbw daxian-dbw merged commit cb2848c into PowerShell:master Jun 21, 2023
40 checks passed
@daxian-dbw
Copy link
Member

@SteveL-MSFT @JamesWTruher I didn't see the new comment above until after I merged the PR ...
Please still leave your comment. If it's something you think that needs code changes, please open an issue to track it.

@daxian-dbw
Copy link
Member

Doc issue MicrosoftDocs/PowerShell-Docs#10183 was opened to track removing mention of the default value.

@@ -116,15 +79,15 @@ protected override void ProcessRecord()
{
// TotalCount and Tail should not be specified at the same time.
// Throw out terminating error if this is the case.
Copy link
Member

Choose a reason for hiding this comment

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

this comment seems wrong - it doesn't look like a terminating error

}

private bool _totalCountSpecified = false;
public long TotalCount { get; set; } = -1;
Copy link
Member

Choose a reason for hiding this comment

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

hmmm, I wonder if this should be just be long? TotalCount

@ghost
Copy link

ghost commented Jun 29, 2023

🎉v7.4.0-preview.4 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log PowerShell-Docs needed The PR was reviewed and a PowerShell Docs update is needed Small WG-Cmdlets general cmdlet issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants