Repository navigation
Add opt-in UPX clean/smudge filters - #136
Conversation
|
ARM64 counterpart PR: git-for-windows#69 |
dscho
left a comment
There was a problem hiding this comment.
Thank you for this very good first iteration.
A lot of that iteration, however, suffers from Sol's overconfidence and inclination to write more code than is necessary, more code than is elegant, way more code than is desirable.
I think basically the entire 130 line script to set up the filter can be reduced to maybe a dozen. And if we do that already, if we condense and distill it to the elegance we strive for, we can easily and neatly fold the setup logic into the filter script.
Speaking of the filter script: I doubt that having upx in the name is doing us any favors. It is technically true, but it doesn't tell the reader anything about the script's purpose. Its purpose is to handle large DLLs. So maybe the filename should reflect that (and a comment at the top would not hurt one bit, either).
Also about the filter script: its location in the top level directory might be based on the prior art of the update-pacman.ps1 script. But I don't think it's actually a good idea to clutter the top level directory that way. In the least, I would like to make it a dot file, e.g. .git-large-dll-smudge-filter.sh. At least this way a regular ls would not show it.
Thoughts? Concerns?
| if ! "$upx" --no-env -t "$directory/input.dll" >/dev/null 2>&1 | ||
| then | ||
| # Validate unpacked input before passing it through. | ||
| "$upx" --no-env --exact -o "$directory/output.dll" \ |
There was a problem hiding this comment.
Very nice, with --exact, code signatures are recreated precisely.
|
|
||
| case "$1" in | ||
| clean) | ||
| # Git can clean content that is already in its repository form. |
There was a problem hiding this comment.
This comment seems a bit misleading. If the DLL is already compressed, we do not want to try to compress it again because that would fail with an error.
Sol initially tried to put the script in the With sparse-checkout however, we'd want to make sure the UPX pieces were always present (or could detect if they were missing; hence the validation). |
Heh. I repeated the exact sequence when I thought about better locations.
I disagree. Whether or not all the necessary bits and pieces are present in a sparse checkout is the user's responsibility, or at least the person's who makes the edits to the This filter is a nice-to-have for most people, not a requirement. I need it to be focused, small, precise in its job. The fact that we will need to decompress the DLLs for the purposes of building Git installers or even for the ci-artifacts (because uncompressed DLLs compress better than UPX-compressed ones) only means that we have to follow up carefully over there, once, not that the script should carry complexity that is not justified by its long-term benefit. |
Large DLLs can exceed remote file-size limits. UPX-packed binaries
remain runnable without filter configuration, at the cost of startup
decompression. Provide opt-in local filtering so users can trade disk
space for avoiding that repeated cost while Git keeps compressed blobs.
Provide clean, smudge, and setup modes in .large-dll-filter.sh. Prefer
the checkout's ucrt64/bin and clangarm64/bin on PATH so the same script
works in both SDKs and from a regular Git Bash.
After checkout, enable filtering and unpack existing attributed files:
bash ./.large-dll-filter.sh setup
Use setup --no-refresh in package-update automation to configure the
driver without rewriting working-tree files. Setup installs these
repository-local values:
filter.upx.clean = bash ./.large-dll-filter.sh clean
filter.upx.smudge = bash ./.large-dll-filter.sh smudge
filter.upx.required = true
Require successful filtering to avoid silently staging unpacked blobs
when clean fails. Attribute selection remains separate from setup.
Unpack existing packed files directly in the working tree, leaving the
index unchanged. Partial optimization is harmless, since both forms
work. Skip absent files, symlinks, and files not recognized as packed.
Disable Git's filename quoting when enumerating Windows paths so
spaces and Unicode names are preserved.
Use private temporary files for stream conversion, where UPX's file
interface requires them, and --exact to preserve original bytes.
Help is available with --help, -h, or -?.
Assisted-by: GPT-6.1 Sol
Signed-off-by: Matthew John Cheetham <[email protected]>
4b43701 to
97b76b4
Compare
dscho
left a comment
There was a problem hiding this comment.
Nice!
I see potential for further improvements, such as letting usage accept an optional exit code (defaulting to exit ${1-1}) because every call to usage exits afterwards, the only difference being the exit code, and moving the primary use case (clean and smudge) way up to the top (probably also refactoring the mktemp logic into its own function).
But these are merely optimizations for something that isn't performance-critical nor subject for heavy development, so the current form is fine.
Summary
Add opt-in clean/smudge filtering for large DLLs. Git stores UPX-packed binaries, while users can choose unpacked working-tree files to avoid decompression at startup.
Packed binaries remain runnable, so ordinary clones work without filter configuration or special checkout steps.
Usage
After checkout:
For configuration only, without unpacking existing files:
Help is available with
--help,-h, or-?.Revised design
Following review, filtering and setup share one hidden script,
.large-dll-filter.sh, withclean,smudge, andsetupmodes.The script prepends the checkout's UCRT64 and clangarm64 bin directories to PATH. Setup configures repository-local filters and directly unpacks existing attributed files. It does not replace files from the index or require transactional conversion: partially unpacked checkouts work too.
Clean/smudge retain private temporary files to bridge Git's streams to UPX's file interface. Packing uses
--exactto preserve original bytes. The local driver is required so failed clean operations cannot silently stage unpacked binaries.No filter attributes are introduced here. Selecting Rust's LLVM DLLs and configuring package-update automation are separate follow-ups.
Validation
Tested with packaged x64 UPX in both SDK directory layouts: lossless round trips, stable staging, repeated setup, configuration-only setup, Unicode and spaced paths, missing files, preservation of local working-file edits, and filter failure handling.
The script is identical across both SDK repositories. Native ARM64 execution has not been tested locally.