X Tutup
The Wayback Machine - https://web.archive.org/web/20241126192832/https://github.com/PowerShell/PowerShell/pull/4985
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

Make Get-ChildItem honor Depth parameter with Include/Exclude #4985

Merged
merged 3 commits into from
Oct 23, 2017
Merged

Make Get-ChildItem honor Depth parameter with Include/Exclude #4985

merged 3 commits into from
Oct 23, 2017

Conversation

Windos
Copy link
Contributor

@Windos Windos commented Oct 3, 2017

Addresses issue #3726 by adding decrementing depth to ProcessPathItems.

Includes tests specifically for the examples listed in the issue and also testing that recursion still works when excluding or including a string.

Honors capped recursion when using Include or Exclude filters with Get-ChildItem
@@ -1593,7 +1593,7 @@ internal Collection<PSObject> GetChildItems(string[] paths, bool recurse, uint d
}

int unUsedChildrenNotMatchingFilterCriteria = 0;
ProcessPathItems(providerInstance, providerPath, recurse, context, out unUsedChildrenNotMatchingFilterCriteria, ProcessMode.Enumerate);
ProcessPathItems(providerInstance, providerPath, recurse, context, out unUsedChildrenNotMatchingFilterCriteria, ProcessMode.Enumerate, depth: depth);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to exclude parameters with defaults and use overloads.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just pushed new commit swapping optional parameter for overload. Is it along the right track?

@iSazonov
Copy link
Collaborator

iSazonov commented Oct 4, 2017

@daxian-dbw Can we ask @Windos to fix (replace with overloads) skipIsItemContainerCheck defaults in the PR? It seems adding new parameter (depth) complicate the Api and it would be good to eliminate that now.

@daxian-dbw
Copy link
Member

Well, the optional parameter was introduced to be an alternative of overloads, to reduce the number of overloads of a method.
If we remove skipIsItemContainerCheck by adding overloads, then there will be 4 overloads of ProcessPathItems, which IMHO might be cumbersome.

The optional parameter should never be used for public APIs or even internal APIs that may be called from other friend assemblies because the default value is baked into the caller, and that means if we change the default value, the caller assembly needs to be re-compile to get the new default value.
However, it's fine for private methods, as long as it doesn't affect readability much.

@iSazonov
Copy link
Collaborator

iSazonov commented Oct 5, 2017

@daxian-dbw I asked because adding second optional parameter reduced readability. Do we have to create overloads in this case or can we just replace its with one method with all the parameters?

@Windos
Copy link
Contributor Author

Windos commented Oct 6, 2017

I'm happy to put the work in regardless of which direction is decided on.

@daxian-dbw
Copy link
Member

@iSazonov I think you made the right call. Adding the second optional parameter would worsen the readability. I think the current two overloads look good.

@adityapatwardhan
Copy link
Member

@iSazonov @daxian-dbw can you update your review

@iSazonov
Copy link
Collaborator

iSazonov commented Oct 9, 2017

@daxian-dbw Is uint depth parameter on best place? What about before last?

Copy link
Member

@adityapatwardhan adityapatwardhan left a comment

Choose a reason for hiding this comment

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

LGTM

@adityapatwardhan
Copy link
Member

@daxian-dbw Can you update your review?

@adityapatwardhan adityapatwardhan merged commit c98fe39 into PowerShell:master Oct 23, 2017
@adityapatwardhan
Copy link
Member

@Windos Thanks for your contribution!

@vors vors removed their request for review October 24, 2017 04:59
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.

4 participants
X Tutup