feat: flatten last n layers. #2182
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new feature to the
flattencommand, allowing users to flatten only the last N layers of an image instead of all layers. This adds flexibility for advanced image management and optimization. The implementation includes a new flag, updates to function signatures, and a new helper function for partial flattening.Feature Addition: Partial Layer Flattening
--last-n-layers(-n) flag to theflattencommand, enabling users to specify that only the last N layers of an image should be flattened. Includes validation to ensure the flag is non-negative. [1] [2]Codebase Updates for Flag Support
flatten,flattenIndex,flattenChild,flattenImage) to accept thelastNparameter and propagate it through the flattening logic. [1] [2] [3] [4] [5]Core Logic Implementation
partialFlattenImagefunction, which merges only the last N layers into a single layer while preserving the earlier layers and original image history. This function handles layer extraction, merging, and history propagation, and ensures annotations are retained.Input Validation
partialFlattenImagefunction to ensurelastNis within a sensible range (1 to total layers). [1] [2]Let me know if you want a walkthrough of how the partial flattening works or have questions about the changes!