Skip to content

Conversation

@lingdie
Copy link

@lingdie lingdie commented Dec 8, 2025

This pull request introduces a new feature to the flatten command, 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

  • Added a --last-n-layers (-n) flag to the flatten command, 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

  • Updated all relevant function signatures (flatten, flattenIndex, flattenChild, flattenImage) to accept the lastN parameter and propagate it through the flattening logic. [1] [2] [3] [4] [5]

Core Logic Implementation

  • Added the partialFlattenImage function, 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

  • Added validation in the command pre-run hook and in the partialFlattenImage function to ensure lastN is 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!

@google-cla
Copy link

google-cla bot commented Dec 8, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

2 participants